• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "viewporter-client-protocol.h"
41 
42 struct client {
43 	struct wl_display *wl_display;
44 	struct wl_registry *wl_registry;
45 	struct wl_compositor *wl_compositor;
46 	struct wl_shm *wl_shm;
47 	struct test *test;
48 	/* the seat that is actually used for input events */
49 	struct input *input;
50 	/* server can have more wl_seats. We need keep them all until we
51 	 * find the one that we need. After that, the others
52 	 * will be destroyed, so this list will have the length of 1.
53 	 * If some day in the future we will need the other seats,
54 	 * we can just keep them here. */
55 	struct wl_list inputs;
56 	struct output *output;
57 	struct surface *surface;
58 	int has_argb;
59 	struct wl_list global_list;
60 	bool has_wl_drm;
61 	struct wl_list output_list; /* struct output::link */
62 };
63 
64 struct global {
65 	uint32_t name;
66 	char *interface;
67 	uint32_t version;
68 	struct wl_list link;
69 };
70 
71 struct test {
72 	struct weston_test *weston_test;
73 	int pointer_x;
74 	int pointer_y;
75 	uint32_t n_egl_buffers;
76 	int buffer_copy_done;
77 };
78 
79 struct input {
80 	struct client *client;
81 	uint32_t global_name;
82 	struct wl_seat *wl_seat;
83 	struct pointer *pointer;
84 	struct keyboard *keyboard;
85 	struct touch *touch;
86 	char *seat_name;
87 	enum wl_seat_capability caps;
88 	struct wl_list link;
89 };
90 
91 struct pointer {
92 	struct wl_pointer *wl_pointer;
93 	struct surface *focus;
94 	int x;
95 	int y;
96 	uint32_t button;
97 	uint32_t state;
98 	uint32_t axis;
99 	double axis_value;
100 	uint32_t motion_time_msec;
101 	uint32_t button_time_msec;
102 	uint32_t axis_time_msec;
103 	uint32_t axis_stop_time_msec;
104 	struct timespec input_timestamp;
105 	struct timespec motion_time_timespec;
106 	struct timespec button_time_timespec;
107 	struct timespec axis_time_timespec;
108 	struct timespec axis_stop_time_timespec;
109 };
110 
111 struct keyboard {
112 	struct wl_keyboard *wl_keyboard;
113 	struct surface *focus;
114 	uint32_t key;
115 	uint32_t state;
116 	uint32_t mods_depressed;
117 	uint32_t mods_latched;
118 	uint32_t mods_locked;
119 	uint32_t group;
120 	struct {
121 		int rate;
122 		int delay;
123 	} repeat_info;
124 	uint32_t key_time_msec;
125 	struct timespec input_timestamp;
126 	struct timespec key_time_timespec;
127 };
128 
129 struct touch {
130 	struct wl_touch *wl_touch;
131 	int down_x;
132 	int down_y;
133 	int x;
134 	int y;
135 	int id;
136 	int up_id; /* id of last wl_touch.up event */
137 	int frame_no;
138 	int cancel_no;
139 	uint32_t down_time_msec;
140 	uint32_t up_time_msec;
141 	uint32_t motion_time_msec;
142 	struct timespec input_timestamp;
143 	struct timespec down_time_timespec;
144 	struct timespec up_time_timespec;
145 	struct timespec motion_time_timespec;
146 };
147 
148 struct output {
149 	struct wl_output *wl_output;
150 	struct wl_list link; /* struct client::output_list */
151 	int x;
152 	int y;
153 	int width;
154 	int height;
155 	int scale;
156 	int initialized;
157 };
158 
159 struct buffer {
160 	struct wl_buffer *proxy;
161 	size_t len;
162 	pixman_image_t *image;
163 };
164 
165 struct surface {
166 	struct wl_surface *wl_surface;
167 	struct output *output; /* not owned */
168 	int x;
169 	int y;
170 	int width;
171 	int height;
172 	struct buffer *buffer;
173 };
174 
175 struct rectangle {
176 	int x;
177 	int y;
178 	int width;
179 	int height;
180 };
181 
182 struct range {
183 	int a;
184 	int b;
185 };
186 
187 struct client *
188 create_client(void);
189 
190 void
191 client_destroy(struct client *client);
192 
193 struct surface *
194 create_test_surface(struct client *client);
195 
196 void
197 surface_destroy(struct surface *surface);
198 
199 struct client *
200 create_client_and_test_surface(int x, int y, int width, int height);
201 
202 struct buffer *
203 create_shm_buffer_a8r8g8b8(struct client *client, int width, int height);
204 
205 void
206 buffer_destroy(struct buffer *buf);
207 
208 int
209 surface_contains(struct surface *surface, int x, int y);
210 
211 void
212 move_client(struct client *client, int x, int y);
213 
214 #define client_roundtrip(c) do { \
215 	assert(wl_display_roundtrip((c)->wl_display) >= 0); \
216 } while (0)
217 
218 struct wl_callback *
219 frame_callback_set(struct wl_surface *surface, int *done);
220 
221 int
222 frame_callback_wait_nofail(struct client *client, int *done);
223 
224 #define frame_callback_wait(c, d) assert(frame_callback_wait_nofail((c), (d)))
225 
226 void
227 skip(const char *fmt, ...);
228 
229 void
230 expect_protocol_error(struct client *client,
231 		      const struct wl_interface *intf, uint32_t code);
232 
233 char *
234 screenshot_output_filename(const char *basename, uint32_t seq);
235 
236 char *
237 screenshot_reference_filename(const char *basename, uint32_t seq);
238 
239 char *
240 image_filename(const char *basename);
241 
242 bool
243 check_images_match(pixman_image_t *img_a, pixman_image_t *img_b,
244 		   const struct rectangle *clip,
245 		   const struct range *prec);
246 
247 pixman_image_t *
248 visualize_image_difference(pixman_image_t *img_a, pixman_image_t *img_b,
249 			   const struct rectangle *clip_rect,
250 			   const struct range *prec);
251 
252 bool
253 write_image_as_png(pixman_image_t *image, const char *fname);
254 
255 pixman_image_t *
256 load_image_from_png(const char *fname);
257 
258 struct buffer *
259 capture_screenshot_of_output(struct client *client);
260 
261 bool
262 verify_screen_content(struct client *client,
263 		      const char *ref_image,
264 		      int ref_seq_no,
265 		      const struct rectangle *clip,
266 		      int seq_no);
267 
268 struct buffer *
269 client_buffer_from_image_file(struct client *client,
270 			      const char *basename,
271 			      int scale);
272 
273 void *
274 bind_to_singleton_global(struct client *client,
275 			 const struct wl_interface *iface,
276 			 int version);
277 
278 struct wp_viewport *
279 client_create_viewport(struct client *client);
280 
281 void
282 fill_image_with_color(pixman_image_t *image, pixman_color_t *color);
283 
284 pixman_color_t *
285 color_rgb888(pixman_color_t *tmp, uint8_t r, uint8_t g, uint8_t b);
286 
287 #endif
288