blob: a288af7ea260db3cc234132c866a69ffddf6c140 [file] [log] [blame]
U. Artie Eoff1ba9b382012-12-07 13:50:32 -08001/*
2 * Copyright © 2012 Intel Corporation
3 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07004 * 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 Eoff1ba9b382012-12-07 13:50:32 -080011 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070012 * 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 Eoff1ba9b382012-12-07 13:50:32 -080024 */
25
26#ifndef _WESTON_TEST_CLIENT_HELPER_H_
27#define _WESTON_TEST_CLIENT_HELPER_H_
28
Andrew Wedgbury9cd661e2014-04-07 12:40:35 +010029#include "config.h"
30
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080031#include <assert.h>
Derek Foreman9bb13392015-01-23 12:12:36 -060032#include <stdbool.h>
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030033#include <stdint.h>
Pekka Paalanen924cd942016-05-20 17:25:38 +030034#include <pixman.h>
Bryce Harrington273c2852014-12-15 15:51:25 -080035
Bill Spitzak2ccd9a22015-08-06 16:24:59 +010036#include <wayland-client-protocol.h>
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080037#include "weston-test-runner.h"
Derek Foremanf6a65922015-02-24 09:32:14 -060038#include "weston-test-client-protocol.h"
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080039
40struct 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 Chalupac3c3fc42015-03-30 09:17:40 -040046 /* the seat that is actually used for input events */
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080047 struct input *input;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040048 /* 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 Eoff1ba9b382012-12-07 13:50:32 -080054 struct output *output;
55 struct surface *surface;
56 int has_argb;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050057 struct wl_list global_list;
Derek Foreman9bb13392015-01-23 12:12:36 -060058 bool has_wl_drm;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050059};
60
61struct global {
62 uint32_t name;
63 char *interface;
64 uint32_t version;
65 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080066};
67
68struct test {
Derek Foremanf6a65922015-02-24 09:32:14 -060069 struct weston_test *weston_test;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080070 int pointer_x;
71 int pointer_y;
Neil Roberts40c0c3f2013-10-29 20:13:45 +000072 uint32_t n_egl_buffers;
Bryce Harrington692275f2015-04-23 16:33:49 -070073 int buffer_copy_done;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080074};
75
76struct input {
77 struct wl_seat *wl_seat;
78 struct pointer *pointer;
79 struct keyboard *keyboard;
Marek Chalupa8a5523c2015-03-30 09:20:07 -040080 struct touch *touch;
Marek Chalupa643d85f2015-03-30 06:37:56 -040081 char *seat_name;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040082 enum wl_seat_capability caps;
83 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080084};
85
86struct 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
95struct 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 Chalupa643d85f2015-03-30 06:37:56 -0400104 struct {
105 int rate;
106 int delay;
107 } repeat_info;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800108};
109
Marek Chalupa8a5523c2015-03-30 09:20:07 -0400110struct 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 Eoff1ba9b382012-12-07 13:50:32 -0800122struct output {
123 struct wl_output *wl_output;
124 int x;
125 int y;
126 int width;
127 int height;
Marek Chalupa643d85f2015-03-30 06:37:56 -0400128 int scale;
129 int initialized;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800130};
131
Pekka Paalanen924cd942016-05-20 17:25:38 +0300132struct buffer {
133 struct wl_buffer *proxy;
134 size_t len;
135 pixman_image_t *image;
136};
137
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800138struct surface {
139 struct wl_surface *wl_surface;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800140 struct output *output;
141 int x;
142 int y;
143 int width;
144 int height;
Pekka Paalanen924cd942016-05-20 17:25:38 +0300145 struct buffer *buffer;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800146};
147
Bryce Harrington273c2852014-12-15 15:51:25 -0800148struct rectangle {
149 int x;
150 int y;
151 int width;
152 int height;
153};
154
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800155struct client *
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200156create_client(void);
157
158struct client *
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200159create_client_and_test_surface(int x, int y, int width, int height);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800160
Pekka Paalanen924cd942016-05-20 17:25:38 +0300161struct buffer *
162create_shm_buffer_a8r8g8b8(struct client *client, int width, int height);
163
164void
165buffer_destroy(struct buffer *buf);
166
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800167int
168surface_contains(struct surface *surface, int x, int y);
169
170void
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800171move_client(struct client *client, int x, int y);
172
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200173#define client_roundtrip(c) do { \
174 assert(wl_display_roundtrip((c)->wl_display) >= 0); \
175} while (0)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800176
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200177struct wl_callback *
178frame_callback_set(struct wl_surface *surface, int *done);
179
Marek Chalupa1740aa82014-07-16 11:32:50 +0200180int
181frame_callback_wait_nofail(struct client *client, int *done);
182
183#define frame_callback_wait(c, d) assert(frame_callback_wait_nofail((c), (d)))
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200184
Kristian Høgsberg42284f52014-01-01 17:38:04 -0800185void
186skip(const char *fmt, ...);
187
Marek Chalupa4d06d462014-07-16 11:27:06 +0200188void
189expect_protocol_error(struct client *client,
190 const struct wl_interface *intf, uint32_t code);
191
Bryce Harrington892122e2015-09-24 14:31:44 -0700192char *
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800193screenshot_output_filename(const char *basename, uint32_t seq);
194
Bryce Harrington892122e2015-09-24 14:31:44 -0700195char *
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800196screenshot_reference_filename(const char *basename, uint32_t seq);
197
Bryce Harrington273c2852014-12-15 15:51:25 -0800198bool
Pekka Paalanen47d68da2016-05-23 17:42:27 +0300199check_images_match(pixman_image_t *img_a, pixman_image_t *img_b,
200 const struct rectangle *clip);
Bryce Harrington273c2852014-12-15 15:51:25 -0800201
Pekka Paalanena5bb91d2016-06-02 18:02:46 +0300202pixman_image_t *
203visualize_image_difference(pixman_image_t *img_a, pixman_image_t *img_b,
204 const struct rectangle *clip_rect);
205
Bryce Harrington892122e2015-09-24 14:31:44 -0700206bool
Pekka Paalanenfd10ef02016-05-27 13:54:35 +0300207write_image_as_png(pixman_image_t *image, const char *fname);
Bryce Harrington892122e2015-09-24 14:31:44 -0700208
Pekka Paalanen289fdeb2016-05-25 11:47:41 +0300209pixman_image_t *
210load_image_from_png(const char *fname);
Bryce Harrington892122e2015-09-24 14:31:44 -0700211
Pekka Paalanen365c1292016-05-27 14:11:01 +0300212struct buffer *
Bryce Harrington892122e2015-09-24 14:31:44 -0700213capture_screenshot_of_output(struct client *client);
214
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800215#endif