[PATCH 3/4 v2] Add function to get new fd of the graphic device

Axel Davy axel.davy at ens.fr
Thu Jan 16 13:29:37 PST 2014


neccessary for dri3

Signed-off-by: Axel Davy <axel.davy at ens.fr>
---
v2: fix indentation
 hw/xfree86/xwayland/xwayland-drm.c | 56 ++++++++++++++++++++++++--------------
 hw/xfree86/xwayland/xwayland.h     |  3 ++
 2 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/hw/xfree86/xwayland/xwayland-drm.c b/hw/xfree86/xwayland/xwayland-drm.c
index 076fb68..12011bf 100644
--- a/hw/xfree86/xwayland/xwayland-drm.c
+++ b/hw/xfree86/xwayland/xwayland-drm.c
@@ -157,49 +157,63 @@ is_fd_render_node(int fd)
 }
 
 int
-xwl_drm_pre_init(struct xwl_screen *xwl_screen)
+xwl_device_get_fd(struct xwl_screen *xwl_screen)
 {
     uint32_t magic;
+    int fd;
 
-    xwl_screen->drm_registry = wl_display_get_registry(xwl_screen->display);
-    wl_registry_add_listener(xwl_screen->drm_registry, &drm_listener,
-			     xwl_screen);
-
-    /* Ensure drm_handler has seen all the interfaces */
-    wl_display_roundtrip(xwl_screen->display);
-    /* Ensure the xwl_drm_listener has seen the drm device, if any */
-    wl_display_roundtrip(xwl_screen->display);
-
-    ErrorF("wayland_drm_screen_init, device name %s\n",
-	   xwl_screen->device_name);
-
-    xwl_screen->drm_fd = open(xwl_screen->device_name, O_RDWR);
-    if (xwl_screen->drm_fd < 0) {
+    fd = open(xwl_screen->device_name, O_RDWR);
+    if (fd < 0) {
 	ErrorF("failed to open the drm fd\n");
-	return BadAccess;
+	return -1;
     }
 
-    if (!is_fd_render_node(xwl_screen->drm_fd)) {
+    if (!is_fd_render_node(fd)) {
 
-	if (drmGetMagic(xwl_screen->drm_fd, &magic)) {
+	if (drmGetMagic(fd, &magic)) {
 	    ErrorF("failed to get drm magic");
-	    return BadAccess;
+	    close (fd);
+	    return -1;
 	}
 
 	wl_drm_authenticate(xwl_screen->drm, magic);
 
 	wl_display_roundtrip(xwl_screen->display);
 
-	ErrorF("opened drm fd: %d\n", xwl_screen->drm_fd);
+	ErrorF("opened drm fd: %d\n", fd);
 
 	if (!xwl_screen->authenticated) {
 	    ErrorF("Failed to auth drm fd\n");
-	    return BadAccess;
+	    close (fd);
+	    return -1;
 	}
     } else {
 	xwl_screen->authenticated = 1;
     }
 
+    return fd;
+}
+
+int
+xwl_drm_pre_init(struct xwl_screen *xwl_screen)
+{
+    xwl_screen->drm_registry = wl_display_get_registry(xwl_screen->display);
+    wl_registry_add_listener(xwl_screen->drm_registry, &drm_listener,
+                             xwl_screen);
+
+    /* Ensure drm_handler has seen all the interfaces */
+    wl_display_roundtrip(xwl_screen->display);
+    /* Ensure the xwl_drm_listener has seen the drm device, if any */
+    wl_display_roundtrip(xwl_screen->display);
+
+    ErrorF("wayland_drm_screen_init, device name %s\n",
+	   xwl_screen->device_name);
+
+    xwl_screen->drm_fd = xwl_device_get_fd(xwl_screen);
+    if (xwl_screen->drm_fd < 0) {
+	return BadAccess;
+    }
+
     return Success;
 }
 
diff --git a/hw/xfree86/xwayland/xwayland.h b/hw/xfree86/xwayland/xwayland.h
index 8e484a1..c380618 100644
--- a/hw/xfree86/xwayland/xwayland.h
+++ b/hw/xfree86/xwayland/xwayland.h
@@ -76,6 +76,9 @@ xwl_drm_authenticate(ClientPtr client, struct xwl_screen *xwl_screen,
 		     uint32_t magic);
 
 extern _X_EXPORT int
+xwl_device_get_fd(struct xwl_screen *xwl_screen);
+
+extern _X_EXPORT int
 xwl_create_window_buffer_drm(struct xwl_window *xwl_window,
 			     PixmapPtr pixmap, uint32_t name);
 
-- 
1.8.3.2



More information about the wayland-devel mailing list