Chromium Code Reviews| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 private: | 83 private: |
| 84 gpu::gles2::GLES2Interface* m_gl; | 84 gpu::gles2::GLES2Interface* m_gl; |
| 85 GLenum m_oldActiveTextureUnit; | 85 GLenum m_oldActiveTextureUnit; |
| 86 GLuint m_oldTextureUnitZeroId; | 86 GLuint m_oldTextureUnitZeroId; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 static bool shouldFailDrawingBufferCreationForTesting = false; | 89 static bool shouldFailDrawingBufferCreationForTesting = false; |
| 90 | 90 |
| 91 } // namespace | 91 } // namespace |
| 92 | 92 |
| 93 PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<WebGraphicsContext3DP rovider> contextProvider, const IntSize& size, bool premultipliedAlpha, Preserve DrawingBuffer preserve, WebGraphicsContext3D::Attributes requestedAttributes) | 93 PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<WebGraphicsContext3DP rovider> contextProvider, const IntSize& size, bool premultipliedAlpha, bool wan tAlphaChannel, bool wantDepthBuffer, bool wantStencilBuffer, bool wantAntialiasi ng, PreserveDrawingBuffer preserve) |
| 94 { | 94 { |
| 95 ASSERT(contextProvider); | 95 ASSERT(contextProvider); |
| 96 | 96 |
| 97 if (shouldFailDrawingBufferCreationForTesting) { | 97 if (shouldFailDrawingBufferCreationForTesting) { |
| 98 shouldFailDrawingBufferCreationForTesting = false; | 98 shouldFailDrawingBufferCreationForTesting = false; |
| 99 return nullptr; | 99 return nullptr; |
| 100 } | 100 } |
| 101 | 101 |
| 102 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(contextPr ovider->contextGL()); | 102 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(contextPr ovider->contextGL()); |
| 103 if (!extensionsUtil->isValid()) { | 103 if (!extensionsUtil->isValid()) { |
| 104 // This might be the first time we notice that the GL context is lost. | 104 // This might be the first time we notice that the GL context is lost. |
| 105 return nullptr; | 105 return nullptr; |
| 106 } | 106 } |
| 107 ASSERT(extensionsUtil->supportsExtension("GL_OES_packed_depth_stencil")); | 107 ASSERT(extensionsUtil->supportsExtension("GL_OES_packed_depth_stencil")); |
| 108 extensionsUtil->ensureExtensionEnabled("GL_OES_packed_depth_stencil"); | 108 extensionsUtil->ensureExtensionEnabled("GL_OES_packed_depth_stencil"); |
| 109 bool multisampleSupported = (extensionsUtil->supportsExtension("GL_CHROMIUM_ framebuffer_multisample") | 109 bool multisampleSupported = |
| 110 || extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_text ure")) | 110 wantAntialiasing |
|
danakj
2016/03/31 20:27:57
This is where we disable MSAA if WebGL app said no
| |
| 111 && (extensionsUtil->supportsExtension("GL_CHROMIUM_framebuffer_multisamp le") | |
| 112 || extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_ texture")) | |
| 111 && extensionsUtil->supportsExtension("GL_OES_rgb8_rgba8"); | 113 && extensionsUtil->supportsExtension("GL_OES_rgb8_rgba8"); |
| 112 if (multisampleSupported) { | 114 if (multisampleSupported) { |
| 113 extensionsUtil->ensureExtensionEnabled("GL_OES_rgb8_rgba8"); | 115 extensionsUtil->ensureExtensionEnabled("GL_OES_rgb8_rgba8"); |
| 114 if (extensionsUtil->supportsExtension("GL_CHROMIUM_framebuffer_multisamp le")) | 116 if (extensionsUtil->supportsExtension("GL_CHROMIUM_framebuffer_multisamp le")) |
| 115 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_mult isample"); | 117 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_mult isample"); |
| 116 else | 118 else |
| 117 extensionsUtil->ensureExtensionEnabled("GL_EXT_multisampled_render_t o_texture"); | 119 extensionsUtil->ensureExtensionEnabled("GL_EXT_multisampled_render_t o_texture"); |
| 118 } | 120 } |
| 119 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT _discard_framebuffer"); | 121 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT _discard_framebuffer"); |
| 120 if (discardFramebufferSupported) | 122 if (discardFramebufferSupported) |
| 121 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer"); | 123 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer"); |
| 122 | 124 |
| 123 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(std::move(c ontextProvider), extensionsUtil.release(), multisampleSupported, discardFramebuf ferSupported, premultipliedAlpha, preserve, requestedAttributes)); | 125 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(std::move(c ontextProvider), extensionsUtil.release(), discardFramebufferSupported, premulti pliedAlpha, preserve)); |
| 124 if (!drawingBuffer->initialize(size)) { | 126 if (!drawingBuffer->initialize(size, wantAlphaChannel, wantDepthBuffer, want StencilBuffer, multisampleSupported)) { |
| 125 drawingBuffer->beginDestruction(); | 127 drawingBuffer->beginDestruction(); |
| 126 return PassRefPtr<DrawingBuffer>(); | 128 return PassRefPtr<DrawingBuffer>(); |
| 127 } | 129 } |
| 128 return drawingBuffer.release(); | 130 return drawingBuffer.release(); |
| 129 } | 131 } |
| 130 | 132 |
| 131 void DrawingBuffer::forceNextDrawingBufferCreationToFail() | 133 void DrawingBuffer::forceNextDrawingBufferCreationToFail() |
| 132 { | 134 { |
| 133 shouldFailDrawingBufferCreationForTesting = true; | 135 shouldFailDrawingBufferCreationForTesting = true; |
| 134 } | 136 } |
| 135 | 137 |
| 136 DrawingBuffer::DrawingBuffer(PassOwnPtr<WebGraphicsContext3DProvider> contextPro vider, PassOwnPtr<Extensions3DUtil> extensionsUtil, bool multisampleExtensionSup ported, bool discardFramebufferSupported, bool premultipliedAlpha, PreserveDrawi ngBuffer preserve, WebGraphicsContext3D::Attributes requestedAttributes) | 138 DrawingBuffer::DrawingBuffer( |
| 139 PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, | |
| 140 PassOwnPtr<Extensions3DUtil> extensionsUtil, | |
| 141 bool discardFramebufferSupported, | |
| 142 bool premultipliedAlpha, | |
| 143 PreserveDrawingBuffer preserve) | |
| 137 : m_preserveDrawingBuffer(preserve) | 144 : m_preserveDrawingBuffer(preserve) |
| 138 , m_scissorEnabled(false) | 145 , m_scissorEnabled(false) |
| 139 , m_texture2DBinding(0) | 146 , m_texture2DBinding(0) |
| 140 , m_drawFramebufferBinding(0) | 147 , m_drawFramebufferBinding(0) |
| 141 , m_readFramebufferBinding(0) | 148 , m_readFramebufferBinding(0) |
| 142 , m_activeTextureUnit(GL_TEXTURE0) | 149 , m_activeTextureUnit(GL_TEXTURE0) |
| 143 , m_contextProvider(std::move(contextProvider)) | 150 , m_contextProvider(std::move(contextProvider)) |
| 144 , m_context(m_contextProvider->context3d()) | 151 , m_context(m_contextProvider->context3d()) |
| 145 , m_gl(m_contextProvider->contextGL()) | 152 , m_gl(m_contextProvider->contextGL()) |
| 146 , m_extensionsUtil(std::move(extensionsUtil)) | 153 , m_extensionsUtil(std::move(extensionsUtil)) |
| 147 , m_size(-1, -1) | 154 , m_size(-1, -1) |
| 148 , m_requestedAttributes(requestedAttributes) | |
| 149 , m_multisampleExtensionSupported(multisampleExtensionSupported) | |
| 150 , m_discardFramebufferSupported(discardFramebufferSupported) | 155 , m_discardFramebufferSupported(discardFramebufferSupported) |
| 151 , m_premultipliedAlpha(premultipliedAlpha) | 156 , m_premultipliedAlpha(premultipliedAlpha) |
| 157 , m_hasAlphaChannel(false) | |
| 158 , m_hasDepthBuffer(false) | |
| 159 , m_hasStencilBuffer(false) | |
| 160 , m_hasImplicitStencilBuffer(false) | |
| 152 , m_fbo(0) | 161 , m_fbo(0) |
| 153 , m_depthStencilBuffer(0) | 162 , m_depthStencilBuffer(0) |
| 154 , m_multisampleFBO(0) | 163 , m_multisampleFBO(0) |
| 155 , m_multisampleColorBuffer(0) | 164 , m_multisampleColorBuffer(0) |
| 156 , m_contentsChanged(true) | 165 , m_contentsChanged(true) |
| 157 , m_contentsChangeCommitted(false) | 166 , m_contentsChangeCommitted(false) |
| 158 , m_bufferClearNeeded(false) | 167 , m_bufferClearNeeded(false) |
| 159 , m_antiAliasingMode(None) | 168 , m_antiAliasingMode(None) |
| 160 , m_maxTextureSize(0) | 169 , m_maxTextureSize(0) |
| 161 , m_sampleCount(0) | 170 , m_sampleCount(0) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 (*m_newMailboxCallback)(); | 270 (*m_newMailboxCallback)(); |
| 262 | 271 |
| 263 // Resolve the multisampled buffer into m_colorBuffer texture. | 272 // Resolve the multisampled buffer into m_colorBuffer texture. |
| 264 if (m_antiAliasingMode != None) | 273 if (m_antiAliasingMode != None) |
| 265 commit(); | 274 commit(); |
| 266 | 275 |
| 267 if (bitmap) { | 276 if (bitmap) { |
| 268 bitmap->setSize(size()); | 277 bitmap->setSize(size()); |
| 269 | 278 |
| 270 unsigned char* pixels = bitmap->pixels(); | 279 unsigned char* pixels = bitmap->pixels(); |
| 271 bool needPremultiply = m_actualAttributes.alpha && !m_premultipliedAlpha ; | 280 bool needPremultiply = m_hasAlphaChannel && !m_premultipliedAlpha; |
| 272 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; | 281 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; |
| 273 if (pixels) | 282 if (pixels) |
| 274 readBackFramebuffer(pixels, size().width(), size().height(), Readbac kSkia, op); | 283 readBackFramebuffer(pixels, size().width(), size().height(), Readbac kSkia, op); |
| 275 } | 284 } |
| 276 | 285 |
| 277 // We must restore the texture binding since creating new textures, | 286 // We must restore the texture binding since creating new textures, |
| 278 // consuming and producing mailboxes changes it. | 287 // consuming and producing mailboxes changes it. |
| 279 ScopedTextureUnit0BindingRestorer restorer(m_gl, m_activeTextureUnit, m_text ure2DBinding); | 288 ScopedTextureUnit0BindingRestorer restorer(m_gl, m_activeTextureUnit, m_text ure2DBinding); |
| 280 | 289 |
| 281 // First try to recycle an old buffer. | 290 // First try to recycle an old buffer. |
| 282 RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); | 291 RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); |
| 283 | 292 |
| 284 // No buffer available to recycle, create a new one. | 293 // No buffer available to recycle, create a new one. |
| 285 if (!frontColorBufferMailbox) { | 294 if (!frontColorBufferMailbox) { |
| 286 frontColorBufferMailbox = createNewMailbox(createTextureAndAllocateMemor y(m_size)); | 295 frontColorBufferMailbox = createNewMailbox(createTextureAndAllocateMemor y(m_size, m_hasAlphaChannel)); |
|
danakj
2016/03/31 20:27:57
This is a possible behaviour change tho I'm not su
piman
2016/03/31 20:54:59
Can we DCHECK they're the same? In particular, if
| |
| 287 } | 296 } |
| 288 | 297 |
| 289 if (m_preserveDrawingBuffer == Discard) { | 298 if (m_preserveDrawingBuffer == Discard) { |
| 290 std::swap(frontColorBufferMailbox->textureInfo, m_colorBuffer); | 299 std::swap(frontColorBufferMailbox->textureInfo, m_colorBuffer); |
| 291 // It appears safe to overwrite the context's framebuffer binding in the Discard case since there will always be a | 300 // It appears safe to overwrite the context's framebuffer binding in the Discard case since there will always be a |
| 292 // WebGLRenderingContext::clearIfComposited() call made before the next draw call which restores the framebuffer binding. | 301 // WebGLRenderingContext::clearIfComposited() call made before the next draw call which restores the framebuffer binding. |
| 293 // If this stops being true at some point, we should track the current f ramebuffer binding in the DrawingBuffer and restore | 302 // If this stops being true at some point, we should track the current f ramebuffer binding in the DrawingBuffer and restore |
| 294 // it after attaching the new back buffer here. | 303 // it after attaching the new back buffer here. |
| 295 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 304 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 296 attachColorBufferToCurrentFBO(); | 305 attachColorBufferToCurrentFBO(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 mailboxInfo->mailbox.validSyncToken = mailbox.validSyncToken; | 349 mailboxInfo->mailbox.validSyncToken = mailbox.validSyncToken; |
| 341 ASSERT(mailboxInfo->m_parentDrawingBuffer.get() == this); | 350 ASSERT(mailboxInfo->m_parentDrawingBuffer.get() == this); |
| 342 mailboxInfo->m_parentDrawingBuffer.clear(); | 351 mailboxInfo->m_parentDrawingBuffer.clear(); |
| 343 m_recycledMailboxQueue.prepend(mailboxInfo->mailbox); | 352 m_recycledMailboxQueue.prepend(mailboxInfo->mailbox); |
| 344 return; | 353 return; |
| 345 } | 354 } |
| 346 } | 355 } |
| 347 ASSERT_NOT_REACHED(); | 356 ASSERT_NOT_REACHED(); |
| 348 } | 357 } |
| 349 | 358 |
| 350 DrawingBuffer::TextureParameters DrawingBuffer::chromiumImageTextureParameters() | 359 DrawingBuffer::TextureParameters DrawingBuffer::chromiumImageTextureParameters(b ool wantAlphaChannel) |
| 351 { | 360 { |
| 352 #if OS(MACOSX) | 361 #if OS(MACOSX) |
| 353 // A CHROMIUM_image backed texture requires a specialized set of parameters | 362 // A CHROMIUM_image backed texture requires a specialized set of parameters |
| 354 // on OSX. | 363 // on OSX. |
| 355 TextureParameters parameters; | 364 TextureParameters parameters; |
| 356 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; | 365 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; |
| 357 parameters.internalColorFormat = GL_BGRA_EXT; | 366 parameters.internalColorFormat = GL_BGRA_EXT; |
| 358 parameters.internalRenderbufferFormat = GL_RGBA8_OES; | 367 parameters.internalRenderbufferFormat = GL_RGBA8_OES; |
| 359 parameters.colorFormat = GL_RGBA; | 368 parameters.colorFormat = GL_RGBA; |
| 360 return parameters; | 369 return parameters; |
| 361 #else | 370 #else |
| 362 return defaultTextureParameters(); | 371 return defaultTextureParameters(wantAlphaChannel); |
| 363 #endif | 372 #endif |
| 364 } | 373 } |
| 365 | 374 |
| 366 DrawingBuffer::TextureParameters DrawingBuffer::defaultTextureParameters() | 375 DrawingBuffer::TextureParameters DrawingBuffer::defaultTextureParameters(bool wa ntAlphaChannel) |
| 367 { | 376 { |
| 368 TextureParameters parameters; | 377 TextureParameters parameters; |
| 369 parameters.target = GL_TEXTURE_2D; | 378 parameters.target = GL_TEXTURE_2D; |
| 370 if (m_requestedAttributes.alpha) { | 379 if (wantAlphaChannel) { |
| 371 parameters.internalColorFormat = GL_RGBA; | 380 parameters.internalColorFormat = GL_RGBA; |
| 372 parameters.colorFormat = GL_RGBA; | 381 parameters.colorFormat = GL_RGBA; |
| 373 parameters.internalRenderbufferFormat = GL_RGBA8_OES; | 382 parameters.internalRenderbufferFormat = GL_RGBA8_OES; |
| 374 } else { | 383 } else { |
| 375 parameters.internalColorFormat = GL_RGB; | 384 parameters.internalColorFormat = GL_RGB; |
| 376 parameters.colorFormat = GL_RGB; | 385 parameters.colorFormat = GL_RGB; |
| 377 parameters.internalRenderbufferFormat = GL_RGB8_OES; | 386 parameters.internalRenderbufferFormat = GL_RGB8_OES; |
| 378 } | 387 } |
| 379 return parameters; | 388 return parameters; |
| 380 } | 389 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 deleteChromiumImageForTexture(&m_textureMailboxes[i]->textureInfo); | 451 deleteChromiumImageForTexture(&m_textureMailboxes[i]->textureInfo); |
| 443 | 452 |
| 444 m_gl->DeleteTextures(1, &m_textureMailboxes[i]->textureInfo.textureI d); | 453 m_gl->DeleteTextures(1, &m_textureMailboxes[i]->textureInfo.textureI d); |
| 445 m_textureMailboxes.remove(i); | 454 m_textureMailboxes.remove(i); |
| 446 return; | 455 return; |
| 447 } | 456 } |
| 448 } | 457 } |
| 449 ASSERT_NOT_REACHED(); | 458 ASSERT_NOT_REACHED(); |
| 450 } | 459 } |
| 451 | 460 |
| 452 bool DrawingBuffer::initialize(const IntSize& size) | 461 bool DrawingBuffer::initialize(const IntSize& size, bool wantAlphaChannel, bool wantDepthBuffer, bool wantStencilBuffer, bool multisampleExtensionSupported) |
| 453 { | 462 { |
| 454 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { | 463 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { |
| 455 // Need to try to restore the context again later. | 464 // Need to try to restore the context again later. |
| 456 return false; | 465 return false; |
| 457 } | 466 } |
| 458 | 467 |
| 459 m_gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); | 468 m_gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); |
| 460 | 469 |
| 470 // We update our expectations as we initialize to what we actually get from | |
| 471 // the GL context. | |
| 472 | |
| 461 int maxSampleCount = 0; | 473 int maxSampleCount = 0; |
| 462 m_antiAliasingMode = None; | 474 m_antiAliasingMode = None; |
| 463 if (m_requestedAttributes.antialias && m_multisampleExtensionSupported) { | 475 if (multisampleExtensionSupported) { |
| 464 m_gl->GetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); | 476 m_gl->GetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); |
| 465 m_antiAliasingMode = MSAAExplicitResolve; | 477 m_antiAliasingMode = MSAAExplicitResolve; |
| 466 if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t exture")) { | 478 if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t exture")) { |
| 467 m_antiAliasingMode = MSAAImplicitResolve; | 479 m_antiAliasingMode = MSAAImplicitResolve; |
| 468 } else if (m_extensionsUtil->supportsExtension("GL_CHROMIUM_screen_space _antialiasing")) { | 480 } else if (m_extensionsUtil->supportsExtension("GL_CHROMIUM_screen_space _antialiasing")) { |
| 469 m_antiAliasingMode = ScreenSpaceAntialiasing; | 481 m_antiAliasingMode = ScreenSpaceAntialiasing; |
| 470 } | 482 } |
| 471 } | 483 } |
| 472 m_sampleCount = std::min(4, maxSampleCount); | 484 m_sampleCount = std::min(4, maxSampleCount); |
| 473 | 485 |
| 474 m_gl->GenFramebuffers(1, &m_fbo); | 486 m_gl->GenFramebuffers(1, &m_fbo); |
| 475 | 487 |
| 476 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 488 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 477 createSecondaryBuffers(); | 489 createSecondaryBuffers(); |
| 478 // We first try to initialize everything with the requested attributes. | 490 // We first try to initialize everything as requested. |
| 479 if (!reset(size)) | 491 if (!reset(size, wantAlphaChannel, wantDepthBuffer || wantStencilBuffer)) |
| 480 return false; | 492 return false; |
| 481 // If that succeeds, we then see what we actually got and update our actual attributes to reflect that. | 493 // Then update our state with what we got from the GL context. |
| 482 m_actualAttributes = m_requestedAttributes; | 494 if (m_depthStencilBuffer && !wantStencilBuffer) { |
| 483 if (m_requestedAttributes.alpha) { | 495 DCHECK(wantDepthBuffer); |
| 496 m_hasImplicitStencilBuffer = true; | |
|
danakj
2016/03/31 20:27:57
This replaces the hasImplicitStencilBuffer() funct
| |
| 497 } | |
| 498 if (wantAlphaChannel) { | |
| 484 GLint alphaBits = 0; | 499 GLint alphaBits = 0; |
| 485 m_gl->GetIntegerv(GL_ALPHA_BITS, &alphaBits); | 500 m_gl->GetIntegerv(GL_ALPHA_BITS, &alphaBits); |
|
danakj
2016/03/31 20:41:16
Oh, these seem to be wrong maybe now. They read ab
danakj
2016/03/31 20:46:43
For alpha.. we just use RGB or RGBA and we use tha
piman
2016/03/31 21:07:49
Hit send before seeing these questions. The values
danakj
2016/03/31 21:57:24
OK IIUC from all this and from IRC, then what I am
| |
| 486 m_actualAttributes.alpha = alphaBits > 0; | 501 m_hasAlphaChannel = alphaBits > 0; |
| 487 } | 502 } |
| 488 if (m_requestedAttributes.depth) { | 503 if (wantDepthBuffer) { |
| 489 GLint depthBits = 0; | 504 GLint depthBits = 0; |
| 490 m_gl->GetIntegerv(GL_DEPTH_BITS, &depthBits); | 505 m_gl->GetIntegerv(GL_DEPTH_BITS, &depthBits); |
| 491 m_actualAttributes.depth = depthBits > 0; | 506 m_hasDepthBuffer = depthBits > 0; |
| 492 } | 507 } |
| 493 if (m_requestedAttributes.stencil) { | 508 if (wantStencilBuffer) { |
| 494 GLint stencilBits = 0; | 509 GLint stencilBits = 0; |
| 495 m_gl->GetIntegerv(GL_STENCIL_BITS, &stencilBits); | 510 m_gl->GetIntegerv(GL_STENCIL_BITS, &stencilBits); |
| 496 m_actualAttributes.stencil = stencilBits > 0; | 511 m_hasStencilBuffer = stencilBits > 0; |
| 497 } | 512 } |
| 498 m_actualAttributes.antialias = multisample(); | |
| 499 | 513 |
| 500 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { | 514 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { |
| 501 // It's possible that the drawing buffer allocation provokes a context l oss, so check again just in case. http://crbug.com/512302 | 515 // It's possible that the drawing buffer allocation provokes a context l oss, so check again just in case. http://crbug.com/512302 |
| 502 return false; | 516 return false; |
| 503 } | 517 } |
| 504 | 518 |
| 505 return true; | 519 return true; |
| 506 } | 520 } |
| 507 | 521 |
| 508 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, gpu::gl es2::GLES2Interface* gl, GLuint texture, GLenum internalFormat, | 522 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, gpu::gl es2::GLES2Interface* gl, GLuint texture, GLenum internalFormat, |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 538 m_gl->GenSyncTokenCHROMIUM(fenceSync, mailbox.syncToken); | 552 m_gl->GenSyncTokenCHROMIUM(fenceSync, mailbox.syncToken); |
| 539 mailbox.validSyncToken = true; | 553 mailbox.validSyncToken = true; |
| 540 } | 554 } |
| 541 | 555 |
| 542 if (mailbox.validSyncToken) | 556 if (mailbox.validSyncToken) |
| 543 gl->WaitSyncTokenCHROMIUM(mailbox.syncToken); | 557 gl->WaitSyncTokenCHROMIUM(mailbox.syncToken); |
| 544 GLuint sourceTexture = gl->CreateAndConsumeTextureCHROMIUM(target, mailbox.n ame); | 558 GLuint sourceTexture = gl->CreateAndConsumeTextureCHROMIUM(target, mailbox.n ame); |
| 545 | 559 |
| 546 GLboolean unpackPremultiplyAlphaNeeded = GL_FALSE; | 560 GLboolean unpackPremultiplyAlphaNeeded = GL_FALSE; |
| 547 GLboolean unpackUnpremultiplyAlphaNeeded = GL_FALSE; | 561 GLboolean unpackUnpremultiplyAlphaNeeded = GL_FALSE; |
| 548 if (m_actualAttributes.alpha && m_premultipliedAlpha && !premultiplyAlpha) | 562 if (m_hasAlphaChannel && m_premultipliedAlpha && !premultiplyAlpha) |
| 549 unpackUnpremultiplyAlphaNeeded = GL_TRUE; | 563 unpackUnpremultiplyAlphaNeeded = GL_TRUE; |
| 550 else if (m_actualAttributes.alpha && !m_premultipliedAlpha && premultiplyAlp ha) | 564 else if (m_hasAlphaChannel && !m_premultipliedAlpha && premultiplyAlpha) |
| 551 unpackPremultiplyAlphaNeeded = GL_TRUE; | 565 unpackPremultiplyAlphaNeeded = GL_TRUE; |
| 552 | 566 |
| 553 gl->CopyTextureCHROMIUM(sourceTexture, texture, internalFormat, destType, fl ipY, unpackPremultiplyAlphaNeeded, unpackUnpremultiplyAlphaNeeded); | 567 gl->CopyTextureCHROMIUM(sourceTexture, texture, internalFormat, destType, fl ipY, unpackPremultiplyAlphaNeeded, unpackUnpremultiplyAlphaNeeded); |
| 554 | 568 |
| 555 gl->DeleteTextures(1, &sourceTexture); | 569 gl->DeleteTextures(1, &sourceTexture); |
| 556 | 570 |
| 557 const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); | 571 const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); |
| 558 | 572 |
| 559 gl->Flush(); | 573 gl->Flush(); |
| 560 GLbyte syncToken[24]; | 574 GLbyte syncToken[24]; |
| 561 gl->GenSyncTokenCHROMIUM(fenceSync, syncToken); | 575 gl->GenSyncTokenCHROMIUM(fenceSync, syncToken); |
| 562 m_gl->WaitSyncTokenCHROMIUM(syncToken); | 576 m_gl->WaitSyncTokenCHROMIUM(syncToken); |
| 563 | 577 |
| 564 return true; | 578 return true; |
| 565 } | 579 } |
| 566 | 580 |
| 567 GLuint DrawingBuffer::framebuffer() const | 581 GLuint DrawingBuffer::framebuffer() const |
| 568 { | 582 { |
| 569 return m_fbo; | 583 return m_fbo; |
| 570 } | 584 } |
| 571 | 585 |
| 572 WebLayer* DrawingBuffer::platformLayer() | 586 WebLayer* DrawingBuffer::platformLayer() |
| 573 { | 587 { |
| 574 if (!m_layer) { | 588 if (!m_layer) { |
| 575 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExter nalTextureLayer(this)); | 589 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExter nalTextureLayer(this)); |
| 576 | 590 |
| 577 m_layer->setOpaque(!m_actualAttributes.alpha); | 591 m_layer->setOpaque(!m_hasAlphaChannel); |
| 578 m_layer->setBlendBackgroundColor(m_actualAttributes.alpha); | 592 m_layer->setBlendBackgroundColor(m_hasAlphaChannel); |
| 579 m_layer->setPremultipliedAlpha(m_premultipliedAlpha); | 593 m_layer->setPremultipliedAlpha(m_premultipliedAlpha); |
| 580 m_layer->setNearestNeighbor(m_filterQuality == kNone_SkFilterQuality); | 594 m_layer->setNearestNeighbor(m_filterQuality == kNone_SkFilterQuality); |
| 581 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 595 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
| 582 } | 596 } |
| 583 | 597 |
| 584 return m_layer->layer(); | 598 return m_layer->layer(); |
| 585 } | 599 } |
| 586 | 600 |
| 587 void DrawingBuffer::clearPlatformLayer() | 601 void DrawingBuffer::clearPlatformLayer() |
| 588 { | 602 { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 647 void DrawingBuffer::createSecondaryBuffers() | 661 void DrawingBuffer::createSecondaryBuffers() |
| 648 { | 662 { |
| 649 // create a multisample FBO | 663 // create a multisample FBO |
| 650 if (m_antiAliasingMode == MSAAExplicitResolve) { | 664 if (m_antiAliasingMode == MSAAExplicitResolve) { |
| 651 m_gl->GenFramebuffers(1, &m_multisampleFBO); | 665 m_gl->GenFramebuffers(1, &m_multisampleFBO); |
| 652 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); | 666 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); |
| 653 m_gl->GenRenderbuffers(1, &m_multisampleColorBuffer); | 667 m_gl->GenRenderbuffers(1, &m_multisampleColorBuffer); |
| 654 } | 668 } |
| 655 } | 669 } |
| 656 | 670 |
| 657 bool DrawingBuffer::resizeFramebuffer(const IntSize& size) | 671 bool DrawingBuffer::resizeFramebuffer(const IntSize& size, bool wantDepthOrStenc ilBuffer) |
| 658 { | 672 { |
| 659 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 673 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 660 if (m_antiAliasingMode != MSAAExplicitResolve) | 674 if (m_antiAliasingMode != MSAAExplicitResolve && wantDepthOrStencilBuffer) |
|
danakj
2016/03/31 20:27:57
we just don't call resizeDepthStencil() instead of
| |
| 661 resizeDepthStencil(size); | 675 resizeDepthStencil(size); |
| 662 if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) | 676 if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) |
| 663 return false; | 677 return false; |
| 664 | 678 |
| 665 return true; | 679 return true; |
| 666 } | 680 } |
| 667 | 681 |
| 668 bool DrawingBuffer::resizeMultisampleFramebuffer(const IntSize& size) | 682 bool DrawingBuffer::resizeMultisampleFramebuffer(const IntSize& size, bool wantD epthOrStencilBuffer) |
| 669 { | 683 { |
| 670 if (m_antiAliasingMode == MSAAExplicitResolve) { | 684 if (m_antiAliasingMode == MSAAExplicitResolve) { |
| 671 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); | 685 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); |
| 672 | 686 |
| 673 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_multisampleColorBuffer); | 687 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_multisampleColorBuffer); |
| 674 m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCo unt, m_colorBuffer.parameters.internalRenderbufferFormat, size.width(), size.hei ght()); | 688 m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCo unt, m_colorBuffer.parameters.internalRenderbufferFormat, size.width(), size.hei ght()); |
| 675 | 689 |
| 676 if (m_gl->GetError() == GL_OUT_OF_MEMORY) | 690 if (m_gl->GetError() == GL_OUT_OF_MEMORY) |
| 677 return false; | 691 return false; |
| 678 | 692 |
| 679 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_R ENDERBUFFER, m_multisampleColorBuffer); | 693 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_R ENDERBUFFER, m_multisampleColorBuffer); |
| 680 resizeDepthStencil(size); | 694 if (wantDepthOrStencilBuffer) |
|
danakj
2016/03/31 20:27:57
same here
| |
| 695 resizeDepthStencil(size); | |
| 681 if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPL ETE) | 696 if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPL ETE) |
| 682 return false; | 697 return false; |
| 683 } | 698 } |
| 684 | 699 |
| 685 return true; | 700 return true; |
| 686 } | 701 } |
| 687 | 702 |
| 688 void DrawingBuffer::resizeDepthStencil(const IntSize& size) | 703 void DrawingBuffer::resizeDepthStencil(const IntSize& size) |
| 689 { | 704 { |
| 690 if (!m_requestedAttributes.depth && !m_requestedAttributes.stencil) | |
|
danakj
2016/03/31 20:27:56
This is the early out we don't need then
| |
| 691 return; | |
| 692 | |
| 693 if (!m_depthStencilBuffer) | 705 if (!m_depthStencilBuffer) |
| 694 m_gl->GenRenderbuffers(1, &m_depthStencilBuffer); | 706 m_gl->GenRenderbuffers(1, &m_depthStencilBuffer); |
| 695 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer); | 707 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer); |
| 696 if (m_antiAliasingMode == MSAAImplicitResolve) | 708 if (m_antiAliasingMode == MSAAImplicitResolve) |
| 697 m_gl->RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, m_sampleCount, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); | 709 m_gl->RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, m_sampleCount, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); |
| 698 else if (m_antiAliasingMode == MSAAExplicitResolve) | 710 else if (m_antiAliasingMode == MSAAExplicitResolve) |
| 699 m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCo unt, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); | 711 m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCo unt, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); |
| 700 else | 712 else |
| 701 m_gl->RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, size .width(), size.height()); | 713 m_gl->RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, size .width(), size.height()); |
| 702 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, G L_RENDERBUFFER, m_depthStencilBuffer); | 714 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, G L_RENDERBUFFER, m_depthStencilBuffer); |
| 703 m_gl->BindRenderbuffer(GL_RENDERBUFFER, 0); | 715 m_gl->BindRenderbuffer(GL_RENDERBUFFER, 0); |
| 704 } | 716 } |
| 705 | 717 |
| 706 | 718 |
| 707 | 719 |
| 708 void DrawingBuffer::clearFramebuffers(GLbitfield clearMask) | 720 void DrawingBuffer::clearFramebuffers(GLbitfield clearMask) |
| 709 { | 721 { |
| 710 // We will clear the multisample FBO, but we also need to clear the non-mult isampled buffer. | 722 // We will clear the multisample FBO, but we also need to clear the non-mult isampled buffer. |
| 711 if (m_multisampleFBO) { | 723 if (m_multisampleFBO) { |
| 712 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 724 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 713 m_gl->Clear(GL_COLOR_BUFFER_BIT); | 725 m_gl->Clear(GL_COLOR_BUFFER_BIT); |
| 714 } | 726 } |
| 715 | 727 |
| 716 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleFBO : m_fbo); | 728 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleFBO : m_fbo); |
| 717 m_gl->Clear(clearMask); | 729 m_gl->Clear(clearMask); |
| 718 } | 730 } |
| 719 | 731 |
| 720 bool DrawingBuffer::hasImplicitStencilBuffer() const | |
| 721 { | |
| 722 return m_depthStencilBuffer && m_requestedAttributes.depth && !m_requestedAt tributes.stencil; | |
|
danakj
2016/03/31 20:27:56
This is stored as a bool in initialize() now
| |
| 723 } | |
| 724 | |
| 725 void DrawingBuffer::setSize(const IntSize& size) | 732 void DrawingBuffer::setSize(const IntSize& size) |
| 726 { | 733 { |
| 727 if (m_size == size) | 734 if (m_size == size) |
| 728 return; | 735 return; |
| 729 | 736 |
| 730 m_size = size; | 737 m_size = size; |
| 731 } | 738 } |
| 732 | 739 |
| 733 IntSize DrawingBuffer::adjustSize(const IntSize& desiredSize, const IntSize& cur Size, int maxTextureSize) | 740 IntSize DrawingBuffer::adjustSize(const IntSize& desiredSize, const IntSize& cur Size, int maxTextureSize) |
| 734 { | 741 { |
| 735 IntSize adjustedSize = desiredSize; | 742 IntSize adjustedSize = desiredSize; |
| 736 | 743 |
| 737 // Clamp if the desired size is greater than the maximum texture size for th e device. | 744 // Clamp if the desired size is greater than the maximum texture size for th e device. |
| 738 if (adjustedSize.height() > maxTextureSize) | 745 if (adjustedSize.height() > maxTextureSize) |
| 739 adjustedSize.setHeight(maxTextureSize); | 746 adjustedSize.setHeight(maxTextureSize); |
| 740 | 747 |
| 741 if (adjustedSize.width() > maxTextureSize) | 748 if (adjustedSize.width() > maxTextureSize) |
| 742 adjustedSize.setWidth(maxTextureSize); | 749 adjustedSize.setWidth(maxTextureSize); |
| 743 | 750 |
| 744 return adjustedSize; | 751 return adjustedSize; |
| 745 } | 752 } |
| 746 | 753 |
| 747 bool DrawingBuffer::reset(const IntSize& newSize) | 754 bool DrawingBuffer::reset(const IntSize& newSize, bool wantAlphaChannel, bool wa ntDepthOrStencilBuffer) |
| 748 { | 755 { |
| 749 ASSERT(!newSize.isEmpty()); | 756 ASSERT(!newSize.isEmpty()); |
| 750 IntSize adjustedSize = adjustSize(newSize, m_size, m_maxTextureSize); | 757 IntSize adjustedSize = adjustSize(newSize, m_size, m_maxTextureSize); |
| 751 if (adjustedSize.isEmpty()) | 758 if (adjustedSize.isEmpty()) |
| 752 return false; | 759 return false; |
| 753 | 760 |
| 754 if (adjustedSize != m_size) { | 761 if (adjustedSize != m_size) { |
| 755 do { | 762 do { |
| 756 if (m_colorBuffer.textureId) { | 763 if (m_colorBuffer.textureId) { |
| 757 resizeTextureMemory(&m_colorBuffer, adjustedSize); | 764 resizeTextureMemory(&m_colorBuffer, adjustedSize); |
| 758 } else { | 765 } else { |
| 759 m_colorBuffer = createTextureAndAllocateMemory(adjustedSize); | 766 m_colorBuffer = createTextureAndAllocateMemory(adjustedSize, wan tAlphaChannel); |
| 760 } | 767 } |
| 761 | 768 |
| 762 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 769 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 763 attachColorBufferToCurrentFBO(); | 770 attachColorBufferToCurrentFBO(); |
| 764 | 771 |
| 765 // resize multisample FBO | 772 // resize multisample FBO |
| 766 if (!resizeMultisampleFramebuffer(adjustedSize) || !resizeFramebuffe r(adjustedSize)) { | 773 if (!resizeMultisampleFramebuffer(adjustedSize, wantDepthOrStencilBu ffer) |
| 774 || !resizeFramebuffer(adjustedSize, wantDepthOrStencilBuffer)) { | |
| 767 adjustedSize.scale(s_resourceAdjustedRatio); | 775 adjustedSize.scale(s_resourceAdjustedRatio); |
| 768 continue; | 776 continue; |
| 769 } | 777 } |
| 770 break; | 778 break; |
| 771 } while (!adjustedSize.isEmpty()); | 779 } while (!adjustedSize.isEmpty()); |
| 772 | 780 |
| 773 setSize(adjustedSize); | 781 setSize(adjustedSize); |
| 774 | 782 |
| 775 if (adjustedSize.isEmpty()) | 783 if (adjustedSize.isEmpty()) |
| 776 return false; | 784 return false; |
| 777 } | 785 } |
| 778 | 786 |
| 779 m_gl->Disable(GL_SCISSOR_TEST); | 787 m_gl->Disable(GL_SCISSOR_TEST); |
| 780 m_gl->ClearColor(0, 0, 0, 0); | 788 m_gl->ClearColor(0, 0, 0, 0); |
| 781 m_gl->ColorMask(true, true, true, true); | 789 m_gl->ColorMask(true, true, true, true); |
| 782 | 790 |
| 783 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; | 791 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; |
| 784 if (m_actualAttributes.depth) { | 792 if (m_hasDepthBuffer) { |
| 785 m_gl->ClearDepthf(1.0f); | 793 m_gl->ClearDepthf(1.0f); |
| 786 clearMask |= GL_DEPTH_BUFFER_BIT; | 794 clearMask |= GL_DEPTH_BUFFER_BIT; |
| 787 m_gl->DepthMask(true); | 795 m_gl->DepthMask(true); |
| 788 } | 796 } |
| 789 if (m_actualAttributes.stencil) { | 797 if (m_hasStencilBuffer) { |
| 790 m_gl->ClearStencil(0); | 798 m_gl->ClearStencil(0); |
| 791 clearMask |= GL_STENCIL_BUFFER_BIT; | 799 clearMask |= GL_STENCIL_BUFFER_BIT; |
| 792 m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); | 800 m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); |
| 793 } | 801 } |
| 794 | 802 |
| 795 clearFramebuffers(clearMask); | 803 clearFramebuffers(clearMask); |
| 796 return true; | 804 return true; |
| 797 } | 805 } |
| 798 | 806 |
| 799 void DrawingBuffer::commit() | 807 void DrawingBuffer::commit() |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 955 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) | 963 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) |
| 956 { | 964 { |
| 957 if (info->imageId) { | 965 if (info->imageId) { |
| 958 m_gl->BindTexture(info->parameters.target, info->textureId); | 966 m_gl->BindTexture(info->parameters.target, info->textureId); |
| 959 m_gl->ReleaseTexImage2DCHROMIUM(info->parameters.target, info->imageId); | 967 m_gl->ReleaseTexImage2DCHROMIUM(info->parameters.target, info->imageId); |
| 960 m_gl->DestroyImageCHROMIUM(info->imageId); | 968 m_gl->DestroyImageCHROMIUM(info->imageId); |
| 961 info->imageId = 0; | 969 info->imageId = 0; |
| 962 } | 970 } |
| 963 } | 971 } |
| 964 | 972 |
| 965 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I ntSize& size) | 973 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I ntSize& size, bool wantAlphaChannel) |
| 966 { | 974 { |
| 967 // TODO(erikchen): Add support for a CHROMIUM_image back buffer whose | 975 // TODO(erikchen): Add support for a CHROMIUM_image back buffer whose |
| 968 // behavior mimics a texture with internal format GL_RGB. | 976 // behavior mimics a texture with internal format GL_RGB. |
| 969 // https://crbug.com/581777. | 977 // https://crbug.com/581777. |
| 970 if (!m_requestedAttributes.alpha) | 978 if (!wantAlphaChannel) |
| 971 return createDefaultTextureAndAllocateMemory(size); | 979 return createDefaultTextureAndAllocateMemory(size, wantAlphaChannel); |
| 972 | 980 |
| 973 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) | 981 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) |
| 974 return createDefaultTextureAndAllocateMemory(size); | 982 return createDefaultTextureAndAllocateMemory(size, wantAlphaChannel); |
| 975 | 983 |
| 976 // First, try to allocate a CHROMIUM_image. This always has the potential to | 984 // First, try to allocate a CHROMIUM_image. This always has the potential to |
| 977 // fail. | 985 // fail. |
| 978 TextureParameters parameters = chromiumImageTextureParameters(); | 986 TextureParameters parameters = chromiumImageTextureParameters(wantAlphaChann el); |
| 979 GLuint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size .height(), parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); | 987 GLuint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size .height(), parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); |
| 980 if (!imageId) | 988 if (!imageId) |
| 981 return createDefaultTextureAndAllocateMemory(size); | 989 return createDefaultTextureAndAllocateMemory(size, wantAlphaChannel); |
| 982 | 990 |
| 983 GLuint textureId = createColorTexture(parameters); | 991 GLuint textureId = createColorTexture(parameters); |
| 984 m_gl->BindTexImage2DCHROMIUM(parameters.target, imageId); | 992 m_gl->BindTexImage2DCHROMIUM(parameters.target, imageId); |
| 985 | 993 |
| 986 TextureInfo info; | 994 TextureInfo info; |
| 987 info.textureId = textureId; | 995 info.textureId = textureId; |
| 988 info.imageId = imageId; | 996 info.imageId = imageId; |
| 989 info.parameters = parameters; | 997 info.parameters = parameters; |
| 990 return info; | 998 return info; |
| 991 } | 999 } |
| 992 | 1000 |
| 993 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory( const IntSize& size) | 1001 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory( const IntSize& size, bool wantAlphaChannel) |
| 994 { | 1002 { |
| 995 TextureParameters parameters = defaultTextureParameters(); | 1003 TextureParameters parameters = defaultTextureParameters(wantAlphaChannel); |
| 996 GLuint textureId = createColorTexture(parameters); | 1004 GLuint textureId = createColorTexture(parameters); |
| 997 texImage2DResourceSafe(parameters.target, 0, parameters.internalColorFormat, size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE); | 1005 texImage2DResourceSafe(parameters.target, 0, parameters.internalColorFormat, size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE); |
| 998 | 1006 |
| 999 DrawingBuffer::TextureInfo info; | 1007 DrawingBuffer::TextureInfo info; |
| 1000 info.textureId = textureId; | 1008 info.textureId = textureId; |
| 1001 info.parameters = parameters; | 1009 info.parameters = parameters; |
| 1002 return info; | 1010 return info; |
| 1003 } | 1011 } |
| 1004 | 1012 |
| 1005 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) | 1013 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) |
| 1006 { | 1014 { |
| 1007 ASSERT(info->textureId); | 1015 ASSERT(info->textureId); |
| 1008 if (info->imageId) { | 1016 if (info->imageId) { |
| 1009 deleteChromiumImageForTexture(info); | 1017 deleteChromiumImageForTexture(info); |
| 1010 info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), s ize.height(), info->parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); | 1018 info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), s ize.height(), info->parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); |
| 1011 if (info->imageId) { | 1019 if (info->imageId) { |
| 1012 m_gl->BindTexture(info->parameters.target, info->textureId); | 1020 m_gl->BindTexture(info->parameters.target, info->textureId); |
| 1013 m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId) ; | 1021 m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId) ; |
| 1014 return; | 1022 return; |
| 1015 } | 1023 } |
| 1016 | 1024 |
| 1017 // If the desired texture target is different, there's no way to fall ba ck | 1025 // If the desired texture target is different, there's no way to fall ba ck |
| 1018 // to a non CHROMIUM_image texture. | 1026 // to a non CHROMIUM_image texture. |
| 1019 if (chromiumImageTextureParameters().target != defaultTextureParameters( ).target) | 1027 bool wantAlphaChannel = false; // Not relevant for the target. |
|
danakj
2016/03/31 20:27:56
It's a bit weird we construct the full texture par
| |
| 1028 if (chromiumImageTextureParameters(wantAlphaChannel).target != defaultTe xtureParameters(wantAlphaChannel).target) | |
| 1020 return; | 1029 return; |
| 1021 } | 1030 } |
| 1022 | 1031 |
| 1023 m_gl->BindTexture(info->parameters.target, info->textureId); | 1032 m_gl->BindTexture(info->parameters.target, info->textureId); |
| 1024 texImage2DResourceSafe(info->parameters.target, 0, info->parameters.internal ColorFormat, size.width(), size.height(), 0, info->parameters.colorFormat, GL_UN SIGNED_BYTE); | 1033 texImage2DResourceSafe(info->parameters.target, 0, info->parameters.internal ColorFormat, size.width(), size.height(), 0, info->parameters.colorFormat, GL_UN SIGNED_BYTE); |
| 1025 } | 1034 } |
| 1026 | 1035 |
| 1027 void DrawingBuffer::attachColorBufferToCurrentFBO() | 1036 void DrawingBuffer::attachColorBufferToCurrentFBO() |
| 1028 { | 1037 { |
| 1029 GLenum target = m_colorBuffer.parameters.target; | 1038 GLenum target = m_colorBuffer.parameters.target; |
| 1030 | 1039 |
| 1031 m_gl->BindTexture(target, m_colorBuffer.textureId); | 1040 m_gl->BindTexture(target, m_colorBuffer.textureId); |
| 1032 | 1041 |
| 1033 if (m_antiAliasingMode == MSAAImplicitResolve) | 1042 if (m_antiAliasingMode == MSAAImplicitResolve) |
| 1034 m_gl->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACH MENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); | 1043 m_gl->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACH MENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); |
| 1035 else | 1044 else |
| 1036 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, m_colorBuffer.textureId, 0); | 1045 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, m_colorBuffer.textureId, 0); |
| 1037 | 1046 |
| 1038 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); | 1047 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); |
| 1039 } | 1048 } |
| 1040 | 1049 |
| 1041 } // namespace blink | 1050 } // namespace blink |
| OLD | NEW |