Bug 1287463 - Use a separate X display for non-XRender basic composition paths. r=lsalzman
authorAndrew Comminos <andrew@comminos.com>
Mon, 18 Jul 2016 11:49:51 -0400
changeset 330500 2a69345f4f4eeb804e6a96c70f086f10e9849724
parent 330499 f89771c94b4ab6dc18a76d14433ae52dc219d4ae
child 330501 9edae2531988223eb282ec0995eb736fd0fb8762
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman
bugs1287463
milestone50.0a1
Bug 1287463 - Use a separate X display for non-XRender basic composition paths. r=lsalzman MozReview-Commit-ID: HQn0nTirgBL
widget/gtk/nsWindow.cpp
widget/nsShmImage.cpp
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -109,16 +109,17 @@ using namespace mozilla::widget;
 #include "gfxContext.h"
 #include "gfxImageSurface.h"
 #include "gfxUtils.h"
 #include "Layers.h"
 #include "GLContextProvider.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/HelpersCairo.h"
 #include "mozilla/layers/CompositorBridgeParent.h"
+#include "mozilla/layers/CompositorThread.h"
 
 #ifdef MOZ_X11
 #include "gfxXlibSurface.h"
 #include "WindowSurfaceX11Image.h"
 #include "WindowSurfaceX11SHM.h"
 #include "WindowSurfaceXRender.h"
 #endif // MOZ_X11
 
@@ -7046,19 +7047,26 @@ nsWindow::CreateWindowSurface()
 
 #ifdef MOZ_WIDGET_GTK
   if (gfxPlatformGtk::GetPlatform()->UseXRender()) {
     LOGDRAW(("Drawing to nsWindow %p using XRender\n", (void*)this));
     return MakeUnique<WindowSurfaceXRender>(mXDisplay, mXWindow, mXVisual, mXDepth);
   }
 #endif // MOZ_WIDGET_GTK
 
+  Display* display;
+  if (CompositorThreadHolder::IsInCompositorThread()) {
+    display = gfxPlatformGtk::GetPlatform()->GetCompositorDisplay();
+  } else {
+    display = mXDisplay;
+  }
+
 #ifdef MOZ_HAVE_SHMIMAGE
   if (nsShmImage::UseShm()) {
     LOGDRAW(("Drawing to nsWindow %p using MIT-SHM\n", (void*)this));
-    return MakeUnique<WindowSurfaceX11SHM>(mXDisplay, mXWindow, mXVisual, mXDepth);
+    return MakeUnique<WindowSurfaceX11SHM>(display, mXWindow, mXVisual, mXDepth);
   }
 #endif // MOZ_HAVE_SHMIMAGE
 
   LOGDRAW(("Drawing to nsWindow %p using XPutImage\n", (void*)this));
-  return MakeUnique<WindowSurfaceX11Image>(mXDisplay, mXWindow, mXVisual, mXDepth);
+  return MakeUnique<WindowSurfaceX11Image>(display, mXWindow, mXVisual, mXDepth);
 #endif // MOZ_X11
 }
--- a/widget/nsShmImage.cpp
+++ b/widget/nsShmImage.cpp
@@ -33,16 +33,22 @@ nsShmImage::nsShmImage(Display* aDisplay
   , mPixmap(XCB_NONE)
   , mGC(XCB_NONE)
   , mShmSeg(XCB_NONE)
   , mShmId(-1)
   , mShmAddr(nullptr)
 {
   mConnection = XGetXCBConnection(aDisplay);
   mozilla::PodZero(&mLastRequest);
+  if (aDisplay == mozilla::DefaultXDisplay()) {
+    // If another thread spins the X event loop during a checked call,
+    // an error that should've been checked by XCB may be handled by the Xlib
+    // error handler. See bug 1287463.
+    NS_WARNING("Main thread X display used with nsShmImage!");
+  }
 }
 
 nsShmImage::~nsShmImage()
 {
   DestroyImage();
 }
 
 // If XShm isn't available to our client, we'll try XShm once, fail,