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