diff --git a/clients/window.c b/clients/window.c index 864a5e40..c41d2f59 100644 --- a/clients/window.c +++ b/clients/window.c @@ -31,6 +31,7 @@ #include #include #include +#include #define EGL_EGLEXT_PROTOTYPES 1 #define GL_GLEXT_PROTOTYPES 1 @@ -56,6 +57,7 @@ struct display { struct wl_drm *drm; struct wl_output *output; struct rectangle screen_allocation; + int authenticated; EGLDisplay dpy; EGLContext ctx; cairo_device_t *device; @@ -694,6 +696,9 @@ drm_handle_device(void *data, struct wl_drm *drm, const char *device) static void drm_handle_authenticated(void *data, struct wl_drm *drm) { + struct display *d = data; + + d->authenticated = 1; } static const struct wl_drm_listener drm_listener = { @@ -865,6 +870,7 @@ display_create(int *argc, char **argv[], const GOptionEntry *option_entries) int fd; GOptionContext *context; GError *error; + drm_magic_t magic; g_type_init(); @@ -902,6 +908,17 @@ display_create(int *argc, char **argv[], const GOptionEntry *option_entries) return NULL; } + if (drmGetMagic(fd, &magic)) { + fprintf(stderr, "DRI2: failed to get drm magic"); + return NULL; + } + + /* Wait for authenticated event */ + wl_drm_authenticate(d->drm, magic); + wl_display_iterate(d->display, WL_DISPLAY_WRITABLE); + while (!d->authenticated) + wl_display_iterate(d->display, WL_DISPLAY_READABLE); + d->dpy = eglGetDRMDisplayMESA(fd); if (!eglInitialize(d->dpy, &major, &minor)) { fprintf(stderr, "failed to initialize display\n"); diff --git a/compositor-drm.c b/compositor-drm.c index 6d156bbc..0daf6777 100644 --- a/compositor-drm.c +++ b/compositor-drm.c @@ -608,6 +608,14 @@ static int setup_tty(struct drm_compositor *ec, struct wl_event_loop *loop) return 0; } +static int +drm_authenticate(struct wlsc_compositor *c, uint32_t id) +{ + struct drm_compositor *ec = (struct drm_compositor *) c; + + return drmAuthMagic(ec->base.drm.fd, id); +} + struct wlsc_compositor * drm_compositor_create(struct wl_display *display) { @@ -668,6 +676,7 @@ drm_compositor_create(struct wl_display *display) wl_event_loop_add_fd(loop, ec->base.drm.fd, WL_EVENT_READABLE, on_drm_input, ec); setup_tty(ec, loop); + ec->base.authenticate = drm_authenticate; ec->base.present = drm_compositor_present; ec->base.focus = 1; diff --git a/compositor-x11.c b/compositor-x11.c index 27bf3280..37bed38b 100644 --- a/compositor-x11.c +++ b/compositor-x11.c @@ -169,16 +169,10 @@ dri2_connect(struct x11_compositor *c) } static int -dri2_authenticate(struct x11_compositor *c) +dri2_authenticate(struct x11_compositor *c, uint32_t magic) { xcb_dri2_authenticate_reply_t *authenticate; xcb_dri2_authenticate_cookie_t authenticate_cookie; - drm_magic_t magic; - - if (drmGetMagic(c->base.drm.fd, &magic)) { - fprintf(stderr, "DRI2: failed to get drm magic"); - return -1; - } authenticate_cookie = xcb_dri2_authenticate_unchecked(c->conn, @@ -202,6 +196,7 @@ x11_compositor_init_egl(struct x11_compositor *c) { EGLint major, minor; const char *extensions; + drm_magic_t magic; static const EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE @@ -210,7 +205,12 @@ x11_compositor_init_egl(struct x11_compositor *c) if (dri2_connect(c) < 0) return -1; - if (dri2_authenticate(c) < 0) + if (drmGetMagic(c->base.drm.fd, &magic)) { + fprintf(stderr, "DRI2: failed to get drm magic"); + return -1; + } + + if (dri2_authenticate(c, magic) < 0) return -1; c->base.display = eglGetDRMDisplayMESA(c->base.drm.fd); @@ -614,6 +614,12 @@ x11_compositor_get_resources(struct x11_compositor *c) xcb_free_pixmap(c->conn, pixmap); } +static int +x11_authenticate(struct wlsc_compositor *c, uint32_t id) +{ + return dri2_authenticate((struct x11_compositor *) c, id); +} + struct wlsc_compositor * x11_compositor_create(struct wl_display *display) { @@ -654,6 +660,7 @@ x11_compositor_create(struct wl_display *display) WL_EVENT_READABLE, x11_compositor_handle_event, c); + c->base.authenticate = x11_authenticate; c->base.present = x11_compositor_present; return &c->base; diff --git a/compositor.h b/compositor.h index fe9779ef..3dfafe52 100644 --- a/compositor.h +++ b/compositor.h @@ -141,7 +141,7 @@ struct wlsc_compositor { uint32_t focus; - void (*authenticate)(struct wlsc_compositor *c, uint32_t id); + int (*authenticate)(struct wlsc_compositor *c, uint32_t id); void (*present)(struct wlsc_compositor *c); }; diff --git a/configure.ac b/configure.ac index e544698d..1ffe3e91 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ PKG_CHECK_MODULES(FFI, [libffi]) PKG_CHECK_MODULES(COMPOSITOR, [egl gl libpng cairo gdk-pixbuf-2.0 libudev >= 136 libdrm >= 2.4.17] xcb-dri2 xcb-xfixes) -PKG_CHECK_MODULES(CLIENT, [egl gl cairo-gl gdk-pixbuf-2.0 glib-2.0 gobject-2.0 xkbcommon]) +PKG_CHECK_MODULES(CLIENT, [egl gl cairo-gl gdk-pixbuf-2.0 glib-2.0 gobject-2.0 xkbcommon libdrm]) PKG_CHECK_MODULES(POPPLER, [poppler-glib gdk-2.0]) if test $CC = gcc; then