• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2015 Samsung Electronics Co., Ltd
3  * Copyright © 2016 Collabora, Ltd.
4  *
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:
12  *
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.
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.
25  */
26 
27 #include "config.h"
28 
29 #include <stdio.h>
30 #include <string.h>
31 #include <sys/mman.h>
32 
33 #include "weston-test-client-helper.h"
34 #include "weston-test-fixture-compositor.h"
35 
36 static const enum renderer_type renderers[] = {
37 	RENDERER_PIXMAN,
38 	RENDERER_GL,
39 };
40 
41 static enum test_result_code
fixture_setup(struct weston_test_harness * harness,const enum renderer_type * arg)42 fixture_setup(struct weston_test_harness *harness, const enum renderer_type *arg)
43 {
44 	struct compositor_setup setup;
45 
46 	compositor_setup_defaults(&setup);
47 	setup.renderer = *arg;
48 	setup.width = 320;
49 	setup.height = 240;
50 	setup.shell = SHELL_TEST_DESKTOP;
51 	setup.logging_scopes = "log,test-harness-plugin";
52 
53 	return weston_test_harness_execute_as_client(harness, &setup);
54 }
55 DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, renderers);
56 
57 static struct wl_subcompositor *
get_subcompositor(struct client * client)58 get_subcompositor(struct client *client)
59 {
60 	struct global *g;
61 	struct global *global_sub = NULL;
62 	struct wl_subcompositor *sub;
63 
64 	wl_list_for_each(g, &client->global_list, link) {
65 		if (strcmp(g->interface, "wl_subcompositor"))
66 			continue;
67 
68 		if (global_sub)
69 			assert(0 && "multiple wl_subcompositor objects");
70 
71 		global_sub = g;
72 	}
73 
74 	assert(global_sub && "no wl_subcompositor found");
75 
76 	assert(global_sub->version == 1);
77 
78 	sub = wl_registry_bind(client->wl_registry, global_sub->name,
79 			       &wl_subcompositor_interface, 1);
80 	assert(sub);
81 
82 	return sub;
83 }
84 
85 static int
check_screen(struct client * client,const char * ref_image,int ref_seq_no,const struct rectangle * clip,int seq_no)86 check_screen(struct client *client,
87 	     const char *ref_image,
88 	     int ref_seq_no,
89 	     const struct rectangle *clip,
90 	     int seq_no)
91 {
92 	bool match;
93 
94 	match = verify_screen_content(client, ref_image, ref_seq_no, clip,
95 				      seq_no);
96 
97 	return match ? 0 : -1;
98 }
99 
100 static struct buffer *
surface_commit_color(struct client * client,struct wl_surface * surface,pixman_color_t * color,int width,int height)101 surface_commit_color(struct client *client, struct wl_surface *surface,
102 		     pixman_color_t *color, int width, int height)
103 {
104 	struct buffer *buf;
105 
106 	buf = create_shm_buffer_a8r8g8b8(client, width, height);
107 	fill_image_with_color(buf->image, color);
108 	wl_surface_attach(surface, buf->proxy, 0, 0);
109 	wl_surface_damage(surface, 0, 0, width, height);
110 	wl_surface_commit(surface);
111 
112 	return buf;
113 }
114 
TEST(subsurface_z_order)115 TEST(subsurface_z_order)
116 {
117 	struct client *client;
118 	struct wl_subcompositor *subco;
119 	struct buffer *bufs[5] = { 0 };
120 	struct wl_surface *surf[5] = { 0 };
121 	struct wl_subsurface *sub[5] = { 0 };
122 	struct rectangle clip = { 40, 40, 280, 200 };
123 	int fail = 0;
124 	unsigned i;
125 	pixman_color_t red;
126 	pixman_color_t blue;
127 	pixman_color_t cyan;
128 	pixman_color_t green;
129 
130 	color_rgb888(&red, 255, 0, 0);
131 	color_rgb888(&blue, 0, 0, 255);
132 	color_rgb888(&cyan, 0, 255, 255);
133 	color_rgb888(&green, 0, 255, 0);
134 
135 	client = create_client_and_test_surface(100, 50, 100, 100);
136 	assert(client);
137 	subco = get_subcompositor(client);
138 
139 	/* move the pointer clearly away from our screenshooting area */
140 	weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 2, 30);
141 
142 	/* make the parent surface red */
143 	surf[0] = client->surface->wl_surface;
144 	bufs[0] = surface_commit_color(client, surf[0], &red, 100, 100);
145 	/* sub[0] is not used */
146 
147 	fail += check_screen(client, "subsurface_z_order", 0, &clip, 0);
148 
149 	/* create a blue sub-surface above red */
150 	surf[1] = wl_compositor_create_surface(client->wl_compositor);
151 	sub[1] = wl_subcompositor_get_subsurface(subco, surf[1], surf[0]);
152 	bufs[1] = surface_commit_color(client, surf[1], &blue, 100, 100);
153 
154 	wl_subsurface_set_position(sub[1], 20, 20);
155 	wl_surface_commit(surf[0]);
156 
157 	fail += check_screen(client, "subsurface_z_order", 1, &clip, 1);
158 
159 	/* create a cyan sub-surface above blue */
160 	surf[2] = wl_compositor_create_surface(client->wl_compositor);
161 	sub[2] = wl_subcompositor_get_subsurface(subco, surf[2], surf[1]);
162 	bufs[2] = surface_commit_color(client, surf[2], &cyan, 100, 100);
163 
164 	wl_subsurface_set_position(sub[2], 20, 20);
165 	wl_surface_commit(surf[1]);
166 	wl_surface_commit(surf[0]);
167 
168 	fail += check_screen(client, "subsurface_z_order", 2, &clip, 2);
169 
170 	/* create a green sub-surface above blue, sibling to cyan */
171 	surf[3] = wl_compositor_create_surface(client->wl_compositor);
172 	sub[3] = wl_subcompositor_get_subsurface(subco, surf[3], surf[1]);
173 	bufs[3] = surface_commit_color(client, surf[3], &green, 100, 100);
174 
175 	wl_subsurface_set_position(sub[3], -40, 10);
176 	wl_surface_commit(surf[1]);
177 	wl_surface_commit(surf[0]);
178 
179 	fail += check_screen(client, "subsurface_z_order", 3, &clip, 3);
180 
181 	/* stack blue below red, which brings also cyan and green below red */
182 	wl_subsurface_place_below(sub[1], surf[0]);
183 	wl_surface_commit(surf[0]);
184 
185 	fail += check_screen(client, "subsurface_z_order", 4, &clip, 4);
186 
187 	assert(fail == 0);
188 
189 	for (i = 0; i < ARRAY_LENGTH(sub); i++)
190 		if (sub[i])
191 			wl_subsurface_destroy(sub[i]);
192 
193 	for (i = 0; i < ARRAY_LENGTH(surf); i++)
194 		if (surf[i])
195 			wl_surface_destroy(surf[i]);
196 
197 	for (i = 0; i < ARRAY_LENGTH(bufs); i++)
198 		if (bufs[i])
199 			buffer_destroy(bufs[i]);
200 }
201