blob: 4910136179d9cc5e90cd068006999350dc77fb74 [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>
Pekka Paalanen924cd942016-05-20 17:25:38 +030033#include <pixman.h>
Bryce Harrington273c2852014-12-15 15:51:25 -080034
Bill Spitzak2ccd9a22015-08-06 16:24:59 +010035#include <wayland-client-protocol.h>
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080036#include "weston-test-runner.h"
Derek Foremanf6a65922015-02-24 09:32:14 -060037#include "weston-test-client-protocol.h"
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080038
39struct 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 Chalupac3c3fc42015-03-30 09:17:40 -040045 /* the seat that is actually used for input events */
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080046 struct input *input;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040047 /* 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 Eoff1ba9b382012-12-07 13:50:32 -080053 struct output *output;
54 struct surface *surface;
55 int has_argb;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050056 struct wl_list global_list;
Derek Foreman9bb13392015-01-23 12:12:36 -060057 bool has_wl_drm;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050058};
59
60struct global {
61 uint32_t name;
62 char *interface;
63 uint32_t version;
64 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080065};
66
67struct test {
Derek Foremanf6a65922015-02-24 09:32:14 -060068 struct weston_test *weston_test;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080069 int pointer_x;
70 int pointer_y;
Neil Roberts40c0c3f2013-10-29 20:13:45 +000071 uint32_t n_egl_buffers;
Bryce Harrington692275f2015-04-23 16:33:49 -070072 int buffer_copy_done;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080073};
74
75struct input {
76 struct wl_seat *wl_seat;
77 struct pointer *pointer;
78 struct keyboard *keyboard;
Marek Chalupa8a5523c2015-03-30 09:20:07 -040079 struct touch *touch;
Marek Chalupa643d85f2015-03-30 06:37:56 -040080 char *seat_name;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040081 enum wl_seat_capability caps;
82 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080083};
84
85struct 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
94struct 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 Chalupa643d85f2015-03-30 06:37:56 -0400103 struct {
104 int rate;
105 int delay;
106 } repeat_info;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800107};
108
Marek Chalupa8a5523c2015-03-30 09:20:07 -0400109struct 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 Eoff1ba9b382012-12-07 13:50:32 -0800121struct output {
122 struct wl_output *wl_output;
123 int x;
124 int y;
125 int width;
126 int height;
Marek Chalupa643d85f2015-03-30 06:37:56 -0400127 int scale;
128 int initialized;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800129};
130
Pekka Paalanen924cd942016-05-20 17:25:38 +0300131struct buffer {
132 struct wl_buffer *proxy;
133 size_t len;
134 pixman_image_t *image;
135};
136
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800137struct surface {
138 struct wl_surface *wl_surface;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800139 struct output *output;
140 int x;
141 int y;
142 int width;
143 int height;
Pekka Paalanen924cd942016-05-20 17:25:38 +0300144 struct buffer *buffer;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800145};
146
Bryce Harrington273c2852014-12-15 15:51:25 -0800147struct rectangle {
148 int x;
149 int y;
150 int width;
151 int height;
152};
153
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800154struct client *
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200155create_client(void);
156
157struct client *
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200158create_client_and_test_surface(int x, int y, int width, int height);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800159
Pekka Paalanen924cd942016-05-20 17:25:38 +0300160struct buffer *
161create_shm_buffer_a8r8g8b8(struct client *client, int width, int height);
162
163void
164buffer_destroy(struct buffer *buf);
165
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800166int
167surface_contains(struct surface *surface, int x, int y);
168
169void
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800170move_client(struct client *client, int x, int y);
171
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200172#define client_roundtrip(c) do { \
173 assert(wl_display_roundtrip((c)->wl_display) >= 0); \
174} while (0)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800175
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200176struct wl_callback *
177frame_callback_set(struct wl_surface *surface, int *done);
178
Marek Chalupa1740aa82014-07-16 11:32:50 +0200179int
180frame_callback_wait_nofail(struct client *client, int *done);
181
182#define frame_callback_wait(c, d) assert(frame_callback_wait_nofail((c), (d)))
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200183
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000184int
185get_n_egl_buffers(struct client *client);
186
Kristian Høgsberg42284f52014-01-01 17:38:04 -0800187void
188skip(const char *fmt, ...);
189
Marek Chalupa4d06d462014-07-16 11:27:06 +0200190void
191expect_protocol_error(struct client *client,
192 const struct wl_interface *intf, uint32_t code);
193
Bryce Harrington892122e2015-09-24 14:31:44 -0700194char *
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800195screenshot_output_filename(const char *basename, uint32_t seq);
196
Bryce Harrington892122e2015-09-24 14:31:44 -0700197char *
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800198screenshot_reference_filename(const char *basename, uint32_t seq);
199
Bryce Harrington273c2852014-12-15 15:51:25 -0800200bool
Pekka Paalanen47d68da2016-05-23 17:42:27 +0300201check_images_match(pixman_image_t *img_a, pixman_image_t *img_b,
202 const struct rectangle *clip);
Bryce Harrington273c2852014-12-15 15:51:25 -0800203
Bryce Harrington892122e2015-09-24 14:31:44 -0700204bool
205write_surface_as_png(const struct surface *weston_surface, const char *fname);
206
207struct surface *
208load_surface_from_png(const char *fname);
209
210struct surface *
211create_screenshot_surface(struct client *client);
212
213struct surface *
214capture_screenshot_of_output(struct client *client);
215
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800216#endif