blob: 64dd7a0c0b5ac8381e0b899a3d14d59250ab2f27 [file] [log] [blame]
Kristian Høgsberg3018b442012-04-27 15:02:56 -04001/*
2 * Copyright © 2012 Intel Corporation
Pekka Paalanend1c426e2013-02-08 17:01:27 +02003 * Copyright © 2013 Collabora, Ltd.
Kristian Høgsberg3018b442012-04-27 15:02:56 -04004 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07005 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
Kristian Høgsberg3018b442012-04-27 15:02:56 -040012 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070013 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
Kristian Høgsberg3018b442012-04-27 15:02:56 -040025 */
26
Bryce Harrington12cc4052014-11-19 17:18:33 -080027#include "config.h"
28
U. Artie Eoff84f9db52012-12-07 13:50:33 -080029#include "weston-test-client-helper.h"
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070030
31static void
U. Artie Eoff84f9db52012-12-07 13:50:33 -080032check_pointer(struct client *client, int x, int y)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070033{
U. Artie Eoff84f9db52012-12-07 13:50:33 -080034 int sx, sy;
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070035
U. Artie Eoff84f9db52012-12-07 13:50:33 -080036 /* check that the client got the global pointer update */
37 assert(client->test->pointer_x == x);
38 assert(client->test->pointer_y == y);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070039
U. Artie Eoff84f9db52012-12-07 13:50:33 -080040 /* Does global pointer map onto the surface? */
41 if (surface_contains(client->surface, x, y)) {
42 /* check that the surface has the pointer focus */
43 assert(client->input->pointer->focus == client->surface);
44
45 /*
46 * check that the local surface pointer maps
47 * to the global pointer.
48 */
49 sx = client->input->pointer->x + client->surface->x;
50 sy = client->input->pointer->y + client->surface->y;
51 assert(sx == x);
52 assert(sy == y);
53 } else {
54 /*
55 * The global pointer does not map onto surface. So
56 * check that it doesn't have the pointer focus.
57 */
58 assert(client->input->pointer->focus == NULL);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070059 }
60}
61
62static void
U. Artie Eoff84f9db52012-12-07 13:50:33 -080063check_pointer_move(struct client *client, int x, int y)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070064{
Derek Foremanf6a65922015-02-24 09:32:14 -060065 weston_test_move_pointer(client->test->weston_test, x, y);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +020066 client_roundtrip(client);
U. Artie Eoff84f9db52012-12-07 13:50:33 -080067 check_pointer(client, x, y);
68}
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070069
U. Artie Eoff84f9db52012-12-07 13:50:33 -080070TEST(test_pointer_top_left)
71{
72 struct client *client;
73 int x, y;
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070074
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +020075 client = create_client_and_test_surface(46, 76, 111, 134);
U. Artie Eoff84f9db52012-12-07 13:50:33 -080076 assert(client);
77
78 /* move pointer outside top left */
79 x = client->surface->x - 1;
80 y = client->surface->y - 1;
81 assert(!surface_contains(client->surface, x, y));
82 check_pointer_move(client, x, y);
83
84 /* move pointer on top left */
85 x += 1; y += 1;
86 assert(surface_contains(client->surface, x, y));
87 check_pointer_move(client, x, y);
88
89 /* move pointer outside top left */
90 x -= 1; y -= 1;
91 assert(!surface_contains(client->surface, x, y));
92 check_pointer_move(client, x, y);
93}
94
95TEST(test_pointer_bottom_left)
96{
97 struct client *client;
98 int x, y;
99
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200100 client = create_client_and_test_surface(99, 100, 100, 98);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800101 assert(client);
102
103 /* move pointer outside bottom left */
104 x = client->surface->x - 1;
105 y = client->surface->y + client->surface->height;
106 assert(!surface_contains(client->surface, x, y));
107 check_pointer_move(client, x, y);
108
109 /* move pointer on bottom left */
110 x += 1; y -= 1;
111 assert(surface_contains(client->surface, x, y));
112 check_pointer_move(client, x, y);
113
114 /* move pointer outside bottom left */
115 x -= 1; y += 1;
116 assert(!surface_contains(client->surface, x, y));
117 check_pointer_move(client, x, y);
118}
119
120TEST(test_pointer_top_right)
121{
122 struct client *client;
123 int x, y;
124
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200125 client = create_client_and_test_surface(48, 100, 67, 100);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800126 assert(client);
127
128 /* move pointer outside top right */
129 x = client->surface->x + client->surface->width;
130 y = client->surface->y - 1;
131 assert(!surface_contains(client->surface, x, y));
132 check_pointer_move(client, x, y);
133
134 /* move pointer on top right */
135 x -= 1; y += 1;
136 assert(surface_contains(client->surface, x, y));
137 check_pointer_move(client, x, y);
138
139 /* move pointer outside top right */
140 x += 1; y -= 1;
141 assert(!surface_contains(client->surface, x, y));
142 check_pointer_move(client, x, y);
143}
144
145TEST(test_pointer_bottom_right)
146{
147 struct client *client;
148 int x, y;
149
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200150 client = create_client_and_test_surface(100, 123, 100, 69);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800151 assert(client);
152
153 /* move pointer outside bottom right */
154 x = client->surface->x + client->surface->width;
155 y = client->surface->y + client->surface->height;
156 assert(!surface_contains(client->surface, x, y));
157 check_pointer_move(client, x, y);
158
159 /* move pointer on bottom right */
160 x -= 1; y -= 1;
161 assert(surface_contains(client->surface, x, y));
162 check_pointer_move(client, x, y);
163
164 /* move pointer outside bottom right */
165 x += 1; y += 1;
166 assert(!surface_contains(client->surface, x, y));
167 check_pointer_move(client, x, y);
168}
169
170TEST(test_pointer_top_center)
171{
172 struct client *client;
173 int x, y;
174
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200175 client = create_client_and_test_surface(100, 201, 100, 50);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800176 assert(client);
177
178 /* move pointer outside top center */
179 x = client->surface->x + client->surface->width/2;
180 y = client->surface->y - 1;
181 assert(!surface_contains(client->surface, x, y));
182 check_pointer_move(client, x, y);
183
184 /* move pointer on top center */
185 y += 1;
186 assert(surface_contains(client->surface, x, y));
187 check_pointer_move(client, x, y);
188
189 /* move pointer outside top center */
190 y -= 1;
191 assert(!surface_contains(client->surface, x, y));
192 check_pointer_move(client, x, y);
193}
194
195TEST(test_pointer_bottom_center)
196{
197 struct client *client;
198 int x, y;
199
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200200 client = create_client_and_test_surface(100, 45, 67, 100);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800201 assert(client);
202
203 /* move pointer outside bottom center */
204 x = client->surface->x + client->surface->width/2;
205 y = client->surface->y + client->surface->height;
206 assert(!surface_contains(client->surface, x, y));
207 check_pointer_move(client, x, y);
208
209 /* move pointer on bottom center */
210 y -= 1;
211 assert(surface_contains(client->surface, x, y));
212 check_pointer_move(client, x, y);
213
214 /* move pointer outside bottom center */
215 y += 1;
216 assert(!surface_contains(client->surface, x, y));
217 check_pointer_move(client, x, y);
218}
219
220TEST(test_pointer_left_center)
221{
222 struct client *client;
223 int x, y;
224
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200225 client = create_client_and_test_surface(167, 45, 78, 100);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800226 assert(client);
227
228 /* move pointer outside left center */
229 x = client->surface->x - 1;
230 y = client->surface->y + client->surface->height/2;
231 assert(!surface_contains(client->surface, x, y));
232 check_pointer_move(client, x, y);
233
234 /* move pointer on left center */
235 x += 1;
236 assert(surface_contains(client->surface, x, y));
237 check_pointer_move(client, x, y);
238
239 /* move pointer outside left center */
240 x -= 1;
241 assert(!surface_contains(client->surface, x, y));
242 check_pointer_move(client, x, y);
243}
244
245TEST(test_pointer_right_center)
246{
247 struct client *client;
248 int x, y;
249
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200250 client = create_client_and_test_surface(110, 37, 100, 46);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800251 assert(client);
252
253 /* move pointer outside right center */
254 x = client->surface->x + client->surface->width;
255 y = client->surface->y + client->surface->height/2;
256 assert(!surface_contains(client->surface, x, y));
257 check_pointer_move(client, x, y);
258
259 /* move pointer on right center */
260 x -= 1;
261 assert(surface_contains(client->surface, x, y));
262 check_pointer_move(client, x, y);
263
264 /* move pointer outside right center */
265 x += 1;
266 assert(!surface_contains(client->surface, x, y));
267 check_pointer_move(client, x, y);
268}
269
270TEST(test_pointer_surface_move)
271{
272 struct client *client;
273
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200274 client = create_client_and_test_surface(100, 100, 100, 100);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800275 assert(client);
276
277 /* move pointer outside of client */
278 assert(!surface_contains(client->surface, 50, 50));
279 check_pointer_move(client, 50, 50);
280
281 /* move client center to pointer */
282 move_client(client, 0, 0);
283 assert(surface_contains(client->surface, 50, 50));
284 check_pointer(client, 50, 50);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700285}
286
287static int
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800288output_contains_client(struct client *client)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700289{
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800290 struct output *output = client->output;
291 struct surface *surface = client->surface;
292
293 return !(output->x >= surface->x + surface->width
294 || output->x + output->width <= surface->x
295 || output->y >= surface->y + surface->height
296 || output->y + output->height <= surface->y);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700297}
298
299static void
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800300check_client_move(struct client *client, int x, int y)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700301{
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800302 move_client(client, x, y);
303
304 if (output_contains_client(client)) {
305 assert(client->surface->output == client->output);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700306 } else {
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800307 assert(client->surface->output == NULL);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700308 }
309}
310
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800311TEST(test_surface_output)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700312{
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800313 struct client *client;
314 int x, y;
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700315
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200316 client = create_client_and_test_surface(100, 100, 100, 100);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800317 assert(client);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700318
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800319 assert(output_contains_client(client));
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700320
321 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800322 x = 0;
323 y = -client->surface->height;
324 check_client_move(client, x, y);
325
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700326 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800327 check_client_move(client, x, ++y);
328
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700329 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800330 x = -client->surface->width;
331 y = 0;
332 check_client_move(client, x, y);
333
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700334 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800335 check_client_move(client, ++x, y);
336
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700337 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800338 x = client->output->width;
339 y = 0;
340 check_client_move(client, x, y);
341
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700342 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800343 check_client_move(client, --x, y);
344 assert(output_contains_client(client));
345
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700346 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800347 x = 0;
348 y = client->output->height;
349 check_client_move(client, x, y);
350 assert(!output_contains_client(client));
351
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700352 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800353 check_client_move(client, x, --y);
354 assert(output_contains_client(client));
Kristian Høgsberg3018b442012-04-27 15:02:56 -0400355}
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200356
357static void
358buffer_release_handler(void *data, struct wl_buffer *buffer)
359{
360 int *released = data;
361
362 *released = 1;
363}
364
365static struct wl_buffer_listener buffer_listener = {
366 buffer_release_handler
367};
368
369TEST(buffer_release)
370{
371 struct client *client;
372 struct wl_surface *surface;
Pekka Paalanen7789acd2016-05-20 18:01:05 +0300373 struct buffer *buf1;
374 struct buffer *buf2;
375 struct buffer *buf3;
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200376 int buf1_released = 0;
377 int buf2_released = 0;
378 int buf3_released = 0;
379 int frame;
380
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200381 client = create_client_and_test_surface(100, 100, 100, 100);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200382 assert(client);
383 surface = client->surface->wl_surface;
384
Pekka Paalanen7789acd2016-05-20 18:01:05 +0300385 buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100);
386 wl_buffer_add_listener(buf1->proxy, &buffer_listener, &buf1_released);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200387
Pekka Paalanen7789acd2016-05-20 18:01:05 +0300388 buf2 = create_shm_buffer_a8r8g8b8(client, 100, 100);
389 wl_buffer_add_listener(buf2->proxy, &buffer_listener, &buf2_released);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200390
Pekka Paalanen7789acd2016-05-20 18:01:05 +0300391 buf3 = create_shm_buffer_a8r8g8b8(client, 100, 100);
392 wl_buffer_add_listener(buf3->proxy, &buffer_listener, &buf3_released);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200393
394 /*
395 * buf1 must never be released, since it is replaced before
396 * it is committed, therefore it never becomes busy.
397 */
398
Pekka Paalanen7789acd2016-05-20 18:01:05 +0300399 wl_surface_attach(surface, buf1->proxy, 0, 0);
400 wl_surface_attach(surface, buf2->proxy, 0, 0);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200401 frame_callback_set(surface, &frame);
402 wl_surface_commit(surface);
403 frame_callback_wait(client, &frame);
404 assert(buf1_released == 0);
405 /* buf2 may or may not be released */
406 assert(buf3_released == 0);
407
Pekka Paalanen7789acd2016-05-20 18:01:05 +0300408 wl_surface_attach(surface, buf3->proxy, 0, 0);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200409 frame_callback_set(surface, &frame);
410 wl_surface_commit(surface);
411 frame_callback_wait(client, &frame);
412 assert(buf1_released == 0);
413 assert(buf2_released == 1);
414 /* buf3 may or may not be released */
415
Pekka Paalanen924cd942016-05-20 17:25:38 +0300416 wl_surface_attach(surface, client->surface->buffer->proxy, 0, 0);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200417 frame_callback_set(surface, &frame);
418 wl_surface_commit(surface);
419 frame_callback_wait(client, &frame);
420 assert(buf1_released == 0);
421 assert(buf2_released == 1);
422 assert(buf3_released == 1);
423}