glx/dri2: add dri2 prime support.
[mesa.git] / src / glx / dri2.c
index 229840d69195fcff74f674ddefb666d5bad93b3e..d6b99db768c611c5b6845fd11c64a121ede48f03 100644 (file)
@@ -190,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;
 }
 
@@ -260,6 +269,7 @@ DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName)
    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
    xDRI2ConnectReply rep;
    xDRI2ConnectReq *req;
+   char *prime;
 
    XextCheckExtension(dpy, info, dri2ExtensionName, False);
 
@@ -268,7 +278,19 @@ 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
+   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();