blob: 7c2727ad47a861c45ff96ca7b2a298f56cd9dd01 [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
Bill Spitzak2ccd9a22015-08-06 16:24:59 +010034#include <wayland-client-protocol.h>
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080035#include "weston-test-runner.h"
Derek Foremanf6a65922015-02-24 09:32:14 -060036#include "weston-test-client-protocol.h"
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080037
38struct client {
39 struct wl_display *wl_display;
40 struct wl_registry *wl_registry;
41 struct wl_compositor *wl_compositor;
42 struct wl_shm *wl_shm;
43 struct test *test;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040044 /* the seat that is actually used for input events */
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080045 struct input *input;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040046 /* server can have more wl_seats. We need keep them all until we
47 * find the one that we need. After that, the others
48 * will be destroyed, so this list will have the length of 1.
49 * If some day in the future we will need the other seats,
50 * we can just keep them here. */
51 struct wl_list inputs;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080052 struct output *output;
53 struct surface *surface;
54 int has_argb;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050055 struct wl_list global_list;
Derek Foreman9bb13392015-01-23 12:12:36 -060056 bool has_wl_drm;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050057};
58
59struct global {
60 uint32_t name;
61 char *interface;
62 uint32_t version;
63 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080064};
65
66struct test {
Derek Foremanf6a65922015-02-24 09:32:14 -060067 struct weston_test *weston_test;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080068 int pointer_x;
69 int pointer_y;
Neil Roberts40c0c3f2013-10-29 20:13:45 +000070 uint32_t n_egl_buffers;
Bryce Harrington692275f2015-04-23 16:33:49 -070071 int buffer_copy_done;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080072};
73
74struct input {
75 struct wl_seat *wl_seat;
76 struct pointer *pointer;
77 struct keyboard *keyboard;
Marek Chalupa8a5523c2015-03-30 09:20:07 -040078 struct touch *touch;
Marek Chalupa643d85f2015-03-30 06:37:56 -040079 char *seat_name;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040080 enum wl_seat_capability caps;
81 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080082};
83
84struct pointer {
85 struct wl_pointer *wl_pointer;
86 struct surface *focus;
87 int x;
88 int y;
89 uint32_t button;
90 uint32_t state;
91};
92
93struct keyboard {
94 struct wl_keyboard *wl_keyboard;
95 struct surface *focus;
96 uint32_t key;
97 uint32_t state;
98 uint32_t mods_depressed;
99 uint32_t mods_latched;
100 uint32_t mods_locked;
101 uint32_t group;
Marek Chalupa643d85f2015-03-30 06:37:56 -0400102 struct {
103 int rate;
104 int delay;
105 } repeat_info;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800106};
107
Marek Chalupa8a5523c2015-03-30 09:20:07 -0400108struct touch {
109 struct wl_touch *wl_touch;
110 int down_x;
111 int down_y;
112 int x;
113 int y;
114 int id;
115 int up_id; /* id of last wl_touch.up event */
116 int frame_no;
117 int cancel_no;
118};
119
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800120struct output {
121 struct wl_output *wl_output;
122 int x;
123 int y;
124 int width;
125 int height;
Marek Chalupa643d85f2015-03-30 06:37:56 -0400126 int scale;
127 int initialized;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800128};
129
130struct surface {
131 struct wl_surface *wl_surface;
132 struct wl_buffer *wl_buffer;
133 struct output *output;
134 int x;
135 int y;
136 int width;
137 int height;
138 void *data;
139};
140
Bryce Harrington273c2852014-12-15 15:51:25 -0800141struct rectangle {
142 int x;
143 int y;
144 int width;
145 int height;
146};
147
Bryce Harrington61a64362015-04-22 18:23:01 -0700148void *
149fail_on_null(void *p);
150
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800151static inline void *
Bryce Harrington61a64362015-04-22 18:23:01 -0700152xzalloc(size_t s)
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800153{
Bryce Harrington61a64362015-04-22 18:23:01 -0700154 return fail_on_null(calloc(1, s));
155}
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800156
Bryce Harrington61a64362015-04-22 18:23:01 -0700157static inline void *
158xmalloc(size_t s)
159{
160 return fail_on_null(malloc(s));
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800161}
162
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800163struct client *
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200164create_client(void);
165
166struct client *
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200167create_client_and_test_surface(int x, int y, int width, int height);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800168
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200169struct wl_buffer *
170create_shm_buffer(struct client *client, int width, int height, void **pixels);
171
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800172int
173surface_contains(struct surface *surface, int x, int y);
174
175void
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800176move_client(struct client *client, int x, int y);
177
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200178#define client_roundtrip(c) do { \
179 assert(wl_display_roundtrip((c)->wl_display) >= 0); \
180} while (0)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800181
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200182struct wl_callback *
183frame_callback_set(struct wl_surface *surface, int *done);
184
Marek Chalupa1740aa82014-07-16 11:32:50 +0200185int
186frame_callback_wait_nofail(struct client *client, int *done);
187
188#define frame_callback_wait(c, d) assert(frame_callback_wait_nofail((c), (d)))
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200189
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000190int
191get_n_egl_buffers(struct client *client);
192
Kristian Høgsberg42284f52014-01-01 17:38:04 -0800193void
194skip(const char *fmt, ...);
195
Marek Chalupa4d06d462014-07-16 11:27:06 +0200196void
197expect_protocol_error(struct client *client,
198 const struct wl_interface *intf, uint32_t code);
199
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800200char*
201screenshot_output_filename(const char *basename, uint32_t seq);
202
203char*
204screenshot_reference_filename(const char *basename, uint32_t seq);
205
Bryce Harrington273c2852014-12-15 15:51:25 -0800206bool
Bryce Harrington39a5be22015-05-14 14:36:18 -0700207check_surfaces_geometry(const struct surface *a, const struct surface *b);
208
209bool
Bryce Harrington273c2852014-12-15 15:51:25 -0800210check_surfaces_equal(const struct surface *a, const struct surface *b);
211
212bool
213check_surfaces_match_in_clip(const struct surface *a, const struct surface *b, const struct rectangle *clip);
214
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800215#endif