Bug 721230 - Implement a compressed texture support stub for WebGL conformance. r=bjacob
authorJon Buckley <jon@jbuckley.ca>
Sat, 28 Jan 2012 16:15:27 -0500
changeset 86898 c84e0881d475c812b7a248760088dda42e1c0001
parent 86897 5049c0494794b2df2b42bb430112254fb5288b0d
child 86899 7d6ce43efe5edec5352f4c2bfb9608b4d30c9e5c
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbjacob
bugs721230
milestone12.0a1
Bug 721230 - Implement a compressed texture support stub for WebGL conformance. r=bjacob
content/canvas/src/CustomQS_WebGL.h
content/canvas/src/WebGLContextGL.cpp
dom/interfaces/canvas/nsIDOMWebGLRenderingContext.idl
js/xpconnect/src/dom_quickstubs.qsconf
--- a/content/canvas/src/CustomQS_WebGL.h
+++ b/content/canvas/src/CustomQS_WebGL.h
@@ -219,16 +219,117 @@ nsIDOMWebGLRenderingContext_BufferSubDat
     if (NS_FAILED(rv))
         return xpc_qsThrowMethodFailed(cx, rv, vp);
 
     *vp = JSVAL_VOID;
     return JS_TRUE;
 }
 
 /*
+ * CompressedTexImage2D takes:
+ *    CompressedTexImage2D(uint, int, uint, int, int, int, ArrayBufferView)
+ */
+static JSBool
+nsIDOMWebGLRenderingContext_CompressedTexImage2D(JSContext *cx, uintN argc, jsval *vp)
+{
+    XPC_QS_ASSERT_CONTEXT_OK(cx);
+    JSObject *obj = JS_THIS_OBJECT(cx, vp);
+    if (!obj)
+        return JS_FALSE;
+
+    nsresult rv;
+
+    nsIDOMWebGLRenderingContext *self;
+    xpc_qsSelfRef selfref;
+    JS::AutoValueRooter tvr(cx);
+    if (!xpc_qsUnwrapThis(cx, obj, nsnull, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
+        return JS_FALSE;
+
+    if (argc != 7)
+        return xpc_qsThrow(cx, NS_ERROR_XPC_NOT_ENOUGH_ARGS);
+
+    jsval *argv = JS_ARGV(cx, vp);
+
+    GET_UINT32_ARG(argv0, 0);
+    GET_INT32_ARG(argv1, 1);
+    GET_UINT32_ARG(argv2, 2);
+    GET_INT32_ARG(argv3, 3);
+    GET_INT32_ARG(argv4, 4);
+    GET_INT32_ARG(argv5, 5);
+
+    if (!JSVAL_IS_PRIMITIVE(argv[6])) {
+        JSObject* argv6 = JSVAL_TO_OBJECT(argv[6]);
+        if (js_IsTypedArray(argv6)) {
+            rv = self->CompressedTexImage2D_array(argv0, argv1, argv2, argv3, argv4, argv5,
+                                                  js::TypedArray::getTypedArray(argv6));
+        } else {
+            xpc_qsThrowBadArg(cx, NS_ERROR_FAILURE, vp, 6);
+            return JS_FALSE;
+        }
+    } else {
+        xpc_qsThrow(cx, NS_ERROR_FAILURE);
+        return JS_FALSE;
+    }
+
+    *vp = JSVAL_VOID;
+    return JS_TRUE;
+}
+
+/*
+ * CompressedTexSubImage2D takes:
+ *    CompressedTexSubImage2D(uint, int, int, int, int, int, uint, ArrayBufferView)
+ */
+static JSBool
+nsIDOMWebGLRenderingContext_CompressedTexSubImage2D(JSContext *cx, uintN argc, jsval *vp)
+{
+    XPC_QS_ASSERT_CONTEXT_OK(cx);
+    JSObject *obj = JS_THIS_OBJECT(cx, vp);
+    if (!obj)
+        return JS_FALSE;
+
+    nsresult rv;
+
+    nsIDOMWebGLRenderingContext *self;
+    xpc_qsSelfRef selfref;
+    JS::AutoValueRooter tvr(cx);
+    if (!xpc_qsUnwrapThis(cx, obj, nsnull, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
+        return JS_FALSE;
+
+    if (argc != 7)
+        return xpc_qsThrow(cx, NS_ERROR_XPC_NOT_ENOUGH_ARGS);
+
+    jsval *argv = JS_ARGV(cx, vp);
+
+    GET_UINT32_ARG(argv0, 0);
+    GET_INT32_ARG(argv1, 1);
+    GET_INT32_ARG(argv2, 2);
+    GET_INT32_ARG(argv3, 3);
+    GET_INT32_ARG(argv4, 4);
+    GET_INT32_ARG(argv5, 5);
+    GET_UINT32_ARG(argv6, 6);
+
+    if (!JSVAL_IS_PRIMITIVE(argv[7])) {
+        JSObject* argv7 = JSVAL_TO_OBJECT(argv[7]);
+        if (js_IsTypedArray(argv7)) {
+            rv = self->CompressedTexSubImage2D_array(argv0, argv1, argv2, argv3, argv4, argv5,
+                                                     argv6, js::TypedArray::getTypedArray(argv7));
+        } else {
+            xpc_qsThrowBadArg(cx, NS_ERROR_FAILURE, vp, 7);
+            return JS_FALSE;
+        }
+    } else {
+        xpc_qsThrow(cx, NS_ERROR_FAILURE);
+        return JS_FALSE;
+    }
+
+    *vp = JSVAL_VOID;
+    return JS_TRUE;
+}
+
+/*
  * ReadPixels takes:
  *    ReadPixels(int, int, int, int, uint, uint, ArrayBufferView)
  */
 static JSBool
 nsIDOMWebGLRenderingContext_ReadPixels(JSContext *cx, uintN argc, jsval *vp)
 {
     XPC_QS_ASSERT_CONTEXT_OK(cx);
     JSObject *obj = JS_THIS_OBJECT(cx, vp);
--- a/content/canvas/src/WebGLContextGL.cpp
+++ b/content/canvas/src/WebGLContextGL.cpp
@@ -2186,17 +2186,17 @@ WebGLContext::GetParameter(PRUint32 pnam
         case LOCAL_GL_MAX_VARYING_VECTORS:
             wrval->SetAsInt32(mGLMaxVaryingVectors);
             break;
 
         case LOCAL_GL_NUM_COMPRESSED_TEXTURE_FORMATS:
             wrval->SetAsInt32(0);
             break;
         case LOCAL_GL_COMPRESSED_TEXTURE_FORMATS:
-            wrval->SetAsEmpty(); // the spec says we must return null
+            wrval->SetAsEmptyArray();
             break;
 
 // unsigned int. here we may have to return very large values like 2^32-1 that can't be represented as
 // javascript integer values. We just return them as doubles and javascript doesn't care.
         case LOCAL_GL_STENCIL_BACK_VALUE_MASK:
         case LOCAL_GL_STENCIL_BACK_WRITEMASK:
         case LOCAL_GL_STENCIL_VALUE_MASK:
         case LOCAL_GL_STENCIL_WRITEMASK:
@@ -4454,16 +4454,61 @@ WebGLContext::CompileShader(nsIWebGLShad
 
         gl->fCompileShader(shadername);
     }
 #endif
 
     return NS_OK;
 }
 
+NS_IMETHODIMP
+WebGLContext::CompressedTexImage2D(PRInt32)
+{
+    NS_RUNTIMEABORT("CompressedTexImage2D(PRInt32) should never be called");
+
+    return NS_ERROR_FAILURE;
+}
+
+NS_IMETHODIMP
+WebGLContext::CompressedTexImage2D_array(WebGLenum target, WebGLint level, WebGLenum internalformat,
+                                         WebGLsizei width, WebGLsizei height, WebGLint border,
+                                         JSObject *pixels)
+{
+    if (!IsContextStable())
+        return NS_OK;
+
+    WebGLTexture *tex = activeBoundTextureForTarget(target);
+    if (!tex)
+        return ErrorInvalidOperation("compressedTexImage2D: no texture is bound to this target");
+
+    return ErrorInvalidEnum("compressedTexImage2D: compressed textures are not supported");
+}
+
+NS_IMETHODIMP
+WebGLContext::CompressedTexSubImage2D(PRInt32)
+{
+    NS_RUNTIMEABORT("CompressedTexSubImage2D(PRInt32) should never be called");
+
+    return NS_ERROR_FAILURE;
+}
+
+NS_IMETHODIMP
+WebGLContext::CompressedTexSubImage2D_array(WebGLenum target, WebGLint level, WebGLint xoffset,
+                                            WebGLint yoffset, WebGLsizei width, WebGLsizei height,
+                                            WebGLenum format, JSObject *pixels)
+{
+    if (!IsContextStable())
+        return NS_OK;
+
+    WebGLTexture *tex = activeBoundTextureForTarget(target);
+    if (!tex)
+        return ErrorInvalidOperation("compressedTexSubImage2D: no texture is bound to this target");
+
+    return ErrorInvalidEnum("compressedTexSubImage2D: compressed textures are not supported");
+}
 
 NS_IMETHODIMP
 WebGLContext::GetShaderParameter(nsIWebGLShader *sobj, WebGLenum pname, nsIVariant **retval)
 {
     if (!IsContextStable())
         return NS_OK;
 
     *retval = nsnull;
--- a/dom/interfaces/canvas/nsIDOMWebGLRenderingContext.idl
+++ b/dom/interfaces/canvas/nsIDOMWebGLRenderingContext.idl
@@ -163,17 +163,17 @@ interface nsIWebGLExtensionStandardDeriv
 
 [scriptable, uuid(b0afc2eb-0895-4509-98de-5c383d160694)]
 interface nsIWebGLExtensionLoseContext : nsIWebGLExtension
 {
   void loseContext();
   void restoreContext();
 };
 
-[scriptable, builtinclass, uuid(ef15ae85-4670-4dc4-848d-51ca81e8397a)]
+[scriptable, builtinclass, uuid(f000afac-11b3-4c06-a35f-8db411f1cf54)]
 interface nsIDOMWebGLRenderingContext : nsISupports
 {
   //
   //  CONSTANTS
   //
 
   /* ClearBufferMask */
   const unsigned long DEPTH_BUFFER_BIT               = 0x00000100;
@@ -627,16 +627,26 @@ interface nsIDOMWebGLRenderingContext : 
   WebGLenum checkFramebufferStatus(in WebGLenum target);
   void clear(in WebGLbitfield mask);
   void clearColor(in WebGLclampf red, in WebGLclampf green, in WebGLclampf blue, in WebGLclampf alpha);
   void clearDepth(in WebGLclampf depth);
   void clearStencil(in WebGLint s);
   void colorMask(in WebGLboolean red, in WebGLboolean green, in WebGLboolean blue, in WebGLboolean alpha);
   void compileShader([optional] in nsIWebGLShader shader);
 
+  void compressedTexImage2D([optional] in long dummy);
+  [noscript] void compressedTexImage2D_array(in WebGLenum target, in WebGLint level, in WebGLenum internalformat,
+                                             in WebGLsizei width, in WebGLsizei height, in WebGLint border,
+                                             in WebGLJSObjectPtr pixels);
+
+  void compressedTexSubImage2D([optional] in long dummy);
+  [noscript] void compressedTexSubImage2D_array(in WebGLenum target, in WebGLint level, in WebGLint xoffset,
+                                                in WebGLint yoffset, in WebGLsizei width, in WebGLsizei height,
+                                                in WebGLenum format, in WebGLJSObjectPtr pixels);
+
   void copyTexImage2D(in WebGLenum target, in WebGLint level, in WebGLenum internalformat, 
                       in WebGLint x, in WebGLint y, in WebGLsizei width, in WebGLsizei height, in WebGLint border);
   void copyTexSubImage2D(in WebGLenum target, in WebGLint level, in WebGLint xoffset, in WebGLint yoffset, 
                          in WebGLint x, in WebGLint y, in WebGLsizei width, in WebGLsizei height);
 
   nsIWebGLBuffer createBuffer();
   nsIWebGLProgram createProgram();
   nsIWebGLFramebuffer createFramebuffer();
--- a/js/xpconnect/src/dom_quickstubs.qsconf
+++ b/js/xpconnect/src/dom_quickstubs.qsconf
@@ -973,16 +973,18 @@ customMethodCalls = {
         'unwrapThisFailureFatal' : False
         },
     # WebGL
     'nsIDOMWebGLRenderingContext_BufferData': CUSTOM_QS,
     'nsIDOMWebGLRenderingContext_BufferSubData': CUSTOM_QS,
     'nsIDOMWebGLRenderingContext_ReadPixels': CUSTOM_QS,
     'nsIDOMWebGLRenderingContext_TexImage2D': CUSTOM_QS,
     'nsIDOMWebGLRenderingContext_TexSubImage2D': CUSTOM_QS,
+    'nsIDOMWebGLRenderingContext_CompressedTexImage2D': CUSTOM_QS,
+    'nsIDOMWebGLRenderingContext_CompressedTexSubImage2D': CUSTOM_QS,
     'nsIDOMWebGLRenderingContext_Uniform1iv': CUSTOM_QS_TN,
     'nsIDOMWebGLRenderingContext_Uniform2iv': CUSTOM_QS_TN,
     'nsIDOMWebGLRenderingContext_Uniform3iv': CUSTOM_QS_TN,
     'nsIDOMWebGLRenderingContext_Uniform4iv': CUSTOM_QS_TN,
     'nsIDOMWebGLRenderingContext_Uniform1fv': CUSTOM_QS_TN,
     'nsIDOMWebGLRenderingContext_Uniform2fv': CUSTOM_QS_TN,
     'nsIDOMWebGLRenderingContext_Uniform3fv': CUSTOM_QS_TN,
     'nsIDOMWebGLRenderingContext_Uniform4fv': CUSTOM_QS_TN,