[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freedesktop-xorg
Subject:    [PATCH xf86-video-nested] Do not error out if XShmAttach fails.
From:       Nick Alcock <nick.alcock () esperi ! org ! uk>
Date:       2012-10-15 14:25:11
Message-ID: 87obk3g6d4.fsf () spindle ! srvr ! nix
[Download RAW message or body]

It is normal for XShmAttach to fail with BadAccess if we are connected to a remote
X server.  Do not fail in this case.  (Largely copied from x11perf.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
---
 src/xlibclient.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/xlibclient.c b/src/xlibclient.c
index 1aa3590..cadb87e 100644
--- a/src/xlibclient.c
+++ b/src/xlibclient.c
@@ -95,6 +95,18 @@ NestedClientValidDepth(int depth) {
     return TRUE;
 }
 
+static Bool hadShmError;
+static int (*origErrorHandler)(Display *, XErrorEvent *);
+
+static int ShmErrorHandler(Display *d, XErrorEvent *e) {
+    if(e->error_code == BadAccess) {
+	/* Probably a remote display.  Fall back to non-SHM. */
+        hadShmError = True;
+        return 0;
+    } else
+        return (*origErrorHandler)(d, e);
+}
+
 static Bool
 NestedClientTryXShm(NestedClientPrivatePtr pPriv, int scrnIndex, int width, int height, int depth) {
     int shmMajor, shmMinor;
@@ -147,11 +159,21 @@ NestedClientTryXShm(NestedClientPrivatePtr pPriv, int scrnIndex, int width, int
         return FALSE;
     }
 
+    XSync(pPriv->display, True);
+    hadShmError = False;
+    origErrorHandler = XSetErrorHandler(ShmErrorHandler);
     pPriv->img->data = pPriv->shminfo.shmaddr;
     pPriv->shminfo.readOnly = FALSE;
     XShmAttach(pPriv->display, &pPriv->shminfo);
+    XSync(pPriv->display, True);
+    XSetErrorHandler(origErrorHandler);
+    if (hadShmError) {
+        xf86DrvMsg(scrnIndex, X_ERROR, "XShmAttach failed.  Dropping XShm support.\n");
+        shmdt(pPriv->shminfo.shmaddr);
+        XDestroyImage(pPriv->img);
+        return FALSE;
+    }
     pPriv->usingShm = TRUE;
-
     return TRUE;
 }
 
-- 
1.7.12.1.157.geb3194e

_______________________________________________
xorg@lists.x.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: http://lists.x.org/mailman/listinfo/xorg
Your subscription address: freedesktop-xorg@progressive-comp.com
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic