Module: Mesa
Branch: main
Commit: c865416f4436707dd6e67121971cd7f4103e0bf7
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c865416f4436707dd6e67121971cd7f4103e0bf7

Author: Adam Jackson <[email protected]>
Date:   Tue Apr 26 16:01:20 2022 -0400

glx/kopper: Wire up a way for SwapBuffers to fail

Reviewed-By: Mike Blumenkrantz <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16038>

---

 include/kopper_interface.h         |  1 +
 src/gallium/frontends/dri/kopper.c | 23 ++++++++++++++++++-----
 src/glx/drisw_glx.c                |  3 +++
 src/glx/glxcmds.c                  |  3 ++-
 4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/include/kopper_interface.h b/include/kopper_interface.h
index 0f176485f33..8852252578d 100644
--- a/include/kopper_interface.h
+++ b/include/kopper_interface.h
@@ -73,6 +73,7 @@ struct __DRIkopperExtensionRec {
                                         const __DRIconfig *config,
                                         void *loaderPrivate,
                                         int pixmap);
+    int64_t (*swapBuffers)(__DRIdrawable *draw);
 };
 
 /**
diff --git a/src/gallium/frontends/dri/kopper.c 
b/src/gallium/frontends/dri/kopper.c
index 2038f13d418..c54d71ff3c1 100644
--- a/src/gallium/frontends/dri/kopper.c
+++ b/src/gallium/frontends/dri/kopper.c
@@ -812,29 +812,41 @@ kopper_create_buffer(__DRIscreen * sPriv,
    return TRUE;
 }
 
-static void
-kopper_swap_buffers(__DRIdrawable *dPriv)
+static int64_t
+kopperSwapBuffers(__DRIdrawable *dPriv)
 {
    struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv);
    struct dri_drawable *drawable = dri_drawable(dPriv);
+   struct kopper_drawable *kdraw = (struct kopper_drawable *)drawable;
    struct pipe_resource *ptex;
 
    if (!ctx)
-      return;
+      return 0;
 
    ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT];
    if (!ptex)
-      return;
+      return 0;
 
    drawable->texture_stamp = dPriv->lastStamp - 1;
    dri_flush(dPriv->driContextPriv, dPriv, __DRI2_FLUSH_DRAWABLE | 
__DRI2_FLUSH_CONTEXT, __DRI2_THROTTLE_SWAPBUFFER);
    kopper_copy_to_front(ctx->st->pipe, dPriv, ptex);
+   if (!kdraw->is_pixmap && !zink_kopper_check(ptex))
+      return -1;
    if (!drawable->textures[ST_ATTACHMENT_FRONT_LEFT]) {
-      return;
+      return 0;
    }
+
    /* have to manually swap the pointers here to make frontbuffer readback 
work */
    drawable->textures[ST_ATTACHMENT_BACK_LEFT] = 
drawable->textures[ST_ATTACHMENT_FRONT_LEFT];
    drawable->textures[ST_ATTACHMENT_FRONT_LEFT] = ptex;
+
+   return 0;
+}
+
+static void
+kopper_swap_buffers(__DRIdrawable *dPriv)
+{
+   kopperSwapBuffers(dPriv);
 }
 
 static __DRIdrawable *
@@ -878,6 +890,7 @@ kopperCreateNewDrawable(__DRIscreen *screen,
 const __DRIkopperExtension driKopperExtension = {
    .base = { __DRI_KOPPER, 1 },
    .createNewDrawable          = kopperCreateNewDrawable,
+   .swapBuffers                = kopperSwapBuffers,
 };
 
 const struct __DriverAPIRec galliumvk_driver_api = {
diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index 109634bf992..6f174d6f348 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -731,6 +731,9 @@ driswSwapBuffers(__GLXDRIdrawable * pdraw,
       glFlush();
    }
 
+   if (psc->kopper)
+       return psc->kopper->swapBuffers (pdp->driDrawable);
+
    (*psc->core->swapBuffers) (pdp->driDrawable);
 
    return 0;
diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c
index e494abe92c1..36003688be6 100644
--- a/src/glx/glxcmds.c
+++ b/src/glx/glxcmds.c
@@ -860,7 +860,8 @@ glXSwapBuffers(Display * dpy, GLXDrawable drawable)
       if (pdraw != NULL) {
          Bool flush = gc != &dummyContext && drawable == gc->currentDrawable;
 
-         pdraw->psc->driScreen->swapBuffers(pdraw, 0, 0, 0, flush);
+         if (pdraw->psc->driScreen->swapBuffers(pdraw, 0, 0, 0, flush) == -1)
+             __glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, 
false);
          return;
       }
    }

Reply via email to