blob: 1c8180dafabe2f983ab480249a3a0d8e096b17f6 [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>
Bryce Harrington273c2852014-12-15 15:51:25 -080033
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080034#include "weston-test-runner.h"
Derek Foremanf6a65922015-02-24 09:32:14 -060035#include "weston-test-client-protocol.h"
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080036
37struct client {
38 struct wl_display *wl_display;
39 struct wl_registry *wl_registry;
40 struct wl_compositor *wl_compositor;
41 struct wl_shm *wl_shm;
42 struct test *test;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040043 /* the seat that is actually used for input events */
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080044 struct input *input;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040045 /* server can have more wl_seats. We need keep them all until we
46 * find the one that we need. After that, the others
47 * will be destroyed, so this list will have the length of 1.
48 * If some day in the future we will need the other seats,
49 * we can just keep them here. */
50 struct wl_list inputs;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080051 struct output *output;
52 struct surface *surface;
53 int has_argb;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050054 struct wl_list global_list;
Derek Foreman9bb13392015-01-23 12:12:36 -060055 bool has_wl_drm;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050056};
57
58struct global {
59 uint32_t name;
60 char *interface;
61 uint32_t version;
62 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080063};
64
65struct test {
Derek Foremanf6a65922015-02-24 09:32:14 -060066 struct weston_test *weston_test;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080067 int pointer_x;
68 int pointer_y;
Neil Roberts40c0c3f2013-10-29 20:13:45 +000069 uint32_t n_egl_buffers;
Bryce Harrington692275f2015-04-23 16:33:49 -070070 int buffer_copy_done;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080071};
72
73struct input {
74 struct wl_seat *wl_seat;
75 struct pointer *pointer;
76 struct keyboard *keyboard;
Marek Chalupa8a5523c2015-03-30 09:20:07 -040077 struct touch *touch;
Marek Chalupa643d85f2015-03-30 06:37:56 -040078 char *seat_name;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040079 enum wl_seat_capability caps;
80 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080081};
82
83struct pointer {
84 struct wl_pointer *wl_pointer;
85 struct surface *focus;
86 int x;
87 int y;
88 uint32_t button;
89 uint32_t state;
90};
91
92struct keyboard {
93 struct wl_keyboard *wl_keyboard;
94 struct surface *focus;
95 uint32_t key;
96 uint32_t state;
97 uint32_t mods_depressed;
98 uint32_t mods_latched;
99 uint32_t mods_locked;
100 uint32_t group;
Marek Chalupa643d85f2015-03-30 06:37:56 -0400101 struct {
102 int rate;
103 int delay;
104 } repeat_info;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800105};
106
Marek Chalupa8a5523c2015-03-30 09:20:07 -0400107struct touch {
108 struct wl_touch *wl_touch;
109 int down_x;
110 int down_y;
111 int x;
112 int y;
113 int id;
114 int up_id; /* id of last wl_touch.up event */
115 int frame_no;
116 int cancel_no;
117};
118
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800119struct output {
120 struct wl_output *wl_output;
121 int x;
122 int y;
123 int width;
124 int height;
Marek Chalupa643d85f2015-03-30 06:37:56 -0400125 int scale;
126 int initialized;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800127};
128
129struct surface {
130 struct wl_surface *wl_surface;
131 struct wl_buffer *wl_buffer;
132 struct output *output;
133 int x;
134 int y;
135 int width;
136 int height;
137 void *data;
138};
139
Bryce Harrington273c2852014-12-15 15:51:25 -0800140struct rectangle {
141 int x;
142 int y;
143 int width;
144 int height;
145};
146
Bryce Harrington61a64362015-04-22 18:23:01 -0700147void *
148fail_on_null(void *p);
149
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800150static inline void *
Bryce Harrington61a64362015-04-22 18:23:01 -0700151xzalloc(size_t s)
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800152{
Bryce Harrington61a64362015-04-22 18:23:01 -0700153 return fail_on_null(calloc(1, s));
154}
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800155
Bryce Harrington61a64362015-04-22 18:23:01 -0700156static inline void *
157xmalloc(size_t s)
158{
159 return fail_on_null(malloc(s));
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800160}
161
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800162struct client *
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200163create_client(void);
164
165struct client *
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200166create_client_and_test_surface(int x, int y, int width, int height);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800167
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200168struct wl_buffer *
169create_shm_buffer(struct client *client, int width, int height, void **pixels);
170
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800171int
172surface_contains(struct surface *surface, int x, int y);
173
174void
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800175move_client(struct client *client, int x, int y);
176
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200177#define client_roundtrip(c) do { \
178 assert(wl_display_roundtrip((c)->wl_display) >= 0); \
179} while (0)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800180
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200181struct wl_callback *
182frame_callback_set(struct wl_surface *surface, int *done);
183
Marek Chalupa1740aa82014-07-16 11:32:50 +0200184int
185frame_callback_wait_nofail(struct client *client, int *done);
186
187#define frame_callback_wait(c, d) assert(frame_callback_wait_nofail((c), (d)))
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200188
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000189int
190get_n_egl_buffers(struct client *client);
191
Kristian Høgsberg42284f52014-01-01 17:38:04 -0800192void
193skip(const char *fmt, ...);
194
Marek Chalupa4d06d462014-07-16 11:27:06 +0200195void
196expect_protocol_error(struct client *client,
197 const struct wl_interface *intf, uint32_t code);
198
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800199char*
200screenshot_output_filename(const char *basename, uint32_t seq);
201
202char*
203screenshot_reference_filename(const char *basename, uint32_t seq);
204
Bryce Harrington273c2852014-12-15 15:51:25 -0800205bool
Bryce Harrington39a5be22015-05-14 14:36:18 -0700206check_surfaces_geometry(const struct surface *a, const struct surface *b);
207
208bool
Bryce Harrington273c2852014-12-15 15:51:25 -0800209check_surfaces_equal(const struct surface *a, const struct surface *b);
210
211bool
212check_surfaces_match_in_clip(const struct surface *a, const struct surface *b, const struct rectangle *clip);
213
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800214#endif