Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
Chia-I Wu | 1b6c0ed | 2010-10-29 15:20:18 +0800 | [diff] [blame] | 19 | #ifdef HAVE_CONFIG_H |
| 20 | #include <config.h> |
| 21 | #endif |
| 22 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 23 | #include <stddef.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | #include <fcntl.h> |
| 28 | #include <unistd.h> |
| 29 | #include <errno.h> |
| 30 | #include <sys/time.h> |
Kristian Høgsberg | f9112b2 | 2010-06-14 12:53:43 -0400 | [diff] [blame] | 31 | #include <linux/input.h> |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 32 | |
| 33 | #include <xcb/xcb.h> |
| 34 | #include <xcb/dri2.h> |
| 35 | #include <xcb/xfixes.h> |
| 36 | |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame^] | 37 | #include <X11/Xlib.h> |
| 38 | #include <X11/Xlib-xcb.h> |
| 39 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 40 | #define GL_GLEXT_PROTOTYPES |
| 41 | #define EGL_EGLEXT_PROTOTYPES |
| 42 | #include <GLES2/gl2.h> |
| 43 | #include <GLES2/gl2ext.h> |
| 44 | #include <EGL/egl.h> |
| 45 | #include <EGL/eglext.h> |
| 46 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 47 | #include "compositor.h" |
| 48 | |
| 49 | #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) |
| 50 | |
| 51 | struct x11_compositor { |
| 52 | struct wlsc_compositor base; |
| 53 | |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame^] | 54 | Display *dpy; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 55 | xcb_connection_t *conn; |
| 56 | xcb_screen_t *screen; |
| 57 | xcb_cursor_t null_cursor; |
| 58 | int dri2_major; |
| 59 | int dri2_minor; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 60 | struct wl_array keys; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 61 | struct wl_event_source *xcb_source; |
| 62 | struct { |
| 63 | xcb_atom_t wm_protocols; |
| 64 | xcb_atom_t wm_normal_hints; |
| 65 | xcb_atom_t wm_size_hints; |
| 66 | xcb_atom_t wm_delete_window; |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 67 | xcb_atom_t wm_class; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 68 | xcb_atom_t net_wm_name; |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 69 | xcb_atom_t net_wm_icon; |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 70 | xcb_atom_t string; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 71 | xcb_atom_t utf8_string; |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 72 | xcb_atom_t cardinal; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 73 | } atom; |
| 74 | }; |
| 75 | |
| 76 | struct x11_output { |
| 77 | struct wlsc_output base; |
| 78 | |
| 79 | xcb_xfixes_region_t region; |
| 80 | xcb_window_t window; |
| 81 | GLuint rbo; |
| 82 | EGLImageKHR image; |
| 83 | xcb_rectangle_t damage[16]; |
| 84 | int damage_count; |
| 85 | }; |
| 86 | |
| 87 | struct x11_input { |
| 88 | struct wlsc_input_device base; |
| 89 | }; |
| 90 | |
| 91 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 92 | static int |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 93 | x11_input_create(struct x11_compositor *c) |
| 94 | { |
| 95 | struct x11_input *input; |
| 96 | |
| 97 | input = malloc(sizeof *input); |
| 98 | if (input == NULL) |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 99 | return -1; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 100 | |
| 101 | memset(input, 0, sizeof *input); |
| 102 | wlsc_input_device_init(&input->base, &c->base); |
| 103 | |
Kristian Høgsberg | 9c3e8d7 | 2010-12-08 09:48:52 -0500 | [diff] [blame] | 104 | c->base.input_device = &input->base.input_device; |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 105 | |
| 106 | return 0; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | |
| 110 | static int |
| 111 | dri2_connect(struct x11_compositor *c) |
| 112 | { |
| 113 | xcb_xfixes_query_version_reply_t *xfixes_query; |
| 114 | xcb_xfixes_query_version_cookie_t xfixes_query_cookie; |
| 115 | xcb_dri2_query_version_reply_t *dri2_query; |
| 116 | xcb_dri2_query_version_cookie_t dri2_query_cookie; |
| 117 | xcb_dri2_connect_reply_t *connect; |
| 118 | xcb_dri2_connect_cookie_t connect_cookie; |
| 119 | xcb_generic_error_t *error; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 120 | char path[256]; |
| 121 | int fd; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 122 | |
| 123 | xcb_prefetch_extension_data (c->conn, &xcb_xfixes_id); |
| 124 | xcb_prefetch_extension_data (c->conn, &xcb_dri2_id); |
| 125 | |
| 126 | xfixes_query_cookie = |
| 127 | xcb_xfixes_query_version(c->conn, |
| 128 | XCB_XFIXES_MAJOR_VERSION, |
| 129 | XCB_XFIXES_MINOR_VERSION); |
| 130 | |
| 131 | dri2_query_cookie = |
| 132 | xcb_dri2_query_version (c->conn, |
| 133 | XCB_DRI2_MAJOR_VERSION, |
| 134 | XCB_DRI2_MINOR_VERSION); |
| 135 | |
| 136 | connect_cookie = xcb_dri2_connect_unchecked (c->conn, |
| 137 | c->screen->root, |
| 138 | XCB_DRI2_DRIVER_TYPE_DRI); |
| 139 | |
| 140 | xfixes_query = |
| 141 | xcb_xfixes_query_version_reply (c->conn, |
| 142 | xfixes_query_cookie, &error); |
| 143 | if (xfixes_query == NULL || |
| 144 | error != NULL || xfixes_query->major_version < 2) { |
| 145 | free(error); |
| 146 | return -1; |
| 147 | } |
| 148 | free(xfixes_query); |
| 149 | |
| 150 | dri2_query = |
| 151 | xcb_dri2_query_version_reply (c->conn, |
| 152 | dri2_query_cookie, &error); |
| 153 | if (dri2_query == NULL || error != NULL) { |
Yuval Fledel | 91b5999 | 2010-11-22 21:42:58 +0200 | [diff] [blame] | 154 | fprintf(stderr, "DRI2: failed to query version\n"); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 155 | free(error); |
| 156 | return EGL_FALSE; |
| 157 | } |
| 158 | c->dri2_major = dri2_query->major_version; |
| 159 | c->dri2_minor = dri2_query->minor_version; |
| 160 | free(dri2_query); |
| 161 | |
| 162 | connect = xcb_dri2_connect_reply (c->conn, |
| 163 | connect_cookie, NULL); |
| 164 | if (connect == NULL || |
| 165 | connect->driver_name_length + connect->device_name_length == 0) { |
Yuval Fledel | 91b5999 | 2010-11-22 21:42:58 +0200 | [diff] [blame] | 166 | fprintf(stderr, "DRI2: failed to connect, DRI2 version: %u.%u\n", |
| 167 | c->dri2_major, c->dri2_minor); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 168 | return -1; |
| 169 | } |
| 170 | |
Chia-I Wu | 1b6c0ed | 2010-10-29 15:20:18 +0800 | [diff] [blame] | 171 | #ifdef XCB_DRI2_CONNECT_DEVICE_NAME_BROKEN |
| 172 | { |
| 173 | char *driver_name, *device_name; |
| 174 | |
| 175 | driver_name = xcb_dri2_connect_driver_name (connect); |
| 176 | device_name = driver_name + |
| 177 | ((connect->driver_name_length + 3) & ~3); |
| 178 | snprintf(path, sizeof path, "%.*s", |
| 179 | xcb_dri2_connect_device_name_length (connect), |
| 180 | device_name); |
| 181 | } |
| 182 | #else |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 183 | snprintf(path, sizeof path, "%.*s", |
| 184 | xcb_dri2_connect_device_name_length (connect), |
| 185 | xcb_dri2_connect_device_name (connect)); |
Chia-I Wu | 1b6c0ed | 2010-10-29 15:20:18 +0800 | [diff] [blame] | 186 | #endif |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 187 | free(connect); |
| 188 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 189 | fd = open(path, O_RDWR); |
| 190 | if (fd < 0) { |
| 191 | fprintf(stderr, |
Yuval Fledel | 91b5999 | 2010-11-22 21:42:58 +0200 | [diff] [blame] | 192 | "DRI2: could not open %s (%s)\n", path, strerror(errno)); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 193 | return -1; |
| 194 | } |
| 195 | |
| 196 | return wlsc_drm_init(&c->base, fd, path); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static int |
Kristian Høgsberg | 640609a | 2010-08-09 22:11:47 -0400 | [diff] [blame] | 200 | dri2_authenticate(struct x11_compositor *c, uint32_t magic) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 201 | { |
| 202 | xcb_dri2_authenticate_reply_t *authenticate; |
| 203 | xcb_dri2_authenticate_cookie_t authenticate_cookie; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 204 | |
| 205 | authenticate_cookie = |
| 206 | xcb_dri2_authenticate_unchecked(c->conn, |
| 207 | c->screen->root, magic); |
| 208 | authenticate = |
| 209 | xcb_dri2_authenticate_reply(c->conn, |
| 210 | authenticate_cookie, NULL); |
| 211 | if (authenticate == NULL || !authenticate->authenticated) { |
Yuval Fledel | 91b5999 | 2010-11-22 21:42:58 +0200 | [diff] [blame] | 212 | fprintf(stderr, "DRI2: failed to authenticate\n"); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 213 | free(authenticate); |
| 214 | return -1; |
| 215 | } |
| 216 | |
| 217 | free(authenticate); |
| 218 | |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | static int |
| 223 | x11_compositor_init_egl(struct x11_compositor *c) |
| 224 | { |
Kristian Høgsberg | 379b678 | 2010-07-28 22:52:28 -0400 | [diff] [blame] | 225 | EGLint major, minor; |
| 226 | const char *extensions; |
Kristian Høgsberg | 2c28aa5 | 2010-07-28 23:47:54 -0400 | [diff] [blame] | 227 | static const EGLint context_attribs[] = { |
| 228 | EGL_CONTEXT_CLIENT_VERSION, 2, |
| 229 | EGL_NONE |
| 230 | }; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 231 | |
| 232 | if (dri2_connect(c) < 0) |
| 233 | return -1; |
Kristian Høgsberg | f252d6a | 2010-07-08 20:15:10 -0400 | [diff] [blame] | 234 | |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame^] | 235 | c->base.display = eglGetDisplay(c->dpy); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 236 | if (c->base.display == NULL) { |
| 237 | fprintf(stderr, "failed to create display\n"); |
| 238 | return -1; |
| 239 | } |
| 240 | |
| 241 | if (!eglInitialize(c->base.display, &major, &minor)) { |
| 242 | fprintf(stderr, "failed to initialize display\n"); |
| 243 | return -1; |
| 244 | } |
| 245 | |
Kristian Høgsberg | 379b678 | 2010-07-28 22:52:28 -0400 | [diff] [blame] | 246 | extensions = eglQueryString(c->base.display, EGL_EXTENSIONS); |
| 247 | if (!strstr(extensions, "EGL_KHR_surfaceless_opengl")) { |
| 248 | fprintf(stderr, "EGL_KHR_surfaceless_opengl not available\n"); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 249 | return -1; |
| 250 | } |
| 251 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 252 | if (!eglBindAPI(EGL_OPENGL_ES_API)) { |
| 253 | fprintf(stderr, "failed to bind EGL_OPENGL_ES_API\n"); |
| 254 | return -1; |
| 255 | } |
| 256 | |
Kristian Høgsberg | 2c28aa5 | 2010-07-28 23:47:54 -0400 | [diff] [blame] | 257 | c->base.context = eglCreateContext(c->base.display, NULL, |
| 258 | EGL_NO_CONTEXT, context_attribs); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 259 | if (c->base.context == NULL) { |
| 260 | fprintf(stderr, "failed to create context\n"); |
| 261 | return -1; |
| 262 | } |
| 263 | |
| 264 | if (!eglMakeCurrent(c->base.display, EGL_NO_SURFACE, |
| 265 | EGL_NO_SURFACE, c->base.context)) { |
| 266 | fprintf(stderr, "failed to make context current\n"); |
| 267 | return -1; |
| 268 | } |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | static void |
| 274 | x11_compositor_present(struct wlsc_compositor *base) |
| 275 | { |
| 276 | struct x11_compositor *c = (struct x11_compositor *) base; |
| 277 | struct x11_output *output; |
| 278 | xcb_dri2_copy_region_cookie_t cookie; |
| 279 | struct timeval tv; |
| 280 | uint32_t msec; |
| 281 | |
| 282 | glFlush(); |
| 283 | |
| 284 | wl_list_for_each(output, &c->base.output_list, base.link) { |
| 285 | cookie = xcb_dri2_copy_region_unchecked(c->conn, |
| 286 | output->window, |
| 287 | output->region, |
| 288 | XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT, |
| 289 | XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT); |
| 290 | free(xcb_dri2_copy_region_reply(c->conn, cookie, NULL)); |
Kristian Høgsberg | 8f66a57 | 2011-01-07 08:38:56 -0500 | [diff] [blame] | 291 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 292 | |
| 293 | gettimeofday(&tv, NULL); |
| 294 | msec = tv.tv_sec * 1000 + tv.tv_usec / 1000; |
| 295 | wlsc_compositor_finish_frame(&c->base, msec); |
| 296 | } |
| 297 | |
| 298 | static void |
| 299 | x11_output_set_wm_protocols(struct x11_output *output) |
| 300 | { |
| 301 | xcb_atom_t list[1]; |
| 302 | struct x11_compositor *c = |
| 303 | (struct x11_compositor *) output->base.compositor; |
| 304 | |
| 305 | list[0] = c->atom.wm_delete_window; |
| 306 | xcb_change_property (c->conn, |
| 307 | XCB_PROP_MODE_REPLACE, |
| 308 | output->window, |
| 309 | c->atom.wm_protocols, |
| 310 | XCB_ATOM_ATOM, |
| 311 | 32, |
| 312 | ARRAY_SIZE(list), |
| 313 | list); |
| 314 | } |
| 315 | |
| 316 | struct wm_normal_hints { |
| 317 | uint32_t flags; |
| 318 | uint32_t pad[4]; |
| 319 | int32_t min_width, min_height; |
| 320 | int32_t max_width, max_height; |
| 321 | int32_t width_inc, height_inc; |
| 322 | int32_t min_aspect_x, min_aspect_y; |
| 323 | int32_t max_aspect_x, max_aspect_y; |
| 324 | int32_t base_width, base_height; |
| 325 | int32_t win_gravity; |
| 326 | }; |
| 327 | |
| 328 | #define WM_NORMAL_HINTS_MIN_SIZE 16 |
| 329 | #define WM_NORMAL_HINTS_MAX_SIZE 32 |
| 330 | |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 331 | static void |
| 332 | x11_output_set_icon(struct x11_compositor *c, struct x11_output *output, |
| 333 | const char *filename, int width, int height) |
| 334 | { |
| 335 | uint32_t *icon, *pixels; |
| 336 | |
| 337 | pixels = wlsc_load_image(filename, width, height); |
| 338 | if (!pixels) |
| 339 | return; |
| 340 | icon = malloc(width * height * 4 + 8); |
| 341 | if (!icon) { |
| 342 | free(pixels); |
| 343 | return; |
| 344 | } |
| 345 | |
| 346 | icon[0] = width; |
| 347 | icon[1] = height; |
| 348 | memcpy(icon + 2, pixels, width * height * 4); |
| 349 | xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 350 | c->atom.net_wm_icon, c->atom.cardinal, 32, |
| 351 | width * height + 2, icon); |
| 352 | free(icon); |
| 353 | free(pixels); |
| 354 | } |
| 355 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 356 | static int |
| 357 | x11_compositor_create_output(struct x11_compositor *c, int width, int height) |
| 358 | { |
| 359 | static const char name[] = "Wayland Compositor"; |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 360 | static const char class[] = "wayland-1\0Wayland Compositor"; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 361 | struct x11_output *output; |
| 362 | xcb_dri2_dri2_buffer_t *buffers; |
| 363 | xcb_dri2_get_buffers_reply_t *reply; |
| 364 | xcb_dri2_get_buffers_cookie_t cookie; |
| 365 | xcb_screen_iterator_t iter; |
| 366 | xcb_rectangle_t rectangle; |
| 367 | struct wm_normal_hints normal_hints; |
| 368 | unsigned int attachments[] = |
| 369 | { XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT}; |
| 370 | uint32_t mask = XCB_CW_EVENT_MASK | XCB_CW_CURSOR; |
| 371 | uint32_t values[2] = { |
| 372 | XCB_EVENT_MASK_KEY_PRESS | |
| 373 | XCB_EVENT_MASK_KEY_RELEASE | |
| 374 | XCB_EVENT_MASK_BUTTON_PRESS | |
| 375 | XCB_EVENT_MASK_BUTTON_RELEASE | |
| 376 | XCB_EVENT_MASK_POINTER_MOTION | |
| 377 | XCB_EVENT_MASK_EXPOSURE | |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 378 | XCB_EVENT_MASK_STRUCTURE_NOTIFY | |
| 379 | XCB_EVENT_MASK_ENTER_WINDOW | |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 380 | XCB_EVENT_MASK_LEAVE_WINDOW | |
| 381 | XCB_EVENT_MASK_KEYMAP_STATE | |
| 382 | XCB_EVENT_MASK_FOCUS_CHANGE, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 383 | 0 |
| 384 | }; |
| 385 | |
| 386 | EGLint attribs[] = { |
| 387 | EGL_WIDTH, 0, |
| 388 | EGL_HEIGHT, 0, |
Kristian Høgsberg | b12fcce | 2010-08-24 17:34:23 -0400 | [diff] [blame] | 389 | EGL_DRM_BUFFER_STRIDE_MESA, 0, |
| 390 | EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 391 | EGL_NONE |
| 392 | }; |
| 393 | |
| 394 | output = malloc(sizeof *output); |
| 395 | if (output == NULL) |
| 396 | return -1; |
| 397 | |
| 398 | memset(output, 0, sizeof *output); |
| 399 | wlsc_output_init(&output->base, &c->base, 0, 0, width, height); |
| 400 | |
| 401 | values[1] = c->null_cursor; |
| 402 | output->window = xcb_generate_id(c->conn); |
| 403 | iter = xcb_setup_roots_iterator(xcb_get_setup(c->conn)); |
| 404 | xcb_create_window(c->conn, |
| 405 | XCB_COPY_FROM_PARENT, |
| 406 | output->window, |
| 407 | iter.data->root, |
| 408 | 0, 0, |
| 409 | width, height, |
| 410 | 0, |
| 411 | XCB_WINDOW_CLASS_INPUT_OUTPUT, |
| 412 | iter.data->root_visual, |
| 413 | mask, values); |
| 414 | |
| 415 | /* Don't resize me. */ |
| 416 | memset(&normal_hints, 0, sizeof normal_hints); |
| 417 | normal_hints.flags = |
| 418 | WM_NORMAL_HINTS_MAX_SIZE | WM_NORMAL_HINTS_MIN_SIZE; |
| 419 | normal_hints.min_width = width; |
| 420 | normal_hints.min_height = height; |
| 421 | normal_hints.max_width = width; |
| 422 | normal_hints.max_height = height; |
| 423 | xcb_change_property (c->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 424 | c->atom.wm_normal_hints, |
| 425 | c->atom.wm_size_hints, 32, |
| 426 | sizeof normal_hints / 4, |
| 427 | (uint8_t *) &normal_hints); |
| 428 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 429 | /* Set window name. Don't bother with non-EWMH WMs. */ |
| 430 | xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 431 | c->atom.net_wm_name, c->atom.utf8_string, 8, |
| 432 | strlen(name), name); |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 433 | xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 434 | c->atom.wm_class, c->atom.string, 8, |
| 435 | sizeof class, class); |
| 436 | |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 437 | x11_output_set_icon(c, output, |
| 438 | DATADIR "/wayland/wayland.png", 128, 128); |
| 439 | |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 440 | xcb_map_window(c->conn, output->window); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 441 | |
| 442 | rectangle.x = 0; |
| 443 | rectangle.y = 0; |
| 444 | rectangle.width = width; |
| 445 | rectangle.height = height; |
| 446 | output->region = xcb_generate_id(c->conn); |
| 447 | xcb_xfixes_create_region(c->conn, output->region, 1, &rectangle); |
| 448 | |
| 449 | xcb_dri2_create_drawable (c->conn, output->window); |
| 450 | |
| 451 | x11_output_set_wm_protocols(output); |
| 452 | |
| 453 | cookie = xcb_dri2_get_buffers_unchecked (c->conn, |
| 454 | output->window, |
| 455 | 1, 1, attachments); |
| 456 | reply = xcb_dri2_get_buffers_reply (c->conn, cookie, NULL); |
| 457 | if (reply == NULL) |
| 458 | return -1; |
| 459 | buffers = xcb_dri2_get_buffers_buffers (reply); |
| 460 | if (buffers == NULL) |
| 461 | return -1; |
| 462 | |
| 463 | if (reply->count != 1) { |
| 464 | fprintf(stderr, |
| 465 | "got wrong number of buffers (%d)\n", reply->count); |
| 466 | return -1; |
| 467 | } |
| 468 | |
| 469 | attribs[1] = reply->width; |
| 470 | attribs[3] = reply->height; |
| 471 | attribs[5] = buffers[0].pitch / 4; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 472 | output->image = |
Kristian Høgsberg | 175e6ce | 2011-01-06 15:45:19 -0500 | [diff] [blame] | 473 | eglCreateImageKHR(c->base.display, |
| 474 | EGL_NO_CONTEXT, |
Kristian Høgsberg | b12fcce | 2010-08-24 17:34:23 -0400 | [diff] [blame] | 475 | EGL_DRM_BUFFER_MESA, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 476 | (EGLClientBuffer) buffers[0].name, |
| 477 | attribs); |
Kristian Høgsberg | 8f2e677 | 2010-07-29 14:48:13 -0400 | [diff] [blame] | 478 | free(reply); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 479 | |
| 480 | glGenRenderbuffers(1, &output->rbo); |
| 481 | glBindRenderbuffer(GL_RENDERBUFFER, output->rbo); |
| 482 | |
| 483 | glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, |
| 484 | output->image); |
| 485 | |
| 486 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, |
| 487 | GL_COLOR_ATTACHMENT0, |
| 488 | GL_RENDERBUFFER, |
| 489 | output->rbo); |
| 490 | |
| 491 | wl_list_insert(c->base.output_list.prev, &output->base.link); |
| 492 | |
| 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | static void |
| 497 | idle_repaint(void *data) |
| 498 | { |
| 499 | struct x11_output *output = data; |
| 500 | struct x11_compositor *c = |
| 501 | (struct x11_compositor *) output->base.compositor; |
| 502 | xcb_xfixes_region_t region; |
| 503 | xcb_dri2_copy_region_cookie_t cookie; |
| 504 | |
| 505 | if (output->damage_count <= ARRAY_SIZE(output->damage)) { |
| 506 | region = xcb_generate_id(c->conn); |
| 507 | xcb_xfixes_create_region(c->conn, region, |
| 508 | output->damage_count, output->damage); |
| 509 | } else { |
| 510 | region = output->region; |
| 511 | } |
| 512 | |
| 513 | cookie = xcb_dri2_copy_region_unchecked(c->conn, |
| 514 | output->window, |
| 515 | region, |
| 516 | XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT, |
| 517 | XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT); |
| 518 | |
| 519 | if (region != output->region) |
| 520 | xcb_xfixes_destroy_region(c->conn, region); |
| 521 | |
| 522 | free(xcb_dri2_copy_region_reply(c->conn, cookie, NULL)); |
| 523 | output->damage_count = 0; |
| 524 | } |
| 525 | |
| 526 | static struct x11_output * |
| 527 | x11_compositor_find_output(struct x11_compositor *c, xcb_window_t window) |
| 528 | { |
| 529 | struct x11_output *output; |
| 530 | |
| 531 | wl_list_for_each(output, &c->base.output_list, base.link) { |
| 532 | if (output->window == window) |
| 533 | return output; |
| 534 | } |
| 535 | |
| 536 | return NULL; |
| 537 | } |
| 538 | |
| 539 | static void |
| 540 | x11_compositor_handle_event(int fd, uint32_t mask, void *data) |
| 541 | { |
| 542 | struct x11_compositor *c = data; |
| 543 | struct x11_output *output; |
| 544 | xcb_generic_event_t *event; |
| 545 | struct wl_event_loop *loop; |
| 546 | xcb_client_message_event_t *client_message; |
| 547 | xcb_motion_notify_event_t *motion_notify; |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 548 | xcb_enter_notify_event_t *enter_notify; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 549 | xcb_key_press_event_t *key_press; |
| 550 | xcb_button_press_event_t *button_press; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 551 | xcb_keymap_notify_event_t *keymap_notify; |
| 552 | xcb_focus_in_event_t *focus_in; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 553 | xcb_expose_event_t *expose; |
| 554 | xcb_rectangle_t *r; |
| 555 | xcb_atom_t atom; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 556 | uint32_t *k; |
| 557 | int i, set; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 558 | |
| 559 | loop = wl_display_get_event_loop(c->base.wl_display); |
| 560 | while (event = xcb_poll_for_event (c->conn), event != NULL) { |
| 561 | switch (event->response_type & ~0x80) { |
| 562 | |
| 563 | case XCB_KEY_PRESS: |
| 564 | key_press = (xcb_key_press_event_t *) event; |
| 565 | notify_key(c->base.input_device, |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 566 | key_press->time, key_press->detail - 8, 1); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 567 | break; |
| 568 | case XCB_KEY_RELEASE: |
| 569 | key_press = (xcb_key_press_event_t *) event; |
| 570 | notify_key(c->base.input_device, |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 571 | key_press->time, key_press->detail - 8, 0); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 572 | break; |
| 573 | case XCB_BUTTON_PRESS: |
| 574 | button_press = (xcb_button_press_event_t *) event; |
| 575 | notify_button(c->base.input_device, |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 576 | button_press->time, |
Kristian Høgsberg | f9112b2 | 2010-06-14 12:53:43 -0400 | [diff] [blame] | 577 | button_press->detail + BTN_LEFT - 1, 1); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 578 | break; |
| 579 | case XCB_BUTTON_RELEASE: |
| 580 | button_press = (xcb_button_press_event_t *) event; |
| 581 | notify_button(c->base.input_device, |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 582 | button_press->time, |
Kristian Høgsberg | f9112b2 | 2010-06-14 12:53:43 -0400 | [diff] [blame] | 583 | button_press->detail + BTN_LEFT - 1, 0); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 584 | break; |
| 585 | |
| 586 | case XCB_MOTION_NOTIFY: |
| 587 | motion_notify = (xcb_motion_notify_event_t *) event; |
| 588 | notify_motion(c->base.input_device, |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 589 | motion_notify->time, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 590 | motion_notify->event_x, |
| 591 | motion_notify->event_y); |
| 592 | break; |
| 593 | |
| 594 | case XCB_EXPOSE: |
| 595 | expose = (xcb_expose_event_t *) event; |
| 596 | output = x11_compositor_find_output(c, expose->window); |
| 597 | if (output->damage_count == 0) |
| 598 | wl_event_loop_add_idle(loop, |
| 599 | idle_repaint, output); |
| 600 | |
| 601 | r = &output->damage[output->damage_count++]; |
| 602 | if (output->damage_count > 16) |
| 603 | break; |
| 604 | r->x = expose->x; |
| 605 | r->y = expose->y; |
| 606 | r->width = expose->width; |
| 607 | r->height = expose->height; |
| 608 | break; |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 609 | |
| 610 | case XCB_ENTER_NOTIFY: |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 611 | enter_notify = (xcb_enter_notify_event_t *) event; |
Kristian Høgsberg | 2dfe626 | 2011-02-08 11:59:53 -0500 | [diff] [blame] | 612 | if (enter_notify->state >= Button1Mask) |
| 613 | break; |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 614 | output = x11_compositor_find_output(c, enter_notify->event); |
| 615 | notify_pointer_focus(c->base.input_device, |
| 616 | enter_notify->time, |
| 617 | &output->base, |
| 618 | enter_notify->event_x, |
| 619 | enter_notify->event_y); |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 620 | break; |
| 621 | |
| 622 | case XCB_LEAVE_NOTIFY: |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 623 | enter_notify = (xcb_enter_notify_event_t *) event; |
Kristian Høgsberg | 2dfe626 | 2011-02-08 11:59:53 -0500 | [diff] [blame] | 624 | if (enter_notify->state >= Button1Mask) |
| 625 | break; |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 626 | notify_pointer_focus(c->base.input_device, |
| 627 | enter_notify->time, |
| 628 | NULL, |
| 629 | enter_notify->event_x, |
| 630 | enter_notify->event_y); |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 631 | break; |
| 632 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 633 | case XCB_CLIENT_MESSAGE: |
| 634 | client_message = (xcb_client_message_event_t *) event; |
| 635 | atom = client_message->data.data32[0]; |
| 636 | if (atom == c->atom.wm_delete_window) |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 637 | wl_display_terminate(c->base.wl_display); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 638 | break; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 639 | |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 640 | case XCB_FOCUS_IN: |
| 641 | focus_in = (xcb_focus_in_event_t *) event; |
| 642 | if (focus_in->mode == XCB_NOTIFY_MODE_WHILE_GRABBED) |
| 643 | break; |
| 644 | |
| 645 | output = x11_compositor_find_output(c, focus_in->event); |
| 646 | notify_keyboard_focus(c->base.input_device, |
| 647 | get_time(), |
| 648 | &output->base, &c->keys); |
| 649 | break; |
| 650 | |
| 651 | case XCB_FOCUS_OUT: |
| 652 | focus_in = (xcb_focus_in_event_t *) event; |
| 653 | if (focus_in->mode == XCB_NOTIFY_MODE_WHILE_GRABBED) |
| 654 | break; |
| 655 | notify_keyboard_focus(c->base.input_device, |
| 656 | get_time(), NULL, NULL); |
| 657 | break; |
| 658 | |
| 659 | case XCB_KEYMAP_NOTIFY: |
| 660 | keymap_notify = (xcb_keymap_notify_event_t *) event; |
| 661 | c->keys.size = 0; |
| 662 | for (i = 0; i < ARRAY_LENGTH(keymap_notify->keys) * 8; i++) { |
| 663 | set = keymap_notify->keys[i >> 3] & |
| 664 | (1 << (i & 7)); |
| 665 | if (set) { |
| 666 | k = wl_array_add(&c->keys, sizeof *k); |
| 667 | *k = i; |
| 668 | } |
| 669 | } |
| 670 | break; |
| 671 | default: |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 672 | break; |
| 673 | } |
| 674 | |
| 675 | free (event); |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 676 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | #define F(field) offsetof(struct x11_compositor, field) |
| 680 | |
| 681 | static void |
| 682 | x11_compositor_get_resources(struct x11_compositor *c) |
| 683 | { |
| 684 | static const struct { const char *name; int offset; } atoms[] = { |
| 685 | { "WM_PROTOCOLS", F(atom.wm_protocols) }, |
| 686 | { "WM_NORMAL_HINTS", F(atom.wm_normal_hints) }, |
| 687 | { "WM_SIZE_HINTS", F(atom.wm_size_hints) }, |
| 688 | { "WM_DELETE_WINDOW", F(atom.wm_delete_window) }, |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 689 | { "WM_CLASS", F(atom.wm_class) }, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 690 | { "_NET_WM_NAME", F(atom.net_wm_name) }, |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 691 | { "_NET_WM_ICON", F(atom.net_wm_icon) }, |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 692 | { "STRING", F(atom.string) }, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 693 | { "UTF8_STRING", F(atom.utf8_string) }, |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 694 | { "CARDINAL", F(atom.cardinal) }, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 695 | }; |
| 696 | |
| 697 | xcb_intern_atom_cookie_t cookies[ARRAY_SIZE(atoms)]; |
| 698 | xcb_intern_atom_reply_t *reply; |
| 699 | xcb_pixmap_t pixmap; |
| 700 | xcb_gc_t gc; |
| 701 | int i; |
| 702 | uint8_t data[] = { 0, 0, 0, 0 }; |
| 703 | |
| 704 | for (i = 0; i < ARRAY_SIZE(atoms); i++) |
| 705 | cookies[i] = xcb_intern_atom (c->conn, 0, |
| 706 | strlen(atoms[i].name), |
| 707 | atoms[i].name); |
| 708 | |
| 709 | for (i = 0; i < ARRAY_SIZE(atoms); i++) { |
| 710 | reply = xcb_intern_atom_reply (c->conn, cookies[i], NULL); |
| 711 | *(xcb_atom_t *) ((char *) c + atoms[i].offset) = reply->atom; |
| 712 | free(reply); |
| 713 | } |
| 714 | |
| 715 | pixmap = xcb_generate_id(c->conn); |
| 716 | gc = xcb_generate_id(c->conn); |
| 717 | xcb_create_pixmap(c->conn, 1, pixmap, c->screen->root, 1, 1); |
| 718 | xcb_create_gc(c->conn, gc, pixmap, 0, NULL); |
| 719 | xcb_put_image(c->conn, XCB_IMAGE_FORMAT_XY_PIXMAP, |
| 720 | pixmap, gc, 1, 1, 0, 0, 0, 32, sizeof data, data); |
| 721 | c->null_cursor = xcb_generate_id(c->conn); |
| 722 | xcb_create_cursor (c->conn, c->null_cursor, |
| 723 | pixmap, pixmap, 0, 0, 0, 0, 0, 0, 1, 1); |
| 724 | xcb_free_gc(c->conn, gc); |
| 725 | xcb_free_pixmap(c->conn, pixmap); |
| 726 | } |
| 727 | |
Kristian Høgsberg | 640609a | 2010-08-09 22:11:47 -0400 | [diff] [blame] | 728 | static int |
| 729 | x11_authenticate(struct wlsc_compositor *c, uint32_t id) |
| 730 | { |
| 731 | return dri2_authenticate((struct x11_compositor *) c, id); |
| 732 | } |
| 733 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 734 | static void |
| 735 | x11_destroy(struct wlsc_compositor *ec) |
| 736 | { |
| 737 | free(ec); |
| 738 | } |
| 739 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 740 | struct wlsc_compositor * |
Kristian Høgsberg | 61a8251 | 2010-10-26 11:26:44 -0400 | [diff] [blame] | 741 | x11_compositor_create(struct wl_display *display, int width, int height) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 742 | { |
| 743 | struct x11_compositor *c; |
| 744 | struct wl_event_loop *loop; |
| 745 | xcb_screen_iterator_t s; |
| 746 | |
| 747 | c = malloc(sizeof *c); |
| 748 | if (c == NULL) |
| 749 | return NULL; |
| 750 | |
| 751 | memset(c, 0, sizeof *c); |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame^] | 752 | |
| 753 | c->dpy = XOpenDisplay(NULL); |
| 754 | c->conn = XGetXCBConnection(c->dpy); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 755 | |
| 756 | if (xcb_connection_has_error(c->conn)) |
| 757 | return NULL; |
| 758 | |
| 759 | s = xcb_setup_roots_iterator(xcb_get_setup(c->conn)); |
| 760 | c->screen = s.data; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 761 | wl_array_init(&c->keys); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 762 | |
| 763 | x11_compositor_get_resources(c); |
| 764 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 765 | c->base.wl_display = display; |
Tiago Vignatti | 997ce64 | 2010-11-10 02:42:35 +0200 | [diff] [blame] | 766 | if (x11_compositor_init_egl(c) < 0) |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 767 | return NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 768 | |
Kristian Høgsberg | 8525a50 | 2011-01-14 16:20:21 -0500 | [diff] [blame] | 769 | c->base.destroy = x11_destroy; |
| 770 | c->base.authenticate = x11_authenticate; |
| 771 | c->base.present = x11_compositor_present; |
| 772 | c->base.create_buffer = wlsc_drm_buffer_create; |
| 773 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 774 | /* Can't init base class until we have a current egl context */ |
Kristian Høgsberg | a946821 | 2010-06-14 21:03:11 -0400 | [diff] [blame] | 775 | if (wlsc_compositor_init(&c->base, display) < 0) |
| 776 | return NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 777 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 778 | if (x11_compositor_create_output(c, width, height) < 0) |
| 779 | return NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 780 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 781 | if (x11_input_create(c) < 0) |
| 782 | return NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 783 | |
| 784 | loop = wl_display_get_event_loop(c->base.wl_display); |
| 785 | |
| 786 | c->xcb_source = |
| 787 | wl_event_loop_add_fd(loop, xcb_get_file_descriptor(c->conn), |
| 788 | WL_EVENT_READABLE, |
| 789 | x11_compositor_handle_event, c); |
| 790 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 791 | return &c->base; |
| 792 | } |