gallium/xlib: Fix glXMakeCurrent(dpy, None, None, ctx)
authorAdam Jackson <ajax@redhat.com>
Tue, 10 Sep 2019 19:11:19 +0000 (15:11 -0400)
committerAdam Jackson <ajax@nwnk.net>
Tue, 17 Sep 2019 20:16:00 +0000 (20:16 +0000)
This is entirely legal in GL 3.0+. I wonder how many more times I'll
need to fix this specific bug.

src/gallium/state_trackers/glx/xlib/glx_api.c
src/gallium/state_trackers/glx/xlib/xm_api.c

index ea503746604de7abb084eb1592bcad748b38942e..029268b32e6948ef3dbef13e4a565410303f49d7 100644 (file)
@@ -1188,33 +1188,41 @@ glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
       firsttime = 0;
    }
 
-   if (ctx && draw && read) {
-      XMesaBuffer drawBuffer, readBuffer;
+   if (ctx) {
+      XMesaBuffer drawBuffer = NULL, readBuffer = NULL;
       XMesaContext xmctx = glxCtx->xmesaContext;
 
-      /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
-      if (ctx == current) {
-         drawBuffer = XMesaFindBuffer( dpy, draw );
-      }
-      if (!drawBuffer) {
-         /* drawable must be a new window! */
-         drawBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, draw );
+      /* either both must be null, or both must be non-null */
+      if (!draw != !read)
+         return False;
+
+      if (draw) {
+         /* Find the XMesaBuffer which corresponds to 'draw' */
+         if (ctx == current) {
+            drawBuffer = XMesaFindBuffer( dpy, draw );
+         }
          if (!drawBuffer) {
-            /* Out of memory, or context/drawable depth mismatch */
-            return False;
+            /* drawable must be a new window! */
+            drawBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, draw );
+            if (!drawBuffer) {
+               /* Out of memory, or context/drawable depth mismatch */
+               return False;
+            }
          }
       }
 
-      /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
-      if (ctx == current) {
-         readBuffer = XMesaFindBuffer( dpy, read );
-      }
-      if (!readBuffer) {
-         /* drawable must be a new window! */
-         readBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, read );
+      if (read) {
+         /* Find the XMesaBuffer which corresponds to 'read' */
+         if (ctx == current) {
+            readBuffer = XMesaFindBuffer( dpy, read );
+         }
          if (!readBuffer) {
-            /* Out of memory, or context/drawable depth mismatch */
-            return False;
+            /* drawable must be a new window! */
+            readBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, read );
+            if (!readBuffer) {
+               /* Out of memory, or context/drawable depth mismatch */
+               return False;
+            }
          }
       }
 
@@ -1240,9 +1248,7 @@ glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
       return True;
    }
    else {
-      /* The args must either all be non-zero or all zero.
-       * This is an error.
-       */
+      /* We were given an invalid set of arguments */
       return False;
    }
 }
index 4351cd6e622521c7057b04ffd73a26336c7b16a2..64eee53f2b88bca38516415f68b5fa0a6d72e526 100644 (file)
@@ -1258,6 +1258,9 @@ xmesa_check_buffer_size(XMesaBuffer b)
 {
    GLuint old_width, old_height;
 
+   if (!b)
+      return;
+
    if (b->type == PBUFFER)
       return;
 
@@ -1287,8 +1290,9 @@ GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer,
    }
 
    if (c) {
-      if (!drawBuffer || !readBuffer)
-         return GL_FALSE;  /* must specify buffers! */
+      if (!drawBuffer != !readBuffer) {
+         return GL_FALSE;  /* must specify zero or two buffers! */
+      }
 
       if (c == old_ctx &&
          c->xm_buffer == drawBuffer &&
@@ -1302,10 +1306,13 @@ GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer,
       c->xm_buffer = drawBuffer;
       c->xm_read_buffer = readBuffer;
 
-      stapi->make_current(stapi, c->st, drawBuffer->stfb, readBuffer->stfb);
+      stapi->make_current(stapi, c->st,
+                          drawBuffer ? drawBuffer->stfb : NULL,
+                          readBuffer ? readBuffer->stfb : NULL);
 
       /* Solution to Stephane Rehel's problem with glXReleaseBuffersMESA(): */
-      drawBuffer->wasCurrent = GL_TRUE;
+      if (drawBuffer)
+         drawBuffer->wasCurrent = GL_TRUE;
    }
    else {
       /* Detach */