Bug 779611 - part 4 - More WebGL extensions cleanup - r-jgilbert
authorBenoit Jacob <bjacob@mozilla.com>
Wed, 03 Oct 2012 17:13:05 -0400
changeset 109235 a5a4c320de967082e9049a82d044d1aef40371cc
parent 109234 0984909abb53f9513ed1dea302b840281958e3a4
child 109236 4417d4fecc1a3a320f42a384a7f27da73ee1f44d
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
bugs779611
milestone18.0a1
Bug 779611 - part 4 - More WebGL extensions cleanup - r-jgilbert
content/canvas/src/WebGLContext.cpp
content/canvas/src/WebGLContext.h
gfx/gl/GLContext.h
--- a/content/canvas/src/WebGLContext.cpp
+++ b/content/canvas/src/WebGLContext.cpp
@@ -911,17 +911,17 @@ WebGLContext::GetContextAttributes(Error
         rv.Throw(NS_ERROR_FAILURE);
         return NULL;
     }
 
     return obj;
 }
 
 bool
-WebGLContext::IsExtensionEnabled(WebGLExtensionID ext) {
+WebGLContext::IsExtensionEnabled(WebGLExtensionID ext) const {
     return mExtensions.SafeElementAt(ext);
 }
 
 /* [noscript] DOMString mozGetUnderlyingParamString(in WebGLenum pname); */
 NS_IMETHODIMP
 WebGLContext::MozGetUnderlyingParamString(uint32_t pname, nsAString& retval)
 {
     if (!IsContextStable())
@@ -944,122 +944,120 @@ WebGLContext::MozGetUnderlyingParamStrin
 
     default:
         return NS_ERROR_INVALID_ARG;
     }
 
     return NS_OK;
 }
 
-bool WebGLContext::IsExtensionSupported(WebGLExtensionID ext)
+bool WebGLContext::IsExtensionSupported(WebGLExtensionID ext) const
 {
-    bool isSupported = false;
+    if (mDisableExtensions) {
+        return false;
+    }
 
     switch (ext) {
         case OES_standard_derivatives:
         case WEBGL_lose_context:
             // We always support these extensions.
-            isSupported = true;
-            break;
+            return true;
         case OES_texture_float:
-            isSupported = gl->IsExtensionSupported(gl->IsGLES2() ? GLContext::OES_texture_float 
-                                                                 : GLContext::ARB_texture_float);
-            break;
+            return gl->IsExtensionSupported(gl->IsGLES2() ? GLContext::OES_texture_float
+                                                          : GLContext::ARB_texture_float);
         case EXT_texture_filter_anisotropic:
-            isSupported = gl->IsExtensionSupported(GLContext::EXT_texture_filter_anisotropic);
-            break;
+            return gl->IsExtensionSupported(GLContext::EXT_texture_filter_anisotropic);
         case WEBGL_compressed_texture_s3tc:
             if (gl->IsExtensionSupported(GLContext::EXT_texture_compression_s3tc)) {
-                isSupported = true;
-            } else if (gl->IsExtensionSupported(GLContext::EXT_texture_compression_dxt1) &&
+                return true;
+            }
+            else if (gl->IsExtensionSupported(GLContext::EXT_texture_compression_dxt1) &&
                        gl->IsExtensionSupported(GLContext::ANGLE_texture_compression_dxt3) &&
                        gl->IsExtensionSupported(GLContext::ANGLE_texture_compression_dxt5))
             {
-                isSupported = true;
-            }
-            break;
-        case WEBGL_compressed_texture_atc:
-            if (gl->IsExtensionSupported(GLContext::AMD_compressed_ATC_texture)) {
-                isSupported = true;
+                return true;
             }
-            break;
+            else
+            {
+                return false;
+            }
+        case WEBGL_compressed_texture_atc:
+            return gl->IsExtensionSupported(GLContext::AMD_compressed_ATC_texture);
         case WEBGL_compressed_texture_pvrtc:
-            if (gl->IsExtensionSupported(GLContext::IMG_texture_compression_pvrtc)) {
-                isSupported = true;
-            }
-            break;
+            return gl->IsExtensionSupported(GLContext::IMG_texture_compression_pvrtc);
         case WEBGL_depth_texture:
             if (gl->IsGLES2() && 
                 gl->IsExtensionSupported(GLContext::OES_packed_depth_stencil) &&
                 gl->IsExtensionSupported(GLContext::OES_depth_texture)) 
             {
-                isSupported = true;
-            } else if (!gl->IsGLES2() &&
-                       gl->IsExtensionSupported(GLContext::EXT_packed_depth_stencil)) 
+                return true;
+            }
+            else if (!gl->IsGLES2() &&
+                     gl->IsExtensionSupported(GLContext::EXT_packed_depth_stencil))
             {
-                isSupported = true;
+                return true;
             }
-            break;
+            else
+            {
+                return false;
+            }
         default:
             MOZ_ASSERT(false, "should not get there.");
     }
 
-    return isSupported;
+    MOZ_ASSERT(false, "should not get there.");
+    return false;
+}
+
+static bool
+CompareWebGLExtensionName(const nsACString& name, const char *other)
+{
+    return name.Equals(other, nsCaseInsensitiveCStringComparator());
 }
 
 JSObject*
 WebGLContext::GetExtension(JSContext *cx, const nsAString& aName)
 {
     if (!IsContextStable())
         return nullptr;
 
-    if (mDisableExtensions) {
-        return nullptr;
-    }
+    NS_LossyConvertUTF16toASCII name(aName);
 
     WebGLExtensionID ext = WebGLExtensionID_unknown_extension;
 
     // step 1: figure what extension is wanted
-    if (aName.Equals(NS_LITERAL_STRING("OES_texture_float"),
-        nsCaseInsensitiveStringComparator()))
+    if (CompareWebGLExtensionName(name, "OES_texture_float"))
     {
         ext = OES_texture_float;
     }
-    else if (aName.Equals(NS_LITERAL_STRING("OES_standard_derivatives"),
-             nsCaseInsensitiveStringComparator()))
+    else if (CompareWebGLExtensionName(name, "OES_standard_derivatives"))
     {
         ext = OES_standard_derivatives;
     }
-    else if (aName.Equals(NS_LITERAL_STRING("EXT_texture_filter_anisotropic"),
-             nsCaseInsensitiveStringComparator()))
+    else if (CompareWebGLExtensionName(name, "EXT_texture_filter_anisotropic"))
     {
         ext = EXT_texture_filter_anisotropic;
     }
-    else if (aName.Equals(NS_LITERAL_STRING("MOZ_WEBGL_lose_context"),
-             nsCaseInsensitiveStringComparator()))
+    else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_lose_context"))
     {
         ext = WEBGL_lose_context;
     }
-    else if (aName.Equals(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_s3tc"),
-             nsCaseInsensitiveStringComparator()))
+    else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_s3tc"))
     {
         ext = WEBGL_compressed_texture_s3tc;
     }
-    else if (aName.Equals(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_atc"),
-             nsCaseInsensitiveStringComparator()))
+    else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_atc"))
     {
         ext = WEBGL_compressed_texture_atc;
     }
-    else if (aName.Equals(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_pvrtc"),
-             nsCaseInsensitiveStringComparator()))
+    else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_pvrtc"))
     {
         ext = WEBGL_compressed_texture_pvrtc;
     }
-    else if (aName.Equals(NS_LITERAL_STRING("MOZ_WEBGL_depth_texture"),
-             nsCaseInsensitiveStringComparator()))
+    else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_depth_texture"))
     {
         ext = WEBGL_depth_texture;
     }
 
     if (ext == WebGLExtensionID_unknown_extension) {
       return nullptr;
     }
 
@@ -1545,30 +1543,25 @@ WebGLActiveInfo::GetName(nsAString & aNa
 }
 
 void
 WebGLContext::GetSupportedExtensions(Nullable< nsTArray<nsString> > &retval)
 {
     retval.SetNull();
     if (!IsContextStable())
         return;
-    
-    if (mDisableExtensions) {
-        return;
-    }
 
     nsTArray<nsString>& arr = retval.SetValue();
     
     if (IsExtensionSupported(OES_texture_float))
         arr.AppendElement(NS_LITERAL_STRING("OES_texture_float"));
     if (IsExtensionSupported(OES_standard_derivatives))
         arr.AppendElement(NS_LITERAL_STRING("OES_standard_derivatives"));
-    if (IsExtensionSupported(EXT_texture_filter_anisotropic)) {
+    if (IsExtensionSupported(EXT_texture_filter_anisotropic))
         arr.AppendElement(NS_LITERAL_STRING("EXT_texture_filter_anisotropic"));
-    }
     if (IsExtensionSupported(WEBGL_lose_context))
         arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_lose_context"));
     if (IsExtensionSupported(WEBGL_compressed_texture_s3tc))
         arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_s3tc"));
     if (IsExtensionSupported(WEBGL_compressed_texture_atc))
         arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_atc"));
     if (IsExtensionSupported(WEBGL_compressed_texture_pvrtc))
         arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_pvrtc"));
--- a/content/canvas/src/WebGLContext.h
+++ b/content/canvas/src/WebGLContext.h
@@ -1175,20 +1175,20 @@ protected:
         WEBGL_compressed_texture_atc,
         WEBGL_compressed_texture_pvrtc,
         WEBGL_depth_texture,
         WebGLExtensionID_unknown_extension
     };
     nsTArray<nsRefPtr<WebGLExtensionBase> > mExtensions;
 
     // returns true if the extension has been enabled by calling getExtension.
-    bool IsExtensionEnabled(WebGLExtensionID ext);
+    bool IsExtensionEnabled(WebGLExtensionID ext) const;
 
     // returns true if the extension is supported (as returned by getSupportedExtensions)
-    bool IsExtensionSupported(WebGLExtensionID ext);
+    bool IsExtensionSupported(WebGLExtensionID ext) const;
 
     nsTArray<WebGLenum> mCompressedTextureFormats;
 
     bool InitAndValidateGL();
     bool ValidateBuffers(int32_t *maxAllowedCount, const char *info);
     bool ValidateCapabilityEnum(WebGLenum cap, const char *info);
     bool ValidateBlendEquationEnum(WebGLenum cap, const char *info);
     bool ValidateBlendFuncDstEnum(WebGLenum mode, const char *info);
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -1670,17 +1670,17 @@ public:
         ARB_sync,
         OES_EGL_image,
         OES_EGL_sync,
         OES_EGL_image_external,
         EXT_packed_depth_stencil,
         Extensions_Max
     };
 
-    bool IsExtensionSupported(GLExtensions aKnownExtension) {
+    bool IsExtensionSupported(GLExtensions aKnownExtension) const {
         return mAvailableExtensions[aKnownExtension];
     }
 
     void MarkExtensionUnsupported(GLExtensions aKnownExtension) {
         mAvailableExtensions[aKnownExtension] = 0;
     }
 
     // Shared code for GL extensions and GLX extensions.
@@ -1732,16 +1732,21 @@ public:
             free(exts);
         }
 
         bool& operator[](size_t index) {
             MOZ_ASSERT(index < Size, "out of range");
             return extensions[index];
         }
 
+        const bool& operator[](size_t index) const {
+            MOZ_ASSERT(index < Size, "out of range");
+            return extensions[index];
+        }
+
         bool extensions[Size];
     };
 
 protected:
     ExtensionBitset<Extensions_Max> mAvailableExtensions;
 
 public:
     /**