2 * Copyright © 2012 Collabora, Ltd.
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.
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.
25 #include "weston-test-client-helper.h"
26 #include "subsurface-client-protocol.h"
28 #define NUM_SUBSURFACES 3
30 struct compound_surface {
31 struct wl_subcompositor *subco;
32 struct wl_surface *parent;
33 struct wl_surface *child[NUM_SUBSURFACES];
34 struct wl_subsurface *sub[NUM_SUBSURFACES];
37 static struct wl_subcompositor *
38 get_subcompositor(struct client *client)
41 struct global *global_sub = NULL;
42 struct wl_subcompositor *sub;
44 wl_list_for_each(g, &client->global_list, link) {
45 if (strcmp(g->interface, "wl_subcompositor"))
49 assert(0 && "multiple wl_subcompositor objects");
54 assert(global_sub && "no wl_subcompositor found");
56 assert(global_sub->version == 1);
58 sub = wl_registry_bind(client->wl_registry, global_sub->name,
59 &wl_subcompositor_interface, 1);
66 populate_compound_surface(struct compound_surface *com, struct client *client)
70 com->subco = get_subcompositor(client);
72 com->parent = wl_compositor_create_surface(client->wl_compositor);
74 for (i = 0; i < NUM_SUBSURFACES; i++) {
76 wl_compositor_create_surface(client->wl_compositor);
78 wl_subcompositor_get_subsurface(com->subco,
84 TEST(test_subsurface_basic_protocol)
86 struct client *client;
87 struct compound_surface com1;
88 struct compound_surface com2;
90 client = client_create(100, 50, 123, 77);
93 populate_compound_surface(&com1, client);
94 populate_compound_surface(&com2, client);
96 client_roundtrip(client);
99 TEST(test_subsurface_position_protocol)
101 struct client *client;
102 struct compound_surface com;
105 client = client_create(100, 50, 123, 77);
108 populate_compound_surface(&com, client);
109 for (i = 0; i < NUM_SUBSURFACES; i++)
110 wl_subsurface_set_position(com.sub[i],
111 (i + 2) * 20, (i + 2) * 10);
113 client_roundtrip(client);
116 TEST(test_subsurface_placement_protocol)
118 struct client *client;
119 struct compound_surface com;
121 client = client_create(100, 50, 123, 77);
124 populate_compound_surface(&com, client);
126 wl_subsurface_place_above(com.sub[0], com.child[1]);
127 wl_subsurface_place_above(com.sub[1], com.parent);
128 wl_subsurface_place_below(com.sub[2], com.child[0]);
129 wl_subsurface_place_below(com.sub[1], com.parent);
131 client_roundtrip(client);
134 FAIL_TEST(test_subsurface_paradox)
136 struct client *client;
137 struct wl_surface *parent;
138 struct wl_subcompositor *subco;
140 client = client_create(100, 50, 123, 77);
143 subco = get_subcompositor(client);
144 parent = wl_compositor_create_surface(client->wl_compositor);
146 /* surface is its own parent */
147 wl_subcompositor_get_subsurface(subco, parent, parent);
149 client_roundtrip(client);
152 FAIL_TEST(test_subsurface_identical_link)
154 struct client *client;
155 struct compound_surface com;
157 client = client_create(100, 50, 123, 77);
160 populate_compound_surface(&com, client);
162 /* surface is already a subsurface */
163 wl_subcompositor_get_subsurface(com.subco, com.child[0], com.parent);
165 client_roundtrip(client);
168 FAIL_TEST(test_subsurface_change_link)
170 struct client *client;
171 struct compound_surface com;
172 struct wl_surface *stranger;
174 client = client_create(100, 50, 123, 77);
177 stranger = wl_compositor_create_surface(client->wl_compositor);
178 populate_compound_surface(&com, client);
180 /* surface is already a subsurface */
181 wl_subcompositor_get_subsurface(com.subco, com.child[0], stranger);
183 client_roundtrip(client);
186 TEST(test_subsurface_nesting)
188 struct client *client;
189 struct compound_surface com;
190 struct wl_surface *stranger;
192 client = client_create(100, 50, 123, 77);
195 stranger = wl_compositor_create_surface(client->wl_compositor);
196 populate_compound_surface(&com, client);
198 /* parent is a sub-surface */
199 wl_subcompositor_get_subsurface(com.subco, stranger, com.child[0]);
201 client_roundtrip(client);
204 TEST(test_subsurface_nesting_parent)
206 struct client *client;
207 struct compound_surface com;
208 struct wl_surface *stranger;
210 client = client_create(100, 50, 123, 77);
213 stranger = wl_compositor_create_surface(client->wl_compositor);
214 populate_compound_surface(&com, client);
216 /* surface is already a parent */
217 wl_subcompositor_get_subsurface(com.subco, com.parent, stranger);
219 client_roundtrip(client);
222 FAIL_TEST(test_subsurface_place_above_stranger)
224 struct client *client;
225 struct compound_surface com;
226 struct wl_surface *stranger;
228 client = client_create(100, 50, 123, 77);
231 stranger = wl_compositor_create_surface(client->wl_compositor);
232 populate_compound_surface(&com, client);
235 wl_subsurface_place_above(com.sub[0], stranger);
237 client_roundtrip(client);
240 FAIL_TEST(test_subsurface_place_below_stranger)
242 struct client *client;
243 struct compound_surface com;
244 struct wl_surface *stranger;
246 client = client_create(100, 50, 123, 77);
249 stranger = wl_compositor_create_surface(client->wl_compositor);
250 populate_compound_surface(&com, client);
253 wl_subsurface_place_below(com.sub[0], stranger);
255 client_roundtrip(client);
258 FAIL_TEST(test_subsurface_place_above_foreign)
260 struct client *client;
261 struct compound_surface com1;
262 struct compound_surface com2;
264 client = client_create(100, 50, 123, 77);
267 populate_compound_surface(&com1, client);
268 populate_compound_surface(&com2, client);
271 wl_subsurface_place_above(com1.sub[0], com2.child[0]);
273 client_roundtrip(client);
276 FAIL_TEST(test_subsurface_place_below_foreign)
278 struct client *client;
279 struct compound_surface com1;
280 struct compound_surface com2;
282 client = client_create(100, 50, 123, 77);
285 populate_compound_surface(&com1, client);
286 populate_compound_surface(&com2, client);
289 wl_subsurface_place_below(com1.sub[0], com2.child[0]);
291 client_roundtrip(client);
294 TEST(test_subsurface_destroy_protocol)
296 struct client *client;
297 struct compound_surface com;
299 client = client_create(100, 50, 123, 77);
302 populate_compound_surface(&com, client);
304 /* not needed anymore */
305 wl_subcompositor_destroy(com.subco);
307 /* detach child from parent */
308 wl_subsurface_destroy(com.sub[0]);
310 /* destroy: child, parent */
311 wl_surface_destroy(com.child[1]);
312 wl_surface_destroy(com.parent);
314 /* destroy: parent, child */
315 wl_surface_destroy(com.child[2]);
317 /* destroy: sub, child */
318 wl_surface_destroy(com.child[0]);
320 /* 2x destroy: child, sub */
321 wl_subsurface_destroy(com.sub[2]);
322 wl_subsurface_destroy(com.sub[1]);
324 client_roundtrip(client);