Bug 1478454 - [Linux/WebRender] Create glxContext with GLX visual chosen at nsWindow::Create(), r?jgilbert draft
authorMartin Stransky <stransky@redhat.com>
Fri, 03 Aug 2018 16:20:09 +0200
changeset 827552 0256b130ef4c53761695f9e701962cb4f7260075
parent 827551 3044bedc568c96cb5fad0d96e4a6bee47122fd94
push id118547
push userstransky@redhat.com
push dateWed, 08 Aug 2018 12:09:51 +0000
reviewersjgilbert
bugs1478454
milestone63.0a1
Bug 1478454 - [Linux/WebRender] Create glxContext with GLX visual chosen at nsWindow::Create(), r?jgilbert We need to use the same visual for X drawable and glxContext, otherwise we get BadMatch when we try to make the glxContext current. The correct glx visual is already configured at nsWindow::Create() so just use it if it also matches the frame buffer config. MozReview-Commit-ID: 78IIfiwOnsf
gfx/gl/GLContextProviderGLX.cpp
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -1007,38 +1007,48 @@ GLContextGLX::FindFBConfigForWindow(Disp
     const VisualID windowVisualID = XVisualIDFromVisual(windowAttrs.visual);
 #ifdef DEBUG
     printf("[GLX] window %lx has VisualID 0x%lx\n", window, windowVisualID);
 #endif
 
     for (int i = 0; i < numConfigs; i++) {
         int visid = X11None;
         sGLXLibrary.fGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_VISUAL_ID, &visid);
-        if (!visid) {
-            continue;
+        if (visid) {
+            // WebRender compatible GLX visual is configured
+            // at nsWindow::Create() by GLContextGLX::FindVisual(),
+            // just reuse it here.
+            if (windowVisualID == static_cast<VisualID>(visid)) {
+                *out_config = cfgs[i];
+                *out_visid = visid;
+                return true;
+            }
         }
-        if (aWebRender || sGLXLibrary.IsATI()) {
+    }
+
+    // We don't have a frame buffer visual which matches the GLX visual
+    // from GLContextGLX::FindVisual(). Let's try to find a near one and hope
+    // we're not on NVIDIA (Bug 1478454) as it causes X11 BadMatch error there.
+    for (int i = 0; i < numConfigs; i++) {
+        int visid = X11None;
+        sGLXLibrary.fGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_VISUAL_ID, &visid);
+        if (visid) {
             int depth;
             Visual* visual;
             FindVisualAndDepth(display, visid, &visual, &depth);
             if (depth == windowAttrs.depth &&
                 AreCompatibleVisuals(windowAttrs.visual, visual)) {
                 *out_config = cfgs[i];
                 *out_visid = visid;
                 return true;
             }
-        } else {
-            if (windowVisualID == static_cast<VisualID>(visid)) {
-                *out_config = cfgs[i];
-                *out_visid = visid;
-                return true;
-            }
         }
     }
 
+
     NS_WARNING("[GLX] Couldn't find a FBConfig matching window visual");
     return false;
 }
 
 static already_AddRefed<GLContextGLX>
 CreateOffscreenPixmapContext(CreateContextFlags flags, const IntSize& size,
                              const SurfaceCaps& minCaps, nsACString* const out_failureId)
 {