tests: add test_seat_release() for symmetry
[platform/upstream/weston.git] / tests / weston-test-client-helper.h
1 /*
2  * Copyright © 2012 Intel Corporation
3  *
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:
11  *
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.
24  */
25
26 #ifndef _WESTON_TEST_CLIENT_HELPER_H_
27 #define _WESTON_TEST_CLIENT_HELPER_H_
28
29 #include "config.h"
30
31 #include <assert.h>
32 #include <stdbool.h>
33 #include <stdint.h>
34 #include <time.h>
35 #include <pixman.h>
36
37 #include <wayland-client-protocol.h>
38 #include "weston-test-runner.h"
39 #include "weston-test-client-protocol.h"
40
41 struct client {
42         struct wl_display *wl_display;
43         struct wl_registry *wl_registry;
44         struct wl_compositor *wl_compositor;
45         struct wl_shm *wl_shm;
46         struct test *test;
47         /* the seat that is actually used for input events */
48         struct input *input;
49         /* server can have more wl_seats. We need keep them all until we
50          * find the one that we need. After that, the others
51          * will be destroyed, so this list will have the length of 1.
52          * If some day in the future we will need the other seats,
53          * we can just keep them here. */
54         struct wl_list inputs;
55         struct output *output;
56         struct surface *surface;
57         int has_argb;
58         struct wl_list global_list;
59         bool has_wl_drm;
60 };
61
62 struct global {
63         uint32_t name;
64         char *interface;
65         uint32_t version;
66         struct wl_list link;
67 };
68
69 struct test {
70         struct weston_test *weston_test;
71         int pointer_x;
72         int pointer_y;
73         uint32_t n_egl_buffers;
74         int buffer_copy_done;
75 };
76
77 struct input {
78         struct client *client;
79         uint32_t global_name;
80         struct wl_seat *wl_seat;
81         struct pointer *pointer;
82         struct keyboard *keyboard;
83         struct touch *touch;
84         char *seat_name;
85         enum wl_seat_capability caps;
86         struct wl_list link;
87 };
88
89 struct pointer {
90         struct wl_pointer *wl_pointer;
91         struct surface *focus;
92         int x;
93         int y;
94         uint32_t button;
95         uint32_t state;
96         uint32_t axis;
97         double axis_value;
98         uint32_t motion_time_msec;
99         uint32_t button_time_msec;
100         uint32_t axis_time_msec;
101         uint32_t axis_stop_time_msec;
102         struct timespec input_timestamp;
103         struct timespec motion_time_timespec;
104         struct timespec button_time_timespec;
105         struct timespec axis_time_timespec;
106         struct timespec axis_stop_time_timespec;
107 };
108
109 struct keyboard {
110         struct wl_keyboard *wl_keyboard;
111         struct surface *focus;
112         uint32_t key;
113         uint32_t state;
114         uint32_t mods_depressed;
115         uint32_t mods_latched;
116         uint32_t mods_locked;
117         uint32_t group;
118         struct {
119                 int rate;
120                 int delay;
121         } repeat_info;
122         uint32_t key_time_msec;
123         struct timespec input_timestamp;
124         struct timespec key_time_timespec;
125 };
126
127 struct touch {
128         struct wl_touch *wl_touch;
129         int down_x;
130         int down_y;
131         int x;
132         int y;
133         int id;
134         int up_id; /* id of last wl_touch.up event */
135         int frame_no;
136         int cancel_no;
137         uint32_t down_time_msec;
138         uint32_t up_time_msec;
139         uint32_t motion_time_msec;
140         struct timespec input_timestamp;
141         struct timespec down_time_timespec;
142         struct timespec up_time_timespec;
143         struct timespec motion_time_timespec;
144 };
145
146 struct output {
147         struct wl_output *wl_output;
148         int x;
149         int y;
150         int width;
151         int height;
152         int scale;
153         int initialized;
154 };
155
156 struct buffer {
157         struct wl_buffer *proxy;
158         size_t len;
159         pixman_image_t *image;
160 };
161
162 struct surface {
163         struct wl_surface *wl_surface;
164         struct output *output;
165         int x;
166         int y;
167         int width;
168         int height;
169         struct buffer *buffer;
170 };
171
172 struct rectangle {
173         int x;
174         int y;
175         int width;
176         int height;
177 };
178
179 struct client *
180 create_client(void);
181
182 struct surface *
183 create_test_surface(struct client *client);
184
185 struct client *
186 create_client_and_test_surface(int x, int y, int width, int height);
187
188 struct buffer *
189 create_shm_buffer_a8r8g8b8(struct client *client, int width, int height);
190
191 void
192 buffer_destroy(struct buffer *buf);
193
194 int
195 surface_contains(struct surface *surface, int x, int y);
196
197 void
198 move_client(struct client *client, int x, int y);
199
200 #define client_roundtrip(c) do { \
201         assert(wl_display_roundtrip((c)->wl_display) >= 0); \
202 } while (0)
203
204 struct wl_callback *
205 frame_callback_set(struct wl_surface *surface, int *done);
206
207 int
208 frame_callback_wait_nofail(struct client *client, int *done);
209
210 #define frame_callback_wait(c, d) assert(frame_callback_wait_nofail((c), (d)))
211
212 void
213 skip(const char *fmt, ...);
214
215 void
216 expect_protocol_error(struct client *client,
217                       const struct wl_interface *intf, uint32_t code);
218
219 char *
220 screenshot_output_filename(const char *basename, uint32_t seq);
221
222 char *
223 screenshot_reference_filename(const char *basename, uint32_t seq);
224
225 bool
226 check_images_match(pixman_image_t *img_a, pixman_image_t *img_b,
227                    const struct rectangle *clip);
228
229 pixman_image_t *
230 visualize_image_difference(pixman_image_t *img_a, pixman_image_t *img_b,
231                            const struct rectangle *clip_rect);
232
233 bool
234 write_image_as_png(pixman_image_t *image, const char *fname);
235
236 pixman_image_t *
237 load_image_from_png(const char *fname);
238
239 struct buffer *
240 capture_screenshot_of_output(struct client *client);
241
242 #endif