Title: [140595] trunk/Source/WebCore
Revision
140595
Author
[email protected]
Date
2013-01-23 14:26:38 -0800 (Wed, 23 Jan 2013)

Log Message

Avoid unnecessary format conversion for tex{Sub}Image2D() for ImageData of WebGL
https://bugs.webkit.org/show_bug.cgi?id=107532

Patch by Jun Jiang <[email protected]> on 2013-01-23
Reviewed by Kenneth Russell.

This patch removes the unnecessary format conversion in tex{Sub}Image2D() for ImageData in WebGL to improve performance.

Already covered by current tests.

* html/canvas/WebGLRenderingContext.cpp:
(WebCore):
(WebCore::WebGLRenderingContext::texImage2D):
(WebCore::WebGLRenderingContext::texSubImage2D):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (140594 => 140595)


--- trunk/Source/WebCore/ChangeLog	2013-01-23 22:25:07 UTC (rev 140594)
+++ trunk/Source/WebCore/ChangeLog	2013-01-23 22:26:38 UTC (rev 140595)
@@ -1,3 +1,19 @@
+2013-01-23  Jun Jiang  <[email protected]>
+
+        Avoid unnecessary format conversion for tex{Sub}Image2D() for ImageData of WebGL
+        https://bugs.webkit.org/show_bug.cgi?id=107532
+
+        Reviewed by Kenneth Russell.
+
+        This patch removes the unnecessary format conversion in tex{Sub}Image2D() for ImageData in WebGL to improve performance.
+
+        Already covered by current tests.
+
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore):
+        (WebCore::WebGLRenderingContext::texImage2D):
+        (WebCore::WebGLRenderingContext::texSubImage2D):
+
 2013-01-23  Xianzhu Wang  <[email protected]>
 
         Should update compositing state when an out-of-view fixed position element becomes in-view

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp (140594 => 140595)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp	2013-01-23 22:25:07 UTC (rev 140594)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp	2013-01-23 22:26:38 UTC (rev 140595)
@@ -3700,14 +3700,22 @@
     if (isContextLost())
         return;
     Vector<uint8_t> data;
-    if (!m_context->extractImageData(pixels, format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
-        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "bad image data");
+    if (!pixels)
         return;
+    bool needConversion = true;
+    // The data from ImageData is always of format RGBA8.
+    // No conversion is needed if destination format is RGBA and type is USIGNED_BYTE and no Flip or Premultiply operation is required.
+    if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GraphicsContext3D::RGBA && type == GraphicsContext3D::UNSIGNED_BYTE)
+        needConversion = false;
+    else {
+        if (!m_context->extractImageData(pixels, format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
+            synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "bad image data");
+            return;
+        }
     }
     if (m_unpackAlignment != 1)
         m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1);
-    texImage2DBase(target, level, internalformat, pixels->width(), pixels->height(), 0,
-                   format, type, data.data(), ec);
+    texImage2DBase(target, level, internalformat, pixels->width(), pixels->height(), 0, format, type, needConversion ? data.data() : pixels->data()->data(), ec);
     if (m_unpackAlignment != 1)
         m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlignment);
 }
@@ -3942,15 +3950,23 @@
     ec = 0;
     if (isContextLost())
         return;
+    if (!pixels)
+        return;
     Vector<uint8_t> data;
-    if (!m_context->extractImageData(pixels, format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
-        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "bad image data");
-        return;
+    bool needConversion = true;
+    // The data from ImageData is always of format RGBA8.
+    // No conversion is needed if destination format is RGBA and type is USIGNED_BYTE and no Flip or Premultiply operation is required.
+    if (format == GraphicsContext3D::RGBA && type == GraphicsContext3D::UNSIGNED_BYTE && !m_unpackFlipY && !m_unpackPremultiplyAlpha)
+        needConversion = false;
+    else {
+        if (!m_context->extractImageData(pixels, format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
+            synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "bad image data");
+            return;
+        }
     }
     if (m_unpackAlignment != 1)
         m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1);
-    texSubImage2DBase(target, level, xoffset, yoffset, pixels->width(), pixels->height(),
-                      format, type, data.data(), ec);
+    texSubImage2DBase(target, level, xoffset, yoffset, pixels->width(), pixels->height(), format, type, needConversion ? data.data() : pixels->data()->data(), ec);
     if (m_unpackAlignment != 1)
         m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlignment);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to