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 |
| 5 | * its documentation for any purpose is hereby granted without fee, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of the copyright holders not be used in |
| 9 | * advertising or publicity pertaining to distribution of the software |
| 10 | * without specific, written prior permission. The copyright holders make |
| 11 | * no representations about the suitability of this software for any |
| 12 | * purpose. It is provided "as is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 15 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 16 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 18 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 19 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 20 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #ifndef _WESTON_TEST_CLIENT_HELPER_H_ |
| 24 | #define _WESTON_TEST_CLIENT_HELPER_H_ |
| 25 | |
Andrew Wedgbury | 9cd661e | 2014-04-07 12:40:35 +0100 | [diff] [blame] | 26 | #include "config.h" |
| 27 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 28 | #include <assert.h> |
Derek Foreman | 9bb1339 | 2015-01-23 12:12:36 -0600 | [diff] [blame] | 29 | #include <stdbool.h> |
Bryce Harrington | 273c285 | 2014-12-15 15:51:25 -0800 | [diff] [blame] | 30 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 31 | #include "weston-test-runner.h" |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 32 | #include "weston-test-client-protocol.h" |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 33 | |
| 34 | struct client { |
| 35 | struct wl_display *wl_display; |
| 36 | struct wl_registry *wl_registry; |
| 37 | struct wl_compositor *wl_compositor; |
| 38 | struct wl_shm *wl_shm; |
| 39 | struct test *test; |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 40 | /* the seat that is actually used for input events */ |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 41 | struct input *input; |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 42 | /* server can have more wl_seats. We need keep them all until we |
| 43 | * find the one that we need. After that, the others |
| 44 | * will be destroyed, so this list will have the length of 1. |
| 45 | * If some day in the future we will need the other seats, |
| 46 | * we can just keep them here. */ |
| 47 | struct wl_list inputs; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 48 | struct output *output; |
| 49 | struct surface *surface; |
| 50 | int has_argb; |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 51 | struct wl_list global_list; |
Derek Foreman | 9bb1339 | 2015-01-23 12:12:36 -0600 | [diff] [blame] | 52 | bool has_wl_drm; |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | struct global { |
| 56 | uint32_t name; |
| 57 | char *interface; |
| 58 | uint32_t version; |
| 59 | struct wl_list link; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | struct test { |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 63 | struct weston_test *weston_test; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 64 | int pointer_x; |
| 65 | int pointer_y; |
Neil Roberts | 40c0c3f | 2013-10-29 20:13:45 +0000 | [diff] [blame] | 66 | uint32_t n_egl_buffers; |
Bryce Harrington | 692275f | 2015-04-23 16:33:49 -0700 | [diff] [blame] | 67 | int buffer_copy_done; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | struct input { |
| 71 | struct wl_seat *wl_seat; |
| 72 | struct pointer *pointer; |
| 73 | struct keyboard *keyboard; |
Marek Chalupa | 8a5523c | 2015-03-30 09:20:07 -0400 | [diff] [blame] | 74 | struct touch *touch; |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 75 | char *seat_name; |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 76 | enum wl_seat_capability caps; |
| 77 | struct wl_list link; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | struct pointer { |
| 81 | struct wl_pointer *wl_pointer; |
| 82 | struct surface *focus; |
| 83 | int x; |
| 84 | int y; |
| 85 | uint32_t button; |
| 86 | uint32_t state; |
| 87 | }; |
| 88 | |
| 89 | struct keyboard { |
| 90 | struct wl_keyboard *wl_keyboard; |
| 91 | struct surface *focus; |
| 92 | uint32_t key; |
| 93 | uint32_t state; |
| 94 | uint32_t mods_depressed; |
| 95 | uint32_t mods_latched; |
| 96 | uint32_t mods_locked; |
| 97 | uint32_t group; |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 98 | struct { |
| 99 | int rate; |
| 100 | int delay; |
| 101 | } repeat_info; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 102 | }; |
| 103 | |
Marek Chalupa | 8a5523c | 2015-03-30 09:20:07 -0400 | [diff] [blame] | 104 | struct touch { |
| 105 | struct wl_touch *wl_touch; |
| 106 | int down_x; |
| 107 | int down_y; |
| 108 | int x; |
| 109 | int y; |
| 110 | int id; |
| 111 | int up_id; /* id of last wl_touch.up event */ |
| 112 | int frame_no; |
| 113 | int cancel_no; |
| 114 | }; |
| 115 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 116 | struct output { |
| 117 | struct wl_output *wl_output; |
| 118 | int x; |
| 119 | int y; |
| 120 | int width; |
| 121 | int height; |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 122 | int scale; |
| 123 | int initialized; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | struct surface { |
| 127 | struct wl_surface *wl_surface; |
| 128 | struct wl_buffer *wl_buffer; |
| 129 | struct output *output; |
| 130 | int x; |
| 131 | int y; |
| 132 | int width; |
| 133 | int height; |
| 134 | void *data; |
| 135 | }; |
| 136 | |
Bryce Harrington | 273c285 | 2014-12-15 15:51:25 -0800 | [diff] [blame] | 137 | struct rectangle { |
| 138 | int x; |
| 139 | int y; |
| 140 | int width; |
| 141 | int height; |
| 142 | }; |
| 143 | |
Bryce Harrington | 61a6436 | 2015-04-22 18:23:01 -0700 | [diff] [blame] | 144 | void * |
| 145 | fail_on_null(void *p); |
| 146 | |
Bryce Harrington | 2cd82b7 | 2014-11-19 17:18:36 -0800 | [diff] [blame] | 147 | static inline void * |
Bryce Harrington | 61a6436 | 2015-04-22 18:23:01 -0700 | [diff] [blame] | 148 | xzalloc(size_t s) |
Bryce Harrington | 2cd82b7 | 2014-11-19 17:18:36 -0800 | [diff] [blame] | 149 | { |
Bryce Harrington | 61a6436 | 2015-04-22 18:23:01 -0700 | [diff] [blame] | 150 | return fail_on_null(calloc(1, s)); |
| 151 | } |
Bryce Harrington | 2cd82b7 | 2014-11-19 17:18:36 -0800 | [diff] [blame] | 152 | |
Bryce Harrington | 61a6436 | 2015-04-22 18:23:01 -0700 | [diff] [blame] | 153 | static inline void * |
| 154 | xmalloc(size_t s) |
| 155 | { |
| 156 | return fail_on_null(malloc(s)); |
Bryce Harrington | 2cd82b7 | 2014-11-19 17:18:36 -0800 | [diff] [blame] | 157 | } |
| 158 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 159 | struct client * |
Pekka Paalanen | 1ffd461 | 2015-03-26 12:49:35 +0200 | [diff] [blame] | 160 | create_client(void); |
| 161 | |
| 162 | struct client * |
Pekka Paalanen | 4ac06ff | 2015-03-26 12:56:10 +0200 | [diff] [blame] | 163 | create_client_and_test_surface(int x, int y, int width, int height); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 164 | |
Pekka Paalanen | 32ac9b9 | 2013-02-08 17:01:26 +0200 | [diff] [blame] | 165 | struct wl_buffer * |
| 166 | create_shm_buffer(struct client *client, int width, int height, void **pixels); |
| 167 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 168 | int |
| 169 | surface_contains(struct surface *surface, int x, int y); |
| 170 | |
| 171 | void |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 172 | move_client(struct client *client, int x, int y); |
| 173 | |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 174 | #define client_roundtrip(c) do { \ |
| 175 | assert(wl_display_roundtrip((c)->wl_display) >= 0); \ |
| 176 | } while (0) |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 177 | |
Pekka Paalanen | 8aaef7d | 2013-02-08 17:01:25 +0200 | [diff] [blame] | 178 | struct wl_callback * |
| 179 | frame_callback_set(struct wl_surface *surface, int *done); |
| 180 | |
Marek Chalupa | 1740aa8 | 2014-07-16 11:32:50 +0200 | [diff] [blame] | 181 | int |
| 182 | frame_callback_wait_nofail(struct client *client, int *done); |
| 183 | |
| 184 | #define frame_callback_wait(c, d) assert(frame_callback_wait_nofail((c), (d))) |
Pekka Paalanen | 8aaef7d | 2013-02-08 17:01:25 +0200 | [diff] [blame] | 185 | |
Neil Roberts | 40c0c3f | 2013-10-29 20:13:45 +0000 | [diff] [blame] | 186 | int |
| 187 | get_n_egl_buffers(struct client *client); |
| 188 | |
Kristian Høgsberg | 42284f5 | 2014-01-01 17:38:04 -0800 | [diff] [blame] | 189 | void |
| 190 | skip(const char *fmt, ...); |
| 191 | |
Marek Chalupa | 4d06d46 | 2014-07-16 11:27:06 +0200 | [diff] [blame] | 192 | void |
| 193 | expect_protocol_error(struct client *client, |
| 194 | const struct wl_interface *intf, uint32_t code); |
| 195 | |
Bryce Harrington | c1a1d6c | 2014-12-09 14:46:36 -0800 | [diff] [blame] | 196 | char* |
| 197 | screenshot_output_filename(const char *basename, uint32_t seq); |
| 198 | |
| 199 | char* |
| 200 | screenshot_reference_filename(const char *basename, uint32_t seq); |
| 201 | |
Bryce Harrington | 273c285 | 2014-12-15 15:51:25 -0800 | [diff] [blame] | 202 | bool |
Bryce Harrington | 39a5be2 | 2015-05-14 14:36:18 -0700 | [diff] [blame] | 203 | check_surfaces_geometry(const struct surface *a, const struct surface *b); |
| 204 | |
| 205 | bool |
Bryce Harrington | 273c285 | 2014-12-15 15:51:25 -0800 | [diff] [blame] | 206 | check_surfaces_equal(const struct surface *a, const struct surface *b); |
| 207 | |
| 208 | bool |
| 209 | check_surfaces_match_in_clip(const struct surface *a, const struct surface *b, const struct rectangle *clip); |
| 210 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 211 | #endif |