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

cmarrin at apple.com cmarrin at apple.com
Thu Apr 8 00:54:54 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit abf8b0a60aa32aba0725cd01045d430544e95438
Author: cmarrin at apple.com <cmarrin at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Jan 5 20:40:45 2010 +0000

            Implement most cases of texImage2D and texSubImage2D
            https://bugs.webkit.org/show_bug.cgi?id=31562
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@52821 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 936abd9..c79e384 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,42 @@
+2010-01-05  Rachel Petterson  <rlp at google.com>
+
+        Reviewed by Simon Fraser.
+
+        Implement most cases of texImage2D and texSubImage2D
+        https://bugs.webkit.org/show_bug.cgi?id=31562
+        
+        This fix is with Chris Marrin  <cmarrin at apple.com>.
+        Also bug: https://bugs.webkit.org/show_bug.cgi?id=31493
+
+        From Chris:
+        This implements all cases except HTMLVideoElement. It changes
+        the bindings to accept all parameter forms of the call. Then
+        it plumbs the calls through WebGLRenderingContext down to
+        GraphicsContext3D for the actual implementation.
+
+        From Rachel:
+        This implements texImage2D for chromium. It also implements the V8
+        bindings for texSubImage2D and updates the V8 bindings for texImage2D.
+
+        Tests: fast/canvas/webgl/texImage2DImageDataTest.html
+                  fast/canvas/webgl/texImageTest.html
+
+        * bindings/js/JSWebGLRenderingContextCustom.cpp:
+        (WebCore::JSWebGLRenderingContext::texImage2D):
+        (WebCore::JSWebGLRenderingContext::texSubImage2D):
+        * bindings/v8/custom/V8WebGLRenderingContextCustom.cpp:
+        (WebCore::CALLBACK_FUNC_DECL):
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore::WebGLRenderingContext::texImage2D):
+        (WebCore::WebGLRenderingContext::texSubImage2D):
+        * html/canvas/WebGLRenderingContext.h:
+        * html/canvas/WebGLRenderingContext.idl:
+        * platform/graphics/GraphicsContext3D.h:
+        * platform/graphics/mac/GraphicsContext3DMac.cpp:
+        (WebCore::imageToTexture):
+        (WebCore::GraphicsContext3D::texImage2D):
+        (WebCore::GraphicsContext3D::texSubImage2D):
+
 2010-01-04  Brian Weinstein  <bweinstein at apple.com>
 
         Reviewed by Tim Hatcher.
diff --git a/WebCore/bindings/js/JSWebGLRenderingContextCustom.cpp b/WebCore/bindings/js/JSWebGLRenderingContextCustom.cpp
index 3de9606..f28305b 100644
--- a/WebCore/bindings/js/JSWebGLRenderingContextCustom.cpp
+++ b/WebCore/bindings/js/JSWebGLRenderingContextCustom.cpp
@@ -33,8 +33,11 @@
 #include "ExceptionCode.h"
 #include "HTMLCanvasElement.h"
 #include "HTMLImageElement.h"
+#include "HTMLVideoElement.h"
 #include "JSHTMLCanvasElement.h"
 #include "JSHTMLImageElement.h"
+#include "JSHTMLVideoElement.h"
+#include "JSImageData.h"
 #include "JSWebGLBuffer.h"
 #include "JSWebGLFloatArray.h"
 #include "JSWebGLFramebuffer.h"
@@ -79,8 +82,7 @@ JSValue JSWebGLRenderingContext::bufferData(JSC::ExecState* exec, JSC::ArgList c
         static_cast<WebGLRenderingContext*>(impl())->bufferData(target, array, usage, ec);
     }
 
-    if (ec != 0)
-        setDOMException(exec, ec);
+    setDOMException(exec, ec);
     return jsUndefined();
 }
 
@@ -97,8 +99,7 @@ JSValue JSWebGLRenderingContext::bufferSubData(JSC::ExecState* exec, JSC::ArgLis
     
     static_cast<WebGLRenderingContext*>(impl())->bufferSubData(target, offset, array, ec);
 
-    if (ec != 0)
-        setDOMException(exec, ec);
+    setDOMException(exec, ec);
     return jsUndefined();
 }
 
@@ -307,27 +308,60 @@ JSValue JSWebGLRenderingContext::getVertexAttrib(ExecState* exec, const ArgList&
     return getObjectParameter(this, exec, args, kVertexAttrib);
 }
 
-// void texImage2DHTML(in unsigned long target, in unsigned long level, in HTMLImageElement image);
+//   void texImage2D(in GLenum target, in GLint level, in GLenum internalformat, in GLsizei width, in GLsizei height, in GLint border, in GLenum format, in GLenum type, in WebGLArray pixels);
+//   void texImage2D(in GLenum target, in GLint level, in ImageData pixels, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
+//   void texImage2D(in GLenum target, in GLint level, in HTMLImageElement image, [Optional] in GLboolean flipY, [Optional] in premultiplyAlpha);
+//   void texImage2D(in GLenum target, in GLint level, in HTMLCanvasElement canvas, [Optional] in GLboolean flipY, [Optional] in premultiplyAlpha);
+//   void texImage2D(in GLenum target, in GLint level, in HTMLVideoElement video, [Optional] in GLboolean flipY, [Optional] in premultiplyAlpha);
 JSValue JSWebGLRenderingContext::texImage2D(ExecState* exec, const ArgList& args)
 { 
-    if (args.size() < 3)
+    if (args.size() < 3 || args.size() > 9)
         return throwError(exec, SyntaxError);
 
     ExceptionCode ec = 0;
+    
     WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl());    
     unsigned target = args.at(0).toInt32(exec);
     if (exec->hadException())    
         return jsUndefined();
-        
+    
     unsigned level = args.at(1).toInt32(exec);
     if (exec->hadException())    
         return jsUndefined();
+
+    JSObject* o = 0;
     
-    if (args.size() > 5) {
-        // This must be the bare array case.
+    if (args.size() <= 5) {
+        // This is one of the last 4 forms. Param 2 can be ImageData or <img>, <canvas> or <video> element.
+        JSValue value = args.at(2);
+    
+        if (!value.isObject())
+            return throwError(exec, TypeError);
+        
+        o = asObject(value);
+        
+        bool flipY = args.at(3).toBoolean(exec);
+        bool premultiplyAlpha = args.at(4).toBoolean(exec);
+        
+        if (o->inherits(&JSImageData::s_info)) {
+            ImageData* data = static_cast<ImageData*>(static_cast<JSImageData*>(o)->impl());
+            context->texImage2D(target, level, data, flipY, premultiplyAlpha, ec);
+        } else if (o->inherits(&JSHTMLImageElement::s_info)) {
+            HTMLImageElement* element = static_cast<HTMLImageElement*>(static_cast<JSHTMLImageElement*>(o)->impl());
+            context->texImage2D(target, level, element, flipY, premultiplyAlpha, ec);
+        } else if (o->inherits(&JSHTMLCanvasElement::s_info)) {
+            HTMLCanvasElement* element = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLCanvasElement*>(o)->impl());
+            context->texImage2D(target, level, element, flipY, premultiplyAlpha, ec);
+        } else if (o->inherits(&JSHTMLVideoElement::s_info)) {
+            HTMLVideoElement* element = static_cast<HTMLVideoElement*>(static_cast<JSHTMLVideoElement*>(o)->impl());
+            context->texImage2D(target, level, element, flipY, premultiplyAlpha, ec);
+        } else
+            ec = TYPE_MISMATCH_ERR;
+    } else {
         if (args.size() != 9)
             return throwError(exec, SyntaxError);
-            
+
+        // This must be the WebGLArray case
         unsigned internalformat = args.at(2).toInt32(exec);
         if (exec->hadException())    
             return jsUndefined();
@@ -352,77 +386,122 @@ JSValue JSWebGLRenderingContext::texImage2D(ExecState* exec, const ArgList& args
         if (exec->hadException())    
             return jsUndefined();
 
-        WebGLArray* array = toWebGLArray(args.at(8));
-        if (exec->hadException())    
-            return jsUndefined();
+        JSValue value = args.at(8);
+            
+        // For this case passing 0 (for a null array) is allowed
+        if (value.isNull())
+            context->texImage2D(target, level, internalformat, width, height, border, format, type, 0, ec);
+        else if (value.isObject()) {
+            o = asObject(value);
             
-        if (!array)
+            if (o->inherits(&JSWebGLArray::s_info)) {
+                // FIXME: Need to check to make sure WebGLArray is a WebGLByteArray or WebGLShortArray,
+                // depending on the passed type parameter.
+                WebGLArray* obj = static_cast<WebGLArray*>(static_cast<JSWebGLArray*>(o)->impl());
+                context->texImage2D(target, level, internalformat, width, height, border, format, type, obj, ec);
+            } else
+                return throwError(exec, TypeError);
+        } else 
             return throwError(exec, TypeError);
-        
-        // FIXME: Need to check to make sure WebGLArray is a WebGLByteArray or WebGLShortArray,
-        // depending on the passed type parameter.
-        
-        context->texImage2D(target, level, internalformat, width, height, border, format, type, array, ec);
-        return jsUndefined();
-    }
-    
-    // The image parameter can be a <img> or <canvas> element.
-    JSValue value = args.at(2);
-    if (!value.isObject())
-        return throwError(exec, TypeError);
-    JSObject* o = asObject(value);
-    
-    bool flipY = (args.size() > 3) ? args.at(3).toBoolean(exec) : false;
-    bool premultiplyAlpha = (args.size() > 4) ? args.at(3).toBoolean(exec) : false;
-    
-    if (o->inherits(&JSHTMLImageElement::s_info)) {
-        HTMLImageElement* imgElt = static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(o)->impl());
-        context->texImage2D(target, level, imgElt, flipY, premultiplyAlpha, ec);
-    } else if (o->inherits(&JSHTMLCanvasElement::s_info)) {
-        HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(o)->impl());
-        context->texImage2D(target, level, canvas, flipY, premultiplyAlpha, ec);
-    } else {
-        setDOMException(exec, TYPE_MISMATCH_ERR);
     }
     
+    setDOMException(exec, ec);
     return jsUndefined();    
 }
 
-// void texSubImage2DHTML(in unsigned long target, in unsigned long level, in unsigned long xoff, in unsigned long yoff, in unsigned long width, in unsigned long height, in HTMLImageElement image);
+//   void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, in GLsizei width, in GLsizei height, in GLenum format, in GLenum type, in WebGLArray pixels);
+//   void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, in ImageData pixels, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
+//   void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, in HTMLImageElement image, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
+//   void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, in HTMLCanvasElement canvas, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
+//   void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, in HTMLVideoElement video, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
 JSValue JSWebGLRenderingContext::texSubImage2D(ExecState* exec, const ArgList& args)
 { 
-    if (args.size() < 7 || args.size() > 9)
+    if (args.size() < 5 || args.size() > 9)
         return throwError(exec, SyntaxError);
 
+    ExceptionCode ec = 0;
+
     WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl());    
     unsigned target = args.at(0).toInt32(exec);
+    if (exec->hadException())    
+        return jsUndefined();
+
     unsigned level = args.at(1).toInt32(exec);
-    unsigned xoff = args.at(2).toInt32(exec);
-    unsigned yoff = args.at(3).toInt32(exec);
-    unsigned width = args.at(4).toInt32(exec);
-    unsigned height = args.at(5).toInt32(exec);
+    if (exec->hadException())    
+        return jsUndefined();
     
-    // The image parameter can be a <img> or <canvas> element.
-    JSValue value = args.at(6);
-    if (!value.isObject())
-        return throwError(exec, TypeError);
-    JSObject* o = asObject(value);
+    unsigned xoff = args.at(2).toInt32(exec);
+    if (exec->hadException())    
+        return jsUndefined();
     
-    bool flipY = (args.size() > 3) ? args.at(3).toBoolean(exec) : false;
-    bool premultiplyAlpha = (args.size() > 4) ? args.at(3).toBoolean(exec) : false;
+    unsigned yoff = args.at(3).toInt32(exec);
+    if (exec->hadException())    
+        return jsUndefined();
     
-    ExceptionCode ec = 0;
-    if (o->inherits(&JSHTMLImageElement::s_info)) {
-        HTMLImageElement* imgElt = static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(o)->impl());
-        context->texSubImage2D(target, level, xoff, yoff, width, height, imgElt, flipY, premultiplyAlpha, ec);
-    } else if (o->inherits(&JSHTMLCanvasElement::s_info)) {
-        HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(o)->impl());
-        context->texSubImage2D(target, level, xoff, yoff, width, height, canvas, flipY, premultiplyAlpha, ec);
-    } else
-        ec = TYPE_MISMATCH_ERR;
+    JSObject* o = 0;
+        
+    if (args.size() <= 7) {
+        // This is one of the last 4 forms. Param 4 can be <img>, <canvas> or <video> element, of the format param.
+        JSValue value = args.at(4);
+
+        if (!value.isObject())
+            return throwError(exec, SyntaxError);
+
+        o = asObject(value);
+
+        bool flipY = args.at(5).toBoolean(exec);
+        bool premultiplyAlpha = args.at(6).toBoolean(exec);
+        
+        if (o->inherits(&JSImageData::s_info)) {
+            ImageData* data = static_cast<ImageData*>(static_cast<JSImageData*>(o)->impl());
+            context->texSubImage2D(target, level, xoff, yoff, data, flipY, premultiplyAlpha, ec);
+        } else if (o->inherits(&JSHTMLImageElement::s_info)) {
+            HTMLImageElement* element = static_cast<HTMLImageElement*>(static_cast<JSHTMLImageElement*>(o)->impl());
+            context->texSubImage2D(target, level, xoff, yoff, element, flipY, premultiplyAlpha, ec);
+        } else if (o->inherits(&JSHTMLCanvasElement::s_info)) {
+            HTMLCanvasElement* element = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLCanvasElement*>(o)->impl());
+            context->texSubImage2D(target, level, xoff, yoff, element, flipY, premultiplyAlpha, ec);
+        } else if (o->inherits(&JSHTMLVideoElement::s_info)) {
+            HTMLVideoElement* element = static_cast<HTMLVideoElement*>(static_cast<JSHTMLVideoElement*>(o)->impl());
+            context->texSubImage2D(target, level, xoff, yoff, element, flipY, premultiplyAlpha, ec);
+        } else
+            ec = TYPE_MISMATCH_ERR;
+    } else {
+        // This must be the WebGLArray form
+        if (args.size() != 9)
+            return throwError(exec, SyntaxError);
+
+        unsigned width = args.at(4).toInt32(exec);
+        if (exec->hadException())    
+            return jsUndefined();
+        
+        unsigned height = args.at(5).toInt32(exec);
+        if (exec->hadException())    
+            return jsUndefined();
+        
+        unsigned format = args.at(6).toInt32(exec);
+        if (exec->hadException())    
+            return jsUndefined();
+        
+        unsigned type = args.at(7).toInt32(exec);
+        if (exec->hadException())    
+            return jsUndefined();
+        
+        JSValue value = args.at(8);
+        if (!value.isObject())
+            context->texSubImage2D(target, level, xoff, yoff, width, height, format, type, 0, ec);
+        else {
+            o = asObject(value);
+        
+            if (o->inherits(&JSWebGLArray::s_info)) {
+                WebGLArray* obj = static_cast<WebGLArray*>(static_cast<JSWebGLArray*>(o)->impl());
+                context->texSubImage2D(target, level, xoff, yoff, width, height, format, type, obj, ec);
+            } else
+                return throwError(exec, TypeError);
+        }
+    }
     
-    if (ec != 0)
-        setDOMException(exec, ec);
+    setDOMException(exec, ec);
     return jsUndefined();    
 }
 
@@ -507,8 +586,8 @@ static JSC::JSValue dataFunctionf(DataFunctionToCall f, JSC::ExecState* exec, co
             case f_vertexAttrib3v: context->vertexAttrib3fv(index, webGLArray.get()); break;
             case f_vertexAttrib4v: context->vertexAttrib4fv(index, webGLArray.get()); break;
         }
-        if (ec != 0)
-            setDOMException(exec, ec);
+        
+        setDOMException(exec, ec);
         return jsUndefined();
     }
     
@@ -529,8 +608,8 @@ static JSC::JSValue dataFunctionf(DataFunctionToCall f, JSC::ExecState* exec, co
         case f_vertexAttrib3v: context->vertexAttrib3fv(index, array, size); break;
         case f_vertexAttrib4v: context->vertexAttrib4fv(index, array, size); break;
     }
-    if (ec != 0)
-        setDOMException(exec, ec);
+    
+    setDOMException(exec, ec);
     return jsUndefined();
 }
 
@@ -557,8 +636,8 @@ static JSC::JSValue dataFunctioni(DataFunctionToCall f, JSC::ExecState* exec, co
             case f_uniform4v: context->uniform4iv(location, webGLArray.get(), ec); break;
             default: break;
         }
-        if (ec != 0)
-            setDOMException(exec, ec);
+        
+        setDOMException(exec, ec);
         return jsUndefined();
     }
     
@@ -576,8 +655,8 @@ static JSC::JSValue dataFunctioni(DataFunctionToCall f, JSC::ExecState* exec, co
         case f_uniform4v: context->uniform4iv(location, array, size, ec); break;
         default: break;
     }
-    if (ec != 0)
-        setDOMException(exec, ec);
+    
+    setDOMException(exec, ec);
     return jsUndefined();
 }
 
@@ -606,8 +685,8 @@ static JSC::JSValue dataFunctionMatrix(DataFunctionMatrixToCall f, JSC::ExecStat
             case f_uniformMatrix3fv: context->uniformMatrix3fv(location, transpose, webGLArray.get(), ec); break;
             case f_uniformMatrix4fv: context->uniformMatrix4fv(location, transpose, webGLArray.get(), ec); break;
         }
-        if (ec != 0)
-            setDOMException(exec, ec);
+        
+        setDOMException(exec, ec);
         return jsUndefined();
     }
     
@@ -623,8 +702,8 @@ static JSC::JSValue dataFunctionMatrix(DataFunctionMatrixToCall f, JSC::ExecStat
         case f_uniformMatrix3fv: context->uniformMatrix3fv(location, transpose, array, size, ec); break;
         case f_uniformMatrix4fv: context->uniformMatrix4fv(location, transpose, array, size, ec); break;
     }
-    if (ec != 0)
-        setDOMException(exec, ec);
+    
+    setDOMException(exec, ec);
     return jsUndefined();
 }
 
diff --git a/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp
index 31b0c9d..3d1c3b6 100644
--- a/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp
+++ b/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp
@@ -54,6 +54,8 @@
 #include "V8WebGLUnsignedShortArray.h"
 #include "V8HTMLCanvasElement.h"
 #include "V8HTMLImageElement.h"
+#include "V8HTMLVideoElement.h"
+#include "V8ImageData.h"
 #include "V8Proxy.h"
 #include "WebGLRenderingContext.h"
 
@@ -459,10 +461,14 @@ v8::Handle<v8::Value> V8WebGLRenderingContext::texImage2DCallback(const v8::Argu
     //                   in GLint internalformat,
     //                   in GLsizei width, in GLsizei height, in GLint border,
     //                   in GLenum format, in GLenum type, in WebGLArray pixels);
+    // * void texImage2D(in GLenum target, in GLint level, in ImageData pixels,
+    //                   [Optional] in GLboolean flipY, [Optional] in GLboolean premulitplyAlpha);
     // * void texImage2D(in GLenum target, in GLint level, in HTMLImageElement image,
     //                   [Optional] in GLboolean flipY, [Optional] in GLboolean premultiplyAlpha);
     // * void texImage2D(in GLenum target, in GLint level, in HTMLCanvasElement image,
     //                   [Optional] in GLboolean flipY, [Optional] in GLboolean premultiplyAlpha);
+    // * void texImage2D(in GLenum target, in GLint level, in HTMLVideoElement image,
+    //                   [Optional] in GLboolean flipY, [Optional] in GLboolean premultiplyAlpha);
     if (args.Length() != 3 &&
         args.Length() != 4 &&
         args.Length() != 5 &&
@@ -489,21 +495,28 @@ v8::Handle<v8::Value> V8WebGLRenderingContext::texImage2DCallback(const v8::Argu
     if (args.Length() == 3 ||
         args.Length() == 4 ||
         args.Length() == 5) {
-        v8::Handle<v8::Value> arg = args[2];
         bool flipY = false;
         bool premultiplyAlpha = false;
         if (args.Length() >= 4)
             flipY = args[3]->BooleanValue();
         if (args.Length() >= 5)
             premultiplyAlpha = args[4]->BooleanValue();
+
+        v8::Handle<v8::Value> arg = args[2];
         if (V8HTMLImageElement::HasInstance(arg)) {
             HTMLImageElement* element = V8DOMWrapper::convertDOMWrapperToNode<HTMLImageElement>(v8::Handle<v8::Object>::Cast(arg));
             context->texImage2D(target, level, element, flipY, premultiplyAlpha, ec);
         } else if (V8HTMLCanvasElement::HasInstance(arg)) {
             HTMLCanvasElement* element = V8DOMWrapper::convertDOMWrapperToNode<HTMLCanvasElement>(v8::Handle<v8::Object>::Cast(arg));
             context->texImage2D(target, level, element, flipY, premultiplyAlpha, ec);
-        } else {
-            // FIXME: support HTMLVideoElement and ImageData.
+        } else if(V8ImageData::HasInstance(arg)) {
+            ImageData* image_element = V8DOMWrapper::convertDOMWrapperToNative<ImageData>(v8::Handle<v8::Object>::Cast(arg));
+            context->texImage2D(target, level, image_element, flipY, premultiplyAlpha, ec);
+        } else if (V8HTMLVideoElement::HasInstance(arg)) {
+            HTMLVideoElement* element = V8DOMWrapper::convertDOMWrapperToNode<HTMLVideoElement>(v8::Handle<v8::Object>::Cast(arg));
+            context->texImage2D(target, level, element, flipY, premultiplyAlpha, ec);
+        }
+        else {
             // FIXME: consider different / better exception type.
             V8Proxy::setDOMException(SYNTAX_ERR);
             return notHandledByInterceptor();
@@ -541,10 +554,20 @@ v8::Handle<v8::Value> V8WebGLRenderingContext::texImage2DCallback(const v8::Argu
             return notHandledByInterceptor();
         }
         v8::Handle<v8::Value> arg = args[8];
-        if (V8WebGLArray::HasInstance(arg)) {
+        if (!arg->IsObject())
+        // Assume that the user is passing null for texture
+            context->texImage2D(target,
+                                level,
+                                internalformat,
+                                width,
+                                height,
+                                border,
+                                format,
+                                type,
+                                0,
+                                ec);
+     else if (V8WebGLArray::HasInstance(arg)) {
             WebGLArray* array = V8DOMWrapper::convertToNativeObject<WebGLArray>(V8ClassIndex::WEBGLARRAY, arg->ToObject());
-            // FIXME: must do validation similar to JOGL's to ensure that
-            // the incoming array is of the appropriate length and type
             context->texImage2D(target,
                                 level,
                                 internalformat,
@@ -576,9 +599,142 @@ v8::Handle<v8::Value> V8WebGLRenderingContext::texSubImage2DCallback(const v8::A
 {
     INC_STATS("DOM.WebGLRenderingContext.texSubImage2D()");
 
-    // FIXME: implement
-    notImplemented();
+    // Currently supported forms:
+    // * void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
+    //                      in GLsizei width, in GLsizei height, 
+    //                      in GLenum format, in GLenum type, in WebGLArray pixels);
+    // * void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset,
+    //                      in ImageData pixels, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
+    // * void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
+    //                      in HTMLImageElement image, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
+    // * void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
+    //                      in HTMLCanvasElement canvas, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
+    // * void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
+    //                      in HTMLVideoElement video, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
+
+    if (args.Length() != 5 &&
+        args.Length() != 6 &&
+        args.Length() != 7 &&
+        args.Length() != 9) {
+        V8Proxy::setDOMException(SYNTAX_ERR);
+        return notHandledByInterceptor();
+    }
+
+    WebGLRenderingContext* context =
+        V8DOMWrapper::convertDOMWrapperToNative<WebGLRenderingContext>(args.Holder());
+    bool ok;
+    int target = toInt32(args[0], ok);
+    if (!ok) {
+        V8Proxy::setDOMException(SYNTAX_ERR);
+        return notHandledByInterceptor();
+    }
+    int level = toInt32(args[1], ok);
+    if (!ok) {
+        V8Proxy::setDOMException(SYNTAX_ERR);
+        return notHandledByInterceptor();
+    }
+    int xoff = toInt32(args[2], ok);
+    if (!ok) {
+        V8Proxy::setDOMException(SYNTAX_ERR);
+        return notHandledByInterceptor();
+    }
+    int yoff = toInt32(args[3], ok);
+    if (!ok) {
+        V8Proxy::setDOMException(SYNTAX_ERR);
+        return notHandledByInterceptor();
+    }
+
+    ExceptionCode ec = 0;
+    if (args.Length() == 5 ||
+        args.Length() == 6 ||
+        args.Length() == 7) {
+        bool flipY = false;
+        bool premultiplyAlpha = false;
+        if (args.Length() >= 6)
+            flipY = args[5]->BooleanValue();
+        if (args.Length() >= 7)
+            premultiplyAlpha = args[6]->BooleanValue();
 
+        v8::Handle<v8::Value> arg = args[4];
+        if (V8HTMLImageElement::HasInstance(arg)) {
+            HTMLImageElement* element = V8DOMWrapper::convertDOMWrapperToNode<HTMLImageElement>(v8::Handle<v8::Object>::Cast(arg));
+            context->texSubImage2D(target, level, xoff, yoff, element, flipY, premultiplyAlpha, ec);
+        } else if (V8HTMLCanvasElement::HasInstance(arg)) {
+            HTMLCanvasElement* element = V8DOMWrapper::convertDOMWrapperToNode<HTMLCanvasElement>(v8::Handle<v8::Object>::Cast(arg));
+            context->texSubImage2D(target, level, xoff, yoff, element, flipY, premultiplyAlpha, ec);
+        } else if(V8ImageData::HasInstance(arg)) {
+            ImageData* image_element = V8DOMWrapper::convertDOMWrapperToNative<ImageData>(v8::Handle<v8::Object>::Cast(arg));
+            context->texSubImage2D(target, level, xoff, yoff, image_element, flipY, premultiplyAlpha, ec);
+        } else if (V8HTMLVideoElement::HasInstance(arg)) {
+            HTMLVideoElement* element = V8DOMWrapper::convertDOMWrapperToNode<HTMLVideoElement>(v8::Handle<v8::Object>::Cast(arg));
+            context->texSubImage2D(target, level, xoff, yoff, element, flipY, premultiplyAlpha, ec);
+        }
+        else {
+            // FIXME: consider different / better exception type.
+            V8Proxy::setDOMException(SYNTAX_ERR);
+            return notHandledByInterceptor();
+        }
+        // Fall through
+    } else if (args.Length() == 9) {
+        int width = toInt32(args[4], ok);
+        if (!ok) {
+            V8Proxy::setDOMException(SYNTAX_ERR);
+            return notHandledByInterceptor();
+        }
+        int height = toInt32(args[5], ok);
+        if (!ok) {
+            V8Proxy::setDOMException(SYNTAX_ERR);
+            return notHandledByInterceptor();
+        }
+        int format = toInt32(args[6], ok);
+        if (!ok) {
+            V8Proxy::setDOMException(SYNTAX_ERR);
+            return notHandledByInterceptor();
+        }
+        int type = toInt32(args[7], ok);
+        if (!ok) {
+            V8Proxy::setDOMException(SYNTAX_ERR);
+            return notHandledByInterceptor();
+        }
+        v8::Handle<v8::Value> arg = args[8];
+        if (!arg->IsObject())
+        // Assume that the user is passing null for texture
+            context->texSubImage2D(target,
+                                   level,
+                                   xoff,
+                                   yoff,
+                                   width,
+                                   height,
+                                   format,
+                                   type,
+                                   0,
+                                   ec);
+     else if (V8WebGLArray::HasInstance(arg)) {
+            WebGLArray* array = V8DOMWrapper::convertToNativeObject<WebGLArray>(V8ClassIndex::WEBGLARRAY, arg->ToObject());
+            context->texSubImage2D(target,
+                                   level,
+                                   xoff,
+                                   yoff,
+                                   width,
+                                   height,
+                                   format,
+                                   type,
+                                   array,
+                                   ec);
+            // Fall through
+        } else {
+            V8Proxy::setDOMException(SYNTAX_ERR);
+            return notHandledByInterceptor();
+        }
+    } else {
+        ASSERT_NOT_REACHED();
+        V8Proxy::setDOMException(SYNTAX_ERR);
+        return notHandledByInterceptor();
+    }
+    if (ec) {
+        V8Proxy::setDOMException(ec);
+        return v8::Handle<v8::Value>();
+    }
     return v8::Undefined();
 }
 
diff --git a/WebCore/html/canvas/WebGLRenderingContext.cpp b/WebCore/html/canvas/WebGLRenderingContext.cpp
index 5b8a326..edcd671 100644
--- a/WebCore/html/canvas/WebGLRenderingContext.cpp
+++ b/WebCore/html/canvas/WebGLRenderingContext.cpp
@@ -29,6 +29,14 @@
 
 #include "WebGLRenderingContext.h"
 
+#include "CanvasPixelArray.h"
+#include "HTMLCanvasElement.h"
+#include "HTMLImageElement.h"
+#include "ImageBuffer.h"
+#include "ImageData.h"
+#include "NotImplemented.h"
+#include "RenderBox.h"
+#include "RenderLayer.h"
 #include "WebGLActiveInfo.h"
 #include "WebGLBuffer.h"
 #include "WebGLFramebuffer.h"
@@ -44,6 +52,8 @@
 #include "RenderBox.h"
 #include "RenderLayer.h"
 
+#include <wtf/ByteArray.h>
+
 namespace WebCore {
 
 class WebGLStateRestorer {
@@ -1605,25 +1615,28 @@ void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, unsigned
                                           unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode& ec)
 {
     // FIXME: For now we ignore any errors returned
+    // FIXME: Need to make sure passed buffer has enough bytes to define the texture
     ec = 0;
     m_context->texImage2D(target, level, internalformat, width, height,
-                         border, format, type, pixels);
+                          border, format, type, pixels ? pixels->baseAddress() : 0);
     cleanupAfterGraphicsCall(false);
 }
 
-void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, unsigned internalformat,
-                                          unsigned width, unsigned height, unsigned border,
-                                          unsigned format, unsigned type, ImageData* pixels, ExceptionCode& ec)
+void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, ImageData* pixels,
+                                       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, internalformat, width, height,
-                         border, format, type, pixels);
+    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);
     cleanupAfterGraphicsCall(false);
 }
 
 void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, HTMLImageElement* image,
-                                          bool flipY, bool premultiplyAlpha, ExceptionCode& ec)
+                                       bool flipY, bool premultiplyAlpha, ExceptionCode& ec)
 {
     ec = 0;
     if (!image) {
@@ -1665,9 +1678,14 @@ void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, HTMLCanv
 void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, HTMLVideoElement* video,
                                           bool flipY, bool premultiplyAlpha, ExceptionCode& ec)
 {
-    // FIXME: For now we ignore any errors returned
+    // FIXME: Need implement this call
+    UNUSED_PARAM(target);
+    UNUSED_PARAM(level);
+    UNUSED_PARAM(video);
+    UNUSED_PARAM(flipY);
+    UNUSED_PARAM(premultiplyAlpha);
+    
     ec = 0;
-    m_context->texImage2D(target, level, video, flipY, premultiplyAlpha);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1688,24 +1706,26 @@ void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsig
                                              unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode& ec)
 {
     // FIXME: For now we ignore any errors returned
+    // FIXME: Need to make sure passed buffer has enough bytes to define the texture
     ec = 0;
-    m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
+    m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels ? pixels->baseAddress() : 0);
     cleanupAfterGraphicsCall(false);
 }
 
 void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
-                                             unsigned width, unsigned height,
-                                             unsigned format, unsigned type, ImageData* pixels, ExceptionCode& ec)
+                                          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, width, height, format, type, pixels);
+    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);
     cleanupAfterGraphicsCall(false);
 }
 
 void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
-                                             unsigned width, unsigned height, HTMLImageElement* image,
-                                             bool flipY, bool premultiplyAlpha, ExceptionCode& ec)
+                                          HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode& ec)
 {
     // FIXME: For now we ignore any errors returned
     ec = 0;
@@ -1720,13 +1740,12 @@ void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsig
         return;
     }
 
-    m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, cachedImage->image(), flipY, premultiplyAlpha);
+    m_context->texSubImage2D(target, level, xoffset, yoffset, cachedImage->image(), flipY, premultiplyAlpha);
     cleanupAfterGraphicsCall(false);
 }
 
 void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
-                                             unsigned width, unsigned height, HTMLCanvasElement* canvas,
-                                             bool flipY, bool premultiplyAlpha, ExceptionCode& ec)
+                                          HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode& ec)
 {
     ec = 0;
     if (!canvas) {
@@ -1741,17 +1760,22 @@ void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsig
     }
     
     // FIXME: For now we ignore any errors returned
-    m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, buffer->image(), flipY, premultiplyAlpha);
+    m_context->texSubImage2D(target, level, xoffset, yoffset, buffer->image(), flipY, premultiplyAlpha);
     cleanupAfterGraphicsCall(false);
 }
 
 void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
-                                             unsigned width, unsigned height, HTMLVideoElement* video,
-                                             bool flipY, bool premultiplyAlpha, ExceptionCode& ec)
-{
-    // FIXME: For now we ignore any errors returned
+                                          HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode& ec)
+{
+    // FIXME: Need to implement this call
+    UNUSED_PARAM(target);
+    UNUSED_PARAM(level);
+    UNUSED_PARAM(xoffset);
+    UNUSED_PARAM(yoffset);
+    UNUSED_PARAM(video);
+    UNUSED_PARAM(flipY);
+    UNUSED_PARAM(premultiplyAlpha);
     ec = 0;
-    m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, video, flipY, premultiplyAlpha);
     cleanupAfterGraphicsCall(false);
 }
 
diff --git a/WebCore/html/canvas/WebGLRenderingContext.h b/WebCore/html/canvas/WebGLRenderingContext.h
index dd54cc2..2b3d593 100644
--- a/WebCore/html/canvas/WebGLRenderingContext.h
+++ b/WebCore/html/canvas/WebGLRenderingContext.h
@@ -196,9 +196,8 @@ class WebKitCSSMatrix;
         void texImage2D(unsigned target, unsigned level, unsigned internalformat,
                         unsigned width, unsigned height, unsigned border,
                         unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode&);
-        void texImage2D(unsigned target, unsigned level, unsigned internalformat,
-                        unsigned width, unsigned height, unsigned border,
-                        unsigned format, unsigned type, ImageData* pixels, ExceptionCode&);
+        void texImage2D(unsigned target, unsigned level, ImageData* pixels,
+                        bool flipY, bool premultiplyAlpha, ExceptionCode&);
         void texImage2D(unsigned target, unsigned level, HTMLImageElement* image,
                         bool flipY, bool premultiplyAlpha, ExceptionCode&);
         void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas,
@@ -213,17 +212,13 @@ class WebKitCSSMatrix;
                            unsigned width, unsigned height,
                            unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode&);
         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
-                           unsigned width, unsigned height,
-                           unsigned format, unsigned type, ImageData* pixels, ExceptionCode&);
+                           ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&);
         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
-                           unsigned width, unsigned height, HTMLImageElement* image,
-                           bool flipY, bool premultiplyAlpha, ExceptionCode&);
+                           HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
-                           unsigned width, unsigned height, HTMLCanvasElement* canvas,
-                           bool flipY, bool premultiplyAlpha, ExceptionCode&);
+                           HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&);
         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
-                           unsigned width, unsigned height, HTMLVideoElement* video,
-                           bool flipY, bool premultiplyAlpha, ExceptionCode&);
+                           HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode&);
 
         void uniform1f(const WebGLUniformLocation* location, float x, ExceptionCode&);
         void uniform1fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode&);
diff --git a/WebCore/html/canvas/WebGLRenderingContext.idl b/WebCore/html/canvas/WebGLRenderingContext.idl
index dbd0b67..4ede52d 100644
--- a/WebCore/html/canvas/WebGLRenderingContext.idl
+++ b/WebCore/html/canvas/WebGLRenderingContext.idl
@@ -609,8 +609,8 @@ module html {
         // Supported forms:
         //   void texImage2D(in GLenum target, in GLint level, in GLenum internalformat, in GLsizei width, in GLsizei height, 
         //                   in GLint border, in GLenum format, in GLenum type, in WebGLArray pixels);
-        //   void texImage2D(in GLenum target, in GLint level, in GLenum internalformat, in GLsizei width, in GLsizei height, 
-        //                   in GLint border, in GLenum format, in GLenum type, in ImageData pixels);
+        //   void texImage2D(in GLenum target, in GLint level, in ImageData pixels,
+        //                   [Optional] in GLboolean flipY, [Optional] in premultiplyAlpha);
         //   void texImage2D(in GLenum target, in GLint level, in HTMLImageElement image,
         //                   [Optional] in GLboolean flipY, [Optional] in premultiplyAlpha);
         //   void texImage2D(in GLenum target, in GLint level, in HTMLCanvasElement canvas,
@@ -623,18 +623,14 @@ module html {
         //   void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
         //                      in GLsizei width, in GLsizei height, 
         //                      in GLenum format, in GLenum type, in WebGLArray pixels);
+        //   void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset,
+        //                      in ImageData pixels, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
         //   void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
-        //                      in GLsizei width, in GLsizei height, 
-        //                      in GLenum format, in GLenum type, in ImageData pixels);
-        //   void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
-        //                      in GLsizei width, in GLsizei height, in HTMLImageElement image,
-        //                      [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
+        //                      in HTMLImageElement image, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
         //   void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
-        //                      in GLsizei width, in GLsizei height, in HTMLCanvasElement canvas,
-        //                      [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
+        //                      in HTMLCanvasElement canvas, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
         //   void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
-        //                      in GLsizei width, in GLsizei height, in HTMLVideoElement video,
-        //                      [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
+        //                      in HTMLVideoElement video, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha);
         [Custom] void texSubImage2D();
 
         void uniform1f(in WebGLUniformLocation location, in float x) raises(DOMException);
diff --git a/WebCore/platform/graphics/GraphicsContext3D.h b/WebCore/platform/graphics/GraphicsContext3D.h
index 94629b2..8d5a35d 100644
--- a/WebCore/platform/graphics/GraphicsContext3D.h
+++ b/WebCore/platform/graphics/GraphicsContext3D.h
@@ -65,9 +65,6 @@ namespace WebCore {
     class WebGLShader;
     class WebGLTexture;
     class Image;
-    class HTMLVideoElement;
-    class ImageData;
-    class WebKitCSSMatrix;
 
     struct ActiveInfo {
         String name;
@@ -528,32 +525,14 @@ namespace WebCore {
 
         // These next several functions return an error code (0 if no errors) rather than using an ExceptionCode.
         // Currently they return -1 on any error.
-        int texImage2D(unsigned target, unsigned level, unsigned internalformat,
-                       unsigned width, unsigned height, unsigned border,
-                       unsigned format, unsigned type, WebGLArray* pixels);
-        int texImage2D(unsigned target, unsigned level, unsigned internalformat,
-                       unsigned width, unsigned height, unsigned border,
-                       unsigned format, unsigned type, ImageData* pixels);
-        int texImage2D(unsigned target, unsigned level, Image* image,
-                       bool flipY, bool premultiplyAlpha);
-        int texImage2D(unsigned target, unsigned level, HTMLVideoElement* video,
-                       bool flipY, bool premultiplyAlpha);
+        int texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels);
+        int texImage2D(unsigned target, unsigned level, Image* image, bool flipY, bool premultiplyAlpha);
 
         void texParameterf(unsigned target, unsigned pname, float param);
         void texParameteri(unsigned target, unsigned pname, int param);
 
-        int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
-                          unsigned width, unsigned height,
-                          unsigned format, unsigned type, WebGLArray* pixels);
-        int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
-                          unsigned width, unsigned height,
-                          unsigned format, unsigned type, ImageData* pixels);
-        int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
-                          unsigned width, unsigned height, Image* image,
-                          bool flipY, bool premultiplyAlpha);
-        int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
-                          unsigned width, unsigned height, HTMLVideoElement* video,
-                          bool flipY, bool premultiplyAlpha);
+        int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, unsigned width, unsigned height, unsigned format, unsigned type, void* pixels);
+        int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, Image* image, bool flipY, bool premultiplyAlpha);
 
         void uniform1f(long location, float x);
         void uniform1fv(long location, float* v, int size);
diff --git a/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp b/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp
index 724f42c..fc5b883 100644
--- a/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp
+++ b/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp
@@ -29,25 +29,21 @@
 
 #include "GraphicsContext3D.h"
 
-#include "CachedImage.h"
+#include "CanvasObject.h"
+#include "CString.h"
+#include "ImageBuffer.h"
+#include "NotImplemented.h"
 #include "WebGLActiveInfo.h"
 #include "WebGLArray.h"
 #include "WebGLBuffer.h"
 #include "WebGLFramebuffer.h"
 #include "WebGLFloatArray.h"
 #include "WebGLIntArray.h"
-#include "CanvasObject.h"
 #include "WebGLProgram.h"
 #include "WebGLRenderbuffer.h"
 #include "WebGLShader.h"
 #include "WebGLTexture.h"
 #include "WebGLUnsignedByteArray.h"
-#include "CString.h"
-#include "HTMLCanvasElement.h"
-#include "HTMLImageElement.h"
-#include "ImageBuffer.h"
-#include "NotImplemented.h"
-#include "WebKitCSSMatrix.h"
 #include <CoreGraphics/CGBitmapContext.h>
 #include <OpenGL/CGLRenderers.h>
 #include <wtf/UnusedParam.h>
@@ -1115,55 +1111,38 @@ long GraphicsContext3D::getVertexAttribOffset(unsigned long index, unsigned long
     return reinterpret_cast<long>(pointer);
 }
 
-// Assumes the texture you want to go into is bound
-static void imageToTexture(Image* image, unsigned target, unsigned level)
+// Returned pointer must be freed by fastFree()
+static bool imageToTexture(Image* image, GLubyte*& buffer, size_t& width, size_t& height)
 {
     if (!image)
-        return;
+        return false;
     
     CGImageRef textureImage = image->getCGImageRef();
     if (!textureImage)
-        return;
+        return false;
     
-    size_t textureWidth = CGImageGetWidth(textureImage);
-    size_t textureHeight = CGImageGetHeight(textureImage);
+    width = CGImageGetWidth(textureImage);
+    height = CGImageGetHeight(textureImage);
     
-    GLubyte* textureData = (GLubyte*) fastMalloc(textureWidth * textureHeight * 4);
-    if (!textureData)
-        return;
+    buffer = (GLubyte*) fastMalloc(width * height * 4);
+    if (!buffer)
+        return false;
         
-    CGContextRef textureContext = CGBitmapContextCreate(textureData, textureWidth, textureHeight, 8, textureWidth * 4, 
+    CGContextRef textureContext = CGBitmapContextCreate(buffer, width, height, 8, width * 4, 
                                                         CGImageGetColorSpace(textureImage), kCGImageAlphaPremultipliedLast);
     CGContextSetBlendMode(textureContext, kCGBlendModeCopy);
-    CGContextDrawImage(textureContext, CGRectMake(0, 0, (CGFloat)textureWidth, (CGFloat)textureHeight), textureImage);
+    CGContextDrawImage(textureContext, CGRectMake(0, 0, (CGFloat)width, (CGFloat)height), textureImage);
     CGContextRelease(textureContext);
-    
-    ::glTexImage2D(target, level, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
-    fastFree(textureData);
+    return true;
 }
 
-int GraphicsContext3D::texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, WebGLArray* pixels)
+int GraphicsContext3D::texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels)
 {
     // FIXME: Need to do bounds checking on the buffer here.
-    ::glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels->baseAddress());
+    ::glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
     return 0;
 }
 
-int GraphicsContext3D::texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, ImageData* pixels)
-{
-    // FIXME: need to implement this form
-    UNUSED_PARAM(target);
-    UNUSED_PARAM(level);
-    UNUSED_PARAM(internalformat);
-    UNUSED_PARAM(width);
-    UNUSED_PARAM(height);
-    UNUSED_PARAM(border);
-    UNUSED_PARAM(format);
-    UNUSED_PARAM(type);
-    UNUSED_PARAM(pixels);
-    return -1;
-}
-
 int GraphicsContext3D::texImage2D(unsigned target, unsigned level, Image* image, bool flipY, bool premultiplyAlpha)
 {
     // FIXME: need to support flipY and premultiplyAlpha
@@ -1172,85 +1151,43 @@ int GraphicsContext3D::texImage2D(unsigned target, unsigned level, Image* image,
     ASSERT(image);
     
     ensureContext(m_contextObj);
-    imageToTexture(image, target, level);
+    GLubyte* buffer;
+    size_t width;
+    size_t height;
+    if (!imageToTexture(image, buffer, width, height))
+        return -1;
+    
+    ::glTexImage2D(target, level, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
+    fastFree(buffer);
     return 0;
 }
-
-int GraphicsContext3D::texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha)
-{
-    // FIXME: need to implement this form
-    UNUSED_PARAM(target);
-    UNUSED_PARAM(level);
-    UNUSED_PARAM(video);
-
-    // FIXME: need to support flipY and premultiplyAlpha
-    UNUSED_PARAM(flipY);
-    UNUSED_PARAM(premultiplyAlpha);
-    return -1;
-}
-
-int GraphicsContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoff, unsigned yoff, unsigned width, unsigned height, unsigned format, unsigned type, WebGLArray* pixels)
-{
-    // FIXME: we will need to deal with PixelStore params when dealing with image buffers that differ from the subimage size
-    UNUSED_PARAM(target);
-    UNUSED_PARAM(level);
-    UNUSED_PARAM(xoff);
-    UNUSED_PARAM(yoff);
-    UNUSED_PARAM(width);
-    UNUSED_PARAM(height);
-    UNUSED_PARAM(format);
-    UNUSED_PARAM(type);
-    UNUSED_PARAM(pixels);
-    return -1;
-}
-
-int GraphicsContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoff, unsigned yoff, unsigned width, unsigned height, unsigned format, unsigned type, ImageData* pixels)
-{
-    // FIXME: we will need to deal with PixelStore params when dealing with image buffers that differ from the subimage size
-    UNUSED_PARAM(target);
-    UNUSED_PARAM(level);
-    UNUSED_PARAM(xoff);
-    UNUSED_PARAM(yoff);
-    UNUSED_PARAM(width);
-    UNUSED_PARAM(height);
-    UNUSED_PARAM(format);
-    UNUSED_PARAM(type);
-    UNUSED_PARAM(pixels);
-    return -1;
-}
-
-int GraphicsContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoff, unsigned yoff, unsigned width, unsigned height, Image* image, bool flipY, bool premultiplyAlpha)
+    
+int GraphicsContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoff, unsigned yoff, unsigned width, unsigned height, unsigned format, unsigned type, void* pixels)
 {
     // FIXME: we will need to deal with PixelStore params when dealing with image buffers that differ from the subimage size
-    UNUSED_PARAM(target);
-    UNUSED_PARAM(level);
-    UNUSED_PARAM(xoff);
-    UNUSED_PARAM(yoff);
-    UNUSED_PARAM(width);
-    UNUSED_PARAM(height);
-    UNUSED_PARAM(image);
-
-    // FIXME: need to support flipY and premultiplyAlpha    
-    UNUSED_PARAM(flipY);
-    UNUSED_PARAM(premultiplyAlpha);
-    return -1;
+    // FIXME: Need to do bounds checking on the buffer here.
+    ::glTexSubImage2D(target, level, xoff, yoff, width, height, format, type, pixels);
+    return 0;
 }
 
-int GraphicsContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoff, unsigned yoff, unsigned width, unsigned height, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha)
+int GraphicsContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoff, unsigned yoff, Image* image, bool flipY, bool premultiplyAlpha)
 {
     // FIXME: we will need to deal with PixelStore params when dealing with image buffers that differ from the subimage size
-    UNUSED_PARAM(target);
-    UNUSED_PARAM(level);
-    UNUSED_PARAM(xoff);
-    UNUSED_PARAM(yoff);
-    UNUSED_PARAM(width);
-    UNUSED_PARAM(height);
-    UNUSED_PARAM(video);
-
-    // FIXME: need to support flipY and premultiplyAlpha    
+    // FIXME: need to support flipY and premultiplyAlpha
     UNUSED_PARAM(flipY);
     UNUSED_PARAM(premultiplyAlpha);
-    return -1;
+    ASSERT(image);
+    
+    ensureContext(m_contextObj);
+    GLubyte* buffer;
+    size_t width;
+    size_t height;
+    if (!imageToTexture(image, buffer, width, height))
+        return -1;
+    
+    ::glTexSubImage2D(target, level, xoff, yoff, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
+    fastFree(buffer);
+    return 0;
 }
 
 unsigned GraphicsContext3D::createBuffer()

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list