glx: fix GLXChangeDrawableAttributesSGIX request
[mesa.git] / src / glx / dri2.c
index 5de55cdbf29505fa97bb9713bf2150f2851b8ea7..adfd3d1f7c8869023fdde46db26fd9a1b45f866e 100644 (file)
@@ -33,7 +33,6 @@
 
 #ifdef GLX_DIRECT_RENDERING
 
-#define NEED_REPLIES
 #include <stdio.h>
 #include <X11/Xlibint.h>
 #include <X11/extensions/Xext.h>
@@ -62,6 +61,8 @@ static Bool
 DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire);
 static Status
 DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire);
+static int
+DRI2Error(Display *display, xError *err, XExtCodes *codes, int *ret_code);
 
 static /* const */ XExtensionHooks dri2ExtensionHooks = {
   NULL,                   /* create_gc */
@@ -73,7 +74,7 @@ static /* const */ XExtensionHooks dri2ExtensionHooks = {
   DRI2CloseDisplay,       /* close_display */
   DRI2WireToEvent,        /* wire_to_event */
   DRI2EventToWire,        /* event_to_wire */
-  NULL,                   /* error */
+  DRI2Error,              /* error */
   NULL,                   /* error_string */
 };
 
@@ -87,7 +88,6 @@ static Bool
 DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
 {
    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
-   XExtDisplayInfo *glx_info = __glXFindDisplay(dpy);
 
    XextCheckExtension(dpy, info, dri2ExtensionName, False);
 
@@ -98,9 +98,13 @@ DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
    {
       GLXBufferSwapComplete *aevent = (GLXBufferSwapComplete *)event;
       xDRI2BufferSwapComplete *awire = (xDRI2BufferSwapComplete *)wire;
+
+      /* Ignore swap events if we're not looking for them */
+      aevent->type = dri2GetSwapEventType(dpy, awire->drawable);
+      if(!aevent->type)
+         return False;
+
       aevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *) wire);
-      aevent->type =
-         (glx_info->codes->first_event + GLX_BufferSwapComplete) & 0x75;
       aevent->send_event = (awire->type & 0x80) != 0;
       aevent->display = dpy;
       aevent->drawable = awire->drawable;
@@ -109,7 +113,7 @@ DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
         aevent->event_type = GLX_EXCHANGE_COMPLETE_INTEL;
         break;
       case DRI2_BLIT_COMPLETE:
-        aevent->event_type = GLX_BLIT_COMPLETE_INTEL;
+        aevent->event_type = GLX_COPY_COMPLETE_INTEL;
         break;
       case DRI2_FLIP_COMPLETE:
         aevent->event_type = GLX_FLIP_COMPLETE_INTEL;
@@ -160,6 +164,25 @@ DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire)
    return Success;
 }
 
+static int
+DRI2Error(Display *display, xError *err, XExtCodes *codes, int *ret_code)
+{
+    if (err->majorCode == codes->major_opcode &&
+       err->errorCode == BadDrawable &&
+       err->minorCode == X_DRI2CopyRegion)
+       return True;
+
+    /* If the X drawable was destroyed before the GLX drawable, the
+     * DRI2 drawble will be gone by the time we call
+     * DRI2DestroyDrawable.  So just ignore BadDrawable here. */
+    if (err->majorCode == codes->major_opcode &&
+       err->errorCode == BadDrawable &&
+       err->minorCode == X_DRI2DestroyDrawable)
+       return True;
+
+    return False;
+}
+
 Bool
 DRI2QueryExtension(Display * dpy, int *eventBase, int *errorBase)
 {