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