Chromium Code Reviews| Index: Source/platform/graphics/gpu/DrawingBuffer.cpp |
| diff --git a/Source/platform/graphics/gpu/DrawingBuffer.cpp b/Source/platform/graphics/gpu/DrawingBuffer.cpp |
| index 8927cd7eb2ea07757d87929eff452128fe81650e..af0652db00864a5162defd561bb9dd61eef408c2 100644 |
| --- a/Source/platform/graphics/gpu/DrawingBuffer.cpp |
| +++ b/Source/platform/graphics/gpu/DrawingBuffer.cpp |
| @@ -32,6 +32,7 @@ |
| #include "platform/graphics/gpu/DrawingBuffer.h" |
| +#include "RuntimeEnabledFeatures.h" |
| #include <algorithm> |
| #include "platform/TraceEvent.h" |
| #include "platform/graphics/GraphicsLayer.h" |
| @@ -228,7 +229,8 @@ bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox, |
| // No buffer available to recycle, create a new one. |
| if (!frontColorBufferMailbox) { |
| - unsigned newColorBuffer = createColorTexture(m_size); |
| + unsigned newColorBuffer = createColorTexture(); |
| + allocateTextureMemory(newColorBuffer, m_size); |
| // Bad things happened, abandon ship. |
| if (!newColorBuffer) |
| return false; |
| @@ -262,6 +264,7 @@ bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox, |
| m_context->produceTextureCHROMIUM(GL_TEXTURE_2D, frontColorBufferMailbox->mailbox.name); |
| m_context->flush(); |
| frontColorBufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); |
| + frontColorBufferMailbox->mailbox.allowOverlay = m_textureToImageChromiumMap.find(frontColorBufferMailbox->textureId) != m_textureToImageChromiumMap.end(); |
| markLayerComposited(); |
| // set m_parentDrawingBuffer to make sure 'this' stays alive as long as it has live mailboxes |
| @@ -323,7 +326,7 @@ PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() |
| if (mailboxInfo->size != m_size) { |
| m_context->bindTexture(GL_TEXTURE_2D, mailboxInfo->textureId); |
| - texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, m_size.width(), m_size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
| + allocateTextureMemory(mailboxInfo->textureId, m_size); |
| mailboxInfo->size = m_size; |
| } |
| @@ -346,6 +349,9 @@ void DrawingBuffer::deleteMailbox(const blink::WebExternalTextureMailbox& mailbo |
| if (nameEquals(m_textureMailboxes[i]->mailbox, mailbox)) { |
| if (mailbox.syncPoint) |
| m_context->waitSyncPoint(mailbox.syncPoint); |
| + if (RuntimeEnabledFeatures::webGLImageChromiumEnabled()) |
| + deleteChromiumImageForTexture(m_textureMailboxes[i]->textureId); |
| + |
| m_context->deleteTexture(m_textureMailboxes[i]->textureId); |
| m_textureMailboxes.remove(i); |
| return; |
| @@ -530,7 +536,8 @@ void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) |
| // We have to make a copy of it here and bind that copy instead. |
| // FIXME: That's not true any more, provided we don't change texture |
| // parameters. |
| - unsigned sourceTexture = createColorTexture(m_size); |
| + unsigned sourceTexture = createColorTexture(); |
| + texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, m_size.width(), m_size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
| m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_frontColorBuffer, sourceTexture, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
| // Since we're using the same context as WebGL, we have to restore any state we change (in this case, just the framebuffer binding). |
| @@ -588,8 +595,12 @@ void DrawingBuffer::beginDestruction() |
| if (m_stencilBuffer) |
| m_context->deleteRenderbuffer(m_stencilBuffer); |
| - if (m_colorBuffer) |
| + if (m_colorBuffer) { |
| + if (RuntimeEnabledFeatures::webGLImageChromiumEnabled()) |
| + deleteChromiumImageForTexture(m_colorBuffer); |
| + |
| m_context->deleteTexture(m_colorBuffer); |
| + } |
| setSize(IntSize()); |
| @@ -607,7 +618,7 @@ void DrawingBuffer::beginDestruction() |
| GraphicsLayer::unregisterContentsLayer(m_layer->layer()); |
| } |
| -unsigned DrawingBuffer::createColorTexture(const IntSize& size) |
| +unsigned DrawingBuffer::createColorTexture() |
| { |
| unsigned offscreenColorTexture = m_context->createTexture(); |
| if (!offscreenColorTexture) |
| @@ -618,8 +629,6 @@ unsigned DrawingBuffer::createColorTexture(const IntSize& size) |
| m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| - if (!size.isEmpty()) |
| - texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, size.width(), size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
| return offscreenColorTexture; |
| } |
| @@ -641,7 +650,7 @@ bool DrawingBuffer::resizeFramebuffer(const IntSize& size) |
| m_context->bindTexture(GL_TEXTURE_2D, m_colorBuffer); |
| - texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, size.width(), size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
| + allocateTextureMemory(m_colorBuffer, size); |
| if (m_multisampleMode == ImplicitResolve) |
| m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0, m_sampleCount); |
| @@ -1020,4 +1029,31 @@ void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in |
| m_context->texImage2D(target, level, internalformat, width, height, border, format, type, 0); |
| } |
| +void DrawingBuffer::allocateTextureMemory(Platform3DObject textureId, const IntSize& size) |
| +{ |
| + if (RuntimeEnabledFeatures::webGLImageChromiumEnabled()) { |
| + deleteChromiumImageForTexture(textureId); |
| + |
| + blink::WGC3Duint newImage = m_context->createImageCHROMIUM(size.width(), size.height(), GL_RGBA8_OES, GC3D_IMAGE_SCANOUT_CHROMIUM); |
| + if (newImage) { |
|
Ken Russell (switch to Gerrit)
2014/05/14 22:11:33
Under what conditions will createImageCHROMIUM fai
alexst (slow to review)
2014/05/14 22:29:55
There may be a limit of memory available to scanou
|
| + m_context->bindTexImage2DCHROMIUM(GL_TEXTURE_2D, newImage); |
| + m_textureToImageChromiumMap.add(textureId, newImage); |
|
Ken Russell (switch to Gerrit)
2014/05/14 22:11:33
The bookkeeping associated with these ImageChromiu
alexst (slow to review)
2014/05/14 22:29:55
Let me have a look.
|
| + return; |
| + } |
| + } |
| + |
| + texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, size.width(), size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
| +} |
| + |
| +void DrawingBuffer::deleteChromiumImageForTexture(Platform3DObject textureId) |
| +{ |
| + HashMap<Platform3DObject, blink::WGC3Duint>::iterator imageIter = m_textureToImageChromiumMap.find(textureId); |
| + // Release the old buffer if we have any. |
| + if (imageIter != m_textureToImageChromiumMap.end()) { |
| + m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, imageIter->value); |
| + m_context->destroyImageCHROMIUM(imageIter->value); |
| + m_textureToImageChromiumMap.remove(imageIter); |
| + } |
| +} |
| + |
| } // namespace WebCore |