Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 Benjamin Franzke |
| 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 | #ifdef HAVE_CONFIG_H |
| 20 | #include <config.h> |
| 21 | #endif |
| 22 | |
| 23 | #include <stddef.h> |
| 24 | #define _GNU_SOURCE |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <fcntl.h> |
| 29 | #include <unistd.h> |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 30 | |
| 31 | #include "wayland-client.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 "compositor.h" |
| 41 | |
| 42 | struct wayland_compositor { |
| 43 | struct wlsc_compositor base; |
| 44 | |
| 45 | struct { |
| 46 | struct wl_display *display; |
| 47 | struct wl_compositor *compositor; |
| 48 | struct wl_shell *shell; |
| 49 | struct wl_drm *drm; |
| 50 | struct wl_output *output; |
| 51 | |
| 52 | struct { |
| 53 | int32_t x, y, width, height; |
| 54 | } screen_allocation; |
| 55 | |
| 56 | char *device_name; |
| 57 | int authenticated; |
| 58 | |
| 59 | struct wl_event_source *wl_source; |
| 60 | uint32_t event_mask; |
| 61 | } parent; |
| 62 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 63 | struct wl_list input_list; |
| 64 | }; |
| 65 | |
| 66 | struct wayland_output { |
| 67 | struct wlsc_output base; |
| 68 | |
| 69 | struct { |
| 70 | struct wl_surface *surface; |
| 71 | struct wl_buffer *buffer[2]; |
| 72 | } parent; |
| 73 | EGLImageKHR image[2]; |
| 74 | GLuint rbo[2]; |
| 75 | uint32_t fb_id[2]; |
| 76 | uint32_t current; |
| 77 | }; |
| 78 | |
| 79 | struct wayland_input { |
| 80 | struct wayland_compositor *compositor; |
| 81 | struct wl_input_device *input_device; |
| 82 | struct wl_list link; |
| 83 | }; |
| 84 | |
| 85 | static int |
| 86 | wayland_input_create(struct wayland_compositor *c) |
| 87 | { |
| 88 | struct wlsc_input_device *input; |
| 89 | |
| 90 | input = malloc(sizeof *input); |
| 91 | if (input == NULL) |
| 92 | return -1; |
| 93 | |
| 94 | memset(input, 0, sizeof *input); |
| 95 | wlsc_input_device_init(input, &c->base); |
| 96 | |
Kristian Høgsberg | 9c3e8d7 | 2010-12-08 09:48:52 -0500 | [diff] [blame] | 97 | c->base.input_device = &input->input_device; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static int |
| 103 | wayland_compositor_init_egl(struct wayland_compositor *c) |
| 104 | { |
| 105 | EGLint major, minor; |
| 106 | const char *extensions; |
| 107 | drm_magic_t magic; |
| 108 | int fd; |
| 109 | static const EGLint context_attribs[] = { |
| 110 | EGL_CONTEXT_CLIENT_VERSION, 2, |
| 111 | EGL_NONE |
| 112 | }; |
| 113 | |
| 114 | fd = open(c->parent.device_name, O_RDWR); |
| 115 | if (fd < 0) { |
| 116 | fprintf(stderr, "drm open failed: %m\n"); |
| 117 | return -1; |
| 118 | } |
| 119 | |
| 120 | wlsc_drm_init(&c->base, fd, c->parent.device_name); |
| 121 | |
| 122 | if (drmGetMagic(fd, &magic)) { |
| 123 | fprintf(stderr, "DRI2: failed to get drm magic"); |
| 124 | return -1; |
| 125 | } |
| 126 | |
| 127 | wl_drm_authenticate(c->parent.drm, magic); |
| 128 | wl_display_iterate(c->parent.display, WL_DISPLAY_WRITABLE); |
| 129 | while (!c->parent.authenticated) |
| 130 | wl_display_iterate(c->parent.display, WL_DISPLAY_READABLE); |
| 131 | |
| 132 | c->base.display = eglGetDRMDisplayMESA(fd); |
| 133 | if (c->base.display == NULL) { |
| 134 | fprintf(stderr, "failed to create display\n"); |
| 135 | return -1; |
| 136 | } |
| 137 | |
| 138 | if (!eglInitialize(c->base.display, &major, &minor)) { |
| 139 | fprintf(stderr, "failed to initialize display\n"); |
| 140 | return -1; |
| 141 | } |
| 142 | |
| 143 | extensions = eglQueryString(c->base.display, EGL_EXTENSIONS); |
| 144 | if (!strstr(extensions, "EGL_KHR_surfaceless_opengl")) { |
| 145 | fprintf(stderr, "EGL_KHR_surfaceless_opengl not available\n"); |
| 146 | return -1; |
| 147 | } |
| 148 | |
| 149 | if (!eglBindAPI(EGL_OPENGL_ES_API)) { |
| 150 | fprintf(stderr, "failed to bind EGL_OPENGL_ES_API\n"); |
| 151 | return -1; |
| 152 | } |
| 153 | |
| 154 | c->base.context = eglCreateContext(c->base.display, NULL, |
| 155 | EGL_NO_CONTEXT, context_attribs); |
| 156 | if (c->base.context == NULL) { |
| 157 | fprintf(stderr, "failed to create context\n"); |
| 158 | return -1; |
| 159 | } |
| 160 | |
| 161 | if (!eglMakeCurrent(c->base.display, EGL_NO_SURFACE, |
| 162 | EGL_NO_SURFACE, c->base.context)) { |
| 163 | fprintf(stderr, "failed to make context current\n"); |
| 164 | return -1; |
| 165 | } |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | static void |
Kristian Høgsberg | 3ada7ec | 2010-12-01 09:42:10 -0500 | [diff] [blame] | 171 | frame_callback(void *data, uint32_t time) |
| 172 | { |
| 173 | struct wayland_compositor *c = (struct wayland_compositor *) data; |
| 174 | |
| 175 | wlsc_compositor_finish_frame(&c->base, time); |
| 176 | } |
| 177 | |
| 178 | static void |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 179 | wayland_compositor_present(struct wlsc_compositor *base) |
| 180 | { |
| 181 | struct wayland_compositor *c = (struct wayland_compositor *) base; |
| 182 | struct wayland_output *output; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 183 | |
Kristian Høgsberg | 4203df1 | 2010-12-01 09:40:58 -0500 | [diff] [blame] | 184 | glFlush(); |
| 185 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 186 | wl_list_for_each(output, &base->output_list, base.link) { |
| 187 | output->current ^= 1; |
| 188 | |
| 189 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, |
| 190 | GL_COLOR_ATTACHMENT0, |
| 191 | GL_RENDERBUFFER, |
| 192 | output->rbo[output->current]); |
| 193 | |
| 194 | wl_surface_attach(output->parent.surface, |
Kristian Høgsberg | 82da52b | 2010-12-17 09:53:12 -0500 | [diff] [blame] | 195 | output->parent.buffer[output->current ^ 1], |
| 196 | 0, 0); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 197 | wl_surface_damage(output->parent.surface, 0, 0, |
| 198 | output->base.width, output->base.height); |
| 199 | } |
| 200 | |
Kristian Høgsberg | 3ada7ec | 2010-12-01 09:42:10 -0500 | [diff] [blame] | 201 | wl_display_frame_callback(c->parent.display, frame_callback, c); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static int |
| 205 | wayland_authenticate(struct wlsc_compositor *ec, uint32_t id) |
| 206 | { |
| 207 | struct wayland_compositor *c = (struct wayland_compositor *) ec; |
| 208 | |
| 209 | wl_drm_authenticate(c->parent.drm, id); |
| 210 | /* FIXME: recv drm_authenticated event from parent? */ |
| 211 | wl_display_iterate(c->parent.display, WL_DISPLAY_WRITABLE); |
| 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | static int |
| 217 | wayland_compositor_create_output(struct wayland_compositor *c, |
| 218 | int width, int height) |
| 219 | { |
| 220 | struct wayland_output *output; |
| 221 | struct wl_visual *visual; |
| 222 | int i; |
| 223 | EGLint name, stride, attribs[] = { |
| 224 | EGL_WIDTH, 0, |
| 225 | EGL_HEIGHT, 0, |
| 226 | EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA, |
| 227 | EGL_DRM_BUFFER_USE_MESA, EGL_DRM_BUFFER_USE_SCANOUT_MESA, |
| 228 | EGL_NONE |
| 229 | }; |
| 230 | |
| 231 | output = malloc(sizeof *output); |
| 232 | if (output == NULL) |
| 233 | return -1; |
| 234 | memset(output, 0, sizeof *output); |
| 235 | |
| 236 | wlsc_output_init(&output->base, &c->base, 0, 0, width, height); |
| 237 | output->parent.surface = |
| 238 | wl_compositor_create_surface(c->parent.compositor); |
| 239 | wl_surface_set_user_data(output->parent.surface, output); |
| 240 | |
| 241 | glGenRenderbuffers(2, output->rbo); |
| 242 | visual = wl_display_get_premultiplied_argb_visual(c->parent.display); |
| 243 | for (i = 0; i < 2; i++) { |
| 244 | glBindRenderbuffer(GL_RENDERBUFFER, output->rbo[i]); |
| 245 | |
| 246 | attribs[1] = width; |
| 247 | attribs[3] = height; |
| 248 | output->image[i] = |
| 249 | eglCreateDRMImageMESA(c->base.display, attribs); |
| 250 | glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, |
| 251 | output->image[i]); |
| 252 | eglExportDRMImageMESA(c->base.display, output->image[i], |
| 253 | &name, NULL, &stride); |
| 254 | output->parent.buffer[i] = |
| 255 | wl_drm_create_buffer(c->parent.drm, name, |
| 256 | width, height, |
| 257 | stride, visual); |
| 258 | } |
| 259 | |
| 260 | output->current = 0; |
| 261 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, |
| 262 | GL_COLOR_ATTACHMENT0, |
| 263 | GL_RENDERBUFFER, |
| 264 | output->rbo[output->current]); |
| 265 | |
| 266 | wl_surface_attach(output->parent.surface, |
Kristian Høgsberg | 82da52b | 2010-12-17 09:53:12 -0500 | [diff] [blame] | 267 | output->parent.buffer[output->current], 0, 0); |
| 268 | wl_surface_map_toplevel(output->parent.surface); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 269 | |
| 270 | glClearColor(0, 0, 0, 0.5); |
| 271 | |
| 272 | wl_list_insert(c->base.output_list.prev, &output->base.link); |
| 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 277 | /* Events received from the wayland-server this compositor is client of: */ |
| 278 | |
| 279 | /* parent output interface */ |
| 280 | static void |
| 281 | display_handle_geometry(void *data, |
| 282 | struct wl_output *output, |
Kristian Høgsberg | f8fc08f | 2010-12-01 20:10:10 -0500 | [diff] [blame] | 283 | int32_t x, int32_t y, |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 284 | int32_t width, int32_t height) |
| 285 | { |
| 286 | struct wayland_compositor *c = data; |
| 287 | |
Kristian Høgsberg | f8fc08f | 2010-12-01 20:10:10 -0500 | [diff] [blame] | 288 | c->parent.screen_allocation.x = x; |
| 289 | c->parent.screen_allocation.y = y; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 290 | c->parent.screen_allocation.width = width; |
| 291 | c->parent.screen_allocation.height = height; |
| 292 | } |
| 293 | |
| 294 | static const struct wl_output_listener output_listener = { |
| 295 | display_handle_geometry, |
| 296 | }; |
| 297 | |
| 298 | /* parent shell interface */ |
| 299 | static void |
| 300 | handle_configure(void *data, struct wl_shell *shell, |
| 301 | uint32_t time, uint32_t edges, |
Kristian Høgsberg | cbe6f04 | 2010-12-17 09:54:45 -0500 | [diff] [blame] | 302 | struct wl_surface *surface, int32_t width, int32_t height) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 303 | { |
| 304 | #if 0 |
| 305 | struct output *output = wl_surface_get_user_data(surface); |
| 306 | |
| 307 | /* FIXME: add resize? */ |
| 308 | #endif |
| 309 | } |
| 310 | |
| 311 | static const struct wl_shell_listener shell_listener = { |
| 312 | handle_configure, |
| 313 | }; |
| 314 | |
| 315 | /* parent drm interface */ |
| 316 | static void |
| 317 | drm_handle_device(void *data, struct wl_drm *drm, const char *device) |
| 318 | { |
| 319 | struct wayland_compositor *c = data; |
| 320 | |
| 321 | c->parent.device_name = strdup(device); |
| 322 | } |
| 323 | |
| 324 | static void drm_handle_authenticated(void *data, struct wl_drm *drm) |
| 325 | { |
| 326 | struct wayland_compositor *c = data; |
| 327 | |
| 328 | c->parent.authenticated = 1; |
| 329 | } |
| 330 | |
| 331 | static const struct wl_drm_listener drm_listener = { |
| 332 | drm_handle_device, |
| 333 | drm_handle_authenticated |
| 334 | }; |
| 335 | |
| 336 | /* parent input interface */ |
| 337 | static void |
| 338 | input_handle_motion(void *data, struct wl_input_device *input_device, |
| 339 | uint32_t time, |
| 340 | int32_t x, int32_t y, int32_t sx, int32_t sy) |
| 341 | { |
| 342 | struct wayland_input *input = data; |
| 343 | struct wayland_compositor *c = input->compositor; |
| 344 | |
| 345 | notify_motion(c->base.input_device, time, sx, sy); |
| 346 | } |
| 347 | |
| 348 | static void |
| 349 | input_handle_button(void *data, |
| 350 | struct wl_input_device *input_device, |
| 351 | uint32_t time, uint32_t button, uint32_t state) |
| 352 | { |
| 353 | struct wayland_input *input = data; |
| 354 | struct wayland_compositor *c = input->compositor; |
| 355 | |
| 356 | notify_button(c->base.input_device, time, button, state); |
| 357 | } |
| 358 | |
| 359 | static void |
| 360 | input_handle_key(void *data, struct wl_input_device *input_device, |
| 361 | uint32_t time, uint32_t key, uint32_t state) |
| 362 | { |
| 363 | struct wayland_input *input = data; |
| 364 | struct wayland_compositor *c = input->compositor; |
| 365 | |
| 366 | notify_key(c->base.input_device, time, key, state); |
| 367 | } |
| 368 | |
| 369 | static void |
| 370 | input_handle_pointer_focus(void *data, |
| 371 | struct wl_input_device *input_device, |
| 372 | uint32_t time, struct wl_surface *surface, |
| 373 | int32_t x, int32_t y, int32_t sx, int32_t sy) |
| 374 | { |
| 375 | struct wayland_input *input = data; |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 376 | struct wayland_output *output = data; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 377 | struct wayland_compositor *c = input->compositor; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 378 | |
| 379 | if (surface) { |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 380 | output = wl_surface_get_user_data(surface); |
| 381 | notify_pointer_focus(c->base.input_device, |
| 382 | time, &output->base, sx, sy); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 383 | } else { |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 384 | notify_pointer_focus(c->base.input_device, time, NULL, 0, 0); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
| 388 | static void |
| 389 | input_handle_keyboard_focus(void *data, |
| 390 | struct wl_input_device *input_device, |
| 391 | uint32_t time, |
| 392 | struct wl_surface *surface, |
| 393 | struct wl_array *keys) |
| 394 | { |
| 395 | /* FIXME: sth to be done here? */ |
| 396 | } |
| 397 | |
| 398 | static const struct wl_input_device_listener input_device_listener = { |
| 399 | input_handle_motion, |
| 400 | input_handle_button, |
| 401 | input_handle_key, |
| 402 | input_handle_pointer_focus, |
| 403 | input_handle_keyboard_focus, |
| 404 | }; |
| 405 | |
| 406 | static void |
| 407 | display_add_input(struct wayland_compositor *c, uint32_t id) |
| 408 | { |
| 409 | struct wayland_input *input; |
| 410 | |
| 411 | input = malloc(sizeof *input); |
| 412 | if (input == NULL) |
| 413 | return; |
| 414 | |
| 415 | memset(input, 0, sizeof *input); |
| 416 | |
| 417 | input->compositor = c; |
| 418 | input->input_device = wl_input_device_create(c->parent.display, id); |
| 419 | wl_list_insert(c->input_list.prev, &input->link); |
| 420 | |
| 421 | wl_input_device_add_listener(input->input_device, |
| 422 | &input_device_listener, input); |
| 423 | wl_input_device_set_user_data(input->input_device, input); |
| 424 | } |
| 425 | |
| 426 | static void |
| 427 | display_handle_global(struct wl_display *display, uint32_t id, |
| 428 | const char *interface, uint32_t version, void *data) |
| 429 | { |
| 430 | struct wayland_compositor *c = data; |
| 431 | |
| 432 | if (strcmp(interface, "compositor") == 0) { |
| 433 | c->parent.compositor = wl_compositor_create(display, id); |
| 434 | } else if (strcmp(interface, "output") == 0) { |
| 435 | c->parent.output = wl_output_create(display, id); |
| 436 | wl_output_add_listener(c->parent.output, &output_listener, c); |
| 437 | } else if (strcmp(interface, "input_device") == 0) { |
| 438 | display_add_input(c, id); |
| 439 | } else if (strcmp(interface, "shell") == 0) { |
| 440 | c->parent.shell = wl_shell_create(display, id); |
| 441 | wl_shell_add_listener(c->parent.shell, &shell_listener, c); |
| 442 | } else if (strcmp(interface, "drm") == 0) { |
| 443 | c->parent.drm = wl_drm_create(display, id); |
| 444 | wl_drm_add_listener(c->parent.drm, &drm_listener, c); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | static int |
| 449 | update_event_mask(uint32_t mask, void *data) |
| 450 | { |
| 451 | struct wayland_compositor *c = data; |
| 452 | |
| 453 | c->parent.event_mask = mask; |
| 454 | if (c->parent.wl_source) |
| 455 | wl_event_source_fd_update(c->parent.wl_source, mask); |
| 456 | |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | static void |
| 461 | wayland_compositor_handle_event(int fd, uint32_t mask, void *data) |
| 462 | { |
| 463 | struct wayland_compositor *c = data; |
| 464 | |
| 465 | if (mask & WL_EVENT_READABLE) |
| 466 | wl_display_iterate(c->parent.display, WL_DISPLAY_READABLE); |
| 467 | if (mask & WL_EVENT_WRITEABLE) |
| 468 | wl_display_iterate(c->parent.display, WL_DISPLAY_WRITABLE); |
| 469 | } |
| 470 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 471 | static void |
| 472 | wayland_destroy(struct wlsc_compositor *ec) |
| 473 | { |
| 474 | free(ec); |
| 475 | } |
| 476 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 477 | struct wlsc_compositor * |
| 478 | wayland_compositor_create(struct wl_display *display, int width, int height) |
| 479 | { |
| 480 | struct wayland_compositor *c; |
| 481 | struct wl_event_loop *loop; |
| 482 | int fd; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 483 | |
| 484 | c = malloc(sizeof *c); |
| 485 | if (c == NULL) |
| 486 | return NULL; |
| 487 | |
| 488 | memset(c, 0, sizeof *c); |
| 489 | |
Kristian Høgsberg | 2bb3ebe | 2010-12-01 15:36:20 -0500 | [diff] [blame] | 490 | c->parent.display = wl_display_connect(NULL); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 491 | |
| 492 | if (c->parent.display == NULL) { |
| 493 | fprintf(stderr, "failed to create display: %m\n"); |
| 494 | return NULL; |
| 495 | } |
| 496 | |
| 497 | wl_list_init(&c->input_list); |
| 498 | wl_display_add_global_listener(c->parent.display, |
| 499 | display_handle_global, c); |
| 500 | |
| 501 | wl_display_iterate(c->parent.display, WL_DISPLAY_READABLE); |
| 502 | |
| 503 | c->base.wl_display = display; |
| 504 | if (wayland_compositor_init_egl(c) < 0) |
| 505 | return NULL; |
| 506 | |
Benjamin Franzke | ecfb2b9 | 2011-01-15 12:34:48 +0100 | [diff] [blame] | 507 | c->base.destroy = wayland_destroy; |
| 508 | c->base.authenticate = wayland_authenticate; |
| 509 | c->base.present = wayland_compositor_present; |
| 510 | c->base.create_buffer = wlsc_drm_buffer_create; |
| 511 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 512 | /* Can't init base class until we have a current egl context */ |
| 513 | if (wlsc_compositor_init(&c->base, display) < 0) |
| 514 | return NULL; |
| 515 | |
| 516 | if (wayland_compositor_create_output(c, width, height) < 0) |
| 517 | return NULL; |
| 518 | |
| 519 | if (wayland_input_create(c) < 0) |
| 520 | return NULL; |
| 521 | |
| 522 | loop = wl_display_get_event_loop(c->base.wl_display); |
| 523 | |
| 524 | fd = wl_display_get_fd(c->parent.display, update_event_mask, c); |
| 525 | c->parent.wl_source = |
| 526 | wl_event_loop_add_fd(loop, fd, c->parent.event_mask, |
| 527 | wayland_compositor_handle_event, c); |
| 528 | if (c->parent.wl_source == NULL) |
| 529 | return NULL; |
| 530 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 531 | return &c->base; |
| 532 | } |