blob: bbadfc324bd72f84ee705e1db9d27c5eb01452d0 [file] [log] [blame]
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001/*
Kristian Høgsberg96aa7da2011-09-15 15:43:14 -04002 * Copyright © 2010-2011 Benjamin Franzke
Jason Ekstrandff2fd462013-10-27 22:24:58 -05003 * Copyright © 2013 Jason Ekstrand
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01004 *
Kristian Høgsberg96aa7da2011-09-15 15:43:14 -04005 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010014 *
Kristian Høgsberg96aa7da2011-09-15 15:43:14 -040015 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010022 */
23
Daniel Stonec228e232013-05-22 18:03:19 +030024#include "config.h"
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010025
26#include <stddef.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010027#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <fcntl.h>
31#include <unistd.h>
Daniel Stoneb7452fe2012-06-01 12:14:06 +010032#include <sys/mman.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010033
Benjamin Franzkebe014562011-02-18 17:04:24 +010034#include <wayland-client.h>
35#include <wayland-egl.h>
Jason Ekstrand7744f712013-10-27 22:24:55 -050036#include <wayland-cursor.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010037
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010038#include "compositor.h"
John Kåre Alsaker30d2b1f2012-11-13 19:10:28 +010039#include "gl-renderer.h"
Jason Ekstrandff2fd462013-10-27 22:24:58 -050040#include "pixman-renderer.h"
Kristian Høgsberg3c2360f2013-01-28 16:01:22 -050041#include "../shared/image-loader.h"
Jonas Ådahle5a12252013-04-05 23:07:11 +020042#include "../shared/os-compatibility.h"
Jason Ekstrand7744f712013-10-27 22:24:55 -050043#include "../shared/cairo-util.h"
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010044
45struct wayland_compositor {
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050046 struct weston_compositor base;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010047
48 struct {
Kristian Høgsberg362b6722012-06-18 15:13:51 -040049 struct wl_display *wl_display;
Kristian Høgsbergfa80e112012-10-10 21:34:26 -040050 struct wl_registry *registry;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010051 struct wl_compositor *compositor;
52 struct wl_shell *shell;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010053 struct wl_output *output;
Jonas Ådahle5a12252013-04-05 23:07:11 +020054 struct wl_shm *shm;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010055
56 struct {
57 int32_t x, y, width, height;
58 } screen_allocation;
59
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010060 struct wl_event_source *wl_source;
61 uint32_t event_mask;
62 } parent;
63
Jason Ekstrandff2fd462013-10-27 22:24:58 -050064 int use_pixman;
65
Jason Ekstrand7744f712013-10-27 22:24:55 -050066 struct theme *theme;
67 cairo_device_t *frame_device;
68 struct wl_cursor_theme *cursor_theme;
69 struct wl_cursor *cursor;
Kristian Høgsberg546a8122012-02-01 07:45:51 -050070
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050071 struct wl_list inputs;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010072};
73
74struct wayland_output {
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050075 struct weston_output base;
76
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010077 struct {
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050078 int draw_initial_frame;
79 struct wl_surface *surface;
80 struct wl_shell_surface *shell_surface;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010081 } parent;
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050082
Jason Ekstrand7744f712013-10-27 22:24:55 -050083 int keyboard_count;
84
85 struct frame *frame;
Jason Ekstrandff2fd462013-10-27 22:24:58 -050086
Jason Ekstrand7744f712013-10-27 22:24:55 -050087 struct {
Jason Ekstrandff2fd462013-10-27 22:24:58 -050088 struct wl_egl_window *egl_window;
89 struct {
90 cairo_surface_t *top;
91 cairo_surface_t *left;
92 cairo_surface_t *right;
93 cairo_surface_t *bottom;
94 } border;
95 } gl;
96
97 struct {
98 struct wl_list buffers;
99 struct wl_list free_buffers;
100 } shm;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500101
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500102 struct weston_mode mode;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100103};
104
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500105struct wayland_shm_buffer {
106 struct wayland_output *output;
107 struct wl_list link;
108 struct wl_list free_link;
109
110 struct wl_buffer *buffer;
111 void *data;
112 size_t size;
113 pixman_region32_t damage;
114 int frame_damaged;
115
116 pixman_image_t *pm_image;
117 cairo_surface_t *c_surface;
118};
119
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100120struct wayland_input {
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -0400121 struct weston_seat base;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100122 struct wayland_compositor *compositor;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100123 struct wl_list link;
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500124
125 struct {
126 struct wl_seat *seat;
127 struct wl_pointer *pointer;
128 struct wl_keyboard *keyboard;
129 struct wl_touch *touch;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500130
131 struct {
132 struct wl_surface *surface;
133 int32_t hx, hy;
134 } cursor;
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500135 } parent;
136
Daniel Stone50692802012-06-22 13:21:41 +0100137 uint32_t key_serial;
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400138 uint32_t enter_serial;
139 int focus;
140 struct wayland_output *output;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500141 struct wayland_output *keyboard_focus;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100142};
143
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +0300144struct gl_renderer_interface *gl_renderer;
145
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500146static void
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500147wayland_shm_buffer_destroy(struct wayland_shm_buffer *buffer)
148{
149 cairo_surface_destroy(buffer->c_surface);
150 pixman_image_unref(buffer->pm_image);
151
152 wl_buffer_destroy(buffer->buffer);
153 munmap(buffer->data, buffer->size);
154
155 pixman_region32_fini(&buffer->damage);
156
157 wl_list_remove(&buffer->link);
158 wl_list_remove(&buffer->free_link);
159 free(buffer);
160}
161
162static void
163buffer_release(void *data, struct wl_buffer *buffer)
164{
165 struct wayland_shm_buffer *sb = data;
166
167 if (sb->output) {
168 wl_list_insert(&sb->output->shm.free_buffers, &sb->free_link);
169 } else {
170 wayland_shm_buffer_destroy(sb);
171 }
172}
173
174static const struct wl_buffer_listener buffer_listener = {
175 buffer_release
176};
177
178static struct wayland_shm_buffer *
179wayland_output_get_shm_buffer(struct wayland_output *output)
180{
181 struct wayland_compositor *c =
182 (struct wayland_compositor *) output->base.compositor;
183 struct wl_shm *shm = c->parent.shm;
184 struct wayland_shm_buffer *sb;
185
186 struct wl_shm_pool *pool;
187 int width, height, stride;
188 int32_t fx, fy;
189 int fd;
190 unsigned char *data;
191
192 if (!wl_list_empty(&output->shm.free_buffers)) {
193 sb = container_of(output->shm.free_buffers.next,
194 struct wayland_shm_buffer, free_link);
195 wl_list_remove(&sb->free_link);
196 wl_list_init(&sb->free_link);
197
198 return sb;
199 }
200
201 if (output->frame) {
202 width = frame_width(output->frame);
203 height = frame_height(output->frame);
204 } else {
205 width = output->mode.width;
206 height = output->mode.height;
207 }
208
209 stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
210
211 fd = os_create_anonymous_file(height * stride);
212 if (fd < 0) {
213 perror("os_create_anonymous_file");
214 return NULL;
215 }
216
217 data = mmap(NULL, height * stride, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
218 if (data == MAP_FAILED) {
219 perror("mmap");
220 close(fd);
221 return NULL;
222 }
223
224 sb = zalloc(sizeof *sb);
225
226 sb->output = output;
227 wl_list_init(&sb->free_link);
228 wl_list_insert(&output->shm.buffers, &sb->link);
229
230 pixman_region32_init_rect(&sb->damage, 0, 0,
231 output->base.width, output->base.height);
232 sb->frame_damaged = 1;
233
234 sb->data = data;
235 sb->size = height * stride;
236
237 pool = wl_shm_create_pool(shm, fd, sb->size);
238
239 sb->buffer = wl_shm_pool_create_buffer(pool, 0,
240 width, height,
241 stride,
242 WL_SHM_FORMAT_ARGB8888);
243 wl_buffer_add_listener(sb->buffer, &buffer_listener, sb);
244 wl_shm_pool_destroy(pool);
245 close(fd);
246
247 memset(data, 0, sb->size);
248
249 sb->c_surface =
250 cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32,
251 width, height, stride);
252
253 fx = 0;
254 fy = 0;
255 if (output->frame)
256 frame_interior(output->frame, &fx, &fy, 0, 0);
257 sb->pm_image =
258 pixman_image_create_bits(PIXMAN_a8r8g8b8, width, height,
259 (uint32_t *)(data + fy * stride) + fx,
260 stride);
261
262 return sb;
263}
264
265static void
Kristian Høgsbergcdd61d02012-02-07 09:56:15 -0500266frame_done(void *data, struct wl_callback *callback, uint32_t time)
Kristian Høgsberg33418202011-08-16 23:01:28 -0400267{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500268 struct weston_output *output = data;
Kristian Høgsberg33418202011-08-16 23:01:28 -0400269
Kristian Høgsbergcdd61d02012-02-07 09:56:15 -0500270 wl_callback_destroy(callback);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500271 weston_output_finish_frame(output, time);
Kristian Høgsberg33418202011-08-16 23:01:28 -0400272}
273
274static const struct wl_callback_listener frame_listener = {
275 frame_done
276};
277
Kristian Høgsberg06cf6b02012-01-25 23:47:45 -0500278static void
Jonas Ådahle5a12252013-04-05 23:07:11 +0200279draw_initial_frame(struct wayland_output *output)
280{
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500281 struct wayland_shm_buffer *sb;
Jonas Ådahle5a12252013-04-05 23:07:11 +0200282
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500283 sb = wayland_output_get_shm_buffer(output);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200284
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500285 /* If we are rendering with GL, then orphan it so that it gets
286 * destroyed immediately */
287 if (output->gl.egl_window)
288 sb->output = NULL;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500289
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500290 wl_surface_attach(output->parent.surface, sb->buffer, 0, 0);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200291
292 /* We only need to damage some part, as its only transparant
293 * pixels anyway. */
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500294 wl_surface_damage(output->parent.surface, 0, 0, 1, 1);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200295}
296
297static void
Jason Ekstrand7744f712013-10-27 22:24:55 -0500298wayland_output_update_gl_border(struct wayland_output *output)
299{
300 int32_t ix, iy, iwidth, iheight, fwidth, fheight;
301 cairo_t *cr;
302
303 if (!output->frame)
304 return;
305 if (!(frame_status(output->frame) & FRAME_STATUS_REPAINT))
306 return;
307
308 fwidth = frame_width(output->frame);
309 fheight = frame_height(output->frame);
310 frame_interior(output->frame, &ix, &iy, &iwidth, &iheight);
311
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500312 if (!output->gl.border.top)
313 output->gl.border.top =
Jason Ekstrand7744f712013-10-27 22:24:55 -0500314 cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
315 fwidth, iy);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500316 cr = cairo_create(output->gl.border.top);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500317 frame_repaint(output->frame, cr);
318 cairo_destroy(cr);
319 gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_TOP,
320 fwidth, iy,
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500321 cairo_image_surface_get_stride(output->gl.border.top) / 4,
322 cairo_image_surface_get_data(output->gl.border.top));
Jason Ekstrand7744f712013-10-27 22:24:55 -0500323
324
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500325 if (!output->gl.border.left)
326 output->gl.border.left =
Jason Ekstrand7744f712013-10-27 22:24:55 -0500327 cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
328 ix, 1);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500329 cr = cairo_create(output->gl.border.left);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500330 cairo_translate(cr, 0, -iy);
331 frame_repaint(output->frame, cr);
332 cairo_destroy(cr);
333 gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_LEFT,
334 ix, 1,
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500335 cairo_image_surface_get_stride(output->gl.border.left) / 4,
336 cairo_image_surface_get_data(output->gl.border.left));
Jason Ekstrand7744f712013-10-27 22:24:55 -0500337
338
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500339 if (!output->gl.border.right)
340 output->gl.border.right =
Jason Ekstrand7744f712013-10-27 22:24:55 -0500341 cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
342 fwidth - (ix + iwidth), 1);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500343 cr = cairo_create(output->gl.border.right);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500344 cairo_translate(cr, -(iwidth + ix), -iy);
345 frame_repaint(output->frame, cr);
346 cairo_destroy(cr);
347 gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_RIGHT,
348 fwidth - (ix + iwidth), 1,
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500349 cairo_image_surface_get_stride(output->gl.border.right) / 4,
350 cairo_image_surface_get_data(output->gl.border.right));
Jason Ekstrand7744f712013-10-27 22:24:55 -0500351
352
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500353 if (!output->gl.border.bottom)
354 output->gl.border.bottom =
Jason Ekstrand7744f712013-10-27 22:24:55 -0500355 cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
356 fwidth, fheight - (iy + iheight));
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500357 cr = cairo_create(output->gl.border.bottom);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500358 cairo_translate(cr, 0, -(iy + iheight));
359 frame_repaint(output->frame, cr);
360 cairo_destroy(cr);
361 gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_BOTTOM,
362 fwidth, fheight - (iy + iheight),
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500363 cairo_image_surface_get_stride(output->gl.border.bottom) / 4,
364 cairo_image_surface_get_data(output->gl.border.bottom));
Jason Ekstrand7744f712013-10-27 22:24:55 -0500365}
366
367static void
Jonas Ådahle5a12252013-04-05 23:07:11 +0200368wayland_output_start_repaint_loop(struct weston_output *output_base)
369{
370 struct wayland_output *output = (struct wayland_output *) output_base;
Jason Ekstrand286ff682013-10-27 22:24:57 -0500371 struct wayland_compositor *wc =
372 (struct wayland_compositor *)output->base.compositor;
Jonas Ådahle5a12252013-04-05 23:07:11 +0200373 struct wl_callback *callback;
374
375 /* If this is the initial frame, we need to attach a buffer so that
376 * the compositor can map the surface and include it in its render
377 * loop. If the surface doesn't end up in the render loop, the frame
378 * callback won't be invoked. The buffer is transparent and of the
379 * same size as the future real output buffer. */
380 if (output->parent.draw_initial_frame) {
381 output->parent.draw_initial_frame = 0;
382
383 draw_initial_frame(output);
384 }
385
386 callback = wl_surface_frame(output->parent.surface);
387 wl_callback_add_listener(callback, &frame_listener, output);
388 wl_surface_commit(output->parent.surface);
Jason Ekstrand286ff682013-10-27 22:24:57 -0500389 wl_display_flush(wc->parent.wl_display);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200390}
391
David Herrmann1edf44c2013-10-22 17:11:26 +0200392static int
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500393wayland_output_repaint_gl(struct weston_output *output_base,
394 pixman_region32_t *damage)
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400395{
396 struct wayland_output *output = (struct wayland_output *) output_base;
Kristian Høgsbergfa1be022012-09-05 22:49:55 -0400397 struct weston_compositor *ec = output->base.compositor;
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400398 struct wl_callback *callback;
Scott Moreau062be7e2012-04-20 13:37:33 -0600399
Kristian Høgsberg33418202011-08-16 23:01:28 -0400400 callback = wl_surface_frame(output->parent.surface);
401 wl_callback_add_listener(callback, &frame_listener, output);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100402
Jason Ekstrand7744f712013-10-27 22:24:55 -0500403 wayland_output_update_gl_border(output);
404
Pekka Paalanenbc106382012-10-10 12:49:31 +0300405 ec->renderer->repaint_output(&output->base, damage);
Ander Conselvan de Oliveira0a887722012-11-22 15:57:00 +0200406
407 pixman_region32_subtract(&ec->primary_plane.damage,
408 &ec->primary_plane.damage, damage);
David Herrmann1edf44c2013-10-22 17:11:26 +0200409 return 0;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100410}
411
Matt Roper361d2ad2011-08-29 13:52:23 -0700412static void
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500413wayland_output_update_shm_border(struct wayland_shm_buffer *buffer)
414{
415 int32_t ix, iy, iwidth, iheight, fwidth, fheight;
416 cairo_t *cr;
417
418 if (!buffer->output->frame || !buffer->frame_damaged)
419 return;
420
421 cr = cairo_create(buffer->c_surface);
422
423 frame_interior(buffer->output->frame, &ix, &iy, &iwidth, &iheight);
424 fwidth = frame_width(buffer->output->frame);
425 fheight = frame_height(buffer->output->frame);
426
427 /* Set the clip so we don't unnecisaraly damage the surface */
428 cairo_move_to(cr, ix, iy);
429 cairo_rel_line_to(cr, iwidth, 0);
430 cairo_rel_line_to(cr, 0, iheight);
431 cairo_rel_line_to(cr, -iwidth, 0);
432 cairo_line_to(cr, ix, iy);
433 cairo_line_to(cr, 0, iy);
434 cairo_line_to(cr, 0, fheight);
435 cairo_line_to(cr, fwidth, fheight);
436 cairo_line_to(cr, fwidth, 0);
437 cairo_line_to(cr, 0, 0);
438 cairo_line_to(cr, 0, iy);
439 cairo_close_path(cr);
440 cairo_clip(cr);
441
442 /* Draw using a pattern so that the final result gets clipped */
443 cairo_push_group(cr);
444 frame_repaint(buffer->output->frame, cr);
445 cairo_pop_group_to_source(cr);
446 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
447 cairo_paint(cr);
448
449 cairo_destroy(cr);
450}
451
452static void
453wayland_shm_buffer_attach(struct wayland_shm_buffer *sb)
454{
455 pixman_region32_t damage;
456 pixman_box32_t *rects;
457 int32_t ix, iy, iwidth, iheight, fwidth, fheight;
458 int i, n;
459
460 if (sb->output->frame) {
461 frame_interior(sb->output->frame, &ix, &iy, &iwidth, &iheight);
462 fwidth = frame_width(sb->output->frame);
463 fheight = frame_height(sb->output->frame);
464
465 pixman_region32_init(&damage);
466 pixman_region32_copy(&damage, &sb->damage);
467 pixman_region32_translate(&damage, ix, iy);
468
469 if (sb->frame_damaged) {
470 pixman_region32_union_rect(&damage, &damage,
471 0, 0, fwidth, iy);
472 pixman_region32_union_rect(&damage, &damage,
473 0, iy, ix, iheight);
474 pixman_region32_union_rect(&damage, &damage,
475 ix + iwidth, iy,
476 fwidth - (ix + iwidth), iheight);
477 pixman_region32_union_rect(&damage, &damage,
478 0, iy + iheight,
479 fwidth, fheight - (iy + iheight));
480 }
481 rects = pixman_region32_rectangles(&damage, &n);
482 } else {
483 rects = pixman_region32_rectangles(&sb->damage, &n);
484 }
485
486 wl_surface_attach(sb->output->parent.surface, sb->buffer, 0, 0);
487 for (i = 0; i < n; ++i)
488 wl_surface_damage(sb->output->parent.surface, rects[i].x1,
489 rects[i].y1, rects[i].x2 - rects[i].x1,
490 rects[i].y2 - rects[i].y1);
491
492 if (sb->output->frame)
493 pixman_region32_fini(&damage);
494}
495
496static int
497wayland_output_repaint_pixman(struct weston_output *output_base,
498 pixman_region32_t *damage)
499{
500 struct wayland_output *output = (struct wayland_output *) output_base;
501 struct wayland_compositor *c =
502 (struct wayland_compositor *)output->base.compositor;
503 struct wl_callback *callback;
504 struct wayland_shm_buffer *sb;
505
506 if (output->frame) {
507 if (frame_status(output->frame) & FRAME_STATUS_REPAINT)
508 wl_list_for_each(sb, &output->shm.buffers, link)
509 sb->frame_damaged = 1;
510 }
511
512 wl_list_for_each(sb, &output->shm.buffers, link)
513 pixman_region32_union(&sb->damage, &sb->damage, damage);
514
515 sb = wayland_output_get_shm_buffer(output);
516
517 wayland_output_update_shm_border(sb);
518 pixman_renderer_output_set_buffer(output_base, sb->pm_image);
519 c->base.renderer->repaint_output(output_base, &sb->damage);
520
521 wayland_shm_buffer_attach(sb);
522
523 callback = wl_surface_frame(output->parent.surface);
524 wl_callback_add_listener(callback, &frame_listener, output);
525 wl_surface_commit(output->parent.surface);
526 wl_display_flush(c->parent.wl_display);
527
528 pixman_region32_fini(&sb->damage);
529 pixman_region32_init(&sb->damage);
530 sb->frame_damaged = 0;
531
532 pixman_region32_subtract(&c->base.primary_plane.damage,
533 &c->base.primary_plane.damage, damage);
534 return 0;
535}
536
537static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500538wayland_output_destroy(struct weston_output *output_base)
Matt Roper361d2ad2011-08-29 13:52:23 -0700539{
540 struct wayland_output *output = (struct wayland_output *) output_base;
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500541 struct wayland_compositor *c =
542 (struct wayland_compositor *) output->base.compositor;
Matt Roper361d2ad2011-08-29 13:52:23 -0700543
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500544 if (c->use_pixman) {
545 pixman_renderer_output_destroy(output_base);
546 } else {
547 gl_renderer->output_destroy(output_base);
548 }
John Kåre Alsaker94659272012-11-13 19:10:18 +0100549
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500550 wl_egl_window_destroy(output->gl.egl_window);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500551 wl_surface_destroy(output->parent.surface);
552 wl_shell_surface_destroy(output->parent.shell_surface);
553
554 if (output->frame) {
555 frame_destroy(output->frame);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500556 cairo_surface_destroy(output->gl.border.top);
557 cairo_surface_destroy(output->gl.border.left);
558 cairo_surface_destroy(output->gl.border.right);
559 cairo_surface_destroy(output->gl.border.bottom);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500560 }
561
562 weston_output_destroy(&output->base);
Matt Roper361d2ad2011-08-29 13:52:23 -0700563 free(output);
564
565 return;
566}
567
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +0300568static const struct wl_shell_surface_listener shell_surface_listener;
569
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200570static int
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500571wayland_output_init_gl_renderer(struct wayland_output *output)
572{
573 int32_t fx, fy, fwidth, fheight;
574
575 if (output->frame) {
576 fwidth = frame_width(output->frame);
577 fheight = frame_height(output->frame);
578 } else {
579 fwidth = output->base.width;
580 fheight = output->base.height;
581 }
582
583 output->gl.egl_window =
584 wl_egl_window_create(output->parent.surface,
585 fwidth, fheight);
586 if (!output->gl.egl_window) {
587 weston_log("failure to create wl_egl_window\n");
588 return -1;
589 }
590
591 if (gl_renderer->output_create(&output->base,
592 output->gl.egl_window) < 0)
593 goto cleanup_window;
594
595 if (output->frame) {
596 frame_interior(output->frame, &fx, &fy, NULL, NULL);
597 output->base.border.left = fx;
598 output->base.border.top = fy;
599 output->base.border.right = fwidth - output->base.width - fx;
600 output->base.border.bottom = fheight - output->base.height - fy;
601 }
602
603 return 0;
604
605cleanup_window:
606 wl_egl_window_destroy(output->gl.egl_window);
607 return -1;
608}
609
610static int
611wayland_output_init_pixman_renderer(struct wayland_output *output)
612{
613 return pixman_renderer_output_create(&output->base);
614}
615
616static int
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100617wayland_compositor_create_output(struct wayland_compositor *c,
618 int width, int height)
619{
620 struct wayland_output *output;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500621 int32_t fx, fy, fwidth, fheight;
622 struct wl_region *region;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100623
Peter Huttererf3d62272013-08-08 11:57:05 +1000624 output = zalloc(sizeof *output);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100625 if (output == NULL)
626 return -1;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100627
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400628 output->mode.flags =
629 WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
630 output->mode.width = width;
631 output->mode.height = height;
632 output->mode.refresh = 60;
633 wl_list_init(&output->base.mode_list);
634 wl_list_insert(&output->base.mode_list, &output->mode.link);
635
Hardeningff39efa2013-09-18 23:56:35 +0200636 output->base.current_mode = &output->mode;
Scott Moreau1bad5db2012-08-18 01:04:05 -0600637 weston_output_init(&output->base, &c->base, 0, 0, width, height,
Alexander Larsson4ea95522013-05-22 14:41:37 +0200638 WL_OUTPUT_TRANSFORM_NORMAL, 1);
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400639
Kristian Høgsberg90bc88c2012-08-13 23:34:04 -0400640 output->base.make = "waywayland";
641 output->base.model = "none";
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500642
643 weston_output_move(&output->base, 0, 0);
644
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500645 wl_list_init(&output->shm.buffers);
646 wl_list_init(&output->shm.free_buffers);
647
Jason Ekstrand7744f712013-10-27 22:24:55 -0500648 if (!c->theme)
649 c->theme = theme_create();
650 output->frame = frame_create(c->theme, width, height,
651 FRAME_BUTTON_CLOSE, "Weston");
652 frame_resize_inside(output->frame, width, height);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500653
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500654 weston_log("Creating %dx%d wayland output\n", width, height);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500655
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100656 output->parent.surface =
657 wl_compositor_create_surface(c->parent.compositor);
658 wl_surface_set_user_data(output->parent.surface, output);
659
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500660 if (c->use_pixman) {
661 if (wayland_output_init_pixman_renderer(output) < 0)
662 goto cleanup_output;
663 output->base.repaint = wayland_output_repaint_pixman;
664 } else {
665 if (wayland_output_init_gl_renderer(output) < 0)
666 goto cleanup_output;
667 output->base.repaint = wayland_output_repaint_gl;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100668 }
669
Jason Ekstrand7744f712013-10-27 22:24:55 -0500670 frame_input_rect(output->frame, &fx, &fy, &fwidth, &fheight);
671 region = wl_compositor_create_region(c->parent.compositor);
672 wl_region_add(region, fx, fy, fwidth, fheight);
673 wl_surface_set_input_region(output->parent.surface, region);
674 wl_region_destroy(region);
675
676 frame_opaque_rect(output->frame, &fx, &fy, &fwidth, &fheight);
677 region = wl_compositor_create_region(c->parent.compositor);
678 wl_region_add(region, fx, fy, fwidth, fheight);
679 wl_surface_set_opaque_region(output->parent.surface, region);
680 wl_region_destroy(region);
681
Jonas Ådahle5a12252013-04-05 23:07:11 +0200682 output->parent.draw_initial_frame = 1;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200683 output->parent.shell_surface =
684 wl_shell_get_shell_surface(c->parent.shell,
685 output->parent.surface);
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +0300686 wl_shell_surface_add_listener(output->parent.shell_surface,
687 &shell_surface_listener, output);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200688 wl_shell_surface_set_toplevel(output->parent.shell_surface);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100689
Jonas Ådahle5a12252013-04-05 23:07:11 +0200690 output->base.start_repaint_loop = wayland_output_start_repaint_loop;
Matt Roper361d2ad2011-08-29 13:52:23 -0700691 output->base.destroy = wayland_output_destroy;
Jesse Barnes5308a5e2012-02-09 13:12:57 -0800692 output->base.assign_planes = NULL;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +0200693 output->base.set_backlight = NULL;
694 output->base.set_dpms = NULL;
Alex Wu2dda6042012-04-17 17:20:47 +0800695 output->base.switch_mode = NULL;
Benjamin Franzkeeefc36c2011-03-11 16:39:20 +0100696
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100697 wl_list_insert(c->base.output_list.prev, &output->base.link);
698
699 return 0;
Benjamin Franzkebe014562011-02-18 17:04:24 +0100700
Benjamin Franzkebe014562011-02-18 17:04:24 +0100701cleanup_output:
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500702 /* FIXME: cleanup weston_output */
Benjamin Franzkebe014562011-02-18 17:04:24 +0100703 free(output);
704
705 return -1;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100706}
707
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +0300708static void
709shell_surface_ping(void *data, struct wl_shell_surface *shell_surface,
710 uint32_t serial)
711{
712 wl_shell_surface_pong(shell_surface, serial);
713}
714
715static void
716shell_surface_configure(void *data, struct wl_shell_surface *shell_surface,
717 uint32_t edges, int32_t width, int32_t height)
718{
719 /* FIXME: implement resizing */
720}
721
722static void
723shell_surface_popup_done(void *data, struct wl_shell_surface *shell_surface)
724{
725}
726
727static const struct wl_shell_surface_listener shell_surface_listener = {
728 shell_surface_ping,
729 shell_surface_configure,
730 shell_surface_popup_done
731};
732
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100733/* Events received from the wayland-server this compositor is client of: */
734
735/* parent output interface */
736static void
737display_handle_geometry(void *data,
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400738 struct wl_output *wl_output,
739 int x,
740 int y,
741 int physical_width,
742 int physical_height,
743 int subpixel,
744 const char *make,
Kristian Høgsberg0e696472012-07-22 15:49:57 -0400745 const char *model,
746 int transform)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100747{
748 struct wayland_compositor *c = data;
749
Kristian Høgsbergf8fc08f2010-12-01 20:10:10 -0500750 c->parent.screen_allocation.x = x;
751 c->parent.screen_allocation.y = y;
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400752}
753
754static void
755display_handle_mode(void *data,
756 struct wl_output *wl_output,
757 uint32_t flags,
758 int width,
759 int height,
760 int refresh)
761{
762 struct wayland_compositor *c = data;
763
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100764 c->parent.screen_allocation.width = width;
765 c->parent.screen_allocation.height = height;
766}
767
768static const struct wl_output_listener output_listener = {
769 display_handle_geometry,
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400770 display_handle_mode
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100771};
772
Jason Ekstrand7744f712013-10-27 22:24:55 -0500773/* parent input interface */
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400774static void
Jason Ekstrand7744f712013-10-27 22:24:55 -0500775input_set_cursor(struct wayland_input *input)
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400776{
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400777
Jason Ekstrand7744f712013-10-27 22:24:55 -0500778 struct wl_buffer *buffer;
779 struct wl_cursor_image *image;
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400780
Jason Ekstrand7744f712013-10-27 22:24:55 -0500781 if (!input->compositor->cursor)
782 return; /* Couldn't load the cursor. Can't set it */
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400783
Jason Ekstrand7744f712013-10-27 22:24:55 -0500784 image = input->compositor->cursor->images[0];
785 buffer = wl_cursor_image_get_buffer(image);
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400786
Jason Ekstrand7744f712013-10-27 22:24:55 -0500787
788 wl_pointer_set_cursor(input->parent.pointer, input->enter_serial,
789 input->parent.cursor.surface,
790 image->hotspot_x, image->hotspot_y);
791
792 wl_surface_attach(input->parent.cursor.surface, buffer, 0, 0);
793 wl_surface_damage(input->parent.cursor.surface, 0, 0,
794 image->width, image->height);
795 wl_surface_commit(input->parent.cursor.surface);
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400796}
797
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100798static void
Daniel Stone37816df2012-05-16 18:45:18 +0100799input_handle_pointer_enter(void *data, struct wl_pointer *pointer,
800 uint32_t serial, struct wl_surface *surface,
Kristian Høgsberge11bbe42012-05-09 12:19:04 -0400801 wl_fixed_t x, wl_fixed_t y)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100802{
803 struct wayland_input *input = data;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500804 int32_t fx, fy;
805 enum theme_location location;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100806
Daniel Stone50692802012-06-22 13:21:41 +0100807 /* XXX: If we get a modifier event immediately before the focus,
808 * we should try to keep the same serial. */
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400809 input->enter_serial = serial;
810 input->output = wl_surface_get_user_data(surface);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500811
812 if (input->output->frame) {
813 location = frame_pointer_enter(input->output->frame, input,
814 wl_fixed_to_int(x),
815 wl_fixed_to_int(y));
816 frame_interior(input->output->frame, &fx, &fy, NULL, NULL);
817 x -= wl_fixed_from_int(fx);
818 y -= wl_fixed_from_int(fy);
819
820 if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
821 weston_output_schedule_repaint(&input->output->base);
822 } else {
823 location = THEME_LOCATION_CLIENT_AREA;
824 }
825
826 x += wl_fixed_from_int(input->output->base.x);
827 y += wl_fixed_from_int(input->output->base.y);
828
829 if (location == THEME_LOCATION_CLIENT_AREA) {
830 input->focus = 1;
831 notify_pointer_focus(&input->base, &input->output->base, x, y);
832 wl_pointer_set_cursor(input->parent.pointer,
833 input->enter_serial, NULL, 0, 0);
834 } else {
835 input->focus = 0;
836 notify_pointer_focus(&input->base, NULL, 0, 0);
837 input_set_cursor(input);
838 }
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100839}
840
841static void
Daniel Stone37816df2012-05-16 18:45:18 +0100842input_handle_pointer_leave(void *data, struct wl_pointer *pointer,
843 uint32_t serial, struct wl_surface *surface)
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500844{
845 struct wayland_input *input = data;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500846
Jason Ekstrand7744f712013-10-27 22:24:55 -0500847 if (input->output->frame) {
848 frame_pointer_leave(input->output->frame, input);
849
850 if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
851 weston_output_schedule_repaint(&input->output->base);
852 }
853
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400854 notify_pointer_focus(&input->base, NULL, 0, 0);
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400855 input->output = NULL;
856 input->focus = 0;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500857}
858
859static void
Daniel Stone37816df2012-05-16 18:45:18 +0100860input_handle_motion(void *data, struct wl_pointer *pointer,
861 uint32_t time, wl_fixed_t x, wl_fixed_t y)
862{
863 struct wayland_input *input = data;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500864 int32_t fx, fy;
865 enum theme_location location;
Daniel Stone37816df2012-05-16 18:45:18 +0100866
Jason Ekstrand7744f712013-10-27 22:24:55 -0500867 if (input->output->frame) {
868 location = frame_pointer_motion(input->output->frame, input,
869 wl_fixed_to_int(x),
870 wl_fixed_to_int(y));
871 frame_interior(input->output->frame, &fx, &fy, NULL, NULL);
872 x -= wl_fixed_from_int(fx);
873 y -= wl_fixed_from_int(fy);
874
875 if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
876 weston_output_schedule_repaint(&input->output->base);
877 } else {
878 location = THEME_LOCATION_CLIENT_AREA;
879 }
880
881 x += wl_fixed_from_int(input->output->base.x);
882 y += wl_fixed_from_int(input->output->base.y);
883
884 if (input->focus && location != THEME_LOCATION_CLIENT_AREA) {
885 input_set_cursor(input);
886 notify_pointer_focus(&input->base, NULL, 0, 0);
887 input->focus = 0;
888 } else if (!input->focus && location == THEME_LOCATION_CLIENT_AREA) {
889 wl_pointer_set_cursor(input->parent.pointer,
890 input->enter_serial, NULL, 0, 0);
891 notify_pointer_focus(&input->base, &input->output->base, x, y);
892 input->focus = 1;
893 }
894
895 if (location == THEME_LOCATION_CLIENT_AREA)
896 notify_motion_absolute(&input->base, time, x, y);
Daniel Stone37816df2012-05-16 18:45:18 +0100897}
898
899static void
900input_handle_button(void *data, struct wl_pointer *pointer,
Daniel Stone4dbadb12012-05-30 16:31:51 +0100901 uint32_t serial, uint32_t time, uint32_t button,
902 uint32_t state_w)
Daniel Stone37816df2012-05-16 18:45:18 +0100903{
904 struct wayland_input *input = data;
Daniel Stone4dbadb12012-05-30 16:31:51 +0100905 enum wl_pointer_button_state state = state_w;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500906 enum frame_button_state fstate;
907 enum theme_location location;
Daniel Stone37816df2012-05-16 18:45:18 +0100908
Jason Ekstrand7744f712013-10-27 22:24:55 -0500909 if (input->output->frame) {
910 fstate = state == WL_POINTER_BUTTON_STATE_PRESSED ?
911 FRAME_BUTTON_PRESSED : FRAME_BUTTON_RELEASED;
912
913 location = frame_pointer_button(input->output->frame, input,
914 button, fstate);
915
916 if (frame_status(input->output->frame) & FRAME_STATUS_MOVE) {
917
918 wl_shell_surface_move(input->output->parent.shell_surface,
919 input->parent.seat, serial);
920 frame_status_clear(input->output->frame,
921 FRAME_STATUS_MOVE);
922 return;
923 }
924
925 if (frame_status(input->output->frame) & FRAME_STATUS_CLOSE)
926 wl_display_terminate(input->compositor->base.wl_display);
927
928 if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
929 weston_output_schedule_repaint(&input->output->base);
930 } else {
931 location = THEME_LOCATION_CLIENT_AREA;
932 }
933
934 if (location == THEME_LOCATION_CLIENT_AREA)
935 notify_button(&input->base, time, button, state);
Daniel Stone37816df2012-05-16 18:45:18 +0100936}
937
938static void
939input_handle_axis(void *data, struct wl_pointer *pointer,
Daniel Stone2fce4022012-05-30 16:32:00 +0100940 uint32_t time, uint32_t axis, wl_fixed_t value)
Daniel Stone37816df2012-05-16 18:45:18 +0100941{
942 struct wayland_input *input = data;
Daniel Stone37816df2012-05-16 18:45:18 +0100943
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400944 notify_axis(&input->base, time, axis, value);
Daniel Stone37816df2012-05-16 18:45:18 +0100945}
946
947static const struct wl_pointer_listener pointer_listener = {
948 input_handle_pointer_enter,
949 input_handle_pointer_leave,
950 input_handle_motion,
951 input_handle_button,
952 input_handle_axis,
953};
954
955static void
Daniel Stoneb7452fe2012-06-01 12:14:06 +0100956input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format,
957 int fd, uint32_t size)
958{
959 struct wayland_input *input = data;
960 struct xkb_keymap *keymap;
961 char *map_str;
962
963 if (!data) {
964 close(fd);
965 return;
966 }
967
968 if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
969 close(fd);
970 return;
971 }
972
973 map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
974 if (map_str == MAP_FAILED) {
975 close(fd);
976 return;
977 }
978
979 keymap = xkb_map_new_from_string(input->compositor->base.xkb_context,
980 map_str,
981 XKB_KEYMAP_FORMAT_TEXT_V1,
982 0);
983 munmap(map_str, size);
984 close(fd);
985
986 if (!keymap) {
Martin Minarik6d118362012-06-07 18:01:59 +0200987 weston_log("failed to compile keymap\n");
Daniel Stoneb7452fe2012-06-01 12:14:06 +0100988 return;
989 }
990
Rui Matos0c194ce2013-10-10 19:44:21 +0200991 if (input->base.keyboard)
992 weston_seat_update_keymap(&input->base, keymap);
993 else
994 weston_seat_init_keyboard(&input->base, keymap);
995
Daniel Stoneb7452fe2012-06-01 12:14:06 +0100996 xkb_map_unref(keymap);
997}
998
999static void
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001000input_handle_keyboard_enter(void *data,
Daniel Stone37816df2012-05-16 18:45:18 +01001001 struct wl_keyboard *keyboard,
1002 uint32_t serial,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001003 struct wl_surface *surface,
1004 struct wl_array *keys)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001005{
Kristian Høgsbergaf82bea2011-01-27 20:18:17 -05001006 struct wayland_input *input = data;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001007 struct wayland_output *focus;
1008
1009 focus = input->keyboard_focus;
1010 if (focus) {
1011 /* This shouldn't happen */
1012 focus->keyboard_count--;
1013 if (!focus->keyboard_count && focus->frame)
1014 frame_unset_flag(focus->frame, FRAME_FLAG_ACTIVE);
1015 if (frame_status(focus->frame) & FRAME_STATUS_REPAINT)
1016 weston_output_schedule_repaint(&focus->base);
1017 }
1018
1019 input->keyboard_focus = wl_surface_get_user_data(surface);
1020 input->keyboard_focus->keyboard_count++;
1021
1022 focus = input->keyboard_focus;
1023 if (focus->frame) {
1024 frame_set_flag(focus->frame, FRAME_FLAG_ACTIVE);
1025 if (frame_status(focus->frame) & FRAME_STATUS_REPAINT)
1026 weston_output_schedule_repaint(&focus->base);
1027 }
1028
Kristian Høgsbergaf82bea2011-01-27 20:18:17 -05001029
Daniel Stone50692802012-06-22 13:21:41 +01001030 /* XXX: If we get a modifier event immediately before the focus,
1031 * we should try to keep the same serial. */
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001032 notify_keyboard_focus_in(&input->base, keys,
Daniel Stoned6da09e2012-06-22 13:21:29 +01001033 STATE_UPDATE_AUTOMATIC);
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001034}
1035
1036static void
1037input_handle_keyboard_leave(void *data,
Daniel Stone37816df2012-05-16 18:45:18 +01001038 struct wl_keyboard *keyboard,
1039 uint32_t serial,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001040 struct wl_surface *surface)
1041{
1042 struct wayland_input *input = data;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001043 struct wayland_output *focus;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001044
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001045 notify_keyboard_focus_out(&input->base);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001046
1047 focus = input->keyboard_focus;
1048 if (!focus)
1049 return; /* This shouldn't happen */
1050
1051 focus->keyboard_count--;
1052 if (!focus->keyboard_count && focus->frame) {
1053 frame_unset_flag(focus->frame, FRAME_FLAG_ACTIVE);
1054 if (frame_status(focus->frame) & FRAME_STATUS_REPAINT)
1055 weston_output_schedule_repaint(&focus->base);
1056 }
1057
1058 input->keyboard_focus = NULL;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001059}
1060
Daniel Stone37816df2012-05-16 18:45:18 +01001061static void
1062input_handle_key(void *data, struct wl_keyboard *keyboard,
1063 uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
1064{
1065 struct wayland_input *input = data;
Daniel Stone37816df2012-05-16 18:45:18 +01001066
Daniel Stone50692802012-06-22 13:21:41 +01001067 input->key_serial = serial;
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001068 notify_key(&input->base, time, key,
Daniel Stonec9785ea2012-05-30 16:31:52 +01001069 state ? WL_KEYBOARD_KEY_STATE_PRESSED :
Daniel Stone1b4e11f2012-06-22 13:21:37 +01001070 WL_KEYBOARD_KEY_STATE_RELEASED,
Daniel Stone50692802012-06-22 13:21:41 +01001071 STATE_UPDATE_NONE);
Daniel Stone37816df2012-05-16 18:45:18 +01001072}
1073
Daniel Stone351eb612012-05-31 15:27:47 -04001074static void
1075input_handle_modifiers(void *data, struct wl_keyboard *keyboard,
Daniel Stone50692802012-06-22 13:21:41 +01001076 uint32_t serial_in, uint32_t mods_depressed,
Daniel Stone351eb612012-05-31 15:27:47 -04001077 uint32_t mods_latched, uint32_t mods_locked,
1078 uint32_t group)
1079{
Daniel Stone50692802012-06-22 13:21:41 +01001080 struct wayland_input *input = data;
1081 struct wayland_compositor *c = input->compositor;
1082 uint32_t serial_out;
1083
1084 /* If we get a key event followed by a modifier event with the
1085 * same serial number, then we try to preserve those semantics by
1086 * reusing the same serial number on the way out too. */
1087 if (serial_in == input->key_serial)
1088 serial_out = wl_display_get_serial(c->base.wl_display);
1089 else
1090 serial_out = wl_display_next_serial(c->base.wl_display);
1091
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -04001092 xkb_state_update_mask(input->base.xkb_state.state,
Daniel Stone50692802012-06-22 13:21:41 +01001093 mods_depressed, mods_latched,
1094 mods_locked, 0, 0, group);
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001095 notify_modifiers(&input->base, serial_out);
Daniel Stone351eb612012-05-31 15:27:47 -04001096}
1097
Daniel Stone37816df2012-05-16 18:45:18 +01001098static const struct wl_keyboard_listener keyboard_listener = {
Daniel Stoneb7452fe2012-06-01 12:14:06 +01001099 input_handle_keymap,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001100 input_handle_keyboard_enter,
1101 input_handle_keyboard_leave,
Daniel Stone37816df2012-05-16 18:45:18 +01001102 input_handle_key,
Daniel Stone351eb612012-05-31 15:27:47 -04001103 input_handle_modifiers,
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001104};
1105
1106static void
Daniel Stone37816df2012-05-16 18:45:18 +01001107input_handle_capabilities(void *data, struct wl_seat *seat,
1108 enum wl_seat_capability caps)
1109{
1110 struct wayland_input *input = data;
1111
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05001112 if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->parent.pointer) {
1113 input->parent.pointer = wl_seat_get_pointer(seat);
1114 wl_pointer_set_user_data(input->parent.pointer, input);
1115 wl_pointer_add_listener(input->parent.pointer,
1116 &pointer_listener, input);
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -04001117 weston_seat_init_pointer(&input->base);
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05001118 } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->parent.pointer) {
1119 wl_pointer_destroy(input->parent.pointer);
1120 input->parent.pointer = NULL;
Daniel Stone37816df2012-05-16 18:45:18 +01001121 }
1122
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05001123 if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->parent.keyboard) {
1124 input->parent.keyboard = wl_seat_get_keyboard(seat);
1125 wl_keyboard_set_user_data(input->parent.keyboard, input);
1126 wl_keyboard_add_listener(input->parent.keyboard,
1127 &keyboard_listener, input);
1128 } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->parent.keyboard) {
1129 wl_keyboard_destroy(input->parent.keyboard);
1130 input->parent.keyboard = NULL;
Daniel Stone37816df2012-05-16 18:45:18 +01001131 }
1132}
1133
1134static const struct wl_seat_listener seat_listener = {
1135 input_handle_capabilities,
1136};
1137
1138static void
1139display_add_seat(struct wayland_compositor *c, uint32_t id)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001140{
1141 struct wayland_input *input;
1142
Peter Huttererf3d62272013-08-08 11:57:05 +10001143 input = zalloc(sizeof *input);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001144 if (input == NULL)
1145 return;
1146
Rob Bradford9af5f9e2013-05-31 18:09:50 +01001147 weston_seat_init(&input->base, &c->base, "default");
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001148 input->compositor = c;
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05001149 input->parent.seat = wl_registry_bind(c->parent.registry, id,
1150 &wl_seat_interface, 1);
1151 wl_list_insert(c->inputs.prev, &input->link);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001152
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05001153 wl_seat_add_listener(input->parent.seat, &seat_listener, input);
1154 wl_seat_set_user_data(input->parent.seat, input);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001155
1156 input->parent.cursor.surface =
1157 wl_compositor_create_surface(c->parent.compositor);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001158}
1159
1160static void
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001161registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
1162 const char *interface, uint32_t version)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001163{
1164 struct wayland_compositor *c = data;
1165
Benjamin Franzke080ab6c2011-04-30 10:41:27 +02001166 if (strcmp(interface, "wl_compositor") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -04001167 c->parent.compositor =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001168 wl_registry_bind(registry, name,
1169 &wl_compositor_interface, 1);
Benjamin Franzke080ab6c2011-04-30 10:41:27 +02001170 } else if (strcmp(interface, "wl_output") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -04001171 c->parent.output =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001172 wl_registry_bind(registry, name,
1173 &wl_output_interface, 1);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001174 wl_output_add_listener(c->parent.output, &output_listener, c);
Benjamin Franzke080ab6c2011-04-30 10:41:27 +02001175 } else if (strcmp(interface, "wl_shell") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -04001176 c->parent.shell =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001177 wl_registry_bind(registry, name,
1178 &wl_shell_interface, 1);
Daniel Stone725c2c32012-06-22 14:04:36 +01001179 } else if (strcmp(interface, "wl_seat") == 0) {
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001180 display_add_seat(c, name);
Jonas Ådahle5a12252013-04-05 23:07:11 +02001181 } else if (strcmp(interface, "wl_shm") == 0) {
1182 c->parent.shm =
1183 wl_registry_bind(registry, name, &wl_shm_interface, 1);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001184 }
1185}
1186
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001187static const struct wl_registry_listener registry_listener = {
1188 registry_handle_global
1189};
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001190
Kristian Høgsberg95d843d2011-04-22 13:01:26 -04001191static int
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001192wayland_compositor_handle_event(int fd, uint32_t mask, void *data)
1193{
1194 struct wayland_compositor *c = data;
Kristian Høgsbergfeb3c1d2012-10-15 12:56:11 -04001195 int count = 0;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001196
Kristian Høgsberg453de7a2013-10-30 23:15:44 -07001197 if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) {
1198 wl_display_terminate(c->base.wl_display);
1199 return 0;
1200 }
1201
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001202 if (mask & WL_EVENT_READABLE)
Kristian Høgsbergfeb3c1d2012-10-15 12:56:11 -04001203 count = wl_display_dispatch(c->parent.wl_display);
Kristian Høgsbergf258a312011-12-28 22:51:20 -05001204 if (mask & WL_EVENT_WRITABLE)
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001205 wl_display_flush(c->parent.wl_display);
Kristian Høgsberg95d843d2011-04-22 13:01:26 -04001206
Kristian Høgsbergfeb3c1d2012-10-15 12:56:11 -04001207 if (mask == 0) {
1208 count = wl_display_dispatch_pending(c->parent.wl_display);
1209 wl_display_flush(c->parent.wl_display);
1210 }
1211
1212 return count;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001213}
1214
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05001215static void
Kristian Høgsberg7b884bc2012-07-31 14:32:01 -04001216wayland_restore(struct weston_compositor *ec)
1217{
1218}
1219
1220static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001221wayland_destroy(struct weston_compositor *ec)
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05001222{
Jonas Ådahle5a12252013-04-05 23:07:11 +02001223 struct wayland_compositor *c = (struct wayland_compositor *) ec;
1224
Vasily Khoruzhick52cfd612013-01-08 19:09:01 +03001225 ec->renderer->destroy(ec);
Kristian Høgsberg3a0de882012-09-06 21:44:24 -04001226
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001227 weston_compositor_shutdown(ec);
Matt Roper361d2ad2011-08-29 13:52:23 -07001228
Jonas Ådahle5a12252013-04-05 23:07:11 +02001229 if (c->parent.shm)
1230 wl_shm_destroy(c->parent.shm);
1231
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05001232 free(ec);
1233}
1234
Jason Ekstrand7744f712013-10-27 22:24:55 -05001235static const char *left_ptrs[] = {
1236 "left_ptr",
1237 "default",
1238 "top_left_arrow",
1239 "left-arrow"
1240};
1241
1242static void
1243create_cursor(struct wayland_compositor *c, struct weston_config *config)
1244{
1245 struct weston_config_section *s;
1246 int size;
1247 char *theme = NULL;
1248 unsigned int i;
1249
1250 s = weston_config_get_section(config, "shell", NULL, NULL);
1251 weston_config_section_get_string(s, "cursor-theme", &theme, NULL);
1252 weston_config_section_get_int(s, "cursor-size", &size, 32);
1253
1254 c->cursor_theme = wl_cursor_theme_load(theme, size, c->parent.shm);
1255
1256 c->cursor = NULL;
1257 for (i = 0; !c->cursor && i < ARRAY_LENGTH(left_ptrs); ++i)
1258 c->cursor = wl_cursor_theme_get_cursor(c->cursor_theme,
1259 left_ptrs[i]);
1260 if (!c->cursor) {
1261 fprintf(stderr, "could not load left cursor\n");
1262 return;
1263 }
1264}
1265
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001266static struct weston_compositor *
Jason Ekstrandff2fd462013-10-27 22:24:58 -05001267wayland_compositor_create(struct wl_display *display, int use_pixman,
Daniel Stonebaf43592012-06-01 11:11:10 -04001268 int width, int height, const char *display_name,
Kristian Høgsberg14e438c2013-05-26 21:48:14 -04001269 int *argc, char *argv[],
1270 struct weston_config *config)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001271{
1272 struct wayland_compositor *c;
1273 struct wl_event_loop *loop;
1274 int fd;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001275
Peter Huttererf3d62272013-08-08 11:57:05 +10001276 c = zalloc(sizeof *c);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001277 if (c == NULL)
1278 return NULL;
1279
Daniel Stone725c2c32012-06-22 14:04:36 +01001280 if (weston_compositor_init(&c->base, display, argc, argv,
Kristian Høgsberg14e438c2013-05-26 21:48:14 -04001281 config) < 0)
Martin Olssonc5db50f2012-07-08 03:03:43 +02001282 goto err_free;
Daniel Stone725c2c32012-06-22 14:04:36 +01001283
Kristian Høgsberg362b6722012-06-18 15:13:51 -04001284 c->parent.wl_display = wl_display_connect(display_name);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001285
Kristian Høgsberg362b6722012-06-18 15:13:51 -04001286 if (c->parent.wl_display == NULL) {
Martin Minarik6d118362012-06-07 18:01:59 +02001287 weston_log("failed to create display: %m\n");
Martin Olssonc5db50f2012-07-08 03:03:43 +02001288 goto err_compositor;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001289 }
1290
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05001291 wl_list_init(&c->inputs);
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001292 c->parent.registry = wl_display_get_registry(c->parent.wl_display);
1293 wl_registry_add_listener(c->parent.registry, &registry_listener, c);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001294 wl_display_roundtrip(c->parent.wl_display);
1295
1296 create_cursor(c, config);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001297
1298 c->base.wl_display = display;
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +03001299
1300 gl_renderer = weston_load_module("gl-renderer.so",
1301 "gl_renderer_interface");
1302 if (!gl_renderer)
1303 goto err_display;
1304
Jason Ekstrandff2fd462013-10-27 22:24:58 -05001305 c->use_pixman = use_pixman;
1306 if (!use_pixman) {
1307 if (gl_renderer->create(&c->base, c->parent.wl_display,
1308 gl_renderer->alpha_attribs,
1309 NULL) < 0) {
1310 weston_log("Failed to initialize the GL renderer; "
1311 "falling back to pixman.\n");
1312 c->use_pixman = 1;
1313 }
1314 }
1315
1316 if (c->use_pixman) {
1317 if (pixman_renderer_init(&c->base) < 0) {
1318 weston_log("Failed to initialize pixman renderer\n");
1319 goto err_display;
1320 }
1321 }
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001322
Benjamin Franzkeecfb2b92011-01-15 12:34:48 +01001323 c->base.destroy = wayland_destroy;
Kristian Høgsberg7b884bc2012-07-31 14:32:01 -04001324 c->base.restore = wayland_restore;
Benjamin Franzkeecfb2b92011-01-15 12:34:48 +01001325
John Kåre Alsakerb9b87122012-10-04 20:42:16 +02001326 /* requires border fields */
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001327 if (wayland_compositor_create_output(c, width, height) < 0)
John Kåre Alsaker779b52a2012-11-13 19:10:29 +01001328 goto err_gl;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001329
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001330 loop = wl_display_get_event_loop(c->base.wl_display);
1331
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001332 fd = wl_display_get_fd(c->parent.wl_display);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001333 c->parent.wl_source =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001334 wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001335 wayland_compositor_handle_event, c);
1336 if (c->parent.wl_source == NULL)
John Kåre Alsaker779b52a2012-11-13 19:10:29 +01001337 goto err_gl;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001338
Kristian Høgsbergfeb3c1d2012-10-15 12:56:11 -04001339 wl_event_source_check(c->parent.wl_source);
1340
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001341 return &c->base;
Martin Olssonc5db50f2012-07-08 03:03:43 +02001342
John Kåre Alsaker779b52a2012-11-13 19:10:29 +01001343err_gl:
Vasily Khoruzhick52cfd612013-01-08 19:09:01 +03001344 c->base.renderer->destroy(&c->base);
Martin Olssonc5db50f2012-07-08 03:03:43 +02001345err_display:
1346 wl_display_disconnect(c->parent.wl_display);
1347err_compositor:
1348 weston_compositor_shutdown(&c->base);
1349err_free:
1350 free(c);
1351 return NULL;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001352}
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001353
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001354WL_EXPORT struct weston_compositor *
Kristian Høgsberg4172f662013-02-20 15:27:49 -05001355backend_init(struct wl_display *display, int *argc, char *argv[],
Kristian Høgsberg14e438c2013-05-26 21:48:14 -04001356 struct weston_config *config)
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001357{
Kristian Høgsbergbcacef12012-03-11 21:05:57 -04001358 int width = 1024, height = 640;
1359 char *display_name = NULL;
Jason Ekstrandff2fd462013-10-27 22:24:58 -05001360 int use_pixman = 0;
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001361
Kristian Høgsbergbcacef12012-03-11 21:05:57 -04001362 const struct weston_option wayland_options[] = {
1363 { WESTON_OPTION_INTEGER, "width", 0, &width },
1364 { WESTON_OPTION_INTEGER, "height", 0, &height },
1365 { WESTON_OPTION_STRING, "display", 0, &display_name },
Jason Ekstrandff2fd462013-10-27 22:24:58 -05001366 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
Kristian Høgsbergbcacef12012-03-11 21:05:57 -04001367 };
1368
1369 parse_options(wayland_options,
1370 ARRAY_LENGTH(wayland_options), argc, argv);
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001371
Jason Ekstrandff2fd462013-10-27 22:24:58 -05001372 return wayland_compositor_create(display, use_pixman, width, height,
1373 display_name, argc, argv, config);
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001374}