blob: 76d95859b2cc6c46358c0e414de57ad8efb66ed0 [file] [log] [blame]
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001/*
2 * Copyright © 2008-2010 Kristian Høgsberg
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#include <stddef.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <fcntl.h>
24#include <unistd.h>
25#include <errno.h>
26#include <sys/time.h>
Kristian Høgsbergf9112b22010-06-14 12:53:43 -040027#include <linux/input.h>
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040028
29#include <xcb/xcb.h>
30#include <xcb/dri2.h>
31#include <xcb/xfixes.h>
32
33#define GL_GLEXT_PROTOTYPES
34#define EGL_EGLEXT_PROTOTYPES
35#include <GLES2/gl2.h>
36#include <GLES2/gl2ext.h>
37#include <EGL/egl.h>
38#include <EGL/eglext.h>
39
40#include "wayland.h"
41#include "wayland-protocol.h"
42#include "compositor.h"
43
44#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
45
46struct x11_compositor {
47 struct wlsc_compositor base;
48
49 xcb_connection_t *conn;
50 xcb_screen_t *screen;
51 xcb_cursor_t null_cursor;
52 int dri2_major;
53 int dri2_minor;
54 int drm_fd;
55 struct wl_event_source *xcb_source;
56 struct {
57 xcb_atom_t wm_protocols;
58 xcb_atom_t wm_normal_hints;
59 xcb_atom_t wm_size_hints;
60 xcb_atom_t wm_delete_window;
61 xcb_atom_t net_wm_name;
62 xcb_atom_t utf8_string;
63 } atom;
64};
65
66struct x11_output {
67 struct wlsc_output base;
68
69 xcb_xfixes_region_t region;
70 xcb_window_t window;
71 GLuint rbo;
72 EGLImageKHR image;
73 xcb_rectangle_t damage[16];
74 int damage_count;
75};
76
77struct x11_input {
78 struct wlsc_input_device base;
79};
80
81
82static void
83x11_input_create(struct x11_compositor *c)
84{
85 struct x11_input *input;
86
87 input = malloc(sizeof *input);
88 if (input == NULL)
89 return;
90
91 memset(input, 0, sizeof *input);
92 wlsc_input_device_init(&input->base, &c->base);
93
94 c->base.input_device = &input->base;
95}
96
97
98static int
99dri2_connect(struct x11_compositor *c)
100{
101 xcb_xfixes_query_version_reply_t *xfixes_query;
102 xcb_xfixes_query_version_cookie_t xfixes_query_cookie;
103 xcb_dri2_query_version_reply_t *dri2_query;
104 xcb_dri2_query_version_cookie_t dri2_query_cookie;
105 xcb_dri2_connect_reply_t *connect;
106 xcb_dri2_connect_cookie_t connect_cookie;
107 xcb_generic_error_t *error;
108
109 xcb_prefetch_extension_data (c->conn, &xcb_xfixes_id);
110 xcb_prefetch_extension_data (c->conn, &xcb_dri2_id);
111
112 xfixes_query_cookie =
113 xcb_xfixes_query_version(c->conn,
114 XCB_XFIXES_MAJOR_VERSION,
115 XCB_XFIXES_MINOR_VERSION);
116
117 dri2_query_cookie =
118 xcb_dri2_query_version (c->conn,
119 XCB_DRI2_MAJOR_VERSION,
120 XCB_DRI2_MINOR_VERSION);
121
122 connect_cookie = xcb_dri2_connect_unchecked (c->conn,
123 c->screen->root,
124 XCB_DRI2_DRIVER_TYPE_DRI);
125
126 xfixes_query =
127 xcb_xfixes_query_version_reply (c->conn,
128 xfixes_query_cookie, &error);
129 if (xfixes_query == NULL ||
130 error != NULL || xfixes_query->major_version < 2) {
131 free(error);
132 return -1;
133 }
134 free(xfixes_query);
135
136 dri2_query =
137 xcb_dri2_query_version_reply (c->conn,
138 dri2_query_cookie, &error);
139 if (dri2_query == NULL || error != NULL) {
140 fprintf(stderr, "DRI2: failed to query version");
141 free(error);
142 return EGL_FALSE;
143 }
144 c->dri2_major = dri2_query->major_version;
145 c->dri2_minor = dri2_query->minor_version;
146 free(dri2_query);
147
148 connect = xcb_dri2_connect_reply (c->conn,
149 connect_cookie, NULL);
150 if (connect == NULL ||
151 connect->driver_name_length + connect->device_name_length == 0) {
152 fprintf(stderr, "DRI2: failed to authenticate");
153 return -1;
154 }
155
156 c->base.base.device =
157 strndup(xcb_dri2_connect_device_name (connect),
158 xcb_dri2_connect_device_name_length (connect));
159
160 if (c->base.base.device == NULL) {
161 free(connect);
162 return -1;
163 }
164 free(connect);
165
166 return 0;
167}
168
169static int
170dri2_authenticate(struct x11_compositor *c)
171{
172 xcb_dri2_authenticate_reply_t *authenticate;
173 xcb_dri2_authenticate_cookie_t authenticate_cookie;
174 drm_magic_t magic;
175
176 if (drmGetMagic(c->drm_fd, &magic)) {
177 fprintf(stderr, "DRI2: failed to get drm magic");
178 return -1;
179 }
180
181 authenticate_cookie =
182 xcb_dri2_authenticate_unchecked(c->conn,
183 c->screen->root, magic);
184 authenticate =
185 xcb_dri2_authenticate_reply(c->conn,
186 authenticate_cookie, NULL);
187 if (authenticate == NULL || !authenticate->authenticated) {
188 fprintf(stderr, "DRI2: failed to authenticate");
189 free(authenticate);
190 return -1;
191 }
192
193 free(authenticate);
194
195 return 0;
196}
197
198static int
199x11_compositor_init_egl(struct x11_compositor *c)
200{
Kristian Høgsberg379b6782010-07-28 22:52:28 -0400201 EGLint major, minor;
202 const char *extensions;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400203
204 if (dri2_connect(c) < 0)
205 return -1;
Kristian Høgsbergf252d6a2010-07-08 20:15:10 -0400206
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400207 c->drm_fd = open(c->base.base.device, O_RDWR);
208 if (c->drm_fd == -1) {
209 fprintf(stderr,
210 "DRI2: could not open %s (%s)", c->base.base.device,
211 strerror(errno));
212 return -1;
213 }
214
215 if (dri2_authenticate(c) < 0)
216 return -1;
217
Kristian Høgsbergf252d6a2010-07-08 20:15:10 -0400218 c->base.display = eglGetDRMDisplayMESA(c->drm_fd);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400219 if (c->base.display == NULL) {
220 fprintf(stderr, "failed to create display\n");
221 return -1;
222 }
223
224 if (!eglInitialize(c->base.display, &major, &minor)) {
225 fprintf(stderr, "failed to initialize display\n");
226 return -1;
227 }
228
Kristian Høgsberg379b6782010-07-28 22:52:28 -0400229 extensions = eglQueryString(c->base.display, EGL_EXTENSIONS);
230 if (!strstr(extensions, "EGL_KHR_surfaceless_opengl")) {
231 fprintf(stderr, "EGL_KHR_surfaceless_opengl not available\n");
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400232 return -1;
233 }
234
235 eglBindAPI(EGL_OPENGL_API);
236 c->base.context = eglCreateContext(c->base.display,
Kristian Høgsberg379b6782010-07-28 22:52:28 -0400237 NULL, EGL_NO_CONTEXT, NULL);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400238 if (c->base.context == NULL) {
239 fprintf(stderr, "failed to create context\n");
240 return -1;
241 }
242
243 if (!eglMakeCurrent(c->base.display, EGL_NO_SURFACE,
244 EGL_NO_SURFACE, c->base.context)) {
245 fprintf(stderr, "failed to make context current\n");
246 return -1;
247 }
248
249 return 0;
250}
251
252static void
253x11_compositor_present(struct wlsc_compositor *base)
254{
255 struct x11_compositor *c = (struct x11_compositor *) base;
256 struct x11_output *output;
257 xcb_dri2_copy_region_cookie_t cookie;
258 struct timeval tv;
259 uint32_t msec;
260
261 glFlush();
262
263 wl_list_for_each(output, &c->base.output_list, base.link) {
264 cookie = xcb_dri2_copy_region_unchecked(c->conn,
265 output->window,
266 output->region,
267 XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT,
268 XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT);
269 free(xcb_dri2_copy_region_reply(c->conn, cookie, NULL));
270 }
271
272 gettimeofday(&tv, NULL);
273 msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
274 wlsc_compositor_finish_frame(&c->base, msec);
275}
276
277static void
278x11_output_set_wm_protocols(struct x11_output *output)
279{
280 xcb_atom_t list[1];
281 struct x11_compositor *c =
282 (struct x11_compositor *) output->base.compositor;
283
284 list[0] = c->atom.wm_delete_window;
285 xcb_change_property (c->conn,
286 XCB_PROP_MODE_REPLACE,
287 output->window,
288 c->atom.wm_protocols,
289 XCB_ATOM_ATOM,
290 32,
291 ARRAY_SIZE(list),
292 list);
293}
294
295struct wm_normal_hints {
296 uint32_t flags;
297 uint32_t pad[4];
298 int32_t min_width, min_height;
299 int32_t max_width, max_height;
300 int32_t width_inc, height_inc;
301 int32_t min_aspect_x, min_aspect_y;
302 int32_t max_aspect_x, max_aspect_y;
303 int32_t base_width, base_height;
304 int32_t win_gravity;
305};
306
307#define WM_NORMAL_HINTS_MIN_SIZE 16
308#define WM_NORMAL_HINTS_MAX_SIZE 32
309
310static int
311x11_compositor_create_output(struct x11_compositor *c, int width, int height)
312{
313 static const char name[] = "Wayland Compositor";
314 struct x11_output *output;
315 xcb_dri2_dri2_buffer_t *buffers;
316 xcb_dri2_get_buffers_reply_t *reply;
317 xcb_dri2_get_buffers_cookie_t cookie;
318 xcb_screen_iterator_t iter;
319 xcb_rectangle_t rectangle;
320 struct wm_normal_hints normal_hints;
321 unsigned int attachments[] =
322 { XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT};
323 uint32_t mask = XCB_CW_EVENT_MASK | XCB_CW_CURSOR;
324 uint32_t values[2] = {
325 XCB_EVENT_MASK_KEY_PRESS |
326 XCB_EVENT_MASK_KEY_RELEASE |
327 XCB_EVENT_MASK_BUTTON_PRESS |
328 XCB_EVENT_MASK_BUTTON_RELEASE |
329 XCB_EVENT_MASK_POINTER_MOTION |
330 XCB_EVENT_MASK_EXPOSURE |
Kristian Høgsberg86e09892010-07-07 09:51:11 -0400331 XCB_EVENT_MASK_STRUCTURE_NOTIFY |
332 XCB_EVENT_MASK_ENTER_WINDOW |
333 XCB_EVENT_MASK_LEAVE_WINDOW,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400334 0
335 };
336
337 EGLint attribs[] = {
338 EGL_WIDTH, 0,
339 EGL_HEIGHT, 0,
340 EGL_IMAGE_STRIDE_MESA, 0,
341 EGL_IMAGE_FORMAT_MESA, EGL_IMAGE_FORMAT_ARGB8888_MESA,
342 EGL_NONE
343 };
344
345 output = malloc(sizeof *output);
346 if (output == NULL)
347 return -1;
348
349 memset(output, 0, sizeof *output);
350 wlsc_output_init(&output->base, &c->base, 0, 0, width, height);
351
352 values[1] = c->null_cursor;
353 output->window = xcb_generate_id(c->conn);
354 iter = xcb_setup_roots_iterator(xcb_get_setup(c->conn));
355 xcb_create_window(c->conn,
356 XCB_COPY_FROM_PARENT,
357 output->window,
358 iter.data->root,
359 0, 0,
360 width, height,
361 0,
362 XCB_WINDOW_CLASS_INPUT_OUTPUT,
363 iter.data->root_visual,
364 mask, values);
365
366 /* Don't resize me. */
367 memset(&normal_hints, 0, sizeof normal_hints);
368 normal_hints.flags =
369 WM_NORMAL_HINTS_MAX_SIZE | WM_NORMAL_HINTS_MIN_SIZE;
370 normal_hints.min_width = width;
371 normal_hints.min_height = height;
372 normal_hints.max_width = width;
373 normal_hints.max_height = height;
374 xcb_change_property (c->conn, XCB_PROP_MODE_REPLACE, output->window,
375 c->atom.wm_normal_hints,
376 c->atom.wm_size_hints, 32,
377 sizeof normal_hints / 4,
378 (uint8_t *) &normal_hints);
379
380 xcb_map_window(c->conn, output->window);
381
382 /* Set window name. Don't bother with non-EWMH WMs. */
383 xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window,
384 c->atom.net_wm_name, c->atom.utf8_string, 8,
385 strlen(name), name);
386
387 rectangle.x = 0;
388 rectangle.y = 0;
389 rectangle.width = width;
390 rectangle.height = height;
391 output->region = xcb_generate_id(c->conn);
392 xcb_xfixes_create_region(c->conn, output->region, 1, &rectangle);
393
394 xcb_dri2_create_drawable (c->conn, output->window);
395
396 x11_output_set_wm_protocols(output);
397
398 cookie = xcb_dri2_get_buffers_unchecked (c->conn,
399 output->window,
400 1, 1, attachments);
401 reply = xcb_dri2_get_buffers_reply (c->conn, cookie, NULL);
402 if (reply == NULL)
403 return -1;
404 buffers = xcb_dri2_get_buffers_buffers (reply);
405 if (buffers == NULL)
406 return -1;
407
408 if (reply->count != 1) {
409 fprintf(stderr,
410 "got wrong number of buffers (%d)\n", reply->count);
411 return -1;
412 }
413
414 attribs[1] = reply->width;
415 attribs[3] = reply->height;
416 attribs[5] = buffers[0].pitch / 4;
417 free(reply);
418
419 output->image =
420 eglCreateImageKHR(c->base.display, c->base.context,
421 EGL_DRM_IMAGE_MESA,
422 (EGLClientBuffer) buffers[0].name,
423 attribs);
424
425 glGenRenderbuffers(1, &output->rbo);
426 glBindRenderbuffer(GL_RENDERBUFFER, output->rbo);
427
428 glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER,
429 output->image);
430
431 glFramebufferRenderbuffer(GL_FRAMEBUFFER,
432 GL_COLOR_ATTACHMENT0,
433 GL_RENDERBUFFER,
434 output->rbo);
435
436 wl_list_insert(c->base.output_list.prev, &output->base.link);
437
438 return 0;
439}
440
441static void
442idle_repaint(void *data)
443{
444 struct x11_output *output = data;
445 struct x11_compositor *c =
446 (struct x11_compositor *) output->base.compositor;
447 xcb_xfixes_region_t region;
448 xcb_dri2_copy_region_cookie_t cookie;
449
450 if (output->damage_count <= ARRAY_SIZE(output->damage)) {
451 region = xcb_generate_id(c->conn);
452 xcb_xfixes_create_region(c->conn, region,
453 output->damage_count, output->damage);
454 } else {
455 region = output->region;
456 }
457
458 cookie = xcb_dri2_copy_region_unchecked(c->conn,
459 output->window,
460 region,
461 XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT,
462 XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT);
463
464 if (region != output->region)
465 xcb_xfixes_destroy_region(c->conn, region);
466
467 free(xcb_dri2_copy_region_reply(c->conn, cookie, NULL));
468 output->damage_count = 0;
469}
470
471static struct x11_output *
472x11_compositor_find_output(struct x11_compositor *c, xcb_window_t window)
473{
474 struct x11_output *output;
475
476 wl_list_for_each(output, &c->base.output_list, base.link) {
477 if (output->window == window)
478 return output;
479 }
480
481 return NULL;
482}
483
484static void
485x11_compositor_handle_event(int fd, uint32_t mask, void *data)
486{
487 struct x11_compositor *c = data;
488 struct x11_output *output;
489 xcb_generic_event_t *event;
490 struct wl_event_loop *loop;
491 xcb_client_message_event_t *client_message;
492 xcb_motion_notify_event_t *motion_notify;
493 xcb_key_press_event_t *key_press;
494 xcb_button_press_event_t *button_press;
495 xcb_expose_event_t *expose;
496 xcb_rectangle_t *r;
497 xcb_atom_t atom;
498
499 loop = wl_display_get_event_loop(c->base.wl_display);
500 while (event = xcb_poll_for_event (c->conn), event != NULL) {
501 switch (event->response_type & ~0x80) {
502
503 case XCB_KEY_PRESS:
504 key_press = (xcb_key_press_event_t *) event;
505 notify_key(c->base.input_device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400506 key_press->time, key_press->detail - 8, 1);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400507 break;
508 case XCB_KEY_RELEASE:
509 key_press = (xcb_key_press_event_t *) event;
510 notify_key(c->base.input_device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400511 key_press->time, key_press->detail - 8, 0);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400512 break;
513 case XCB_BUTTON_PRESS:
514 button_press = (xcb_button_press_event_t *) event;
515 notify_button(c->base.input_device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400516 button_press->time,
Kristian Høgsbergf9112b22010-06-14 12:53:43 -0400517 button_press->detail + BTN_LEFT - 1, 1);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400518 break;
519 case XCB_BUTTON_RELEASE:
520 button_press = (xcb_button_press_event_t *) event;
521 notify_button(c->base.input_device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400522 button_press->time,
Kristian Høgsbergf9112b22010-06-14 12:53:43 -0400523 button_press->detail + BTN_LEFT - 1, 0);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400524 break;
525
526 case XCB_MOTION_NOTIFY:
527 motion_notify = (xcb_motion_notify_event_t *) event;
528 notify_motion(c->base.input_device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400529 motion_notify->time,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400530 motion_notify->event_x,
531 motion_notify->event_y);
532 break;
533
534 case XCB_EXPOSE:
535 expose = (xcb_expose_event_t *) event;
536 output = x11_compositor_find_output(c, expose->window);
537 if (output->damage_count == 0)
538 wl_event_loop_add_idle(loop,
539 idle_repaint, output);
540
541 r = &output->damage[output->damage_count++];
542 if (output->damage_count > 16)
543 break;
544 r->x = expose->x;
545 r->y = expose->y;
546 r->width = expose->width;
547 r->height = expose->height;
548 break;
Kristian Høgsberg86e09892010-07-07 09:51:11 -0400549
550 case XCB_ENTER_NOTIFY:
551 c->base.focus = 1;
552 wlsc_compositor_schedule_repaint(&c->base);
553 break;
554
555 case XCB_LEAVE_NOTIFY:
556 c->base.focus = 0;
557 wlsc_compositor_schedule_repaint(&c->base);
558 break;
559
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400560 case XCB_CLIENT_MESSAGE:
561 client_message = (xcb_client_message_event_t *) event;
562 atom = client_message->data.data32[0];
563 if (atom == c->atom.wm_delete_window)
564 exit(1);
565 break;
566 default:
567
568 break;
569 }
570
571 free (event);
572 }
573}
574
575#define F(field) offsetof(struct x11_compositor, field)
576
577static void
578x11_compositor_get_resources(struct x11_compositor *c)
579{
580 static const struct { const char *name; int offset; } atoms[] = {
581 { "WM_PROTOCOLS", F(atom.wm_protocols) },
582 { "WM_NORMAL_HINTS", F(atom.wm_normal_hints) },
583 { "WM_SIZE_HINTS", F(atom.wm_size_hints) },
584 { "WM_DELETE_WINDOW", F(atom.wm_delete_window) },
585 { "_NET_WM_NAME", F(atom.net_wm_name) },
586 { "UTF8_STRING", F(atom.utf8_string) },
587 };
588
589 xcb_intern_atom_cookie_t cookies[ARRAY_SIZE(atoms)];
590 xcb_intern_atom_reply_t *reply;
591 xcb_pixmap_t pixmap;
592 xcb_gc_t gc;
593 int i;
594 uint8_t data[] = { 0, 0, 0, 0 };
595
596 for (i = 0; i < ARRAY_SIZE(atoms); i++)
597 cookies[i] = xcb_intern_atom (c->conn, 0,
598 strlen(atoms[i].name),
599 atoms[i].name);
600
601 for (i = 0; i < ARRAY_SIZE(atoms); i++) {
602 reply = xcb_intern_atom_reply (c->conn, cookies[i], NULL);
603 *(xcb_atom_t *) ((char *) c + atoms[i].offset) = reply->atom;
604 free(reply);
605 }
606
607 pixmap = xcb_generate_id(c->conn);
608 gc = xcb_generate_id(c->conn);
609 xcb_create_pixmap(c->conn, 1, pixmap, c->screen->root, 1, 1);
610 xcb_create_gc(c->conn, gc, pixmap, 0, NULL);
611 xcb_put_image(c->conn, XCB_IMAGE_FORMAT_XY_PIXMAP,
612 pixmap, gc, 1, 1, 0, 0, 0, 32, sizeof data, data);
613 c->null_cursor = xcb_generate_id(c->conn);
614 xcb_create_cursor (c->conn, c->null_cursor,
615 pixmap, pixmap, 0, 0, 0, 0, 0, 0, 1, 1);
616 xcb_free_gc(c->conn, gc);
617 xcb_free_pixmap(c->conn, pixmap);
618}
619
620struct wlsc_compositor *
621x11_compositor_create(struct wl_display *display)
622{
623 struct x11_compositor *c;
624 struct wl_event_loop *loop;
625 xcb_screen_iterator_t s;
626
627 c = malloc(sizeof *c);
628 if (c == NULL)
629 return NULL;
630
631 memset(c, 0, sizeof *c);
632 c->conn = xcb_connect(0, 0);
633
634 if (xcb_connection_has_error(c->conn))
635 return NULL;
636
637 s = xcb_setup_roots_iterator(xcb_get_setup(c->conn));
638 c->screen = s.data;
639
640 x11_compositor_get_resources(c);
641
642 x11_compositor_init_egl(c);
643
644 /* Can't init base class until we have a current egl context */
Kristian Høgsberga9468212010-06-14 21:03:11 -0400645 if (wlsc_compositor_init(&c->base, display) < 0)
646 return NULL;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400647
648 x11_compositor_create_output(c, 1024, 640);
649
650 x11_input_create(c);
651
652 loop = wl_display_get_event_loop(c->base.wl_display);
653
654 c->xcb_source =
655 wl_event_loop_add_fd(loop, xcb_get_file_descriptor(c->conn),
656 WL_EVENT_READABLE,
657 x11_compositor_handle_event, c);
658
659 c->base.present = x11_compositor_present;
660
661 return &c->base;
662}