U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and its |
| 5 | * documentation for any purpose is hereby granted without fee, provided that |
| 6 | * the above copyright notice appear in all copies and that both that copyright |
| 7 | * notice and this permission notice appear in supporting documentation, and |
| 8 | * that the name of the copyright holders not be used in advertising or |
| 9 | * publicity pertaining to distribution of the software without specific, |
| 10 | * written prior permission. The copyright holders make no representations |
| 11 | * about the suitability of this software for any purpose. It is provided "as |
| 12 | * is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 16 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 20 | * OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
Bryce Harrington | 12cc405 | 2014-11-19 17:18:33 -0800 | [diff] [blame] | 23 | #include "config.h" |
Kristian Høgsberg | c7d2c4c | 2013-08-26 14:43:17 -0700 | [diff] [blame] | 24 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 25 | #include <stdlib.h> |
| 26 | #include <stdio.h> |
| 27 | #include <string.h> |
| 28 | #include <unistd.h> |
Marek Chalupa | 4d06d46 | 2014-07-16 11:27:06 +0200 | [diff] [blame] | 29 | #include <errno.h> |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 30 | #include <sys/mman.h> |
| 31 | |
| 32 | #include "../shared/os-compatibility.h" |
| 33 | #include "weston-test-client-helper.h" |
| 34 | |
Bryce Harrington | 61a6436 | 2015-04-22 18:23:01 -0700 | [diff] [blame^] | 35 | void * |
| 36 | fail_on_null(void *p) |
| 37 | { |
| 38 | if (p == NULL) { |
| 39 | fprintf(stderr, "out of memory\n"); |
| 40 | exit(EXIT_FAILURE); |
| 41 | } |
| 42 | return p; |
| 43 | } |
| 44 | |
| 45 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 46 | int |
| 47 | surface_contains(struct surface *surface, int x, int y) |
| 48 | { |
| 49 | /* test whether a global x,y point is contained in the surface */ |
| 50 | int sx = surface->x; |
| 51 | int sy = surface->y; |
| 52 | int sw = surface->width; |
| 53 | int sh = surface->height; |
| 54 | return x >= sx && y >= sy && x < sx + sw && y < sy + sh; |
| 55 | } |
| 56 | |
Kristian Høgsberg | db6dc7d | 2012-12-11 21:49:13 -0500 | [diff] [blame] | 57 | static void |
Pekka Paalanen | 8aaef7d | 2013-02-08 17:01:25 +0200 | [diff] [blame] | 58 | frame_callback_handler(void *data, struct wl_callback *callback, uint32_t time) |
Kristian Høgsberg | db6dc7d | 2012-12-11 21:49:13 -0500 | [diff] [blame] | 59 | { |
| 60 | int *done = data; |
| 61 | |
| 62 | *done = 1; |
| 63 | |
| 64 | wl_callback_destroy(callback); |
| 65 | } |
| 66 | |
| 67 | static const struct wl_callback_listener frame_listener = { |
Pekka Paalanen | 8aaef7d | 2013-02-08 17:01:25 +0200 | [diff] [blame] | 68 | frame_callback_handler |
Kristian Høgsberg | db6dc7d | 2012-12-11 21:49:13 -0500 | [diff] [blame] | 69 | }; |
| 70 | |
Pekka Paalanen | 8aaef7d | 2013-02-08 17:01:25 +0200 | [diff] [blame] | 71 | struct wl_callback * |
| 72 | frame_callback_set(struct wl_surface *surface, int *done) |
| 73 | { |
| 74 | struct wl_callback *callback; |
| 75 | |
| 76 | *done = 0; |
| 77 | callback = wl_surface_frame(surface); |
| 78 | wl_callback_add_listener(callback, &frame_listener, done); |
| 79 | |
| 80 | return callback; |
| 81 | } |
| 82 | |
Marek Chalupa | 1740aa8 | 2014-07-16 11:32:50 +0200 | [diff] [blame] | 83 | int |
| 84 | frame_callback_wait_nofail(struct client *client, int *done) |
Pekka Paalanen | 8aaef7d | 2013-02-08 17:01:25 +0200 | [diff] [blame] | 85 | { |
| 86 | while (!*done) { |
Marek Chalupa | 1740aa8 | 2014-07-16 11:32:50 +0200 | [diff] [blame] | 87 | if (wl_display_dispatch(client->wl_display) < 0) |
| 88 | return 0; |
Pekka Paalanen | 8aaef7d | 2013-02-08 17:01:25 +0200 | [diff] [blame] | 89 | } |
Marek Chalupa | 1740aa8 | 2014-07-16 11:32:50 +0200 | [diff] [blame] | 90 | |
| 91 | return 1; |
Pekka Paalanen | 8aaef7d | 2013-02-08 17:01:25 +0200 | [diff] [blame] | 92 | } |
| 93 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 94 | void |
| 95 | move_client(struct client *client, int x, int y) |
| 96 | { |
| 97 | struct surface *surface = client->surface; |
Kristian Høgsberg | db6dc7d | 2012-12-11 21:49:13 -0500 | [diff] [blame] | 98 | int done; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 99 | |
| 100 | client->surface->x = x; |
| 101 | client->surface->y = y; |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 102 | weston_test_move_surface(client->test->weston_test, surface->wl_surface, |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 103 | surface->x, surface->y); |
Bryce Harrington | cb50ed2 | 2014-12-10 18:33:47 -0800 | [diff] [blame] | 104 | /* The attach here is necessary because commit() will call configure |
Giulio Camuffo | 82cb505 | 2013-02-28 18:44:54 +0100 | [diff] [blame] | 105 | * only on surfaces newly attached, and the one that sets the surface |
| 106 | * position is the configure. */ |
| 107 | wl_surface_attach(surface->wl_surface, surface->wl_buffer, 0, 0); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 108 | wl_surface_damage(surface->wl_surface, 0, 0, surface->width, |
| 109 | surface->height); |
Kristian Høgsberg | db6dc7d | 2012-12-11 21:49:13 -0500 | [diff] [blame] | 110 | |
Pekka Paalanen | 8aaef7d | 2013-02-08 17:01:25 +0200 | [diff] [blame] | 111 | frame_callback_set(surface->wl_surface, &done); |
Kristian Høgsberg | db6dc7d | 2012-12-11 21:49:13 -0500 | [diff] [blame] | 112 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 113 | wl_surface_commit(surface->wl_surface); |
| 114 | |
Pekka Paalanen | 8aaef7d | 2013-02-08 17:01:25 +0200 | [diff] [blame] | 115 | frame_callback_wait(client, &done); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Neil Roberts | 40c0c3f | 2013-10-29 20:13:45 +0000 | [diff] [blame] | 118 | int |
| 119 | get_n_egl_buffers(struct client *client) |
| 120 | { |
| 121 | client->test->n_egl_buffers = -1; |
| 122 | |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 123 | weston_test_get_n_egl_buffers(client->test->weston_test); |
Neil Roberts | 40c0c3f | 2013-10-29 20:13:45 +0000 | [diff] [blame] | 124 | wl_display_roundtrip(client->wl_display); |
| 125 | |
| 126 | return client->test->n_egl_buffers; |
| 127 | } |
| 128 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 129 | static void |
| 130 | pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, |
| 131 | uint32_t serial, struct wl_surface *wl_surface, |
| 132 | wl_fixed_t x, wl_fixed_t y) |
| 133 | { |
| 134 | struct pointer *pointer = data; |
| 135 | |
| 136 | pointer->focus = wl_surface_get_user_data(wl_surface); |
| 137 | pointer->x = wl_fixed_to_int(x); |
| 138 | pointer->y = wl_fixed_to_int(y); |
| 139 | |
| 140 | fprintf(stderr, "test-client: got pointer enter %d %d, surface %p\n", |
| 141 | pointer->x, pointer->y, pointer->focus); |
| 142 | } |
| 143 | |
| 144 | static void |
| 145 | pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, |
| 146 | uint32_t serial, struct wl_surface *wl_surface) |
| 147 | { |
| 148 | struct pointer *pointer = data; |
| 149 | |
| 150 | pointer->focus = NULL; |
| 151 | |
| 152 | fprintf(stderr, "test-client: got pointer leave, surface %p\n", |
| 153 | wl_surface_get_user_data(wl_surface)); |
| 154 | } |
| 155 | |
| 156 | static void |
| 157 | pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, |
| 158 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
| 159 | { |
| 160 | struct pointer *pointer = data; |
| 161 | |
| 162 | pointer->x = wl_fixed_to_int(x); |
| 163 | pointer->y = wl_fixed_to_int(y); |
| 164 | |
| 165 | fprintf(stderr, "test-client: got pointer motion %d %d\n", |
| 166 | pointer->x, pointer->y); |
| 167 | } |
| 168 | |
| 169 | static void |
| 170 | pointer_handle_button(void *data, struct wl_pointer *wl_pointer, |
| 171 | uint32_t serial, uint32_t time, uint32_t button, |
| 172 | uint32_t state) |
| 173 | { |
| 174 | struct pointer *pointer = data; |
| 175 | |
| 176 | pointer->button = button; |
| 177 | pointer->state = state; |
| 178 | |
| 179 | fprintf(stderr, "test-client: got pointer button %u %u\n", |
| 180 | button, state); |
| 181 | } |
| 182 | |
| 183 | static void |
| 184 | pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, |
| 185 | uint32_t time, uint32_t axis, wl_fixed_t value) |
| 186 | { |
Kristian Høgsberg | 4c8ce20 | 2013-10-09 14:23:00 -0700 | [diff] [blame] | 187 | fprintf(stderr, "test-client: got pointer axis %u %f\n", |
| 188 | axis, wl_fixed_to_double(value)); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | static const struct wl_pointer_listener pointer_listener = { |
| 192 | pointer_handle_enter, |
| 193 | pointer_handle_leave, |
| 194 | pointer_handle_motion, |
| 195 | pointer_handle_button, |
| 196 | pointer_handle_axis, |
| 197 | }; |
| 198 | |
| 199 | static void |
| 200 | keyboard_handle_keymap(void *data, struct wl_keyboard *wl_keyboard, |
| 201 | uint32_t format, int fd, uint32_t size) |
| 202 | { |
| 203 | close(fd); |
| 204 | |
| 205 | fprintf(stderr, "test-client: got keyboard keymap\n"); |
| 206 | } |
| 207 | |
| 208 | static void |
| 209 | keyboard_handle_enter(void *data, struct wl_keyboard *wl_keyboard, |
| 210 | uint32_t serial, struct wl_surface *wl_surface, |
| 211 | struct wl_array *keys) |
| 212 | { |
| 213 | struct keyboard *keyboard = data; |
| 214 | |
| 215 | keyboard->focus = wl_surface_get_user_data(wl_surface); |
| 216 | |
| 217 | fprintf(stderr, "test-client: got keyboard enter, surface %p\n", |
| 218 | keyboard->focus); |
| 219 | } |
| 220 | |
| 221 | static void |
| 222 | keyboard_handle_leave(void *data, struct wl_keyboard *wl_keyboard, |
| 223 | uint32_t serial, struct wl_surface *wl_surface) |
| 224 | { |
| 225 | struct keyboard *keyboard = data; |
| 226 | |
| 227 | keyboard->focus = NULL; |
| 228 | |
| 229 | fprintf(stderr, "test-client: got keyboard leave, surface %p\n", |
| 230 | wl_surface_get_user_data(wl_surface)); |
| 231 | } |
| 232 | |
| 233 | static void |
| 234 | keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard, |
| 235 | uint32_t serial, uint32_t time, uint32_t key, |
| 236 | uint32_t state) |
| 237 | { |
| 238 | struct keyboard *keyboard = data; |
| 239 | |
| 240 | keyboard->key = key; |
| 241 | keyboard->state = state; |
| 242 | |
| 243 | fprintf(stderr, "test-client: got keyboard key %u %u\n", key, state); |
| 244 | } |
| 245 | |
| 246 | static void |
| 247 | keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard, |
| 248 | uint32_t serial, uint32_t mods_depressed, |
| 249 | uint32_t mods_latched, uint32_t mods_locked, |
| 250 | uint32_t group) |
| 251 | { |
| 252 | struct keyboard *keyboard = data; |
| 253 | |
| 254 | keyboard->mods_depressed = mods_depressed; |
| 255 | keyboard->mods_latched = mods_latched; |
| 256 | keyboard->mods_locked = mods_locked; |
| 257 | keyboard->group = group; |
| 258 | |
| 259 | fprintf(stderr, "test-client: got keyboard modifiers %u %u %u %u\n", |
| 260 | mods_depressed, mods_latched, mods_locked, group); |
| 261 | } |
| 262 | |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 263 | static void |
| 264 | keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard, |
| 265 | int32_t rate, int32_t delay) |
| 266 | { |
| 267 | struct keyboard *keyboard = data; |
| 268 | |
| 269 | keyboard->repeat_info.rate = rate; |
| 270 | keyboard->repeat_info.delay = delay; |
| 271 | |
| 272 | fprintf(stderr, "test-client: got keyboard repeat_info %d %d\n", |
| 273 | rate, delay); |
| 274 | } |
| 275 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 276 | static const struct wl_keyboard_listener keyboard_listener = { |
| 277 | keyboard_handle_keymap, |
| 278 | keyboard_handle_enter, |
| 279 | keyboard_handle_leave, |
| 280 | keyboard_handle_key, |
| 281 | keyboard_handle_modifiers, |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 282 | keyboard_handle_repeat_info, |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | static void |
Marek Chalupa | 8a5523c | 2015-03-30 09:20:07 -0400 | [diff] [blame] | 286 | touch_handle_down(void *data, struct wl_touch *wl_touch, |
| 287 | uint32_t serial, uint32_t time, struct wl_surface *surface, |
| 288 | int32_t id, wl_fixed_t x_w, wl_fixed_t y_w) |
| 289 | { |
| 290 | struct touch *touch = data; |
| 291 | |
| 292 | touch->down_x = wl_fixed_to_int(x_w); |
| 293 | touch->down_y = wl_fixed_to_int(y_w); |
| 294 | touch->id = id; |
| 295 | |
| 296 | fprintf(stderr, "test-client: got touch down %d %d, surf: %p, id: %d\n", |
| 297 | touch->down_x, touch->down_y, surface, id); |
| 298 | } |
| 299 | |
| 300 | static void |
| 301 | touch_handle_up(void *data, struct wl_touch *wl_touch, |
| 302 | uint32_t serial, uint32_t time, int32_t id) |
| 303 | { |
| 304 | struct touch *touch = data; |
| 305 | touch->up_id = id; |
| 306 | |
| 307 | fprintf(stderr, "test-client: got touch up, id: %d\n", id); |
| 308 | } |
| 309 | |
| 310 | static void |
| 311 | touch_handle_motion(void *data, struct wl_touch *wl_touch, |
| 312 | uint32_t time, int32_t id, wl_fixed_t x_w, wl_fixed_t y_w) |
| 313 | { |
| 314 | struct touch *touch = data; |
| 315 | touch->x = wl_fixed_to_int(x_w); |
| 316 | touch->y = wl_fixed_to_int(y_w); |
| 317 | |
| 318 | fprintf(stderr, "test-client: got touch motion, %d %d, id: %d\n", |
| 319 | touch->x, touch->y, id); |
| 320 | } |
| 321 | |
| 322 | static void |
| 323 | touch_handle_frame(void *data, struct wl_touch *wl_touch) |
| 324 | { |
| 325 | struct touch *touch = data; |
| 326 | |
| 327 | ++touch->frame_no; |
| 328 | |
| 329 | fprintf(stderr, "test-client: got touch frame (%d)\n", touch->frame_no); |
| 330 | } |
| 331 | |
| 332 | static void |
| 333 | touch_handle_cancel(void *data, struct wl_touch *wl_touch) |
| 334 | { |
| 335 | struct touch *touch = data; |
| 336 | |
| 337 | ++touch->cancel_no; |
| 338 | |
| 339 | fprintf(stderr, "test-client: got touch cancel (%d)\n", touch->cancel_no); |
| 340 | } |
| 341 | |
| 342 | static const struct wl_touch_listener touch_listener = { |
| 343 | touch_handle_down, |
| 344 | touch_handle_up, |
| 345 | touch_handle_motion, |
| 346 | touch_handle_frame, |
| 347 | touch_handle_cancel, |
| 348 | }; |
| 349 | |
| 350 | static void |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 351 | surface_enter(void *data, |
| 352 | struct wl_surface *wl_surface, struct wl_output *output) |
| 353 | { |
| 354 | struct surface *surface = data; |
| 355 | |
| 356 | surface->output = wl_output_get_user_data(output); |
| 357 | |
| 358 | fprintf(stderr, "test-client: got surface enter output %p\n", |
| 359 | surface->output); |
| 360 | } |
| 361 | |
| 362 | static void |
| 363 | surface_leave(void *data, |
| 364 | struct wl_surface *wl_surface, struct wl_output *output) |
| 365 | { |
| 366 | struct surface *surface = data; |
| 367 | |
| 368 | surface->output = NULL; |
| 369 | |
| 370 | fprintf(stderr, "test-client: got surface leave output %p\n", |
| 371 | wl_output_get_user_data(output)); |
| 372 | } |
| 373 | |
| 374 | static const struct wl_surface_listener surface_listener = { |
| 375 | surface_enter, |
| 376 | surface_leave |
| 377 | }; |
| 378 | |
Pekka Paalanen | 32ac9b9 | 2013-02-08 17:01:26 +0200 | [diff] [blame] | 379 | struct wl_buffer * |
| 380 | create_shm_buffer(struct client *client, int width, int height, void **pixels) |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 381 | { |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 382 | struct wl_shm *shm = client->wl_shm; |
Pekka Paalanen | 32ac9b9 | 2013-02-08 17:01:26 +0200 | [diff] [blame] | 383 | int stride = width * 4; |
| 384 | int size = stride * height; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 385 | struct wl_shm_pool *pool; |
Pekka Paalanen | 32ac9b9 | 2013-02-08 17:01:26 +0200 | [diff] [blame] | 386 | struct wl_buffer *buffer; |
| 387 | int fd; |
| 388 | void *data; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 389 | |
| 390 | fd = os_create_anonymous_file(size); |
| 391 | assert(fd >= 0); |
| 392 | |
Pekka Paalanen | 32ac9b9 | 2013-02-08 17:01:26 +0200 | [diff] [blame] | 393 | data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
| 394 | if (data == MAP_FAILED) { |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 395 | close(fd); |
Pekka Paalanen | 32ac9b9 | 2013-02-08 17:01:26 +0200 | [diff] [blame] | 396 | assert(data != MAP_FAILED); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | pool = wl_shm_create_pool(shm, fd, size); |
Pekka Paalanen | 32ac9b9 | 2013-02-08 17:01:26 +0200 | [diff] [blame] | 400 | buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride, |
| 401 | WL_SHM_FORMAT_ARGB8888); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 402 | wl_shm_pool_destroy(pool); |
| 403 | |
| 404 | close(fd); |
Pekka Paalanen | 32ac9b9 | 2013-02-08 17:01:26 +0200 | [diff] [blame] | 405 | |
| 406 | if (pixels) |
| 407 | *pixels = data; |
| 408 | |
| 409 | return buffer; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | static void |
| 413 | shm_format(void *data, struct wl_shm *wl_shm, uint32_t format) |
| 414 | { |
| 415 | struct client *client = data; |
| 416 | |
| 417 | if (format == WL_SHM_FORMAT_ARGB8888) |
| 418 | client->has_argb = 1; |
| 419 | } |
| 420 | |
| 421 | struct wl_shm_listener shm_listener = { |
| 422 | shm_format |
| 423 | }; |
| 424 | |
| 425 | static void |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 426 | test_handle_pointer_position(void *data, struct weston_test *weston_test, |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 427 | wl_fixed_t x, wl_fixed_t y) |
| 428 | { |
| 429 | struct test *test = data; |
| 430 | test->pointer_x = wl_fixed_to_int(x); |
| 431 | test->pointer_y = wl_fixed_to_int(y); |
| 432 | |
| 433 | fprintf(stderr, "test-client: got global pointer %d %d\n", |
| 434 | test->pointer_x, test->pointer_y); |
| 435 | } |
| 436 | |
Neil Roberts | 40c0c3f | 2013-10-29 20:13:45 +0000 | [diff] [blame] | 437 | static void |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 438 | test_handle_n_egl_buffers(void *data, struct weston_test *weston_test, uint32_t n) |
Neil Roberts | 40c0c3f | 2013-10-29 20:13:45 +0000 | [diff] [blame] | 439 | { |
| 440 | struct test *test = data; |
| 441 | |
| 442 | test->n_egl_buffers = n; |
| 443 | } |
| 444 | |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 445 | static const struct weston_test_listener test_listener = { |
Neil Roberts | 40c0c3f | 2013-10-29 20:13:45 +0000 | [diff] [blame] | 446 | test_handle_pointer_position, |
| 447 | test_handle_n_egl_buffers, |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 448 | }; |
| 449 | |
| 450 | static void |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 451 | input_update_devices(struct input *input) |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 452 | { |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 453 | struct pointer *pointer; |
| 454 | struct keyboard *keyboard; |
Marek Chalupa | 8a5523c | 2015-03-30 09:20:07 -0400 | [diff] [blame] | 455 | struct touch *touch; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 456 | |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 457 | struct wl_seat *seat = input->wl_seat; |
| 458 | enum wl_seat_capability caps = input->caps; |
| 459 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 460 | if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) { |
Kristian Høgsberg | c1b244f | 2013-10-09 14:01:23 -0700 | [diff] [blame] | 461 | pointer = xzalloc(sizeof *pointer); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 462 | pointer->wl_pointer = wl_seat_get_pointer(seat); |
| 463 | wl_pointer_set_user_data(pointer->wl_pointer, pointer); |
| 464 | wl_pointer_add_listener(pointer->wl_pointer, &pointer_listener, |
| 465 | pointer); |
| 466 | input->pointer = pointer; |
| 467 | } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) { |
| 468 | wl_pointer_destroy(input->pointer->wl_pointer); |
| 469 | free(input->pointer); |
| 470 | input->pointer = NULL; |
| 471 | } |
| 472 | |
| 473 | if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) { |
Kristian Høgsberg | c1b244f | 2013-10-09 14:01:23 -0700 | [diff] [blame] | 474 | keyboard = xzalloc(sizeof *keyboard); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 475 | keyboard->wl_keyboard = wl_seat_get_keyboard(seat); |
| 476 | wl_keyboard_set_user_data(keyboard->wl_keyboard, keyboard); |
| 477 | wl_keyboard_add_listener(keyboard->wl_keyboard, &keyboard_listener, |
| 478 | keyboard); |
| 479 | input->keyboard = keyboard; |
| 480 | } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) { |
| 481 | wl_keyboard_destroy(input->keyboard->wl_keyboard); |
| 482 | free(input->keyboard); |
| 483 | input->keyboard = NULL; |
| 484 | } |
Marek Chalupa | 8a5523c | 2015-03-30 09:20:07 -0400 | [diff] [blame] | 485 | |
| 486 | if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->touch) { |
| 487 | touch = xzalloc(sizeof *touch); |
| 488 | touch->wl_touch = wl_seat_get_touch(seat); |
| 489 | wl_touch_set_user_data(touch->wl_touch, touch); |
| 490 | wl_touch_add_listener(touch->wl_touch, &touch_listener, |
| 491 | touch); |
| 492 | input->touch = touch; |
| 493 | } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->touch) { |
| 494 | wl_touch_destroy(input->touch->wl_touch); |
| 495 | free(input->touch); |
| 496 | input->touch = NULL; |
| 497 | } |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 498 | } |
| 499 | |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 500 | static void |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 501 | seat_handle_capabilities(void *data, struct wl_seat *seat, |
| 502 | enum wl_seat_capability caps) |
| 503 | { |
| 504 | struct input *input = data; |
| 505 | |
| 506 | input->caps = caps; |
| 507 | |
| 508 | /* we will create/update the devices only with the right (test) seat. |
| 509 | * If we haven't discovered which seat is the test seat, just |
| 510 | * store capabilities and bail out */ |
| 511 | if(input->seat_name && strcmp(input->seat_name, "test-seat") == 0) |
| 512 | input_update_devices(input); |
| 513 | |
| 514 | fprintf(stderr, "test-client: got seat %p capabilities: %x\n", |
| 515 | input, caps); |
| 516 | } |
| 517 | |
| 518 | static void |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 519 | seat_handle_name(void *data, struct wl_seat *seat, const char *name) |
| 520 | { |
| 521 | struct input *input = data; |
| 522 | |
| 523 | input->seat_name = strdup(name); |
| 524 | assert(input->seat_name && "No memory"); |
| 525 | |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 526 | fprintf(stderr, "test-client: got seat %p name: \'%s\'\n", |
| 527 | input, name); |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 528 | } |
| 529 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 530 | static const struct wl_seat_listener seat_listener = { |
| 531 | seat_handle_capabilities, |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 532 | seat_handle_name, |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 533 | }; |
| 534 | |
| 535 | static void |
| 536 | output_handle_geometry(void *data, |
| 537 | struct wl_output *wl_output, |
| 538 | int x, int y, |
| 539 | int physical_width, |
| 540 | int physical_height, |
| 541 | int subpixel, |
| 542 | const char *make, |
| 543 | const char *model, |
| 544 | int32_t transform) |
| 545 | { |
| 546 | struct output *output = data; |
| 547 | |
| 548 | output->x = x; |
| 549 | output->y = y; |
| 550 | } |
| 551 | |
| 552 | static void |
| 553 | output_handle_mode(void *data, |
| 554 | struct wl_output *wl_output, |
| 555 | uint32_t flags, |
| 556 | int width, |
| 557 | int height, |
| 558 | int refresh) |
| 559 | { |
| 560 | struct output *output = data; |
| 561 | |
| 562 | if (flags & WL_OUTPUT_MODE_CURRENT) { |
| 563 | output->width = width; |
| 564 | output->height = height; |
| 565 | } |
| 566 | } |
| 567 | |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 568 | static void |
| 569 | output_handle_scale(void *data, |
| 570 | struct wl_output *wl_output, |
| 571 | int scale) |
| 572 | { |
| 573 | struct output *output = data; |
| 574 | |
| 575 | output->scale = scale; |
| 576 | } |
| 577 | |
| 578 | static void |
| 579 | output_handle_done(void *data, |
| 580 | struct wl_output *wl_output) |
| 581 | { |
| 582 | struct output *output = data; |
| 583 | |
| 584 | output->initialized = 1; |
| 585 | } |
| 586 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 587 | static const struct wl_output_listener output_listener = { |
| 588 | output_handle_geometry, |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 589 | output_handle_mode, |
| 590 | output_handle_done, |
| 591 | output_handle_scale, |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 592 | }; |
| 593 | |
| 594 | static void |
| 595 | handle_global(void *data, struct wl_registry *registry, |
| 596 | uint32_t id, const char *interface, uint32_t version) |
| 597 | { |
| 598 | struct client *client = data; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 599 | struct output *output; |
| 600 | struct test *test; |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 601 | struct global *global; |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 602 | struct input *input; |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 603 | |
Kristian Høgsberg | c1b244f | 2013-10-09 14:01:23 -0700 | [diff] [blame] | 604 | global = xzalloc(sizeof *global); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 605 | global->name = id; |
| 606 | global->interface = strdup(interface); |
| 607 | assert(interface); |
| 608 | global->version = version; |
| 609 | wl_list_insert(client->global_list.prev, &global->link); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 610 | |
| 611 | if (strcmp(interface, "wl_compositor") == 0) { |
| 612 | client->wl_compositor = |
| 613 | wl_registry_bind(registry, id, |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 614 | &wl_compositor_interface, version); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 615 | } else if (strcmp(interface, "wl_seat") == 0) { |
Kristian Høgsberg | c1b244f | 2013-10-09 14:01:23 -0700 | [diff] [blame] | 616 | input = xzalloc(sizeof *input); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 617 | input->wl_seat = |
| 618 | wl_registry_bind(registry, id, |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 619 | &wl_seat_interface, version); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 620 | wl_seat_add_listener(input->wl_seat, &seat_listener, input); |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 621 | wl_list_insert(&client->inputs, &input->link); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 622 | } else if (strcmp(interface, "wl_shm") == 0) { |
| 623 | client->wl_shm = |
| 624 | wl_registry_bind(registry, id, |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 625 | &wl_shm_interface, version); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 626 | wl_shm_add_listener(client->wl_shm, &shm_listener, client); |
| 627 | } else if (strcmp(interface, "wl_output") == 0) { |
Kristian Høgsberg | c1b244f | 2013-10-09 14:01:23 -0700 | [diff] [blame] | 628 | output = xzalloc(sizeof *output); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 629 | output->wl_output = |
| 630 | wl_registry_bind(registry, id, |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 631 | &wl_output_interface, version); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 632 | wl_output_add_listener(output->wl_output, |
| 633 | &output_listener, output); |
| 634 | client->output = output; |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 635 | } else if (strcmp(interface, "weston_test") == 0) { |
Kristian Høgsberg | c1b244f | 2013-10-09 14:01:23 -0700 | [diff] [blame] | 636 | test = xzalloc(sizeof *test); |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 637 | test->weston_test = |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 638 | wl_registry_bind(registry, id, |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 639 | &weston_test_interface, version); |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 640 | weston_test_add_listener(test->weston_test, &test_listener, test); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 641 | client->test = test; |
Derek Foreman | 9bb1339 | 2015-01-23 12:12:36 -0600 | [diff] [blame] | 642 | } else if (strcmp(interface, "wl_drm") == 0) { |
| 643 | client->has_wl_drm = true; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | |
| 647 | static const struct wl_registry_listener registry_listener = { |
| 648 | handle_global |
| 649 | }; |
| 650 | |
Kristian Høgsberg | 42284f5 | 2014-01-01 17:38:04 -0800 | [diff] [blame] | 651 | void |
| 652 | skip(const char *fmt, ...) |
| 653 | { |
| 654 | va_list argp; |
| 655 | |
| 656 | va_start(argp, fmt); |
| 657 | vfprintf(stderr, fmt, argp); |
| 658 | va_end(argp); |
| 659 | |
Emilio Pozuelo Monfort | dae8a4b | 2014-02-07 09:34:48 +0100 | [diff] [blame] | 660 | /* automake tests uses exit code 77. weston-test-runner will see |
| 661 | * this and use it, and then weston-test's sigchld handler (in the |
| 662 | * weston process) will use that as an exit status, which is what |
| 663 | * automake will see in the end. */ |
| 664 | exit(77); |
Kristian Høgsberg | 42284f5 | 2014-01-01 17:38:04 -0800 | [diff] [blame] | 665 | } |
| 666 | |
Marek Chalupa | 4d06d46 | 2014-07-16 11:27:06 +0200 | [diff] [blame] | 667 | void |
| 668 | expect_protocol_error(struct client *client, |
| 669 | const struct wl_interface *intf, |
| 670 | uint32_t code) |
| 671 | { |
| 672 | int err; |
| 673 | uint32_t errcode, failed = 0; |
| 674 | const struct wl_interface *interface; |
| 675 | unsigned int id; |
| 676 | |
| 677 | /* if the error has not come yet, make it happen */ |
| 678 | wl_display_roundtrip(client->wl_display); |
| 679 | |
| 680 | err = wl_display_get_error(client->wl_display); |
| 681 | |
| 682 | assert(err && "Expected protocol error but nothing came"); |
| 683 | assert(err == EPROTO && "Expected protocol error but got local error"); |
| 684 | |
| 685 | errcode = wl_display_get_protocol_error(client->wl_display, |
| 686 | &interface, &id); |
| 687 | |
| 688 | /* check error */ |
| 689 | if (errcode != code) { |
| 690 | fprintf(stderr, "Should get error code %d but got %d\n", |
| 691 | code, errcode); |
| 692 | failed = 1; |
| 693 | } |
| 694 | |
| 695 | /* this should be definitely set */ |
| 696 | assert(interface); |
| 697 | |
| 698 | if (strcmp(intf->name, interface->name) != 0) { |
| 699 | fprintf(stderr, "Should get interface '%s' but got '%s'\n", |
| 700 | intf->name, interface->name); |
| 701 | failed = 1; |
| 702 | } |
| 703 | |
| 704 | if (failed) { |
| 705 | fprintf(stderr, "Expected other protocol error\n"); |
| 706 | abort(); |
| 707 | } |
| 708 | |
| 709 | /* all OK */ |
| 710 | fprintf(stderr, "Got expected protocol error on '%s' (object id: %d) " |
| 711 | "with code %d\n", interface->name, id, errcode); |
| 712 | } |
| 713 | |
Pekka Paalanen | 07921d7 | 2012-12-12 14:26:40 +0200 | [diff] [blame] | 714 | static void |
| 715 | log_handler(const char *fmt, va_list args) |
| 716 | { |
| 717 | fprintf(stderr, "libwayland: "); |
| 718 | vfprintf(stderr, fmt, args); |
| 719 | } |
| 720 | |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 721 | static void |
| 722 | input_destroy(struct input *inp) |
| 723 | { |
| 724 | wl_list_remove(&inp->link); |
| 725 | wl_seat_destroy(inp->wl_seat); |
| 726 | free(inp); |
| 727 | } |
| 728 | |
| 729 | /* find the test-seat and set it in client. |
| 730 | * Destroy other inputs */ |
| 731 | static void |
| 732 | client_set_input(struct client *cl) |
| 733 | { |
| 734 | struct input *inp, *inptmp; |
| 735 | wl_list_for_each_safe(inp, inptmp, &cl->inputs, link) { |
| 736 | assert(inp->seat_name && "BUG: input with no name"); |
| 737 | if (strcmp(inp->seat_name, "test-seat") == 0) { |
| 738 | cl->input = inp; |
| 739 | input_update_devices(inp); |
| 740 | } else { |
| 741 | input_destroy(inp); |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | /* we keep only one input */ |
| 746 | assert(wl_list_length(&cl->inputs) == 1); |
| 747 | } |
| 748 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 749 | struct client * |
Pekka Paalanen | 1ffd461 | 2015-03-26 12:49:35 +0200 | [diff] [blame] | 750 | create_client(void) |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 751 | { |
| 752 | struct client *client; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 753 | |
Pekka Paalanen | 07921d7 | 2012-12-12 14:26:40 +0200 | [diff] [blame] | 754 | wl_log_set_handler_client(log_handler); |
| 755 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 756 | /* connect to display */ |
Kristian Høgsberg | c1b244f | 2013-10-09 14:01:23 -0700 | [diff] [blame] | 757 | client = xzalloc(sizeof *client); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 758 | client->wl_display = wl_display_connect(NULL); |
| 759 | assert(client->wl_display); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 760 | wl_list_init(&client->global_list); |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 761 | wl_list_init(&client->inputs); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 762 | |
| 763 | /* setup registry so we can bind to interfaces */ |
| 764 | client->wl_registry = wl_display_get_registry(client->wl_display); |
Pekka Paalanen | 1ffd461 | 2015-03-26 12:49:35 +0200 | [diff] [blame] | 765 | wl_registry_add_listener(client->wl_registry, ®istry_listener, |
| 766 | client); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 767 | |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 768 | /* this roundtrip makes sure we have all globals and we bound to them */ |
| 769 | client_roundtrip(client); |
| 770 | /* this roundtrip makes sure we got all wl_shm.format and wl_seat.* |
| 771 | * events */ |
| 772 | client_roundtrip(client); |
| 773 | |
| 774 | /* find the right input for us */ |
| 775 | client_set_input(client); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 776 | |
| 777 | /* must have WL_SHM_FORMAT_ARGB32 */ |
| 778 | assert(client->has_argb); |
| 779 | |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 780 | /* must have weston_test interface */ |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 781 | assert(client->test); |
| 782 | |
| 783 | /* must have an output */ |
| 784 | assert(client->output); |
| 785 | |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 786 | /* the output must be initialized */ |
| 787 | assert(client->output->initialized == 1); |
| 788 | |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 789 | /* must have seat set */ |
| 790 | assert(client->input); |
| 791 | |
Pekka Paalanen | 1ffd461 | 2015-03-26 12:49:35 +0200 | [diff] [blame] | 792 | return client; |
| 793 | } |
| 794 | |
| 795 | struct client * |
Pekka Paalanen | 4ac06ff | 2015-03-26 12:56:10 +0200 | [diff] [blame] | 796 | create_client_and_test_surface(int x, int y, int width, int height) |
Pekka Paalanen | 1ffd461 | 2015-03-26 12:49:35 +0200 | [diff] [blame] | 797 | { |
| 798 | struct client *client; |
| 799 | struct surface *surface; |
| 800 | |
| 801 | client = create_client(); |
| 802 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 803 | /* initialize the client surface */ |
Kristian Høgsberg | c1b244f | 2013-10-09 14:01:23 -0700 | [diff] [blame] | 804 | surface = xzalloc(sizeof *surface); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 805 | surface->wl_surface = |
| 806 | wl_compositor_create_surface(client->wl_compositor); |
| 807 | assert(surface->wl_surface); |
| 808 | |
| 809 | wl_surface_add_listener(surface->wl_surface, &surface_listener, |
| 810 | surface); |
| 811 | |
| 812 | client->surface = surface; |
| 813 | wl_surface_set_user_data(surface->wl_surface, surface); |
| 814 | |
| 815 | surface->width = width; |
| 816 | surface->height = height; |
Pekka Paalanen | 32ac9b9 | 2013-02-08 17:01:26 +0200 | [diff] [blame] | 817 | surface->wl_buffer = create_shm_buffer(client, width, height, |
| 818 | &surface->data); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 819 | |
| 820 | memset(surface->data, 64, width * height * 4); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 821 | |
| 822 | move_client(client, x, y); |
| 823 | |
| 824 | return client; |
| 825 | } |
Bryce Harrington | c1a1d6c | 2014-12-09 14:46:36 -0800 | [diff] [blame] | 826 | |
| 827 | static const char* |
| 828 | output_path(void) { |
| 829 | char *path = getenv("WESTON_TEST_OUTPUT_PATH"); |
| 830 | |
| 831 | if (!path) |
| 832 | return "."; |
| 833 | return path; |
| 834 | } |
| 835 | |
| 836 | char* |
| 837 | screenshot_output_filename(const char *basename, uint32_t seq) { |
| 838 | char *filename; |
| 839 | |
| 840 | if (asprintf(&filename, "%s/%s-%02d.png", |
| 841 | output_path(), basename, seq) < 0) |
| 842 | return NULL; |
| 843 | return filename; |
| 844 | } |
| 845 | |
| 846 | static const char* |
| 847 | reference_path(void) { |
| 848 | char *path = getenv("WESTON_TEST_REFERENCE_PATH"); |
| 849 | |
| 850 | if (!path) |
| 851 | return "./tests/reference"; |
| 852 | return path; |
| 853 | } |
| 854 | |
| 855 | char* |
| 856 | screenshot_reference_filename(const char *basename, uint32_t seq) { |
| 857 | char *filename; |
| 858 | |
| 859 | if (asprintf(&filename, "%s/%s-%02d.png", |
| 860 | reference_path(), basename, seq) < 0) |
| 861 | return NULL; |
| 862 | return filename; |
| 863 | } |