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> |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 30 | #include "weston-test-runner.h" |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 31 | #include "weston-test-client-protocol.h" |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 32 | |
| 33 | struct client { |
| 34 | struct wl_display *wl_display; |
| 35 | struct wl_registry *wl_registry; |
| 36 | struct wl_compositor *wl_compositor; |
| 37 | struct wl_shm *wl_shm; |
| 38 | struct test *test; |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 39 | /* the seat that is actually used for input events */ |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 40 | struct input *input; |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 41 | /* server can have more wl_seats. We need keep them all until we |
| 42 | * find the one that we need. After that, the others |
| 43 | * will be destroyed, so this list will have the length of 1. |
| 44 | * If some day in the future we will need the other seats, |
| 45 | * we can just keep them here. */ |
| 46 | struct wl_list inputs; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 47 | struct output *output; |
| 48 | struct surface *surface; |
| 49 | int has_argb; |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 50 | struct wl_list global_list; |
Derek Foreman | 9bb1339 | 2015-01-23 12:12:36 -0600 | [diff] [blame] | 51 | bool has_wl_drm; |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | struct global { |
| 55 | uint32_t name; |
| 56 | char *interface; |
| 57 | uint32_t version; |
| 58 | struct wl_list link; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | struct test { |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 62 | struct weston_test *weston_test; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 63 | int pointer_x; |
| 64 | int pointer_y; |
Neil Roberts | 40c0c3f | 2013-10-29 20:13:45 +0000 | [diff] [blame] | 65 | uint32_t n_egl_buffers; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | struct input { |
| 69 | struct wl_seat *wl_seat; |
| 70 | struct pointer *pointer; |
| 71 | struct keyboard *keyboard; |
Marek Chalupa | 8a5523c | 2015-03-30 09:20:07 -0400 | [diff] [blame] | 72 | struct touch *touch; |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 73 | char *seat_name; |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 74 | enum wl_seat_capability caps; |
| 75 | struct wl_list link; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | struct pointer { |
| 79 | struct wl_pointer *wl_pointer; |
| 80 | struct surface *focus; |
| 81 | int x; |
| 82 | int y; |
| 83 | uint32_t button; |
| 84 | uint32_t state; |
| 85 | }; |
| 86 | |
| 87 | struct keyboard { |
| 88 | struct wl_keyboard *wl_keyboard; |
| 89 | struct surface *focus; |
| 90 | uint32_t key; |
| 91 | uint32_t state; |
| 92 | uint32_t mods_depressed; |
| 93 | uint32_t mods_latched; |
| 94 | uint32_t mods_locked; |
| 95 | uint32_t group; |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 96 | struct { |
| 97 | int rate; |
| 98 | int delay; |
| 99 | } repeat_info; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 100 | }; |
| 101 | |
Marek Chalupa | 8a5523c | 2015-03-30 09:20:07 -0400 | [diff] [blame] | 102 | struct touch { |
| 103 | struct wl_touch *wl_touch; |
| 104 | int down_x; |
| 105 | int down_y; |
| 106 | int x; |
| 107 | int y; |
| 108 | int id; |
| 109 | int up_id; /* id of last wl_touch.up event */ |
| 110 | int frame_no; |
| 111 | int cancel_no; |
| 112 | }; |
| 113 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 114 | struct output { |
| 115 | struct wl_output *wl_output; |
| 116 | int x; |
| 117 | int y; |
| 118 | int width; |
| 119 | int height; |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 120 | int scale; |
| 121 | int initialized; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | struct surface { |
| 125 | struct wl_surface *wl_surface; |
| 126 | struct wl_buffer *wl_buffer; |
| 127 | struct output *output; |
| 128 | int x; |
| 129 | int y; |
| 130 | int width; |
| 131 | int height; |
| 132 | void *data; |
| 133 | }; |
| 134 | |
Bryce Harrington | 2cd82b7 | 2014-11-19 17:18:36 -0800 | [diff] [blame] | 135 | static inline void * |
| 136 | xzalloc(size_t size) |
| 137 | { |
| 138 | void *p; |
| 139 | |
| 140 | p = calloc(1, size); |
| 141 | assert(p); |
| 142 | |
| 143 | return p; |
| 144 | } |
| 145 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 146 | struct client * |
Pekka Paalanen | 1ffd461 | 2015-03-26 12:49:35 +0200 | [diff] [blame] | 147 | create_client(void); |
| 148 | |
| 149 | struct client * |
Pekka Paalanen | 4ac06ff | 2015-03-26 12:56:10 +0200 | [diff] [blame] | 150 | 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] | 151 | |
Pekka Paalanen | 32ac9b9 | 2013-02-08 17:01:26 +0200 | [diff] [blame] | 152 | struct wl_buffer * |
| 153 | create_shm_buffer(struct client *client, int width, int height, void **pixels); |
| 154 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 155 | int |
| 156 | surface_contains(struct surface *surface, int x, int y); |
| 157 | |
| 158 | void |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 159 | move_client(struct client *client, int x, int y); |
| 160 | |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 161 | #define client_roundtrip(c) do { \ |
| 162 | assert(wl_display_roundtrip((c)->wl_display) >= 0); \ |
| 163 | } while (0) |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 164 | |
Pekka Paalanen | 8aaef7d | 2013-02-08 17:01:25 +0200 | [diff] [blame] | 165 | struct wl_callback * |
| 166 | frame_callback_set(struct wl_surface *surface, int *done); |
| 167 | |
Marek Chalupa | 1740aa8 | 2014-07-16 11:32:50 +0200 | [diff] [blame] | 168 | int |
| 169 | frame_callback_wait_nofail(struct client *client, int *done); |
| 170 | |
| 171 | #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] | 172 | |
Neil Roberts | 40c0c3f | 2013-10-29 20:13:45 +0000 | [diff] [blame] | 173 | int |
| 174 | get_n_egl_buffers(struct client *client); |
| 175 | |
Kristian Høgsberg | 42284f5 | 2014-01-01 17:38:04 -0800 | [diff] [blame] | 176 | void |
| 177 | skip(const char *fmt, ...); |
| 178 | |
Marek Chalupa | 4d06d46 | 2014-07-16 11:27:06 +0200 | [diff] [blame] | 179 | void |
| 180 | expect_protocol_error(struct client *client, |
| 181 | const struct wl_interface *intf, uint32_t code); |
| 182 | |
Bryce Harrington | c1a1d6c | 2014-12-09 14:46:36 -0800 | [diff] [blame^] | 183 | char* |
| 184 | screenshot_output_filename(const char *basename, uint32_t seq); |
| 185 | |
| 186 | char* |
| 187 | screenshot_reference_filename(const char *basename, uint32_t seq); |
| 188 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 189 | #endif |