Implement current drm auth scheme in the drm object

This commit is contained in:
Kristian Høgsberg 2010-08-09 22:11:47 -04:00
parent 3862e43779
commit 640609acfc
5 changed files with 43 additions and 10 deletions

View File

@ -31,6 +31,7 @@
#include <cairo.h>
#include <glib.h>
#include <glib-object.h>
#include <xf86drm.h>
#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");

View File

@ -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;

View File

@ -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;

View File

@ -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);
};

View File

@ -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