OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 , m_drawFramebufferBinding(0) | 144 , m_drawFramebufferBinding(0) |
145 , m_readFramebufferBinding(0) | 145 , m_readFramebufferBinding(0) |
146 , m_activeTextureUnit(GL_TEXTURE0) | 146 , m_activeTextureUnit(GL_TEXTURE0) |
147 , m_context(context) | 147 , m_context(context) |
148 , m_extensionsUtil(extensionsUtil) | 148 , m_extensionsUtil(extensionsUtil) |
149 , m_size(-1, -1) | 149 , m_size(-1, -1) |
150 , m_requestedAttributes(requestedAttributes) | 150 , m_requestedAttributes(requestedAttributes) |
151 , m_multisampleExtensionSupported(multisampleExtensionSupported) | 151 , m_multisampleExtensionSupported(multisampleExtensionSupported) |
152 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte d) | 152 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte d) |
153 , m_discardFramebufferSupported(discardFramebufferSupported) | 153 , m_discardFramebufferSupported(discardFramebufferSupported) |
154 , m_storageTextureSupported(false) | |
154 , m_fbo(0) | 155 , m_fbo(0) |
155 , m_depthStencilBuffer(0) | 156 , m_depthStencilBuffer(0) |
156 , m_depthBuffer(0) | 157 , m_depthBuffer(0) |
157 , m_stencilBuffer(0) | 158 , m_stencilBuffer(0) |
158 , m_multisampleFBO(0) | 159 , m_multisampleFBO(0) |
159 , m_multisampleColorBuffer(0) | 160 , m_multisampleColorBuffer(0) |
160 , m_contentsChanged(true) | 161 , m_contentsChanged(true) |
161 , m_contentsChangeCommitted(false) | 162 , m_contentsChangeCommitted(false) |
162 , m_bufferClearNeeded(false) | 163 , m_bufferClearNeeded(false) |
163 , m_antiAliasingMode(None) | 164 , m_antiAliasingMode(None) |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; | 267 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; |
267 if (pixels) | 268 if (pixels) |
268 readBackFramebuffer(pixels, size().width(), size().height(), Readbac kSkia, op); | 269 readBackFramebuffer(pixels, size().width(), size().height(), Readbac kSkia, op); |
269 } | 270 } |
270 | 271 |
271 // We must restore the texture binding since creating new textures, | 272 // We must restore the texture binding since creating new textures, |
272 // consuming and producing mailboxes changes it. | 273 // consuming and producing mailboxes changes it. |
273 ScopedTextureUnit0BindingRestorer restorer(m_context.get(), m_activeTextureU nit, m_texture2DBinding); | 274 ScopedTextureUnit0BindingRestorer restorer(m_context.get(), m_activeTextureU nit, m_texture2DBinding); |
274 | 275 |
275 // First try to recycle an old buffer. | 276 // First try to recycle an old buffer. |
276 RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); | 277 RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); |
dshwang
2015/11/20 09:31:32
resizing code is here. it calls allocateTextureMem
Ken Russell (switch to Gerrit)
2015/11/23 22:26:31
OK, thanks, I had missed the fact that recycledMai
| |
277 | 278 |
278 // No buffer available to recycle, create a new one. | 279 // No buffer available to recycle, create a new one. |
279 if (!frontColorBufferMailbox) { | 280 if (!frontColorBufferMailbox) { |
280 TextureInfo newTexture; | 281 TextureInfo newTexture; |
281 newTexture.textureId = createColorTexture(); | 282 newTexture.textureId = createColorTexture(); |
282 allocateTextureMemory(&newTexture, m_size); | 283 allocateTextureMemory(&newTexture, m_size); |
283 // Bad things happened, abandon ship. | 284 // Bad things happened, abandon ship. |
284 if (!newTexture.textureId) | 285 if (!newTexture.textureId) |
285 return false; | 286 return false; |
286 | 287 |
(...skipping 11 matching lines...) Expand all Loading... | |
298 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COL OR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer.textureId, 0, m_sampleCount); | 299 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COL OR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer.textureId, 0, m_sampleCount); |
299 else | 300 else |
300 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D, m_colorBuffer.textureId, 0); | 301 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D, m_colorBuffer.textureId, 0); |
301 | 302 |
302 if (m_discardFramebufferSupported) { | 303 if (m_discardFramebufferSupported) { |
303 // Explicitly discard framebuffer to save GPU memory bandwidth for t ile-based GPU arch. | 304 // Explicitly discard framebuffer to save GPU memory bandwidth for t ile-based GPU arch. |
304 const WGC3Denum attachments[3] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_AT TACHMENT, GL_STENCIL_ATTACHMENT}; | 305 const WGC3Denum attachments[3] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_AT TACHMENT, GL_STENCIL_ATTACHMENT}; |
305 m_context->discardFramebufferEXT(GL_FRAMEBUFFER, 3, attachments); | 306 m_context->discardFramebufferEXT(GL_FRAMEBUFFER, 3, attachments); |
306 } | 307 } |
307 } else { | 308 } else { |
308 m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_colorBuffer.textureId, f rontColorBufferMailbox->textureInfo.textureId, GL_RGBA, GL_UNSIGNED_BYTE, GL_FAL SE, GL_FALSE, GL_FALSE); | 309 m_context->copySubTextureCHROMIUM(GL_TEXTURE_2D, m_colorBuffer.textureId , frontColorBufferMailbox->textureInfo.textureId, |
dshwang
2015/11/19 12:33:00
copyTextureCHROMIUM must not used for immutable te
Ken Russell (switch to Gerrit)
2015/11/19 21:47:41
If this code was relying on the copyTextureCHROMIU
dshwang
2015/11/20 09:31:32
This code doesn't rely on copyTextureCHROMIUM call
Ken Russell (switch to Gerrit)
2015/11/23 22:26:31
I went ahead and wrote the test I had in mind in h
dshwang
2015/11/24 12:05:11
Thank you for adding test! The test works well wit
| |
310 0, 0, 0, 0, m_size.width(), m_size.height(), GL_FALSE, GL_FALSE, GL_ FALSE); | |
309 } | 311 } |
310 | 312 |
311 restoreFramebufferBindings(); | 313 restoreFramebufferBindings(); |
312 m_contentsChanged = false; | 314 m_contentsChanged = false; |
313 | 315 |
314 m_context->produceTextureDirectCHROMIUM(frontColorBufferMailbox->textureInfo .textureId, GL_TEXTURE_2D, frontColorBufferMailbox->mailbox.name); | 316 m_context->produceTextureDirectCHROMIUM(frontColorBufferMailbox->textureInfo .textureId, GL_TEXTURE_2D, frontColorBufferMailbox->mailbox.name); |
315 m_context->flush(); | 317 m_context->flush(); |
316 frontColorBufferMailbox->mailbox.validSyncToken = m_context->insertSyncPoint (frontColorBufferMailbox->mailbox.syncToken); | 318 frontColorBufferMailbox->mailbox.validSyncToken = m_context->insertSyncPoint (frontColorBufferMailbox->mailbox.syncToken); |
317 frontColorBufferMailbox->mailbox.allowOverlay = frontColorBufferMailbox->tex tureInfo.imageId != 0; | 319 frontColorBufferMailbox->mailbox.allowOverlay = frontColorBufferMailbox->tex tureInfo.imageId != 0; |
318 setBufferClearNeeded(true); | 320 setBufferClearNeeded(true); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 if (m_requestedAttributes.antialias && m_multisampleExtensionSupported) { | 444 if (m_requestedAttributes.antialias && m_multisampleExtensionSupported) { |
443 m_context->getIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); | 445 m_context->getIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); |
444 m_antiAliasingMode = MSAAExplicitResolve; | 446 m_antiAliasingMode = MSAAExplicitResolve; |
445 if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t exture")) { | 447 if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t exture")) { |
446 m_antiAliasingMode = MSAAImplicitResolve; | 448 m_antiAliasingMode = MSAAImplicitResolve; |
447 } else if (m_extensionsUtil->supportsExtension("GL_CHROMIUM_screen_space _antialiasing")) { | 449 } else if (m_extensionsUtil->supportsExtension("GL_CHROMIUM_screen_space _antialiasing")) { |
448 m_antiAliasingMode = ScreenSpaceAntialiasing; | 450 m_antiAliasingMode = ScreenSpaceAntialiasing; |
449 } | 451 } |
450 } | 452 } |
451 m_sampleCount = std::min(4, maxSampleCount); | 453 m_sampleCount = std::min(4, maxSampleCount); |
454 m_storageTextureSupported = m_extensionsUtil->supportsExtension("GL_EXT_text ure_storage"); | |
452 | 455 |
453 m_fbo = m_context->createFramebuffer(); | 456 m_fbo = m_context->createFramebuffer(); |
454 | 457 |
455 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 458 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
456 m_colorBuffer.textureId = createColorTexture(); | 459 m_colorBuffer.textureId = createColorTexture(); |
457 if (m_antiAliasingMode == MSAAImplicitResolve) | 460 if (m_antiAliasingMode == MSAAImplicitResolve) |
458 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A TTACHMENT0, GL_TEXTURE_2D, m_colorBuffer.textureId, 0, m_sampleCount); | 461 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A TTACHMENT0, GL_TEXTURE_2D, m_colorBuffer.textureId, 0, m_sampleCount); |
459 else | 462 else |
460 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL _TEXTURE_2D, m_colorBuffer.textureId, 0); | 463 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL _TEXTURE_2D, m_colorBuffer.textureId, 0); |
461 createSecondaryBuffers(); | 464 createSecondaryBuffers(); |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
952 unsigned count = height / 2; | 955 unsigned count = height / 2; |
953 for (unsigned i = 0; i < count; i++) { | 956 for (unsigned i = 0; i < count; i++) { |
954 uint8* rowA = framebuffer + i * rowBytes; | 957 uint8* rowA = framebuffer + i * rowBytes; |
955 uint8* rowB = framebuffer + (height - i - 1) * rowBytes; | 958 uint8* rowB = framebuffer + (height - i - 1) * rowBytes; |
956 memcpy(scanline, rowB, rowBytes); | 959 memcpy(scanline, rowB, rowBytes); |
957 memcpy(rowB, rowA, rowBytes); | 960 memcpy(rowB, rowA, rowBytes); |
958 memcpy(rowA, scanline, rowBytes); | 961 memcpy(rowA, scanline, rowBytes); |
959 } | 962 } |
960 } | 963 } |
961 | 964 |
962 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLint unpackAlignment) | |
963 { | |
964 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4 || unpackAlignment == 8); | |
965 m_context->texImage2D(target, level, internalformat, width, height, border, format, type, 0); | |
966 } | |
967 | |
968 void DrawingBuffer::allocateTextureMemory(TextureInfo* info, const IntSize& size ) | 965 void DrawingBuffer::allocateTextureMemory(TextureInfo* info, const IntSize& size ) |
969 { | 966 { |
970 if (RuntimeEnabledFeatures::webGLImageChromiumEnabled()) { | 967 if (RuntimeEnabledFeatures::webGLImageChromiumEnabled()) { |
971 deleteChromiumImageForTexture(info); | 968 deleteChromiumImageForTexture(info); |
972 | 969 |
973 info->imageId = m_context->createGpuMemoryBufferImageCHROMIUM(size.width (), size.height(), GL_RGBA, GC3D_SCANOUT_CHROMIUM); | 970 info->imageId = m_context->createGpuMemoryBufferImageCHROMIUM(size.width (), size.height(), GL_RGBA, GC3D_SCANOUT_CHROMIUM); |
974 if (info->imageId) { | 971 if (info->imageId) { |
975 m_context->bindTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); | 972 m_context->bindTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); |
976 return; | 973 return; |
977 } | 974 } |
978 } | 975 } |
979 | 976 |
980 texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, size.width() , size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); | 977 if (m_storageTextureSupported) { |
978 if (info->immutable) { | |
979 m_context->deleteTexture(info->textureId); | |
980 info->textureId = createColorTexture(); | |
981 } | |
982 | |
983 // TODO(dshwang): GL_BGRA8_EXT can be better in some platforms. crbug.co m/557848 | |
984 m_context->texStorage2DEXT(GL_TEXTURE_2D, 1, m_internalRenderbufferForma t, size.width(), size.height()); | |
985 info->immutable = true; | |
986 return; | |
987 } | |
988 m_context->texImage2D(GL_TEXTURE_2D, 0, m_internalColorFormat, size.width(), size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE, 0); | |
981 } | 989 } |
982 | 990 |
983 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) | 991 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) |
984 { | 992 { |
985 if (info->imageId) { | 993 if (info->imageId) { |
986 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); | 994 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); |
987 m_context->destroyImageCHROMIUM(info->imageId); | 995 m_context->destroyImageCHROMIUM(info->imageId); |
988 info->imageId = 0; | 996 info->imageId = 0; |
989 } | 997 } |
990 } | 998 } |
991 | 999 |
992 } // namespace blink | 1000 } // namespace blink |
OLD | NEW |