blob: 7d26e027f176d49b3d6570308cbd1c856a962558 [file] [log] [blame]
Pekka Paalanenfbd41602020-12-04 15:20:11 +02001/*
2 * Copyright © 2020 Collabora, Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26#include "config.h"
27
28#include <stdio.h>
29#include <string.h>
30#include <sys/mman.h>
31
32#include "weston-test-client-helper.h"
33#include "weston-test-fixture-compositor.h"
34
35#define RENDERERS(s, t) \
36 { \
37 .renderer = RENDERER_PIXMAN, \
38 .scale = s, \
39 .transform = WL_OUTPUT_TRANSFORM_ ## t, \
40 .transform_name = #t, \
Pekka Paalanenb1e56142020-12-08 14:13:56 +020041 .gl_shadow_fb = false, \
Pekka Paalanenfbd41602020-12-04 15:20:11 +020042 .meta.name = "pixman " #s " " #t, \
43 }, \
44 { \
45 .renderer = RENDERER_GL, \
46 .scale = s, \
47 .transform = WL_OUTPUT_TRANSFORM_ ## t, \
48 .transform_name = #t, \
Pekka Paalanenb1e56142020-12-08 14:13:56 +020049 .gl_shadow_fb = false, \
50 .meta.name = "GL no-shadow " #s " " #t, \
51 }, \
52 { \
53 .renderer = RENDERER_GL, \
54 .scale = s, \
55 .transform = WL_OUTPUT_TRANSFORM_ ## t, \
56 .transform_name = #t, \
57 .gl_shadow_fb = true, \
58 .meta.name = "GL shadow " #s " " #t, \
Pekka Paalanenfbd41602020-12-04 15:20:11 +020059 }
60
61struct setup_args {
62 struct fixture_metadata meta;
63 enum renderer_type renderer;
64 int scale;
65 enum wl_output_transform transform;
66 const char *transform_name;
Pekka Paalanenb1e56142020-12-08 14:13:56 +020067 bool gl_shadow_fb;
Pekka Paalanenfbd41602020-12-04 15:20:11 +020068};
69
70static const struct setup_args my_setup_args[] = {
71 RENDERERS(1, NORMAL),
72 RENDERERS(1, 90),
73 RENDERERS(1, 180),
74 RENDERERS(1, 270),
75 RENDERERS(1, FLIPPED),
76 RENDERERS(1, FLIPPED_90),
77 RENDERERS(1, FLIPPED_180),
78 RENDERERS(1, FLIPPED_270),
79 RENDERERS(2, NORMAL),
80 RENDERERS(3, NORMAL),
81 RENDERERS(2, 90),
82 RENDERERS(2, 180),
83 RENDERERS(2, FLIPPED),
84 RENDERERS(3, FLIPPED_270),
85};
86
87static enum test_result_code
88fixture_setup(struct weston_test_harness *harness, const struct setup_args *arg)
89{
90 struct compositor_setup setup;
91
92 /*
93 * The width and height are chosen to produce 324x240 framebuffer, to
94 * emulate keeping the video mode constant.
95 * This resolution is divisible by 2 and 3.
96 * Headless multiplies the given size by scale.
97 */
98
99 compositor_setup_defaults(&setup);
100 setup.renderer = arg->renderer;
101 setup.width = 324 / arg->scale;
102 setup.height = 240 / arg->scale;
103 setup.scale = arg->scale;
104 setup.transform = arg->transform;
105 setup.shell = SHELL_TEST_DESKTOP;
106
107 /*
108 * The test here works by swapping the whole wl_surface into a
109 * different color but lying that there is only a small damage area.
110 * Then the test checks that only the damage area gets the new color
111 * on screen.
112 *
113 * The following quirk forces GL-renderer to update the whole texture
114 * even for partial damage. Otherwise, GL-renderer would only copy the
115 * damaged area from the wl_shm buffer into a GL texture.
116 *
117 * Those output_damage tests where the surface is scaled up by the
118 * compositor will use bilinear texture sampling due to the policy
119 * in the renderers.
120 *
121 * Pixman renderer never makes copies of wl_shm buffers, so bilinear
122 * sampling there will always produce the expected result. However,
123 * with GL-renderer if the texture is not updated beyond the strict
124 * damage region, bilinear sampling will result in a blend of the old
125 * and new colors at the edges of the damage rectangles. This blend
126 * would be detrimental to testing the damage regions and would cause
127 * test failures due to reference image mismatch. What we actually
128 * want to see is the crisp outline of the damage rectangles.
129 */
130 setup.test_quirks.gl_force_full_upload = true;
131
Pekka Paalanenb1e56142020-12-08 14:13:56 +0200132 if (arg->gl_shadow_fb) {
133 /*
134 * A second case for GL-renderer: the shadow framebuffer
135 *
136 * This tests blit_shadow_to_output() specifically. The quirk
137 * forces the shadow framebuffer to be redrawn completely, which
138 * means the test surface will be completely filled with a new
139 * color regardless of damage. The blit uses damage too, and
140 * the damage pattern that is tested for needs to appear in
141 * that step.
142 */
143 setup.test_quirks.gl_force_full_redraw_of_shadow_fb = true;
Pekka Paalanenf1fb48e2021-03-01 11:31:59 +0200144
145 /* To skip instead of fail the test if shadow not available */
146 setup.test_quirks.required_capabilities = WESTON_CAP_COLOR_OPS;
147
Pekka Paalanenb1e56142020-12-08 14:13:56 +0200148 weston_ini_setup(&setup,
149 cfgln("[output]"),
150 cfgln("name=headless"),
151 cfgln("use-renderer-shadow=true"));
152 }
153
Pekka Paalanenfbd41602020-12-04 15:20:11 +0200154 return weston_test_harness_execute_as_client(harness, &setup);
155}
156DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args, meta);
157
158static void
159commit_buffer_with_damage(struct surface *surface,
160 struct buffer *buffer,
161 struct rectangle damage)
162{
163 wl_surface_attach(surface->wl_surface, buffer->proxy, 0, 0);
164 wl_surface_damage(surface->wl_surface, damage.x, damage.y,
165 damage.width, damage.height);
166 wl_surface_commit(surface->wl_surface);
167}
168
169/*
170 * Test that Weston repaints exactly the damage a client sends to it.
171 *
172 * NOTE: This relies on the Weston implementation detail that Weston actually
173 * will repaint exactly the client's damage and nothing more. This is not
174 * generally true of Wayland compositors.
175 */
176TEST(output_damage)
177{
178#define COUNT_BUFS 3
179 const struct setup_args *oargs;
180 struct client *client;
181 bool match = true;
182 char *refname;
183 int ret;
184 struct buffer *buf[COUNT_BUFS];
185 pixman_color_t colors[COUNT_BUFS];
186 static const struct rectangle damages[COUNT_BUFS] = {
187 { 0 /* full damage */ },
188 { .x = 10, .y = 10, .width = 20, .height = 10 },
189 { .x = 43, .y = 47, .width = 5, .height = 50 },
190 };
191 int i;
192 const int width = 140;
193 const int height = 110;
194
195 color_rgb888(&colors[0], 100, 100, 100); /* grey */
196 color_rgb888(&colors[1], 0, 255, 255); /* cyan */
197 color_rgb888(&colors[2], 0, 255, 0); /* green */
198
199 oargs = &my_setup_args[get_test_fixture_index()];
200
201 ret = asprintf(&refname, "output-damage_%d-%s",
202 oargs->scale, oargs->transform_name);
203 assert(ret);
204
205 testlog("%s: %s\n", get_test_name(), refname);
206
207 client = create_client();
208 client->surface = create_test_surface(client);
209 client->surface->width = width;
210 client->surface->height = height;
211
212 for (i = 0; i < COUNT_BUFS; i++) {
213 buf[i] = create_shm_buffer_a8r8g8b8(client, width, height);
214 fill_image_with_color(buf[i]->image, &colors[i]);
215 }
216
217 client->surface->buffer = buf[0];
218 move_client(client, 19, 19);
219
220 /*
221 * Each time we commit a buffer with a different color, the damage box
222 * should color just the box on the output.
223 */
224 for (i = 1; i < COUNT_BUFS; i++) {
225 commit_buffer_with_damage(client->surface, buf[i], damages[i]);
226 if (!verify_screen_content(client, refname, i, NULL, i))
227 match = false;
228 }
229
230 assert(match);
231
232 for (i = 0; i < COUNT_BUFS; i++)
233 buffer_destroy(buf[i]);
234
235 client->surface->buffer = NULL;
236 client_destroy(client);
237}