blob: a6ea524b5763f13c68f238eb8859f8f51e598a18 [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"
31#include "wayland-test-client-protocol.h"
32
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 {
55 struct wl_test *wl_test;
56 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;
65};
66
67struct pointer {
68 struct wl_pointer *wl_pointer;
69 struct surface *focus;
70 int x;
71 int y;
72 uint32_t button;
73 uint32_t state;
74};
75
76struct keyboard {
77 struct wl_keyboard *wl_keyboard;
78 struct surface *focus;
79 uint32_t key;
80 uint32_t state;
81 uint32_t mods_depressed;
82 uint32_t mods_latched;
83 uint32_t mods_locked;
84 uint32_t group;
85};
86
87struct output {
88 struct wl_output *wl_output;
89 int x;
90 int y;
91 int width;
92 int height;
93};
94
95struct surface {
96 struct wl_surface *wl_surface;
97 struct wl_buffer *wl_buffer;
98 struct output *output;
99 int x;
100 int y;
101 int width;
102 int height;
103 void *data;
104};
105
Bryce Harrington2cd82b72014-11-19 17:18:36 -0800106static inline void *
107xzalloc(size_t size)
108{
109 void *p;
110
111 p = calloc(1, size);
112 assert(p);
113
114 return p;
115}
116
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800117struct client *
118client_create(int x, int y, int width, int height);
119
Pekka Paalanen32ac9b92013-02-08 17:01:26 +0200120struct wl_buffer *
121create_shm_buffer(struct client *client, int width, int height, void **pixels);
122
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800123int
124surface_contains(struct surface *surface, int x, int y);
125
126void
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800127move_client(struct client *client, int x, int y);
128
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200129#define client_roundtrip(c) do { \
130 assert(wl_display_roundtrip((c)->wl_display) >= 0); \
131} while (0)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800132
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200133struct wl_callback *
134frame_callback_set(struct wl_surface *surface, int *done);
135
Marek Chalupa1740aa82014-07-16 11:32:50 +0200136int
137frame_callback_wait_nofail(struct client *client, int *done);
138
139#define frame_callback_wait(c, d) assert(frame_callback_wait_nofail((c), (d)))
Pekka Paalanen8aaef7d2013-02-08 17:01:25 +0200140
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000141int
142get_n_egl_buffers(struct client *client);
143
Kristian Høgsberg42284f52014-01-01 17:38:04 -0800144void
145skip(const char *fmt, ...);
146
Marek Chalupa4d06d462014-07-16 11:27:06 +0200147void
148expect_protocol_error(struct client *client,
149 const struct wl_interface *intf, uint32_t code);
150
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800151#endif