Bug 1289251 - Allow GLContextProviderGLX to create a GLContext out of process. r=acomminos,jgilbert
☠☠ backed out by 3e28c1a68c24 ☠ ☠
authorRyan Hunt <rhunt@mozilla.com>
Mon, 29 Aug 2016 17:14:20 -0700
changeset 312456 2df13967b7466c92cb629e3600a101a1826dfad8
parent 312455 c0285428a8a04dd0d8f7ad1ed46a2e04147dfbc6
child 312457 5a63a118b8b9660cd8ec16490a39d0d2f505773e
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersacomminos, jgilbert
bugs1289251
milestone51.0a1
Bug 1289251 - Allow GLContextProviderGLX to create a GLContext out of process. r=acomminos,jgilbert MozReview-Commit-ID: 9AdBGkEzI1n
gfx/gl/GLContextProviderGLX.cpp
widget/gtk/X11CompositorWidget.h
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -11,16 +11,17 @@
 
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include "X11UndefineNone.h"
 
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/widget/CompositorWidget.h"
+#include "mozilla/widget/X11CompositorWidget.h"
 #include "mozilla/Unused.h"
 
 #include "prenv.h"
 #include "GLContextProvider.h"
 #include "GLLibraryLoader.h"
 #include "nsDebug.h"
 #include "nsIWidget.h"
 #include "GLXLibrary.h"
@@ -1092,62 +1093,76 @@ GLContextProviderGLX::CreateWrappingExis
 
         return glContext.forget();
     }
 
     return nullptr;
 }
 
 already_AddRefed<GLContext>
-GLContextProviderGLX::CreateForCompositorWidget(CompositorWidget* aCompositorWidget, bool aForceAccelerated)
-{
-    return CreateForWindow(aCompositorWidget->RealWidget(), aForceAccelerated);
-}
-
-already_AddRefed<GLContext>
-GLContextProviderGLX::CreateForWindow(nsIWidget* aWidget, bool aForceAccelerated)
+CreateForWidget(Display* aXDisplay, Window aXWindow, bool aForceAccelerated)
 {
     if (!sGLXLibrary.EnsureInitialized()) {
         return nullptr;
     }
 
     // Currently, we take whatever Visual the window already has, and
     // try to create an fbconfig for that visual.  This isn't
     // necessarily what we want in the long run; an fbconfig may not
     // be available for the existing visual, or if it is, the GL
     // performance might be suboptimal.  But using the existing visual
     // is a relatively safe intermediate step.
 
-    Display* display = (Display*)aWidget->GetNativeData(NS_NATIVE_COMPOSITOR_DISPLAY);
-    if (!display) {
+    if (!aXDisplay) {
         NS_ERROR("X Display required for GLX Context provider");
         return nullptr;
     }
 
-    int xscreen = DefaultScreen(display);
-    Window window = GET_NATIVE_WINDOW(aWidget);
+    int xscreen = DefaultScreen(aXDisplay);
 
     ScopedXFree<GLXFBConfig> cfgs;
     GLXFBConfig config;
     int visid;
-    if (!GLContextGLX::FindFBConfigForWindow(display, xscreen, window, &cfgs,
+    if (!GLContextGLX::FindFBConfigForWindow(aXDisplay, xscreen, aXWindow, &cfgs,
                                              &config, &visid))
     {
         return nullptr;
     }
 
     SurfaceCaps caps = SurfaceCaps::Any();
     GLContextGLX* shareContext = GetGlobalContextGLX();
     RefPtr<GLContextGLX> gl = GLContextGLX::CreateGLContext(CreateContextFlags::NONE,
                                                             caps, shareContext, false,
-                                                            display, window, config,
+                                                            aXDisplay, aXWindow, config,
                                                             false);
     return gl.forget();
 }
 
+already_AddRefed<GLContext>
+GLContextProviderGLX::CreateForCompositorWidget(CompositorWidget* aCompositorWidget, bool aForceAccelerated)
+{
+    X11CompositorWidget* compWidget = aCompositorWidget->AsX11();
+    MOZ_ASSERT(compWidget);
+
+    return CreateForWidget(compWidget->XDisplay(),
+                           compWidget->XWindow(),
+                           aForceAccelerated);
+}
+
+already_AddRefed<GLContext>
+GLContextProviderGLX::CreateForWindow(nsIWidget* aWidget, bool aForceAccelerated)
+{
+    Display* display = (Display*)aWidget->GetNativeData(NS_NATIVE_COMPOSITOR_DISPLAY);
+    Window window = GET_NATIVE_WINDOW(aWidget);
+
+    return CreateForWidget(display,
+                           window,
+                           aForceAccelerated);
+}
+
 static bool
 ChooseConfig(GLXLibrary* glx, Display* display, int screen, const SurfaceCaps& minCaps,
              ScopedXFree<GLXFBConfig>* const out_scopedConfigArr,
              GLXFBConfig* const out_config, int* const out_visid)
 {
     ScopedXFree<GLXFBConfig>& scopedConfigArr = *out_scopedConfigArr;
 
     if (minCaps.antialias)
--- a/widget/gtk/X11CompositorWidget.h
+++ b/widget/gtk/X11CompositorWidget.h
@@ -44,16 +44,19 @@ public:
 
   void NotifyClientSizeChanged(const LayoutDeviceIntSize& aClientSize) override;
   LayoutDeviceIntSize GetClientSize() override;
 
   nsIWidget* RealWidget() override;
   X11CompositorWidget* AsX11() override { return this; }
   CompositorWidgetDelegate* AsDelegate() override { return this; }
 
+  Display* XDisplay() const { return mXDisplay; }
+  Window XWindow() const { return mXWindow; }
+
 protected:
   nsWindow* mWidget;
 
 private:
   LayoutDeviceIntSize mClientSize;
 
   Display* mXDisplay;
   Window   mXWindow;