Bug 1261179 - Don't fallback GLContextProviders in WebGL. - r=jrmuizel
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 14 Apr 2016 13:46:37 -0700
changeset 331175 1b77af186da211485fa9c5573d843d96c708a829
parent 331174 1411186a9603c9b897f7942c8a2781a81766082d
child 331176 22f36f2a2e4c740a0c750aad18c444de94ac2658
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1261179
milestone48.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 1261179 - Don't fallback GLContextProviders in WebGL. - r=jrmuizel
dom/canvas/WebGLContext.cpp
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -565,50 +565,49 @@ BaseCaps(const WebGLContextOptions& opti
 }
 
 ////////////////////////////////////////
 
 static already_AddRefed<gl::GLContext>
 CreateGLWithEGL(const gl::SurfaceCaps& caps, gl::CreateContextFlags flags,
                 WebGLContext* webgl)
 {
-    RefPtr<GLContext> gl;
-#ifndef XP_MACOSX // Mac doesn't have GLContextProviderEGL.
-    gfx::IntSize dummySize(16, 16);
-    gl = gl::GLContextProviderEGL::CreateOffscreen(dummySize, caps,
+    const gfx::IntSize dummySize(16, 16);
+    RefPtr<GLContext> gl = gl::GLContextProviderEGL::CreateOffscreen(dummySize, caps,
                                                                      flags);
+
+    if (gl && gl->IsANGLE()) {
+        gl = nullptr;
+    }
+
     if (!gl) {
         webgl->GenerateWarning("Error during EGL OpenGL init.");
         return nullptr;
     }
 
-    if (gl->IsANGLE())
-        return nullptr;
-#endif // XP_MACOSX
     return gl.forget();
 }
 
 static already_AddRefed<GLContext>
 CreateGLWithANGLE(const gl::SurfaceCaps& caps, gl::CreateContextFlags flags,
                   WebGLContext* webgl)
 {
-    RefPtr<GLContext> gl;
+    const gfx::IntSize dummySize(16, 16);
+    RefPtr<GLContext> gl = gl::GLContextProviderEGL::CreateOffscreen(dummySize, caps,
+                                                                     flags);
 
-#ifdef XP_WIN
-    gfx::IntSize dummySize(16, 16);
-    gl = gl::GLContextProviderEGL::CreateOffscreen(dummySize, caps, flags);
+    if (gl && !gl->IsANGLE()) {
+        gl = nullptr;
+    }
+
     if (!gl) {
         webgl->GenerateWarning("Error during ANGLE OpenGL init.");
         return nullptr;
     }
 
-    if (!gl->IsANGLE())
-        return nullptr;
-#endif
-
     return gl.forget();
 }
 
 static already_AddRefed<gl::GLContext>
 CreateGLWithDefault(const gl::SurfaceCaps& caps, gl::CreateContextFlags flags,
                     WebGLContext* webgl)
 {
     nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
@@ -616,41 +615,42 @@ CreateGLWithDefault(const gl::SurfaceCap
     if (!(flags & CreateContextFlags::FORCE_ENABLE_HARDWARE) &&
         IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_OPENGL))
     {
         webgl->GenerateWarning("Refused to create native OpenGL context because of"
                                " blacklisting.");
         return nullptr;
     }
 
-    gfx::IntSize dummySize(16, 16);
+    const gfx::IntSize dummySize(16, 16);
     RefPtr<GLContext> gl = gl::GLContextProvider::CreateOffscreen(dummySize, caps, flags);
+
+    if (gl && gl->IsANGLE()) {
+        gl = nullptr;
+    }
+
     if (!gl) {
         webgl->GenerateWarning("Error during native OpenGL init.");
         return nullptr;
     }
 
-    if (gl->IsANGLE())
-        return nullptr;
-
     return gl.forget();
 }
 
 ////////////////////////////////////////
 
 bool
 WebGLContext::CreateAndInitGLWith(FnCreateGL_T fnCreateGL,
                                   const gl::SurfaceCaps& baseCaps,
                                   gl::CreateContextFlags flags)
 {
-    MOZ_ASSERT(!gl);
-
     std::queue<gl::SurfaceCaps> fallbackCaps;
     PopulateCapFallbackQueue(baseCaps, &fallbackCaps);
 
+    MOZ_RELEASE_ASSERT(!gl);
     gl = nullptr;
     while (!fallbackCaps.empty()) {
         gl::SurfaceCaps& caps = fallbackCaps.front();
 
         gl = fnCreateGL(caps, flags, this);
         if (gl)
             break;
 
@@ -665,52 +665,39 @@ WebGLContext::CreateAndInitGLWith(FnCrea
     }
 
     return true;
 }
 
 bool
 WebGLContext::CreateAndInitGL(bool forceEnabled)
 {
-    bool preferEGL = PR_GetEnv("MOZ_WEBGL_PREFER_EGL");
-    bool disableANGLE = gfxPrefs::WebGLDisableANGLE();
+    const bool useEGL = PR_GetEnv("MOZ_WEBGL_PREFER_EGL");
 
-    if (PR_GetEnv("MOZ_WEBGL_FORCE_OPENGL"))
-        disableANGLE = true;
+    bool useANGLE = false;
+#ifdef XP_WIN
+    const bool disableANGLE = (gfxPrefs::WebGLDisableANGLE() ||
+                               PR_GetEnv("MOZ_WEBGL_FORCE_OPENGL"));
+    useANGLE = !disableANGLE;
+#endif
 
     gl::CreateContextFlags flags = gl::CreateContextFlags::NONE;
     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);
 
-    MOZ_ASSERT(!gl);
-
-    if (preferEGL) {
-        if (CreateAndInitGLWith(CreateGLWithEGL, baseCaps, flags))
-            return true;
-    }
-
-    MOZ_ASSERT(!gl);
+    if (useEGL)
+        return CreateAndInitGLWith(CreateGLWithEGL, baseCaps, flags);
 
-    if (!disableANGLE) {
-        if (CreateAndInitGLWith(CreateGLWithANGLE, baseCaps, flags))
-            return true;
-    }
-
-    MOZ_ASSERT(!gl);
+    if (useANGLE)
+        return CreateAndInitGLWith(CreateGLWithANGLE, baseCaps, flags);
 
-    if (CreateAndInitGLWith(CreateGLWithDefault, baseCaps, flags))
-        return true;
-
-    MOZ_ASSERT(!gl);
-    gl = nullptr;
-
-    return false;
+    return CreateAndInitGLWith(CreateGLWithDefault, baseCaps, flags);
 }
 
 // Fallback for resizes:
 bool
 WebGLContext::ResizeBackbuffer(uint32_t requestedWidth,
                                uint32_t requestedHeight)
 {
     uint32_t width = requestedWidth;