blob: bd60f2819c2028d513cb35567b84bf488ebda467 [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 Chalupa643d85f2015-03-30 06:37:56 -040072 char *seat_name;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040073 enum wl_seat_capability caps;
74 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080075};
76
77struct pointer {
78 struct wl_pointer *wl_pointer;
79 struct surface *focus;
80 int x;
81 int y;
82 uint32_t button;
83 uint32_t state;
84};
85
86struct keyboard {
87 struct wl_keyboard *wl_keyboard;
88 struct surface *focus;
89 uint32_t key;
90 uint32_t state;
91 uint32_t mods_depressed;
92 uint32_t mods_latched;
93 uint32_t mods_locked;
94 uint32_t group;
Marek Chalupa643d85f2015-03-30 06:37:56 -040095 struct {
96 int rate;
97 int delay;
98 } repeat_info;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080099};
100
101struct output {
102 struct wl_output *wl_output;
103 int x;
104 int y;
105 int width;
106 int height;
Marek Chalupa643d85f2015-03-30 06:37:56 -0400107 int scale;
108 int initialized;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800109};
110
111struct surface {
112 struct wl_surface *wl_surface;
113 struct wl_buffer *wl_buffer;
114 struct output *output;
115 int x;
116 int y;
117 int width;
118 int height;
119 void *data;
120};
121
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800122static inline void *
123xzalloc(size_t size)
124{
125 void *p;
126
127 p = calloc(1, size);
128 assert(p);
129
130 return p;
131}
132
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800133struct client *
134client_create(int x, int y, int width, int height);
135
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200136struct wl_buffer *
137create_shm_buffer(struct client *client, int width, int height, void **pixels);
138
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800139int
140surface_contains(struct surface *surface, int x, int y);
141
142void
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800143move_client(struct client *client, int x, int y);
144
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200145#define client_roundtrip(c) do { \
146 assert(wl_display_roundtrip((c)->wl_display) >= 0); \
147} while (0)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800148
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200149struct wl_callback *
150frame_callback_set(struct wl_surface *surface, int *done);
151
Marek Chalupa1740aa82014-07-16 11:32:50 +0200152int
153frame_callback_wait_nofail(struct client *client, int *done);
154
155#define frame_callback_wait(c, d) assert(frame_callback_wait_nofail((c), (d)))
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200156
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000157int
158get_n_egl_buffers(struct client *client);
159
Kristian Høgsberg42284f52014-01-01 17:38:04 -0800160void
161skip(const char *fmt, ...);
162
Marek Chalupa4d06d462014-07-16 11:27:06 +0200163void
164expect_protocol_error(struct client *client,
165 const struct wl_interface *intf, uint32_t code);
166
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800167#endif