| 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 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include "platform/graphics/gpu/DrawingBuffer.h" | 33 #include "platform/graphics/gpu/DrawingBuffer.h" |
| 34 | 34 |
| 35 #include "RuntimeEnabledFeatures.h" |
| 35 #include <algorithm> | 36 #include <algorithm> |
| 36 #include "platform/TraceEvent.h" | 37 #include "platform/TraceEvent.h" |
| 37 #include "platform/graphics/GraphicsLayer.h" | 38 #include "platform/graphics/GraphicsLayer.h" |
| 38 #include "platform/graphics/gpu/Extensions3DUtil.h" | 39 #include "platform/graphics/gpu/Extensions3DUtil.h" |
| 39 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
| 40 #include "public/platform/WebCompositorSupport.h" | 41 #include "public/platform/WebCompositorSupport.h" |
| 41 #include "public/platform/WebExternalBitmap.h" | 42 #include "public/platform/WebExternalBitmap.h" |
| 42 #include "public/platform/WebExternalTextureLayer.h" | 43 #include "public/platform/WebExternalTextureLayer.h" |
| 43 #include "public/platform/WebGraphicsContext3D.h" | 44 #include "public/platform/WebGraphicsContext3D.h" |
| 44 #include "public/platform/WebGraphicsContext3DProvider.h" | 45 #include "public/platform/WebGraphicsContext3DProvider.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 , m_scissorEnabled(false) | 123 , m_scissorEnabled(false) |
| 123 , m_texture2DBinding(0) | 124 , m_texture2DBinding(0) |
| 124 , m_framebufferBinding(0) | 125 , m_framebufferBinding(0) |
| 125 , m_activeTextureUnit(GL_TEXTURE0) | 126 , m_activeTextureUnit(GL_TEXTURE0) |
| 126 , m_context(context) | 127 , m_context(context) |
| 127 , m_extensionsUtil(extensionsUtil) | 128 , m_extensionsUtil(extensionsUtil) |
| 128 , m_size(-1, -1) | 129 , m_size(-1, -1) |
| 129 , m_multisampleExtensionSupported(multisampleExtensionSupported) | 130 , m_multisampleExtensionSupported(multisampleExtensionSupported) |
| 130 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte
d) | 131 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte
d) |
| 131 , m_fbo(0) | 132 , m_fbo(0) |
| 132 , m_colorBuffer(0) | |
| 133 , m_frontColorBuffer(0) | |
| 134 , m_depthStencilBuffer(0) | 133 , m_depthStencilBuffer(0) |
| 135 , m_depthBuffer(0) | 134 , m_depthBuffer(0) |
| 136 , m_stencilBuffer(0) | 135 , m_stencilBuffer(0) |
| 137 , m_multisampleFBO(0) | 136 , m_multisampleFBO(0) |
| 138 , m_multisampleColorBuffer(0) | 137 , m_multisampleColorBuffer(0) |
| 139 , m_contentsChanged(true) | 138 , m_contentsChanged(true) |
| 140 , m_contentsChangeCommitted(false) | 139 , m_contentsChangeCommitted(false) |
| 141 , m_layerComposited(false) | 140 , m_layerComposited(false) |
| 142 , m_multisampleMode(None) | 141 , m_multisampleMode(None) |
| 143 , m_internalColorFormat(0) | 142 , m_internalColorFormat(0) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 220 |
| 222 // We must restore the texture binding since creating new textures, | 221 // We must restore the texture binding since creating new textures, |
| 223 // consuming and producing mailboxes changes it. | 222 // consuming and producing mailboxes changes it. |
| 224 ScopedTextureUnit0BindingRestorer restorer(m_context.get(), m_activeTextureU
nit, m_texture2DBinding); | 223 ScopedTextureUnit0BindingRestorer restorer(m_context.get(), m_activeTextureU
nit, m_texture2DBinding); |
| 225 | 224 |
| 226 // First try to recycle an old buffer. | 225 // First try to recycle an old buffer. |
| 227 RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); | 226 RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); |
| 228 | 227 |
| 229 // No buffer available to recycle, create a new one. | 228 // No buffer available to recycle, create a new one. |
| 230 if (!frontColorBufferMailbox) { | 229 if (!frontColorBufferMailbox) { |
| 231 unsigned newColorBuffer = createColorTexture(m_size); | 230 TextureInfo newTexture; |
| 231 newTexture.textureId = createColorTexture(); |
| 232 allocateTextureMemory(&newTexture, m_size); |
| 232 // Bad things happened, abandon ship. | 233 // Bad things happened, abandon ship. |
| 233 if (!newColorBuffer) | 234 if (!newTexture.textureId) |
| 234 return false; | 235 return false; |
| 235 | 236 |
| 236 frontColorBufferMailbox = createNewMailbox(newColorBuffer); | 237 frontColorBufferMailbox = createNewMailbox(newTexture); |
| 237 } | 238 } |
| 238 | 239 |
| 239 if (m_preserveDrawingBuffer == Discard) { | 240 if (m_preserveDrawingBuffer == Discard) { |
| 240 swap(frontColorBufferMailbox->textureId, m_colorBuffer); | 241 swap(frontColorBufferMailbox->textureInfo, m_colorBuffer); |
| 241 // It appears safe to overwrite the context's framebuffer binding in the
Discard case since there will always be a | 242 // It appears safe to overwrite the context's framebuffer binding in the
Discard case since there will always be a |
| 242 // WebGLRenderingContext::clearIfComposited() call made before the next
draw call which restores the framebuffer binding. | 243 // WebGLRenderingContext::clearIfComposited() call made before the next
draw call which restores the framebuffer binding. |
| 243 // If this stops being true at some point, we should track the current f
ramebuffer binding in the DrawingBuffer and restore | 244 // If this stops being true at some point, we should track the current f
ramebuffer binding in the DrawingBuffer and restore |
| 244 // it after attaching the new back buffer here. | 245 // it after attaching the new back buffer here. |
| 245 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 246 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 246 if (m_multisampleMode == ImplicitResolve) | 247 if (m_multisampleMode == ImplicitResolve) |
| 247 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COL
OR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0, m_sampleCount); | 248 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COL
OR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer.textureId, 0, m_sampleCount); |
| 248 else | 249 else |
| 249 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D, m_colorBuffer, 0); | 250 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D, m_colorBuffer.textureId, 0); |
| 250 } else { | 251 } else { |
| 251 m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_colorBuffer, frontColorB
ufferMailbox->textureId, 0, GL_RGBA, GL_UNSIGNED_BYTE); | 252 m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_colorBuffer.textureId, f
rontColorBufferMailbox->textureInfo.textureId, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
| 252 } | 253 } |
| 253 | 254 |
| 254 if (m_multisampleMode != None && !m_framebufferBinding) | 255 if (m_multisampleMode != None && !m_framebufferBinding) |
| 255 bind(); | 256 bind(); |
| 256 else | 257 else |
| 257 restoreFramebufferBinding(); | 258 restoreFramebufferBinding(); |
| 258 | 259 |
| 259 m_contentsChanged = false; | 260 m_contentsChanged = false; |
| 260 | 261 |
| 261 m_context->bindTexture(GL_TEXTURE_2D, frontColorBufferMailbox->textureId); | 262 m_context->bindTexture(GL_TEXTURE_2D, frontColorBufferMailbox->textureInfo.t
extureId); |
| 262 m_context->produceTextureCHROMIUM(GL_TEXTURE_2D, frontColorBufferMailbox->ma
ilbox.name); | 263 m_context->produceTextureCHROMIUM(GL_TEXTURE_2D, frontColorBufferMailbox->ma
ilbox.name); |
| 263 m_context->flush(); | 264 m_context->flush(); |
| 264 frontColorBufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); | 265 frontColorBufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); |
| 266 frontColorBufferMailbox->mailbox.allowOverlay = frontColorBufferMailbox->tex
tureInfo.imageId != 0; |
| 265 markLayerComposited(); | 267 markLayerComposited(); |
| 266 | 268 |
| 267 // set m_parentDrawingBuffer to make sure 'this' stays alive as long as it h
as live mailboxes | 269 // set m_parentDrawingBuffer to make sure 'this' stays alive as long as it h
as live mailboxes |
| 268 ASSERT(!frontColorBufferMailbox->m_parentDrawingBuffer); | 270 ASSERT(!frontColorBufferMailbox->m_parentDrawingBuffer); |
| 269 frontColorBufferMailbox->m_parentDrawingBuffer = this; | 271 frontColorBufferMailbox->m_parentDrawingBuffer = this; |
| 270 *outMailbox = frontColorBufferMailbox->mailbox; | 272 *outMailbox = frontColorBufferMailbox->mailbox; |
| 271 m_frontColorBuffer = frontColorBufferMailbox->textureId; | 273 m_frontColorBuffer = frontColorBufferMailbox->textureInfo; |
| 272 return true; | 274 return true; |
| 273 } | 275 } |
| 274 | 276 |
| 275 void DrawingBuffer::mailboxReleased(const blink::WebExternalTextureMailbox& mail
box) | 277 void DrawingBuffer::mailboxReleased(const blink::WebExternalTextureMailbox& mail
box) |
| 276 { | 278 { |
| 277 if (m_destructionInProgress) { | 279 if (m_destructionInProgress) { |
| 278 mailboxReleasedWhileDestructionInProgress(mailbox); | 280 mailboxReleasedWhileDestructionInProgress(mailbox); |
| 279 return; | 281 return; |
| 280 } | 282 } |
| 281 | 283 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 } | 317 } |
| 316 } | 318 } |
| 317 ASSERT(mailboxInfo); | 319 ASSERT(mailboxInfo); |
| 318 | 320 |
| 319 if (mailboxInfo->mailbox.syncPoint) { | 321 if (mailboxInfo->mailbox.syncPoint) { |
| 320 m_context->waitSyncPoint(mailboxInfo->mailbox.syncPoint); | 322 m_context->waitSyncPoint(mailboxInfo->mailbox.syncPoint); |
| 321 mailboxInfo->mailbox.syncPoint = 0; | 323 mailboxInfo->mailbox.syncPoint = 0; |
| 322 } | 324 } |
| 323 | 325 |
| 324 if (mailboxInfo->size != m_size) { | 326 if (mailboxInfo->size != m_size) { |
| 325 m_context->bindTexture(GL_TEXTURE_2D, mailboxInfo->textureId); | 327 m_context->bindTexture(GL_TEXTURE_2D, mailboxInfo->textureInfo.textureId
); |
| 326 texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, m_size.w
idth(), m_size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); | 328 allocateTextureMemory(&mailboxInfo->textureInfo, m_size); |
| 327 mailboxInfo->size = m_size; | 329 mailboxInfo->size = m_size; |
| 328 } | 330 } |
| 329 | 331 |
| 330 return mailboxInfo.release(); | 332 return mailboxInfo.release(); |
| 331 } | 333 } |
| 332 | 334 |
| 333 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(unsigned
textureId) | 335 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(const Tex
tureInfo& info) |
| 334 { | 336 { |
| 335 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo()); | 337 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo()); |
| 336 m_context->genMailboxCHROMIUM(returnMailbox->mailbox.name); | 338 m_context->genMailboxCHROMIUM(returnMailbox->mailbox.name); |
| 337 returnMailbox->textureId = textureId; | 339 returnMailbox->textureInfo = info; |
| 338 returnMailbox->size = m_size; | 340 returnMailbox->size = m_size; |
| 339 m_textureMailboxes.append(returnMailbox); | 341 m_textureMailboxes.append(returnMailbox); |
| 340 return returnMailbox.release(); | 342 return returnMailbox.release(); |
| 341 } | 343 } |
| 342 | 344 |
| 343 void DrawingBuffer::deleteMailbox(const blink::WebExternalTextureMailbox& mailbo
x) | 345 void DrawingBuffer::deleteMailbox(const blink::WebExternalTextureMailbox& mailbo
x) |
| 344 { | 346 { |
| 345 for (size_t i = 0; i < m_textureMailboxes.size(); i++) { | 347 for (size_t i = 0; i < m_textureMailboxes.size(); i++) { |
| 346 if (nameEquals(m_textureMailboxes[i]->mailbox, mailbox)) { | 348 if (nameEquals(m_textureMailboxes[i]->mailbox, mailbox)) { |
| 347 if (mailbox.syncPoint) | 349 if (mailbox.syncPoint) |
| 348 m_context->waitSyncPoint(mailbox.syncPoint); | 350 m_context->waitSyncPoint(mailbox.syncPoint); |
| 349 m_context->deleteTexture(m_textureMailboxes[i]->textureId); | 351 |
| 352 deleteChromiumImageForTexture(&m_textureMailboxes[i]->textureInfo); |
| 353 |
| 354 m_context->deleteTexture(m_textureMailboxes[i]->textureInfo.textureI
d); |
| 350 m_textureMailboxes.remove(i); | 355 m_textureMailboxes.remove(i); |
| 351 return; | 356 return; |
| 352 } | 357 } |
| 353 } | 358 } |
| 354 ASSERT_NOT_REACHED(); | 359 ASSERT_NOT_REACHED(); |
| 355 } | 360 } |
| 356 | 361 |
| 357 bool DrawingBuffer::initialize(const IntSize& size) | 362 bool DrawingBuffer::initialize(const IntSize& size) |
| 358 { | 363 { |
| 359 if (!m_context->makeContextCurrent()) { | 364 if (!m_context->makeContextCurrent()) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 387 m_context->getIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); | 392 m_context->getIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); |
| 388 m_multisampleMode = ExplicitResolve; | 393 m_multisampleMode = ExplicitResolve; |
| 389 if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t
exture")) | 394 if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t
exture")) |
| 390 m_multisampleMode = ImplicitResolve; | 395 m_multisampleMode = ImplicitResolve; |
| 391 } | 396 } |
| 392 m_sampleCount = std::min(4, maxSampleCount); | 397 m_sampleCount = std::min(4, maxSampleCount); |
| 393 | 398 |
| 394 m_fbo = m_context->createFramebuffer(); | 399 m_fbo = m_context->createFramebuffer(); |
| 395 | 400 |
| 396 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 401 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 397 m_colorBuffer = createColorTexture(); | 402 m_colorBuffer.textureId = createColorTexture(); |
| 398 if (m_multisampleMode == ImplicitResolve) | 403 if (m_multisampleMode == ImplicitResolve) |
| 399 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A
TTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0, m_sampleCount); | 404 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A
TTACHMENT0, GL_TEXTURE_2D, m_colorBuffer.textureId, 0, m_sampleCount); |
| 400 else | 405 else |
| 401 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL
_TEXTURE_2D, m_colorBuffer, 0); | 406 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL
_TEXTURE_2D, m_colorBuffer.textureId, 0); |
| 402 createSecondaryBuffers(); | 407 createSecondaryBuffers(); |
| 403 return reset(size); | 408 return reset(size); |
| 404 } | 409 } |
| 405 | 410 |
| 406 bool DrawingBuffer::copyToPlatformTexture(blink::WebGraphicsContext3D* context,
Platform3DObject texture, GLenum internalFormat, GLenum destType, GLint level, b
ool premultiplyAlpha, bool flipY) | 411 bool DrawingBuffer::copyToPlatformTexture(blink::WebGraphicsContext3D* context,
Platform3DObject texture, GLenum internalFormat, GLenum destType, GLint level, b
ool premultiplyAlpha, bool flipY) |
| 407 { | 412 { |
| 408 if (!m_context->makeContextCurrent()) | 413 if (!m_context->makeContextCurrent()) |
| 409 return false; | 414 return false; |
| 410 if (m_contentsChanged) { | 415 if (m_contentsChanged) { |
| 411 if (m_multisampleMode != None) { | 416 if (m_multisampleMode != None) { |
| 412 commit(); | 417 commit(); |
| 413 if (!m_framebufferBinding) | 418 if (!m_framebufferBinding) |
| 414 bind(); | 419 bind(); |
| 415 else | 420 else |
| 416 restoreFramebufferBinding(); | 421 restoreFramebufferBinding(); |
| 417 } | 422 } |
| 418 m_context->flush(); | 423 m_context->flush(); |
| 419 } | 424 } |
| 420 | 425 |
| 421 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, destType, l
evel)) | 426 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, destType, l
evel)) |
| 422 return false; | 427 return false; |
| 423 | 428 |
| 424 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first | 429 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first |
| 425 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); | 430 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); |
| 426 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); | 431 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); |
| 427 m_context->bindTexture(GL_TEXTURE_2D, m_colorBuffer); | 432 m_context->bindTexture(GL_TEXTURE_2D, m_colorBuffer.textureId); |
| 428 m_context->produceTextureCHROMIUM(GL_TEXTURE_2D, bufferMailbox->mailbox.name
); | 433 m_context->produceTextureCHROMIUM(GL_TEXTURE_2D, bufferMailbox->mailbox.name
); |
| 429 m_context->flush(); | 434 m_context->flush(); |
| 430 | 435 |
| 431 bufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); | 436 bufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); |
| 432 | 437 |
| 433 if (!context->makeContextCurrent()) | 438 if (!context->makeContextCurrent()) |
| 434 return false; | 439 return false; |
| 435 | 440 |
| 436 Platform3DObject sourceTexture = context->createTexture(); | 441 Platform3DObject sourceTexture = context->createTexture(); |
| 437 | 442 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 { | 496 { |
| 492 if (!m_context->makeContextCurrent() || m_context->getGraphicsResetStatusARB
() != GL_NO_ERROR) | 497 if (!m_context->makeContextCurrent() || m_context->getGraphicsResetStatusARB
() != GL_NO_ERROR) |
| 493 return; | 498 return; |
| 494 | 499 |
| 495 if (!imageBuffer) | 500 if (!imageBuffer) |
| 496 return; | 501 return; |
| 497 Platform3DObject tex = imageBuffer->getBackingTexture(); | 502 Platform3DObject tex = imageBuffer->getBackingTexture(); |
| 498 if (tex) { | 503 if (tex) { |
| 499 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); | 504 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); |
| 500 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); | 505 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); |
| 501 m_context->bindTexture(GL_TEXTURE_2D, m_frontColorBuffer); | 506 m_context->bindTexture(GL_TEXTURE_2D, m_frontColorBuffer.textureId); |
| 502 m_context->produceTextureCHROMIUM(GL_TEXTURE_2D, bufferMailbox->mailbox.
name); | 507 m_context->produceTextureCHROMIUM(GL_TEXTURE_2D, bufferMailbox->mailbox.
name); |
| 503 m_context->flush(); | 508 m_context->flush(); |
| 504 | 509 |
| 505 bufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); | 510 bufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); |
| 506 OwnPtr<blink::WebGraphicsContext3DProvider> provider = | 511 OwnPtr<blink::WebGraphicsContext3DProvider> provider = |
| 507 adoptPtr(blink::Platform::current()->createSharedOffscreenGraphicsCo
ntext3DProvider()); | 512 adoptPtr(blink::Platform::current()->createSharedOffscreenGraphicsCo
ntext3DProvider()); |
| 508 if (!provider) | 513 if (!provider) |
| 509 return; | 514 return; |
| 510 blink::WebGraphicsContext3D* context = provider->context3d(); | 515 blink::WebGraphicsContext3D* context = provider->context3d(); |
| 511 if (!context || !context->makeContextCurrent()) | 516 if (!context || !context->makeContextCurrent()) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 523 context->deleteTexture(sourceTexture); | 528 context->deleteTexture(sourceTexture); |
| 524 context->flush(); | 529 context->flush(); |
| 525 m_context->waitSyncPoint(context->insertSyncPoint()); | 530 m_context->waitSyncPoint(context->insertSyncPoint()); |
| 526 return; | 531 return; |
| 527 } | 532 } |
| 528 | 533 |
| 529 // Since the m_frontColorBuffer was produced and sent to the compositor, it
cannot be bound to an fbo. | 534 // Since the m_frontColorBuffer was produced and sent to the compositor, it
cannot be bound to an fbo. |
| 530 // We have to make a copy of it here and bind that copy instead. | 535 // We have to make a copy of it here and bind that copy instead. |
| 531 // FIXME: That's not true any more, provided we don't change texture | 536 // FIXME: That's not true any more, provided we don't change texture |
| 532 // parameters. | 537 // parameters. |
| 533 unsigned sourceTexture = createColorTexture(m_size); | 538 unsigned sourceTexture = createColorTexture(); |
| 534 m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_frontColorBuffer, sourceText
ure, 0, GL_RGBA, GL_UNSIGNED_BYTE); | 539 texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, m_size.width
(), m_size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
| 540 m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_frontColorBuffer.textureId,
sourceTexture, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
| 535 | 541 |
| 536 // Since we're using the same context as WebGL, we have to restore any state
we change (in this case, just the framebuffer binding). | 542 // Since we're using the same context as WebGL, we have to restore any state
we change (in this case, just the framebuffer binding). |
| 537 // FIXME: The WebGLRenderingContext tracks the current framebuffer binding,
it would be slightly more efficient to use this value | 543 // FIXME: The WebGLRenderingContext tracks the current framebuffer binding,
it would be slightly more efficient to use this value |
| 538 // rather than querying it off of the context. | 544 // rather than querying it off of the context. |
| 539 GLint previousFramebuffer = 0; | 545 GLint previousFramebuffer = 0; |
| 540 m_context->getIntegerv(GL_FRAMEBUFFER_BINDING, &previousFramebuffer); | 546 m_context->getIntegerv(GL_FRAMEBUFFER_BINDING, &previousFramebuffer); |
| 541 | 547 |
| 542 Platform3DObject framebuffer = m_context->createFramebuffer(); | 548 Platform3DObject framebuffer = m_context->createFramebuffer(); |
| 543 m_context->bindFramebuffer(GL_FRAMEBUFFER, framebuffer); | 549 m_context->bindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 544 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEX
TURE_2D, sourceTexture, 0); | 550 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEX
TURE_2D, sourceTexture, 0); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 | 587 |
| 582 if (m_depthStencilBuffer) | 588 if (m_depthStencilBuffer) |
| 583 m_context->deleteRenderbuffer(m_depthStencilBuffer); | 589 m_context->deleteRenderbuffer(m_depthStencilBuffer); |
| 584 | 590 |
| 585 if (m_depthBuffer) | 591 if (m_depthBuffer) |
| 586 m_context->deleteRenderbuffer(m_depthBuffer); | 592 m_context->deleteRenderbuffer(m_depthBuffer); |
| 587 | 593 |
| 588 if (m_stencilBuffer) | 594 if (m_stencilBuffer) |
| 589 m_context->deleteRenderbuffer(m_stencilBuffer); | 595 m_context->deleteRenderbuffer(m_stencilBuffer); |
| 590 | 596 |
| 591 if (m_colorBuffer) | 597 if (m_colorBuffer.textureId) { |
| 592 m_context->deleteTexture(m_colorBuffer); | 598 deleteChromiumImageForTexture(&m_colorBuffer); |
| 599 m_context->deleteTexture(m_colorBuffer.textureId); |
| 600 } |
| 593 | 601 |
| 594 setSize(IntSize()); | 602 setSize(IntSize()); |
| 595 | 603 |
| 596 m_colorBuffer = 0; | 604 m_colorBuffer = TextureInfo(); |
| 597 m_frontColorBuffer = 0; | 605 m_frontColorBuffer = TextureInfo(); |
| 598 m_multisampleColorBuffer = 0; | 606 m_multisampleColorBuffer = 0; |
| 599 m_depthStencilBuffer = 0; | 607 m_depthStencilBuffer = 0; |
| 600 m_depthBuffer = 0; | 608 m_depthBuffer = 0; |
| 601 m_stencilBuffer = 0; | 609 m_stencilBuffer = 0; |
| 602 m_multisampleFBO = 0; | 610 m_multisampleFBO = 0; |
| 603 m_fbo = 0; | 611 m_fbo = 0; |
| 604 m_contextEvictionManager.clear(); | 612 m_contextEvictionManager.clear(); |
| 605 | 613 |
| 606 if (m_layer) | 614 if (m_layer) |
| 607 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); | 615 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); |
| 608 } | 616 } |
| 609 | 617 |
| 610 unsigned DrawingBuffer::createColorTexture(const IntSize& size) | 618 unsigned DrawingBuffer::createColorTexture() |
| 611 { | 619 { |
| 612 unsigned offscreenColorTexture = m_context->createTexture(); | 620 unsigned offscreenColorTexture = m_context->createTexture(); |
| 613 if (!offscreenColorTexture) | 621 if (!offscreenColorTexture) |
| 614 return 0; | 622 return 0; |
| 615 | 623 |
| 616 m_context->bindTexture(GL_TEXTURE_2D, offscreenColorTexture); | 624 m_context->bindTexture(GL_TEXTURE_2D, offscreenColorTexture); |
| 617 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 625 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 618 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 626 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 619 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
; | 627 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
; |
| 620 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
; | 628 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
; |
| 621 if (!size.isEmpty()) | |
| 622 texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, size.wid
th(), size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); | |
| 623 | 629 |
| 624 return offscreenColorTexture; | 630 return offscreenColorTexture; |
| 625 } | 631 } |
| 626 | 632 |
| 627 void DrawingBuffer::createSecondaryBuffers() | 633 void DrawingBuffer::createSecondaryBuffers() |
| 628 { | 634 { |
| 629 // create a multisample FBO | 635 // create a multisample FBO |
| 630 if (m_multisampleMode == ExplicitResolve) { | 636 if (m_multisampleMode == ExplicitResolve) { |
| 631 m_multisampleFBO = m_context->createFramebuffer(); | 637 m_multisampleFBO = m_context->createFramebuffer(); |
| 632 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); | 638 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); |
| 633 m_multisampleColorBuffer = m_context->createRenderbuffer(); | 639 m_multisampleColorBuffer = m_context->createRenderbuffer(); |
| 634 } | 640 } |
| 635 } | 641 } |
| 636 | 642 |
| 637 bool DrawingBuffer::resizeFramebuffer(const IntSize& size) | 643 bool DrawingBuffer::resizeFramebuffer(const IntSize& size) |
| 638 { | 644 { |
| 639 // resize regular FBO | 645 // resize regular FBO |
| 640 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 646 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 641 | 647 |
| 642 m_context->bindTexture(GL_TEXTURE_2D, m_colorBuffer); | 648 m_context->bindTexture(GL_TEXTURE_2D, m_colorBuffer.textureId); |
| 643 | 649 |
| 644 texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, size.width()
, size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); | 650 allocateTextureMemory(&m_colorBuffer, size); |
| 645 | 651 |
| 646 if (m_multisampleMode == ImplicitResolve) | 652 if (m_multisampleMode == ImplicitResolve) |
| 647 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A
TTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0, m_sampleCount); | 653 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A
TTACHMENT0, GL_TEXTURE_2D, m_colorBuffer.textureId, 0, m_sampleCount); |
| 648 else | 654 else |
| 649 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL
_TEXTURE_2D, m_colorBuffer, 0); | 655 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL
_TEXTURE_2D, m_colorBuffer.textureId, 0); |
| 650 | 656 |
| 651 m_context->bindTexture(GL_TEXTURE_2D, 0); | 657 m_context->bindTexture(GL_TEXTURE_2D, 0); |
| 652 | 658 |
| 653 if (m_multisampleMode != ExplicitResolve) | 659 if (m_multisampleMode != ExplicitResolve) |
| 654 resizeDepthStencil(size); | 660 resizeDepthStencil(size); |
| 655 if (m_context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMP
LETE) | 661 if (m_context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMP
LETE) |
| 656 return false; | 662 return false; |
| 657 | 663 |
| 658 return true; | 664 return true; |
| 659 } | 665 } |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 memcpy(rowA, scanline, rowBytes); | 1019 memcpy(rowA, scanline, rowBytes); |
| 1014 } | 1020 } |
| 1015 } | 1021 } |
| 1016 | 1022 |
| 1017 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in
ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum
type, GLint unpackAlignment) | 1023 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in
ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum
type, GLint unpackAlignment) |
| 1018 { | 1024 { |
| 1019 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4
|| unpackAlignment == 8); | 1025 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4
|| unpackAlignment == 8); |
| 1020 m_context->texImage2D(target, level, internalformat, width, height, border,
format, type, 0); | 1026 m_context->texImage2D(target, level, internalformat, width, height, border,
format, type, 0); |
| 1021 } | 1027 } |
| 1022 | 1028 |
| 1029 void DrawingBuffer::allocateTextureMemory(TextureInfo* info, const IntSize& size
) |
| 1030 { |
| 1031 if (RuntimeEnabledFeatures::webGLImageChromiumEnabled()) { |
| 1032 deleteChromiumImageForTexture(info); |
| 1033 |
| 1034 info->imageId = m_context->createImageCHROMIUM(size.width(), size.height
(), GL_RGBA8_OES, GC3D_IMAGE_SCANOUT_CHROMIUM); |
| 1035 if (info->imageId) { |
| 1036 m_context->bindTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); |
| 1037 return; |
| 1038 } |
| 1039 } |
| 1040 |
| 1041 texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, size.width()
, size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
| 1042 } |
| 1043 |
| 1044 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) |
| 1045 { |
| 1046 if (info->imageId) { |
| 1047 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); |
| 1048 m_context->destroyImageCHROMIUM(info->imageId); |
| 1049 info->imageId = 0; |
| 1050 } |
| 1051 } |
| 1052 |
| 1023 } // namespace WebCore | 1053 } // namespace WebCore |
| OLD | NEW |