2 * Copyright © 2015 Samsung Electronics Co., Ltd
3 * Copyright © 2016 Collabora, Ltd.
5 * 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:
13 * 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.
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
33 #include "weston-test-client-helper.h"
35 char *server_parameters = "--use-pixman --width=320 --height=240"
36 " --shell=weston-test-desktop-shell.so";
38 static struct wl_subcompositor *
39 get_subcompositor(struct client *client)
42 struct global *global_sub = NULL;
43 struct wl_subcompositor *sub;
45 wl_list_for_each(g, &client->global_list, link) {
46 if (strcmp(g->interface, "wl_subcompositor"))
50 assert(0 && "multiple wl_subcompositor objects");
55 assert(global_sub && "no wl_subcompositor found");
57 assert(global_sub->version == 1);
59 sub = wl_registry_bind(client->wl_registry, global_sub->name,
60 &wl_subcompositor_interface, 1);
67 fill_color(pixman_image_t *image, pixman_color_t *color)
69 pixman_image_t *solid;
73 width = pixman_image_get_width(image);
74 height = pixman_image_get_height(image);
76 solid = pixman_image_create_solid_fill(color);
77 pixman_image_composite32(PIXMAN_OP_SRC,
85 pixman_image_unref(solid);
88 static pixman_color_t *
89 color(pixman_color_t *tmp, uint8_t r, uint8_t g, uint8_t b)
92 tmp->red = (r << 8) + r;
93 tmp->green = (g << 8) + g;
94 tmp->blue = (b << 8) + b;
100 write_visual_diff(pixman_image_t *ref_image,
102 const struct rectangle *clip,
103 const char *test_name,
108 pixman_image_t *diff;
111 ret = asprintf(&ext_test_name, "%s-diff", test_name);
114 fname = screenshot_output_filename(ext_test_name, seq_no);
115 diff = visualize_image_difference(shot->image, ref_image, clip);
116 write_image_as_png(diff, fname);
118 pixman_image_unref(diff);
124 check_screen(struct client *client,
125 const char *ref_image,
127 const struct rectangle *clip,
130 const char *test_name = get_test_name();
137 ref_fname = screenshot_reference_filename(ref_image, ref_seq_no);
138 shot_fname = screenshot_output_filename(test_name, seq_no);
140 ref = load_image_from_png(ref_fname);
143 shot = capture_screenshot_of_output(client);
146 match = check_images_match(shot->image, ref, clip);
147 printf("ref %s vs. shot %s: %s\n", ref_fname, shot_fname,
148 match ? "PASS" : "FAIL");
150 write_image_as_png(shot->image, shot_fname);
152 write_visual_diff(ref, shot, clip, test_name, seq_no);
154 buffer_destroy(shot);
155 pixman_image_unref(ref);
159 return match ? 0 : -1;
162 static struct buffer *
163 surface_commit_color(struct client *client, struct wl_surface *surface,
164 pixman_color_t *color, int width, int height)
168 buf = create_shm_buffer_a8r8g8b8(client, width, height);
169 fill_color(buf->image, color);
170 wl_surface_attach(surface, buf->proxy, 0, 0);
171 wl_surface_damage(surface, 0, 0, width, height);
172 wl_surface_commit(surface);
177 TEST(subsurface_z_order)
179 const char *test_name = get_test_name();
180 struct client *client;
181 struct wl_subcompositor *subco;
182 struct buffer *bufs[5] = { 0 };
183 struct wl_surface *surf[5] = { 0 };
184 struct wl_subsurface *sub[5] = { 0 };
185 struct rectangle clip = { 40, 40, 280, 200 };
191 pixman_color_t green;
193 color(&red, 255, 0, 0);
194 color(&blue, 0, 0, 255);
195 color(&cyan, 0, 255, 255);
196 color(&green, 0, 255, 0);
198 client = create_client_and_test_surface(100, 50, 100, 100);
200 subco = get_subcompositor(client);
202 /* move the pointer clearly away from our screenshooting area */
203 weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 2, 30);
205 /* make the parent surface red */
206 surf[0] = client->surface->wl_surface;
207 bufs[0] = surface_commit_color(client, surf[0], &red, 100, 100);
208 /* sub[0] is not used */
210 fail += check_screen(client, test_name, 0, &clip, 0);
212 /* create a blue sub-surface above red */
213 surf[1] = wl_compositor_create_surface(client->wl_compositor);
214 sub[1] = wl_subcompositor_get_subsurface(subco, surf[1], surf[0]);
215 bufs[1] = surface_commit_color(client, surf[1], &blue, 100, 100);
217 wl_subsurface_set_position(sub[1], 20, 20);
218 wl_surface_commit(surf[0]);
220 fail += check_screen(client, test_name, 1, &clip, 1);
222 /* create a cyan sub-surface above blue */
223 surf[2] = wl_compositor_create_surface(client->wl_compositor);
224 sub[2] = wl_subcompositor_get_subsurface(subco, surf[2], surf[1]);
225 bufs[2] = surface_commit_color(client, surf[2], &cyan, 100, 100);
227 wl_subsurface_set_position(sub[2], 20, 20);
228 wl_surface_commit(surf[1]);
229 wl_surface_commit(surf[0]);
231 fail += check_screen(client, test_name, 2, &clip, 2);
233 /* create a green sub-surface above blue, sibling to cyan */
234 surf[3] = wl_compositor_create_surface(client->wl_compositor);
235 sub[3] = wl_subcompositor_get_subsurface(subco, surf[3], surf[1]);
236 bufs[3] = surface_commit_color(client, surf[3], &green, 100, 100);
238 wl_subsurface_set_position(sub[3], -40, 10);
239 wl_surface_commit(surf[1]);
240 wl_surface_commit(surf[0]);
242 fail += check_screen(client, test_name, 3, &clip, 3);
244 /* stack blue below red, which brings also cyan and green below red */
245 wl_subsurface_place_below(sub[1], surf[0]);
246 wl_surface_commit(surf[0]);
248 fail += check_screen(client, test_name, 4, &clip, 4);
252 for (i = 0; i < ARRAY_LENGTH(sub); i++)
254 wl_subsurface_destroy(sub[i]);
256 for (i = 0; i < ARRAY_LENGTH(surf); i++)
258 wl_surface_destroy(surf[i]);
260 for (i = 0; i < ARRAY_LENGTH(bufs); i++)
262 buffer_destroy(bufs[i]);