blob: ec5f1cb7d337c9cf2c81da80fbc468b7b7cef36d [file] [log] [blame]
George Kiagiadakis53868982014-06-12 16:26:49 +02001/*
2 * Copyright © 2011 Benjamin Franzke
3 * Copyright © 2010 Intel Corporation
4 * Copyright © 2014 Collabora Ltd.
5 *
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that copyright
9 * notice and this permission notice appear in supporting documentation, and
10 * that the name of the copyright holders not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. The copyright holders make no representations
13 * about the suitability of this software for any purpose. It is provided "as
14 * is" without express or implied warranty.
15 *
16 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 * OF THIS SOFTWARE.
23 */
24
Bryce Harringtonb4dae9b2016-06-15 18:13:07 -070025#include "config.h"
George Kiagiadakis53868982014-06-12 16:26:49 +020026
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030027#include <stdint.h>
George Kiagiadakis53868982014-06-12 16:26:49 +020028#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#include <stdbool.h>
32#include <assert.h>
33#include <unistd.h>
34#include <sys/mman.h>
35#include <signal.h>
36#include <fcntl.h>
37
38#include <xf86drm.h>
Emmanuel Gil Peyrot8ef29572016-01-11 19:04:37 +000039#include <i915_drm.h>
40#include <intel_bufmgr.h>
41#include <drm_fourcc.h>
George Kiagiadakis53868982014-06-12 16:26:49 +020042
43#include <wayland-client.h>
Bryce Harrington0d1a6222016-02-11 16:42:49 -080044#include "shared/zalloc.h"
Jonas Ådahl42682622016-08-11 23:44:41 +080045#include "xdg-shell-unstable-v6-client-protocol.h"
Jonas Ådahl496adb32015-11-17 16:00:27 +080046#include "fullscreen-shell-unstable-v1-client-protocol.h"
Jonas Ådahl57e48f02015-11-17 16:00:28 +080047#include "linux-dmabuf-unstable-v1-client-protocol.h"
George Kiagiadakis53868982014-06-12 16:26:49 +020048
49struct display {
50 struct wl_display *display;
51 struct wl_registry *registry;
52 struct wl_compositor *compositor;
Jonas Ådahl42682622016-08-11 23:44:41 +080053 struct zxdg_shell_v6 *shell;
Jonas Ådahl496adb32015-11-17 16:00:27 +080054 struct zwp_fullscreen_shell_v1 *fshell;
Jonas Ådahl57e48f02015-11-17 16:00:28 +080055 struct zwp_linux_dmabuf_v1 *dmabuf;
George Kiagiadakis53868982014-06-12 16:26:49 +020056 int xrgb8888_format_found;
57};
58
59struct buffer {
60 struct wl_buffer *buffer;
61 int busy;
62
63 int drm_fd;
64
65 drm_intel_bufmgr *bufmgr;
66 drm_intel_bo *bo;
67
68 uint32_t gem_handle;
69 int dmabuf_fd;
70 uint8_t *mmap;
71
72 int width;
73 int height;
74 int bpp;
75 unsigned long stride;
76};
77
Pekka Paalanend56b94a2016-06-10 13:13:01 +030078#define NUM_BUFFERS 3
79
George Kiagiadakis53868982014-06-12 16:26:49 +020080struct window {
81 struct display *display;
82 int width, height;
83 struct wl_surface *surface;
Jonas Ådahl42682622016-08-11 23:44:41 +080084 struct zxdg_surface_v6 *xdg_surface;
85 struct zxdg_toplevel_v6 *xdg_toplevel;
Pekka Paalanend56b94a2016-06-10 13:13:01 +030086 struct buffer buffers[NUM_BUFFERS];
George Kiagiadakis53868982014-06-12 16:26:49 +020087 struct buffer *prev_buffer;
88 struct wl_callback *callback;
Jonas Ådahl42682622016-08-11 23:44:41 +080089 bool initialized;
90 bool wait_for_configure;
George Kiagiadakis53868982014-06-12 16:26:49 +020091};
92
93static int running = 1;
94
95static void
Jonas Ådahl42682622016-08-11 23:44:41 +080096redraw(void *data, struct wl_callback *callback, uint32_t time);
97
98static void
George Kiagiadakis53868982014-06-12 16:26:49 +020099buffer_release(void *data, struct wl_buffer *buffer)
100{
101 struct buffer *mybuf = data;
102
103 mybuf->busy = 0;
104}
105
106static const struct wl_buffer_listener buffer_listener = {
107 buffer_release
108};
109
110static int
111drm_connect(struct buffer *my_buf)
112{
113 /* This won't work with card0 as we need to be authenticated; instead,
114 * boot with drm.rnodes=1 and use that. */
115 my_buf->drm_fd = open("/dev/dri/renderD128", O_RDWR);
116 if (my_buf->drm_fd < 0)
117 return 0;
118
119 my_buf->bufmgr = drm_intel_bufmgr_gem_init(my_buf->drm_fd, 32);
120 if (!my_buf->bufmgr)
121 return 0;
122
123 return 1;
124}
125
126static void
127drm_shutdown(struct buffer *my_buf)
128{
129 drm_intel_bufmgr_destroy(my_buf->bufmgr);
130 close(my_buf->drm_fd);
131}
132
133static int
134alloc_bo(struct buffer *my_buf)
135{
136 /* XXX: try different tiling modes for testing FB modifiers. */
137 uint32_t tiling = I915_TILING_NONE;
138
139 assert(my_buf->bufmgr);
140
141 my_buf->bo = drm_intel_bo_alloc_tiled(my_buf->bufmgr, "test",
142 my_buf->width, my_buf->height,
143 (my_buf->bpp / 8), &tiling,
144 &my_buf->stride, 0);
145
146 printf("buffer allocated w %d, h %d, stride %lu, size %lu\n",
147 my_buf->width, my_buf->height, my_buf->stride, my_buf->bo->size);
148
149 if (!my_buf->bo)
150 return 0;
151
152 if (tiling != I915_TILING_NONE)
153 return 0;
154
155 return 1;
156}
157
158static void
159free_bo(struct buffer *my_buf)
160{
161 drm_intel_bo_unreference(my_buf->bo);
162}
163
164static int
165map_bo(struct buffer *my_buf)
166{
167 if (drm_intel_gem_bo_map_gtt(my_buf->bo) != 0)
168 return 0;
169
170 my_buf->mmap = my_buf->bo->virtual;
171
172 return 1;
173}
174
175static void
176fill_content(struct buffer *my_buf)
177{
178 int x = 0, y = 0;
179 uint32_t *pix;
180
181 assert(my_buf->mmap);
182
183 for (y = 0; y < my_buf->height; y++) {
184 pix = (uint32_t *)(my_buf->mmap + y * my_buf->stride);
185 for (x = 0; x < my_buf->width; x++) {
186 *pix++ = (0xff << 24) | ((x % 256) << 16) |
187 ((y % 256) << 8) | 0xf0;
188 }
189 }
190}
191
192static void
193unmap_bo(struct buffer *my_buf)
194{
195 drm_intel_gem_bo_unmap_gtt(my_buf->bo);
196}
197
198static void
199create_succeeded(void *data,
Jonas Ådahl57e48f02015-11-17 16:00:28 +0800200 struct zwp_linux_buffer_params_v1 *params,
George Kiagiadakis53868982014-06-12 16:26:49 +0200201 struct wl_buffer *new_buffer)
202{
203 struct buffer *buffer = data;
204
205 buffer->buffer = new_buffer;
206 wl_buffer_add_listener(buffer->buffer, &buffer_listener, buffer);
207
Jonas Ådahl57e48f02015-11-17 16:00:28 +0800208 zwp_linux_buffer_params_v1_destroy(params);
George Kiagiadakis53868982014-06-12 16:26:49 +0200209}
210
211static void
Jonas Ådahl57e48f02015-11-17 16:00:28 +0800212create_failed(void *data, struct zwp_linux_buffer_params_v1 *params)
George Kiagiadakis53868982014-06-12 16:26:49 +0200213{
214 struct buffer *buffer = data;
215
216 buffer->buffer = NULL;
Emmanuel Gil Peyrot8ef29572016-01-11 19:04:37 +0000217 running = 0;
George Kiagiadakis53868982014-06-12 16:26:49 +0200218
Jonas Ådahl57e48f02015-11-17 16:00:28 +0800219 zwp_linux_buffer_params_v1_destroy(params);
George Kiagiadakis53868982014-06-12 16:26:49 +0200220
Jonas Ådahl57e48f02015-11-17 16:00:28 +0800221 fprintf(stderr, "Error: zwp_linux_buffer_params.create failed.\n");
George Kiagiadakis53868982014-06-12 16:26:49 +0200222}
223
Jonas Ådahl57e48f02015-11-17 16:00:28 +0800224static const struct zwp_linux_buffer_params_v1_listener params_listener = {
George Kiagiadakis53868982014-06-12 16:26:49 +0200225 create_succeeded,
226 create_failed
227};
228
229static int
230create_dmabuf_buffer(struct display *display, struct buffer *buffer,
231 int width, int height)
232{
Jonas Ådahl57e48f02015-11-17 16:00:28 +0800233 struct zwp_linux_buffer_params_v1 *params;
George Kiagiadakis53868982014-06-12 16:26:49 +0200234 uint64_t modifier;
235 uint32_t flags;
236
237 if (!drm_connect(buffer)) {
238 fprintf(stderr, "drm_connect failed\n");
239 goto error;
240 }
241
242 buffer->width = width;
243 buffer->height = height;
244 buffer->bpp = 32; /* hardcoded XRGB8888 format */
245
246 if (!alloc_bo(buffer)) {
247 fprintf(stderr, "alloc_bo failed\n");
248 goto error1;
249 }
250
251 if (!map_bo(buffer)) {
252 fprintf(stderr, "map_bo failed\n");
253 goto error2;
254 }
255 fill_content(buffer);
256 unmap_bo(buffer);
257
258 if (drm_intel_bo_gem_export_to_prime(buffer->bo, &buffer->dmabuf_fd) != 0) {
259 fprintf(stderr, "drm_intel_bo_gem_export_to_prime failed\n");
260 goto error2;
261 }
262 if (buffer->dmabuf_fd < 0) {
263 fprintf(stderr, "error: dmabuf_fd < 0\n");
264 goto error2;
265 }
266
267 /* We now have a dmabuf! It should contain 2x2 tiles (i.e. each tile
268 * is 256x256) of misc colours, and be mappable, either as ARGB8888, or
269 * XRGB8888. */
270 modifier = 0;
271 flags = 0;
272
Jonas Ådahl57e48f02015-11-17 16:00:28 +0800273 params = zwp_linux_dmabuf_v1_create_params(display->dmabuf);
274 zwp_linux_buffer_params_v1_add(params,
275 buffer->dmabuf_fd,
276 0, /* plane_idx */
277 0, /* offset */
278 buffer->stride,
279 modifier >> 32,
280 modifier & 0xffffffff);
281 zwp_linux_buffer_params_v1_add_listener(params, &params_listener, buffer);
282 zwp_linux_buffer_params_v1_create(params,
283 buffer->width,
284 buffer->height,
285 DRM_FORMAT_XRGB8888,
286 flags);
George Kiagiadakis53868982014-06-12 16:26:49 +0200287
George Kiagiadakis53868982014-06-12 16:26:49 +0200288 return 0;
289
290error2:
291 free_bo(buffer);
292error1:
293 drm_shutdown(buffer);
294error:
295 return -1;
296}
297
298static void
Jonas Ådahl42682622016-08-11 23:44:41 +0800299xdg_surface_handle_configure(void *data, struct zxdg_surface_v6 *surface,
300 uint32_t serial)
301{
302 struct window *window = data;
303
304 zxdg_surface_v6_ack_configure(surface, serial);
305
306 if (window->initialized && window->wait_for_configure)
307 redraw(window, NULL, 0);
308 window->wait_for_configure = false;
309}
310
311static const struct zxdg_surface_v6_listener xdg_surface_listener = {
312 xdg_surface_handle_configure,
313};
314
315static void
316xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *toplevel,
317 int32_t width, int32_t height,
318 struct wl_array *states)
George Kiagiadakis53868982014-06-12 16:26:49 +0200319{
320}
321
322static void
Jonas Ådahl42682622016-08-11 23:44:41 +0800323xdg_toplevel_handle_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel)
George Kiagiadakis53868982014-06-12 16:26:49 +0200324{
325 running = 0;
326}
327
Jonas Ådahl42682622016-08-11 23:44:41 +0800328static const struct zxdg_toplevel_v6_listener xdg_toplevel_listener = {
329 xdg_toplevel_handle_configure,
330 xdg_toplevel_handle_close,
George Kiagiadakis53868982014-06-12 16:26:49 +0200331};
332
333static struct window *
334create_window(struct display *display, int width, int height)
335{
336 struct window *window;
Emmanuel Gil Peyrot8ef29572016-01-11 19:04:37 +0000337 int i;
338 int ret;
George Kiagiadakis53868982014-06-12 16:26:49 +0200339
Bryce Harrington0d1a6222016-02-11 16:42:49 -0800340 window = zalloc(sizeof *window);
George Kiagiadakis53868982014-06-12 16:26:49 +0200341 if (!window)
342 return NULL;
343
344 window->callback = NULL;
345 window->display = display;
346 window->width = width;
347 window->height = height;
348 window->surface = wl_compositor_create_surface(display->compositor);
349
350 if (display->shell) {
351 window->xdg_surface =
Jonas Ådahl42682622016-08-11 23:44:41 +0800352 zxdg_shell_v6_get_xdg_surface(display->shell,
353 window->surface);
George Kiagiadakis53868982014-06-12 16:26:49 +0200354
355 assert(window->xdg_surface);
356
Jonas Ådahl42682622016-08-11 23:44:41 +0800357 zxdg_surface_v6_add_listener(window->xdg_surface,
358 &xdg_surface_listener, window);
George Kiagiadakis53868982014-06-12 16:26:49 +0200359
Jonas Ådahl42682622016-08-11 23:44:41 +0800360 window->xdg_toplevel =
361 zxdg_surface_v6_get_toplevel(window->xdg_surface);
362
363 assert(window->xdg_toplevel);
364
365 zxdg_toplevel_v6_add_listener(window->xdg_toplevel,
366 &xdg_toplevel_listener, window);
367
368 zxdg_toplevel_v6_set_title(window->xdg_toplevel, "simple-dmabuf");
369
370 window->wait_for_configure = true;
371 wl_surface_commit(window->surface);
George Kiagiadakis53868982014-06-12 16:26:49 +0200372 } else if (display->fshell) {
Jonas Ådahl496adb32015-11-17 16:00:27 +0800373 zwp_fullscreen_shell_v1_present_surface(display->fshell,
374 window->surface,
375 ZWP_FULLSCREEN_SHELL_V1_PRESENT_METHOD_DEFAULT,
376 NULL);
George Kiagiadakis53868982014-06-12 16:26:49 +0200377 } else {
378 assert(0);
379 }
380
Pekka Paalanend56b94a2016-06-10 13:13:01 +0300381 for (i = 0; i < NUM_BUFFERS; ++i) {
Emmanuel Gil Peyrot8ef29572016-01-11 19:04:37 +0000382 ret = create_dmabuf_buffer(display, &window->buffers[i],
383 width, height);
384
385 if (ret < 0)
386 return NULL;
387 }
388
George Kiagiadakis53868982014-06-12 16:26:49 +0200389 return window;
390}
391
392static void
393destroy_window(struct window *window)
394{
395 int i;
396
397 if (window->callback)
398 wl_callback_destroy(window->callback);
399
Pekka Paalanend56b94a2016-06-10 13:13:01 +0300400 for (i = 0; i < NUM_BUFFERS; i++) {
George Kiagiadakis53868982014-06-12 16:26:49 +0200401 if (!window->buffers[i].buffer)
402 continue;
403
404 wl_buffer_destroy(window->buffers[i].buffer);
405 free_bo(&window->buffers[i]);
406 close(window->buffers[i].dmabuf_fd);
407 drm_shutdown(&window->buffers[i]);
408 }
409
Jonas Ådahl42682622016-08-11 23:44:41 +0800410 if (window->xdg_toplevel)
411 zxdg_toplevel_v6_destroy(window->xdg_toplevel);
George Kiagiadakis53868982014-06-12 16:26:49 +0200412 if (window->xdg_surface)
Jonas Ådahl42682622016-08-11 23:44:41 +0800413 zxdg_surface_v6_destroy(window->xdg_surface);
George Kiagiadakis53868982014-06-12 16:26:49 +0200414 wl_surface_destroy(window->surface);
415 free(window);
416}
417
418static struct buffer *
419window_next_buffer(struct window *window)
420{
Pekka Paalanend56b94a2016-06-10 13:13:01 +0300421 int i;
George Kiagiadakis53868982014-06-12 16:26:49 +0200422
Pekka Paalanend56b94a2016-06-10 13:13:01 +0300423 for (i = 0; i < NUM_BUFFERS; i++)
424 if (!window->buffers[i].busy)
425 return &window->buffers[i];
George Kiagiadakis53868982014-06-12 16:26:49 +0200426
Pekka Paalanend56b94a2016-06-10 13:13:01 +0300427 return NULL;
George Kiagiadakis53868982014-06-12 16:26:49 +0200428}
429
430static const struct wl_callback_listener frame_listener;
431
432static void
433redraw(void *data, struct wl_callback *callback, uint32_t time)
434{
435 struct window *window = data;
436 struct buffer *buffer;
437
438 buffer = window_next_buffer(window);
439 if (!buffer) {
440 fprintf(stderr,
441 !callback ? "Failed to create the first buffer.\n" :
Pekka Paalanend56b94a2016-06-10 13:13:01 +0300442 "All buffers busy at redraw(). Server bug?\n");
George Kiagiadakis53868982014-06-12 16:26:49 +0200443 abort();
444 }
445
446 /* XXX: would be nice to draw something that changes here... */
447
448 wl_surface_attach(window->surface, buffer->buffer, 0, 0);
449 wl_surface_damage(window->surface, 0, 0, window->width, window->height);
450
451 if (callback)
452 wl_callback_destroy(callback);
453
454 window->callback = wl_surface_frame(window->surface);
455 wl_callback_add_listener(window->callback, &frame_listener, window);
456 wl_surface_commit(window->surface);
457 buffer->busy = 1;
458}
459
460static const struct wl_callback_listener frame_listener = {
461 redraw
462};
463
464static void
Jonas Ådahl57e48f02015-11-17 16:00:28 +0800465dmabuf_format(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf, uint32_t format)
George Kiagiadakis53868982014-06-12 16:26:49 +0200466{
467 struct display *d = data;
468
469 if (format == DRM_FORMAT_XRGB8888)
470 d->xrgb8888_format_found = 1;
471}
472
Jonas Ådahl57e48f02015-11-17 16:00:28 +0800473static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener = {
George Kiagiadakis53868982014-06-12 16:26:49 +0200474 dmabuf_format
475};
476
477static void
Jonas Ådahl42682622016-08-11 23:44:41 +0800478xdg_shell_ping(void *data, struct zxdg_shell_v6 *shell, uint32_t serial)
George Kiagiadakis53868982014-06-12 16:26:49 +0200479{
Jonas Ådahl42682622016-08-11 23:44:41 +0800480 zxdg_shell_v6_pong(shell, serial);
George Kiagiadakis53868982014-06-12 16:26:49 +0200481}
482
Jonas Ådahl42682622016-08-11 23:44:41 +0800483static const struct zxdg_shell_v6_listener xdg_shell_listener = {
George Kiagiadakis53868982014-06-12 16:26:49 +0200484 xdg_shell_ping,
485};
486
George Kiagiadakis53868982014-06-12 16:26:49 +0200487static void
488registry_handle_global(void *data, struct wl_registry *registry,
489 uint32_t id, const char *interface, uint32_t version)
490{
491 struct display *d = data;
492
493 if (strcmp(interface, "wl_compositor") == 0) {
494 d->compositor =
495 wl_registry_bind(registry,
496 id, &wl_compositor_interface, 1);
Jonas Ådahl42682622016-08-11 23:44:41 +0800497 } else if (strcmp(interface, "zxdg_shell_v6") == 0) {
George Kiagiadakis53868982014-06-12 16:26:49 +0200498 d->shell = wl_registry_bind(registry,
Jonas Ådahl42682622016-08-11 23:44:41 +0800499 id, &zxdg_shell_v6_interface, 1);
500 zxdg_shell_v6_add_listener(d->shell, &xdg_shell_listener, d);
Jonas Ådahl496adb32015-11-17 16:00:27 +0800501 } else if (strcmp(interface, "zwp_fullscreen_shell_v1") == 0) {
George Kiagiadakis53868982014-06-12 16:26:49 +0200502 d->fshell = wl_registry_bind(registry,
Jonas Ådahl496adb32015-11-17 16:00:27 +0800503 id, &zwp_fullscreen_shell_v1_interface, 1);
Jonas Ådahl57e48f02015-11-17 16:00:28 +0800504 } else if (strcmp(interface, "zwp_linux_dmabuf_v1") == 0) {
George Kiagiadakis53868982014-06-12 16:26:49 +0200505 d->dmabuf = wl_registry_bind(registry,
Jonas Ådahl57e48f02015-11-17 16:00:28 +0800506 id, &zwp_linux_dmabuf_v1_interface, 1);
507 zwp_linux_dmabuf_v1_add_listener(d->dmabuf, &dmabuf_listener, d);
George Kiagiadakis53868982014-06-12 16:26:49 +0200508 }
509}
510
511static void
512registry_handle_global_remove(void *data, struct wl_registry *registry,
513 uint32_t name)
514{
515}
516
517static const struct wl_registry_listener registry_listener = {
518 registry_handle_global,
519 registry_handle_global_remove
520};
521
522static struct display *
523create_display(void)
524{
525 struct display *display;
526
527 display = malloc(sizeof *display);
528 if (display == NULL) {
529 fprintf(stderr, "out of memory\n");
530 exit(1);
531 }
532 display->display = wl_display_connect(NULL);
533 assert(display->display);
534
535 /* XXX: fake, because the compositor does not yet advertise anything */
536 display->xrgb8888_format_found = 1;
537
538 display->registry = wl_display_get_registry(display->display);
539 wl_registry_add_listener(display->registry,
540 &registry_listener, display);
541 wl_display_roundtrip(display->display);
542 if (display->dmabuf == NULL) {
Jonas Ådahl57e48f02015-11-17 16:00:28 +0800543 fprintf(stderr, "No zwp_linux_dmabuf global\n");
George Kiagiadakis53868982014-06-12 16:26:49 +0200544 exit(1);
545 }
546
547 wl_display_roundtrip(display->display);
548
549 if (!display->xrgb8888_format_found) {
550 fprintf(stderr, "DRM_FORMAT_XRGB8888 not available\n");
551 exit(1);
552 }
553
554 return display;
555}
556
557static void
558destroy_display(struct display *display)
559{
560 if (display->dmabuf)
Jonas Ådahl57e48f02015-11-17 16:00:28 +0800561 zwp_linux_dmabuf_v1_destroy(display->dmabuf);
George Kiagiadakis53868982014-06-12 16:26:49 +0200562
563 if (display->shell)
Jonas Ådahl42682622016-08-11 23:44:41 +0800564 zxdg_shell_v6_destroy(display->shell);
George Kiagiadakis53868982014-06-12 16:26:49 +0200565
566 if (display->fshell)
Jonas Ådahl496adb32015-11-17 16:00:27 +0800567 zwp_fullscreen_shell_v1_release(display->fshell);
George Kiagiadakis53868982014-06-12 16:26:49 +0200568
569 if (display->compositor)
570 wl_compositor_destroy(display->compositor);
571
572 wl_registry_destroy(display->registry);
573 wl_display_flush(display->display);
574 wl_display_disconnect(display->display);
575 free(display);
576}
577
578static void
579signal_int(int signum)
580{
581 running = 0;
582}
583
584int
585main(int argc, char **argv)
586{
587 struct sigaction sigint;
588 struct display *display;
589 struct window *window;
590 int ret = 0;
591
592 display = create_display();
593 window = create_window(display, 250, 250);
594 if (!window)
595 return 1;
596
597 sigint.sa_handler = signal_int;
598 sigemptyset(&sigint.sa_mask);
599 sigint.sa_flags = SA_RESETHAND;
600 sigaction(SIGINT, &sigint, NULL);
601
Emmanuel Gil Peyrot8ef29572016-01-11 19:04:37 +0000602 /* Here we retrieve the linux-dmabuf objects, or error */
603 wl_display_roundtrip(display->display);
604
605 if (!running)
606 return 1;
George Kiagiadakis53868982014-06-12 16:26:49 +0200607
Jonas Ådahl42682622016-08-11 23:44:41 +0800608 window->initialized = true;
609
610 if (!window->wait_for_configure)
611 redraw(window, NULL, 0);
George Kiagiadakis53868982014-06-12 16:26:49 +0200612
613 while (running && ret != -1)
614 ret = wl_display_dispatch(display->display);
615
616 fprintf(stderr, "simple-dmabuf exiting\n");
617 destroy_window(window);
618 destroy_display(display);
619
620 return 0;
621}