blob: 3f7ff2b9f5007b39bd9db4fd76a8ee8dbb17ad23 [file] [log] [blame]
U. Artie Eoff1ba9b382012-12-07 13:50:32 -08001/*
2 * Copyright © 2012 Intel Corporation
3 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080011 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080024 */
25
Bryce Harrington12cc4052014-11-19 17:18:33 -080026#include "config.h"
Kristian Høgsbergc7d2c4c2013-08-26 14:43:17 -070027
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080028#include <stdlib.h>
29#include <stdio.h>
30#include <string.h>
31#include <unistd.h>
Marek Chalupa4d06d462014-07-16 11:27:06 +020032#include <errno.h>
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080033#include <sys/mman.h>
Bryce Harrington892122e2015-09-24 14:31:44 -070034#include <cairo.h>
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080035
Jon Cruz4678bab2015-06-15 15:37:07 -070036#include "shared/os-compatibility.h"
Bryce Harringtone99e4bf2016-03-16 14:15:18 -070037#include "shared/xalloc.h"
38#include "shared/zalloc.h"
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080039#include "weston-test-client-helper.h"
40
Bryce Harrington273c2852014-12-15 15:51:25 -080041#define max(a, b) (((a) > (b)) ? (a) : (b))
42#define min(a, b) (((a) > (b)) ? (b) : (a))
43#define clip(x, a, b) min(max(x, a), b)
44
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080045int
46surface_contains(struct surface *surface, int x, int y)
47{
48 /* test whether a global x,y point is contained in the surface */
49 int sx = surface->x;
50 int sy = surface->y;
51 int sw = surface->width;
52 int sh = surface->height;
53 return x >= sx && y >= sy && x < sx + sw && y < sy + sh;
54}
55
Kristian Høgsbergdb6dc7d2012-12-11 21:49:13 -050056static void
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +020057frame_callback_handler(void *data, struct wl_callback *callback, uint32_t time)
Kristian Høgsbergdb6dc7d2012-12-11 21:49:13 -050058{
59 int *done = data;
60
61 *done = 1;
62
63 wl_callback_destroy(callback);
64}
65
66static const struct wl_callback_listener frame_listener = {
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +020067 frame_callback_handler
Kristian Høgsbergdb6dc7d2012-12-11 21:49:13 -050068};
69
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +020070struct wl_callback *
71frame_callback_set(struct wl_surface *surface, int *done)
72{
73 struct wl_callback *callback;
74
75 *done = 0;
76 callback = wl_surface_frame(surface);
77 wl_callback_add_listener(callback, &frame_listener, done);
78
79 return callback;
80}
81
Marek Chalupa1740aa82014-07-16 11:32:50 +020082int
83frame_callback_wait_nofail(struct client *client, int *done)
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +020084{
85 while (!*done) {
Marek Chalupa1740aa82014-07-16 11:32:50 +020086 if (wl_display_dispatch(client->wl_display) < 0)
87 return 0;
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +020088 }
Marek Chalupa1740aa82014-07-16 11:32:50 +020089
90 return 1;
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +020091}
92
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080093void
94move_client(struct client *client, int x, int y)
95{
96 struct surface *surface = client->surface;
Kristian Høgsbergdb6dc7d2012-12-11 21:49:13 -050097 int done;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080098
99 client->surface->x = x;
100 client->surface->y = y;
Derek Foremanf6a65922015-02-24 09:32:14 -0600101 weston_test_move_surface(client->test->weston_test, surface->wl_surface,
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800102 surface->x, surface->y);
Bryce Harringtoncb50ed22014-12-10 18:33:47 -0800103 /* The attach here is necessary because commit() will call configure
Giulio Camuffo82cb5052013-02-28 18:44:54 +0100104 * only on surfaces newly attached, and the one that sets the surface
105 * position is the configure. */
106 wl_surface_attach(surface->wl_surface, surface->wl_buffer, 0, 0);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800107 wl_surface_damage(surface->wl_surface, 0, 0, surface->width,
108 surface->height);
Kristian Høgsbergdb6dc7d2012-12-11 21:49:13 -0500109
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200110 frame_callback_set(surface->wl_surface, &done);
Kristian Høgsbergdb6dc7d2012-12-11 21:49:13 -0500111
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800112 wl_surface_commit(surface->wl_surface);
113
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200114 frame_callback_wait(client, &done);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800115}
116
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000117int
118get_n_egl_buffers(struct client *client)
119{
120 client->test->n_egl_buffers = -1;
121
Derek Foremanf6a65922015-02-24 09:32:14 -0600122 weston_test_get_n_egl_buffers(client->test->weston_test);
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000123 wl_display_roundtrip(client->wl_display);
124
125 return client->test->n_egl_buffers;
126}
127
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800128static void
129pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
130 uint32_t serial, struct wl_surface *wl_surface,
131 wl_fixed_t x, wl_fixed_t y)
132{
133 struct pointer *pointer = data;
134
135 pointer->focus = wl_surface_get_user_data(wl_surface);
136 pointer->x = wl_fixed_to_int(x);
137 pointer->y = wl_fixed_to_int(y);
138
139 fprintf(stderr, "test-client: got pointer enter %d %d, surface %p\n",
140 pointer->x, pointer->y, pointer->focus);
141}
142
143static void
144pointer_handle_leave(void *data, struct wl_pointer *wl_pointer,
145 uint32_t serial, struct wl_surface *wl_surface)
146{
147 struct pointer *pointer = data;
148
149 pointer->focus = NULL;
150
151 fprintf(stderr, "test-client: got pointer leave, surface %p\n",
152 wl_surface_get_user_data(wl_surface));
153}
154
155static void
156pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
157 uint32_t time, wl_fixed_t x, wl_fixed_t y)
158{
159 struct pointer *pointer = data;
160
161 pointer->x = wl_fixed_to_int(x);
162 pointer->y = wl_fixed_to_int(y);
163
164 fprintf(stderr, "test-client: got pointer motion %d %d\n",
165 pointer->x, pointer->y);
166}
167
168static void
169pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
170 uint32_t serial, uint32_t time, uint32_t button,
171 uint32_t state)
172{
173 struct pointer *pointer = data;
174
175 pointer->button = button;
176 pointer->state = state;
177
178 fprintf(stderr, "test-client: got pointer button %u %u\n",
179 button, state);
180}
181
182static void
183pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
184 uint32_t time, uint32_t axis, wl_fixed_t value)
185{
Kristian Høgsberg4c8ce202013-10-09 14:23:00 -0700186 fprintf(stderr, "test-client: got pointer axis %u %f\n",
187 axis, wl_fixed_to_double(value));
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800188}
189
Peter Hutterer87743e92016-01-18 16:38:22 +1000190static void
191pointer_handle_frame(void *data, struct wl_pointer *wl_pointer)
192{
193 fprintf(stderr, "test-client: got pointer frame\n");
194}
195
196static void
197pointer_handle_axis_source(void *data, struct wl_pointer *wl_pointer,
198 uint32_t source)
199{
200 fprintf(stderr, "test-client: got pointer axis source %u\n", source);
201}
202
203static void
204pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer,
205 uint32_t time, uint32_t axis)
206{
207 fprintf(stderr, "test-client: got pointer axis stop\n");
208}
209
210static void
211pointer_handle_axis_discrete(void *data, struct wl_pointer *wl_pointer,
212 uint32_t axis, int32_t value)
213{
214 fprintf(stderr, "test-client: got pointer axis discrete %u %d\n",
215 axis, value);
216}
217
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800218static const struct wl_pointer_listener pointer_listener = {
219 pointer_handle_enter,
220 pointer_handle_leave,
221 pointer_handle_motion,
222 pointer_handle_button,
223 pointer_handle_axis,
Peter Hutterer87743e92016-01-18 16:38:22 +1000224 pointer_handle_frame,
225 pointer_handle_axis_source,
226 pointer_handle_axis_stop,
227 pointer_handle_axis_discrete,
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800228};
229
230static void
231keyboard_handle_keymap(void *data, struct wl_keyboard *wl_keyboard,
232 uint32_t format, int fd, uint32_t size)
233{
234 close(fd);
235
236 fprintf(stderr, "test-client: got keyboard keymap\n");
237}
238
239static void
240keyboard_handle_enter(void *data, struct wl_keyboard *wl_keyboard,
241 uint32_t serial, struct wl_surface *wl_surface,
242 struct wl_array *keys)
243{
244 struct keyboard *keyboard = data;
245
246 keyboard->focus = wl_surface_get_user_data(wl_surface);
247
248 fprintf(stderr, "test-client: got keyboard enter, surface %p\n",
249 keyboard->focus);
250}
251
252static void
253keyboard_handle_leave(void *data, struct wl_keyboard *wl_keyboard,
254 uint32_t serial, struct wl_surface *wl_surface)
255{
256 struct keyboard *keyboard = data;
257
258 keyboard->focus = NULL;
259
260 fprintf(stderr, "test-client: got keyboard leave, surface %p\n",
261 wl_surface_get_user_data(wl_surface));
262}
263
264static void
265keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard,
266 uint32_t serial, uint32_t time, uint32_t key,
267 uint32_t state)
268{
269 struct keyboard *keyboard = data;
270
271 keyboard->key = key;
272 keyboard->state = state;
273
274 fprintf(stderr, "test-client: got keyboard key %u %u\n", key, state);
275}
276
277static void
278keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard,
279 uint32_t serial, uint32_t mods_depressed,
280 uint32_t mods_latched, uint32_t mods_locked,
281 uint32_t group)
282{
283 struct keyboard *keyboard = data;
284
285 keyboard->mods_depressed = mods_depressed;
286 keyboard->mods_latched = mods_latched;
287 keyboard->mods_locked = mods_locked;
288 keyboard->group = group;
289
290 fprintf(stderr, "test-client: got keyboard modifiers %u %u %u %u\n",
291 mods_depressed, mods_latched, mods_locked, group);
292}
293
Marek Chalupa643d85f2015-03-30 06:37:56 -0400294static void
295keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
296 int32_t rate, int32_t delay)
297{
298 struct keyboard *keyboard = data;
299
300 keyboard->repeat_info.rate = rate;
301 keyboard->repeat_info.delay = delay;
302
303 fprintf(stderr, "test-client: got keyboard repeat_info %d %d\n",
304 rate, delay);
305}
306
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800307static const struct wl_keyboard_listener keyboard_listener = {
308 keyboard_handle_keymap,
309 keyboard_handle_enter,
310 keyboard_handle_leave,
311 keyboard_handle_key,
312 keyboard_handle_modifiers,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400313 keyboard_handle_repeat_info,
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800314};
315
316static void
Marek Chalupa8a5523c2015-03-30 09:20:07 -0400317touch_handle_down(void *data, struct wl_touch *wl_touch,
318 uint32_t serial, uint32_t time, struct wl_surface *surface,
319 int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
320{
321 struct touch *touch = data;
322
323 touch->down_x = wl_fixed_to_int(x_w);
324 touch->down_y = wl_fixed_to_int(y_w);
325 touch->id = id;
326
327 fprintf(stderr, "test-client: got touch down %d %d, surf: %p, id: %d\n",
328 touch->down_x, touch->down_y, surface, id);
329}
330
331static void
332touch_handle_up(void *data, struct wl_touch *wl_touch,
333 uint32_t serial, uint32_t time, int32_t id)
334{
335 struct touch *touch = data;
336 touch->up_id = id;
337
338 fprintf(stderr, "test-client: got touch up, id: %d\n", id);
339}
340
341static void
342touch_handle_motion(void *data, struct wl_touch *wl_touch,
343 uint32_t time, int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
344{
345 struct touch *touch = data;
346 touch->x = wl_fixed_to_int(x_w);
347 touch->y = wl_fixed_to_int(y_w);
348
349 fprintf(stderr, "test-client: got touch motion, %d %d, id: %d\n",
350 touch->x, touch->y, id);
351}
352
353static void
354touch_handle_frame(void *data, struct wl_touch *wl_touch)
355{
356 struct touch *touch = data;
357
358 ++touch->frame_no;
359
360 fprintf(stderr, "test-client: got touch frame (%d)\n", touch->frame_no);
361}
362
363static void
364touch_handle_cancel(void *data, struct wl_touch *wl_touch)
365{
366 struct touch *touch = data;
367
368 ++touch->cancel_no;
369
370 fprintf(stderr, "test-client: got touch cancel (%d)\n", touch->cancel_no);
371}
372
373static const struct wl_touch_listener touch_listener = {
374 touch_handle_down,
375 touch_handle_up,
376 touch_handle_motion,
377 touch_handle_frame,
378 touch_handle_cancel,
379};
380
381static void
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800382surface_enter(void *data,
383 struct wl_surface *wl_surface, struct wl_output *output)
384{
385 struct surface *surface = data;
386
387 surface->output = wl_output_get_user_data(output);
388
389 fprintf(stderr, "test-client: got surface enter output %p\n",
390 surface->output);
391}
392
393static void
394surface_leave(void *data,
395 struct wl_surface *wl_surface, struct wl_output *output)
396{
397 struct surface *surface = data;
398
399 surface->output = NULL;
400
401 fprintf(stderr, "test-client: got surface leave output %p\n",
402 wl_output_get_user_data(output));
403}
404
405static const struct wl_surface_listener surface_listener = {
406 surface_enter,
407 surface_leave
408};
409
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200410struct wl_buffer *
411create_shm_buffer(struct client *client, int width, int height, void **pixels)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800412{
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800413 struct wl_shm *shm = client->wl_shm;
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200414 int stride = width * 4;
415 int size = stride * height;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800416 struct wl_shm_pool *pool;
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200417 struct wl_buffer *buffer;
418 int fd;
419 void *data;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800420
421 fd = os_create_anonymous_file(size);
422 assert(fd >= 0);
423
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200424 data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
425 if (data == MAP_FAILED) {
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800426 close(fd);
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200427 assert(data != MAP_FAILED);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800428 }
429
430 pool = wl_shm_create_pool(shm, fd, size);
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200431 buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride,
432 WL_SHM_FORMAT_ARGB8888);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800433 wl_shm_pool_destroy(pool);
434
435 close(fd);
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200436
437 if (pixels)
438 *pixels = data;
439
440 return buffer;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800441}
442
443static void
444shm_format(void *data, struct wl_shm *wl_shm, uint32_t format)
445{
446 struct client *client = data;
447
448 if (format == WL_SHM_FORMAT_ARGB8888)
449 client->has_argb = 1;
450}
451
452struct wl_shm_listener shm_listener = {
453 shm_format
454};
455
456static void
Derek Foremanf6a65922015-02-24 09:32:14 -0600457test_handle_pointer_position(void *data, struct weston_test *weston_test,
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800458 wl_fixed_t x, wl_fixed_t y)
459{
460 struct test *test = data;
461 test->pointer_x = wl_fixed_to_int(x);
462 test->pointer_y = wl_fixed_to_int(y);
463
464 fprintf(stderr, "test-client: got global pointer %d %d\n",
465 test->pointer_x, test->pointer_y);
466}
467
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000468static void
Derek Foremanf6a65922015-02-24 09:32:14 -0600469test_handle_n_egl_buffers(void *data, struct weston_test *weston_test, uint32_t n)
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000470{
471 struct test *test = data;
472
473 test->n_egl_buffers = n;
474}
475
Bryce Harrington692275f2015-04-23 16:33:49 -0700476static void
477test_handle_capture_screenshot_done(void *data, struct weston_test *weston_test)
478{
479 struct test *test = data;
480
481 printf("Screenshot has been captured\n");
482 test->buffer_copy_done = 1;
483}
484
Derek Foremanf6a65922015-02-24 09:32:14 -0600485static const struct weston_test_listener test_listener = {
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000486 test_handle_pointer_position,
487 test_handle_n_egl_buffers,
Bryce Harrington692275f2015-04-23 16:33:49 -0700488 test_handle_capture_screenshot_done,
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800489};
490
491static void
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400492input_update_devices(struct input *input)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800493{
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800494 struct pointer *pointer;
495 struct keyboard *keyboard;
Marek Chalupa8a5523c2015-03-30 09:20:07 -0400496 struct touch *touch;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800497
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400498 struct wl_seat *seat = input->wl_seat;
499 enum wl_seat_capability caps = input->caps;
500
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800501 if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700502 pointer = xzalloc(sizeof *pointer);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800503 pointer->wl_pointer = wl_seat_get_pointer(seat);
504 wl_pointer_set_user_data(pointer->wl_pointer, pointer);
505 wl_pointer_add_listener(pointer->wl_pointer, &pointer_listener,
506 pointer);
507 input->pointer = pointer;
508 } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
509 wl_pointer_destroy(input->pointer->wl_pointer);
510 free(input->pointer);
511 input->pointer = NULL;
512 }
513
514 if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) {
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700515 keyboard = xzalloc(sizeof *keyboard);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800516 keyboard->wl_keyboard = wl_seat_get_keyboard(seat);
517 wl_keyboard_set_user_data(keyboard->wl_keyboard, keyboard);
518 wl_keyboard_add_listener(keyboard->wl_keyboard, &keyboard_listener,
519 keyboard);
520 input->keyboard = keyboard;
521 } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) {
522 wl_keyboard_destroy(input->keyboard->wl_keyboard);
523 free(input->keyboard);
524 input->keyboard = NULL;
525 }
Marek Chalupa8a5523c2015-03-30 09:20:07 -0400526
527 if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->touch) {
528 touch = xzalloc(sizeof *touch);
529 touch->wl_touch = wl_seat_get_touch(seat);
530 wl_touch_set_user_data(touch->wl_touch, touch);
531 wl_touch_add_listener(touch->wl_touch, &touch_listener,
532 touch);
533 input->touch = touch;
534 } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->touch) {
535 wl_touch_destroy(input->touch->wl_touch);
536 free(input->touch);
537 input->touch = NULL;
538 }
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800539}
540
Marek Chalupa643d85f2015-03-30 06:37:56 -0400541static void
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400542seat_handle_capabilities(void *data, struct wl_seat *seat,
543 enum wl_seat_capability caps)
544{
545 struct input *input = data;
546
547 input->caps = caps;
548
549 /* we will create/update the devices only with the right (test) seat.
550 * If we haven't discovered which seat is the test seat, just
551 * store capabilities and bail out */
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300552 if (input->seat_name && strcmp(input->seat_name, "test-seat") == 0)
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400553 input_update_devices(input);
554
555 fprintf(stderr, "test-client: got seat %p capabilities: %x\n",
556 input, caps);
557}
558
559static void
Marek Chalupa643d85f2015-03-30 06:37:56 -0400560seat_handle_name(void *data, struct wl_seat *seat, const char *name)
561{
562 struct input *input = data;
563
564 input->seat_name = strdup(name);
565 assert(input->seat_name && "No memory");
566
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400567 fprintf(stderr, "test-client: got seat %p name: \'%s\'\n",
568 input, name);
Marek Chalupa643d85f2015-03-30 06:37:56 -0400569}
570
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800571static const struct wl_seat_listener seat_listener = {
572 seat_handle_capabilities,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400573 seat_handle_name,
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800574};
575
576static void
577output_handle_geometry(void *data,
578 struct wl_output *wl_output,
579 int x, int y,
580 int physical_width,
581 int physical_height,
582 int subpixel,
583 const char *make,
584 const char *model,
585 int32_t transform)
586{
587 struct output *output = data;
588
589 output->x = x;
590 output->y = y;
591}
592
593static void
594output_handle_mode(void *data,
595 struct wl_output *wl_output,
596 uint32_t flags,
597 int width,
598 int height,
599 int refresh)
600{
601 struct output *output = data;
602
603 if (flags & WL_OUTPUT_MODE_CURRENT) {
604 output->width = width;
605 output->height = height;
606 }
607}
608
Marek Chalupa643d85f2015-03-30 06:37:56 -0400609static void
610output_handle_scale(void *data,
611 struct wl_output *wl_output,
612 int scale)
613{
614 struct output *output = data;
615
616 output->scale = scale;
617}
618
619static void
620output_handle_done(void *data,
621 struct wl_output *wl_output)
622{
623 struct output *output = data;
624
625 output->initialized = 1;
626}
627
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800628static const struct wl_output_listener output_listener = {
629 output_handle_geometry,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400630 output_handle_mode,
631 output_handle_done,
632 output_handle_scale,
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800633};
634
635static void
636handle_global(void *data, struct wl_registry *registry,
637 uint32_t id, const char *interface, uint32_t version)
638{
639 struct client *client = data;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800640 struct output *output;
641 struct test *test;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500642 struct global *global;
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400643 struct input *input;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500644
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700645 global = xzalloc(sizeof *global);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500646 global->name = id;
647 global->interface = strdup(interface);
648 assert(interface);
649 global->version = version;
650 wl_list_insert(client->global_list.prev, &global->link);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800651
652 if (strcmp(interface, "wl_compositor") == 0) {
653 client->wl_compositor =
654 wl_registry_bind(registry, id,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400655 &wl_compositor_interface, version);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800656 } else if (strcmp(interface, "wl_seat") == 0) {
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700657 input = xzalloc(sizeof *input);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800658 input->wl_seat =
659 wl_registry_bind(registry, id,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400660 &wl_seat_interface, version);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800661 wl_seat_add_listener(input->wl_seat, &seat_listener, input);
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400662 wl_list_insert(&client->inputs, &input->link);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800663 } else if (strcmp(interface, "wl_shm") == 0) {
664 client->wl_shm =
665 wl_registry_bind(registry, id,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400666 &wl_shm_interface, version);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800667 wl_shm_add_listener(client->wl_shm, &shm_listener, client);
668 } else if (strcmp(interface, "wl_output") == 0) {
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700669 output = xzalloc(sizeof *output);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800670 output->wl_output =
671 wl_registry_bind(registry, id,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400672 &wl_output_interface, version);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800673 wl_output_add_listener(output->wl_output,
674 &output_listener, output);
675 client->output = output;
Derek Foremanf6a65922015-02-24 09:32:14 -0600676 } else if (strcmp(interface, "weston_test") == 0) {
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700677 test = xzalloc(sizeof *test);
Derek Foremanf6a65922015-02-24 09:32:14 -0600678 test->weston_test =
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800679 wl_registry_bind(registry, id,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400680 &weston_test_interface, version);
Derek Foremanf6a65922015-02-24 09:32:14 -0600681 weston_test_add_listener(test->weston_test, &test_listener, test);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800682 client->test = test;
Derek Foreman9bb13392015-01-23 12:12:36 -0600683 } else if (strcmp(interface, "wl_drm") == 0) {
684 client->has_wl_drm = true;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800685 }
686}
687
688static const struct wl_registry_listener registry_listener = {
689 handle_global
690};
691
Kristian Høgsberg42284f52014-01-01 17:38:04 -0800692void
693skip(const char *fmt, ...)
694{
695 va_list argp;
696
697 va_start(argp, fmt);
698 vfprintf(stderr, fmt, argp);
699 va_end(argp);
700
Emilio Pozuelo Monfortdae8a4b2014-02-07 09:34:48 +0100701 /* automake tests uses exit code 77. weston-test-runner will see
702 * this and use it, and then weston-test's sigchld handler (in the
703 * weston process) will use that as an exit status, which is what
704 * automake will see in the end. */
705 exit(77);
Kristian Høgsberg42284f52014-01-01 17:38:04 -0800706}
707
Marek Chalupa4d06d462014-07-16 11:27:06 +0200708void
709expect_protocol_error(struct client *client,
710 const struct wl_interface *intf,
711 uint32_t code)
712{
713 int err;
714 uint32_t errcode, failed = 0;
715 const struct wl_interface *interface;
716 unsigned int id;
717
718 /* if the error has not come yet, make it happen */
719 wl_display_roundtrip(client->wl_display);
720
721 err = wl_display_get_error(client->wl_display);
722
723 assert(err && "Expected protocol error but nothing came");
724 assert(err == EPROTO && "Expected protocol error but got local error");
725
726 errcode = wl_display_get_protocol_error(client->wl_display,
727 &interface, &id);
728
729 /* check error */
730 if (errcode != code) {
731 fprintf(stderr, "Should get error code %d but got %d\n",
732 code, errcode);
733 failed = 1;
734 }
735
736 /* this should be definitely set */
737 assert(interface);
738
739 if (strcmp(intf->name, interface->name) != 0) {
740 fprintf(stderr, "Should get interface '%s' but got '%s'\n",
741 intf->name, interface->name);
742 failed = 1;
743 }
744
745 if (failed) {
746 fprintf(stderr, "Expected other protocol error\n");
747 abort();
748 }
749
750 /* all OK */
751 fprintf(stderr, "Got expected protocol error on '%s' (object id: %d) "
752 "with code %d\n", interface->name, id, errcode);
753}
754
Pekka Paalanen07921d72012-12-12 14:26:40 +0200755static void
756log_handler(const char *fmt, va_list args)
757{
758 fprintf(stderr, "libwayland: ");
759 vfprintf(stderr, fmt, args);
760}
761
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400762static void
763input_destroy(struct input *inp)
764{
765 wl_list_remove(&inp->link);
766 wl_seat_destroy(inp->wl_seat);
767 free(inp);
768}
769
770/* find the test-seat and set it in client.
771 * Destroy other inputs */
772static void
773client_set_input(struct client *cl)
774{
775 struct input *inp, *inptmp;
776 wl_list_for_each_safe(inp, inptmp, &cl->inputs, link) {
777 assert(inp->seat_name && "BUG: input with no name");
778 if (strcmp(inp->seat_name, "test-seat") == 0) {
779 cl->input = inp;
780 input_update_devices(inp);
781 } else {
782 input_destroy(inp);
783 }
784 }
785
786 /* we keep only one input */
787 assert(wl_list_length(&cl->inputs) == 1);
788}
789
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800790struct client *
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200791create_client(void)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800792{
793 struct client *client;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800794
Pekka Paalanen07921d72012-12-12 14:26:40 +0200795 wl_log_set_handler_client(log_handler);
796
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800797 /* connect to display */
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700798 client = xzalloc(sizeof *client);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800799 client->wl_display = wl_display_connect(NULL);
800 assert(client->wl_display);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500801 wl_list_init(&client->global_list);
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400802 wl_list_init(&client->inputs);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800803
804 /* setup registry so we can bind to interfaces */
805 client->wl_registry = wl_display_get_registry(client->wl_display);
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200806 wl_registry_add_listener(client->wl_registry, &registry_listener,
807 client);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800808
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400809 /* this roundtrip makes sure we have all globals and we bound to them */
810 client_roundtrip(client);
811 /* this roundtrip makes sure we got all wl_shm.format and wl_seat.*
812 * events */
813 client_roundtrip(client);
814
815 /* find the right input for us */
816 client_set_input(client);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800817
818 /* must have WL_SHM_FORMAT_ARGB32 */
819 assert(client->has_argb);
820
Derek Foremanf6a65922015-02-24 09:32:14 -0600821 /* must have weston_test interface */
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800822 assert(client->test);
823
824 /* must have an output */
825 assert(client->output);
826
Marek Chalupa643d85f2015-03-30 06:37:56 -0400827 /* the output must be initialized */
828 assert(client->output->initialized == 1);
829
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400830 /* must have seat set */
831 assert(client->input);
832
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200833 return client;
834}
835
836struct client *
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200837create_client_and_test_surface(int x, int y, int width, int height)
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200838{
839 struct client *client;
840 struct surface *surface;
841
842 client = create_client();
843
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800844 /* initialize the client surface */
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700845 surface = xzalloc(sizeof *surface);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800846 surface->wl_surface =
847 wl_compositor_create_surface(client->wl_compositor);
848 assert(surface->wl_surface);
849
850 wl_surface_add_listener(surface->wl_surface, &surface_listener,
851 surface);
852
853 client->surface = surface;
854 wl_surface_set_user_data(surface->wl_surface, surface);
855
856 surface->width = width;
857 surface->height = height;
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200858 surface->wl_buffer = create_shm_buffer(client, width, height,
859 &surface->data);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800860
861 memset(surface->data, 64, width * height * 4);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800862
863 move_client(client, x, y);
864
865 return client;
866}
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800867
868static const char*
Bryce Harrington3835d052015-05-18 17:47:13 -0700869output_path(void)
870{
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800871 char *path = getenv("WESTON_TEST_OUTPUT_PATH");
872
873 if (!path)
874 return ".";
875 return path;
876 }
877
878char*
Bryce Harrington3835d052015-05-18 17:47:13 -0700879screenshot_output_filename(const char *basename, uint32_t seq)
880{
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800881 char *filename;
882
883 if (asprintf(&filename, "%s/%s-%02d.png",
884 output_path(), basename, seq) < 0)
885 return NULL;
886 return filename;
887}
888
889static const char*
Bryce Harrington3835d052015-05-18 17:47:13 -0700890reference_path(void)
891{
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800892 char *path = getenv("WESTON_TEST_REFERENCE_PATH");
893
894 if (!path)
895 return "./tests/reference";
896 return path;
897}
898
899char*
Bryce Harrington3835d052015-05-18 17:47:13 -0700900screenshot_reference_filename(const char *basename, uint32_t seq)
901{
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800902 char *filename;
903
904 if (asprintf(&filename, "%s/%s-%02d.png",
905 reference_path(), basename, seq) < 0)
906 return NULL;
907 return filename;
908}
Bryce Harrington273c2852014-12-15 15:51:25 -0800909
910/**
Bryce Harrington39a5be22015-05-14 14:36:18 -0700911 * check_surfaces_geometry() - verifies two surfaces are same size
912 *
913 * @returns true if surfaces have the same width and height, or false
914 * if not, or if there is no actual data.
915 */
916bool
917check_surfaces_geometry(const struct surface *a, const struct surface *b)
918{
919 if (a == NULL || b == NULL) {
920 printf("Undefined surfaces\n");
921 return false;
922 }
923 else if (a->data == NULL || b->data == NULL) {
924 printf("Undefined data\n");
925 return false;
926 }
927 else if (a->width != b->width || a->height != b->height) {
928 printf("Mismatched dimensions: %d,%d != %d,%d\n",
929 a->width, a->height, b->width, b->height);
930 return false;
931 }
932 return true;
933}
934
935/**
Bryce Harrington273c2852014-12-15 15:51:25 -0800936 * check_surfaces_equal() - tests if two surfaces are pixel-identical
937 *
938 * Returns true if surface buffers have all the same byte values,
939 * false if the surfaces don't match or can't be compared due to
940 * different dimensions.
941 */
942bool
943check_surfaces_equal(const struct surface *a, const struct surface *b)
944{
945 int bpp = 4; /* Assumes ARGB */
946
Bryce Harrington39a5be22015-05-14 14:36:18 -0700947 if (!check_surfaces_geometry(a, b))
Bryce Harrington273c2852014-12-15 15:51:25 -0800948 return false;
949
950 return (memcmp(a->data, b->data, bpp * a->width * a->height) == 0);
951}
952
953/**
954 * check_surfaces_match_in_clip() - tests if a given region within two
955 * surfaces are pixel-identical.
956 *
957 * Returns true if the two surfaces have the same byte values within the
958 * given clipping region, or false if they don't match or the surfaces
959 * can't be compared.
960 */
961bool
962check_surfaces_match_in_clip(const struct surface *a, const struct surface *b, const struct rectangle *clip_rect)
963{
964 int i, j;
965 int x0, y0, x1, y1;
966 void *p, *q;
967 int bpp = 4; /* Assumes ARGB */
968
Bryce Harrington39a5be22015-05-14 14:36:18 -0700969 if (!check_surfaces_geometry(a, b) || clip_rect == NULL)
Bryce Harrington273c2852014-12-15 15:51:25 -0800970 return false;
971
Bryce Harrington273c2852014-12-15 15:51:25 -0800972 if (clip_rect->x > a->width || clip_rect->y > a->height) {
973 printf("Clip outside image boundaries\n");
974 return true;
975 }
976
977 x0 = max(0, clip_rect->x);
978 y0 = max(0, clip_rect->y);
979 x1 = min(a->width, clip_rect->x + clip_rect->width);
980 y1 = min(a->height, clip_rect->y + clip_rect->height);
981
982 if (x0 == x1 || y0 == y1) {
983 printf("Degenerate comparison\n");
984 return true;
985 }
986
987 printf("Bytewise comparison inside clip\n");
988 for (i=y0; i<y1; i++) {
989 p = a->data + i * a->width * bpp + x0 * bpp;
990 q = b->data + i * b->width * bpp + x0 * bpp;
991 if (memcmp(p, q, (x1-x0)*bpp) != 0) {
992 /* Dump the bad row */
993 printf("Mismatched image on row %d\n", i);
994 for (j=0; j<(x1-x0)*bpp; j++) {
995 char a_char = *((char*)(p+j*bpp));
996 char b_char = *((char*)(q+j*bpp));
997 printf("%d,%d: %8x %8x %s\n", i, j, a_char, b_char,
998 (a_char != b_char)? " <---": "");
999 }
1000 return false;
1001 }
1002 }
1003
1004 return true;
1005}
Bryce Harrington892122e2015-09-24 14:31:44 -07001006
1007/** write_surface_as_png()
1008 *
1009 * Writes out a given weston test surface to disk as a PNG image
1010 * using the provided filename (with path).
1011 *
1012 * @returns true if successfully saved file; false otherwise.
1013 */
1014bool
1015write_surface_as_png(const struct surface *weston_surface, const char *fname)
1016{
1017 cairo_surface_t *cairo_surface;
1018 cairo_status_t status;
1019 int bpp = 4; /* Assume ARGB */
1020 int stride = bpp * weston_surface->width;
1021
1022 cairo_surface = cairo_image_surface_create_for_data(weston_surface->data,
1023 CAIRO_FORMAT_ARGB32,
1024 weston_surface->width,
1025 weston_surface->height,
1026 stride);
1027 printf("Writing PNG to disk\n");
1028 status = cairo_surface_write_to_png(cairo_surface, fname);
1029 if (status != CAIRO_STATUS_SUCCESS) {
1030 printf("Failed to save screenshot: %s\n",
1031 cairo_status_to_string(status));
1032 return false;
1033 }
1034 cairo_surface_destroy(cairo_surface);
1035 return true;
1036}
1037
1038/** load_surface_from_png()
1039 *
1040 * Reads a PNG image from disk using the given filename (and path)
1041 * and returns as a freshly allocated weston test surface.
1042 *
1043 * @returns weston test surface with image, which should be free'd
1044 * when no longer used; or, NULL in case of error.
1045 */
1046struct surface *
1047load_surface_from_png(const char *fname)
1048{
1049 struct surface *reference;
1050 cairo_surface_t *reference_cairo_surface;
1051 cairo_status_t status;
1052 size_t source_data_size;
1053 int bpp;
1054 int stride;
1055
1056 reference_cairo_surface = cairo_image_surface_create_from_png(fname);
1057 status = cairo_surface_status(reference_cairo_surface);
1058 if (status != CAIRO_STATUS_SUCCESS) {
1059 printf("Could not open %s: %s\n", fname, cairo_status_to_string(status));
1060 cairo_surface_destroy(reference_cairo_surface);
1061 return NULL;
1062 }
1063
1064 /* Disguise the cairo surface in a weston test surface */
1065 reference = zalloc(sizeof *reference);
1066 if (reference == NULL) {
1067 perror("zalloc reference");
1068 cairo_surface_destroy(reference_cairo_surface);
1069 return NULL;
1070 }
1071 reference->width = cairo_image_surface_get_width(reference_cairo_surface);
1072 reference->height = cairo_image_surface_get_height(reference_cairo_surface);
1073 stride = cairo_image_surface_get_stride(reference_cairo_surface);
1074 source_data_size = stride * reference->height;
1075
1076 /* Check that the file's stride matches our assumption */
1077 bpp = 4;
1078 if (stride != bpp * reference->width) {
1079 printf("Mismatched stride for screenshot reference image %s\n", fname);
1080 cairo_surface_destroy(reference_cairo_surface);
1081 free(reference);
1082 return NULL;
1083 }
1084
1085 /* Allocate new buffer for our weston reference, and copy the data from
1086 the cairo surface so we can destroy it */
1087 reference->data = zalloc(source_data_size);
1088 if (reference->data == NULL) {
1089 perror("zalloc reference data");
1090 cairo_surface_destroy(reference_cairo_surface);
1091 free(reference);
1092 return NULL;
1093 }
1094 memcpy(reference->data,
1095 cairo_image_surface_get_data(reference_cairo_surface),
1096 source_data_size);
1097
1098 cairo_surface_destroy(reference_cairo_surface);
1099 return reference;
1100}
1101
1102/** create_screenshot_surface()
1103 *
1104 * Allocates and initializes a weston test surface for use in
1105 * storing a screenshot of the client's output. Establishes a
1106 * shm backed wl_buffer for retrieving screenshot image data
1107 * from the server, sized to match the client's output display.
1108 *
1109 * @returns stack allocated surface image, which should be
1110 * free'd when done using it.
1111 */
1112struct surface *
1113create_screenshot_surface(struct client *client)
1114{
1115 struct surface *screenshot;
1116 screenshot = zalloc(sizeof *screenshot);
1117 if (screenshot == NULL)
1118 return NULL;
1119 screenshot->wl_buffer = create_shm_buffer(client,
1120 client->output->width,
1121 client->output->height,
1122 &screenshot->data);
1123 screenshot->height = client->output->height;
1124 screenshot->width = client->output->width;
1125
1126 return screenshot;
1127}
1128
1129/** capture_screenshot_of_output()
1130 *
1131 * Requests a screenshot from the server of the output that the
1132 * client appears on. The image data returned from the server
1133 * can be accessed from the screenshot surface's data member.
1134 *
1135 * @returns a new surface object, which should be free'd when no
1136 * longer needed.
1137 */
1138struct surface *
1139capture_screenshot_of_output(struct client *client)
1140{
1141 struct surface *screenshot;
1142
1143 /* Create a surface to hold the screenshot */
1144 screenshot = create_screenshot_surface(client);
1145
1146 client->test->buffer_copy_done = 0;
1147 weston_test_capture_screenshot(client->test->weston_test,
1148 client->output->wl_output,
1149 screenshot->wl_buffer);
1150 while (client->test->buffer_copy_done == 0)
1151 if (wl_display_dispatch(client->wl_display) < 0)
1152 break;
1153
1154 /* FIXME: Document somewhere the orientation the screenshot is taken
1155 * and how the clip coords are interpreted, in case of scaling/transform.
1156 * If we're using read_pixels() just make sure it is documented somewhere.
1157 * Protocol docs in the XML, comparison function docs in Doxygen style.
1158 */
1159
1160 return screenshot;
1161}