blob: 43a5aa706e2b052b5c93155b33ee4fce758ac1c4 [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>
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080030#include "weston-test-runner.h"
Derek Foremanf6a65922015-02-24 09:32:14 -060031#include "weston-test-client-protocol.h"
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080032
33struct client {
34 struct wl_display *wl_display;
35 struct wl_registry *wl_registry;
36 struct wl_compositor *wl_compositor;
37 struct wl_shm *wl_shm;
38 struct test *test;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040039 /* the seat that is actually used for input events */
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080040 struct input *input;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040041 /* server can have more wl_seats. We need keep them all until we
42 * find the one that we need. After that, the others
43 * will be destroyed, so this list will have the length of 1.
44 * If some day in the future we will need the other seats,
45 * we can just keep them here. */
46 struct wl_list inputs;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080047 struct output *output;
48 struct surface *surface;
49 int has_argb;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050050 struct wl_list global_list;
Derek Foreman9bb13392015-01-23 12:12:36 -060051 bool has_wl_drm;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050052};
53
54struct global {
55 uint32_t name;
56 char *interface;
57 uint32_t version;
58 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080059};
60
61struct test {
Derek Foremanf6a65922015-02-24 09:32:14 -060062 struct weston_test *weston_test;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080063 int pointer_x;
64 int pointer_y;
Neil Roberts40c0c3f2013-10-29 20:13:45 +000065 uint32_t n_egl_buffers;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080066};
67
68struct input {
69 struct wl_seat *wl_seat;
70 struct pointer *pointer;
71 struct keyboard *keyboard;
Marek Chalupa8a5523c2015-03-30 09:20:07 -040072 struct touch *touch;
Marek Chalupa643d85f2015-03-30 06:37:56 -040073 char *seat_name;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040074 enum wl_seat_capability caps;
75 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080076};
77
78struct pointer {
79 struct wl_pointer *wl_pointer;
80 struct surface *focus;
81 int x;
82 int y;
83 uint32_t button;
84 uint32_t state;
85};
86
87struct keyboard {
88 struct wl_keyboard *wl_keyboard;
89 struct surface *focus;
90 uint32_t key;
91 uint32_t state;
92 uint32_t mods_depressed;
93 uint32_t mods_latched;
94 uint32_t mods_locked;
95 uint32_t group;
Marek Chalupa643d85f2015-03-30 06:37:56 -040096 struct {
97 int rate;
98 int delay;
99 } repeat_info;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800100};
101
Marek Chalupa8a5523c2015-03-30 09:20:07 -0400102struct touch {
103 struct wl_touch *wl_touch;
104 int down_x;
105 int down_y;
106 int x;
107 int y;
108 int id;
109 int up_id; /* id of last wl_touch.up event */
110 int frame_no;
111 int cancel_no;
112};
113
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800114struct output {
115 struct wl_output *wl_output;
116 int x;
117 int y;
118 int width;
119 int height;
Marek Chalupa643d85f2015-03-30 06:37:56 -0400120 int scale;
121 int initialized;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800122};
123
124struct surface {
125 struct wl_surface *wl_surface;
126 struct wl_buffer *wl_buffer;
127 struct output *output;
128 int x;
129 int y;
130 int width;
131 int height;
132 void *data;
133};
134
Bryce Harrington61a64362015-04-22 18:23:01 -0700135void *
136fail_on_null(void *p);
137
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800138static inline void *
Bryce Harrington61a64362015-04-22 18:23:01 -0700139xzalloc(size_t s)
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800140{
Bryce Harrington61a64362015-04-22 18:23:01 -0700141 return fail_on_null(calloc(1, s));
142}
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800143
Bryce Harrington61a64362015-04-22 18:23:01 -0700144static inline void *
145xmalloc(size_t s)
146{
147 return fail_on_null(malloc(s));
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800148}
149
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800150struct client *
Pekka Paalanen1ffd4612015-03-26 12:49:35 +0200151create_client(void);
152
153struct client *
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200154create_client_and_test_surface(int x, int y, int width, int height);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800155
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200156struct wl_buffer *
157create_shm_buffer(struct client *client, int width, int height, void **pixels);
158
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800159int
160surface_contains(struct surface *surface, int x, int y);
161
162void
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800163move_client(struct client *client, int x, int y);
164
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200165#define client_roundtrip(c) do { \
166 assert(wl_display_roundtrip((c)->wl_display) >= 0); \
167} while (0)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800168
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200169struct wl_callback *
170frame_callback_set(struct wl_surface *surface, int *done);
171
Marek Chalupa1740aa82014-07-16 11:32:50 +0200172int
173frame_callback_wait_nofail(struct client *client, int *done);
174
175#define frame_callback_wait(c, d) assert(frame_callback_wait_nofail((c), (d)))
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200176
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000177int
178get_n_egl_buffers(struct client *client);
179
Kristian Høgsberg42284f52014-01-01 17:38:04 -0800180void
181skip(const char *fmt, ...);
182
Marek Chalupa4d06d462014-07-16 11:27:06 +0200183void
184expect_protocol_error(struct client *client,
185 const struct wl_interface *intf, uint32_t code);
186
Bryce Harringtonc1a1d6c2014-12-09 14:46:36 -0800187char*
188screenshot_output_filename(const char *basename, uint32_t seq);
189
190char*
191screenshot_reference_filename(const char *basename, uint32_t seq);
192
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800193#endif