Bug 584840 - Fix texParameter methods - r=vladimir a=blocking2.0
authorBenoit Jacob <bjacob@mozilla.com>
Mon, 23 Aug 2010 17:03:44 -0400
changeset 51420 6774a67212e0c1c0abbda00688bab76f56d293fe
parent 51419 760ada4a4e873c41ce28d61427115298e724d6f3
child 51421 33a6231b3e80f74cd92963f363d2ad76dc3d15f2
push id15307
push userbjacob@mozilla.com
push dateWed, 25 Aug 2010 12:19:08 +0000
treeherdermozilla-central@4999ff306455 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvladimir, blocking2.0
bugs584840
milestone2.0b5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 584840 - Fix texParameter methods - r=vladimir a=blocking2.0
content/canvas/src/WebGLContext.h
content/canvas/src/WebGLContextGL.cpp
js/src/xpconnect/src/dom_quickstubs.qsconf
--- a/content/canvas/src/WebGLContext.h
+++ b/content/canvas/src/WebGLContext.h
@@ -377,16 +377,18 @@ protected:
                              void *data, PRUint32 byteLength);
     nsresult TexSubImage2D_base(WebGLenum target, WebGLint level,
                                 WebGLint xoffset, WebGLint yoffset,
                                 WebGLsizei width, WebGLsizei height,
                                 WebGLenum format, WebGLenum type,
                                 void *pixels, PRUint32 byteLength);
     nsresult ReadPixels_base(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height,
                              WebGLenum format, WebGLenum type, void *data, PRUint32 byteLength);
+    nsresult TexParameter_base(WebGLenum target, WebGLenum pname,
+                               WebGLint *intParamPtr, WebGLfloat *floatParamPtr);
 
     nsresult DOMElementToImageSurface(nsIDOMElement *imageOrCanvas,
                                       gfxImageSurface **imageOut,
                                       PRBool flipY, PRBool premultiplyAlpha);
 
     // Conversion from public nsI* interfaces to concrete objects
     template<class ConcreteObjectType, class BaseInterfaceType>
     PRBool GetConcreteObject(const char *info,
--- a/content/canvas/src/WebGLContextGL.cpp
+++ b/content/canvas/src/WebGLContextGL.cpp
@@ -1787,143 +1787,102 @@ WebGLContext::GetProgramInfoLog(nsIWebGL
 
     log.SetLength(k);
 
     CopyASCIItoUTF16(log, retval);
 
     return NS_OK;
 }
 
-/* XXX fix */
-/* void texParameter (); */
-NS_IMETHODIMP
-WebGLContext::TexParameterf(WebGLenum target, WebGLenum pname, WebGLfloat param)
+// here we have to support all pnames with both int and float params.
+// See this discussion:
+//  https://www.khronos.org/webgl/public-mailing-list/archives/1008/msg00014.html
+nsresult WebGLContext::TexParameter_base(WebGLenum target, WebGLenum pname,
+                                         WebGLint *intParamPtr, WebGLfloat *floatParamPtr)
 {
-    NativeJSContext js;
-    if (NS_FAILED(js.error))
-        return js.error;
-
-    if (js.argc != 3)
-        return NS_ERROR_DOM_SYNTAX_ERR;
+    NS_ENSURE_TRUE(intParamPtr || floatParamPtr, NS_ERROR_FAILURE);
+
+    WebGLint intParam   = intParamPtr   ? *intParamPtr   : WebGLint(*floatParamPtr);
+    WebGLint floatParam = floatParamPtr ? *floatParamPtr : WebGLfloat(*intParamPtr);
+
+    if (!ValidateTextureTargetEnum(target, "texParameter: target"))
+        return NS_OK;
+
+    PRBool pnameAndParamAreIncompatible = PR_FALSE;
+
+    switch (pname) {
+        case LOCAL_GL_TEXTURE_MIN_FILTER:
+            switch (intParam) {
+                case LOCAL_GL_NEAREST:
+                case LOCAL_GL_LINEAR:
+                case LOCAL_GL_NEAREST_MIPMAP_NEAREST:
+                case LOCAL_GL_LINEAR_MIPMAP_NEAREST:
+                case LOCAL_GL_NEAREST_MIPMAP_LINEAR:
+                case LOCAL_GL_LINEAR_MIPMAP_LINEAR:
+                    break;
+                default:
+                    pnameAndParamAreIncompatible = PR_TRUE;
+            }
+            break;
+        case LOCAL_GL_TEXTURE_MAG_FILTER:
+            switch (intParam) {
+                case LOCAL_GL_NEAREST:
+                case LOCAL_GL_LINEAR:
+                    break;
+                default:
+                    pnameAndParamAreIncompatible = PR_TRUE;
+            }
+            break;
+        case LOCAL_GL_TEXTURE_WRAP_S:
+        case LOCAL_GL_TEXTURE_WRAP_T:
+            switch (intParam) {
+                case LOCAL_GL_CLAMP_TO_EDGE:
+                case LOCAL_GL_MIRRORED_REPEAT:
+                case LOCAL_GL_REPEAT:
+                    break;
+                default:
+                    pnameAndParamAreIncompatible = PR_TRUE;
+            }
+            break;
+        default:
+            return ErrorInvalidEnumInfo("texParameter: pname", pname);
+    }
+
+    if (pnameAndParamAreIncompatible) {
+        if (intParamPtr)
+            return ErrorInvalidEnum("texParameteri: pname %x and param %x (decimal %d) are mutually incompatible",
+                                    pname, intParam, intParam);
+        else
+            return ErrorInvalidValue("texParameterf: pname %x and floating-point param %e are mutually incompatible",
+                                    pname, floatParam);
+    }
+
+    if (!activeBoundTextureForTarget(target))
+        return ErrorInvalidOperation("texParameter: no texture is bound to this target");
 
     MakeContextCurrent();
-
-    gl->fTexParameterf (target, pname, param);
-
-    return NS_OK;
-}
-NS_IMETHODIMP
-WebGLContext::TexParameteri(WebGLenum target, WebGLenum pname, WebGLint param)
-{
-    NativeJSContext js;
-    if (NS_FAILED(js.error))
-        return js.error;
-
-    if (js.argc != 3)
-        return NS_ERROR_DOM_SYNTAX_ERR;
-
-    MakeContextCurrent();
-
-    gl->fTexParameteri (target, pname, param);
+    if (intParamPtr)
+        gl->fTexParameteri(target, pname, intParam);
+    else
+        gl->fTexParameterf(target, pname, floatParam);
 
     return NS_OK;
 }
 
-#if 0
 NS_IMETHODIMP
-WebGLContext::TexParameter()
+WebGLContext::TexParameterf(WebGLenum target, WebGLenum pname, WebGLfloat param)
 {
-    NativeJSContext js;
-    if (NS_FAILED(js.error))
-        return js.error;
-
-    if (js.argc != 3)
-        return NS_ERROR_DOM_SYNTAX_ERR;
-
-    jsuint targetVal;
-    jsuint pnameVal;
-    if (!::JS_ValueToECMAUint32(js.ctx, js.argv[0], &targetVal) ||
-        !::JS_ValueToECMAUint32(js.ctx, js.argv[1], &pnameVal))
-        return NS_ERROR_DOM_SYNTAX_ERR;
-
-    if (targetVal != LOCAL_GL_TEXTURE_2D &&
-        targetVal != LOCAL_GL_TEXTURE_CUBE_MAP)
-    {
-        return NS_ERROR_DOM_SYNTAX_ERR;
-    }
-
-    MakeContextCurrent();
-    switch (pnameVal) {
-        case LOCAL_GL_TEXTURE_MIN_FILTER: {
-            jsuint ival;
-            if (!::JS_ValueToECMAUint32(js.ctx, js.argv[2], &ival) ||
-                (ival != LOCAL_GL_NEAREST &&
-                 ival != LOCAL_GL_LINEAR &&
-                 ival != LOCAL_GL_NEAREST_MIPMAP_NEAREST &&
-                 ival != LOCAL_GL_LINEAR_MIPMAP_NEAREST &&
-                 ival != LOCAL_GL_NEAREST_MIPMAP_LINEAR &&
-                 ival != LOCAL_GL_LINEAR_MIPMAP_LINEAR))
-                return NS_ERROR_DOM_SYNTAX_ERR;
-            gl->fTexParameteri (targetVal, pnameVal, ival);
-        }
-            break;
-        case LOCAL_GL_TEXTURE_MAG_FILTER: {
-            jsuint ival;
-            if (!::JS_ValueToECMAUint32(js.ctx, js.argv[2], &ival) ||
-                (ival != LOCAL_GL_NEAREST &&
-                 ival != LOCAL_GL_LINEAR))
-                return NS_ERROR_DOM_SYNTAX_ERR;
-            gl->fTexParameteri (targetVal, pnameVal, ival);
-        }
-            break;
-        case LOCAL_GL_TEXTURE_WRAP_S:
-        case LOCAL_GL_TEXTURE_WRAP_T: {
-            jsuint ival;
-            if (!::JS_ValueToECMAUint32(js.ctx, js.argv[2], &ival) ||
-                (ival != LOCAL_GL_CLAMP &&
-                 ival != LOCAL_GL_CLAMP_TO_EDGE &&
-                 ival != LOCAL_GL_REPEAT))
-                return NS_ERROR_DOM_SYNTAX_ERR;
-            gl->fTexParameteri (targetVal, pnameVal, ival);
-        }
-            break;
-        case LOCAL_GL_GENERATE_MIPMAP: {
-            jsuint ival;
-            if (js.argv[2] == JSVAL_TRUE)
-                ival = 1;
-            else if (js.argv[2] == JSVAL_FALSE)
-                ival = 0;
-            else if (!::JS_ValueToECMAUint32(js.ctx, js.argv[2], &ival) ||
-                     (ival != 0 && ival != 1))
-                return NS_ERROR_DOM_SYNTAX_ERR;
-            gl->fTexParameteri (targetVal, pnameVal, ival);
-        }
-            break;
-        case LOCAL_GL_TEXTURE_MAX_ANISOTROPY_EXT: {
-#if 0
-            if (GLEW_EXT_texture_filter_anisotropic) {
-                jsdouble dval;
-                if (!::JS_ValueToNumber(js.ctx, js.argv[2], &dval))
-                    return NS_ERROR_DOM_SYNTAX_ERR;
-                gl->fTexParameterf (targetVal, pnameVal, (float) dval);
-            } else {
-                return NS_ERROR_NOT_IMPLEMENTED;
-            }
-#else
-            return NS_ERROR_NOT_IMPLEMENTED;
-#endif
-        }
-            break;
-        default:
-            return NS_ERROR_DOM_SYNTAX_ERR;
-    }
-
-    return NS_OK;
+    return TexParameter_base(target, pname, nsnull, &param);
 }
-#endif
+
+NS_IMETHODIMP
+WebGLContext::TexParameteri(WebGLenum target, WebGLenum pname, WebGLint param)
+{
+    return TexParameter_base(target, pname, &param, nsnull);
+}
 
 NS_IMETHODIMP
 WebGLContext::GetTexParameter(WebGLenum target, WebGLenum pname, nsIVariant **retval)
 {
     nsCOMPtr<nsIWritableVariant> wrval = do_CreateInstance("@mozilla.org/variant;1");
     NS_ENSURE_TRUE(wrval, NS_ERROR_FAILURE);
 
     MakeContextCurrent();
--- a/js/src/xpconnect/src/dom_quickstubs.qsconf
+++ b/js/src/xpconnect/src/dom_quickstubs.qsconf
@@ -440,18 +440,16 @@ members = [
     # custom-quickstubbed.
     '-nsICanvasRenderingContextWebGL.getActiveAttrib',
     '-nsICanvasRenderingContextWebGL.getActiveUniform',
     '-nsICanvasRenderingContextWebGL.getParameter',
     '-nsICanvasRenderingContextWebGL.getBufferParameter',
     '-nsICanvasRenderingContextWebGL.getFramebufferAttachmentParameter',
     '-nsICanvasRenderingContextWebGL.getRenderbufferParameter',
     '-nsICanvasRenderingContextWebGL.getProgramParameter',
-    '-nsICanvasRenderingContextWebGL.texParameterf',
-    '-nsICanvasRenderingContextWebGL.texParameteri',
     '-nsICanvasRenderingContextWebGL.getUniform',
     '-nsICanvasRenderingContextWebGL.getVertexAttrib',
     '-nsICanvasRenderingContextWebGL.getShaderParameter',
 
     # dom/indexedDB
     'nsIIDBCursor.*',
     'nsIIDBDatabase.*',
     'nsIIDBDatabaseException.*',