blob: 2564044774faaa628538c206491a28380789046d [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;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080067};
68
69struct input {
70 struct wl_seat *wl_seat;
71 struct pointer *pointer;
72 struct keyboard *keyboard;
Marek Chalupa8a5523c2015-03-30 09:20:07 -040073 struct touch *touch;
Marek Chalupa643d85f2015-03-30 06:37:56 -040074 char *seat_name;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040075 enum wl_seat_capability caps;
76 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080077};
78
79struct pointer {
80 struct wl_pointer *wl_pointer;
81 struct surface *focus;
82 int x;
83 int y;
84 uint32_t button;
85 uint32_t state;
86};
87
88struct keyboard {
89 struct wl_keyboard *wl_keyboard;
90 struct surface *focus;
91 uint32_t key;
92 uint32_t state;
93 uint32_t mods_depressed;
94 uint32_t mods_latched;
95 uint32_t mods_locked;
96 uint32_t group;
Marek Chalupa643d85f2015-03-30 06:37:56 -040097 struct {
98 int rate;
99 int delay;
100 } repeat_info;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800101};
102
Marek Chalupa8a5523c2015-03-30 09:20:07 -0400103struct touch {
104 struct wl_touch *wl_touch;
105 int down_x;
106 int down_y;
107 int x;
108 int y;
109 int id;
110 int up_id; /* id of last wl_touch.up event */
111 int frame_no;
112 int cancel_no;
113};
114
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800115struct output {
116 struct wl_output *wl_output;
117 int x;
118 int y;
119 int width;
120 int height;
Marek Chalupa643d85f2015-03-30 06:37:56 -0400121 int scale;
122 int initialized;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800123};
124
125struct surface {
126 struct wl_surface *wl_surface;
127 struct wl_buffer *wl_buffer;
128 struct output *output;
129 int x;
130 int y;
131 int width;
132 int height;
133 void *data;
134};
135
Bryce Harrington273c2852014-12-15 15:51:25 -0800136struct rectangle {
137 int x;
138 int y;
139 int width;
140 int height;
141};
142
Bryce Harrington61a64362015-04-22 18:23:01 -0700143void *
144fail_on_null(void *p);
145
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800146static inline void *
Bryce Harrington61a64362015-04-22 18:23:01 -0700147xzalloc(size_t s)
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800148{
Bryce Harrington61a64362015-04-22 18:23:01 -0700149 return fail_on_null(calloc(1, s));
150}
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800151
Bryce Harrington61a64362015-04-22 18:23:01 -0700152static inline void *
153xmalloc(size_t s)
154{
155 return fail_on_null(malloc(s));
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800156}
157
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800158struct client *
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200159create_client(void);
160
161struct client *
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200162create_client_and_test_surface(int x, int y, int width, int height);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800163
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200164struct wl_buffer *
165create_shm_buffer(struct client *client, int width, int height, void **pixels);
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
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000185int
186get_n_egl_buffers(struct client *client);
187
Kristian Høgsberg42284f52014-01-01 17:38:04 -0800188void
189skip(const char *fmt, ...);
190
Marek Chalupa4d06d462014-07-16 11:27:06 +0200191void
192expect_protocol_error(struct client *client,
193 const struct wl_interface *intf, uint32_t code);
194
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800195char*
196screenshot_output_filename(const char *basename, uint32_t seq);
197
198char*
199screenshot_reference_filename(const char *basename, uint32_t seq);
200
Bryce Harrington273c2852014-12-15 15:51:25 -0800201bool
202check_surfaces_equal(const struct surface *a, const struct surface *b);
203
204bool
205check_surfaces_match_in_clip(const struct surface *a, const struct surface *b, const struct rectangle *clip);
206
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800207#endif