[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

eric at webkit.org eric at webkit.org
Thu Apr 8 02:00:19 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit 97bf8e260b4b766e12c8711743df144042438506
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Feb 26 15:48:59 2010 +0000

    2010-02-26  Zhenyao Mo  <zmo at google.com>
    
            Reviewed by David Levin.
    
            texImage2D and texSubImage2D taking ImageData ignore flipY and premultiplyAlpha
            https://bugs.webkit.org/show_bug.cgi?id=34459
    
            * fast/canvas/webgl/tex-image-and-sub-image-2d-with-image-data-expected.txt: Added.
            * fast/canvas/webgl/tex-image-and-sub-image-2d-with-image-data.html: Added.
    2010-02-26  Zhenyao Mo  <zmo at google.com>
    
            Reviewed by David Levin.
    
            texImage2D and texSubImage2D taking ImageData ignore flipY and premultiplyAlpha
            https://bugs.webkit.org/show_bug.cgi?id=34459
    
            Test: fast/canvas/webgl/tex-image-and-sub-image-2d-with-image-data.html
    
            * html/canvas/WebGLRenderingContext.cpp:
            (WebCore::WebGLRenderingContext::texImage2D): Apply flipY and premultiplyAlpha to the texture data.
            (WebCore::WebGLRenderingContext::texSubImage2D): Ditto.
            * platform/graphics/GraphicsContext3D.cpp:
            (WebCore::GraphicsContext3D::extractImageData): Extract data from ImageData, applying flipY and premultiplyAlpha.
            * platform/graphics/GraphicsContext3D.h: Add function extractImageData declaration.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55283 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index c3417f6..646c429 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -2,6 +2,16 @@
 
         Reviewed by David Levin.
 
+        texImage2D and texSubImage2D taking ImageData ignore flipY and premultiplyAlpha
+        https://bugs.webkit.org/show_bug.cgi?id=34459
+
+        * fast/canvas/webgl/tex-image-and-sub-image-2d-with-image-data-expected.txt: Added.
+        * fast/canvas/webgl/tex-image-and-sub-image-2d-with-image-data.html: Added.
+
+2010-02-26  Zhenyao Mo  <zmo at google.com>
+
+        Reviewed by David Levin.
+
         Set viewport to canvas size upon context creation
         https://bugs.webkit.org/show_bug.cgi?id=35057
 
diff --git a/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-image-data-expected.txt b/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-image-data-expected.txt
new file mode 100644
index 0000000..2285e81
--- /dev/null
+++ b/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-image-data-expected.txt
@@ -0,0 +1,50 @@
+ 
+Verify texImage2D and texSubImage2D code paths taking ImageData, in particular flipY and premultiplyAlpha argument
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Regression test for https://bugs.webkit.org/show_bug.cgi?id=34459 : Refactor texImage2D and texSubImage2D taking ImageData to use common code
+Testing texImage2D with flipY=true and premultiplyAlpha=false
+Checking bottom pixel
+PASS pixel is correctColor
+Checking top pixel
+PASS pixel is correctColor
+Testing texImage2D with flipY=false and premultiplyAlpha=false
+Checking bottom pixel
+PASS pixel is correctColor
+Checking top pixel
+PASS pixel is correctColor
+Testing texImage2D with flipY=true and premultiplyAlpha=true
+Checking bottom pixel
+PASS pixel is correctColor
+Checking top pixel
+PASS pixel is correctColor
+Testing texImage2D with flipY=false and premultiplyAlpha=true
+Checking bottom pixel
+PASS pixel is correctColor
+Checking top pixel
+PASS pixel is correctColor
+Testing texSubImage2D with flipY=true and premultiplyAlpha=false
+Checking bottom pixel
+PASS pixel is correctColor
+Checking top pixel
+PASS pixel is correctColor
+Testing texSubImage2D with flipY=false and premultiplyAlpha=false
+Checking bottom pixel
+PASS pixel is correctColor
+Checking top pixel
+PASS pixel is correctColor
+Testing texSubImage2D with flipY=true and premultiplyAlpha=true
+Checking bottom pixel
+PASS pixel is correctColor
+Checking top pixel
+PASS pixel is correctColor
+Testing texSubImage2D with flipY=false and premultiplyAlpha=true
+Checking bottom pixel
+PASS pixel is correctColor
+Checking top pixel
+PASS pixel is correctColor
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-image-data.html b/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-image-data.html
new file mode 100644
index 0000000..32be49e
--- /dev/null
+++ b/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-image-data.html
@@ -0,0 +1,201 @@
+<html>
+<head>
+<link rel="stylesheet" href="../../js/resources/js-test-style.css"/>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script src="resources/webgl-test.js"></script>
+<script src="resources/utils3d.js"> </script>
+<script id="vshader" type="x-shader/x-vertex">
+attribute vec3 g_Position;
+attribute vec2 g_TexCoord0;
+
+varying vec2 texCoord;
+
+void main()
+{
+    gl_Position = vec4(g_Position.x, g_Position.y, g_Position.z, 1.0);
+    texCoord = g_TexCoord0;
+}
+</script>
+
+<script id="fshader" type="x-shader/x-fragment">
+uniform sampler2D tex;
+varying vec2 texCoord;
+
+void main()
+{
+    gl_FragColor = texture2D(tex, texCoord);
+}
+</script>
+
+<script>
+var gl = null;
+var textureLoc = null;
+var successfullyParsed = false;
+var imageData = null;
+
+function init()
+{
+    if (window.layoutTestController) {
+        layoutTestController.overridePreference("WebKitWebGLEnabled", "1");
+        layoutTestController.dumpAsText();
+        layoutTestController.waitUntilDone();
+    }
+
+    description('Verify texImage2D and texSubImage2D code paths taking ImageData, in particular flipY and premultiplyAlpha argument');
+
+    debug('Regression test for <a href="https://bugs.webkit.org/show_bug.cgi?id=34459">https://bugs.webkit.org/show_bug.cgi?id=34459</a> : <code>Refactor texImage2D and texSubImage2D taking ImageData to use common code</code>');
+
+    var canvas2d = document.getElementById("texcanvas");
+    var context2d = canvas2d.getContext("2d");
+    imageData = context2d.createImageData(1, 2);
+    var data = imageData.data;
+    data[0] = 255;
+    data[1] = 0;
+    data[2] = 0;
+    data[3] = 255;
+    data[4] = 0;
+    data[5] = 255;
+    data[6] = 0;
+    data[7] = 0;
+
+    gl = initWebGL("example", "vshader", "fshader", [ "g_Position", "g_TexCoord0" ], [ 0, 0, 0, 1 ], 1);
+    gl.viewport(0, 0, 1, 2);
+    gl.disable(gl.BLEND);
+
+    textureLoc = gl.getUniformLocation(gl.program, "tex");
+
+    var vertices = new WebGLFloatArray([
+         1.0,  1.0, 0.0,
+        -1.0,  1.0, 0.0,
+        -1.0, -1.0, 0.0,
+         1.0,  1.0, 0.0,
+        -1.0, -1.0, 0.0,
+         1.0, -1.0, 0.0]);
+    var texCoords = new WebGLFloatArray([
+        1.0, 1.0,
+        0.0, 1.0,
+        0.0, 0.0,
+        1.0, 1.0,
+        0.0, 0.0,
+        1.0, 0.0]);
+    var texCoordOffset = vertices.byteLength;
+
+    var vbo = gl.createBuffer();
+    gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
+    gl.bufferData(gl.ARRAY_BUFFER,
+                  texCoordOffset + texCoords.byteLength,
+                  gl.STATIC_DRAW);
+    gl.bufferSubData(gl.ARRAY_BUFFER, 0, vertices);
+    gl.bufferSubData(gl.ARRAY_BUFFER, texCoordOffset, texCoords);
+
+    gl.enableVertexAttribArray(0);
+    gl.vertexAttribPointer(0, 3, gl.FLOAT, gl.FALSE, 0, 0);
+    gl.enableVertexAttribArray(1);
+    gl.vertexAttribPointer(1, 2, gl.FLOAT, gl.FALSE, 0, texCoordOffset);
+
+    runTest();
+}
+
+// These two declarations need to be global for "shouldBe" to see them
+var buf = null;
+var idx = 0;
+var pixel = [0, 0, 0, 1];
+var correctColor = null;
+
+function runOneIteration(useTexSubImage2D, flipY, premultiplyAlpha, topColor, bottomColor)
+{
+    debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') +
+          ' with flipY=' + flipY + ' and premultiplyAlpha=' + premultiplyAlpha);
+    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+    // Enable writes to the RGBA channels
+    gl.colorMask(1, 1, 1, 0);
+    var texture = gl.createTexture();
+    // Bind the texture to texture unit 0
+    gl.bindTexture(gl.TEXTURE_2D, texture);
+    // Set up texture parameters
+    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
+    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
+    // Upload the image into the texture
+    if (useTexSubImage2D) {
+        // Initialize the texture to black first
+        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 2, 0,
+                      gl.RGBA, gl.UNSIGNED_BYTE, null);
+        gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, imageData,
+                         flipY, premultiplyAlpha);
+    } else {
+        gl.texImage2D(gl.TEXTURE_2D, 0, imageData,
+                      flipY, premultiplyAlpha);
+    }
+
+    // Point the uniform sampler to texture unit 0
+    gl.uniform1i(textureLoc, 0);
+    // Draw the triangles
+    gl.drawArrays(gl.TRIANGLES, 0, 6);
+
+    // Read back the rendering results
+    buf = gl.readPixels(0, 0, 1, 2, gl.RGBA, gl.UNSIGNED_BYTE);
+    // Check the top pixel and bottom pixel and make sure they have
+    // the right color.
+    debug("Checking bottom pixel");
+    correctColor = bottomColor;
+    idx = 0;
+    pixel[0] = buf[idx];
+    pixel[1] = buf[idx + 1];
+    pixel[2] = buf[idx + 2];
+    pixel[3] = buf[idx + 3];
+    shouldBe("pixel", "correctColor");
+    debug("Checking top pixel");
+    correctColor = topColor;
+    idx = 4;
+    pixel[0] = buf[idx];
+    pixel[1] = buf[idx + 1];
+    pixel[2] = buf[idx + 2];
+    pixel[3] = buf[idx + 3];
+    shouldBe("pixel", "correctColor");
+}
+
+function runTest()
+{
+    var red = [255, 0, 0, 255];
+    var green = [0, 255, 0, 255];
+    var redPremultiplyAlpha = [255, 0, 0, 255];
+    var greenPremultiplyAlpha = [0, 0, 0, 255];
+
+    runOneIteration(false, true, false,
+                    red, green);
+    runOneIteration(false, false, false,
+                    green, red);
+    runOneIteration(false, true, true,
+                    redPremultiplyAlpha, greenPremultiplyAlpha);
+    runOneIteration(false, false, true,
+                    greenPremultiplyAlpha, redPremultiplyAlpha);
+    runOneIteration(true, true, false,
+                    red, green);
+    runOneIteration(true, false, false,
+                    green, red);
+    runOneIteration(true, true, true,
+                    redPremultiplyAlpha, greenPremultiplyAlpha);
+    runOneIteration(true, false, true,
+                    greenPremultiplyAlpha, redPremultiplyAlpha);
+
+    successfullyParsed = true;
+    var epilogue = document.createElement("script");
+    epilogue.onload = finish;
+    epilogue.src = "../../js/resources/js-test-post.js";
+    document.body.appendChild(epilogue);
+}
+
+function finish() {
+    if (window.layoutTestController) {
+        layoutTestController.notifyDone();
+    }
+}
+</script>
+</head>
+<body onload="init()">
+<canvas id="texcanvas" width="1px" height="2px"></canvas>
+<canvas id="example" width="1px" height="2px"></canvas>
+<div id="description"></div>
+<div id="console"></div>
+</body>
+</html>
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index a51b302..2045ef2 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -2,6 +2,22 @@
 
         Reviewed by David Levin.
 
+        texImage2D and texSubImage2D taking ImageData ignore flipY and premultiplyAlpha
+        https://bugs.webkit.org/show_bug.cgi?id=34459
+
+        Test: fast/canvas/webgl/tex-image-and-sub-image-2d-with-image-data.html
+
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore::WebGLRenderingContext::texImage2D): Apply flipY and premultiplyAlpha to the texture data.
+        (WebCore::WebGLRenderingContext::texSubImage2D): Ditto.
+        * platform/graphics/GraphicsContext3D.cpp:
+        (WebCore::GraphicsContext3D::extractImageData): Extract data from ImageData, applying flipY and premultiplyAlpha.
+        * platform/graphics/GraphicsContext3D.h: Add function extractImageData declaration.
+
+2010-02-26  Zhenyao Mo  <zmo at google.com>
+
+        Reviewed by David Levin.
+
         Set viewport to canvas size upon context creation
         https://bugs.webkit.org/show_bug.cgi?id=35057
 
diff --git a/WebCore/html/canvas/WebGLRenderingContext.cpp b/WebCore/html/canvas/WebGLRenderingContext.cpp
index 118d734..e258a61 100644
--- a/WebCore/html/canvas/WebGLRenderingContext.cpp
+++ b/WebCore/html/canvas/WebGLRenderingContext.cpp
@@ -1635,12 +1635,10 @@ void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, ImageDat
                                        bool flipY, bool premultiplyAlpha, ExceptionCode& ec)
 {
     // FIXME: For now we ignore any errors returned
-    // FIXME: Need a form of this call that can take both a pixel buffer and flipY and premultiplyAlpha flags
-    UNUSED_PARAM(flipY);
-    UNUSED_PARAM(premultiplyAlpha);
     ec = 0;
-    m_context->texImage2D(target, level, GraphicsContext3D::RGBA, pixels->width(), pixels->height(), 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, pixels->data()->data()->data());
-    //RLP: m_context->texImage2D(target, level, pixels, flipY, premultiplyAlpha);
+    Vector<uint8_t> data;
+    m_context->extractImageData(pixels, flipY, premultiplyAlpha, data);
+    m_context->texImage2D(target, level, GraphicsContext3D::RGBA, pixels->width(), pixels->height(), 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, data.data());
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1725,11 +1723,10 @@ void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsig
                                           ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode& ec)
 {
     // FIXME: For now we ignore any errors returned
-    UNUSED_PARAM(flipY);
-    UNUSED_PARAM(premultiplyAlpha);
     ec = 0;
-    m_context->texSubImage2D(target, level, xoffset, yoffset, pixels->width(), pixels->height(), GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, pixels->data()->data()->data());
-    //RLP: m_context->texSubImage2D(target, level, xoffset, yoffset, pixels, flipY, premultiplyAlpha);
+    Vector<uint8_t> data;
+    m_context->extractImageData(pixels, flipY, premultiplyAlpha, data);
+    m_context->texSubImage2D(target, level, xoffset, yoffset, pixels->width(), pixels->height(), GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, data.data());
     cleanupAfterGraphicsCall(false);
 }
 
diff --git a/WebCore/platform/graphics/GraphicsContext3D.cpp b/WebCore/platform/graphics/GraphicsContext3D.cpp
index 3eb9818..97465e2 100644
--- a/WebCore/platform/graphics/GraphicsContext3D.cpp
+++ b/WebCore/platform/graphics/GraphicsContext3D.cpp
@@ -31,6 +31,7 @@
 #include "GraphicsContext3D.h"
 
 #include "Image.h"
+#include "ImageData.h"
 
 namespace WebCore {
 
@@ -57,6 +58,28 @@ bool GraphicsContext3D::extractImageData(Image* image,
     return true;
 }
 
+bool GraphicsContext3D::extractImageData(ImageData* imageData,
+                                         bool flipY,
+                                         bool premultiplyAlpha,
+                                         Vector<uint8_t>& data)
+{
+    if (!imageData)
+        return false;
+    int width = imageData->width();
+    int height = imageData->height();
+    int dataBytes = width * height * 4;
+    data.resize(dataBytes);
+    uint8_t* dst = data.data();
+    uint8_t* src = imageData->data()->data()->data();
+    memcpy(dst, src, dataBytes);
+    processImageData(dst,
+                     width,
+                     height,
+                     flipY,
+                     premultiplyAlpha ? kAlphaDoPremultiply : kAlphaDoNothing);
+    return true;
+}
+
 void GraphicsContext3D::processImageData(uint8_t* imageData,
                                          unsigned width,
                                          unsigned height,
diff --git a/WebCore/platform/graphics/GraphicsContext3D.h b/WebCore/platform/graphics/GraphicsContext3D.h
index cf1df70..3acbebf 100644
--- a/WebCore/platform/graphics/GraphicsContext3D.h
+++ b/WebCore/platform/graphics/GraphicsContext3D.h
@@ -72,6 +72,7 @@ namespace WebCore {
     class WebGLShader;
     class WebGLTexture;
     class Image;
+    class ImageData;
 
     struct ActiveInfo {
         String name;
@@ -445,6 +446,14 @@ namespace WebCore {
                               unsigned int* format,
                               unsigned int* internalFormat);
 
+        // Extracts the contents of the given ImageData into the passed
+        // Vector, obeying the flipY and premultiplyAlpha flags.
+        // Returns true upon success.
+        bool extractImageData(ImageData*,
+                              bool flipY,
+                              bool premultiplyAlpha,
+                              Vector<uint8_t>& data);
+
         // Processes the given image data in preparation for uploading
         // via texImage2D or texSubImage2D. The input data must be in
         // 4-component format with the alpha channel last (i.e., RGBA

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list