| 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 = wantAntialiasing |
| 110 || extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_text
ure")) | 110 && (extensionsUtil->supportsExtension("GL_CHROMIUM_framebuffer_multisamp
le") |
| 111 || extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_
texture")) |
| 111 && extensionsUtil->supportsExtension("GL_OES_rgb8_rgba8"); | 112 && extensionsUtil->supportsExtension("GL_OES_rgb8_rgba8"); |
| 112 if (multisampleSupported) { | 113 if (multisampleSupported) { |
| 113 extensionsUtil->ensureExtensionEnabled("GL_OES_rgb8_rgba8"); | 114 extensionsUtil->ensureExtensionEnabled("GL_OES_rgb8_rgba8"); |
| 114 if (extensionsUtil->supportsExtension("GL_CHROMIUM_framebuffer_multisamp
le")) | 115 if (extensionsUtil->supportsExtension("GL_CHROMIUM_framebuffer_multisamp
le")) |
| 115 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_mult
isample"); | 116 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_mult
isample"); |
| 116 else | 117 else |
| 117 extensionsUtil->ensureExtensionEnabled("GL_EXT_multisampled_render_t
o_texture"); | 118 extensionsUtil->ensureExtensionEnabled("GL_EXT_multisampled_render_t
o_texture"); |
| 118 } | 119 } |
| 119 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT
_discard_framebuffer"); | 120 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT
_discard_framebuffer"); |
| 120 if (discardFramebufferSupported) | 121 if (discardFramebufferSupported) |
| 121 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer"); | 122 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer"); |
| 122 | 123 |
| 123 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(std::move(c
ontextProvider), extensionsUtil.release(), multisampleSupported, discardFramebuf
ferSupported, premultipliedAlpha, preserve, requestedAttributes)); | 124 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(std::move(c
ontextProvider), extensionsUtil.release(), discardFramebufferSupported, wantAlph
aChannel, premultipliedAlpha, preserve)); |
| 124 if (!drawingBuffer->initialize(size)) { | 125 if (!drawingBuffer->initialize(size, wantDepthBuffer, wantStencilBuffer, mul
tisampleSupported)) { |
| 125 drawingBuffer->beginDestruction(); | 126 drawingBuffer->beginDestruction(); |
| 126 return PassRefPtr<DrawingBuffer>(); | 127 return PassRefPtr<DrawingBuffer>(); |
| 127 } | 128 } |
| 128 return drawingBuffer.release(); | 129 return drawingBuffer.release(); |
| 129 } | 130 } |
| 130 | 131 |
| 131 void DrawingBuffer::forceNextDrawingBufferCreationToFail() | 132 void DrawingBuffer::forceNextDrawingBufferCreationToFail() |
| 132 { | 133 { |
| 133 shouldFailDrawingBufferCreationForTesting = true; | 134 shouldFailDrawingBufferCreationForTesting = true; |
| 134 } | 135 } |
| 135 | 136 |
| 136 DrawingBuffer::DrawingBuffer(PassOwnPtr<WebGraphicsContext3DProvider> contextPro
vider, PassOwnPtr<Extensions3DUtil> extensionsUtil, bool multisampleExtensionSup
ported, bool discardFramebufferSupported, bool premultipliedAlpha, PreserveDrawi
ngBuffer preserve, WebGraphicsContext3D::Attributes requestedAttributes) | 137 DrawingBuffer::DrawingBuffer( |
| 138 PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, |
| 139 PassOwnPtr<Extensions3DUtil> extensionsUtil, |
| 140 bool discardFramebufferSupported, |
| 141 bool wantAlphaChannel, |
| 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) |
| 156 , m_wantAlphaChannel(wantAlphaChannel) |
| 151 , m_premultipliedAlpha(premultipliedAlpha) | 157 , m_premultipliedAlpha(premultipliedAlpha) |
| 158 , m_hasImplicitStencilBuffer(false) |
| 152 , m_fbo(0) | 159 , m_fbo(0) |
| 153 , m_depthStencilBuffer(0) | 160 , m_depthStencilBuffer(0) |
| 154 , m_multisampleFBO(0) | 161 , m_multisampleFBO(0) |
| 155 , m_multisampleColorBuffer(0) | 162 , m_multisampleColorBuffer(0) |
| 156 , m_contentsChanged(true) | 163 , m_contentsChanged(true) |
| 157 , m_contentsChangeCommitted(false) | 164 , m_contentsChangeCommitted(false) |
| 158 , m_bufferClearNeeded(false) | 165 , m_bufferClearNeeded(false) |
| 159 , m_antiAliasingMode(None) | 166 , m_antiAliasingMode(None) |
| 160 , m_maxTextureSize(0) | 167 , m_maxTextureSize(0) |
| 161 , m_sampleCount(0) | 168 , m_sampleCount(0) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 (*m_newMailboxCallback)(); | 268 (*m_newMailboxCallback)(); |
| 262 | 269 |
| 263 // Resolve the multisampled buffer into m_colorBuffer texture. | 270 // Resolve the multisampled buffer into m_colorBuffer texture. |
| 264 if (m_antiAliasingMode != None) | 271 if (m_antiAliasingMode != None) |
| 265 commit(); | 272 commit(); |
| 266 | 273 |
| 267 if (bitmap) { | 274 if (bitmap) { |
| 268 bitmap->setSize(size()); | 275 bitmap->setSize(size()); |
| 269 | 276 |
| 270 unsigned char* pixels = bitmap->pixels(); | 277 unsigned char* pixels = bitmap->pixels(); |
| 271 bool needPremultiply = m_actualAttributes.alpha && !m_premultipliedAlpha
; | 278 bool needPremultiply = m_wantAlphaChannel && !m_premultipliedAlpha; |
| 272 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; | 279 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; |
| 273 if (pixels) | 280 if (pixels) |
| 274 readBackFramebuffer(pixels, size().width(), size().height(), Readbac
kSkia, op); | 281 readBackFramebuffer(pixels, size().width(), size().height(), Readbac
kSkia, op); |
| 275 } | 282 } |
| 276 | 283 |
| 277 // We must restore the texture binding since creating new textures, | 284 // We must restore the texture binding since creating new textures, |
| 278 // consuming and producing mailboxes changes it. | 285 // consuming and producing mailboxes changes it. |
| 279 ScopedTextureUnit0BindingRestorer restorer(m_gl, m_activeTextureUnit, m_text
ure2DBinding); | 286 ScopedTextureUnit0BindingRestorer restorer(m_gl, m_activeTextureUnit, m_text
ure2DBinding); |
| 280 | 287 |
| 281 // First try to recycle an old buffer. | 288 // First try to recycle an old buffer. |
| 282 RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); | 289 RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); |
| 283 | 290 |
| 284 // No buffer available to recycle, create a new one. | 291 // No buffer available to recycle, create a new one. |
| 285 if (!frontColorBufferMailbox) { | 292 if (!frontColorBufferMailbox) |
| 286 frontColorBufferMailbox = createNewMailbox(createTextureAndAllocateMemor
y(m_size)); | 293 frontColorBufferMailbox = createNewMailbox(createTextureAndAllocateMemor
y(m_size)); |
| 287 } | |
| 288 | 294 |
| 289 if (m_preserveDrawingBuffer == Discard) { | 295 if (m_preserveDrawingBuffer == Discard) { |
| 290 std::swap(frontColorBufferMailbox->textureInfo, m_colorBuffer); | 296 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 | 297 // 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. | 298 // 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 | 299 // 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. | 300 // it after attaching the new back buffer here. |
| 295 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 301 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 296 attachColorBufferToCurrentFBO(); | 302 attachColorBufferToCurrentFBO(); |
| 297 | 303 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 return parameters; | 366 return parameters; |
| 361 #else | 367 #else |
| 362 return defaultTextureParameters(); | 368 return defaultTextureParameters(); |
| 363 #endif | 369 #endif |
| 364 } | 370 } |
| 365 | 371 |
| 366 DrawingBuffer::TextureParameters DrawingBuffer::defaultTextureParameters() | 372 DrawingBuffer::TextureParameters DrawingBuffer::defaultTextureParameters() |
| 367 { | 373 { |
| 368 TextureParameters parameters; | 374 TextureParameters parameters; |
| 369 parameters.target = GL_TEXTURE_2D; | 375 parameters.target = GL_TEXTURE_2D; |
| 370 if (m_requestedAttributes.alpha) { | 376 if (m_wantAlphaChannel) { |
| 371 parameters.internalColorFormat = GL_RGBA; | 377 parameters.internalColorFormat = GL_RGBA; |
| 372 parameters.colorFormat = GL_RGBA; | 378 parameters.colorFormat = GL_RGBA; |
| 373 parameters.internalRenderbufferFormat = GL_RGBA8_OES; | 379 parameters.internalRenderbufferFormat = GL_RGBA8_OES; |
| 374 } else { | 380 } else { |
| 375 parameters.internalColorFormat = GL_RGB; | 381 parameters.internalColorFormat = GL_RGB; |
| 376 parameters.colorFormat = GL_RGB; | 382 parameters.colorFormat = GL_RGB; |
| 377 parameters.internalRenderbufferFormat = GL_RGB8_OES; | 383 parameters.internalRenderbufferFormat = GL_RGB8_OES; |
| 378 } | 384 } |
| 379 return parameters; | 385 return parameters; |
| 380 } | 386 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 deleteChromiumImageForTexture(&m_textureMailboxes[i]->textureInfo); | 448 deleteChromiumImageForTexture(&m_textureMailboxes[i]->textureInfo); |
| 443 | 449 |
| 444 m_gl->DeleteTextures(1, &m_textureMailboxes[i]->textureInfo.textureI
d); | 450 m_gl->DeleteTextures(1, &m_textureMailboxes[i]->textureInfo.textureI
d); |
| 445 m_textureMailboxes.remove(i); | 451 m_textureMailboxes.remove(i); |
| 446 return; | 452 return; |
| 447 } | 453 } |
| 448 } | 454 } |
| 449 ASSERT_NOT_REACHED(); | 455 ASSERT_NOT_REACHED(); |
| 450 } | 456 } |
| 451 | 457 |
| 452 bool DrawingBuffer::initialize(const IntSize& size) | 458 bool DrawingBuffer::initialize(const IntSize& size, bool wantDepthBuffer, bool w
antStencilBuffer, bool useMultisampling) |
| 453 { | 459 { |
| 454 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { | 460 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { |
| 455 // Need to try to restore the context again later. | 461 // Need to try to restore the context again later. |
| 456 return false; | 462 return false; |
| 457 } | 463 } |
| 458 | 464 |
| 459 m_gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); | 465 m_gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); |
| 460 | 466 |
| 461 int maxSampleCount = 0; | 467 int maxSampleCount = 0; |
| 462 m_antiAliasingMode = None; | 468 m_antiAliasingMode = None; |
| 463 if (m_requestedAttributes.antialias && m_multisampleExtensionSupported) { | 469 if (useMultisampling) { |
| 464 m_gl->GetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); | 470 m_gl->GetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); |
| 465 m_antiAliasingMode = MSAAExplicitResolve; | 471 m_antiAliasingMode = MSAAExplicitResolve; |
| 466 if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t
exture")) { | 472 if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t
exture")) { |
| 467 m_antiAliasingMode = MSAAImplicitResolve; | 473 m_antiAliasingMode = MSAAImplicitResolve; |
| 468 } else if (m_extensionsUtil->supportsExtension("GL_CHROMIUM_screen_space
_antialiasing")) { | 474 } else if (m_extensionsUtil->supportsExtension("GL_CHROMIUM_screen_space
_antialiasing")) { |
| 469 m_antiAliasingMode = ScreenSpaceAntialiasing; | 475 m_antiAliasingMode = ScreenSpaceAntialiasing; |
| 470 } | 476 } |
| 471 } | 477 } |
| 472 m_sampleCount = std::min(4, maxSampleCount); | 478 m_sampleCount = std::min(4, maxSampleCount); |
| 473 | 479 |
| 474 m_gl->GenFramebuffers(1, &m_fbo); | 480 m_gl->GenFramebuffers(1, &m_fbo); |
| 475 | 481 |
| 476 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 482 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 477 createSecondaryBuffers(); | 483 createSecondaryBuffers(); |
| 478 // We first try to initialize everything with the requested attributes. | 484 if (!reset(size, wantDepthBuffer || wantStencilBuffer)) |
| 479 if (!reset(size)) | |
| 480 return false; | 485 return false; |
| 481 // If that succeeds, we then see what we actually got and update our actual
attributes to reflect that. | 486 |
| 482 m_actualAttributes = m_requestedAttributes; | 487 if (m_depthStencilBuffer) { |
| 483 if (m_requestedAttributes.alpha) { | 488 DCHECK(wantDepthBuffer || wantStencilBuffer); |
| 484 GLint alphaBits = 0; | 489 m_hasImplicitStencilBuffer = !wantStencilBuffer; |
| 485 m_gl->GetIntegerv(GL_ALPHA_BITS, &alphaBits); | |
| 486 m_actualAttributes.alpha = alphaBits > 0; | |
| 487 } | 490 } |
| 488 if (m_requestedAttributes.depth) { | |
| 489 GLint depthBits = 0; | |
| 490 m_gl->GetIntegerv(GL_DEPTH_BITS, &depthBits); | |
| 491 m_actualAttributes.depth = depthBits > 0; | |
| 492 } | |
| 493 if (m_requestedAttributes.stencil) { | |
| 494 GLint stencilBits = 0; | |
| 495 m_gl->GetIntegerv(GL_STENCIL_BITS, &stencilBits); | |
| 496 m_actualAttributes.stencil = stencilBits > 0; | |
| 497 } | |
| 498 m_actualAttributes.antialias = multisample(); | |
| 499 | 491 |
| 500 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { | 492 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 | 493 // 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; | 494 return false; |
| 503 } | 495 } |
| 504 | 496 |
| 505 return true; | 497 return true; |
| 506 } | 498 } |
| 507 | 499 |
| 508 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, gpu::gl
es2::GLES2Interface* gl, GLuint texture, GLenum internalFormat, | 500 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); | 530 m_gl->GenSyncTokenCHROMIUM(fenceSync, mailbox.syncToken); |
| 539 mailbox.validSyncToken = true; | 531 mailbox.validSyncToken = true; |
| 540 } | 532 } |
| 541 | 533 |
| 542 if (mailbox.validSyncToken) | 534 if (mailbox.validSyncToken) |
| 543 gl->WaitSyncTokenCHROMIUM(mailbox.syncToken); | 535 gl->WaitSyncTokenCHROMIUM(mailbox.syncToken); |
| 544 GLuint sourceTexture = gl->CreateAndConsumeTextureCHROMIUM(target, mailbox.n
ame); | 536 GLuint sourceTexture = gl->CreateAndConsumeTextureCHROMIUM(target, mailbox.n
ame); |
| 545 | 537 |
| 546 GLboolean unpackPremultiplyAlphaNeeded = GL_FALSE; | 538 GLboolean unpackPremultiplyAlphaNeeded = GL_FALSE; |
| 547 GLboolean unpackUnpremultiplyAlphaNeeded = GL_FALSE; | 539 GLboolean unpackUnpremultiplyAlphaNeeded = GL_FALSE; |
| 548 if (m_actualAttributes.alpha && m_premultipliedAlpha && !premultiplyAlpha) | 540 if (m_wantAlphaChannel && m_premultipliedAlpha && !premultiplyAlpha) |
| 549 unpackUnpremultiplyAlphaNeeded = GL_TRUE; | 541 unpackUnpremultiplyAlphaNeeded = GL_TRUE; |
| 550 else if (m_actualAttributes.alpha && !m_premultipliedAlpha && premultiplyAlp
ha) | 542 else if (m_wantAlphaChannel && !m_premultipliedAlpha && premultiplyAlpha) |
| 551 unpackPremultiplyAlphaNeeded = GL_TRUE; | 543 unpackPremultiplyAlphaNeeded = GL_TRUE; |
| 552 | 544 |
| 553 gl->CopyTextureCHROMIUM(sourceTexture, texture, internalFormat, destType, fl
ipY, unpackPremultiplyAlphaNeeded, unpackUnpremultiplyAlphaNeeded); | 545 gl->CopyTextureCHROMIUM(sourceTexture, texture, internalFormat, destType, fl
ipY, unpackPremultiplyAlphaNeeded, unpackUnpremultiplyAlphaNeeded); |
| 554 | 546 |
| 555 gl->DeleteTextures(1, &sourceTexture); | 547 gl->DeleteTextures(1, &sourceTexture); |
| 556 | 548 |
| 557 const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); | 549 const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); |
| 558 | 550 |
| 559 gl->Flush(); | 551 gl->Flush(); |
| 560 GLbyte syncToken[24]; | 552 GLbyte syncToken[24]; |
| 561 gl->GenSyncTokenCHROMIUM(fenceSync, syncToken); | 553 gl->GenSyncTokenCHROMIUM(fenceSync, syncToken); |
| 562 m_gl->WaitSyncTokenCHROMIUM(syncToken); | 554 m_gl->WaitSyncTokenCHROMIUM(syncToken); |
| 563 | 555 |
| 564 return true; | 556 return true; |
| 565 } | 557 } |
| 566 | 558 |
| 567 GLuint DrawingBuffer::framebuffer() const | 559 GLuint DrawingBuffer::framebuffer() const |
| 568 { | 560 { |
| 569 return m_fbo; | 561 return m_fbo; |
| 570 } | 562 } |
| 571 | 563 |
| 572 WebLayer* DrawingBuffer::platformLayer() | 564 WebLayer* DrawingBuffer::platformLayer() |
| 573 { | 565 { |
| 574 if (!m_layer) { | 566 if (!m_layer) { |
| 575 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExter
nalTextureLayer(this)); | 567 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExter
nalTextureLayer(this)); |
| 576 | 568 |
| 577 m_layer->setOpaque(!m_actualAttributes.alpha); | 569 m_layer->setOpaque(!m_wantAlphaChannel); |
| 578 m_layer->setBlendBackgroundColor(m_actualAttributes.alpha); | 570 m_layer->setBlendBackgroundColor(m_wantAlphaChannel); |
| 579 m_layer->setPremultipliedAlpha(m_premultipliedAlpha); | 571 m_layer->setPremultipliedAlpha(m_premultipliedAlpha); |
| 580 m_layer->setNearestNeighbor(m_filterQuality == kNone_SkFilterQuality); | 572 m_layer->setNearestNeighbor(m_filterQuality == kNone_SkFilterQuality); |
| 581 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 573 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
| 582 } | 574 } |
| 583 | 575 |
| 584 return m_layer->layer(); | 576 return m_layer->layer(); |
| 585 } | 577 } |
| 586 | 578 |
| 587 void DrawingBuffer::clearPlatformLayer() | 579 void DrawingBuffer::clearPlatformLayer() |
| 588 { | 580 { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 void DrawingBuffer::createSecondaryBuffers() | 639 void DrawingBuffer::createSecondaryBuffers() |
| 648 { | 640 { |
| 649 // create a multisample FBO | 641 // create a multisample FBO |
| 650 if (m_antiAliasingMode == MSAAExplicitResolve) { | 642 if (m_antiAliasingMode == MSAAExplicitResolve) { |
| 651 m_gl->GenFramebuffers(1, &m_multisampleFBO); | 643 m_gl->GenFramebuffers(1, &m_multisampleFBO); |
| 652 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); | 644 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); |
| 653 m_gl->GenRenderbuffers(1, &m_multisampleColorBuffer); | 645 m_gl->GenRenderbuffers(1, &m_multisampleColorBuffer); |
| 654 } | 646 } |
| 655 } | 647 } |
| 656 | 648 |
| 657 bool DrawingBuffer::resizeFramebuffer(const IntSize& size) | 649 bool DrawingBuffer::resizeFramebuffer(const IntSize& size, bool wantDepthOrStenc
ilBuffer) |
| 658 { | 650 { |
| 659 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 651 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 660 if (m_antiAliasingMode != MSAAExplicitResolve) | 652 if (m_antiAliasingMode != MSAAExplicitResolve && wantDepthOrStencilBuffer) |
| 661 resizeDepthStencil(size); | 653 resizeDepthStencil(size); |
| 662 if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) | 654 if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) |
| 663 return false; | 655 return false; |
| 664 | 656 |
| 665 return true; | 657 return true; |
| 666 } | 658 } |
| 667 | 659 |
| 668 bool DrawingBuffer::resizeMultisampleFramebuffer(const IntSize& size) | 660 bool DrawingBuffer::resizeMultisampleFramebuffer(const IntSize& size, bool wantD
epthOrStencilBuffer) |
| 669 { | 661 { |
| 670 if (m_antiAliasingMode == MSAAExplicitResolve) { | 662 if (m_antiAliasingMode == MSAAExplicitResolve) { |
| 671 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); | 663 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); |
| 672 | 664 |
| 673 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_multisampleColorBuffer); | 665 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()); | 666 m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCo
unt, m_colorBuffer.parameters.internalRenderbufferFormat, size.width(), size.hei
ght()); |
| 675 | 667 |
| 676 if (m_gl->GetError() == GL_OUT_OF_MEMORY) | 668 if (m_gl->GetError() == GL_OUT_OF_MEMORY) |
| 677 return false; | 669 return false; |
| 678 | 670 |
| 679 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_R
ENDERBUFFER, m_multisampleColorBuffer); | 671 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_R
ENDERBUFFER, m_multisampleColorBuffer); |
| 680 resizeDepthStencil(size); | 672 if (wantDepthOrStencilBuffer) |
| 673 resizeDepthStencil(size); |
| 681 if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPL
ETE) | 674 if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPL
ETE) |
| 682 return false; | 675 return false; |
| 683 } | 676 } |
| 684 | 677 |
| 685 return true; | 678 return true; |
| 686 } | 679 } |
| 687 | 680 |
| 688 void DrawingBuffer::resizeDepthStencil(const IntSize& size) | 681 void DrawingBuffer::resizeDepthStencil(const IntSize& size) |
| 689 { | 682 { |
| 690 if (!m_requestedAttributes.depth && !m_requestedAttributes.stencil) | |
| 691 return; | |
| 692 | |
| 693 if (!m_depthStencilBuffer) | 683 if (!m_depthStencilBuffer) |
| 694 m_gl->GenRenderbuffers(1, &m_depthStencilBuffer); | 684 m_gl->GenRenderbuffers(1, &m_depthStencilBuffer); |
| 695 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer); | 685 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer); |
| 696 if (m_antiAliasingMode == MSAAImplicitResolve) | 686 if (m_antiAliasingMode == MSAAImplicitResolve) |
| 697 m_gl->RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, m_sampleCount,
GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); | 687 m_gl->RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, m_sampleCount,
GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); |
| 698 else if (m_antiAliasingMode == MSAAExplicitResolve) | 688 else if (m_antiAliasingMode == MSAAExplicitResolve) |
| 699 m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCo
unt, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); | 689 m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCo
unt, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); |
| 700 else | 690 else |
| 701 m_gl->RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, size
.width(), size.height()); | 691 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); | 692 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, G
L_RENDERBUFFER, m_depthStencilBuffer); |
| 703 m_gl->BindRenderbuffer(GL_RENDERBUFFER, 0); | 693 m_gl->BindRenderbuffer(GL_RENDERBUFFER, 0); |
| 704 } | 694 } |
| 705 | 695 |
| 706 | 696 |
| 707 | 697 |
| 708 void DrawingBuffer::clearFramebuffers(GLbitfield clearMask) | 698 void DrawingBuffer::clearFramebuffers(GLbitfield clearMask) |
| 709 { | 699 { |
| 710 // We will clear the multisample FBO, but we also need to clear the non-mult
isampled buffer. | 700 // We will clear the multisample FBO, but we also need to clear the non-mult
isampled buffer. |
| 711 if (m_multisampleFBO) { | 701 if (m_multisampleFBO) { |
| 712 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 702 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 713 m_gl->Clear(GL_COLOR_BUFFER_BIT); | 703 m_gl->Clear(GL_COLOR_BUFFER_BIT); |
| 714 } | 704 } |
| 715 | 705 |
| 716 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleFBO :
m_fbo); | 706 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleFBO :
m_fbo); |
| 717 m_gl->Clear(clearMask); | 707 m_gl->Clear(clearMask); |
| 718 } | 708 } |
| 719 | 709 |
| 720 bool DrawingBuffer::hasImplicitStencilBuffer() const | |
| 721 { | |
| 722 return m_depthStencilBuffer && m_requestedAttributes.depth && !m_requestedAt
tributes.stencil; | |
| 723 } | |
| 724 | |
| 725 void DrawingBuffer::setSize(const IntSize& size) | 710 void DrawingBuffer::setSize(const IntSize& size) |
| 726 { | 711 { |
| 727 if (m_size == size) | 712 if (m_size == size) |
| 728 return; | 713 return; |
| 729 | 714 |
| 730 m_size = size; | 715 m_size = size; |
| 731 } | 716 } |
| 732 | 717 |
| 733 IntSize DrawingBuffer::adjustSize(const IntSize& desiredSize, const IntSize& cur
Size, int maxTextureSize) | 718 IntSize DrawingBuffer::adjustSize(const IntSize& desiredSize, const IntSize& cur
Size, int maxTextureSize) |
| 734 { | 719 { |
| 735 IntSize adjustedSize = desiredSize; | 720 IntSize adjustedSize = desiredSize; |
| 736 | 721 |
| 737 // Clamp if the desired size is greater than the maximum texture size for th
e device. | 722 // Clamp if the desired size is greater than the maximum texture size for th
e device. |
| 738 if (adjustedSize.height() > maxTextureSize) | 723 if (adjustedSize.height() > maxTextureSize) |
| 739 adjustedSize.setHeight(maxTextureSize); | 724 adjustedSize.setHeight(maxTextureSize); |
| 740 | 725 |
| 741 if (adjustedSize.width() > maxTextureSize) | 726 if (adjustedSize.width() > maxTextureSize) |
| 742 adjustedSize.setWidth(maxTextureSize); | 727 adjustedSize.setWidth(maxTextureSize); |
| 743 | 728 |
| 744 return adjustedSize; | 729 return adjustedSize; |
| 745 } | 730 } |
| 746 | 731 |
| 747 bool DrawingBuffer::reset(const IntSize& newSize) | 732 bool DrawingBuffer::reset(const IntSize& newSize, bool wantDepthOrStencilBuffer) |
| 748 { | 733 { |
| 749 ASSERT(!newSize.isEmpty()); | 734 ASSERT(!newSize.isEmpty()); |
| 750 IntSize adjustedSize = adjustSize(newSize, m_size, m_maxTextureSize); | 735 IntSize adjustedSize = adjustSize(newSize, m_size, m_maxTextureSize); |
| 751 if (adjustedSize.isEmpty()) | 736 if (adjustedSize.isEmpty()) |
| 752 return false; | 737 return false; |
| 753 | 738 |
| 754 if (adjustedSize != m_size) { | 739 if (adjustedSize != m_size) { |
| 755 do { | 740 do { |
| 756 if (m_colorBuffer.textureId) { | 741 if (m_colorBuffer.textureId) { |
| 757 resizeTextureMemory(&m_colorBuffer, adjustedSize); | 742 resizeTextureMemory(&m_colorBuffer, adjustedSize); |
| 758 } else { | 743 } else { |
| 759 m_colorBuffer = createTextureAndAllocateMemory(adjustedSize); | 744 m_colorBuffer = createTextureAndAllocateMemory(adjustedSize); |
| 760 } | 745 } |
| 761 | 746 |
| 762 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 747 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 763 attachColorBufferToCurrentFBO(); | 748 attachColorBufferToCurrentFBO(); |
| 764 | 749 |
| 765 // resize multisample FBO | 750 // resize multisample FBO |
| 766 if (!resizeMultisampleFramebuffer(adjustedSize) || !resizeFramebuffe
r(adjustedSize)) { | 751 if (!resizeMultisampleFramebuffer(adjustedSize, wantDepthOrStencilBu
ffer) |
| 752 || !resizeFramebuffer(adjustedSize, wantDepthOrStencilBuffer)) { |
| 767 adjustedSize.scale(s_resourceAdjustedRatio); | 753 adjustedSize.scale(s_resourceAdjustedRatio); |
| 768 continue; | 754 continue; |
| 769 } | 755 } |
| 770 break; | 756 break; |
| 771 } while (!adjustedSize.isEmpty()); | 757 } while (!adjustedSize.isEmpty()); |
| 772 | 758 |
| 773 setSize(adjustedSize); | 759 setSize(adjustedSize); |
| 774 | 760 |
| 775 if (adjustedSize.isEmpty()) | 761 if (adjustedSize.isEmpty()) |
| 776 return false; | 762 return false; |
| 777 } | 763 } |
| 778 | 764 |
| 779 m_gl->Disable(GL_SCISSOR_TEST); | 765 m_gl->Disable(GL_SCISSOR_TEST); |
| 780 m_gl->ClearColor(0, 0, 0, 0); | 766 m_gl->ClearColor(0, 0, 0, 0); |
| 781 m_gl->ColorMask(true, true, true, true); | 767 m_gl->ColorMask(true, true, true, true); |
| 782 | 768 |
| 783 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; | 769 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; |
| 784 if (m_actualAttributes.depth) { | 770 if (!!m_depthStencilBuffer) { |
| 785 m_gl->ClearDepthf(1.0f); | 771 m_gl->ClearDepthf(1.0f); |
| 786 clearMask |= GL_DEPTH_BUFFER_BIT; | 772 clearMask |= GL_DEPTH_BUFFER_BIT; |
| 787 m_gl->DepthMask(true); | 773 m_gl->DepthMask(true); |
| 788 } | 774 } |
| 789 if (m_actualAttributes.stencil) { | 775 if (!!m_depthStencilBuffer) { |
| 790 m_gl->ClearStencil(0); | 776 m_gl->ClearStencil(0); |
| 791 clearMask |= GL_STENCIL_BUFFER_BIT; | 777 clearMask |= GL_STENCIL_BUFFER_BIT; |
| 792 m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); | 778 m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); |
| 793 } | 779 } |
| 794 | 780 |
| 795 clearFramebuffers(clearMask); | 781 clearFramebuffers(clearMask); |
| 796 return true; | 782 return true; |
| 797 } | 783 } |
| 798 | 784 |
| 799 void DrawingBuffer::commit() | 785 void DrawingBuffer::commit() |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 m_gl->DestroyImageCHROMIUM(info->imageId); | 946 m_gl->DestroyImageCHROMIUM(info->imageId); |
| 961 info->imageId = 0; | 947 info->imageId = 0; |
| 962 } | 948 } |
| 963 } | 949 } |
| 964 | 950 |
| 965 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I
ntSize& size) | 951 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I
ntSize& size) |
| 966 { | 952 { |
| 967 // TODO(erikchen): Add support for a CHROMIUM_image back buffer whose | 953 // TODO(erikchen): Add support for a CHROMIUM_image back buffer whose |
| 968 // behavior mimics a texture with internal format GL_RGB. | 954 // behavior mimics a texture with internal format GL_RGB. |
| 969 // https://crbug.com/581777. | 955 // https://crbug.com/581777. |
| 970 if (!m_requestedAttributes.alpha) | 956 if (!m_wantAlphaChannel) |
| 971 return createDefaultTextureAndAllocateMemory(size); | 957 return createDefaultTextureAndAllocateMemory(size); |
| 972 | 958 |
| 973 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) | 959 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) |
| 974 return createDefaultTextureAndAllocateMemory(size); | 960 return createDefaultTextureAndAllocateMemory(size); |
| 975 | 961 |
| 976 // First, try to allocate a CHROMIUM_image. This always has the potential to | 962 // First, try to allocate a CHROMIUM_image. This always has the potential to |
| 977 // fail. | 963 // fail. |
| 978 TextureParameters parameters = chromiumImageTextureParameters(); | 964 TextureParameters parameters = chromiumImageTextureParameters(); |
| 979 GLuint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size
.height(), parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); | 965 GLuint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size
.height(), parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); |
| 980 if (!imageId) | 966 if (!imageId) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 | 1018 |
| 1033 if (m_antiAliasingMode == MSAAImplicitResolve) | 1019 if (m_antiAliasingMode == MSAAImplicitResolve) |
| 1034 m_gl->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACH
MENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); | 1020 m_gl->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACH
MENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); |
| 1035 else | 1021 else |
| 1036 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
m_colorBuffer.textureId, 0); | 1022 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
m_colorBuffer.textureId, 0); |
| 1037 | 1023 |
| 1038 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); | 1024 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); |
| 1039 } | 1025 } |
| 1040 | 1026 |
| 1041 } // namespace blink | 1027 } // namespace blink |
| OLD | NEW |