2 * Copyright © 2014 Jason Ekstrand
3 * Copyright © 2011 Benjamin Franzke
4 * Copyright © 2010 Intel Corporation
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
39 #include <wayland-client.h>
40 #include "shared/os-compatibility.h"
41 #include "shared/zalloc.h"
42 #include "xdg-shell-unstable-v6-client-protocol.h"
43 #include "fullscreen-shell-unstable-v1-client-protocol.h"
44 #include "viewporter-client-protocol.h"
49 struct wl_display *display;
50 struct wl_registry *registry;
51 int compositor_version;
52 struct wl_compositor *compositor;
53 struct wp_viewporter *viewporter;
54 struct zxdg_shell_v6 *shell;
55 struct zwp_fullscreen_shell_v1 *fshell;
61 struct wl_buffer *buffer;
67 WINDOW_FLAG_USE_VIEWPORT = 0x1,
68 WINDOW_FLAG_ROTATING_TRANSFORM = 0x2,
69 WINDOW_FLAG_USE_DAMAGE_BUFFER = 0x4,
73 struct display *display;
74 int width, height, border;
75 struct wl_surface *surface;
76 struct wp_viewport *viewport;
77 struct zxdg_surface_v6 *xdg_surface;
78 struct zxdg_toplevel_v6 *xdg_toplevel;
79 struct wl_callback *callback;
80 struct buffer buffers[2];
81 struct buffer *prev_buffer;
82 bool wait_for_configure;
84 enum window_flags flags;
86 enum wl_output_transform transform;
89 float x, y; /* position in pixels */
90 float dx, dy; /* velocity in pixels/second */
91 int radius; /* radius in pixels */
96 static int running = 1;
99 redraw(void *data, struct wl_callback *callback, uint32_t time);
102 buffer_release(void *data, struct wl_buffer *buffer)
104 struct buffer *mybuf = data;
109 static const struct wl_buffer_listener buffer_listener = {
114 create_shm_buffer(struct display *display, struct buffer *buffer,
115 int width, int height, uint32_t format)
117 struct wl_shm_pool *pool;
122 size = pitch * height;
124 fd = os_create_anonymous_file(size);
126 fprintf(stderr, "creating a buffer file for %d B failed: %m\n",
131 data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
132 if (data == MAP_FAILED) {
133 fprintf(stderr, "mmap failed: %m\n");
138 pool = wl_shm_create_pool(display->shm, fd, size);
139 buffer->buffer = wl_shm_pool_create_buffer(pool, 0,
142 wl_buffer_add_listener(buffer->buffer, &buffer_listener, buffer);
143 wl_shm_pool_destroy(pool);
146 buffer->shm_data = data;
152 xdg_surface_handle_configure(void *data, struct zxdg_surface_v6 *surface,
155 struct window *window = data;
157 zxdg_surface_v6_ack_configure(surface, serial);
159 if (window->wait_for_configure) {
160 redraw(window, NULL, 0);
161 window->wait_for_configure = false;
165 static const struct zxdg_surface_v6_listener xdg_surface_listener = {
166 xdg_surface_handle_configure,
170 xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *toplevel,
171 int32_t width, int32_t height,
172 struct wl_array *states)
177 xdg_toplevel_handle_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel)
182 static const struct zxdg_toplevel_v6_listener xdg_toplevel_listener = {
183 xdg_toplevel_handle_configure,
184 xdg_toplevel_handle_close,
188 bounded_randf(float a, float b)
190 return a + ((float)rand() / (float)RAND_MAX) * (b - a);
194 window_init_game(struct window *window)
196 int ax1, ay1, ax2, ay2; /* playable arena size */
199 gettimeofday(&tv, NULL);
202 window->ball.radius = 10;
204 ax1 = window->border + window->ball.radius;
205 ay1 = window->border + window->ball.radius;
206 ax2 = window->width - window->border - window->ball.radius;
207 ay2 = window->height - window->border - window->ball.radius;
209 window->ball.x = bounded_randf(ax1, ax2);
210 window->ball.y = bounded_randf(ay1, ay2);
212 window->ball.dx = bounded_randf(0, window->width);
213 window->ball.dy = bounded_randf(0, window->height);
215 window->ball.prev_time = 0;
219 window_advance_game(struct window *window, uint32_t timestamp)
221 int ax1, ay1, ax2, ay2; /* Arena size */
224 if (window->ball.prev_time == 0) {
225 /* first pass, don't do anything */
226 window->ball.prev_time = timestamp;
231 dt = (float)(timestamp - window->ball.prev_time) / 1000.0f;
233 ax1 = window->border + window->ball.radius;
234 ay1 = window->border + window->ball.radius;
235 ax2 = window->width - window->border - window->ball.radius;
236 ay2 = window->height - window->border - window->ball.radius;
238 window->ball.x += window->ball.dx * dt;
239 while (window->ball.x < ax1 || ax2 < window->ball.x) {
240 if (window->ball.x < ax1)
241 window->ball.x = 2 * ax1 - window->ball.x;
242 if (ax2 <= window->ball.x)
243 window->ball.x = 2 * ax2 - window->ball.x;
245 window->ball.dx *= -1.0f;
248 window->ball.y += window->ball.dy * dt;
249 while (window->ball.y < ay1 || ay2 < window->ball.y) {
250 if (window->ball.y < ay1)
251 window->ball.y = 2 * ay1 - window->ball.y;
252 if (ay2 <= window->ball.y)
253 window->ball.y = 2 * ay2 - window->ball.y;
255 window->ball.dy *= -1.0f;
258 window->ball.prev_time = timestamp;
261 static struct window *
262 create_window(struct display *display, int width, int height,
263 enum wl_output_transform transform, int scale,
264 enum window_flags flags)
266 struct window *window;
268 if (display->compositor_version < 2 &&
269 (transform != WL_OUTPUT_TRANSFORM_NORMAL ||
270 flags & WINDOW_FLAG_ROTATING_TRANSFORM)) {
271 fprintf(stderr, "wl_surface.buffer_transform unsupported in "
272 "wl_surface version %d\n",
273 display->compositor_version);
277 if (display->compositor_version < 3 &&
278 (! (flags & WINDOW_FLAG_USE_VIEWPORT)) && scale != 1) {
279 fprintf(stderr, "wl_surface.buffer_scale unsupported in "
280 "wl_surface version %d\n",
281 display->compositor_version);
285 if (display->viewporter == NULL && (flags & WINDOW_FLAG_USE_VIEWPORT)) {
286 fprintf(stderr, "Compositor does not support wp_viewport");
290 if (display->compositor_version <
291 WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION &&
292 (flags & WINDOW_FLAG_USE_DAMAGE_BUFFER)) {
293 fprintf(stderr, "wl_surface.damage_buffer unsupported in "
294 "wl_surface version %d\n",
295 display->compositor_version);
299 window = zalloc(sizeof *window);
303 window->callback = NULL;
304 window->display = display;
305 window->width = width;
306 window->height = height;
308 window->flags = flags;
309 window->transform = transform;
310 window->scale = scale;
312 window_init_game(window);
314 window->surface = wl_compositor_create_surface(display->compositor);
316 if (window->flags & WINDOW_FLAG_USE_VIEWPORT)
317 window->viewport = wp_viewporter_get_viewport(display->viewporter,
320 if (display->shell) {
321 window->xdg_surface =
322 zxdg_shell_v6_get_xdg_surface(display->shell,
325 assert(window->xdg_surface);
327 zxdg_surface_v6_add_listener(window->xdg_surface,
328 &xdg_surface_listener, window);
330 window->xdg_toplevel =
331 zxdg_surface_v6_get_toplevel(window->xdg_surface);
333 assert(window->xdg_toplevel);
335 zxdg_toplevel_v6_add_listener(window->xdg_toplevel,
336 &xdg_toplevel_listener, window);
338 zxdg_toplevel_v6_set_title(window->xdg_toplevel, "simple-damage");
340 window->wait_for_configure = true;
341 wl_surface_commit(window->surface);
342 } else if (display->fshell) {
343 zwp_fullscreen_shell_v1_present_surface(display->fshell,
345 ZWP_FULLSCREEN_SHELL_V1_PRESENT_METHOD_DEFAULT,
351 /* Initialise damage to full surface, so the padding gets painted */
352 if (window->flags & WINDOW_FLAG_USE_DAMAGE_BUFFER) {
353 wl_surface_damage_buffer(window->surface, 0, 0,
354 INT32_MAX, INT32_MAX);
356 wl_surface_damage(window->surface, 0, 0, INT32_MAX, INT32_MAX);
362 destroy_window(struct window *window)
364 if (window->callback)
365 wl_callback_destroy(window->callback);
367 if (window->buffers[0].buffer)
368 wl_buffer_destroy(window->buffers[0].buffer);
369 if (window->buffers[1].buffer)
370 wl_buffer_destroy(window->buffers[1].buffer);
372 if (window->xdg_toplevel)
373 zxdg_toplevel_v6_destroy(window->xdg_toplevel);
374 if (window->xdg_surface)
375 zxdg_surface_v6_destroy(window->xdg_surface);
376 if (window->viewport)
377 wp_viewport_destroy(window->viewport);
378 wl_surface_destroy(window->surface);
382 static struct buffer *
383 window_next_buffer(struct window *window)
385 struct buffer *buffer;
386 int ret = 0, bwidth, bheight;
388 if (!window->buffers[0].busy)
389 buffer = &window->buffers[0];
390 else if (!window->buffers[1].busy)
391 buffer = &window->buffers[1];
395 switch (window->transform) {
397 case WL_OUTPUT_TRANSFORM_NORMAL:
398 case WL_OUTPUT_TRANSFORM_180:
399 case WL_OUTPUT_TRANSFORM_FLIPPED:
400 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
401 bwidth = window->width * window->scale;
402 bheight = window->height * window->scale;
404 case WL_OUTPUT_TRANSFORM_90:
405 case WL_OUTPUT_TRANSFORM_270:
406 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
407 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
408 bwidth = window->height * window->scale;
409 bheight = window->width * window->scale;
413 if (!buffer->buffer) {
414 ret = create_shm_buffer(window->display, buffer,
416 WL_SHM_FORMAT_ARGB8888);
426 paint_box(uint32_t *pixels, int pitch, int x, int y, int width, int height,
431 for (j = y; j < y + height; ++j)
432 for (i = x; i < x + width; ++i)
433 pixels[i + j * pitch] = color;
437 paint_circle(uint32_t *pixels, int pitch, float x, float y, int radius,
442 for (j = y - radius; j <= (int)(y + radius); ++j)
443 for (i = x - radius; i <= (int)(x + radius); ++i)
444 if ((j+0.5f-y)*(j+0.5f-y) + (i+0.5f-x)*(i+0.5f-x) <= radius * radius)
445 pixels[i + j * pitch] = color;
449 window_get_transformed_ball(struct window *window, float *bx, float *by)
456 switch (window->transform) {
458 case WL_OUTPUT_TRANSFORM_NORMAL:
462 case WL_OUTPUT_TRANSFORM_90:
463 *bx = window->height - wy;
466 case WL_OUTPUT_TRANSFORM_180:
467 *bx = window->width - wx;
468 *by = window->height - wy;
470 case WL_OUTPUT_TRANSFORM_270:
472 *by = window->width - wx;
474 case WL_OUTPUT_TRANSFORM_FLIPPED:
475 *bx = window->width - wx;
478 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
479 *bx = window->height - wy;
480 *by = window->width - wx;
482 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
484 *by = window->height - wy;
486 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
492 *bx *= window->scale;
493 *by *= window->scale;
495 if (window->viewport) {
496 /* We're drawing half-size because of the viewport */
502 static const struct wl_callback_listener frame_listener;
505 redraw(void *data, struct wl_callback *callback, uint32_t time)
507 struct window *window = data;
508 struct buffer *buffer;
509 int off_x = 0, off_y = 0;
510 int bwidth, bheight, bborder, bpitch, bradius;
513 buffer = window_next_buffer(window);
516 !callback ? "Failed to create the first buffer.\n" :
517 "Both buffers busy at redraw(). Server bug?\n");
521 /* Rotate the damage, but keep the even/odd parity so the
522 * dimensions of the buffers don't change */
523 if (window->flags & WINDOW_FLAG_ROTATING_TRANSFORM)
524 window->transform = (window->transform + 2) % 8;
526 switch (window->transform) {
528 case WL_OUTPUT_TRANSFORM_NORMAL:
529 case WL_OUTPUT_TRANSFORM_180:
530 case WL_OUTPUT_TRANSFORM_FLIPPED:
531 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
532 bwidth = window->width * window->scale;
533 bheight = window->height * window->scale;
535 case WL_OUTPUT_TRANSFORM_90:
536 case WL_OUTPUT_TRANSFORM_270:
537 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
538 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
539 bwidth = window->height * window->scale;
540 bheight = window->width * window->scale;
546 bborder = window->border * window->scale;
547 bradius = window->ball.radius * window->scale;
549 if (window->viewport) {
551 /* Fill the whole thing with red to detect viewport errors */
552 paint_box(buffer->shm_data, bpitch, 0, 0, bwidth, bheight,
555 /* The buffer is the same size. However, we crop it
556 * and scale it up by a factor of 2 */
562 /* Offset the drawing region */
563 tx = (window->width / 3) * window->scale;
564 ty = (window->height / 5) * window->scale;
565 switch (window->transform) {
567 case WL_OUTPUT_TRANSFORM_NORMAL:
571 case WL_OUTPUT_TRANSFORM_90:
575 case WL_OUTPUT_TRANSFORM_180:
576 off_y = bheight - ty;
579 case WL_OUTPUT_TRANSFORM_270:
580 off_y = bheight - tx;
583 case WL_OUTPUT_TRANSFORM_FLIPPED:
587 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
588 off_y = bheight - tx;
591 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
592 off_y = bheight - ty;
595 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
600 wp_viewport_set_source(window->viewport,
601 wl_fixed_from_int(window->width / 3),
602 wl_fixed_from_int(window->height / 5),
603 wl_fixed_from_int(window->width / 2),
604 wl_fixed_from_int(window->height / 2));
607 /* Paint the border */
608 paint_box(buffer->shm_data, bpitch, off_x, off_y,
609 bwidth, bborder, 0xffffffff);
610 paint_box(buffer->shm_data, bpitch, off_x, off_y,
611 bborder, bheight, 0xffffffff);
612 paint_box(buffer->shm_data, bpitch, off_x + bwidth - bborder, off_y,
613 bborder, bheight, 0xffffffff);
614 paint_box(buffer->shm_data, bpitch, off_x, off_y + bheight - bborder,
615 bwidth, bborder, 0xffffffff);
617 /* fill with translucent */
618 paint_box(buffer->shm_data, bpitch, off_x + bborder, off_y + bborder,
619 bwidth - 2 * bborder, bheight - 2 * bborder, 0x80000000);
621 /* Damage where the ball was */
622 if (window->flags & WINDOW_FLAG_USE_DAMAGE_BUFFER) {
623 window_get_transformed_ball(window, &bx, &by);
624 wl_surface_damage_buffer(window->surface,
625 bx - bradius + off_x,
626 by - bradius + off_y,
630 wl_surface_damage(window->surface,
631 window->ball.x - window->ball.radius,
632 window->ball.y - window->ball.radius,
633 window->ball.radius * 2 + 1,
634 window->ball.radius * 2 + 1);
636 window_advance_game(window, time);
638 window_get_transformed_ball(window, &bx, &by);
641 paint_circle(buffer->shm_data, bpitch, off_x + bx, off_y + by,
642 bradius, 0xff00ff00);
645 printf("Ball now located at (%f, %f)\n",
646 window->ball.x, window->ball.y);
648 printf("Circle painted at (%f, %f), radius %d\n", bx, by,
651 printf("Buffer damage rectangle: (%d, %d) @ %dx%d\n",
652 (int)(bx - bradius) + off_x,
653 (int)(by - bradius) + off_y,
654 bradius * 2 + 1, bradius * 2 + 1);
657 /* Damage where the ball is now */
658 if (window->flags & WINDOW_FLAG_USE_DAMAGE_BUFFER) {
659 wl_surface_damage_buffer(window->surface,
660 bx - bradius + off_x,
661 by - bradius + off_y,
665 wl_surface_damage(window->surface,
666 window->ball.x - window->ball.radius,
667 window->ball.y - window->ball.radius,
668 window->ball.radius * 2 + 1,
669 window->ball.radius * 2 + 1);
671 wl_surface_attach(window->surface, buffer->buffer, 0, 0);
673 if (window->display->compositor_version >= 2 &&
674 (window->transform != WL_OUTPUT_TRANSFORM_NORMAL ||
675 window->flags & WINDOW_FLAG_ROTATING_TRANSFORM))
676 wl_surface_set_buffer_transform(window->surface,
679 if (window->viewport)
680 wp_viewport_set_destination(window->viewport,
684 if (window->scale != 1)
685 wl_surface_set_buffer_scale(window->surface,
689 wl_callback_destroy(callback);
691 window->callback = wl_surface_frame(window->surface);
692 wl_callback_add_listener(window->callback, &frame_listener, window);
693 wl_surface_commit(window->surface);
697 static const struct wl_callback_listener frame_listener = {
702 shm_format(void *data, struct wl_shm *wl_shm, uint32_t format)
704 struct display *d = data;
706 d->formats |= (1 << format);
709 struct wl_shm_listener shm_listener = {
714 xdg_shell_ping(void *data, struct zxdg_shell_v6*shell, uint32_t serial)
716 zxdg_shell_v6_pong(shell, serial);
719 static const struct zxdg_shell_v6_listener xdg_shell_listener = {
724 registry_handle_global(void *data, struct wl_registry *registry,
725 uint32_t id, const char *interface, uint32_t version)
727 struct display *d = data;
729 if (strcmp(interface, "wl_compositor") == 0) {
730 if (d->compositor_version > (int)version) {
731 fprintf(stderr, "Compositor does not support "
732 "wl_surface version %d\n", d->compositor_version);
736 if (d->compositor_version < 0)
737 d->compositor_version = version;
740 wl_registry_bind(registry,
741 id, &wl_compositor_interface,
742 d->compositor_version);
743 } else if (strcmp(interface, "wp_viewporter") == 0) {
744 d->viewporter = wl_registry_bind(registry, id,
745 &wp_viewporter_interface, 1);
746 } else if (strcmp(interface, "zxdg_shell_v6") == 0) {
747 d->shell = wl_registry_bind(registry,
748 id, &zxdg_shell_v6_interface, 1);
749 zxdg_shell_v6_add_listener(d->shell, &xdg_shell_listener, d);
750 } else if (strcmp(interface, "zwp_fullscreen_shell_v1") == 0) {
751 d->fshell = wl_registry_bind(registry,
752 id, &zwp_fullscreen_shell_v1_interface, 1);
753 } else if (strcmp(interface, "wl_shm") == 0) {
754 d->shm = wl_registry_bind(registry,
755 id, &wl_shm_interface, 1);
756 wl_shm_add_listener(d->shm, &shm_listener, d);
761 registry_handle_global_remove(void *data, struct wl_registry *registry,
766 static const struct wl_registry_listener registry_listener = {
767 registry_handle_global,
768 registry_handle_global_remove
771 static struct display *
772 create_display(int version)
774 struct display *display;
776 display = malloc(sizeof *display);
777 if (display == NULL) {
778 fprintf(stderr, "out of memory\n");
781 display->display = wl_display_connect(NULL);
782 assert(display->display);
784 display->compositor_version = version;
785 display->formats = 0;
786 display->registry = wl_display_get_registry(display->display);
787 wl_registry_add_listener(display->registry,
788 ®istry_listener, display);
789 wl_display_roundtrip(display->display);
790 if (display->shm == NULL) {
791 fprintf(stderr, "No wl_shm global\n");
795 wl_display_roundtrip(display->display);
797 if (!(display->formats & (1 << WL_SHM_FORMAT_XRGB8888))) {
798 fprintf(stderr, "WL_SHM_FORMAT_XRGB32 not available\n");
806 destroy_display(struct display *display)
809 wl_shm_destroy(display->shm);
812 zxdg_shell_v6_destroy(display->shell);
815 zwp_fullscreen_shell_v1_release(display->fshell);
817 if (display->viewporter)
818 wp_viewporter_destroy(display->viewporter);
820 if (display->compositor)
821 wl_compositor_destroy(display->compositor);
823 wl_registry_destroy(display->registry);
824 wl_display_flush(display->display);
825 wl_display_disconnect(display->display);
830 signal_int(int signum)
836 print_usage(int retval)
839 "usage: weston-simple-damage [options]\n\n"
841 " -h, --help\t\tPring this help\n"
842 " --verbose\t\tPrint verbose log information\n"
843 " --version=VERSION\tVersion of wl_surface to use\n"
844 " --width=WIDTH\t\tWidth of the window\n"
845 " --height=HEIGHT\tHeight of the window\n"
846 " --scale=SCALE\t\tScale factor for the surface\n"
847 " --transform=TRANSFORM\tTransform for the surface\n"
848 " --rotating-transform\tUse a different buffer_transform for each frame\n"
849 " --use-viewport\tUse wp_viewport\n"
850 " --use-damage-buffer\tUse damage_buffer to post damage\n"
857 parse_transform(const char *str, enum wl_output_transform *transform)
860 static const struct {
862 enum wl_output_transform transform;
864 { "normal", WL_OUTPUT_TRANSFORM_NORMAL },
865 { "90", WL_OUTPUT_TRANSFORM_90 },
866 { "180", WL_OUTPUT_TRANSFORM_180 },
867 { "270", WL_OUTPUT_TRANSFORM_270 },
868 { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED },
869 { "flipped-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 },
870 { "flipped-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 },
871 { "flipped-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 },
874 for (i = 0; i < 8; i++) {
875 if (strcmp(names[i].name, str) == 0) {
876 *transform = names[i].transform;
885 main(int argc, char **argv)
887 struct sigaction sigint;
888 struct display *display;
889 struct window *window;
892 int width = 300, height = 200, scale = 1;
893 enum wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
894 enum window_flags flags = 0;
896 for (i = 1; i < argc; ++i) {
897 if (strcmp(argv[i], "--help") == 0 ||
898 strcmp(argv[i], "-h") == 0) {
900 } else if (sscanf(argv[i], "--version=%d", &version) > 0) {
901 if (version < 1 || version > 4) {
902 fprintf(stderr, "Unsupported wl_surface version: %d\n",
907 } else if (strcmp(argv[i], "--verbose") == 0) {
910 } else if (sscanf(argv[i], "--width=%d", &width) > 0) {
912 } else if (sscanf(argv[i], "--height=%d", &height) > 0) {
914 } else if (strncmp(argv[i], "--transform=", 12) == 0 &&
915 parse_transform(argv[i] + 12, &transform) > 0) {
917 } else if (strcmp(argv[i], "--rotating-transform") == 0) {
918 flags |= WINDOW_FLAG_ROTATING_TRANSFORM;
920 } else if (sscanf(argv[i], "--scale=%d", &scale) > 0) {
922 } else if (strcmp(argv[i], "--use-viewport") == 0) {
923 flags |= WINDOW_FLAG_USE_VIEWPORT;
925 } else if (strcmp(argv[i], "--use-damage-buffer") == 0) {
926 flags |= WINDOW_FLAG_USE_DAMAGE_BUFFER;
929 printf("Invalid option: %s\n", argv[i]);
934 display = create_display(version);
936 window = create_window(display, width, height, transform, scale, flags);
940 sigint.sa_handler = signal_int;
941 sigemptyset(&sigint.sa_mask);
942 sigint.sa_flags = SA_RESETHAND;
943 sigaction(SIGINT, &sigint, NULL);
945 if (!window->wait_for_configure)
946 redraw(window, NULL, 0);
948 while (running && ret != -1)
949 ret = wl_display_dispatch(display->display);
951 fprintf(stderr, "simple-shm exiting\n");
952 destroy_window(window);
953 destroy_display(display);