Bug 1304195 - silence warnings from ScopedXErrorHandler when used off main thread if acknowledged. r=nical
authorLee Salzman <lsalzman@mozilla.com>
Tue, 27 Sep 2016 12:28:57 -0400
changeset 315405 5cf67663e9622d85040f5f286cf5b3376e3702fa
parent 315404 5285464565a804f3766f273b20fb7147f92db53e
child 315406 403d09199a2afa7b63f082c2f13ae07e71e584b9
push id82161
push userlsalzman@mozilla.com
push dateTue, 27 Sep 2016 21:29:29 +0000
treeherdermozilla-inbound@5cf67663e962 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1304195
milestone52.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 1304195 - silence warnings from ScopedXErrorHandler when used off main thread if acknowledged. r=nical MozReview-Commit-ID: 34LaghDR15f
gfx/gl/GLContextProviderGLX.cpp
gfx/src/X11Util.cpp
gfx/src/X11Util.h
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -818,17 +818,17 @@ GLContextGLX::CreateGLContext(CreateCont
             printf("[GLX] FBConfig is %sdouble-buffered\n", db ? "" : "not ");
         }
     }
 
     GLXContext context;
     RefPtr<GLContextGLX> glContext;
     bool error;
 
-    ScopedXErrorHandler xErrorHandler;
+    OffMainThreadScopedXErrorHandler xErrorHandler;
 
     do {
         error = false;
 
         GLXContext glxContext = shareContext ? shareContext->mContext : nullptr;
         if (glx.HasCreateContextAttribs()) {
             AutoTArray<int, 11> attrib_list;
             if (glx.HasRobustness()) {
@@ -1306,17 +1306,17 @@ CreateOffscreenPixmapContext(CreateConte
         NS_WARNING("Failed to find a compatible config.");
         return nullptr;
     }
 
     Visual* visual;
     int depth;
     FindVisualAndDepth(display, visid, &visual, &depth);
 
-    ScopedXErrorHandler xErrorHandler;
+    OffMainThreadScopedXErrorHandler xErrorHandler;
     bool error = false;
 
     Drawable drawable;
     GLXPixmap pixmap = 0;
 
     gfx::IntSize dummySize(16, 16);
     RefPtr<gfxXlibSurface> surface = gfxXlibSurface::Create(DefaultScreenOfDisplay(display),
                                                             visual,
--- a/gfx/src/X11Util.cpp
+++ b/gfx/src/X11Util.cpp
@@ -52,23 +52,25 @@ ScopedXErrorHandler::ErrorHandler(Displa
 {
     // only record the error if no error was previously recorded.
     // this means that in case of multiple errors, it's the first error that we report.
     if (!sXErrorPtr->mError.error_code)
       sXErrorPtr->mError = *ev;
     return 0;
 }
 
-ScopedXErrorHandler::ScopedXErrorHandler()
+ScopedXErrorHandler::ScopedXErrorHandler(bool aAllowOffMainThread)
 {
-    // Off main thread usage is not safe in general, but OMTC GL layers uses this
-    // with the main thread blocked, which makes it safe.
-    NS_WARNING_ASSERTION(
+    if (!aAllowOffMainThread) {
+      // Off main thread usage is not safe in general, but OMTC GL layers uses this
+      // with the main thread blocked, which makes it safe.
+      NS_WARNING_ASSERTION(
         NS_IsMainThread(),
         "ScopedXErrorHandler being called off main thread, may cause issues");
+    }
     // let sXErrorPtr point to this object's mXError object, but don't reset this mXError object!
     // think of the case of nested ScopedXErrorHandler's.
     mOldXErrorPtr = sXErrorPtr;
     sXErrorPtr = &mXError;
     mOldErrorHandler = XSetErrorHandler(ErrorHandler);
 }
 
 ScopedXErrorHandler::~ScopedXErrorHandler()
--- a/gfx/src/X11Util.h
+++ b/gfx/src/X11Util.h
@@ -113,24 +113,36 @@ private:
     // what to restore the error handler to on destruction
     int (*mOldErrorHandler)(Display *, XErrorEvent *);
 
 public:
 
     static int
     ErrorHandler(Display *, XErrorEvent *ev);
 
-    ScopedXErrorHandler();
+    /**
+     * @param aAllowOffMainThread whether to warn if used off main thread
+     */
+    explicit ScopedXErrorHandler(bool aAllowOffMainThread = false);
 
     ~ScopedXErrorHandler();
 
     /** \returns true if a X error occurred since the last time this method was called on this ScopedXErrorHandler object,
      *           or since the creation of this ScopedXErrorHandler object if this method was never called on it.
      *
      * \param ev this optional parameter, if set, will be filled with the XErrorEvent object. If multiple errors occurred,
      *           the first one will be returned.
      */
     bool SyncAndGetError(Display *dpy, XErrorEvent *ev = nullptr);
 };
 
+class OffMainThreadScopedXErrorHandler : public ScopedXErrorHandler
+{
+public:
+  OffMainThreadScopedXErrorHandler()
+    : ScopedXErrorHandler(true)
+  {
+  }
+};
+
 } // namespace mozilla
 
 #endif  // mozilla_X11Util_h