[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.15.1-1414-gc69ee75

cmarrin at apple.com cmarrin at apple.com
Thu Oct 29 20:43:25 UTC 2009


The following commit has been merged in the webkit-1.1 branch:
commit 6846b038e1f900e8704eaf07289627e0fcd2a170
Author: cmarrin at apple.com <cmarrin at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Oct 12 20:00:42 2009 +0000

            Added automatic flush before compositing
            https://bugs.webkit.org/show_bug.cgi?id=30236
    
            This causes image to always render correctly. In writing a testcase
            I needed to implement readPixels. This exposed a bug in reading back
            values from a CanvasArray subclass, so I fixed that as well. Now when
            you wrap a CanvasArray in a JSValue it actually wraps the specific
            subclass. To do this I need to add virtual methods to each CanvasArray
            subclass to determine the type and a custom toJS method for CanvasArray
            to create the proper wrapper.
    
            Test: fast/canvas/webgl/triangle.html
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@49447 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 2cf7fea..8d18669 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,18 @@
+2009-10-12  Chris Marrin  <cmarrin at apple.com>
+
+        Reviewed by Oliver Hunt.
+
+        Added test case for bug
+        https://bugs.webkit.org/show_bug.cgi?id=30236
+
+        This test case draws a simple triangle, does a readPixels and looks at some pixels
+        to verify that the triangle rendered.
+
+        * fast/canvas/webgl/resources: Added.
+        * fast/canvas/webgl/resources/utils3d.js: Added.
+        * fast/canvas/webgl/triangle-expected.txt: Added.
+        * fast/canvas/webgl/triangle.html: Added.
+
 2009-10-12  Jan Michael Alonzo  <jmalonzo at webkit.org>
 
         Reviewed by Xan Lopez.
diff --git a/WebKitSite/blog-files/webgl/resources/utils3d.js b/LayoutTests/fast/canvas/webgl/resources/utils3d.js
similarity index 100%
copy from WebKitSite/blog-files/webgl/resources/utils3d.js
copy to LayoutTests/fast/canvas/webgl/resources/utils3d.js
diff --git a/LayoutTests/fast/canvas/webgl/triangle-expected.txt b/LayoutTests/fast/canvas/webgl/triangle-expected.txt
new file mode 100644
index 0000000..883063e
--- /dev/null
+++ b/LayoutTests/fast/canvas/webgl/triangle-expected.txt
@@ -0,0 +1 @@
+Test PASSED
diff --git a/LayoutTests/fast/canvas/webgl/triangle.html b/LayoutTests/fast/canvas/webgl/triangle.html
new file mode 100644
index 0000000..613940b
--- /dev/null
+++ b/LayoutTests/fast/canvas/webgl/triangle.html
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Spinning Box</title>
+    <script src="resources/utils3d.js"> </script>
+    <script id="vshader" type="x-shader/x-vertex">
+        attribute vec4 vPosition;
+        void main()
+        {
+            gl_Position = vPosition;
+        }
+    </script>
+
+    <script id="fshader" type="x-shader/x-fragment">
+        void main()
+        {
+            gl_FragColor = vec4(1.0,0.0,0.0,1.0);
+        }
+    </script>
+
+    <script>
+        function fail(x,y, buf, shouldBe)
+        {
+            var i = (y*50+x) * 4;
+            var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe;
+            document.getElementById("results").innerHTML = "Test <span style='color:red'>FAILED</span> "+reason;
+        }
+        
+        function pass()
+        {
+            document.getElementById("results").innerHTML = "Test <span style='color:green'>PASSED</span>";
+        }
+        
+        function init()
+        {
+            if (window.layoutTestController) {
+                layoutTestController.overridePreference("WebKitWebGLEnabled", "1");
+                layoutTestController.dumpAsText();
+            }
+            
+            gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0, 0, 0, 1 ], 1);
+            gl.viewport(0, 0, 50, 50);
+            
+            var vertexObject = gl.createBuffer();
+            gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
+            gl.bufferData(gl.ARRAY_BUFFER, new CanvasFloatArray([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
+            gl.enableVertexAttribArray(0);
+            gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
+            
+            gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+            gl.drawArrays(gl.TRIANGLES, 0, 3);
+            
+            var buf = gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE);
+            
+            // Test several locations
+            // First line should be all black
+            for (var i = 0; i < 50; ++i)
+                if (buf[i*4] != 0 || buf[i*4+1] != 0 || buf[i*4+2] != 0 || buf[i*4+3] != 255) {
+                    fail(i, 0, buf, "(0,0,0,255)");
+                    return;
+                }
+                
+            // Line 15 should be red for at least 10 red pixels starting 20 pixels in
+            var offset = (15*50+20) * 4;
+            for (var i = 0; i < 10; ++i)
+                if (buf[offset+i*4] != 255 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) {
+                    fail(20, 15, buf, "(255,0,0,255)");
+                    return;
+                }
+            // Last line should be all black
+            offset = (49*50) * 4
+            for (var i = 0; i < 50; ++i)
+                if (buf[offset+i*4] != 0 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) {
+                    fail(i, 49, buf, "(0,0,0,255)");
+                    return;
+                }
+                
+            pass();
+       }
+    </script>
+  </head>
+  <body onload="init()">
+    <canvas id="example" width="50px" height="50px">
+    There is supposed to be an example drawing here, but it's not important.
+    </canvas>
+    <div id="results">Test <span style="color:red">FAILED</span></div>
+  </body>
+</html>
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index d9084b4..2df2a1d 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,56 @@
+2009-10-12  Chris Marrin  <cmarrin at apple.com>
+
+        Reviewed by Oliver Hunt.
+
+        Added automatic flush before compositing
+        https://bugs.webkit.org/show_bug.cgi?id=30236
+
+        This causes image to always render correctly. In writing a testcase
+        I needed to implement readPixels. This exposed a bug in reading back
+        values from a CanvasArray subclass, so I fixed that as well. Now when
+        you wrap a CanvasArray in a JSValue it actually wraps the specific
+        subclass. To do this I need to add virtual methods to each CanvasArray
+        subclass to determine the type and a custom toJS method for CanvasArray
+        to create the proper wrapper. 
+
+        Test: fast/canvas/webgl/triangle.html
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSCanvasArrayCustom.cpp:
+        (WebCore::toJS):
+        * html/canvas/CanvasArray.h:
+        (WebCore::CanvasArray::isByteArray):
+        (WebCore::CanvasArray::isUnsignedByteArray):
+        (WebCore::CanvasArray::isShortArray):
+        (WebCore::CanvasArray::isUnsignedShortArray):
+        (WebCore::CanvasArray::isIntArray):
+        (WebCore::CanvasArray::isUnsignedIntArray):
+        (WebCore::CanvasArray::isFloatArray):
+        * html/canvas/CanvasArray.idl:
+        * html/canvas/CanvasByteArray.h:
+        (WebCore::CanvasByteArray::isByteArray):
+        * html/canvas/CanvasFloatArray.h:
+        (WebCore::CanvasFloatArray::isFloatArray):
+        * html/canvas/CanvasIntArray.h:
+        (WebCore::CanvasIntArray::isIntArray):
+        * html/canvas/CanvasRenderingContext3D.cpp:
+        (WebCore::CanvasRenderingContext3D::readPixels):
+        * html/canvas/CanvasRenderingContext3D.h:
+        * html/canvas/CanvasRenderingContext3D.idl:
+        * html/canvas/CanvasShortArray.h:
+        (WebCore::CanvasShortArray::isShortArray):
+        * html/canvas/CanvasUnsignedByteArray.h:
+        (WebCore::CanvasUnsignedByteArray::isUnsignedByteArray):
+        * html/canvas/CanvasUnsignedIntArray.h:
+        (WebCore::CanvasUnsignedIntArray::isUnsignedIntArray):
+        * html/canvas/CanvasUnsignedShortArray.h:
+        (WebCore::CanvasUnsignedShortArray::isUnsignedShortArray):
+        * platform/graphics/GraphicsContext3D.h:
+        * platform/graphics/mac/Canvas3DLayer.mm:
+        (-[Canvas3DLayer drawInCGLContext:pixelFormat:forLayerTime:displayTime:]):
+        * platform/graphics/mac/GraphicsContext3DMac.cpp:
+        (WebCore::GraphicsContext3D::readPixels):
+
 2009-10-12  Sebastian Dröge  <sebastian.droege at collabora.co.uk>
 
         Reviewed by Gustavo Noronha.
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index 56b391d..358f759 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -758,6 +758,7 @@
 		46F9D5DD0B0D60170028EE36 /* aliasCursor.png in Resources */ = {isa = PBXBuildFile; fileRef = 46F9D5DA0B0D60170028EE36 /* aliasCursor.png */; };
 		46F9D5DE0B0D60170028EE36 /* noDropCursor.png in Resources */ = {isa = PBXBuildFile; fileRef = 46F9D5DB0B0D60170028EE36 /* noDropCursor.png */; };
 		46F9D5DF0B0D60170028EE36 /* progressCursor.png in Resources */ = {isa = PBXBuildFile; fileRef = 46F9D5DC0B0D60170028EE36 /* progressCursor.png */; };
+		492273A31083B3B100EE5C84 /* JSCanvasArrayCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 492273A21083B3B100EE5C84 /* JSCanvasArrayCustom.cpp */; };
 		49484FC1102CF23C00187DD3 /* CanvasGradient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49484FB3102CF23C00187DD3 /* CanvasGradient.cpp */; };
 		49484FC2102CF23C00187DD3 /* CanvasGradient.h in Headers */ = {isa = PBXBuildFile; fileRef = 49484FB4102CF23C00187DD3 /* CanvasGradient.h */; };
 		49484FC4102CF23C00187DD3 /* CanvasPattern.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49484FB6102CF23C00187DD3 /* CanvasPattern.cpp */; };
@@ -5973,6 +5974,7 @@
 		46F9D5DA0B0D60170028EE36 /* aliasCursor.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = aliasCursor.png; sourceTree = "<group>"; };
 		46F9D5DB0B0D60170028EE36 /* noDropCursor.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = noDropCursor.png; sourceTree = "<group>"; };
 		46F9D5DC0B0D60170028EE36 /* progressCursor.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = progressCursor.png; sourceTree = "<group>"; };
+		492273A21083B3B100EE5C84 /* JSCanvasArrayCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCanvasArrayCustom.cpp; sourceTree = "<group>"; };
 		49484FB3102CF23C00187DD3 /* CanvasGradient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CanvasGradient.cpp; path = canvas/CanvasGradient.cpp; sourceTree = "<group>"; };
 		49484FB4102CF23C00187DD3 /* CanvasGradient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CanvasGradient.h; path = canvas/CanvasGradient.h; sourceTree = "<group>"; };
 		49484FB5102CF23C00187DD3 /* CanvasGradient.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = CanvasGradient.idl; path = canvas/CanvasGradient.idl; sourceTree = "<group>"; };
@@ -14337,6 +14339,7 @@
 			children = (
 				415B7C540FF598E6006770F7 /* JSAbstractWorkerCustom.cpp */,
 				BC2ED6BB0C6BD2F000920BFF /* JSAttrCustom.cpp */,
+				492273A21083B3B100EE5C84 /* JSCanvasArrayCustom.cpp */,
 				49EECF7110508D9C00099FAB /* JSCanvasByteArrayCustom.cpp */,
 				49EECF7210508D9C00099FAB /* JSCanvasFloatArrayCustom.cpp */,
 				49EECF7310508D9C00099FAB /* JSCanvasIntArrayCustom.cpp */,
@@ -20153,6 +20156,7 @@
 				97DD4D860FDF4D6E00ECF9A4 /* XSSAuditor.cpp in Sources */,
 				97DCE20110807C750057D394 /* HistoryController.cpp in Sources */,
 				A7D20F62107F406900A80392 /* JSCanvasActiveInfo.cpp in Sources */,
+				492273A31083B3B100EE5C84 /* JSCanvasArrayCustom.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/WebCore/bindings/js/JSCanvasArrayCustom.cpp b/WebCore/bindings/js/JSCanvasArrayCustom.cpp
index 4aa1547..14548d7 100644
--- a/WebCore/bindings/js/JSCanvasArrayCustom.cpp
+++ b/WebCore/bindings/js/JSCanvasArrayCustom.cpp
@@ -29,6 +29,13 @@
 
 #include "config.h"
 #include "JSCanvasArray.h"
+#include "JSCanvasByteArray.h"
+#include "JSCanvasUnsignedByteArray.h"
+#include "JSCanvasShortArray.h"
+#include "JSCanvasUnsignedShortArray.h"
+#include "JSCanvasIntArray.h"
+#include "JSCanvasUnsignedIntArray.h"
+#include "JSCanvasFloatArray.h"
 
 #include "CanvasArray.h"
 
@@ -38,17 +45,21 @@ namespace WebCore {
 
 JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, CanvasArray* object)
 {
-    if (!object)
-        return jsUndefined();
-        
-    
-
-#if ENABLE(3D_CANVAS)
-    if (object->is3d())
-        return getDOMObjectWrapper<JSCanvasRenderingContext3D>(exec, globalObject, static_cast<CanvasRenderingContext3D*>(object));
-#endif
-    ASSERT(object->is2d());
-    return getDOMObjectWrapper<JSCanvasRenderingContext2D>(exec, globalObject, static_cast<CanvasRenderingContext2D*>(object));
+    if (object->isFloatArray())
+        return getDOMObjectWrapper<JSCanvasFloatArray>(exec, globalObject, static_cast<CanvasFloatArray*>(object));
+    if (object->isUnsignedByteArray())
+        return getDOMObjectWrapper<JSCanvasUnsignedByteArray>(exec, globalObject, static_cast<CanvasUnsignedByteArray*>(object));
+    if (object->isByteArray())
+        return getDOMObjectWrapper<JSCanvasByteArray>(exec, globalObject, static_cast<CanvasByteArray*>(object));
+    if (object->isIntArray())
+        return getDOMObjectWrapper<JSCanvasIntArray>(exec, globalObject, static_cast<CanvasIntArray*>(object));
+    if (object->isUnsignedIntArray())
+        return getDOMObjectWrapper<JSCanvasUnsignedIntArray>(exec, globalObject, static_cast<CanvasUnsignedIntArray*>(object));
+    if (object->isShortArray())
+        return getDOMObjectWrapper<JSCanvasShortArray>(exec, globalObject, static_cast<CanvasShortArray*>(object));
+    if (object->isUnsignedShortArray())
+        return getDOMObjectWrapper<JSCanvasUnsignedShortArray>(exec, globalObject, static_cast<CanvasUnsignedShortArray*>(object));
+    return jsUndefined();
 }
 
 } // namespace WebCore
diff --git a/WebCore/html/canvas/CanvasArray.h b/WebCore/html/canvas/CanvasArray.h
index e34ad8c..8cedbbe 100644
--- a/WebCore/html/canvas/CanvasArray.h
+++ b/WebCore/html/canvas/CanvasArray.h
@@ -34,6 +34,14 @@
 namespace WebCore {
     class CanvasArray : public RefCounted<CanvasArray> {
     public:
+        virtual bool isByteArray() const { return false; }
+        virtual bool isUnsignedByteArray() const { return false; }
+        virtual bool isShortArray() const { return false; }
+        virtual bool isUnsignedShortArray() const { return false; }
+        virtual bool isIntArray() const { return false; }
+        virtual bool isUnsignedIntArray() const { return false; }
+        virtual bool isFloatArray() const { return false; }
+        
         PassRefPtr<CanvasArrayBuffer> buffer() {
             return m_buffer;
         }
diff --git a/WebCore/html/canvas/CanvasArray.idl b/WebCore/html/canvas/CanvasArray.idl
index 01bb37e..63b2dcd 100644
--- a/WebCore/html/canvas/CanvasArray.idl
+++ b/WebCore/html/canvas/CanvasArray.idl
@@ -24,7 +24,7 @@
  */
 
 module html {
-    interface [Conditional=3D_CANVAS] CanvasArray {
+    interface [Conditional=3D_CANVAS, CustomToJS] CanvasArray {
         readonly attribute long length;
         int sizeInBytes();
         int alignedSizeInBytes();
diff --git a/WebCore/html/canvas/CanvasByteArray.h b/WebCore/html/canvas/CanvasByteArray.h
index 329f396..69cadf7 100644
--- a/WebCore/html/canvas/CanvasByteArray.h
+++ b/WebCore/html/canvas/CanvasByteArray.h
@@ -38,6 +38,8 @@ namespace WebCore {
 
     class CanvasByteArray : public CanvasArray {
     public:
+        virtual bool isByteArray() const { return true; }
+
         static PassRefPtr<CanvasByteArray> create(unsigned length);
         static PassRefPtr<CanvasByteArray> create(signed char* array, unsigned length);
         static PassRefPtr<CanvasByteArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length);
diff --git a/WebCore/html/canvas/CanvasFloatArray.h b/WebCore/html/canvas/CanvasFloatArray.h
index 49bd897..d2dc4ff 100644
--- a/WebCore/html/canvas/CanvasFloatArray.h
+++ b/WebCore/html/canvas/CanvasFloatArray.h
@@ -35,6 +35,8 @@ namespace WebCore {
     
     class CanvasFloatArray : public CanvasArray {
     public:
+        virtual bool isFloatArray() const { return true; }
+
         static PassRefPtr<CanvasFloatArray> create(unsigned length);
         static PassRefPtr<CanvasFloatArray> create(float* array, unsigned length);
         static PassRefPtr<CanvasFloatArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length);
diff --git a/WebCore/html/canvas/CanvasIntArray.h b/WebCore/html/canvas/CanvasIntArray.h
index 8846be7..4977034 100644
--- a/WebCore/html/canvas/CanvasIntArray.h
+++ b/WebCore/html/canvas/CanvasIntArray.h
@@ -36,6 +36,8 @@ namespace WebCore {
     
     class CanvasIntArray : public CanvasArray {
     public:
+        virtual bool isIntArray() const { return true; }
+
         static PassRefPtr<CanvasIntArray> create(unsigned length);
         static PassRefPtr<CanvasIntArray> create(int* array, unsigned length);
         static PassRefPtr<CanvasIntArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length);
diff --git a/WebCore/html/canvas/CanvasRenderingContext3D.cpp b/WebCore/html/canvas/CanvasRenderingContext3D.cpp
index 35f18ef..9cca57b 100644
--- a/WebCore/html/canvas/CanvasRenderingContext3D.cpp
+++ b/WebCore/html/canvas/CanvasRenderingContext3D.cpp
@@ -814,6 +814,13 @@ void CanvasRenderingContext3D::polygonOffset(double factor, double units)
     cleanupAfterGraphicsCall(false);
 }
 
+PassRefPtr<CanvasArray> CanvasRenderingContext3D::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type)
+{
+    RefPtr<CanvasArray> array = m_context.readPixels(x, y, width, height, format, type);
+    cleanupAfterGraphicsCall(false);
+    return array;
+}
+
 void CanvasRenderingContext3D::releaseShaderCompiler()
 {
     m_context.releaseShaderCompiler();
diff --git a/WebCore/html/canvas/CanvasRenderingContext3D.h b/WebCore/html/canvas/CanvasRenderingContext3D.h
index 3471aca..526281b 100644
--- a/WebCore/html/canvas/CanvasRenderingContext3D.h
+++ b/WebCore/html/canvas/CanvasRenderingContext3D.h
@@ -191,8 +191,7 @@ class WebKitCSSMatrix;
         void pixelStorei(unsigned long pname, long param);
         void polygonOffset(double factor, double units);
         
-        // TBD
-        //void readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type, void* pixels);
+        PassRefPtr<CanvasArray> readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type);
         
         void releaseShaderCompiler();
         void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height);
diff --git a/WebCore/html/canvas/CanvasRenderingContext3D.idl b/WebCore/html/canvas/CanvasRenderingContext3D.idl
index 7b0daa9..db0fff3 100644
--- a/WebCore/html/canvas/CanvasRenderingContext3D.idl
+++ b/WebCore/html/canvas/CanvasRenderingContext3D.idl
@@ -600,8 +600,7 @@ module html {
         void         pixelStorei(in unsigned long pname, in long param);
         void         polygonOffset(in double factor, in double units);
         
-        // FIXME
-        //void         readPixels(in long x, in long y, in unsigned long width, in unsigned long height, in unsigned long format, in unsigned long type, void* pixels);
+        CanvasArray readPixels(in long x, in long y, in unsigned long width, in unsigned long height, in unsigned long format, in unsigned long type);
         
         void         releaseShaderCompiler();
         void         renderbufferStorage(in unsigned long target, in unsigned long internalformat, in unsigned long width, in unsigned long height);
diff --git a/WebCore/html/canvas/CanvasShortArray.h b/WebCore/html/canvas/CanvasShortArray.h
index 00a170f..1eeef0c 100644
--- a/WebCore/html/canvas/CanvasShortArray.h
+++ b/WebCore/html/canvas/CanvasShortArray.h
@@ -36,6 +36,8 @@ namespace WebCore {
     
     class CanvasShortArray : public CanvasArray {
     public:
+        virtual bool isShortArray() const { return true; }
+
         static PassRefPtr<CanvasShortArray> create(unsigned length);
         static PassRefPtr<CanvasShortArray> create(short* array, unsigned length);
         static PassRefPtr<CanvasShortArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length);
diff --git a/WebCore/html/canvas/CanvasUnsignedByteArray.h b/WebCore/html/canvas/CanvasUnsignedByteArray.h
index 6293034..d8864e0 100644
--- a/WebCore/html/canvas/CanvasUnsignedByteArray.h
+++ b/WebCore/html/canvas/CanvasUnsignedByteArray.h
@@ -36,6 +36,8 @@ namespace WebCore {
     
     class CanvasUnsignedByteArray : public CanvasArray {
     public:
+        virtual bool isUnsignedByteArray() const { return true; }
+
         static PassRefPtr<CanvasUnsignedByteArray> create(unsigned length);
         static PassRefPtr<CanvasUnsignedByteArray> create(unsigned char* array, unsigned length);
         static PassRefPtr<CanvasUnsignedByteArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length);
diff --git a/WebCore/html/canvas/CanvasUnsignedIntArray.h b/WebCore/html/canvas/CanvasUnsignedIntArray.h
index 5b5994c..10b8edf 100644
--- a/WebCore/html/canvas/CanvasUnsignedIntArray.h
+++ b/WebCore/html/canvas/CanvasUnsignedIntArray.h
@@ -36,6 +36,8 @@ namespace WebCore {
     
     class CanvasUnsignedIntArray : public CanvasArray {
     public:
+        virtual bool isUnsignedIntArray() const { return true; }
+
         static PassRefPtr<CanvasUnsignedIntArray> create(unsigned length);
         static PassRefPtr<CanvasUnsignedIntArray> create(unsigned int* array, unsigned length);
         static PassRefPtr<CanvasUnsignedIntArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length);
diff --git a/WebCore/html/canvas/CanvasUnsignedShortArray.h b/WebCore/html/canvas/CanvasUnsignedShortArray.h
index 1f6252e..9e27566 100644
--- a/WebCore/html/canvas/CanvasUnsignedShortArray.h
+++ b/WebCore/html/canvas/CanvasUnsignedShortArray.h
@@ -36,6 +36,8 @@ namespace WebCore {
     
     class CanvasUnsignedShortArray : public CanvasArray {
     public:
+        virtual bool isUnsignedShortArray() const { return true; }
+
         static PassRefPtr<CanvasUnsignedShortArray> create(unsigned length);
         static PassRefPtr<CanvasUnsignedShortArray> create(unsigned short* array, unsigned length);
         static PassRefPtr<CanvasUnsignedShortArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length);
diff --git a/WebCore/platform/graphics/GraphicsContext3D.h b/WebCore/platform/graphics/GraphicsContext3D.h
index 314fc82..67224e2 100644
--- a/WebCore/platform/graphics/GraphicsContext3D.h
+++ b/WebCore/platform/graphics/GraphicsContext3D.h
@@ -214,8 +214,7 @@ namespace WebCore {
         void pixelStorei(unsigned long pname, long param);
         void polygonOffset(double factor, double units);
         
-        // TBD
-        //void readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type, void* pixels);
+        PassRefPtr<CanvasArray> readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type);
         
         void releaseShaderCompiler();
         void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height);
diff --git a/WebCore/platform/graphics/mac/Canvas3DLayer.mm b/WebCore/platform/graphics/mac/Canvas3DLayer.mm
index 545c58b..f34eba7 100644
--- a/WebCore/platform/graphics/mac/Canvas3DLayer.mm
+++ b/WebCore/platform/graphics/mac/Canvas3DLayer.mm
@@ -72,6 +72,10 @@ using namespace WebCore;
 
 -(void)drawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp
 {
+    CGLSetCurrentContext(m_contextObj);
+    glFinish();
+    CGLSetCurrentContext(glContext);
+
     CGRect frame = [self frame];
         
     // draw the FBO into the layer
diff --git a/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp b/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp
index 9eee2d0..b56a191 100644
--- a/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp
+++ b/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp
@@ -597,6 +597,22 @@ void GraphicsContext3D::polygonOffset(double factor, double units)
     ::glPolygonOffset(static_cast<float>(factor), static_cast<float>(units));
 }
 
+PassRefPtr<CanvasArray> GraphicsContext3D::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type)
+{
+    ensureContext(m_contextObj);
+    
+    // FIXME: For now we only accept GL_UNSIGNED_BYTE/GL_RGBA. In reality OpenGL ES 2.0 accepts that pair and one other
+    // as specified by GL_IMPLEMENTATION_COLOR_READ_FORMAT and GL_IMPLEMENTATION_COLOR_READ_TYPE. But for now we will
+    // not accept those.
+    // FIXME: Also, we should throw when an unacceptable value is passed
+    if (type != GL_UNSIGNED_BYTE || format != GL_RGBA)
+        return 0;
+        
+    RefPtr<CanvasUnsignedByteArray> array = CanvasUnsignedByteArray::create(width * height * 4);
+    ::glReadPixels(x, y, width, height, format, type, (GLvoid*) array->data());
+    return array;    
+}
+
 void GraphicsContext3D::releaseShaderCompiler()
 {
     // FIXME: This is not implemented on desktop OpenGL. We need to have ifdefs for the different GL variants

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list