Bug 1018239 - Make WebGLContext::GetExtensionString fool-proof and remove a dangerous EnumeratedArrayConstructor - r=jgilbert
authorBenoit Jacob <bjacob@mozilla.com>
Fri, 30 May 2014 16:21:23 -0400
changeset 205178 646dcacbd009acfdd03a1df31854b5da4478c04f
parent 205177 7b6b2d8dd79b7d050a20471b63fada1cb74b3bff
child 205179 67d59294aef1c987484e75567612ed0c50c881fc
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1018239
milestone32.0a1
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 1018239 - Make WebGLContext::GetExtensionString fool-proof and remove a dangerous EnumeratedArrayConstructor - r=jgilbert
content/canvas/src/WebGLContextExtensions.cpp
mfbt/EnumeratedArray.h
--- a/content/canvas/src/WebGLContextExtensions.cpp
+++ b/content/canvas/src/WebGLContextExtensions.cpp
@@ -13,49 +13,55 @@
 #include "AccessCheck.h"
 
 using namespace mozilla;
 using namespace mozilla::gl;
 
 /* static */ const char*
 WebGLContext::GetExtensionString(WebGLExtensionID ext)
 {
-    // must match WebGLExtensionID.
-    // Once we can use variadic templates, EnumeratedArray should get a constructor
-    // allowing to initialize it directly without using this auxiliary plain array.
-    static const char *kExtensionNames[] = {
-        "ANGLE_instanced_arrays",
-        "EXT_color_buffer_half_float",
-        "EXT_frag_depth",
-        "EXT_sRGB",
-        "EXT_texture_filter_anisotropic",
-        "OES_element_index_uint",
-        "OES_standard_derivatives",
-        "OES_texture_float",
-        "OES_texture_float_linear",
-        "OES_texture_half_float",
-        "OES_texture_half_float_linear",
-        "OES_vertex_array_object",
-        "WEBGL_color_buffer_float",
-        "WEBGL_compressed_texture_atc",
-        "WEBGL_compressed_texture_etc1",
-        "WEBGL_compressed_texture_pvrtc",
-        "WEBGL_compressed_texture_s3tc",
-        "WEBGL_debug_renderer_info",
-        "WEBGL_debug_shaders",
-        "WEBGL_depth_texture",
-        "WEBGL_draw_buffers",
-        "WEBGL_lose_context"
-    };
-
     typedef EnumeratedArray<WebGLExtensionID, WebGLExtensionID::Max, const char*>
             names_array_t;
-    static const names_array_t kExtensionNamesEnumeratedArray(kExtensionNames);
+    static names_array_t sExtensionNamesEnumeratedArray;
+
+    static bool initialized = false;
+
+    if (!initialized) {
+        initialized = true;
+
+#define WEBGL_EXTENSION_IDENTIFIER(x) \
+        sExtensionNamesEnumeratedArray[WebGLExtensionID::x] = #x;
 
-    return kExtensionNamesEnumeratedArray[ext];
+        WEBGL_EXTENSION_IDENTIFIER(ANGLE_instanced_arrays)
+        WEBGL_EXTENSION_IDENTIFIER(EXT_color_buffer_half_float)
+        WEBGL_EXTENSION_IDENTIFIER(EXT_frag_depth)
+        WEBGL_EXTENSION_IDENTIFIER(EXT_sRGB)
+        WEBGL_EXTENSION_IDENTIFIER(EXT_texture_filter_anisotropic)
+        WEBGL_EXTENSION_IDENTIFIER(OES_element_index_uint)
+        WEBGL_EXTENSION_IDENTIFIER(OES_standard_derivatives)
+        WEBGL_EXTENSION_IDENTIFIER(OES_texture_float)
+        WEBGL_EXTENSION_IDENTIFIER(OES_texture_float_linear)
+        WEBGL_EXTENSION_IDENTIFIER(OES_texture_half_float)
+        WEBGL_EXTENSION_IDENTIFIER(OES_texture_half_float_linear)
+        WEBGL_EXTENSION_IDENTIFIER(OES_vertex_array_object)
+        WEBGL_EXTENSION_IDENTIFIER(WEBGL_color_buffer_float)
+        WEBGL_EXTENSION_IDENTIFIER(WEBGL_compressed_texture_atc)
+        WEBGL_EXTENSION_IDENTIFIER(WEBGL_compressed_texture_etc1)
+        WEBGL_EXTENSION_IDENTIFIER(WEBGL_compressed_texture_pvrtc)
+        WEBGL_EXTENSION_IDENTIFIER(WEBGL_compressed_texture_s3tc)
+        WEBGL_EXTENSION_IDENTIFIER(WEBGL_debug_renderer_info)
+        WEBGL_EXTENSION_IDENTIFIER(WEBGL_debug_shaders)
+        WEBGL_EXTENSION_IDENTIFIER(WEBGL_depth_texture)
+        WEBGL_EXTENSION_IDENTIFIER(WEBGL_draw_buffers)
+        WEBGL_EXTENSION_IDENTIFIER(WEBGL_lose_context)
+
+#undef WEBGL_EXTENSION_IDENTIFIER
+    }
+
+    return sExtensionNamesEnumeratedArray[ext];
 }
 
 bool
 WebGLContext::IsExtensionEnabled(WebGLExtensionID ext) const {
     return mExtensions[ext];
 }
 
 bool WebGLContext::IsExtensionSupported(JSContext *cx, WebGLExtensionID ext) const
--- a/mfbt/EnumeratedArray.h
+++ b/mfbt/EnumeratedArray.h
@@ -54,22 +54,16 @@ class EnumeratedArray
     EnumeratedArray() {}
 
     explicit EnumeratedArray(const EnumeratedArray& aOther)
     {
       for (size_t i = 0; i < Size; i++)
         mArray[i] = aOther.mArray[i];
     }
 
-    explicit EnumeratedArray(const ValueType (&aOther)[Size])
-    {
-      for (size_t i = 0; i < Size; i++)
-        mArray[i] = aOther[i];
-    }
-
     ValueType& operator[](IndexType aIndex)
     {
       return mArray[size_t(aIndex)];
     }
 
     const ValueType& operator[](IndexType aIndex) const
     {
       return mArray[size_t(aIndex)];