Skip to content

Commit

Permalink
Pull in xcb dri2 so we can auth drm clients
Browse files Browse the repository at this point in the history
  • Loading branch information
krh committed Dec 8, 2010
1 parent 5e7ec9f commit 8668865
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ clayland_LDADD = \
$(CLAYLAND_LIBS)

clayland_SOURCES = \
clayland.h \
clayland.c \
wayland-source.c
wayland-source.c \
dri2.c

ACLOCAL_AMFLAGS = -I m4
13 changes: 5 additions & 8 deletions clayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <wayland-server.h>
#include <clutter/clutter.h>

#include <sys/time.h>
#include <math.h>
#include <errno.h>
#include <stdlib.h>
Expand Down Expand Up @@ -31,8 +32,6 @@ typedef struct ClaylandSurface {
static gboolean
event_cb (ClutterActor *stage, ClutterEvent *event, gpointer data)
{
ClaylandCompositor *compositor = data;

switch (event->type) {
case CLUTTER_NOTHING:
case CLUTTER_KEY_PRESS:
Expand Down Expand Up @@ -220,14 +219,10 @@ clayland_compositor_create(ClutterActor *stage)
int
main (int argc, char *argv[])
{
ClutterAlpha *alpha;
ClutterActor *stage;
ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff };
ClaylandCompositor *compositor;
struct wl_event_loop *loop;
gint i;
GError *error;
gchar *file;

error = NULL;

Expand All @@ -240,6 +235,10 @@ main (int argc, char *argv[])
return EXIT_FAILURE;
}

/* Can we figure out whether we're compiling against clutter
* x11 or not? */
dri2_connect();

stage = clutter_stage_get_default ();
clutter_actor_set_size (stage, 800, 600);
clutter_actor_set_name (stage, "Clayland");
Expand All @@ -254,8 +253,6 @@ main (int argc, char *argv[])
if (compositor->hand == NULL)
g_error ("image load failed: %s", error->message);

g_free (file);

compositor->stage_width = clutter_actor_get_width (stage);
compositor->stage_height = clutter_actor_get_height (stage);

Expand Down
3 changes: 3 additions & 0 deletions clayland.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@

GSource *wl_glib_source_new(struct wl_event_loop *loop);

int dri2_connect(void);
int dri2_authenticate(uint32_t magic);

#endif /* CLAYLAND_H */
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AM_SILENT_RULES([yes])

PKG_PROG_PKG_CONFIG()

PKG_CHECK_MODULES(CLAYLAND, [wayland-server clutter-1.0 libdrm >= 2.4.17])
PKG_CHECK_MODULES(CLAYLAND, [wayland-server clutter-1.0 libdrm >= 2.4.17 x11-xcb xcb-dri2])

if test $CC = gcc; then
GCC_CFLAGS="-Wall -g -Wstrict-prototypes -Wmissing-prototypes -fvisibility=hidden"
Expand Down
70 changes: 70 additions & 0 deletions dri2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <stdlib.h>
#include <xcb/xcb.h>
#include <xcb/dri2.h>
#include <clutter/x11/clutter-x11.h>
#include <X11/Xlib-xcb.h>

int
dri2_connect(void)
{
Display *dpy;
xcb_connection_t *conn;
xcb_dri2_query_version_reply_t *dri2_query;
xcb_dri2_query_version_cookie_t dri2_query_cookie;
xcb_generic_error_t *error;

dpy = clutter_x11_get_default_display ();
conn = XGetXCBConnection(dpy);

xcb_prefetch_extension_data (conn, &xcb_dri2_id);

dri2_query_cookie =
xcb_dri2_query_version (conn,
XCB_DRI2_MAJOR_VERSION,
XCB_DRI2_MINOR_VERSION);

dri2_query =
xcb_dri2_query_version_reply (conn,
dri2_query_cookie, &error);
if (dri2_query == NULL || error != NULL) {
fprintf(stderr, "DRI2: failed to query version\n");
free(error);
return -1;
}

fprintf(stderr, "DRI2: %d.%d\n",
dri2_query->major_version, dri2_query->minor_version);

free(dri2_query);

return 0;
}

int
dri2_authenticate(uint32_t magic)
{
Display *dpy;
xcb_connection_t *conn;
xcb_dri2_authenticate_reply_t *authenticate;
xcb_dri2_authenticate_cookie_t authenticate_cookie;
Window root;

dpy = clutter_x11_get_default_display ();
conn = XGetXCBConnection (dpy);
root = clutter_x11_get_root_window ();

authenticate_cookie =
xcb_dri2_authenticate_unchecked(conn, root, magic);
authenticate =
xcb_dri2_authenticate_reply(conn,
authenticate_cookie, NULL);
if (authenticate == NULL || !authenticate->authenticated) {
fprintf(stderr, "DRI2: failed to authenticate\n");
free(authenticate);
return -1;
}

free(authenticate);

return 0;
}

0 comments on commit 8668865

Please sign in to comment.