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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 m_context->produceTextureDirectCHROMIUM(frontColorBufferMailbox->textureInfo .textureId, GL_TEXTURE_2D, frontColorBufferMailbox->mailbox.name); | 290 m_context->produceTextureDirectCHROMIUM(frontColorBufferMailbox->textureInfo .textureId, GL_TEXTURE_2D, frontColorBufferMailbox->mailbox.name); |
291 m_context->flush(); | 291 m_context->flush(); |
292 frontColorBufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); | 292 frontColorBufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); |
293 frontColorBufferMailbox->mailbox.allowOverlay = frontColorBufferMailbox->tex tureInfo.imageId != 0; | 293 frontColorBufferMailbox->mailbox.allowOverlay = frontColorBufferMailbox->tex tureInfo.imageId != 0; |
294 markLayerComposited(); | 294 markLayerComposited(); |
295 | 295 |
296 // set m_parentDrawingBuffer to make sure 'this' stays alive as long as it h as live mailboxes | 296 // set m_parentDrawingBuffer to make sure 'this' stays alive as long as it h as live mailboxes |
297 ASSERT(!frontColorBufferMailbox->m_parentDrawingBuffer); | 297 ASSERT(!frontColorBufferMailbox->m_parentDrawingBuffer); |
298 frontColorBufferMailbox->m_parentDrawingBuffer = this; | 298 frontColorBufferMailbox->m_parentDrawingBuffer = this; |
299 *outMailbox = frontColorBufferMailbox->mailbox; | 299 *outMailbox = frontColorBufferMailbox->mailbox; |
300 m_frontColorBuffer = frontColorBufferMailbox->textureInfo; | 300 m_frontColorBuffer = { frontColorBufferMailbox->textureInfo, frontColorBuffe rMailbox->mailbox }; |
301 return true; | 301 return true; |
302 } | 302 } |
303 | 303 |
304 void DrawingBuffer::mailboxReleased(const WebExternalTextureMailbox& mailbox, bo ol lostResource) | 304 void DrawingBuffer::mailboxReleased(const WebExternalTextureMailbox& mailbox, bo ol lostResource) |
305 { | 305 { |
306 if (m_destructionInProgress || m_context->isContextLost() || lostResource || m_isHidden) { | 306 if (m_destructionInProgress || m_context->isContextLost() || lostResource || m_isHidden) { |
307 mailboxReleasedWithoutRecycling(mailbox); | 307 mailboxReleasedWithoutRecycling(mailbox); |
308 return; | 308 return; |
309 } | 309 } |
310 | 310 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 WGC3Dint stencilBits = 0; | 449 WGC3Dint stencilBits = 0; |
450 m_context->getIntegerv(GL_STENCIL_BITS, &stencilBits); | 450 m_context->getIntegerv(GL_STENCIL_BITS, &stencilBits); |
451 m_actualAttributes.stencil = stencilBits > 0; | 451 m_actualAttributes.stencil = stencilBits > 0; |
452 } | 452 } |
453 m_actualAttributes.antialias = multisample(); | 453 m_actualAttributes.antialias = multisample(); |
454 return true; | 454 return true; |
455 } | 455 } |
456 | 456 |
457 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platfor m3DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool pre multiplyAlpha, bool flipY, bool fromFrontBuffer) | 457 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platfor m3DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool pre multiplyAlpha, bool flipY, bool fromFrontBuffer) |
458 { | 458 { |
459 GLint textureId = m_colorBuffer.textureId; | |
460 if (fromFrontBuffer && m_frontColorBuffer.textureId) | |
461 textureId = m_frontColorBuffer.textureId; | |
462 | |
463 if (m_contentsChanged) { | 459 if (m_contentsChanged) { |
464 if (m_multisampleMode != None) { | 460 if (m_multisampleMode != None) { |
465 commit(); | 461 commit(); |
466 if (!m_framebufferBinding) | 462 if (!m_framebufferBinding) |
467 bind(); | 463 bind(); |
468 else | 464 else |
469 restoreFramebufferBinding(); | 465 restoreFramebufferBinding(); |
470 } | 466 } |
471 m_context->flush(); | 467 m_context->flush(); |
472 } | 468 } |
473 | 469 |
474 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, destType, l evel)) | 470 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, destType, l evel)) |
475 return false; | 471 return false; |
476 | 472 |
477 // Contexts may be in a different share group. We must transfer the texture through a mailbox first | 473 // Contexts may be in a different share group. We must transfer the texture through a mailbox first |
478 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); | 474 WebExternalTextureMailbox mailbox; |
479 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); | 475 GLint textureId = 0; |
480 m_context->produceTextureDirectCHROMIUM(textureId, GL_TEXTURE_2D, bufferMail box->mailbox.name); | 476 if (fromFrontBuffer && m_frontColorBuffer.texInfo.textureId) { |
481 m_context->flush(); | 477 textureId = m_frontColorBuffer.texInfo.textureId; |
478 mailbox = m_frontColorBuffer.mailbox; | |
479 } else { | |
480 textureId = m_colorBuffer.textureId; | |
481 m_context->genMailboxCHROMIUM(mailbox.name); | |
482 m_context->produceTextureDirectCHROMIUM(textureId, GL_TEXTURE_2D, mailbo x.name); | |
483 m_context->flush(); | |
484 mailbox.syncPoint = m_context->insertSyncPoint(); | |
485 } | |
482 | 486 |
483 bufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); | 487 context->waitSyncPoint(mailbox.syncPoint); |
Ken Russell (switch to Gerrit)
2014/10/31 00:54:21
Forgive my ignorance, but is it legal to wait mult
dshwang
2014/10/31 06:46:07
Yes, it's legal. For example, video frame is used
Ken Russell (switch to Gerrit)
2014/10/31 21:32:54
Right, confirmed by reading CHROMIUM_sync_point.tx
| |
484 | 488 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(GL _TEXTURE_2D, mailbox.name); |
485 context->waitSyncPoint(bufferMailbox->mailbox.syncPoint); | |
486 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(GL _TEXTURE_2D, bufferMailbox->mailbox.name); | |
487 | 489 |
488 bool unpackPremultiplyAlphaNeeded = false; | 490 bool unpackPremultiplyAlphaNeeded = false; |
489 bool unpackUnpremultiplyAlphaNeeded = false; | 491 bool unpackUnpremultiplyAlphaNeeded = false; |
490 if (m_actualAttributes.alpha && m_actualAttributes.premultipliedAlpha && !pr emultiplyAlpha) | 492 if (m_actualAttributes.alpha && m_actualAttributes.premultipliedAlpha && !pr emultiplyAlpha) |
491 unpackUnpremultiplyAlphaNeeded = true; | 493 unpackUnpremultiplyAlphaNeeded = true; |
492 else if (m_actualAttributes.alpha && !m_actualAttributes.premultipliedAlpha && premultiplyAlpha) | 494 else if (m_actualAttributes.alpha && !m_actualAttributes.premultipliedAlpha && premultiplyAlpha) |
493 unpackPremultiplyAlphaNeeded = true; | 495 unpackPremultiplyAlphaNeeded = true; |
494 | 496 |
495 context->pixelStorei(GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, unpackUnpremu ltiplyAlphaNeeded); | 497 context->pixelStorei(GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, unpackUnpremu ltiplyAlphaNeeded); |
496 context->pixelStorei(GC3D_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, unpackPremultip lyAlphaNeeded); | 498 context->pixelStorei(GC3D_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, unpackPremultip lyAlphaNeeded); |
(...skipping 28 matching lines...) Expand all Loading... | |
525 } | 527 } |
526 | 528 |
527 return m_layer->layer(); | 529 return m_layer->layer(); |
528 } | 530 } |
529 | 531 |
530 void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) | 532 void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) |
531 { | 533 { |
532 if (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR) | 534 if (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR) |
533 return; | 535 return; |
534 | 536 |
535 if (!imageBuffer) | 537 if (!imageBuffer || !m_frontColorBuffer.texInfo.textureId) |
536 return; | 538 return; |
537 Platform3DObject tex = imageBuffer->getBackingTexture(); | 539 Platform3DObject tex = imageBuffer->getBackingTexture(); |
538 if (tex) { | 540 if (tex) { |
539 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); | |
540 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); | |
541 m_context->produceTextureDirectCHROMIUM(m_frontColorBuffer.textureId, GL _TEXTURE_2D, bufferMailbox->mailbox.name); | |
542 m_context->flush(); | |
543 | |
544 bufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); | |
545 OwnPtr<WebGraphicsContext3DProvider> provider = | 541 OwnPtr<WebGraphicsContext3DProvider> provider = |
546 adoptPtr(Platform::current()->createSharedOffscreenGraphicsContext3D Provider()); | 542 adoptPtr(Platform::current()->createSharedOffscreenGraphicsContext3D Provider()); |
547 if (!provider) | 543 if (!provider) |
548 return; | 544 return; |
549 WebGraphicsContext3D* context = provider->context3d(); | 545 WebGraphicsContext3D* context = provider->context3d(); |
550 if (!context) | 546 if (!context) |
551 return; | 547 return; |
552 | 548 |
553 context->waitSyncPoint(bufferMailbox->mailbox.syncPoint); | 549 context->waitSyncPoint(m_frontColorBuffer.mailbox.syncPoint); |
554 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIU M(GL_TEXTURE_2D, bufferMailbox->mailbox.name); | 550 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIU M(GL_TEXTURE_2D, m_frontColorBuffer.mailbox.name); |
555 context->copyTextureCHROMIUM(GL_TEXTURE_2D, sourceTexture, | 551 context->copyTextureCHROMIUM(GL_TEXTURE_2D, sourceTexture, |
556 tex, 0, GL_RGBA, GL_UNSIGNED_BYTE); | 552 tex, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
557 context->deleteTexture(sourceTexture); | 553 context->deleteTexture(sourceTexture); |
558 context->flush(); | 554 context->flush(); |
559 m_context->waitSyncPoint(context->insertSyncPoint()); | 555 m_context->waitSyncPoint(context->insertSyncPoint()); |
560 imageBuffer->didModifyBackingTexture(); | 556 imageBuffer->didModifyBackingTexture(); |
561 | |
562 return; | 557 return; |
563 } | 558 } |
564 | 559 |
565 Platform3DObject framebuffer = m_context->createFramebuffer(); | 560 Platform3DObject framebuffer = m_context->createFramebuffer(); |
566 m_context->bindFramebuffer(GL_FRAMEBUFFER, framebuffer); | 561 m_context->bindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
567 // We don't need to bind a copy of m_frontColorBuffer since the texture para meters are untouched. | 562 // We don't need to bind a copy of m_frontColorBuffer since the texture para meters are untouched. |
568 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEX TURE_2D, m_frontColorBuffer.textureId, 0); | 563 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEX TURE_2D, m_frontColorBuffer.texInfo.textureId, 0); |
569 | 564 |
570 paintFramebufferToCanvas(framebuffer, size().width(), size().height(), !m_ac tualAttributes.premultipliedAlpha, imageBuffer); | 565 paintFramebufferToCanvas(framebuffer, size().width(), size().height(), !m_ac tualAttributes.premultipliedAlpha, imageBuffer); |
571 m_context->deleteFramebuffer(framebuffer); | 566 m_context->deleteFramebuffer(framebuffer); |
572 // Since we're using the same context as WebGL, we have to restore any state we change (in this case, just the framebuffer binding). | 567 // Since we're using the same context as WebGL, we have to restore any state we change (in this case, just the framebuffer binding). |
573 restoreFramebufferBinding(); | 568 restoreFramebufferBinding(); |
574 } | 569 } |
575 | 570 |
576 void DrawingBuffer::clearPlatformLayer() | 571 void DrawingBuffer::clearPlatformLayer() |
577 { | 572 { |
578 if (m_layer) | 573 if (m_layer) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 m_context->deleteRenderbuffer(m_stencilBuffer); | 605 m_context->deleteRenderbuffer(m_stencilBuffer); |
611 | 606 |
612 if (m_colorBuffer.textureId) { | 607 if (m_colorBuffer.textureId) { |
613 deleteChromiumImageForTexture(&m_colorBuffer); | 608 deleteChromiumImageForTexture(&m_colorBuffer); |
614 m_context->deleteTexture(m_colorBuffer.textureId); | 609 m_context->deleteTexture(m_colorBuffer.textureId); |
615 } | 610 } |
616 | 611 |
617 setSize(IntSize()); | 612 setSize(IntSize()); |
618 | 613 |
619 m_colorBuffer = TextureInfo(); | 614 m_colorBuffer = TextureInfo(); |
620 m_frontColorBuffer = TextureInfo(); | 615 m_frontColorBuffer = FrontBufferInfo(); |
621 m_multisampleColorBuffer = 0; | 616 m_multisampleColorBuffer = 0; |
622 m_depthStencilBuffer = 0; | 617 m_depthStencilBuffer = 0; |
623 m_depthBuffer = 0; | 618 m_depthBuffer = 0; |
624 m_stencilBuffer = 0; | 619 m_stencilBuffer = 0; |
625 m_multisampleFBO = 0; | 620 m_multisampleFBO = 0; |
626 m_fbo = 0; | 621 m_fbo = 0; |
627 m_contextEvictionManager.clear(); | 622 m_contextEvictionManager.clear(); |
628 | 623 |
629 if (m_layer) | 624 if (m_layer) |
630 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); | 625 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1060 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) | 1055 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) |
1061 { | 1056 { |
1062 if (info->imageId) { | 1057 if (info->imageId) { |
1063 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); | 1058 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); |
1064 m_context->destroyImageCHROMIUM(info->imageId); | 1059 m_context->destroyImageCHROMIUM(info->imageId); |
1065 info->imageId = 0; | 1060 info->imageId = 0; |
1066 } | 1061 } |
1067 } | 1062 } |
1068 | 1063 |
1069 } // namespace blink | 1064 } // namespace blink |
OLD | NEW |