U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 11 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial |
| 14 | * portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #ifndef _WESTON_TEST_CLIENT_HELPER_H_ |
| 27 | #define _WESTON_TEST_CLIENT_HELPER_H_ |
| 28 | |
Andrew Wedgbury | 9cd661e | 2014-04-07 12:40:35 +0100 | [diff] [blame] | 29 | #include "config.h" |
| 30 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 31 | #include <assert.h> |
Derek Foreman | 9bb1339 | 2015-01-23 12:12:36 -0600 | [diff] [blame] | 32 | #include <stdbool.h> |
Pekka Paalanen | 924cd94 | 2016-05-20 17:25:38 +0300 | [diff] [blame] | 33 | #include <pixman.h> |
Bryce Harrington | 273c285 | 2014-12-15 15:51:25 -0800 | [diff] [blame] | 34 | |
Bill Spitzak | 2ccd9a2 | 2015-08-06 16:24:59 +0100 | [diff] [blame] | 35 | #include <wayland-client-protocol.h> |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 36 | #include "weston-test-runner.h" |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 37 | #include "weston-test-client-protocol.h" |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 38 | |
| 39 | struct client { |
| 40 | struct wl_display *wl_display; |
| 41 | struct wl_registry *wl_registry; |
| 42 | struct wl_compositor *wl_compositor; |
| 43 | struct wl_shm *wl_shm; |
| 44 | struct test *test; |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 45 | /* the seat that is actually used for input events */ |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 46 | struct input *input; |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 47 | /* server can have more wl_seats. We need keep them all until we |
| 48 | * find the one that we need. After that, the others |
| 49 | * will be destroyed, so this list will have the length of 1. |
| 50 | * If some day in the future we will need the other seats, |
| 51 | * we can just keep them here. */ |
| 52 | struct wl_list inputs; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 53 | struct output *output; |
| 54 | struct surface *surface; |
| 55 | int has_argb; |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 56 | struct wl_list global_list; |
Derek Foreman | 9bb1339 | 2015-01-23 12:12:36 -0600 | [diff] [blame] | 57 | bool has_wl_drm; |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | struct global { |
| 61 | uint32_t name; |
| 62 | char *interface; |
| 63 | uint32_t version; |
| 64 | struct wl_list link; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | struct test { |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 68 | struct weston_test *weston_test; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 69 | int pointer_x; |
| 70 | int pointer_y; |
Neil Roberts | 40c0c3f | 2013-10-29 20:13:45 +0000 | [diff] [blame] | 71 | uint32_t n_egl_buffers; |
Bryce Harrington | 692275f | 2015-04-23 16:33:49 -0700 | [diff] [blame] | 72 | int buffer_copy_done; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | struct input { |
| 76 | struct wl_seat *wl_seat; |
| 77 | struct pointer *pointer; |
| 78 | struct keyboard *keyboard; |
Marek Chalupa | 8a5523c | 2015-03-30 09:20:07 -0400 | [diff] [blame] | 79 | struct touch *touch; |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 80 | char *seat_name; |
Marek Chalupa | c3c3fc4 | 2015-03-30 09:17:40 -0400 | [diff] [blame] | 81 | enum wl_seat_capability caps; |
| 82 | struct wl_list link; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | struct pointer { |
| 86 | struct wl_pointer *wl_pointer; |
| 87 | struct surface *focus; |
| 88 | int x; |
| 89 | int y; |
| 90 | uint32_t button; |
| 91 | uint32_t state; |
| 92 | }; |
| 93 | |
| 94 | struct keyboard { |
| 95 | struct wl_keyboard *wl_keyboard; |
| 96 | struct surface *focus; |
| 97 | uint32_t key; |
| 98 | uint32_t state; |
| 99 | uint32_t mods_depressed; |
| 100 | uint32_t mods_latched; |
| 101 | uint32_t mods_locked; |
| 102 | uint32_t group; |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 103 | struct { |
| 104 | int rate; |
| 105 | int delay; |
| 106 | } repeat_info; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
Marek Chalupa | 8a5523c | 2015-03-30 09:20:07 -0400 | [diff] [blame] | 109 | struct touch { |
| 110 | struct wl_touch *wl_touch; |
| 111 | int down_x; |
| 112 | int down_y; |
| 113 | int x; |
| 114 | int y; |
| 115 | int id; |
| 116 | int up_id; /* id of last wl_touch.up event */ |
| 117 | int frame_no; |
| 118 | int cancel_no; |
| 119 | }; |
| 120 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 121 | struct output { |
| 122 | struct wl_output *wl_output; |
| 123 | int x; |
| 124 | int y; |
| 125 | int width; |
| 126 | int height; |
Marek Chalupa | 643d85f | 2015-03-30 06:37:56 -0400 | [diff] [blame] | 127 | int scale; |
| 128 | int initialized; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 129 | }; |
| 130 | |
Pekka Paalanen | 924cd94 | 2016-05-20 17:25:38 +0300 | [diff] [blame] | 131 | struct buffer { |
| 132 | struct wl_buffer *proxy; |
| 133 | size_t len; |
| 134 | pixman_image_t *image; |
| 135 | }; |
| 136 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 137 | struct surface { |
| 138 | struct wl_surface *wl_surface; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 139 | struct output *output; |
| 140 | int x; |
| 141 | int y; |
| 142 | int width; |
| 143 | int height; |
Pekka Paalanen | 924cd94 | 2016-05-20 17:25:38 +0300 | [diff] [blame] | 144 | struct buffer *buffer; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 145 | }; |
| 146 | |
Bryce Harrington | 273c285 | 2014-12-15 15:51:25 -0800 | [diff] [blame] | 147 | struct rectangle { |
| 148 | int x; |
| 149 | int y; |
| 150 | int width; |
| 151 | int height; |
| 152 | }; |
| 153 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 154 | struct client * |
Pekka Paalanen | 1ffd461 | 2015-03-26 12:49:35 +0200 | [diff] [blame] | 155 | create_client(void); |
| 156 | |
| 157 | struct client * |
Pekka Paalanen | 4ac06ff | 2015-03-26 12:56:10 +0200 | [diff] [blame] | 158 | 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] | 159 | |
Pekka Paalanen | 924cd94 | 2016-05-20 17:25:38 +0300 | [diff] [blame] | 160 | struct buffer * |
| 161 | create_shm_buffer_a8r8g8b8(struct client *client, int width, int height); |
| 162 | |
| 163 | void |
| 164 | buffer_destroy(struct buffer *buf); |
| 165 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 166 | int |
| 167 | surface_contains(struct surface *surface, int x, int y); |
| 168 | |
| 169 | void |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 170 | move_client(struct client *client, int x, int y); |
| 171 | |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 172 | #define client_roundtrip(c) do { \ |
| 173 | assert(wl_display_roundtrip((c)->wl_display) >= 0); \ |
| 174 | } while (0) |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 175 | |
Pekka Paalanen | 8aaef7d | 2013-02-08 17:01:25 +0200 | [diff] [blame] | 176 | struct wl_callback * |
| 177 | frame_callback_set(struct wl_surface *surface, int *done); |
| 178 | |
Marek Chalupa | 1740aa8 | 2014-07-16 11:32:50 +0200 | [diff] [blame] | 179 | int |
| 180 | frame_callback_wait_nofail(struct client *client, int *done); |
| 181 | |
| 182 | #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] | 183 | |
Neil Roberts | 40c0c3f | 2013-10-29 20:13:45 +0000 | [diff] [blame] | 184 | int |
| 185 | get_n_egl_buffers(struct client *client); |
| 186 | |
Kristian Høgsberg | 42284f5 | 2014-01-01 17:38:04 -0800 | [diff] [blame] | 187 | void |
| 188 | skip(const char *fmt, ...); |
| 189 | |
Marek Chalupa | 4d06d46 | 2014-07-16 11:27:06 +0200 | [diff] [blame] | 190 | void |
| 191 | expect_protocol_error(struct client *client, |
| 192 | const struct wl_interface *intf, uint32_t code); |
| 193 | |
Bryce Harrington | 892122e | 2015-09-24 14:31:44 -0700 | [diff] [blame] | 194 | char * |
Bryce Harrington | c1a1d6c | 2014-12-09 14:46:36 -0800 | [diff] [blame] | 195 | screenshot_output_filename(const char *basename, uint32_t seq); |
| 196 | |
Bryce Harrington | 892122e | 2015-09-24 14:31:44 -0700 | [diff] [blame] | 197 | char * |
Bryce Harrington | c1a1d6c | 2014-12-09 14:46:36 -0800 | [diff] [blame] | 198 | screenshot_reference_filename(const char *basename, uint32_t seq); |
| 199 | |
Bryce Harrington | 273c285 | 2014-12-15 15:51:25 -0800 | [diff] [blame] | 200 | bool |
Pekka Paalanen | 47d68da | 2016-05-23 17:42:27 +0300 | [diff] [blame^] | 201 | check_images_match(pixman_image_t *img_a, pixman_image_t *img_b, |
| 202 | const struct rectangle *clip); |
Bryce Harrington | 273c285 | 2014-12-15 15:51:25 -0800 | [diff] [blame] | 203 | |
Bryce Harrington | 892122e | 2015-09-24 14:31:44 -0700 | [diff] [blame] | 204 | bool |
| 205 | write_surface_as_png(const struct surface *weston_surface, const char *fname); |
| 206 | |
| 207 | struct surface * |
| 208 | load_surface_from_png(const char *fname); |
| 209 | |
| 210 | struct surface * |
| 211 | create_screenshot_surface(struct client *client); |
| 212 | |
| 213 | struct surface * |
| 214 | capture_screenshot_of_output(struct client *client); |
| 215 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 216 | #endif |