[Mesa-dev] [PATCH] glx/dri2: Paper over errors in DRI2Connect when indirect (#28125)

Adam Jackson ajax at redhat.com
Tue May 24 15:10:20 PDT 2011


DRI2 will throw BadRequest for this when the client is not local, but
DRI2 is an implementation detail and not something callers should have
to know about.  Silently swallow errors in this case, and just propagate
the failure through DRI2Connect's return code.

Signed-off-by: Adam Jackson <ajax at redhat.com>
---
 src/glx/dri2.c |   41 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/src/glx/dri2.c b/src/glx/dri2.c
index adfd3d1..00a2cb4 100644
--- a/src/glx/dri2.c
+++ b/src/glx/dri2.c
@@ -244,8 +244,8 @@ DRI2QueryVersion(Display * dpy, int *major, int *minor)
    return True;
 }
 
-Bool
-DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName)
+static Bool
+doDRI2Connect(Display *dpy, XID window, char **driverName, char **deviceName)
 {
    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
    xDRI2ConnectReply rep;
@@ -300,6 +300,43 @@ DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName)
    return True;
 }
 
+/* swallow errors from DRI2Connect for non-local */
+
+static Display *dri2connect_display;
+static int (*old_handler)(Display *, XErrorEvent *);
+static XExtDisplayInfo *dri2connect_info;
+
+static int
+dri2connect_handler(Display *dpy, XErrorEvent *error)
+{
+    if (dpy == dri2connect_display &&
+	error->request_code == dri2connect_info->codes->major_opcode &&
+	error->minor_code == X_DRI2Connect &&
+	error->error_code == BadRequest)
+	return 0;
+
+    return old_handler(dpy, error);
+}
+
+Bool
+DRI2Connect(Display *dpy, XID window, char **driverName, char **deviceName)
+{
+    Bool ret;
+
+    XLockDisplay(dpy);
+    dri2connect_info = DRI2FindDisplay(dpy);
+    dri2connect_display = dpy;
+    old_handler = XSetErrorHandler(dri2connect_handler);
+    ret = doDRI2Connect(dpy, window, driverName, deviceName);
+    XSetErrorHandler(old_handler);
+    old_handler = NULL;
+    dri2connect_display = NULL;
+    dri2connect_info = NULL;
+    XUnlockDisplay(dpy);
+
+    return ret;
+}
+
 Bool
 DRI2Authenticate(Display * dpy, XID window, drm_magic_t magic)
 {
-- 
1.7.5.1



More information about the mesa-dev mailing list