Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Unified Diff: Source/platform/graphics/gpu/DrawingBuffer.cpp

Issue 274833002: Enable WebGL rendering into ImageCHROMIUM, backed by a scanout buffer to enable overlay suppor… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/graphics/gpu/DrawingBuffer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..02e838c204a5a5d52ece85851377f97edff6a14f 100644
--- a/Source/platform/graphics/gpu/DrawingBuffer.cpp
+++ b/Source/platform/graphics/gpu/DrawingBuffer.cpp
@@ -46,6 +46,8 @@
#include "wtf/RefCountedLeakCounter.h"
#endif
+#define ENABLE_WEBGL_IMAGE_CHROMIUM
+
using namespace std;
namespace WebCore {
@@ -228,7 +230,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 +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 defined(ENABLE_WEBGL_IMAGE_CHROMIUM)
+ deleteChromiumImageForTexture(m_textureMailboxes[i]->textureId);
+#endif
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 defined(ENABLE_WEBGL_IMAGE_CHROMIUM)
+ deleteChromiumImageForTexture(m_colorBuffer);
+#endif
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, m_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 defined(ENABLE_WEBGL_IMAGE_CHROMIUM)
+ deleteChromiumImageForTexture(textureId);
+
+ blink::WGC3Duint newImage = m_context->createImageCHROMIUM(size.width(), size.height(), GL_RGBA8_OES);
alexst (slow to review) 2014/05/08 18:00:50 This will have a scanout usage once deps roll.
+ if (newImage) {
+ m_context->bindTexImage2DCHROMIUM(GL_TEXTURE_2D, newImage);
+ m_textureToImageChromiumMap.add(textureId, newImage);
+ return;
+ }
+#endif
+
+ 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
« no previous file with comments | « Source/platform/graphics/gpu/DrawingBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698