glapi: Do not use backtrace on Cygwin.
[mesa.git] / src / glx / dri2.c
index adfd3d1f7c8869023fdde46db26fd9a1b45f866e..e17da6f7fc213c117db59c4dfa1526f3ea6afdcc 100644 (file)
@@ -88,6 +88,7 @@ static Bool
 DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
 {
    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+   struct glx_drawable *glxDraw;
 
    XextCheckExtension(dpy, info, dri2ExtensionName, False);
 
@@ -97,7 +98,10 @@ DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
    case DRI2_BufferSwapComplete:
    {
       GLXBufferSwapComplete *aevent = (GLXBufferSwapComplete *)event;
-      xDRI2BufferSwapComplete *awire = (xDRI2BufferSwapComplete *)wire;
+      xDRI2BufferSwapComplete2 *awire = (xDRI2BufferSwapComplete2 *)wire;
+      __GLXDRIdrawable *pdraw;
+
+      pdraw = dri2GetGlxDrawableFromXDrawableId(dpy, awire->drawable);
 
       /* Ignore swap events if we're not looking for them */
       aevent->type = dri2GetSwapEventType(dpy, awire->drawable);
@@ -124,7 +128,13 @@ DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
       }
       aevent->ust = ((CARD64)awire->ust_hi << 32) | awire->ust_lo;
       aevent->msc = ((CARD64)awire->msc_hi << 32) | awire->msc_lo;
-      aevent->sbc = ((CARD64)awire->sbc_hi << 32) | awire->sbc_lo;
+
+      glxDraw = GetGLXDrawable(dpy, pdraw->drawable);
+      if (awire->sbc < glxDraw->lastEventSbc)
+        glxDraw->eventSbcWrap += 0x100000000;
+      glxDraw->lastEventSbc = awire->sbc;
+      aevent->sbc = awire->sbc + glxDraw->eventSbcWrap;
+
       return True;
    }
 #endif
@@ -180,6 +190,15 @@ DRI2Error(Display *display, xError *err, XExtCodes *codes, int *ret_code)
        err->minorCode == X_DRI2DestroyDrawable)
        return True;
 
+    /* If the server is non-local DRI2Connect will raise BadRequest.
+     * Swallow this so that DRI2Connect can signal this in its return code */
+    if (err->majorCode == codes->major_opcode &&
+        err->minorCode == X_DRI2Connect &&
+        err->errorCode == BadRequest) {
+       *ret_code = False;
+       return True;
+    }
+
     return False;
 }
 
@@ -258,7 +277,22 @@ DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName)
    req->reqType = info->codes->major_opcode;
    req->dri2ReqType = X_DRI2Connect;
    req->window = window;
+
    req->driverType = DRI2DriverDRI;
+#ifdef DRI2DriverPrimeShift
+   {
+      char *prime = getenv("DRI_PRIME");
+      if (prime) {
+         uint32_t primeid;
+         errno = 0;
+         primeid = strtoul(prime, NULL, 0);
+         if (errno == 0)
+            req->driverType |=
+               ((primeid & DRI2DriverPrimeMask) << DRI2DriverPrimeShift);
+      }
+   }
+#endif
+
    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
       UnlockDisplay(dpy);
       SyncHandle();
@@ -271,7 +305,7 @@ DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName)
       return False;
    }
 
-   *driverName = Xmalloc(rep.driverNameLength + 1);
+   *driverName = malloc(rep.driverNameLength + 1);
    if (*driverName == NULL) {
       _XEatData(dpy,
                 ((rep.driverNameLength + 3) & ~3) +
@@ -283,9 +317,9 @@ DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName)
    _XReadPad(dpy, *driverName, rep.driverNameLength);
    (*driverName)[rep.driverNameLength] = '\0';
 
-   *deviceName = Xmalloc(rep.deviceNameLength + 1);
+   *deviceName = malloc(rep.deviceNameLength + 1);
    if (*deviceName == NULL) {
-      Xfree(*driverName);
+      free(*driverName);
       _XEatData(dpy, ((rep.deviceNameLength + 3) & ~3));
       UnlockDisplay(dpy);
       SyncHandle();
@@ -399,7 +433,7 @@ DRI2GetBuffers(Display * dpy, XID drawable,
    *height = rep.height;
    *outCount = rep.count;
 
-   buffers = Xmalloc(rep.count * sizeof buffers[0]);
+   buffers = malloc(rep.count * sizeof buffers[0]);
    if (buffers == NULL) {
       _XEatData(dpy, rep.count * sizeof repBuffer);
       UnlockDisplay(dpy);
@@ -458,7 +492,7 @@ DRI2GetBuffersWithFormat(Display * dpy, XID drawable,
    *height = rep.height;
    *outCount = rep.count;
 
-   buffers = Xmalloc(rep.count * sizeof buffers[0]);
+   buffers = malloc(rep.count * sizeof buffers[0]);
    if (buffers == NULL) {
       _XEatData(dpy, rep.count * sizeof repBuffer);
       UnlockDisplay(dpy);