blob: 97c4395a4a006b09f23022ead24b912802ec3722 [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
Bryce Harrington892122e2015-09-24 14:31:44 -070036#include "zalloc.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070037#include "shared/os-compatibility.h"
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080038#include "weston-test-client-helper.h"
39
Bryce Harrington273c2852014-12-15 15:51:25 -080040#define max(a, b) (((a) > (b)) ? (a) : (b))
41#define min(a, b) (((a) > (b)) ? (b) : (a))
42#define clip(x, a, b) min(max(x, a), b)
43
Bryce Harrington61a64362015-04-22 18:23:01 -070044void *
45fail_on_null(void *p)
46{
47 if (p == NULL) {
48 fprintf(stderr, "out of memory\n");
49 exit(EXIT_FAILURE);
50 }
51 return p;
52}
53
54
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080055int
56surface_contains(struct surface *surface, int x, int y)
57{
58 /* test whether a global x,y point is contained in the surface */
59 int sx = surface->x;
60 int sy = surface->y;
61 int sw = surface->width;
62 int sh = surface->height;
63 return x >= sx && y >= sy && x < sx + sw && y < sy + sh;
64}
65
Kristian Høgsbergdb6dc7d2012-12-11 21:49:13 -050066static void
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +020067frame_callback_handler(void *data, struct wl_callback *callback, uint32_t time)
Kristian Høgsbergdb6dc7d2012-12-11 21:49:13 -050068{
69 int *done = data;
70
71 *done = 1;
72
73 wl_callback_destroy(callback);
74}
75
76static const struct wl_callback_listener frame_listener = {
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +020077 frame_callback_handler
Kristian Høgsbergdb6dc7d2012-12-11 21:49:13 -050078};
79
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +020080struct wl_callback *
81frame_callback_set(struct wl_surface *surface, int *done)
82{
83 struct wl_callback *callback;
84
85 *done = 0;
86 callback = wl_surface_frame(surface);
87 wl_callback_add_listener(callback, &frame_listener, done);
88
89 return callback;
90}
91
Marek Chalupa1740aa82014-07-16 11:32:50 +020092int
93frame_callback_wait_nofail(struct client *client, int *done)
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +020094{
95 while (!*done) {
Marek Chalupa1740aa82014-07-16 11:32:50 +020096 if (wl_display_dispatch(client->wl_display) < 0)
97 return 0;
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +020098 }
Marek Chalupa1740aa82014-07-16 11:32:50 +020099
100 return 1;
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200101}
102
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800103void
104move_client(struct client *client, int x, int y)
105{
106 struct surface *surface = client->surface;
Kristian Høgsbergdb6dc7d2012-12-11 21:49:13 -0500107 int done;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800108
109 client->surface->x = x;
110 client->surface->y = y;
Derek Foremanf6a65922015-02-24 09:32:14 -0600111 weston_test_move_surface(client->test->weston_test, surface->wl_surface,
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800112 surface->x, surface->y);
Bryce Harringtoncb50ed22014-12-10 18:33:47 -0800113 /* The attach here is necessary because commit() will call configure
Giulio Camuffo82cb5052013-02-28 18:44:54 +0100114 * only on surfaces newly attached, and the one that sets the surface
115 * position is the configure. */
116 wl_surface_attach(surface->wl_surface, surface->wl_buffer, 0, 0);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800117 wl_surface_damage(surface->wl_surface, 0, 0, surface->width,
118 surface->height);
Kristian Høgsbergdb6dc7d2012-12-11 21:49:13 -0500119
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200120 frame_callback_set(surface->wl_surface, &done);
Kristian Høgsbergdb6dc7d2012-12-11 21:49:13 -0500121
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800122 wl_surface_commit(surface->wl_surface);
123
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200124 frame_callback_wait(client, &done);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800125}
126
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000127int
128get_n_egl_buffers(struct client *client)
129{
130 client->test->n_egl_buffers = -1;
131
Derek Foremanf6a65922015-02-24 09:32:14 -0600132 weston_test_get_n_egl_buffers(client->test->weston_test);
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000133 wl_display_roundtrip(client->wl_display);
134
135 return client->test->n_egl_buffers;
136}
137
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800138static void
139pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
140 uint32_t serial, struct wl_surface *wl_surface,
141 wl_fixed_t x, wl_fixed_t y)
142{
143 struct pointer *pointer = data;
144
145 pointer->focus = wl_surface_get_user_data(wl_surface);
146 pointer->x = wl_fixed_to_int(x);
147 pointer->y = wl_fixed_to_int(y);
148
149 fprintf(stderr, "test-client: got pointer enter %d %d, surface %p\n",
150 pointer->x, pointer->y, pointer->focus);
151}
152
153static void
154pointer_handle_leave(void *data, struct wl_pointer *wl_pointer,
155 uint32_t serial, struct wl_surface *wl_surface)
156{
157 struct pointer *pointer = data;
158
159 pointer->focus = NULL;
160
161 fprintf(stderr, "test-client: got pointer leave, surface %p\n",
162 wl_surface_get_user_data(wl_surface));
163}
164
165static void
166pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
167 uint32_t time, wl_fixed_t x, wl_fixed_t y)
168{
169 struct pointer *pointer = data;
170
171 pointer->x = wl_fixed_to_int(x);
172 pointer->y = wl_fixed_to_int(y);
173
174 fprintf(stderr, "test-client: got pointer motion %d %d\n",
175 pointer->x, pointer->y);
176}
177
178static void
179pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
180 uint32_t serial, uint32_t time, uint32_t button,
181 uint32_t state)
182{
183 struct pointer *pointer = data;
184
185 pointer->button = button;
186 pointer->state = state;
187
188 fprintf(stderr, "test-client: got pointer button %u %u\n",
189 button, state);
190}
191
192static void
193pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
194 uint32_t time, uint32_t axis, wl_fixed_t value)
195{
Kristian Høgsberg4c8ce202013-10-09 14:23:00 -0700196 fprintf(stderr, "test-client: got pointer axis %u %f\n",
197 axis, wl_fixed_to_double(value));
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800198}
199
Peter Hutterer87743e92016-01-18 16:38:22 +1000200static void
201pointer_handle_frame(void *data, struct wl_pointer *wl_pointer)
202{
203 fprintf(stderr, "test-client: got pointer frame\n");
204}
205
206static void
207pointer_handle_axis_source(void *data, struct wl_pointer *wl_pointer,
208 uint32_t source)
209{
210 fprintf(stderr, "test-client: got pointer axis source %u\n", source);
211}
212
213static void
214pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer,
215 uint32_t time, uint32_t axis)
216{
217 fprintf(stderr, "test-client: got pointer axis stop\n");
218}
219
220static void
221pointer_handle_axis_discrete(void *data, struct wl_pointer *wl_pointer,
222 uint32_t axis, int32_t value)
223{
224 fprintf(stderr, "test-client: got pointer axis discrete %u %d\n",
225 axis, value);
226}
227
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800228static const struct wl_pointer_listener pointer_listener = {
229 pointer_handle_enter,
230 pointer_handle_leave,
231 pointer_handle_motion,
232 pointer_handle_button,
233 pointer_handle_axis,
Peter Hutterer87743e92016-01-18 16:38:22 +1000234 pointer_handle_frame,
235 pointer_handle_axis_source,
236 pointer_handle_axis_stop,
237 pointer_handle_axis_discrete,
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800238};
239
240static void
241keyboard_handle_keymap(void *data, struct wl_keyboard *wl_keyboard,
242 uint32_t format, int fd, uint32_t size)
243{
244 close(fd);
245
246 fprintf(stderr, "test-client: got keyboard keymap\n");
247}
248
249static void
250keyboard_handle_enter(void *data, struct wl_keyboard *wl_keyboard,
251 uint32_t serial, struct wl_surface *wl_surface,
252 struct wl_array *keys)
253{
254 struct keyboard *keyboard = data;
255
256 keyboard->focus = wl_surface_get_user_data(wl_surface);
257
258 fprintf(stderr, "test-client: got keyboard enter, surface %p\n",
259 keyboard->focus);
260}
261
262static void
263keyboard_handle_leave(void *data, struct wl_keyboard *wl_keyboard,
264 uint32_t serial, struct wl_surface *wl_surface)
265{
266 struct keyboard *keyboard = data;
267
268 keyboard->focus = NULL;
269
270 fprintf(stderr, "test-client: got keyboard leave, surface %p\n",
271 wl_surface_get_user_data(wl_surface));
272}
273
274static void
275keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard,
276 uint32_t serial, uint32_t time, uint32_t key,
277 uint32_t state)
278{
279 struct keyboard *keyboard = data;
280
281 keyboard->key = key;
282 keyboard->state = state;
283
284 fprintf(stderr, "test-client: got keyboard key %u %u\n", key, state);
285}
286
287static void
288keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard,
289 uint32_t serial, uint32_t mods_depressed,
290 uint32_t mods_latched, uint32_t mods_locked,
291 uint32_t group)
292{
293 struct keyboard *keyboard = data;
294
295 keyboard->mods_depressed = mods_depressed;
296 keyboard->mods_latched = mods_latched;
297 keyboard->mods_locked = mods_locked;
298 keyboard->group = group;
299
300 fprintf(stderr, "test-client: got keyboard modifiers %u %u %u %u\n",
301 mods_depressed, mods_latched, mods_locked, group);
302}
303
Marek Chalupa643d85f2015-03-30 06:37:56 -0400304static void
305keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
306 int32_t rate, int32_t delay)
307{
308 struct keyboard *keyboard = data;
309
310 keyboard->repeat_info.rate = rate;
311 keyboard->repeat_info.delay = delay;
312
313 fprintf(stderr, "test-client: got keyboard repeat_info %d %d\n",
314 rate, delay);
315}
316
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800317static const struct wl_keyboard_listener keyboard_listener = {
318 keyboard_handle_keymap,
319 keyboard_handle_enter,
320 keyboard_handle_leave,
321 keyboard_handle_key,
322 keyboard_handle_modifiers,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400323 keyboard_handle_repeat_info,
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800324};
325
326static void
Marek Chalupa8a5523c2015-03-30 09:20:07 -0400327touch_handle_down(void *data, struct wl_touch *wl_touch,
328 uint32_t serial, uint32_t time, struct wl_surface *surface,
329 int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
330{
331 struct touch *touch = data;
332
333 touch->down_x = wl_fixed_to_int(x_w);
334 touch->down_y = wl_fixed_to_int(y_w);
335 touch->id = id;
336
337 fprintf(stderr, "test-client: got touch down %d %d, surf: %p, id: %d\n",
338 touch->down_x, touch->down_y, surface, id);
339}
340
341static void
342touch_handle_up(void *data, struct wl_touch *wl_touch,
343 uint32_t serial, uint32_t time, int32_t id)
344{
345 struct touch *touch = data;
346 touch->up_id = id;
347
348 fprintf(stderr, "test-client: got touch up, id: %d\n", id);
349}
350
351static void
352touch_handle_motion(void *data, struct wl_touch *wl_touch,
353 uint32_t time, int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
354{
355 struct touch *touch = data;
356 touch->x = wl_fixed_to_int(x_w);
357 touch->y = wl_fixed_to_int(y_w);
358
359 fprintf(stderr, "test-client: got touch motion, %d %d, id: %d\n",
360 touch->x, touch->y, id);
361}
362
363static void
364touch_handle_frame(void *data, struct wl_touch *wl_touch)
365{
366 struct touch *touch = data;
367
368 ++touch->frame_no;
369
370 fprintf(stderr, "test-client: got touch frame (%d)\n", touch->frame_no);
371}
372
373static void
374touch_handle_cancel(void *data, struct wl_touch *wl_touch)
375{
376 struct touch *touch = data;
377
378 ++touch->cancel_no;
379
380 fprintf(stderr, "test-client: got touch cancel (%d)\n", touch->cancel_no);
381}
382
383static const struct wl_touch_listener touch_listener = {
384 touch_handle_down,
385 touch_handle_up,
386 touch_handle_motion,
387 touch_handle_frame,
388 touch_handle_cancel,
389};
390
391static void
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800392surface_enter(void *data,
393 struct wl_surface *wl_surface, struct wl_output *output)
394{
395 struct surface *surface = data;
396
397 surface->output = wl_output_get_user_data(output);
398
399 fprintf(stderr, "test-client: got surface enter output %p\n",
400 surface->output);
401}
402
403static void
404surface_leave(void *data,
405 struct wl_surface *wl_surface, struct wl_output *output)
406{
407 struct surface *surface = data;
408
409 surface->output = NULL;
410
411 fprintf(stderr, "test-client: got surface leave output %p\n",
412 wl_output_get_user_data(output));
413}
414
415static const struct wl_surface_listener surface_listener = {
416 surface_enter,
417 surface_leave
418};
419
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200420struct wl_buffer *
421create_shm_buffer(struct client *client, int width, int height, void **pixels)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800422{
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800423 struct wl_shm *shm = client->wl_shm;
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200424 int stride = width * 4;
425 int size = stride * height;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800426 struct wl_shm_pool *pool;
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200427 struct wl_buffer *buffer;
428 int fd;
429 void *data;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800430
431 fd = os_create_anonymous_file(size);
432 assert(fd >= 0);
433
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200434 data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
435 if (data == MAP_FAILED) {
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800436 close(fd);
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200437 assert(data != MAP_FAILED);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800438 }
439
440 pool = wl_shm_create_pool(shm, fd, size);
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200441 buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride,
442 WL_SHM_FORMAT_ARGB8888);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800443 wl_shm_pool_destroy(pool);
444
445 close(fd);
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200446
447 if (pixels)
448 *pixels = data;
449
450 return buffer;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800451}
452
453static void
454shm_format(void *data, struct wl_shm *wl_shm, uint32_t format)
455{
456 struct client *client = data;
457
458 if (format == WL_SHM_FORMAT_ARGB8888)
459 client->has_argb = 1;
460}
461
462struct wl_shm_listener shm_listener = {
463 shm_format
464};
465
466static void
Derek Foremanf6a65922015-02-24 09:32:14 -0600467test_handle_pointer_position(void *data, struct weston_test *weston_test,
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800468 wl_fixed_t x, wl_fixed_t y)
469{
470 struct test *test = data;
471 test->pointer_x = wl_fixed_to_int(x);
472 test->pointer_y = wl_fixed_to_int(y);
473
474 fprintf(stderr, "test-client: got global pointer %d %d\n",
475 test->pointer_x, test->pointer_y);
476}
477
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000478static void
Derek Foremanf6a65922015-02-24 09:32:14 -0600479test_handle_n_egl_buffers(void *data, struct weston_test *weston_test, uint32_t n)
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000480{
481 struct test *test = data;
482
483 test->n_egl_buffers = n;
484}
485
Bryce Harrington692275f2015-04-23 16:33:49 -0700486static void
487test_handle_capture_screenshot_done(void *data, struct weston_test *weston_test)
488{
489 struct test *test = data;
490
491 printf("Screenshot has been captured\n");
492 test->buffer_copy_done = 1;
493}
494
Derek Foremanf6a65922015-02-24 09:32:14 -0600495static const struct weston_test_listener test_listener = {
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000496 test_handle_pointer_position,
497 test_handle_n_egl_buffers,
Bryce Harrington692275f2015-04-23 16:33:49 -0700498 test_handle_capture_screenshot_done,
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800499};
500
501static void
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400502input_update_devices(struct input *input)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800503{
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800504 struct pointer *pointer;
505 struct keyboard *keyboard;
Marek Chalupa8a5523c2015-03-30 09:20:07 -0400506 struct touch *touch;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800507
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400508 struct wl_seat *seat = input->wl_seat;
509 enum wl_seat_capability caps = input->caps;
510
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800511 if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700512 pointer = xzalloc(sizeof *pointer);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800513 pointer->wl_pointer = wl_seat_get_pointer(seat);
514 wl_pointer_set_user_data(pointer->wl_pointer, pointer);
515 wl_pointer_add_listener(pointer->wl_pointer, &pointer_listener,
516 pointer);
517 input->pointer = pointer;
518 } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
519 wl_pointer_destroy(input->pointer->wl_pointer);
520 free(input->pointer);
521 input->pointer = NULL;
522 }
523
524 if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) {
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700525 keyboard = xzalloc(sizeof *keyboard);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800526 keyboard->wl_keyboard = wl_seat_get_keyboard(seat);
527 wl_keyboard_set_user_data(keyboard->wl_keyboard, keyboard);
528 wl_keyboard_add_listener(keyboard->wl_keyboard, &keyboard_listener,
529 keyboard);
530 input->keyboard = keyboard;
531 } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) {
532 wl_keyboard_destroy(input->keyboard->wl_keyboard);
533 free(input->keyboard);
534 input->keyboard = NULL;
535 }
Marek Chalupa8a5523c2015-03-30 09:20:07 -0400536
537 if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->touch) {
538 touch = xzalloc(sizeof *touch);
539 touch->wl_touch = wl_seat_get_touch(seat);
540 wl_touch_set_user_data(touch->wl_touch, touch);
541 wl_touch_add_listener(touch->wl_touch, &touch_listener,
542 touch);
543 input->touch = touch;
544 } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->touch) {
545 wl_touch_destroy(input->touch->wl_touch);
546 free(input->touch);
547 input->touch = NULL;
548 }
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800549}
550
Marek Chalupa643d85f2015-03-30 06:37:56 -0400551static void
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400552seat_handle_capabilities(void *data, struct wl_seat *seat,
553 enum wl_seat_capability caps)
554{
555 struct input *input = data;
556
557 input->caps = caps;
558
559 /* we will create/update the devices only with the right (test) seat.
560 * If we haven't discovered which seat is the test seat, just
561 * store capabilities and bail out */
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300562 if (input->seat_name && strcmp(input->seat_name, "test-seat") == 0)
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400563 input_update_devices(input);
564
565 fprintf(stderr, "test-client: got seat %p capabilities: %x\n",
566 input, caps);
567}
568
569static void
Marek Chalupa643d85f2015-03-30 06:37:56 -0400570seat_handle_name(void *data, struct wl_seat *seat, const char *name)
571{
572 struct input *input = data;
573
574 input->seat_name = strdup(name);
575 assert(input->seat_name && "No memory");
576
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400577 fprintf(stderr, "test-client: got seat %p name: \'%s\'\n",
578 input, name);
Marek Chalupa643d85f2015-03-30 06:37:56 -0400579}
580
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800581static const struct wl_seat_listener seat_listener = {
582 seat_handle_capabilities,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400583 seat_handle_name,
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800584};
585
586static void
587output_handle_geometry(void *data,
588 struct wl_output *wl_output,
589 int x, int y,
590 int physical_width,
591 int physical_height,
592 int subpixel,
593 const char *make,
594 const char *model,
595 int32_t transform)
596{
597 struct output *output = data;
598
599 output->x = x;
600 output->y = y;
601}
602
603static void
604output_handle_mode(void *data,
605 struct wl_output *wl_output,
606 uint32_t flags,
607 int width,
608 int height,
609 int refresh)
610{
611 struct output *output = data;
612
613 if (flags & WL_OUTPUT_MODE_CURRENT) {
614 output->width = width;
615 output->height = height;
616 }
617}
618
Marek Chalupa643d85f2015-03-30 06:37:56 -0400619static void
620output_handle_scale(void *data,
621 struct wl_output *wl_output,
622 int scale)
623{
624 struct output *output = data;
625
626 output->scale = scale;
627}
628
629static void
630output_handle_done(void *data,
631 struct wl_output *wl_output)
632{
633 struct output *output = data;
634
635 output->initialized = 1;
636}
637
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800638static const struct wl_output_listener output_listener = {
639 output_handle_geometry,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400640 output_handle_mode,
641 output_handle_done,
642 output_handle_scale,
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800643};
644
645static void
646handle_global(void *data, struct wl_registry *registry,
647 uint32_t id, const char *interface, uint32_t version)
648{
649 struct client *client = data;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800650 struct output *output;
651 struct test *test;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500652 struct global *global;
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400653 struct input *input;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500654
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700655 global = xzalloc(sizeof *global);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500656 global->name = id;
657 global->interface = strdup(interface);
658 assert(interface);
659 global->version = version;
660 wl_list_insert(client->global_list.prev, &global->link);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800661
662 if (strcmp(interface, "wl_compositor") == 0) {
663 client->wl_compositor =
664 wl_registry_bind(registry, id,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400665 &wl_compositor_interface, version);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800666 } else if (strcmp(interface, "wl_seat") == 0) {
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700667 input = xzalloc(sizeof *input);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800668 input->wl_seat =
669 wl_registry_bind(registry, id,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400670 &wl_seat_interface, version);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800671 wl_seat_add_listener(input->wl_seat, &seat_listener, input);
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400672 wl_list_insert(&client->inputs, &input->link);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800673 } else if (strcmp(interface, "wl_shm") == 0) {
674 client->wl_shm =
675 wl_registry_bind(registry, id,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400676 &wl_shm_interface, version);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800677 wl_shm_add_listener(client->wl_shm, &shm_listener, client);
678 } else if (strcmp(interface, "wl_output") == 0) {
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700679 output = xzalloc(sizeof *output);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800680 output->wl_output =
681 wl_registry_bind(registry, id,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400682 &wl_output_interface, version);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800683 wl_output_add_listener(output->wl_output,
684 &output_listener, output);
685 client->output = output;
Derek Foremanf6a65922015-02-24 09:32:14 -0600686 } else if (strcmp(interface, "weston_test") == 0) {
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700687 test = xzalloc(sizeof *test);
Derek Foremanf6a65922015-02-24 09:32:14 -0600688 test->weston_test =
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800689 wl_registry_bind(registry, id,
Marek Chalupa643d85f2015-03-30 06:37:56 -0400690 &weston_test_interface, version);
Derek Foremanf6a65922015-02-24 09:32:14 -0600691 weston_test_add_listener(test->weston_test, &test_listener, test);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800692 client->test = test;
Derek Foreman9bb13392015-01-23 12:12:36 -0600693 } else if (strcmp(interface, "wl_drm") == 0) {
694 client->has_wl_drm = true;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800695 }
696}
697
698static const struct wl_registry_listener registry_listener = {
699 handle_global
700};
701
Kristian Høgsberg42284f52014-01-01 17:38:04 -0800702void
703skip(const char *fmt, ...)
704{
705 va_list argp;
706
707 va_start(argp, fmt);
708 vfprintf(stderr, fmt, argp);
709 va_end(argp);
710
Emilio Pozuelo Monfortdae8a4b2014-02-07 09:34:48 +0100711 /* automake tests uses exit code 77. weston-test-runner will see
712 * this and use it, and then weston-test's sigchld handler (in the
713 * weston process) will use that as an exit status, which is what
714 * automake will see in the end. */
715 exit(77);
Kristian Høgsberg42284f52014-01-01 17:38:04 -0800716}
717
Marek Chalupa4d06d462014-07-16 11:27:06 +0200718void
719expect_protocol_error(struct client *client,
720 const struct wl_interface *intf,
721 uint32_t code)
722{
723 int err;
724 uint32_t errcode, failed = 0;
725 const struct wl_interface *interface;
726 unsigned int id;
727
728 /* if the error has not come yet, make it happen */
729 wl_display_roundtrip(client->wl_display);
730
731 err = wl_display_get_error(client->wl_display);
732
733 assert(err && "Expected protocol error but nothing came");
734 assert(err == EPROTO && "Expected protocol error but got local error");
735
736 errcode = wl_display_get_protocol_error(client->wl_display,
737 &interface, &id);
738
739 /* check error */
740 if (errcode != code) {
741 fprintf(stderr, "Should get error code %d but got %d\n",
742 code, errcode);
743 failed = 1;
744 }
745
746 /* this should be definitely set */
747 assert(interface);
748
749 if (strcmp(intf->name, interface->name) != 0) {
750 fprintf(stderr, "Should get interface '%s' but got '%s'\n",
751 intf->name, interface->name);
752 failed = 1;
753 }
754
755 if (failed) {
756 fprintf(stderr, "Expected other protocol error\n");
757 abort();
758 }
759
760 /* all OK */
761 fprintf(stderr, "Got expected protocol error on '%s' (object id: %d) "
762 "with code %d\n", interface->name, id, errcode);
763}
764
Pekka Paalanen07921d72012-12-12 14:26:40 +0200765static void
766log_handler(const char *fmt, va_list args)
767{
768 fprintf(stderr, "libwayland: ");
769 vfprintf(stderr, fmt, args);
770}
771
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400772static void
773input_destroy(struct input *inp)
774{
775 wl_list_remove(&inp->link);
776 wl_seat_destroy(inp->wl_seat);
777 free(inp);
778}
779
780/* find the test-seat and set it in client.
781 * Destroy other inputs */
782static void
783client_set_input(struct client *cl)
784{
785 struct input *inp, *inptmp;
786 wl_list_for_each_safe(inp, inptmp, &cl->inputs, link) {
787 assert(inp->seat_name && "BUG: input with no name");
788 if (strcmp(inp->seat_name, "test-seat") == 0) {
789 cl->input = inp;
790 input_update_devices(inp);
791 } else {
792 input_destroy(inp);
793 }
794 }
795
796 /* we keep only one input */
797 assert(wl_list_length(&cl->inputs) == 1);
798}
799
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800800struct client *
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200801create_client(void)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800802{
803 struct client *client;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800804
Pekka Paalanen07921d72012-12-12 14:26:40 +0200805 wl_log_set_handler_client(log_handler);
806
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800807 /* connect to display */
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700808 client = xzalloc(sizeof *client);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800809 client->wl_display = wl_display_connect(NULL);
810 assert(client->wl_display);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500811 wl_list_init(&client->global_list);
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400812 wl_list_init(&client->inputs);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800813
814 /* setup registry so we can bind to interfaces */
815 client->wl_registry = wl_display_get_registry(client->wl_display);
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200816 wl_registry_add_listener(client->wl_registry, &registry_listener,
817 client);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800818
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400819 /* this roundtrip makes sure we have all globals and we bound to them */
820 client_roundtrip(client);
821 /* this roundtrip makes sure we got all wl_shm.format and wl_seat.*
822 * events */
823 client_roundtrip(client);
824
825 /* find the right input for us */
826 client_set_input(client);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800827
828 /* must have WL_SHM_FORMAT_ARGB32 */
829 assert(client->has_argb);
830
Derek Foremanf6a65922015-02-24 09:32:14 -0600831 /* must have weston_test interface */
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800832 assert(client->test);
833
834 /* must have an output */
835 assert(client->output);
836
Marek Chalupa643d85f2015-03-30 06:37:56 -0400837 /* the output must be initialized */
838 assert(client->output->initialized == 1);
839
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400840 /* must have seat set */
841 assert(client->input);
842
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200843 return client;
844}
845
846struct client *
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200847create_client_and_test_surface(int x, int y, int width, int height)
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200848{
849 struct client *client;
850 struct surface *surface;
851
852 client = create_client();
853
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800854 /* initialize the client surface */
Kristian Høgsbergc1b244f2013-10-09 14:01:23 -0700855 surface = xzalloc(sizeof *surface);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800856 surface->wl_surface =
857 wl_compositor_create_surface(client->wl_compositor);
858 assert(surface->wl_surface);
859
860 wl_surface_add_listener(surface->wl_surface, &surface_listener,
861 surface);
862
863 client->surface = surface;
864 wl_surface_set_user_data(surface->wl_surface, surface);
865
866 surface->width = width;
867 surface->height = height;
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200868 surface->wl_buffer = create_shm_buffer(client, width, height,
869 &surface->data);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800870
871 memset(surface->data, 64, width * height * 4);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800872
873 move_client(client, x, y);
874
875 return client;
876}
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800877
878static const char*
Bryce Harrington3835d052015-05-18 17:47:13 -0700879output_path(void)
880{
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800881 char *path = getenv("WESTON_TEST_OUTPUT_PATH");
882
883 if (!path)
884 return ".";
885 return path;
886 }
887
888char*
Bryce Harrington3835d052015-05-18 17:47:13 -0700889screenshot_output_filename(const char *basename, uint32_t seq)
890{
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800891 char *filename;
892
893 if (asprintf(&filename, "%s/%s-%02d.png",
894 output_path(), basename, seq) < 0)
895 return NULL;
896 return filename;
897}
898
899static const char*
Bryce Harrington3835d052015-05-18 17:47:13 -0700900reference_path(void)
901{
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800902 char *path = getenv("WESTON_TEST_REFERENCE_PATH");
903
904 if (!path)
905 return "./tests/reference";
906 return path;
907}
908
909char*
Bryce Harrington3835d052015-05-18 17:47:13 -0700910screenshot_reference_filename(const char *basename, uint32_t seq)
911{
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800912 char *filename;
913
914 if (asprintf(&filename, "%s/%s-%02d.png",
915 reference_path(), basename, seq) < 0)
916 return NULL;
917 return filename;
918}
Bryce Harrington273c2852014-12-15 15:51:25 -0800919
920/**
Bryce Harrington39a5be22015-05-14 14:36:18 -0700921 * check_surfaces_geometry() - verifies two surfaces are same size
922 *
923 * @returns true if surfaces have the same width and height, or false
924 * if not, or if there is no actual data.
925 */
926bool
927check_surfaces_geometry(const struct surface *a, const struct surface *b)
928{
929 if (a == NULL || b == NULL) {
930 printf("Undefined surfaces\n");
931 return false;
932 }
933 else if (a->data == NULL || b->data == NULL) {
934 printf("Undefined data\n");
935 return false;
936 }
937 else if (a->width != b->width || a->height != b->height) {
938 printf("Mismatched dimensions: %d,%d != %d,%d\n",
939 a->width, a->height, b->width, b->height);
940 return false;
941 }
942 return true;
943}
944
945/**
Bryce Harrington273c2852014-12-15 15:51:25 -0800946 * check_surfaces_equal() - tests if two surfaces are pixel-identical
947 *
948 * Returns true if surface buffers have all the same byte values,
949 * false if the surfaces don't match or can't be compared due to
950 * different dimensions.
951 */
952bool
953check_surfaces_equal(const struct surface *a, const struct surface *b)
954{
955 int bpp = 4; /* Assumes ARGB */
956
Bryce Harrington39a5be22015-05-14 14:36:18 -0700957 if (!check_surfaces_geometry(a, b))
Bryce Harrington273c2852014-12-15 15:51:25 -0800958 return false;
959
960 return (memcmp(a->data, b->data, bpp * a->width * a->height) == 0);
961}
962
963/**
964 * check_surfaces_match_in_clip() - tests if a given region within two
965 * surfaces are pixel-identical.
966 *
967 * Returns true if the two surfaces have the same byte values within the
968 * given clipping region, or false if they don't match or the surfaces
969 * can't be compared.
970 */
971bool
972check_surfaces_match_in_clip(const struct surface *a, const struct surface *b, const struct rectangle *clip_rect)
973{
974 int i, j;
975 int x0, y0, x1, y1;
976 void *p, *q;
977 int bpp = 4; /* Assumes ARGB */
978
Bryce Harrington39a5be22015-05-14 14:36:18 -0700979 if (!check_surfaces_geometry(a, b) || clip_rect == NULL)
Bryce Harrington273c2852014-12-15 15:51:25 -0800980 return false;
981
Bryce Harrington273c2852014-12-15 15:51:25 -0800982 if (clip_rect->x > a->width || clip_rect->y > a->height) {
983 printf("Clip outside image boundaries\n");
984 return true;
985 }
986
987 x0 = max(0, clip_rect->x);
988 y0 = max(0, clip_rect->y);
989 x1 = min(a->width, clip_rect->x + clip_rect->width);
990 y1 = min(a->height, clip_rect->y + clip_rect->height);
991
992 if (x0 == x1 || y0 == y1) {
993 printf("Degenerate comparison\n");
994 return true;
995 }
996
997 printf("Bytewise comparison inside clip\n");
998 for (i=y0; i<y1; i++) {
999 p = a->data + i * a->width * bpp + x0 * bpp;
1000 q = b->data + i * b->width * bpp + x0 * bpp;
1001 if (memcmp(p, q, (x1-x0)*bpp) != 0) {
1002 /* Dump the bad row */
1003 printf("Mismatched image on row %d\n", i);
1004 for (j=0; j<(x1-x0)*bpp; j++) {
1005 char a_char = *((char*)(p+j*bpp));
1006 char b_char = *((char*)(q+j*bpp));
1007 printf("%d,%d: %8x %8x %s\n", i, j, a_char, b_char,
1008 (a_char != b_char)? " <---": "");
1009 }
1010 return false;
1011 }
1012 }
1013
1014 return true;
1015}
Bryce Harrington892122e2015-09-24 14:31:44 -07001016
1017/** write_surface_as_png()
1018 *
1019 * Writes out a given weston test surface to disk as a PNG image
1020 * using the provided filename (with path).
1021 *
1022 * @returns true if successfully saved file; false otherwise.
1023 */
1024bool
1025write_surface_as_png(const struct surface *weston_surface, const char *fname)
1026{
1027 cairo_surface_t *cairo_surface;
1028 cairo_status_t status;
1029 int bpp = 4; /* Assume ARGB */
1030 int stride = bpp * weston_surface->width;
1031
1032 cairo_surface = cairo_image_surface_create_for_data(weston_surface->data,
1033 CAIRO_FORMAT_ARGB32,
1034 weston_surface->width,
1035 weston_surface->height,
1036 stride);
1037 printf("Writing PNG to disk\n");
1038 status = cairo_surface_write_to_png(cairo_surface, fname);
1039 if (status != CAIRO_STATUS_SUCCESS) {
1040 printf("Failed to save screenshot: %s\n",
1041 cairo_status_to_string(status));
1042 return false;
1043 }
1044 cairo_surface_destroy(cairo_surface);
1045 return true;
1046}
1047
1048/** load_surface_from_png()
1049 *
1050 * Reads a PNG image from disk using the given filename (and path)
1051 * and returns as a freshly allocated weston test surface.
1052 *
1053 * @returns weston test surface with image, which should be free'd
1054 * when no longer used; or, NULL in case of error.
1055 */
1056struct surface *
1057load_surface_from_png(const char *fname)
1058{
1059 struct surface *reference;
1060 cairo_surface_t *reference_cairo_surface;
1061 cairo_status_t status;
1062 size_t source_data_size;
1063 int bpp;
1064 int stride;
1065
1066 reference_cairo_surface = cairo_image_surface_create_from_png(fname);
1067 status = cairo_surface_status(reference_cairo_surface);
1068 if (status != CAIRO_STATUS_SUCCESS) {
1069 printf("Could not open %s: %s\n", fname, cairo_status_to_string(status));
1070 cairo_surface_destroy(reference_cairo_surface);
1071 return NULL;
1072 }
1073
1074 /* Disguise the cairo surface in a weston test surface */
1075 reference = zalloc(sizeof *reference);
1076 if (reference == NULL) {
1077 perror("zalloc reference");
1078 cairo_surface_destroy(reference_cairo_surface);
1079 return NULL;
1080 }
1081 reference->width = cairo_image_surface_get_width(reference_cairo_surface);
1082 reference->height = cairo_image_surface_get_height(reference_cairo_surface);
1083 stride = cairo_image_surface_get_stride(reference_cairo_surface);
1084 source_data_size = stride * reference->height;
1085
1086 /* Check that the file's stride matches our assumption */
1087 bpp = 4;
1088 if (stride != bpp * reference->width) {
1089 printf("Mismatched stride for screenshot reference image %s\n", fname);
1090 cairo_surface_destroy(reference_cairo_surface);
1091 free(reference);
1092 return NULL;
1093 }
1094
1095 /* Allocate new buffer for our weston reference, and copy the data from
1096 the cairo surface so we can destroy it */
1097 reference->data = zalloc(source_data_size);
1098 if (reference->data == NULL) {
1099 perror("zalloc reference data");
1100 cairo_surface_destroy(reference_cairo_surface);
1101 free(reference);
1102 return NULL;
1103 }
1104 memcpy(reference->data,
1105 cairo_image_surface_get_data(reference_cairo_surface),
1106 source_data_size);
1107
1108 cairo_surface_destroy(reference_cairo_surface);
1109 return reference;
1110}
1111
1112/** create_screenshot_surface()
1113 *
1114 * Allocates and initializes a weston test surface for use in
1115 * storing a screenshot of the client's output. Establishes a
1116 * shm backed wl_buffer for retrieving screenshot image data
1117 * from the server, sized to match the client's output display.
1118 *
1119 * @returns stack allocated surface image, which should be
1120 * free'd when done using it.
1121 */
1122struct surface *
1123create_screenshot_surface(struct client *client)
1124{
1125 struct surface *screenshot;
1126 screenshot = zalloc(sizeof *screenshot);
1127 if (screenshot == NULL)
1128 return NULL;
1129 screenshot->wl_buffer = create_shm_buffer(client,
1130 client->output->width,
1131 client->output->height,
1132 &screenshot->data);
1133 screenshot->height = client->output->height;
1134 screenshot->width = client->output->width;
1135
1136 return screenshot;
1137}
1138
1139/** capture_screenshot_of_output()
1140 *
1141 * Requests a screenshot from the server of the output that the
1142 * client appears on. The image data returned from the server
1143 * can be accessed from the screenshot surface's data member.
1144 *
1145 * @returns a new surface object, which should be free'd when no
1146 * longer needed.
1147 */
1148struct surface *
1149capture_screenshot_of_output(struct client *client)
1150{
1151 struct surface *screenshot;
1152
1153 /* Create a surface to hold the screenshot */
1154 screenshot = create_screenshot_surface(client);
1155
1156 client->test->buffer_copy_done = 0;
1157 weston_test_capture_screenshot(client->test->weston_test,
1158 client->output->wl_output,
1159 screenshot->wl_buffer);
1160 while (client->test->buffer_copy_done == 0)
1161 if (wl_display_dispatch(client->wl_display) < 0)
1162 break;
1163
1164 /* FIXME: Document somewhere the orientation the screenshot is taken
1165 * and how the clip coords are interpreted, in case of scaling/transform.
1166 * If we're using read_pixels() just make sure it is documented somewhere.
1167 * Protocol docs in the XML, comparison function docs in Doxygen style.
1168 */
1169
1170 return screenshot;
1171}