Title: [189730] releases/WebKitGTK/webkit-2.10/Source/WebCore
Revision
189730
Author
carlo...@webkit.org
Date
2015-09-14 06:59:52 -0700 (Mon, 14 Sep 2015)

Log Message

Merge r189216 - [Cairo][WebGL] Upload the accelerated canvas as a texture by copying via GPU directly
https://bugs.webkit.org/show_bug.cgi?id=148631

Patch by Jinyoung Hur <hur....@navercorp.com> on 2015-09-01
Reviewed by Dean Jackson.

When an accelerated canvas needs to be uploaded as a gl texture, it would be better to copy it to
texture directly via GPU using glCopyTexImage2D.
Note that GPU copy can not always be enabled because, with premultiplyAlpha and flipY unpack option,
it seems hard to be implemented in a way of direct GPU copy.

No new tests because there is no behavior change.

* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::texImage2D):
* platform/graphics/ImageBuffer.cpp:
(WebCore::ImageBuffer::copyToPlatformTexture):
* platform/graphics/ImageBuffer.h:
* platform/graphics/cairo/ImageBufferCairo.cpp:
(WebCore::ImageBuffer::copyToPlatformTexture):

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog (189729 => 189730)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog	2015-09-14 13:55:15 UTC (rev 189729)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog	2015-09-14 13:59:52 UTC (rev 189730)
@@ -1,3 +1,25 @@
+2015-09-01  Jinyoung Hur  <hur....@navercorp.com>
+
+        [Cairo][WebGL] Upload the accelerated canvas as a texture by copying via GPU directly
+        https://bugs.webkit.org/show_bug.cgi?id=148631
+
+        Reviewed by Dean Jackson.
+
+        When an accelerated canvas needs to be uploaded as a gl texture, it would be better to copy it to 
+        texture directly via GPU using glCopyTexImage2D. 
+        Note that GPU copy can not always be enabled because, with premultiplyAlpha and flipY unpack option,
+        it seems hard to be implemented in a way of direct GPU copy.
+
+        No new tests because there is no behavior change.
+
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::texImage2D):
+        * platform/graphics/ImageBuffer.cpp:
+        (WebCore::ImageBuffer::copyToPlatformTexture):
+        * platform/graphics/ImageBuffer.h:
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        (WebCore::ImageBuffer::copyToPlatformTexture):
+
 2015-08-31  Chris Dumez  <cdu...@apple.com>
 
         NodeFilter.SHOW_ALL has wrong value on 32-bit

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (189729 => 189730)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2015-09-14 13:55:15 UTC (rev 189729)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2015-09-14 13:59:52 UTC (rev 189730)
@@ -3219,10 +3219,12 @@
     //
     // FIXME: restriction of (RGB || RGBA)/UNSIGNED_BYTE should be lifted when
     // ImageBuffer::copyToPlatformTexture implementations are fully functional.
-    if (GraphicsContext3D::TEXTURE_2D == target && texture && type == texture->getType(target, level)
-        && (format == GraphicsContext3D::RGB || format == GraphicsContext3D::RGBA) && type == GraphicsContext3D::UNSIGNED_BYTE) {
+    if (texture
+        && (format == GraphicsContext3D::RGB || format == GraphicsContext3D::RGBA)
+        && type == GraphicsContext3D::UNSIGNED_BYTE
+        && (texture->getType(target, level) == GraphicsContext3D::UNSIGNED_BYTE || !texture->isValid(target, level))) {
         ImageBuffer* buffer = canvas->buffer();
-        if (buffer && buffer->copyToPlatformTexture(*m_context.get(), texture->object(), internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
+        if (buffer && buffer->copyToPlatformTexture(*m_context.get(), target, texture->object(), internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
             texture->setLevelInfo(target, level, internalformat, canvas->width(), canvas->height(), type);
             return;
         }

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/graphics/ImageBuffer.cpp (189729 => 189730)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/graphics/ImageBuffer.cpp	2015-09-14 13:55:15 UTC (rev 189729)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/graphics/ImageBuffer.cpp	2015-09-14 13:59:52 UTC (rev 189730)
@@ -151,12 +151,12 @@
 {
     return 0;
 }
-#endif
 
-bool ImageBuffer::copyToPlatformTexture(GraphicsContext3D&, Platform3DObject, GC3Denum, bool, bool)
+bool ImageBuffer::copyToPlatformTexture(GraphicsContext3D&, GC3Denum, Platform3DObject, GC3Denum, bool, bool)
 {
     return false;
 }
+#endif
 
 std::unique_ptr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const FloatSize& size, float resolutionScale, ColorSpace colorSpace, const GraphicsContext* context, bool)
 {

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/graphics/ImageBuffer.h (189729 => 189730)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/graphics/ImageBuffer.h	2015-09-14 13:55:15 UTC (rev 189729)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/graphics/ImageBuffer.h	2015-09-14 13:59:52 UTC (rev 189730)
@@ -122,7 +122,7 @@
 
     // FIXME: current implementations of this method have the restriction that they only work
     // with textures that are RGB or RGBA format, and UNSIGNED_BYTE type.
-    bool copyToPlatformTexture(GraphicsContext3D&, Platform3DObject, GC3Denum, bool, bool);
+    bool copyToPlatformTexture(GraphicsContext3D&, GC3Denum, Platform3DObject, GC3Denum, bool, bool);
 
     FloatSize spaceSize() const { return m_space; }
     void setSpaceSize(const FloatSize& space) { m_space = space; }

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp (189729 => 189730)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2015-09-14 13:55:15 UTC (rev 189729)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2015-09-14 13:59:52 UTC (rev 189730)
@@ -431,6 +431,57 @@
     return 0;
 }
 
+bool ImageBuffer::copyToPlatformTexture(GraphicsContext3D&, GC3Denum target, Platform3DObject destinationTexture, GC3Denum internalformat, bool premultiplyAlpha, bool flipY)
+{
+#if ENABLE(ACCELERATED_2D_CANVAS)
+    if (premultiplyAlpha || flipY)
+        return false;
+
+    if (!m_data.m_texture)
+        return false;
+
+    GC3Denum bindTextureTarget;
+    switch (target) {
+    case GL_TEXTURE_2D:
+        bindTextureTarget = GL_TEXTURE_2D;
+        break;
+    case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+    case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+    case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+    case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+    case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+    case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+        bindTextureTarget = GL_TEXTURE_CUBE_MAP;
+        break;
+    default:
+        return false;
+    }
+
+    cairo_surface_flush(m_data.m_surface.get());
+
+    std::unique_ptr<GLContext> context = GLContext::createContextForWindow(0, GLContext::sharingContext());
+    context->makeContextCurrent();
+    uint32_t fbo;
+    glGenFramebuffers(1, &fbo);
+    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_data.m_texture, 0);
+    glBindTexture(bindTextureTarget, destinationTexture);
+    glCopyTexImage2D(target, 0, internalformat, 0, 0, m_size.width(), m_size.height(), 0);
+    glBindTexture(bindTextureTarget, 0);
+    glBindFramebuffer(GL_FRAMEBUFFER, 0);
+    glFlush();
+    glDeleteFramebuffers(1, &fbo);
+    return true;
+#else
+    UNUSED_PARAM(target);
+    UNUSED_PARAM(destinationTexture);
+    UNUSED_PARAM(internalformat);
+    UNUSED_PARAM(premultiplyAlpha);
+    UNUSED_PARAM(flipY);
+    return false;
+#endif
+}
+
 } // namespace WebCore
 
 #endif // USE(CAIRO)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to