glx: Use _X_EXPORT instead of our own PUBLIC macro
[mesa.git] / src / glx / dri2.c
index 91053d3fb61d539a49556e3f8c99842ec86b09b9..f288ab8183557693d7ec4c12fd2371ecef2a8b6f 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 */
 };
 
@@ -81,15 +82,12 @@ static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay,
                                    dri2Info,
                                    dri2ExtensionName,
                                    &dri2ExtensionHooks,
-                                   1, NULL)
+                                   0, NULL)
 
 static Bool
 DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
 {
    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
-   XExtDisplayInfo *glx_info = __glXFindDisplay(dpy);
-   static int glx_event_base;
-   static Bool found_glx_info = False;
 
    XextCheckExtension(dpy, info, dri2ExtensionName, False);
 
@@ -100,9 +98,16 @@ DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
    {
       GLXBufferSwapComplete *aevent = (GLXBufferSwapComplete *)event;
       xDRI2BufferSwapComplete *awire = (xDRI2BufferSwapComplete *)wire;
+      __GLXDRIdrawable *pdraw;
+      __GLXdisplayPrivate *glx_dpy = __glXInitialize(dpy);
+
+      /* Ignore swap events if we're not looking for them */
+      pdraw = dri2GetGlxDrawableFromXDrawableId(dpy, awire->drawable);
+      if (!(pdraw->eventMask & GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK))
+        return False;
+
       aevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *) wire);
-      aevent->type =
-         (glx_info->codes->first_event + GLX_BufferSwapComplete) & 0x75;
+      aevent->type = glx_dpy->codes->first_event + GLX_BufferSwapComplete;
       aevent->send_event = (awire->type & 0x80) != 0;
       aevent->display = dpy;
       aevent->drawable = awire->drawable;
@@ -111,7 +116,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;
@@ -126,7 +131,15 @@ DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
       return True;
    }
 #endif
+#ifdef DRI2_InvalidateBuffers
+   case DRI2_InvalidateBuffers:
+   {
+      xDRI2InvalidateBuffers *awire = (xDRI2InvalidateBuffers *)wire;
 
+      dri2InvalidateBuffers(dpy, awire->drawable);
+      return False;
+   }
+#endif
    default:
       /* client doesn't support server event */
       break;
@@ -154,6 +167,17 @@ 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;
+
+    return False;
+}
+
 Bool
 DRI2QueryExtension(Display * dpy, int *eventBase, int *errorBase)
 {
@@ -174,6 +198,7 @@ DRI2QueryVersion(Display * dpy, int *major, int *minor)
    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
    xDRI2QueryVersionReply rep;
    xDRI2QueryVersionReq *req;
+   int i, nevents;
 
    XextCheckExtension(dpy, info, dri2ExtensionName, False);
 
@@ -193,6 +218,24 @@ DRI2QueryVersion(Display * dpy, int *major, int *minor)
    UnlockDisplay(dpy);
    SyncHandle();
 
+   switch (rep.minorVersion) {
+   case 1:
+          nevents = 0;
+          break;
+   case 2:
+          nevents = 1;
+          break;
+   case 3:
+   default:
+          nevents = 2;
+          break;
+   }
+       
+   for (i = 0; i < nevents; i++) {
+       XESetWireToEvent (dpy, info->codes->first_event + i, DRI2WireToEvent);
+       XESetEventToWire (dpy, info->codes->first_event + i, DRI2EventToWire);
+   }
+
    return True;
 }