glx: Make glXGetScreenDriver() work for DRI2
authorAdam Jackson <ajax@redhat.com>
Tue, 14 Apr 2009 21:56:29 +0000 (17:56 -0400)
committerAdam Jackson <ajax@redhat.com>
Tue, 14 Apr 2009 21:56:29 +0000 (17:56 -0400)
src/glx/x11/dri_glx.c

index 3089aa172856dce6bf00bf47a839f31391230405..87d62ad8468f281590f3c753a9a2bf6d7378fb70 100644 (file)
@@ -40,6 +40,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "glxclient.h"
 #include "glcontextmodes.h"
 #include "xf86dri.h"
+#include "dri2.h"
 #include "sarea.h"
 #include <dlfcn.h>
 #include <sys/types.h>
@@ -75,32 +76,45 @@ struct __GLXDRIcontextPrivateRec {
  */
 static Bool driGetDriverName(Display *dpy, int scrNum, char **driverName)
 {
-   int directCapable;
-   Bool b;
-   int driverMajor, driverMinor, driverPatch;
+    int directCapable;
+    Bool b;
+    int event, error;
+    int driverMajor, driverMinor, driverPatch;
 
-   *driverName = NULL;
+    *driverName = NULL;
 
-   if (!XF86DRIQueryDirectRenderingCapable(dpy, scrNum, &directCapable)) {
-      ErrorMessageF("XF86DRIQueryDirectRenderingCapable failed\n");
-      return False;
-   }
-   if (!directCapable) {
-      ErrorMessageF("XF86DRIQueryDirectRenderingCapable returned false\n");
-      return False;
-   }
+    if (XF86DRIQueryExtension(dpy, &event, &error)) { /* DRI1 */
+       if (!XF86DRIQueryDirectRenderingCapable(dpy, scrNum, &directCapable)) {
+           ErrorMessageF("XF86DRIQueryDirectRenderingCapable failed\n");
+           return False;
+       }
+       if (!directCapable) {
+           ErrorMessageF("XF86DRIQueryDirectRenderingCapable returned false\n");
+           return False;
+       }
 
-   b = XF86DRIGetClientDriverName(dpy, scrNum, &driverMajor, &driverMinor,
-                                  &driverPatch, driverName);
-   if (!b) {
-      ErrorMessageF("Cannot determine driver name for screen %d\n", scrNum);
-      return False;
-   }
+       b = XF86DRIGetClientDriverName(dpy, scrNum, &driverMajor, &driverMinor,
+               &driverPatch, driverName);
+       if (!b) {
+           ErrorMessageF("Cannot determine driver name for screen %d\n", scrNum);
+           return False;
+       }
+
+       InfoMessageF("XF86DRIGetClientDriverName: %d.%d.%d %s (screen %d)\n",
+               driverMajor, driverMinor, driverPatch, *driverName, scrNum);
+
+       return True;
+    } else if (DRI2QueryExtension(dpy, &event, &error)) { /* DRI2 */
+       char *dev;
+       Bool ret = DRI2Connect(dpy, RootWindow(dpy, scrNum), driverName, &dev);
 
-   InfoMessageF("XF86DRIGetClientDriverName: %d.%d.%d %s (screen %d)\n",
-            driverMajor, driverMinor, driverPatch, *driverName, scrNum);
+       if (ret)
+           Xfree(dev);
+
+       return ret;
+    }
 
-   return True;
+    return False;
 }
 
 /*