Bug 1289655 - Organize GLFeature checks for WebGL2. - r=mtseng draft
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 28 Jul 2016 17:14:47 -0700
changeset 394559 5f4b32c6bb13a4c5dcb2e0273b70009d9054beec
parent 394558 2f9bef88234008a7e15e45cb585e956bcc6342cb
child 394560 d36a63e11871e2e56f3cce3f93c8c28725c5bae1
push id24605
push userbmo:jgilbert@mozilla.com
push dateFri, 29 Jul 2016 23:50:29 +0000
reviewersmtseng
bugs1289655
milestone50.0a1
Bug 1289655 - Organize GLFeature checks for WebGL2. - r=mtseng MozReview-Commit-ID: 7Ci6PqVkvM0
dom/canvas/WebGL2Context.cpp
--- a/dom/canvas/WebGL2Context.cpp
+++ b/dom/canvas/WebGL2Context.cpp
@@ -96,44 +96,50 @@ static const gl::GLFeature kRequiredFeat
     gl::GLFeature::vertex_array_object
 };
 
 bool
 WebGLContext::InitWebGL2(FailureReason* const out_failReason)
 {
     MOZ_ASSERT(IsWebGL2(), "WebGLContext is not a WebGL 2 context!");
 
-    // check OpenGL features
-    if (!gl->IsSupported(gl::GLFeature::occlusion_query) &&
-        !gl->IsSupported(gl::GLFeature::occlusion_query_boolean))
-    {
-        // On desktop, we fake occlusion_query_boolean with occlusion_query if
-        // necessary. (See WebGL2ContextQueries.cpp)
-        *out_failReason = FailureReason("FEATURE_FAILURE_WEBGL2_OCCL",
-                                        "WebGL 2 requires occlusion query support.");
-        return false;
+    std::vector<gl::GLFeature> missingList;
+
+    const auto fnGatherMissing = [&](gl::GLFeature cur) {
+        if (!gl->IsSupported(cur)) {
+            missingList.push_back(cur);
+        }
+    };
+
+    const auto fnGatherMissing2 = [&](gl::GLFeature main, gl::GLFeature alt) {
+        if (!gl->IsSupported(main) && !gl->IsSupported(alt)) {
+            missingList.push_back(main);
+        }
+    };
+
+    ////
+
+    for (const auto& cur : kRequiredFeatures) {
+        fnGatherMissing(cur);
     }
 
-    std::vector<gl::GLFeature> missingList;
-
-    for (size_t i = 0; i < ArrayLength(kRequiredFeatures); i++) {
-        if (!gl->IsSupported(kRequiredFeatures[i])) {
-            missingList.push_back(kRequiredFeatures[i]);
-        }
-    }
+    // On desktop, we fake occlusion_query_boolean with occlusion_query if
+    // necessary. (See WebGL2ContextQueries.cpp)
+    fnGatherMissing2(gl::GLFeature::occlusion_query_boolean,
+                     gl::GLFeature::occlusion_query);
 
 #ifdef XP_MACOSX
     // On OSX, GL core profile is used. This requires texture swizzle
     // support to emulate legacy texture formats: ALPHA, LUMINANCE,
     // and LUMINANCE_ALPHA.
-    if (!gl->IsSupported(gl::GLFeature::texture_swizzle)) {
-        missingList.push_back(gl::GLFeature::texture_swizzle);
-    }
+    fnGatherMissing(gl::GLFeature::texture_swizzle);
 #endif
 
+    ////
+
     if (missingList.size()) {
         nsAutoCString exts;
         for (auto itr = missingList.begin(); itr != missingList.end(); ++itr) {
             exts.AppendLiteral("\n  ");
             exts.Append(gl::GLContext::GetFeatureName(*itr));
         }
 
         const nsPrintfCString reason("WebGL 2 requires support for the following"