Bug 1291845 - Use the compositor X display on the GLX VSync thread. r?lsalzman draft
authorAndrew Comminos <andrew@comminos.com>
Wed, 03 Aug 2016 15:59:15 -0400
changeset 396388 9ab1ed45c897282c7f2bc36141ba0ee94c1badb5
parent 396180 8ab41761981936b5fb655e07f4d0d725ea514905
child 527190 d868a48c5f6e3e8798c466a27b6af7b4ad7dad6a
push id24987
push userbmo:andrew@comminos.com
push dateWed, 03 Aug 2016 19:59:44 +0000
reviewerslsalzman
bugs1291845
milestone51.0a1
Bug 1291845 - Use the compositor X display on the GLX VSync thread. r?lsalzman MozReview-Commit-ID: ZC5MJd0BUJ
gfx/thebes/gfxPlatformGtk.cpp
--- a/gfx/thebes/gfxPlatformGtk.cpp
+++ b/gfx/thebes/gfxPlatformGtk.cpp
@@ -667,17 +667,16 @@ public:
   }
 
   class GLXDisplay final : public VsyncSource::Display
   {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GLXDisplay)
 
   public:
     GLXDisplay() : mGLContext(nullptr)
-                 , mXDisplay(nullptr)
                  , mSetupLock("GLXVsyncSetupLock")
                  , mVsyncThread("GLXVsyncThread")
                  , mVsyncTask(nullptr)
                  , mVsyncEnabledLock("GLXVsyncEnabledLock")
                  , mVsyncEnabled(false)
     {
     }
 
@@ -700,43 +699,36 @@ public:
 
     // Called on the Vsync thread to setup the GL context.
     void SetupGLContext()
     {
         MonitorAutoLock lock(mSetupLock);
         MOZ_ASSERT(!NS_IsMainThread());
         MOZ_ASSERT(!mGLContext, "GLContext already setup!");
 
-        // Create video sync timer on a separate Display to prevent locking the
-        // main thread X display.
-        mXDisplay = XOpenDisplay(nullptr);
-        if (!mXDisplay) {
-          lock.NotifyAll();
-          return;
-        }
-
+        _XDisplay* display = gfxPlatformGtk::GetPlatform()->GetCompositorDisplay();
         // Most compositors wait for vsync events on the root window.
-        Window root = DefaultRootWindow(mXDisplay);
-        int screen = DefaultScreen(mXDisplay);
+        Window root = DefaultRootWindow(display);
+        int screen = DefaultScreen(display);
 
         ScopedXFree<GLXFBConfig> cfgs;
         GLXFBConfig config;
         int visid;
-        if (!gl::GLContextGLX::FindFBConfigForWindow(mXDisplay, screen, root,
+        if (!gl::GLContextGLX::FindFBConfigForWindow(display, screen, root,
                                                      &cfgs, &config, &visid)) {
           lock.NotifyAll();
           return;
         }
 
         mGLContext = gl::GLContextGLX::CreateGLContext(
             gl::CreateContextFlags::NONE,
             gl::SurfaceCaps::Any(),
             nullptr,
             false,
-            mXDisplay,
+            display,
             root,
             config,
             false);
 
         if (!mGLContext) {
           lock.NotifyAll();
           return;
         }
@@ -848,22 +840,20 @@ public:
         NotifyVsync(lastVsync);
       }
     }
 
     void Cleanup() {
       MOZ_ASSERT(!NS_IsMainThread());
 
       mGLContext = nullptr;
-      XCloseDisplay(mXDisplay);
     }
 
     // Owned by the vsync thread.
     RefPtr<gl::GLContextGLX> mGLContext;
-    _XDisplay* mXDisplay;
     Monitor mSetupLock;
     base::Thread mVsyncThread;
     RefPtr<Runnable> mVsyncTask;
     Monitor mVsyncEnabledLock;
     bool mVsyncEnabled;
   };
 private:
   // We need a refcounted VsyncSource::Display to use chromium IPC runnables.