| 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, PreserveDrawingBuffer preserve, W
ebGraphicsContext3D::Attributes requestedAttributes) | 93 PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<WebGraphicsContext3DP
rovider> contextProvider, const IntSize& size, bool premultipliedAlpha, Preserve
DrawingBuffer preserve, WebGraphicsContext3D::Attributes requestedAttributes) |
| 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 = (extensionsUtil->supportsExtension("GL_CHROMIUM_
framebuffer_multisample") |
| 110 || extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_text
ure")) | 110 || extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_text
ure")) |
| 111 && extensionsUtil->supportsExtension("GL_OES_rgb8_rgba8"); | 111 && extensionsUtil->supportsExtension("GL_OES_rgb8_rgba8"); |
| 112 if (multisampleSupported) { | 112 if (multisampleSupported) { |
| 113 extensionsUtil->ensureExtensionEnabled("GL_OES_rgb8_rgba8"); | 113 extensionsUtil->ensureExtensionEnabled("GL_OES_rgb8_rgba8"); |
| 114 if (extensionsUtil->supportsExtension("GL_CHROMIUM_framebuffer_multisamp
le")) | 114 if (extensionsUtil->supportsExtension("GL_CHROMIUM_framebuffer_multisamp
le")) |
| 115 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_mult
isample"); | 115 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_mult
isample"); |
| 116 else | 116 else |
| 117 extensionsUtil->ensureExtensionEnabled("GL_EXT_multisampled_render_t
o_texture"); | 117 extensionsUtil->ensureExtensionEnabled("GL_EXT_multisampled_render_t
o_texture"); |
| 118 } | 118 } |
| 119 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT
_discard_framebuffer"); | 119 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT
_discard_framebuffer"); |
| 120 if (discardFramebufferSupported) | 120 if (discardFramebufferSupported) |
| 121 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer"); | 121 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer"); |
| 122 | 122 |
| 123 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(std::move(c
ontextProvider), extensionsUtil.release(), multisampleSupported, discardFramebuf
ferSupported, preserve, requestedAttributes)); | 123 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(std::move(c
ontextProvider), extensionsUtil.release(), multisampleSupported, discardFramebuf
ferSupported, premultipliedAlpha, preserve, requestedAttributes)); |
| 124 if (!drawingBuffer->initialize(size)) { | 124 if (!drawingBuffer->initialize(size)) { |
| 125 drawingBuffer->beginDestruction(); | 125 drawingBuffer->beginDestruction(); |
| 126 return PassRefPtr<DrawingBuffer>(); | 126 return PassRefPtr<DrawingBuffer>(); |
| 127 } | 127 } |
| 128 return drawingBuffer.release(); | 128 return drawingBuffer.release(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void DrawingBuffer::forceNextDrawingBufferCreationToFail() | 131 void DrawingBuffer::forceNextDrawingBufferCreationToFail() |
| 132 { | 132 { |
| 133 shouldFailDrawingBufferCreationForTesting = true; | 133 shouldFailDrawingBufferCreationForTesting = true; |
| 134 } | 134 } |
| 135 | 135 |
| 136 DrawingBuffer::DrawingBuffer(PassOwnPtr<WebGraphicsContext3DProvider> contextPro
vider, PassOwnPtr<Extensions3DUtil> extensionsUtil, bool multisampleExtensionSup
ported, bool discardFramebufferSupported, PreserveDrawingBuffer preserve, WebGra
phicsContext3D::Attributes requestedAttributes) | 136 DrawingBuffer::DrawingBuffer(PassOwnPtr<WebGraphicsContext3DProvider> contextPro
vider, PassOwnPtr<Extensions3DUtil> extensionsUtil, bool multisampleExtensionSup
ported, bool discardFramebufferSupported, bool premultipliedAlpha, PreserveDrawi
ngBuffer preserve, WebGraphicsContext3D::Attributes requestedAttributes) |
| 137 : m_preserveDrawingBuffer(preserve) | 137 : m_preserveDrawingBuffer(preserve) |
| 138 , m_scissorEnabled(false) | 138 , m_scissorEnabled(false) |
| 139 , m_texture2DBinding(0) | 139 , m_texture2DBinding(0) |
| 140 , m_drawFramebufferBinding(0) | 140 , m_drawFramebufferBinding(0) |
| 141 , m_readFramebufferBinding(0) | 141 , m_readFramebufferBinding(0) |
| 142 , m_activeTextureUnit(GL_TEXTURE0) | 142 , m_activeTextureUnit(GL_TEXTURE0) |
| 143 , m_contextProvider(std::move(contextProvider)) | 143 , m_contextProvider(std::move(contextProvider)) |
| 144 , m_context(m_contextProvider->context3d()) | 144 , m_context(m_contextProvider->context3d()) |
| 145 , m_gl(m_contextProvider->contextGL()) | 145 , m_gl(m_contextProvider->contextGL()) |
| 146 , m_extensionsUtil(std::move(extensionsUtil)) | 146 , m_extensionsUtil(std::move(extensionsUtil)) |
| 147 , m_size(-1, -1) | 147 , m_size(-1, -1) |
| 148 , m_requestedAttributes(requestedAttributes) | 148 , m_requestedAttributes(requestedAttributes) |
| 149 , m_multisampleExtensionSupported(multisampleExtensionSupported) | 149 , m_multisampleExtensionSupported(multisampleExtensionSupported) |
| 150 , m_discardFramebufferSupported(discardFramebufferSupported) | 150 , m_discardFramebufferSupported(discardFramebufferSupported) |
| 151 , m_premultipliedAlpha(premultipliedAlpha) |
| 151 , m_fbo(0) | 152 , m_fbo(0) |
| 152 , m_depthStencilBuffer(0) | 153 , m_depthStencilBuffer(0) |
| 153 , m_multisampleFBO(0) | 154 , m_multisampleFBO(0) |
| 154 , m_multisampleColorBuffer(0) | 155 , m_multisampleColorBuffer(0) |
| 155 , m_contentsChanged(true) | 156 , m_contentsChanged(true) |
| 156 , m_contentsChangeCommitted(false) | 157 , m_contentsChangeCommitted(false) |
| 157 , m_bufferClearNeeded(false) | 158 , m_bufferClearNeeded(false) |
| 158 , m_antiAliasingMode(None) | 159 , m_antiAliasingMode(None) |
| 159 , m_maxTextureSize(0) | 160 , m_maxTextureSize(0) |
| 160 , m_sampleCount(0) | 161 , m_sampleCount(0) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 (*m_newMailboxCallback)(); | 261 (*m_newMailboxCallback)(); |
| 261 | 262 |
| 262 // Resolve the multisampled buffer into m_colorBuffer texture. | 263 // Resolve the multisampled buffer into m_colorBuffer texture. |
| 263 if (m_antiAliasingMode != None) | 264 if (m_antiAliasingMode != None) |
| 264 commit(); | 265 commit(); |
| 265 | 266 |
| 266 if (bitmap) { | 267 if (bitmap) { |
| 267 bitmap->setSize(size()); | 268 bitmap->setSize(size()); |
| 268 | 269 |
| 269 unsigned char* pixels = bitmap->pixels(); | 270 unsigned char* pixels = bitmap->pixels(); |
| 270 bool needPremultiply = m_actualAttributes.alpha && !m_actualAttributes.p
remultipliedAlpha; | 271 bool needPremultiply = m_actualAttributes.alpha && !m_premultipliedAlpha
; |
| 271 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; | 272 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; |
| 272 if (pixels) | 273 if (pixels) |
| 273 readBackFramebuffer(pixels, size().width(), size().height(), Readbac
kSkia, op); | 274 readBackFramebuffer(pixels, size().width(), size().height(), Readbac
kSkia, op); |
| 274 } | 275 } |
| 275 | 276 |
| 276 // We must restore the texture binding since creating new textures, | 277 // We must restore the texture binding since creating new textures, |
| 277 // consuming and producing mailboxes changes it. | 278 // consuming and producing mailboxes changes it. |
| 278 ScopedTextureUnit0BindingRestorer restorer(m_gl, m_activeTextureUnit, m_text
ure2DBinding); | 279 ScopedTextureUnit0BindingRestorer restorer(m_gl, m_activeTextureUnit, m_text
ure2DBinding); |
| 279 | 280 |
| 280 // First try to recycle an old buffer. | 281 // First try to recycle an old buffer. |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 m_gl->GenSyncTokenCHROMIUM(fenceSync, mailbox.syncToken); | 538 m_gl->GenSyncTokenCHROMIUM(fenceSync, mailbox.syncToken); |
| 538 mailbox.validSyncToken = true; | 539 mailbox.validSyncToken = true; |
| 539 } | 540 } |
| 540 | 541 |
| 541 if (mailbox.validSyncToken) | 542 if (mailbox.validSyncToken) |
| 542 gl->WaitSyncTokenCHROMIUM(mailbox.syncToken); | 543 gl->WaitSyncTokenCHROMIUM(mailbox.syncToken); |
| 543 GLuint sourceTexture = gl->CreateAndConsumeTextureCHROMIUM(target, mailbox.n
ame); | 544 GLuint sourceTexture = gl->CreateAndConsumeTextureCHROMIUM(target, mailbox.n
ame); |
| 544 | 545 |
| 545 GLboolean unpackPremultiplyAlphaNeeded = GL_FALSE; | 546 GLboolean unpackPremultiplyAlphaNeeded = GL_FALSE; |
| 546 GLboolean unpackUnpremultiplyAlphaNeeded = GL_FALSE; | 547 GLboolean unpackUnpremultiplyAlphaNeeded = GL_FALSE; |
| 547 if (m_actualAttributes.alpha && m_actualAttributes.premultipliedAlpha && !pr
emultiplyAlpha) | 548 if (m_actualAttributes.alpha && m_premultipliedAlpha && !premultiplyAlpha) |
| 548 unpackUnpremultiplyAlphaNeeded = GL_TRUE; | 549 unpackUnpremultiplyAlphaNeeded = GL_TRUE; |
| 549 else if (m_actualAttributes.alpha && !m_actualAttributes.premultipliedAlpha
&& premultiplyAlpha) | 550 else if (m_actualAttributes.alpha && !m_premultipliedAlpha && premultiplyAlp
ha) |
| 550 unpackPremultiplyAlphaNeeded = GL_TRUE; | 551 unpackPremultiplyAlphaNeeded = GL_TRUE; |
| 551 | 552 |
| 552 gl->CopyTextureCHROMIUM(sourceTexture, texture, internalFormat, destType, fl
ipY, unpackPremultiplyAlphaNeeded, unpackUnpremultiplyAlphaNeeded); | 553 gl->CopyTextureCHROMIUM(sourceTexture, texture, internalFormat, destType, fl
ipY, unpackPremultiplyAlphaNeeded, unpackUnpremultiplyAlphaNeeded); |
| 553 | 554 |
| 554 gl->DeleteTextures(1, &sourceTexture); | 555 gl->DeleteTextures(1, &sourceTexture); |
| 555 | 556 |
| 556 const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); | 557 const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); |
| 557 | 558 |
| 558 gl->Flush(); | 559 gl->Flush(); |
| 559 GLbyte syncToken[24]; | 560 GLbyte syncToken[24]; |
| 560 gl->GenSyncTokenCHROMIUM(fenceSync, syncToken); | 561 gl->GenSyncTokenCHROMIUM(fenceSync, syncToken); |
| 561 m_gl->WaitSyncTokenCHROMIUM(syncToken); | 562 m_gl->WaitSyncTokenCHROMIUM(syncToken); |
| 562 | 563 |
| 563 return true; | 564 return true; |
| 564 } | 565 } |
| 565 | 566 |
| 566 GLuint DrawingBuffer::framebuffer() const | 567 GLuint DrawingBuffer::framebuffer() const |
| 567 { | 568 { |
| 568 return m_fbo; | 569 return m_fbo; |
| 569 } | 570 } |
| 570 | 571 |
| 571 WebLayer* DrawingBuffer::platformLayer() | 572 WebLayer* DrawingBuffer::platformLayer() |
| 572 { | 573 { |
| 573 if (!m_layer) { | 574 if (!m_layer) { |
| 574 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExter
nalTextureLayer(this)); | 575 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExter
nalTextureLayer(this)); |
| 575 | 576 |
| 576 m_layer->setOpaque(!m_actualAttributes.alpha); | 577 m_layer->setOpaque(!m_actualAttributes.alpha); |
| 577 m_layer->setBlendBackgroundColor(m_actualAttributes.alpha); | 578 m_layer->setBlendBackgroundColor(m_actualAttributes.alpha); |
| 578 m_layer->setPremultipliedAlpha(m_actualAttributes.premultipliedAlpha); | 579 m_layer->setPremultipliedAlpha(m_premultipliedAlpha); |
| 579 m_layer->setNearestNeighbor(m_filterQuality == kNone_SkFilterQuality); | 580 m_layer->setNearestNeighbor(m_filterQuality == kNone_SkFilterQuality); |
| 580 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 581 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
| 581 } | 582 } |
| 582 | 583 |
| 583 return m_layer->layer(); | 584 return m_layer->layer(); |
| 584 } | 585 } |
| 585 | 586 |
| 586 void DrawingBuffer::clearPlatformLayer() | 587 void DrawingBuffer::clearPlatformLayer() |
| 587 { | 588 { |
| 588 if (m_layer) | 589 if (m_layer) |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 m_gl->BindFramebuffer(target, m_fbo); | 858 m_gl->BindFramebuffer(target, m_fbo); |
| 858 } | 859 } |
| 859 | 860 |
| 860 void DrawingBuffer::setPackAlignment(GLint param) | 861 void DrawingBuffer::setPackAlignment(GLint param) |
| 861 { | 862 { |
| 862 m_packAlignment = param; | 863 m_packAlignment = param; |
| 863 } | 864 } |
| 864 | 865 |
| 865 bool DrawingBuffer::paintRenderingResultsToImageData(int& width, int& height, So
urceDrawingBuffer sourceBuffer, WTF::ArrayBufferContents& contents) | 866 bool DrawingBuffer::paintRenderingResultsToImageData(int& width, int& height, So
urceDrawingBuffer sourceBuffer, WTF::ArrayBufferContents& contents) |
| 866 { | 867 { |
| 867 ASSERT(!m_actualAttributes.premultipliedAlpha); | 868 ASSERT(!m_premultipliedAlpha); |
| 868 width = size().width(); | 869 width = size().width(); |
| 869 height = size().height(); | 870 height = size().height(); |
| 870 | 871 |
| 871 CheckedNumeric<int> dataSize = 4; | 872 CheckedNumeric<int> dataSize = 4; |
| 872 dataSize *= width; | 873 dataSize *= width; |
| 873 dataSize *= height; | 874 dataSize *= height; |
| 874 if (!dataSize.IsValid()) | 875 if (!dataSize.IsValid()) |
| 875 return false; | 876 return false; |
| 876 | 877 |
| 877 WTF::ArrayBufferContents pixels(width * height, 4, WTF::ArrayBufferContents:
:NotShared, WTF::ArrayBufferContents::DontInitialize); | 878 WTF::ArrayBufferContents pixels(width * height, 4, WTF::ArrayBufferContents:
:NotShared, WTF::ArrayBufferContents::DontInitialize); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 | 1032 |
| 1032 if (m_antiAliasingMode == MSAAImplicitResolve) | 1033 if (m_antiAliasingMode == MSAAImplicitResolve) |
| 1033 m_gl->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACH
MENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); | 1034 m_gl->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACH
MENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); |
| 1034 else | 1035 else |
| 1035 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
m_colorBuffer.textureId, 0); | 1036 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
m_colorBuffer.textureId, 0); |
| 1036 | 1037 |
| 1037 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); | 1038 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); |
| 1038 } | 1039 } |
| 1039 | 1040 |
| 1040 } // namespace blink | 1041 } // namespace blink |
| OLD | NEW |