Bug 1268638 - Redo backend selection dance for WebGL. - r=jrmuizel draft
authorJeff Gilbert <jgilbert@mozilla.com>
Wed, 22 Jun 2016 12:47:03 -0700
changeset 380729 a5ff5c8a05398d4fe1ce680ec79e674c0386b770
parent 380728 c37be66ffb219b606c351a9eee86686116fbd2fd
child 523799 4cfb9a212ea3d5c46e7093a5f0a514a9477e09e3
push id21304
push userbmo:jgilbert@mozilla.com
push dateWed, 22 Jun 2016 22:06:38 +0000
reviewersjrmuizel
bugs1268638
milestone50.0a1
Bug 1268638 - Redo backend selection dance for WebGL. - r=jrmuizel MozReview-Commit-ID: EW8vDujwn4x
dom/canvas/WebGLContext.cpp
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -638,17 +638,16 @@ static already_AddRefed<gl::GLContext>
 CreateGLWithDefault(const gl::SurfaceCaps& caps, gl::CreateContextFlags flags,
                     WebGLContext* webgl,
                     std::vector<WebGLContext::FailureReason>* const out_failReasons)
 {
     const gfx::IntSize dummySize(16, 16);
     nsCString failureId;
     RefPtr<GLContext> gl = gl::GLContextProvider::CreateOffscreen(dummySize, caps,
                                                                   flags, &failureId);
-
     if (gl && gl->IsANGLE()) {
         gl = nullptr;
     }
 
     if (!gl) {
         out_failReasons->push_back(WebGLContext::FailureReason(
             failureId,
             "Error during native OpenGL init."
@@ -693,77 +692,82 @@ WebGLContext::CreateAndInitGLWith(FnCrea
 
     return true;
 }
 
 bool
 WebGLContext::CreateAndInitGL(bool forceEnabled,
                               std::vector<FailureReason>* const out_failReasons)
 {
-    bool disableNativeGL = true;
+    const gl::SurfaceCaps baseCaps = BaseCaps(mOptions, this);
+    gl::CreateContextFlags flags = gl::CreateContextFlags::NO_VALIDATION;
+    bool tryNativeGL = true;
+    bool tryANGLE = false;
+
     if (forceEnabled) {
-        disableNativeGL = false;
-    } else if (IsWebGL2()) {
+        flags |= gl::CreateContextFlags::FORCE_ENABLE_HARDWARE;
+    }
+
+    if (IsWebGL2()) {
+        flags |= gl::CreateContextFlags::PREFER_ES3;
+    } else {
+        flags |= gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE;
+    }
+
+    //////
+
+    const bool useEGL = PR_GetEnv("MOZ_WEBGL_FORCE_EGL");
+
+#ifdef XP_WIN
+    if (!IsWebGL2()) {
+        // Use only ANGLE on Windows for WebGL 1.
+        tryNativeGL = false;
+        tryANGLE = true;
+    }
+
+    if (gfxPrefs::WebGLDisableWGL()) {
+        tryNativeGL = false;
+    }
+
+    if (gfxPrefs::WebGLDisableANGLE() || PR_GetEnv("MOZ_WEBGL_FORCE_OPENGL") || useEGL) {
+        tryNativeGL = true;
+        tryANGLE = false;
+    }
+#endif
+
+    if (tryNativeGL && !forceEnabled) {
         const nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
         const auto feature = nsIGfxInfo::FEATURE_WEBGL_OPENGL;
 
         FailureReason reason;
         if (IsFeatureInBlacklist(gfxInfo, feature, &reason.key)) {
             reason.info = "Refused to create native OpenGL context because of blacklist"
                           " entry: ";
             reason.info.Append(reason.key);
 
             out_failReasons->push_back(reason);
 
             GenerateWarning(reason.info.BeginReading());
-        } else {
-            disableNativeGL = false;
+            tryNativeGL = false;
         }
     }
 
     //////
 
-    gl::CreateContextFlags flags = gl::CreateContextFlags::NO_VALIDATION;
-
-    if (forceEnabled) flags |= gl::CreateContextFlags::FORCE_ENABLE_HARDWARE;
-    if (!IsWebGL2())  flags |= gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE;
-    if (IsWebGL2())   flags |= gl::CreateContextFlags::PREFER_ES3;
-
-    const gl::SurfaceCaps baseCaps = BaseCaps(mOptions, this);
-
-    //////
-
-    if (!disableNativeGL) {
-        const bool useEGL = PR_GetEnv("MOZ_WEBGL_FORCE_EGL");
-
+    if (tryNativeGL) {
         if (useEGL)
             return CreateAndInitGLWith(CreateGLWithEGL, baseCaps, flags, out_failReasons);
 
-        bool tryNativeGL = true;
-#ifdef XP_WIN
-        if (gfxPrefs::WebGLDisableWGL()) {
-            tryNativeGL = false;
-        }
-#endif
-        if (tryNativeGL) {
-            if (CreateAndInitGLWith(CreateGLWithDefault, baseCaps, flags, out_failReasons))
-                return true;
-        }
+        if (CreateAndInitGLWith(CreateGLWithDefault, baseCaps, flags, out_failReasons))
+            return true;
     }
 
     //////
 
-    bool useANGLE = false;
-#ifdef XP_WIN
-    const bool disableANGLE = (gfxPrefs::WebGLDisableANGLE() ||
-                               PR_GetEnv("MOZ_WEBGL_FORCE_OPENGL"));
-    useANGLE = !disableANGLE;
-#endif
-
-    if (useANGLE)
+    if (tryANGLE)
         return CreateAndInitGLWith(CreateGLWithANGLE, baseCaps, flags, out_failReasons);
 
     //////
 
     out_failReasons->push_back(FailureReason("FEATURE_FAILURE_WEBGL_EXHAUSTED_DRIVERS",
                                              "Exhausted GL driver options."));
     return false;
 }