etnaviv: Add libdrm code as of 922d92994267743266024ecceb734ce0ebbca808
[mesa.git] / src / glx / drisw_glx.c
index 00c7fa100ab2a4b589bfb2c4bafeee37440b5c10..f38dbbca2dffee18ce327724774f9b62ba1ce65c 100644 (file)
@@ -73,11 +73,10 @@ handle_xerror(Display *dpy, XErrorEvent *event)
    (void) dpy;
 
    assert(xshm_opcode != -1);
-   if (event->request_code != xshm_opcode ||
-       event->minor_code != X_ShmAttach)
+   if (event->request_code != xshm_opcode)
       return 0;
 
-   xshm_error = 1;
+   xshm_error = event->error_code;
    return 0;
 }
 
@@ -147,6 +146,9 @@ XDestroyDrawable(struct drisw_drawable * pdp, Display * dpy, XID drawable)
    if (pdp->ximage)
       XDestroyImage(pdp->ximage);
 
+   if (pdp->shminfo.shmid > 0)
+      XShmDetach(dpy, &pdp->shminfo);
+
    free(pdp->visinfo);
 
    XFreeGC(dpy, pdp->gc);
@@ -596,6 +598,9 @@ drisw_create_context_attribs(struct glx_screen *base,
                                  &api, &reset, &release, error))
       return NULL;
 
+   if (!dri2_check_no_error(flags, shareList, major_ver, error))
+      return NULL;
+
    /* Check the renderType value */
    if (!validate_renderType_against_config(config_base, renderType)) {
        return NULL;
@@ -638,6 +643,9 @@ drisw_create_context_attribs(struct glx_screen *base,
        * GLX_CONTEXT_*_BIT values.
        */
       ctx_attribs[num_ctx_attribs++] = flags;
+
+      if (flags & __DRI_CTX_FLAG_NO_ERROR)
+         pcp->base.noError = GL_TRUE;
    }
 
    pcp->base.renderType = renderType;
@@ -817,9 +825,27 @@ driswBindExtensions(struct drisw_screen *psc, const __DRIextension **extensions)
 static int
 check_xshm(Display *dpy)
 {
+   int (*old_handler)(Display *, XErrorEvent *);
+
    int ignore;
+   XShmSegmentInfo info = { 0, };
+
+   if (!XQueryExtension(dpy, "MIT-SHM", &xshm_opcode, &ignore, &ignore))
+      return False;
+
+   old_handler = XSetErrorHandler(handle_xerror);
+   XShmDetach(dpy, &info);
+   XSync(dpy, False);
+   (void) XSetErrorHandler(old_handler);
+
+   /* BadRequest means we're a remote client. If we were local we'd
+    * expect BadValue since 'info' has an invalid segment name.
+    */
+   if (xshm_error == BadRequest)
+      return False;
 
-   return XQueryExtension(dpy, "MIT-SHM", &xshm_opcode, &ignore, &ignore);
+   xshm_error = 0;
+   return True;
 }
 
 static struct glx_screen *