blob: 9be39d9eec6a7d42a3d1cce2264d2929db74a745 [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;
39 struct input *input;
40 struct output *output;
41 struct surface *surface;
42 int has_argb;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050043 struct wl_list global_list;
Derek Foreman9bb13392015-01-23 12:12:36 -060044 bool has_wl_drm;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050045};
46
47struct global {
48 uint32_t name;
49 char *interface;
50 uint32_t version;
51 struct wl_list link;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080052};
53
54struct test {
Derek Foremanf6a65922015-02-24 09:32:14 -060055 struct weston_test *weston_test;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080056 int pointer_x;
57 int pointer_y;
Neil Roberts40c0c3f2013-10-29 20:13:45 +000058 uint32_t n_egl_buffers;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080059};
60
61struct input {
62 struct wl_seat *wl_seat;
63 struct pointer *pointer;
64 struct keyboard *keyboard;
Marek Chalupa643d85f2015-03-30 06:37:56 -040065 char *seat_name;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080066};
67
68struct pointer {
69 struct wl_pointer *wl_pointer;
70 struct surface *focus;
71 int x;
72 int y;
73 uint32_t button;
74 uint32_t state;
75};
76
77struct keyboard {
78 struct wl_keyboard *wl_keyboard;
79 struct surface *focus;
80 uint32_t key;
81 uint32_t state;
82 uint32_t mods_depressed;
83 uint32_t mods_latched;
84 uint32_t mods_locked;
85 uint32_t group;
Marek Chalupa643d85f2015-03-30 06:37:56 -040086 struct {
87 int rate;
88 int delay;
89 } repeat_info;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080090};
91
92struct output {
93 struct wl_output *wl_output;
94 int x;
95 int y;
96 int width;
97 int height;
Marek Chalupa643d85f2015-03-30 06:37:56 -040098 int scale;
99 int initialized;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800100};
101
102struct surface {
103 struct wl_surface *wl_surface;
104 struct wl_buffer *wl_buffer;
105 struct output *output;
106 int x;
107 int y;
108 int width;
109 int height;
110 void *data;
111};
112
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800113static inline void *
114xzalloc(size_t size)
115{
116 void *p;
117
118 p = calloc(1, size);
119 assert(p);
120
121 return p;
122}
123
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800124struct client *
125client_create(int x, int y, int width, int height);
126
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200127struct wl_buffer *
128create_shm_buffer(struct client *client, int width, int height, void **pixels);
129
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800130int
131surface_contains(struct surface *surface, int x, int y);
132
133void
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800134move_client(struct client *client, int x, int y);
135
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200136#define client_roundtrip(c) do { \
137 assert(wl_display_roundtrip((c)->wl_display) >= 0); \
138} while (0)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800139
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200140struct wl_callback *
141frame_callback_set(struct wl_surface *surface, int *done);
142
Marek Chalupa1740aa82014-07-16 11:32:50 +0200143int
144frame_callback_wait_nofail(struct client *client, int *done);
145
146#define frame_callback_wait(c, d) assert(frame_callback_wait_nofail((c), (d)))
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200147
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000148int
149get_n_egl_buffers(struct client *client);
150
Kristian Høgsberg42284f52014-01-01 17:38:04 -0800151void
152skip(const char *fmt, ...);
153
Marek Chalupa4d06d462014-07-16 11:27:06 +0200154void
155expect_protocol_error(struct client *client,
156 const struct wl_interface *intf, uint32_t code);
157
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800158#endif