Module: Mesa
Branch: staging/23.2
Commit: 0c84f8d915a52998d706600a6c362adf4bfcafe8
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=0c84f8d915a52998d706600a6c362adf4bfcafe8

Author: Mike Blumenkrantz <[email protected]>
Date:   Mon Jul 10 14:31:18 2023 -0400

glxsw: check geometry of drawables on creation

this mimics the dri codepath and allows early rejection of invalid
drawables to avoid subsequent breakage

cc: mesa-stable

Reviewed-by: Adam Jackson <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24075>
(cherry picked from commit 7100ef4566595f73b967231d0b877781d0911de5)

---

 .pick_status.json   |  2 +-
 src/glx/drisw_glx.c | 16 +++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 8453a2d21bb..387888c9cc4 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -22984,7 +22984,7 @@
         "description": "glxsw: check geometry of drawables on creation",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null,
         "notes": null
diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index 9b67a1a871f..7dd41eb8746 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -675,11 +675,22 @@ driswCreateDrawable(struct glx_screen *base, XID 
xDrawable,
 {
    struct drisw_drawable *pdp;
    __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes;
+   unsigned depth;
    struct drisw_screen *psc = (struct drisw_screen *) base;
    const __DRIswrastExtension *swrast = psc->swrast;
    const __DRIkopperExtension *kopper = psc->kopper;
    Display *dpy = psc->base.dpy;
 
+   xcb_connection_t *conn = XGetXCBConnection(dpy);
+   xcb_generic_error_t *error;
+   xcb_get_geometry_cookie_t cookie = xcb_get_geometry(conn, xDrawable);
+   xcb_get_geometry_reply_t *reply = xcb_get_geometry_reply(conn, cookie, 
&error);
+   if (reply)
+      depth = reply->depth;
+   free(reply);
+   if (!reply || error)
+      return NULL;
+
    pdp = calloc(1, sizeof(*pdp));
    if (!pdp)
       return NULL;
@@ -709,11 +720,6 @@ driswCreateDrawable(struct glx_screen *base, XID xDrawable,
 
    /* Otherwise, or if XGetVisualInfo failed, ask the server */
    if (pdp->xDepth == 0) {
-      Window root;
-      int x, y;
-      unsigned uw, uh, bw, depth;
-
-      XGetGeometry(dpy, xDrawable, &root, &x, &y, &uw, &uh, &bw, &depth);
       pdp->xDepth = depth;
    }
 

Reply via email to