egl/dri2: use the correct screen index
authorMarek Olšák <marek.olsak@amd.com>
Tue, 19 Aug 2014 22:33:34 +0000 (00:33 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 1 Sep 2014 18:09:19 +0000 (20:09 +0200)
Required for multi-GPU configuration where each GPU has its own X screen.

src/egl/drivers/dri2/egl_dri2.h
src/egl/drivers/dri2/platform_x11.c

index 0dd9d69d08e08bd814f9c75b2c3784d15a082147..52f05fbfd3ccef95f56163f43052f773eab076ef 100644 (file)
@@ -184,6 +184,7 @@ struct dri2_egl_display
 
 #ifdef HAVE_X11_PLATFORM
    xcb_connection_t         *conn;
+   int                      screen;
 #endif
 
 #ifdef HAVE_WAYLAND_PLATFORM
index 4ef1f3e4b440e0ff0ca8097f7c677b7473594825..a7a73383cbee050a6cb09e9a9ab120e28ad61d12 100644 (file)
@@ -178,6 +178,17 @@ swrastGetImage(__DRIdrawable * read,
 }
 
 
+static xcb_screen_t *
+get_xcb_screen(xcb_screen_iterator_t iter, int screen)
+{
+    for (; iter.rem; --screen, xcb_screen_next(&iter))
+        if (screen == 0)
+            return iter.data;
+
+    return NULL;
+}
+
+
 /**
  * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
  */
@@ -214,7 +225,8 @@ dri2_x11_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
       dri2_surf->drawable = xcb_generate_id(dri2_dpy->conn);
       s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
       xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize,
-                       dri2_surf->drawable, s.data->root,
+                        dri2_surf->drawable,
+                        get_xcb_screen(s, dri2_dpy->screen)->root,
                        dri2_surf->base.Width, dri2_surf->base.Height);
    } else {
       dri2_surf->drawable = drawable;
@@ -515,9 +527,9 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy)
                                               XCB_DRI2_MINOR_VERSION);
 
    s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
-   connect_cookie = xcb_dri2_connect_unchecked (dri2_dpy->conn,
-                                               s.data->root,
-                                               XCB_DRI2_DRIVER_TYPE_DRI);
+   connect_cookie = xcb_dri2_connect_unchecked(dri2_dpy->conn,
+                                   get_xcb_screen(s, dri2_dpy->screen)->root,
+                                   XCB_DRI2_DRIVER_TYPE_DRI);
 
    xfixes_query =
       xcb_xfixes_query_version_reply (dri2_dpy->conn,
@@ -581,7 +593,8 @@ dri2_x11_authenticate(_EGLDisplay *disp, uint32_t id)
 
    s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
    authenticate_cookie =
-      xcb_dri2_authenticate_unchecked(dri2_dpy->conn, s.data->root, id);
+      xcb_dri2_authenticate_unchecked(dri2_dpy->conn,
+                           get_xcb_screen(s, dri2_dpy->screen)->root, id);
    authenticate =
       xcb_dri2_authenticate_reply(dri2_dpy->conn, authenticate_cookie, NULL);
 
@@ -630,7 +643,7 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
    };
 
    s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
-   d = xcb_screen_allowed_depths_iterator(s.data);
+   d = xcb_screen_allowed_depths_iterator(get_xcb_screen(s, dri2_dpy->screen));
    id = 1;
 
    surface_type =
@@ -1065,10 +1078,13 @@ dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp)
 
    disp->DriverData = (void *) dri2_dpy;
    if (disp->PlatformDisplay == NULL) {
-      dri2_dpy->conn = xcb_connect(0, 0);
+      dri2_dpy->conn = xcb_connect(0, &dri2_dpy->screen);
       dri2_dpy->own_device = true;
    } else {
-      dri2_dpy->conn = XGetXCBConnection((Display *) disp->PlatformDisplay);
+      Display *dpy = disp->PlatformDisplay;
+
+      dri2_dpy->conn = XGetXCBConnection(dpy);
+      dri2_dpy->screen = DefaultScreen(dpy);
    }
 
    if (xcb_connection_has_error(dri2_dpy->conn)) {
@@ -1185,10 +1201,13 @@ dri2_initialize_x11_dri2(_EGLDriver *drv, _EGLDisplay *disp)
 
    disp->DriverData = (void *) dri2_dpy;
    if (disp->PlatformDisplay == NULL) {
-      dri2_dpy->conn = xcb_connect(0, 0);
+      dri2_dpy->conn = xcb_connect(0, &dri2_dpy->screen);
       dri2_dpy->own_device = true;
    } else {
-      dri2_dpy->conn = XGetXCBConnection((Display *) disp->PlatformDisplay);
+      Display *dpy = disp->PlatformDisplay;
+
+      dri2_dpy->conn = XGetXCBConnection(dpy);
+      dri2_dpy->screen = DefaultScreen(dpy);
    }
 
    if (xcb_connection_has_error(dri2_dpy->conn)) {