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..0932e14b8ee9480ceffe54706a823d35a7ad9f87 100644 |
--- a/Source/platform/graphics/gpu/DrawingBuffer.cpp |
+++ b/Source/platform/graphics/gpu/DrawingBuffer.cpp |
@@ -147,6 +147,11 @@ DrawingBuffer::DrawingBuffer(PassOwnPtr<blink::WebGraphicsContext3D> context, |
, m_sampleCount(0) |
, m_packAlignment(4) |
, m_destructionInProgress(false) |
+#ifdef ENABLE_WEBGL_IMAGE_CHROMIUM |
piman
2014/05/09 19:34:14
Why an ifdef? Should we, say, turn it on with a co
|
+ , m_useImageChromium(true) |
+#else |
+ , m_useImageChromium(false) |
+#endif |
, m_contextEvictionManager(contextEvictionManager) |
{ |
// Used by browser tests to detect the use of a DrawingBuffer. |
@@ -228,7 +233,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; |
@@ -323,7 +329,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 +352,9 @@ void DrawingBuffer::deleteMailbox(const blink::WebExternalTextureMailbox& mailbo |
if (nameEquals(m_textureMailboxes[i]->mailbox, mailbox)) { |
if (mailbox.syncPoint) |
m_context->waitSyncPoint(mailbox.syncPoint); |
+ if (m_useImageChromium) |
+ deleteChromiumImageForTexture(m_textureMailboxes[i]->textureId); |
+ |
m_context->deleteTexture(m_textureMailboxes[i]->textureId); |
m_textureMailboxes.remove(i); |
return; |
@@ -530,7 +539,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 +598,12 @@ void DrawingBuffer::beginDestruction() |
if (m_stencilBuffer) |
m_context->deleteRenderbuffer(m_stencilBuffer); |
- if (m_colorBuffer) |
+ if (m_colorBuffer) { |
+ if (m_useImageChromium) |
+ deleteChromiumImageForTexture(m_colorBuffer); |
+ |
m_context->deleteTexture(m_colorBuffer); |
+ } |
setSize(IntSize()); |
@@ -607,7 +621,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 +632,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 +653,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, m_size); |
if (m_multisampleMode == ImplicitResolve) |
m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0, m_sampleCount); |
@@ -1020,4 +1032,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 (m_useImageChromium) { |
+ deleteChromiumImageForTexture(textureId); |
+ |
+ blink::WGC3Duint newImage = m_context->createImageCHROMIUM(size.width(), size.height(), GL_RGBA8_OES, GC3D_IMAGE_SCANOUT_CHROMIUM); |
+ if (newImage) { |
+ m_context->bindTexImage2DCHROMIUM(GL_TEXTURE_2D, newImage); |
+ m_textureToImageChromiumMap.add(textureId, newImage); |
+ 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 |