Bug 1167651 - Passed the forceEnabled pref from function to function down to GLLibraryEGL::EnsureInitialized. r=jgilbert
authorKyle <kfung@mozilla.com>
Thu, 23 Jul 2015 13:12:59 -0400
changeset 286105 d05a79889594df7d1d12b0fcef7904b2fb9e3cf8
parent 286104 4c6d629ba832635d87e52f92128a0c65fc96e88d
child 286106 1cdbaf4b98070366e5630c9da07952003a7e5013
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1167651
milestone42.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 1167651 - Passed the forceEnabled pref from function to function down to GLLibraryEGL::EnsureInitialized. r=jgilbert
dom/canvas/WebGLContext.cpp
gfx/gl/GLContextProviderCGL.mm
gfx/gl/GLContextProviderEGL.cpp
gfx/gl/GLContextProviderGLX.cpp
gfx/gl/GLContextProviderImpl.h
gfx/gl/GLContextProviderWGL.cpp
gfx/gl/GLLibraryEGL.cpp
gfx/gl/GLLibraryEGL.h
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -565,25 +565,18 @@ CreateHeadlessNativeGL(bool forceEnabled
 // Eventually, we want to be able to pick ANGLE-EGL or native EGL.
 static already_AddRefed<GLContext>
 CreateHeadlessANGLE(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
                     bool requireCompatProfile, WebGLContext* webgl)
 {
     nsRefPtr<GLContext> gl;
 
 #ifdef XP_WIN
-    if (!forceEnabled &&
-        IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_ANGLE))
-    {
-        webgl->GenerateWarning("Refused to create ANGLE OpenGL context"
-                               " because of blacklisting.");
-        return nullptr;
-    }
-
-    gl = gl::GLContextProviderEGL::CreateHeadless(requireCompatProfile);
+    gl = gl::GLContextProviderEGL::CreateHeadless(requireCompatProfile,
+                                                  forceEnabled);
     if (!gl) {
         webgl->GenerateWarning("Error during ANGLE OpenGL init.");
         return nullptr;
     }
     MOZ_ASSERT(gl->IsANGLE());
 #endif
 
     return gl.forget();
--- a/gfx/gl/GLContextProviderCGL.mm
+++ b/gfx/gl/GLContextProviderCGL.mm
@@ -282,17 +282,17 @@ CreateOffscreenFBOContext(bool requireCo
     SurfaceCaps dummyCaps = SurfaceCaps::Any();
     nsRefPtr<GLContextCGL> glContext = new GLContextCGL(dummyCaps, context,
                                                         true, profile);
 
     return glContext.forget();
 }
 
 already_AddRefed<GLContext>
-GLContextProviderCGL::CreateHeadless(bool requireCompatProfile)
+GLContextProviderCGL::CreateHeadless(bool requireCompatProfile, bool forceEnabled)
 {
     nsRefPtr<GLContextCGL> gl;
     gl = CreateOffscreenFBOContext(requireCompatProfile);
     if (!gl)
         return nullptr;
 
     if (!gl->Init()) {
         NS_WARNING("Failed during Init.");
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -928,19 +928,19 @@ GLContextEGL::CreateEGLPixmapOffscreenCo
     }
 
     glContext->HoldSurface(thebesSurface);
 
     return glContext.forget();
 }
 
 already_AddRefed<GLContext>
-GLContextProviderEGL::CreateHeadless(bool)
+GLContextProviderEGL::CreateHeadless(bool requireCompatProfile, bool forceEnabled)
 {
-    if (!sEGLLibrary.EnsureInitialized()) {
+    if (!sEGLLibrary.EnsureInitialized(forceEnabled)) {
         return nullptr;
     }
 
     mozilla::gfx::IntSize dummySize = mozilla::gfx::IntSize(16, 16);
     nsRefPtr<GLContext> glContext;
     glContext = GLContextEGL::CreateEGLPBufferOffscreenContext(dummySize);
     if (!glContext)
         return nullptr;
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -1210,17 +1210,17 @@ DONE_CREATING_PIXMAP:
                                                   true,
                                                   xsurface);
     }
 
     return glContext.forget();
 }
 
 already_AddRefed<GLContext>
-GLContextProviderGLX::CreateHeadless(bool)
+GLContextProviderGLX::CreateHeadless(bool requireCompatProfile, bool forceEnabled)
 {
     IntSize dummySize = IntSize(16, 16);
     nsRefPtr<GLContext> glContext = CreateOffscreenPixmapContext(dummySize);
     if (!glContext)
         return nullptr;
 
     return glContext.forget();
 }
--- a/gfx/gl/GLContextProviderImpl.h
+++ b/gfx/gl/GLContextProviderImpl.h
@@ -61,17 +61,17 @@ public:
      */
     static already_AddRefed<GLContext>
     CreateOffscreen(const mozilla::gfx::IntSize& size,
                     const SurfaceCaps& caps,
                     bool requireCompatProfile);
 
     // Just create a context. We'll add offscreen stuff ourselves.
     static already_AddRefed<GLContext>
-    CreateHeadless(bool requireCompatProfile);
+    CreateHeadless(bool requireCompatProfile, bool forceEnabled = false);
 
     /**
      * Create wrapping Gecko GLContext for external gl context.
      *
      * @param aContext External context which will be wrapped by Gecko GLContext.
      * @param aSurface External surface which is used for external context.
      *
      * @return Wrapping Context to use for rendering
--- a/gfx/gl/GLContextProviderWGL.cpp
+++ b/gfx/gl/GLContextProviderWGL.cpp
@@ -602,17 +602,17 @@ CreateWindowOffscreenContext()
     nsRefPtr<GLContextWGL> glContext = new GLContextWGL(caps,
                                                         shareContext, true,
                                                         dc, context, win);
 
     return glContext.forget();
 }
 
 already_AddRefed<GLContext>
-GLContextProviderWGL::CreateHeadless(bool)
+GLContextProviderWGL::CreateHeadless(bool requireCompatProfile, bool forceEnabled)
 {
     if (!sWGLLib.EnsureInitialized()) {
         return nullptr;
     }
 
     nsRefPtr<GLContextWGL> glContext;
 
     // Always try to create a pbuffer context first, because we
--- a/gfx/gl/GLLibraryEGL.cpp
+++ b/gfx/gl/GLLibraryEGL.cpp
@@ -141,17 +141,17 @@ GetAndInitDisplay(GLLibraryEGL& egl, voi
 
     if (!egl.fInitialize(display, nullptr, nullptr))
         return EGL_NO_DISPLAY;
 
     return display;
 }
 
 bool
-GLLibraryEGL::EnsureInitialized()
+GLLibraryEGL::EnsureInitialized(bool forceAccel)
 {
     if (mInitialized) {
         return true;
     }
 
     mozilla::ScopedGfxFeatureReporter reporter("EGL");
 
 #ifdef MOZ_B2G
@@ -306,68 +306,65 @@ GLLibraryEGL::EnsureInitialized()
         }
     }
 #endif
     mEGLDisplay = EGL_NO_DISPLAY;
     // Check the ANGLE support the system has
     nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
     mIsANGLE = IsExtensionSupported(ANGLE_platform_angle_d3d);
 
-    //WARP ANGLE fallback path
     if (mIsANGLE) {
         bool accelAngleSupport = IsAccelAngleSupported(gfxInfo);
         bool warpAngleSupport = gfxPlatform::CanUseDirect3D11ANGLE();
 
+        bool shouldTryAccel = forceAccel || accelAngleSupport;
+        bool shouldTryWARP = !shouldTryAccel && warpAngleSupport;
+        if (gfxPrefs::WebGLANGLEForceWARP()) {
+            shouldTryWARP = true;
+            shouldTryAccel = false;
+        }
+
         // Fallback to a WARP display if non-WARP is blacklisted,
         // or if WARP is forced
-        bool shouldTryWARP = warpAngleSupport && !accelAngleSupport;
-        if (gfxPrefs::WebGLANGLEForceWARP()) {
-            shouldTryWARP = true;
-        }
-
         if (shouldTryWARP) {
             mEGLDisplay = GetAndInitWARPDisplay(*this,
                                                 EGL_DEFAULT_DISPLAY);
             if (mEGLDisplay != EGL_NO_DISPLAY) {
                 mIsWARP = true;
             }
         }
 
-        // If falling back to WARP did not work, then fail
-        if (mEGLDisplay == EGL_NO_DISPLAY && !accelAngleSupport) {
+        // If falling back to WARP did not work and we don't want to try
+        // using HW accelerated ANGLE, then fail
+        if (mEGLDisplay == EGL_NO_DISPLAY && !shouldTryAccel) {
             NS_ERROR("Fallback WARP ANGLE context failed to initialize.");
             return false;
         }
+
+        // Hardware accelerated ANGLE path
+        if (mEGLDisplay == EGL_NO_DISPLAY && shouldTryAccel) {
+            // D3D11 ANGLE only works with OMTC; there's a bug in the non-OMTC layer
+            // manager, and it's pointless to try to fix it.  We also don't try
+            // D3D11 ANGLE if the layer manager is prefering D3D9 (hrm, do we care?)
+            if (gfxPrefs::LayersOffMainThreadCompositionEnabled() &&
+                !gfxPrefs::LayersPreferD3D9())
+            {
+                if (gfxPrefs::WebGLANGLEForceD3D11()) {
+                    mEGLDisplay = GetAndInitDisplay(*this,
+                                                    LOCAL_EGL_D3D11_ONLY_DISPLAY_ANGLE);
+                } else if (gfxPrefs::WebGLANGLETryD3D11() && gfxPlatform::CanUseDirect3D11ANGLE()) {
+                    mEGLDisplay = GetAndInitDisplay(*this,
+                                                    LOCAL_EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE);
+                }
+            }
+        }
     }
 
     if (mEGLDisplay == EGL_NO_DISPLAY) {
         mEGLDisplay = GetAndInitDisplay(*this, EGL_DEFAULT_DISPLAY);
-
-        EGLDisplay newDisplay = EGL_NO_DISPLAY;
-
-        // D3D11 ANGLE only works with OMTC; there's a bug in the non-OMTC layer
-        // manager, and it's pointless to try to fix it.  We also don't try
-        // D3D11 ANGLE if the layer manager is prefering D3D9 (hrm, do we care?)
-        if (gfxPrefs::LayersOffMainThreadCompositionEnabled() &&
-            !gfxPrefs::LayersPreferD3D9())
-        {
-            if (gfxPrefs::WebGLANGLEForceD3D11()) {
-                newDisplay = GetAndInitDisplay(*this,
-                                               LOCAL_EGL_D3D11_ONLY_DISPLAY_ANGLE);
-            } else if (gfxPrefs::WebGLANGLETryD3D11() && gfxPlatform::CanUseDirect3D11ANGLE()) {
-                newDisplay = GetAndInitDisplay(*this,
-                                               LOCAL_EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE);
-            }
-        }
-
-        if (newDisplay != EGL_NO_DISPLAY) {
-            DebugOnly<EGLBoolean> success = fTerminate(mEGLDisplay);
-            MOZ_ASSERT(success == LOCAL_EGL_TRUE);
-            mEGLDisplay = newDisplay;
-        }
     }
 
     InitExtensionsFromDisplay(mEGLDisplay);
 
     if (IsExtensionSupported(KHR_lock_surface)) {
         GLLibraryLoader::SymLoadStruct lockSymbols[] = {
             { (PRFuncPtr*) &mSymbols.fLockSurface,   { "eglLockSurfaceKHR",   nullptr } },
             { (PRFuncPtr*) &mSymbols.fUnlockSurface, { "eglUnlockSurfaceKHR", nullptr } },
--- a/gfx/gl/GLLibraryEGL.h
+++ b/gfx/gl/GLLibraryEGL.h
@@ -489,17 +489,17 @@ public:
     bool HasANGLESurfaceD3DTexture2DShareHandle() {
         return IsExtensionSupported(ANGLE_surface_d3d_texture_2d_share_handle);
     }
 
     bool HasRobustness() const {
         return IsExtensionSupported(EXT_create_context_robustness);
     }
 
-    bool EnsureInitialized();
+    bool EnsureInitialized(bool forceAccel = false);
 
     void DumpEGLConfig(EGLConfig cfg);
     void DumpEGLConfigs();
 
     struct {
         typedef EGLDisplay (GLAPIENTRY * pfnGetDisplay)(void *display_id);
         pfnGetDisplay fGetDisplay;
         typedef EGLDisplay(GLAPIENTRY * pfnGetPlatformDisplayEXT)(EGLenum platform, void *native_display, const EGLint *attrib_list);