blob: c2290b10aa2c43fab11904210861e088ea95668c [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"
Pekka Paalanen701676d2019-11-13 15:45:10 +020030#include "weston-test-fixture-compositor.h"
31
32static enum test_result_code
33fixture_setup(struct weston_test_harness *harness)
34{
35 struct compositor_setup setup;
36
37 compositor_setup_defaults(&setup);
38
39 return weston_test_harness_execute_as_client(harness, &setup);
40}
41DECLARE_FIXTURE_SETUP(fixture_setup);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070042
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070043static int
U. Artie Eoff84f9db52012-12-07 13:50:33 -080044output_contains_client(struct client *client)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070045{
U. Artie Eoff84f9db52012-12-07 13:50:33 -080046 struct output *output = client->output;
47 struct surface *surface = client->surface;
48
49 return !(output->x >= surface->x + surface->width
50 || output->x + output->width <= surface->x
51 || output->y >= surface->y + surface->height
52 || output->y + output->height <= surface->y);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070053}
54
55static void
U. Artie Eoff84f9db52012-12-07 13:50:33 -080056check_client_move(struct client *client, int x, int y)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070057{
U. Artie Eoff84f9db52012-12-07 13:50:33 -080058 move_client(client, x, y);
59
60 if (output_contains_client(client)) {
61 assert(client->surface->output == client->output);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070062 } else {
U. Artie Eoff84f9db52012-12-07 13:50:33 -080063 assert(client->surface->output == NULL);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070064 }
65}
66
U. Artie Eoff84f9db52012-12-07 13:50:33 -080067TEST(test_surface_output)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070068{
U. Artie Eoff84f9db52012-12-07 13:50:33 -080069 struct client *client;
70 int x, y;
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070071
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +020072 client = create_client_and_test_surface(100, 100, 100, 100);
U. Artie Eoff84f9db52012-12-07 13:50:33 -080073 assert(client);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070074
U. Artie Eoff84f9db52012-12-07 13:50:33 -080075 assert(output_contains_client(client));
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070076
77 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -080078 x = 0;
79 y = -client->surface->height;
80 check_client_move(client, x, y);
81
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070082 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -080083 check_client_move(client, x, ++y);
84
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070085 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -080086 x = -client->surface->width;
87 y = 0;
88 check_client_move(client, x, y);
89
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070090 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -080091 check_client_move(client, ++x, y);
92
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070093 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -080094 x = client->output->width;
95 y = 0;
96 check_client_move(client, x, y);
97
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070098 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -080099 check_client_move(client, --x, y);
100 assert(output_contains_client(client));
101
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700102 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800103 x = 0;
104 y = client->output->height;
105 check_client_move(client, x, y);
106 assert(!output_contains_client(client));
107
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700108 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800109 check_client_move(client, x, --y);
110 assert(output_contains_client(client));
Pekka Paalanend3acfd32021-06-14 14:25:08 +0300111
112 client_destroy(client);
Kristian Høgsberg3018b442012-04-27 15:02:56 -0400113}
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200114
115static void
116buffer_release_handler(void *data, struct wl_buffer *buffer)
117{
118 int *released = data;
119
120 *released = 1;
121}
122
123static struct wl_buffer_listener buffer_listener = {
124 buffer_release_handler
125};
126
127TEST(buffer_release)
128{
129 struct client *client;
130 struct wl_surface *surface;
Pekka Paalanen7789acd2016-05-20 18:01:05 +0300131 struct buffer *buf1;
132 struct buffer *buf2;
133 struct buffer *buf3;
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200134 int buf1_released = 0;
135 int buf2_released = 0;
136 int buf3_released = 0;
137 int frame;
138
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200139 client = create_client_and_test_surface(100, 100, 100, 100);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200140 assert(client);
141 surface = client->surface->wl_surface;
142
Pekka Paalanen7789acd2016-05-20 18:01:05 +0300143 buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100);
144 wl_buffer_add_listener(buf1->proxy, &buffer_listener, &buf1_released);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200145
Pekka Paalanen7789acd2016-05-20 18:01:05 +0300146 buf2 = create_shm_buffer_a8r8g8b8(client, 100, 100);
147 wl_buffer_add_listener(buf2->proxy, &buffer_listener, &buf2_released);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200148
Pekka Paalanen7789acd2016-05-20 18:01:05 +0300149 buf3 = create_shm_buffer_a8r8g8b8(client, 100, 100);
150 wl_buffer_add_listener(buf3->proxy, &buffer_listener, &buf3_released);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200151
152 /*
153 * buf1 must never be released, since it is replaced before
154 * it is committed, therefore it never becomes busy.
155 */
156
Pekka Paalanen7789acd2016-05-20 18:01:05 +0300157 wl_surface_attach(surface, buf1->proxy, 0, 0);
158 wl_surface_attach(surface, buf2->proxy, 0, 0);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200159 frame_callback_set(surface, &frame);
160 wl_surface_commit(surface);
161 frame_callback_wait(client, &frame);
162 assert(buf1_released == 0);
163 /* buf2 may or may not be released */
164 assert(buf3_released == 0);
165
Pekka Paalanen7789acd2016-05-20 18:01:05 +0300166 wl_surface_attach(surface, buf3->proxy, 0, 0);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200167 frame_callback_set(surface, &frame);
168 wl_surface_commit(surface);
169 frame_callback_wait(client, &frame);
170 assert(buf1_released == 0);
171 assert(buf2_released == 1);
172 /* buf3 may or may not be released */
173
Pekka Paalanen924cd942016-05-20 17:25:38 +0300174 wl_surface_attach(surface, client->surface->buffer->proxy, 0, 0);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200175 frame_callback_set(surface, &frame);
176 wl_surface_commit(surface);
177 frame_callback_wait(client, &frame);
178 assert(buf1_released == 0);
179 assert(buf2_released == 1);
180 assert(buf3_released == 1);
Pekka Paalanend3acfd32021-06-14 14:25:08 +0300181
182 buffer_destroy(buf1);
183 buffer_destroy(buf2);
184 buffer_destroy(buf3);
185 client_destroy(client);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200186}