Bug 1347289 - Remove GL context sharing support except on EAGL - r=snorp draft
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 14 Mar 2017 13:59:00 -0700
changeset 498487 df7d949772d8f79b7f8f10c793860194bd3e950b
parent 498480 8773772e68a8380557fa1d6f4f5dabeaecc0b423
child 549167 6c107a390e98195bbec6ed360b767bbad9897172
push id49207
push userbmo:jgilbert@mozilla.com
push dateTue, 14 Mar 2017 20:59:57 +0000
reviewerssnorp
bugs1347289
milestone55.0a1
Bug 1347289 - Remove GL context sharing support except on EAGL - r=snorp MozReview-Commit-ID: FUGSsQ9r7Bd
gfx/gl/GLContextEGL.h
gfx/gl/GLContextGLX.h
gfx/gl/GLContextProviderEGL.cpp
gfx/gl/GLContextProviderGLX.cpp
--- a/gfx/gl/GLContextEGL.h
+++ b/gfx/gl/GLContextEGL.h
@@ -18,27 +18,25 @@ namespace gl {
 
 class GLContextEGL : public GLContext
 {
     friend class TextureImageEGL;
 
     static already_AddRefed<GLContextEGL>
     CreateGLContext(CreateContextFlags flags,
                     const SurfaceCaps& caps,
-                    GLContextEGL* shareContext,
                     bool isOffscreen,
                     EGLConfig config,
                     EGLSurface surface,
                     nsACString* const out_failureId);
 
 public:
     MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextEGL, override)
     GLContextEGL(CreateContextFlags flags,
                  const SurfaceCaps& caps,
-                 GLContext* shareContext,
                  bool isOffscreen,
                  EGLConfig config,
                  EGLSurface surface,
                  EGLContext context);
 
     ~GLContextEGL();
 
     virtual GLContextType GetContextType() const override { return GLContextType::EGL; }
--- a/gfx/gl/GLContextGLX.h
+++ b/gfx/gl/GLContextGLX.h
@@ -16,17 +16,16 @@ namespace gl {
 
 class GLContextGLX : public GLContext
 {
 public:
     MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextGLX, override)
     static already_AddRefed<GLContextGLX>
     CreateGLContext(CreateContextFlags flags,
                     const SurfaceCaps& caps,
-                    GLContextGLX* shareContext,
                     bool isOffscreen,
                     Display* display,
                     GLXDrawable drawable,
                     GLXFBConfig cfg,
                     bool deleteDrawable,
                     gfxXlibSurface* pixmap = nullptr,
                     ContextProfile profile = ContextProfile::OpenGLCompatibility);
 
@@ -67,17 +66,16 @@ public:
     // Undoes the effect of a drawable override.
     bool RestoreDrawable();
 
 private:
     friend class GLContextProviderGLX;
 
     GLContextGLX(CreateContextFlags flags,
                  const SurfaceCaps& caps,
-                 GLContext* shareContext,
                  bool isOffscreen,
                  Display* aDisplay,
                  GLXDrawable aDrawable,
                  GLXContext aContext,
                  bool aDeleteDrawable,
                  bool aDoubleBuffered,
                  gfxXlibSurface* aPixmap,
                  ContextProfile profile);
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -183,35 +183,34 @@ GLContextEGLFactory::Create(EGLNativeWin
         return nullptr;
     }
 
     CreateContextFlags flags = CreateContextFlags::NONE;
     if (aWebRender) {
         flags |= CreateContextFlags::PREFER_ES3;
     }
     SurfaceCaps caps = SurfaceCaps::Any();
-    RefPtr<GLContextEGL> gl = GLContextEGL::CreateGLContext(flags,
-                                                            caps, nullptr, false, config,
+    RefPtr<GLContextEGL> gl = GLContextEGL::CreateGLContext(flags, caps, false, config,
                                                             surface, &discardFailureId);
     if (!gl) {
         MOZ_CRASH("GFX: Failed to create EGLContext!\n");
         mozilla::gl::DestroySurface(surface);
         return nullptr;
     }
 
     gl->MakeCurrent();
     gl->SetIsDoubleBuffered(doubleBuffered);
 
     return gl.forget();
 }
 
 GLContextEGL::GLContextEGL(CreateContextFlags flags, const SurfaceCaps& caps,
-                           GLContext* shareContext, bool isOffscreen, EGLConfig config,
-                           EGLSurface surface, EGLContext context)
-    : GLContext(flags, caps, shareContext, isOffscreen)
+                           bool isOffscreen, EGLConfig config, EGLSurface surface,
+                           EGLContext context)
+    : GLContext(flags, caps, nullptr, isOffscreen)
     , mConfig(config)
     , mSurface(surface)
     , mContext(context)
     , mSurfaceOverride(EGL_NO_SURFACE)
     , mThebesSurface(nullptr)
     , mBound(false)
     , mIsPBuffer(false)
     , mIsDoubleBuffered(false)
@@ -462,17 +461,16 @@ GLContextEGL::GetWSIInfo(nsCString* cons
 void
 GLContextEGL::HoldSurface(gfxASurface* aSurf) {
     mThebesSurface = aSurf;
 }
 
 already_AddRefed<GLContextEGL>
 GLContextEGL::CreateGLContext(CreateContextFlags flags,
                 const SurfaceCaps& caps,
-                GLContextEGL* shareContext,
                 bool isOffscreen,
                 EGLConfig config,
                 EGLSurface surface,
                 nsACString* const out_failureId)
 {
     if (sEGLLibrary.fBindAPI(LOCAL_EGL_OPENGL_ES_API) == LOCAL_EGL_FALSE) {
         *out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_EGL_ES");
         NS_WARNING("Failed to bind API to GLES!");
@@ -508,30 +506,18 @@ GLContextEGL::CreateGLContext(CreateCont
 
     const auto fnCreate = [&](const std::vector<EGLint>& attribs) {
         auto terminated_attribs = attribs;
 
         for (const auto& cur : kTerminationAttribs) {
             terminated_attribs.push_back(cur);
         }
 
-        if (shareContext) {
-            const auto context = sEGLLibrary.fCreateContext(EGL_DISPLAY(), config,
-                                                            shareContext->mContext,
-                                                            terminated_attribs.data());
-            if (context)
-                return context;
-        }
-        const auto context = sEGLLibrary.fCreateContext(EGL_DISPLAY(), config,
-                                                        EGL_NO_CONTEXT,
-                                                        terminated_attribs.data());
-        if (context) {
-            shareContext = nullptr;
-        }
-        return context;
+        return sEGLLibrary.fCreateContext(EGL_DISPLAY(), config, EGL_NO_CONTEXT,
+                                          terminated_attribs.data());
     };
 
     EGLContext context;
     do {
         if (rbab_attribs.size()) {
             context = fnCreate(rbab_attribs);
             if (context)
                 break;
@@ -550,19 +536,18 @@ GLContextEGL::CreateGLContext(CreateCont
             break;
         NS_WARNING("Failed to create EGLContext with required_attribs");
 
         *out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_EGL_CREATE");
         return nullptr;
     } while (false);
     MOZ_ASSERT(context);
 
-    RefPtr<GLContextEGL> glContext = new GLContextEGL(flags, caps, shareContext,
-                                                      isOffscreen, config, surface,
-                                                      context);
+    RefPtr<GLContextEGL> glContext = new GLContextEGL(flags, caps, isOffscreen, config,
+                                                      surface, context);
     if (!glContext->Init()) {
         *out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_EGL_INIT");
         return nullptr;
     }
 
     return glContext.forget();
 }
 
@@ -740,18 +725,18 @@ GLContextProviderEGL::CreateWrappingExis
         return nullptr;
     }
 
     if (!aContext || !aSurface)
         return nullptr;
 
     SurfaceCaps caps = SurfaceCaps::Any();
     EGLConfig config = EGL_NO_CONFIG;
-    RefPtr<GLContextEGL> gl = new GLContextEGL(CreateContextFlags::NONE, caps, nullptr,
-                                               false, config, (EGLSurface)aSurface,
+    RefPtr<GLContextEGL> gl = new GLContextEGL(CreateContextFlags::NONE, caps, false,
+                                               config, (EGLSurface)aSurface,
                                                (EGLContext)aContext);
     gl->SetIsDoubleBuffered(true);
     gl->mOwnsContext = false;
 
     return gl.forget();
 }
 
 already_AddRefed<GLContext>
@@ -938,18 +923,18 @@ GLContextEGL::CreateEGLPBufferOffscreenC
                                                                             LOCAL_EGL_NONE,
                                                                             pbSize);
     if (!surface) {
         *out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_EGL_POT");
         NS_WARNING("Failed to create PBuffer for context!");
         return nullptr;
     }
 
-    RefPtr<GLContextEGL> gl = GLContextEGL::CreateGLContext(flags, configCaps, nullptr,
-                                                            true, config, surface,
+    RefPtr<GLContextEGL> gl = GLContextEGL::CreateGLContext(flags, configCaps, true,
+                                                            config, surface,
                                                             out_failureId);
     if (!gl) {
         NS_WARNING("Failed to create GLContext from PBuffer");
         sEGLLibrary.fDestroySurface(sEGLLibrary.Display(), surface);
         return nullptr;
     }
 
     return gl.forget();
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -477,20 +477,19 @@ GLXLibrary::AfterGLXCall() const
             NS_ABORT();
         }
         XSetErrorHandler(sOldErrorHandler);
     }
 }
 
 already_AddRefed<GLContextGLX>
 GLContextGLX::CreateGLContext(CreateContextFlags flags, const SurfaceCaps& caps,
-                              GLContextGLX* shareContext, bool isOffscreen,
-                              Display* display, GLXDrawable drawable, GLXFBConfig cfg,
-                              bool deleteDrawable, gfxXlibSurface* pixmap,
-                              ContextProfile profile)
+                              bool isOffscreen, Display* display, GLXDrawable drawable,
+                              GLXFBConfig cfg, bool deleteDrawable,
+                              gfxXlibSurface* pixmap, ContextProfile profile)
 {
     GLXLibrary& glx = sGLXLibrary;
 
     int db = 0;
     int err = glx.fGetFBConfigAttrib(display, cfg,
                                       LOCAL_GLX_DOUBLEBUFFER, &db);
     if (LOCAL_GLX_BAD_ATTRIBUTE != err) {
         if (ShouldSpew()) {
@@ -502,17 +501,16 @@ GLContextGLX::CreateGLContext(CreateCont
     RefPtr<GLContextGLX> glContext;
     bool error;
 
     OffMainThreadScopedXErrorHandler xErrorHandler;
 
     do {
         error = false;
 
-        GLXContext glxContext = shareContext ? shareContext->mContext : nullptr;
         if (glx.HasCreateContextAttribs()) {
             AutoTArray<int, 11> attrib_list;
             if (glx.HasRobustness()) {
                 const int robust_attribs[] = {
                     LOCAL_GLX_CONTEXT_FLAGS_ARB,
                     LOCAL_GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB,
                     LOCAL_GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
                     LOCAL_GLX_LOSE_CONTEXT_ON_RESET_ARB,
@@ -527,46 +525,40 @@ GLContextGLX::CreateGLContext(CreateCont
                 };
                 attrib_list.AppendElements(core_attribs, MOZ_ARRAY_LENGTH(core_attribs));
             };
             attrib_list.AppendElement(0);
 
             context = glx.fCreateContextAttribs(
                 display,
                 cfg,
-                glxContext,
+                nullptr,
                 True,
                 attrib_list.Elements());
         } else {
             context = glx.fCreateNewContext(
                 display,
                 cfg,
                 LOCAL_GLX_RGBA_TYPE,
-                glxContext,
+                nullptr,
                 True);
         }
 
         if (context) {
-            glContext = new GLContextGLX(flags, caps, shareContext, isOffscreen, display,
-                                         drawable, context, deleteDrawable, db, pixmap,
-                                         profile);
+            glContext = new GLContextGLX(flags, caps, isOffscreen, display, drawable,
+                                         context, deleteDrawable, db, pixmap, profile);
             if (!glContext->Init())
                 error = true;
         } else {
             error = true;
         }
 
         error |= xErrorHandler.SyncAndGetError(display);
 
         if (error) {
-            if (shareContext) {
-                shareContext = nullptr;
-                continue;
-            }
-
             NS_WARNING("Failed to create GLXContext!");
             glContext = nullptr; // note: this must be done while the graceful X error handler is set,
                                 // because glxMakeCurrent can give a GLXBadDrawable error
         }
 
         return glContext.forget();
     } while (true);
 }
@@ -707,26 +699,25 @@ bool
 GLContextGLX::RestoreDrawable()
 {
     return mGLX->fMakeCurrent(mDisplay, mDrawable, mContext);
 }
 
 GLContextGLX::GLContextGLX(
                   CreateContextFlags flags,
                   const SurfaceCaps& caps,
-                  GLContext* shareContext,
                   bool isOffscreen,
                   Display* aDisplay,
                   GLXDrawable aDrawable,
                   GLXContext aContext,
                   bool aDeleteDrawable,
                   bool aDoubleBuffered,
                   gfxXlibSurface* aPixmap,
                   ContextProfile profile)
-    : GLContext(flags, caps, shareContext, isOffscreen),
+    : GLContext(flags, caps, nullptr, isOffscreen),
       mContext(aContext),
       mDisplay(aDisplay),
       mDrawable(aDrawable),
       mDeleteDrawable(aDeleteDrawable),
       mDoubleBuffered(aDoubleBuffered),
       mGLX(&sGLXLibrary),
       mPixmap(aPixmap),
       mOwnsContext(true)
@@ -758,41 +749,36 @@ AreCompatibleVisuals(Visual* one, Visual
 
     if (one->bits_per_rgb != two->bits_per_rgb) {
         return false;
     }
 
     return true;
 }
 
-static StaticRefPtr<GLContext> gGlobalContext;
-
 already_AddRefed<GLContext>
 GLContextProviderGLX::CreateWrappingExisting(void* aContext, void* aSurface)
 {
     if (!sGLXLibrary.EnsureInitialized()) {
         return nullptr;
     }
 
     if (aContext && aSurface) {
         SurfaceCaps caps = SurfaceCaps::Any();
         RefPtr<GLContextGLX> glContext =
             new GLContextGLX(CreateContextFlags::NONE, caps,
-                             nullptr, // SharedContext
                              false, // Offscreen
                              (Display*)DefaultXDisplay(), // Display
                              (GLXDrawable)aSurface, (GLXContext)aContext,
                              false, // aDeleteDrawable,
                              true,
                              (gfxXlibSurface*)nullptr,
                              ContextProfile::OpenGLCompatibility);
 
         glContext->mOwnsContext = false;
-        gGlobalContext = glContext;
-
         return glContext.forget();
     }
 
     return nullptr;
 }
 
 already_AddRefed<GLContext>
 CreateForWidget(Display* aXDisplay, Window aXWindow,
@@ -822,27 +808,26 @@ CreateForWidget(Display* aXDisplay, Wind
     int visid;
     if (!GLContextGLX::FindFBConfigForWindow(aXDisplay, xscreen, aXWindow, &cfgs,
                                              &config, &visid, aWebRender))
     {
         return nullptr;
     }
 
     SurfaceCaps caps = SurfaceCaps::Any();
-    GLContextGLX* shareContext = GetGlobalContextGLX();
     RefPtr<GLContextGLX> gl;
     if (aWebRender) {
       gl = GLContextGLX::CreateGLContext(CreateContextFlags::NONE,
-                                         caps, shareContext, false,
+                                         caps, false,
                                          aXDisplay, aXWindow, config,
                                          //TODO: we might want to pass an additional bool to select GL core/compat
                                          false, nullptr, ContextProfile::OpenGLCore); //WR: required GL 3.2+
     } else {
       gl = GLContextGLX::CreateGLContext(CreateContextFlags::NONE,
-                                         caps, shareContext, false,
+                                         caps, false,
                                          aXDisplay, aXWindow, config,
                                          false);
     }
 
     return gl.forget();
 }
 
 already_AddRefed<GLContext>
@@ -1065,18 +1050,17 @@ CreateOffscreenPixmapContext(CreateConte
     if (pixmap == 0) {
         error = true;
     }
 
     bool serverError = xErrorHandler.SyncAndGetError(display);
     if (error || serverError)
         return nullptr;
 
-    GLContextGLX* shareContext = GetGlobalContextGLX();
-    return GLContextGLX::CreateGLContext(flags, minCaps, shareContext, true, display,
+    return GLContextGLX::CreateGLContext(flags, minCaps, true, display,
                                          pixmap, config, true, surface, profile);
 }
 
 /*static*/ already_AddRefed<GLContext>
 GLContextProviderGLX::CreateHeadless(CreateContextFlags flags,
                                      nsACString* const out_failureId)
 {
     IntSize dummySize = IntSize(16, 16);
@@ -1114,34 +1098,20 @@ GLContextProviderGLX::CreateOffscreen(co
     }
 
     return gl.forget();
 }
 
 /*static*/ GLContext*
 GLContextProviderGLX::GetGlobalContext()
 {
-    // TODO: get GLX context sharing to work well with multiple threads
-    if (gfxEnv::DisableContextSharingGlx())
-        return nullptr;
-
-    static bool triedToCreateContext = false;
-    if (!triedToCreateContext) {
-        triedToCreateContext = true;
-
-        MOZ_RELEASE_ASSERT(!gGlobalContext, "GFX: Global GL context already initialized.");
-        nsCString discardFailureId;
-        RefPtr<GLContext> temp = CreateHeadless(CreateContextFlags::NONE, &discardFailureId);
-        gGlobalContext = temp;
-    }
-
-    return gGlobalContext;
+    // Context sharing not supported.
+    return nullptr;
 }
 
 /*static*/ void
 GLContextProviderGLX::Shutdown()
 {
-    gGlobalContext = nullptr;
 }
 
 } /* namespace gl */
 } /* namespace mozilla */