Mesa (master): wayland-egl: Force roundtrips to get device name and authenticate correctly

Kristian Høgsberg krh at kemper.freedesktop.org
Mon Feb 7 14:10:23 UTC 2011


Module: Mesa
Branch: master
Commit: 56758c839ff29bd168529535a4816bff3b79cde5
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=56758c839ff29bd168529535a4816bff3b79cde5

Author: Kristian Høgsberg <krh at bitplanet.net>
Date:   Fri Feb  4 15:37:51 2011 -0500

wayland-egl: Force roundtrips to get device name and authenticate correctly

If the client hasn't done the initial wl_display_iterate() at the time
we initialize the display, we have to do that in platform_wayland.c.
Make sure we detect that correctly instead of dup()ing fd=0, and use
the sync callback to make sure we don't wait forever for authorization that
won't happen.

---

 src/egl/drivers/dri2/platform_wayland.c |   32 +++++++++++++++++++++++++++---
 src/egl/wayland/wayland-egl.c           |    1 +
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index b223403..16e0888 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -504,6 +504,24 @@ dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp)
    return EGL_TRUE;
 }
 
+static void
+sync_callback(void *data)
+{
+   int *done = data;
+
+   *done = 1;
+}
+
+static void
+force_roundtrip(struct wl_display *display)
+{
+   int done = 0;
+
+   wl_display_sync_callback(display, sync_callback, &done);
+   wl_display_iterate(display, WL_DISPLAY_WRITABLE);
+   while (!done)
+      wl_display_iterate(display, WL_DISPLAY_READABLE);
+}
 
 EGLBoolean
 dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
@@ -525,15 +543,21 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
    disp->DriverData = (void *) dri2_dpy;
    dri2_dpy->wl_dpy = disp->PlatformDisplay;
 
+   if (dri2_dpy->wl_dpy->fd == -1)
+      force_roundtrip(dri2_dpy->wl_dpy->display);
+   if (dri2_dpy->wl_dpy->fd == -1)
+      goto cleanup_dpy;
+
    dri2_dpy->fd = dup(dri2_dpy->wl_dpy->fd);
    if (dri2_dpy->fd < 0) {
       _eglError(EGL_BAD_ALLOC, "DRI2: failed to dup fd");
       goto cleanup_dpy;
    }
-   
-   wl_display_iterate(dri2_dpy->wl_dpy->display, WL_DISPLAY_WRITABLE);
-   while (!dri2_dpy->wl_dpy->authenticated)
-      wl_display_iterate(dri2_dpy->wl_dpy->display, WL_DISPLAY_READABLE);
+
+   if (!dri2_dpy->wl_dpy->authenticated)
+      force_roundtrip(dri2_dpy->wl_dpy->display);
+   if (!dri2_dpy->wl_dpy->authenticated)
+      goto cleanup_dpy;
 
    dri2_dpy->driver_name = dri2_get_driver_for_fd(dri2_dpy->fd);
    if (dri2_dpy->driver_name == NULL) {
diff --git a/src/egl/wayland/wayland-egl.c b/src/egl/wayland/wayland-egl.c
index 6aa2d51..bb95fcb 100644
--- a/src/egl/wayland/wayland-egl.c
+++ b/src/egl/wayland/wayland-egl.c
@@ -102,6 +102,7 @@ wl_egl_display_create(struct wl_display *display)
 
 	egl_display->display = display;
 	egl_display->drm = NULL;
+	egl_display->fd = -1;
 	egl_display->device_name = NULL;
 	egl_display->authenticated = false;
 




More information about the mesa-commit mailing list