[PATCH 2/2] xwayland: Decouple drm init from screen init.

Christopher James Halse Rogers christopher.halse.rogers at canonical.com
Wed May 23 05:05:54 PDT 2012


The nouveau driver wants access to its drm fd well before
xwl_screen_pre_init can be called. Allow this by decoupling
xwl_screen creation, xwl drm initialisation, and xwl_screen_pre_init.

Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
---
 hw/xfree86/xwayland/xwayland-drm.c     |    8 +++++++
 hw/xfree86/xwayland/xwayland-private.h |    2 +-
 hw/xfree86/xwayland/xwayland.c         |   39 ++++++++++++++++----------------
 hw/xfree86/xwayland/xwayland.h         |    8 ++++++-
 4 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/hw/xfree86/xwayland/xwayland-drm.c b/hw/xfree86/xwayland/xwayland-drm.c
index ec5d327..cf1124e 100644
--- a/hw/xfree86/xwayland/xwayland-drm.c
+++ b/hw/xfree86/xwayland/xwayland-drm.c
@@ -99,6 +99,9 @@ xwl_drm_pre_init(struct xwl_screen *xwl_screen)
 	wl_display_add_global_listener(xwl_screen->display,
 				       drm_handler, 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",
@@ -129,6 +132,11 @@ xwl_drm_pre_init(struct xwl_screen *xwl_screen)
     return Success;
 }
 
+Bool xwl_drm_initialised(struct xwl_screen *xwl_screen)
+{
+    return xwl_screen->authenticated;
+}
+
 int xwl_screen_get_drm_fd(struct xwl_screen *xwl_screen)
 {
     return xwl_screen->drm_fd;
diff --git a/hw/xfree86/xwayland/xwayland-private.h b/hw/xfree86/xwayland/xwayland-private.h
index bde56f2..f1fec23 100644
--- a/hw/xfree86/xwayland/xwayland-private.h
+++ b/hw/xfree86/xwayland/xwayland-private.h
@@ -122,6 +122,6 @@ int wayland_screen_pre_init(struct xwl_screen *screen, int use_drm);
 int wayland_screen_init(struct xwl_screen *screen);
 int wayland_screen_close(struct xwl_screen *screen);
 
-int xwl_drm_pre_init(struct xwl_screen *screen);
+Bool xwl_drm_initialised(struct xwl_screen *screen);
 
 #endif /* _XWAYLAND_PRIVATE_H_ */
diff --git a/hw/xfree86/xwayland/xwayland.c b/hw/xfree86/xwayland/xwayland.c
index d04c764..fea5210 100644
--- a/hw/xfree86/xwayland/xwayland.c
+++ b/hw/xfree86/xwayland/xwayland.c
@@ -208,13 +208,10 @@ xwayland_selection_callback(CallbackListPtr *callbacks,
     }
 }
 
-
 struct xwl_screen *
-xwl_screen_pre_init(ScrnInfoPtr scrninfo,
-		    uint32_t flags, struct xwl_driver *driver)
+xwl_screen_create(void)
 {
     struct xwl_screen *xwl_screen;
-    int ret;
 
     xwl_screen = calloc(sizeof *xwl_screen, 1);
     if (xwl_screen == NULL) {
@@ -222,14 +219,26 @@ xwl_screen_pre_init(ScrnInfoPtr scrninfo,
 	return NULL;
     }
 
+    xwl_screen->display = wl_display_connect(NULL);
+    if (xwl_screen->display == NULL) {
+	ErrorF("wl_display_create failed\n");
+	return NULL;
+    }
+
+    return xwl_screen;
+}
+
+Bool
+xwl_screen_pre_init(ScrnInfoPtr scrninfo, struct xwl_screen *xwl_screen,
+		    uint32_t flags, struct xwl_driver *driver)
+{
     noScreenSaverExtension = TRUE;
 
     xdnd_atom = MakeAtom("XdndSelection", 13, 1);
     ErrorF("xdnd_atom: %d\n", xdnd_atom);
     if (!AddCallback(&SelectionCallback,
 		     xwayland_selection_callback, xwl_screen)) {
-	free(xwl_screen);
-	return NULL;
+	return FALSE;
     }
 
     xorg_list_init(&xwl_screen->seat_list);
@@ -242,33 +251,25 @@ xwl_screen_pre_init(ScrnInfoPtr scrninfo,
     if (xorgRootless)
 	xwl_screen->flags |= XWL_FLAGS_ROOTLESS;
 
-    xwl_screen->display = wl_display_connect(NULL);
-    if (xwl_screen->display == NULL) {
-	ErrorF("wl_display_create failed\n");
-	return NULL;
-    }
-
     /* Set up listener so we'll catch all events. */
     xwl_screen->global_listener =
 	    wl_display_add_global_listener(xwl_screen->display,
 					   global_handler, xwl_screen);
 
-    /* Process connection events. */
-    wl_display_iterate(xwl_screen->display, WL_DISPLAY_READABLE);
+    wl_display_roundtrip(xwl_screen->display);
 
     xwl_screen->wayland_fd =
 	wl_display_get_fd(xwl_screen->display, source_update, xwl_screen);
 
 #ifdef WITH_LIBDRM
-    if (xwl_screen->driver->use_drm)
-	ret = xwl_drm_pre_init(xwl_screen);
-    if (xwl_screen->driver->use_drm && ret != Success)
-	return NULL;
+    if (xwl_screen->driver->use_drm && !xwl_drm_initialised(xwl_screen))
+	if (xwl_drm_pre_init(xwl_screen) != Success)
+            return FALSE;
 #endif
 
     xwayland_screen_preinit_output(xwl_screen, scrninfo);
 
-    return xwl_screen;
+    return TRUE;
 }
 
 int
diff --git a/hw/xfree86/xwayland/xwayland.h b/hw/xfree86/xwayland/xwayland.h
index 5eba934..e536c42 100644
--- a/hw/xfree86/xwayland/xwayland.h
+++ b/hw/xfree86/xwayland/xwayland.h
@@ -44,13 +44,19 @@ extern _X_EXPORT int
 xwl_version(void);
 
 extern _X_EXPORT struct xwl_screen *
-xwl_screen_pre_init(ScrnInfoPtr scrninfo,
+xwl_screen_create(void);
+
+extern _X_EXPORT Bool
+xwl_screen_pre_init(ScrnInfoPtr scrninfo, struct xwl_screen *xwl_screen,
 		    uint32_t flags, struct xwl_driver *driver);
 
 extern _X_EXPORT int
 xwl_screen_init(struct xwl_screen *xwl_screen, ScreenPtr screen);
 
 extern _X_EXPORT int
+xwl_drm_pre_init(struct xwl_screen *xwl_screen);
+
+extern _X_EXPORT int
 xwl_screen_get_drm_fd(struct xwl_screen *xwl_screen);
 
 extern _X_EXPORT void
-- 
1.7.10



More information about the wayland-devel mailing list