blob: 5762258fafb8e467d3924b42ef81a0a9cce225cc [file] [log] [blame]
U. Artie Eoff1ba9b382012-12-07 13:50:32 -08001/*
2 * Copyright © 2012 Intel Corporation
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#ifndef _WESTON_TEST_CLIENT_HELPER_H_
24#define _WESTON_TEST_CLIENT_HELPER_H_
25
Andrew Wedgbury9cd661e2014-04-07 12:40:35 +010026#include "config.h"
27
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080028#include <assert.h>
Derek Foreman9bb13392015-01-23 12:12:36 -060029#include <stdbool.h>
Bryce Harrington273c2852014-12-15 15:51:25 -080030
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080031#include "weston-test-runner.h"
Derek Foremanf6a65922015-02-24 09:32:14 -060032#include "weston-test-client-protocol.h"
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080033
34struct client {
35 struct wl_display *wl_display;
36 struct wl_registry *wl_registry;
37 struct wl_compositor *wl_compositor;
38 struct wl_shm *wl_shm;
39 struct test *test;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040040 /* the seat that is actually used for input events */
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080041 struct input *input;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040042 /* server can have more wl_seats. We need keep them all until we
43 * find the one that we need. After that, the others
44 * will be destroyed, so this list will have the length of 1.
45 * If some day in the future we will need the other seats,
46 * we can just keep them here. */
47 struct wl_list inputs;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080048 struct output *output;
49 struct surface *surface;
50 int has_argb;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050051 struct wl_list global_list;
Derek Foreman9bb13392015-01-23 12:12:36 -060052 bool has_wl_drm;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050053};
54
55struct global {
56 uint32_t name;
57 char *interface;
58 uint32_t version;
59 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080060};
61
62struct test {
Derek Foremanf6a65922015-02-24 09:32:14 -060063 struct weston_test *weston_test;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080064 int pointer_x;
65 int pointer_y;
Neil Roberts40c0c3f2013-10-29 20:13:45 +000066 uint32_t n_egl_buffers;
Bryce Harrington692275f2015-04-23 16:33:49 -070067 int buffer_copy_done;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080068};
69
70struct input {
71 struct wl_seat *wl_seat;
72 struct pointer *pointer;
73 struct keyboard *keyboard;
Marek Chalupa8a5523c2015-03-30 09:20:07 -040074 struct touch *touch;
Marek Chalupa643d85f2015-03-30 06:37:56 -040075 char *seat_name;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040076 enum wl_seat_capability caps;
77 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080078};
79
80struct pointer {
81 struct wl_pointer *wl_pointer;
82 struct surface *focus;
83 int x;
84 int y;
85 uint32_t button;
86 uint32_t state;
87};
88
89struct keyboard {
90 struct wl_keyboard *wl_keyboard;
91 struct surface *focus;
92 uint32_t key;
93 uint32_t state;
94 uint32_t mods_depressed;
95 uint32_t mods_latched;
96 uint32_t mods_locked;
97 uint32_t group;
Marek Chalupa643d85f2015-03-30 06:37:56 -040098 struct {
99 int rate;
100 int delay;
101 } repeat_info;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800102};
103
Marek Chalupa8a5523c2015-03-30 09:20:07 -0400104struct touch {
105 struct wl_touch *wl_touch;
106 int down_x;
107 int down_y;
108 int x;
109 int y;
110 int id;
111 int up_id; /* id of last wl_touch.up event */
112 int frame_no;
113 int cancel_no;
114};
115
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800116struct output {
117 struct wl_output *wl_output;
118 int x;
119 int y;
120 int width;
121 int height;
Marek Chalupa643d85f2015-03-30 06:37:56 -0400122 int scale;
123 int initialized;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800124};
125
126struct surface {
127 struct wl_surface *wl_surface;
128 struct wl_buffer *wl_buffer;
129 struct output *output;
130 int x;
131 int y;
132 int width;
133 int height;
134 void *data;
135};
136
Bryce Harrington273c2852014-12-15 15:51:25 -0800137struct rectangle {
138 int x;
139 int y;
140 int width;
141 int height;
142};
143
Bryce Harrington61a64362015-04-22 18:23:01 -0700144void *
145fail_on_null(void *p);
146
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800147static inline void *
Bryce Harrington61a64362015-04-22 18:23:01 -0700148xzalloc(size_t s)
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800149{
Bryce Harrington61a64362015-04-22 18:23:01 -0700150 return fail_on_null(calloc(1, s));
151}
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800152
Bryce Harrington61a64362015-04-22 18:23:01 -0700153static inline void *
154xmalloc(size_t s)
155{
156 return fail_on_null(malloc(s));
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800157}
158
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800159struct client *
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200160create_client(void);
161
162struct client *
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200163create_client_and_test_surface(int x, int y, int width, int height);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800164
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200165struct wl_buffer *
166create_shm_buffer(struct client *client, int width, int height, void **pixels);
167
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800168int
169surface_contains(struct surface *surface, int x, int y);
170
171void
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800172move_client(struct client *client, int x, int y);
173
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200174#define client_roundtrip(c) do { \
175 assert(wl_display_roundtrip((c)->wl_display) >= 0); \
176} while (0)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800177
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200178struct wl_callback *
179frame_callback_set(struct wl_surface *surface, int *done);
180
Marek Chalupa1740aa82014-07-16 11:32:50 +0200181int
182frame_callback_wait_nofail(struct client *client, int *done);
183
184#define frame_callback_wait(c, d) assert(frame_callback_wait_nofail((c), (d)))
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200185
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000186int
187get_n_egl_buffers(struct client *client);
188
Kristian Høgsberg42284f52014-01-01 17:38:04 -0800189void
190skip(const char *fmt, ...);
191
Marek Chalupa4d06d462014-07-16 11:27:06 +0200192void
193expect_protocol_error(struct client *client,
194 const struct wl_interface *intf, uint32_t code);
195
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800196char*
197screenshot_output_filename(const char *basename, uint32_t seq);
198
199char*
200screenshot_reference_filename(const char *basename, uint32_t seq);
201
Bryce Harrington273c2852014-12-15 15:51:25 -0800202bool
Bryce Harrington39a5be22015-05-14 14:36:18 -0700203check_surfaces_geometry(const struct surface *a, const struct surface *b);
204
205bool
Bryce Harrington273c2852014-12-15 15:51:25 -0800206check_surfaces_equal(const struct surface *a, const struct surface *b);
207
208bool
209check_surfaces_match_in_clip(const struct surface *a, const struct surface *b, const struct rectangle *clip);
210
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800211#endif