Pekka Paalanen | fbd4160 | 2020-12-04 15:20:11 +0200 | [diff] [blame] | 1 | /* |
| 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 Paalanen | b1e5614 | 2020-12-08 14:13:56 +0200 | [diff] [blame] | 41 | .gl_shadow_fb = false, \ |
Pekka Paalanen | fbd4160 | 2020-12-04 15:20:11 +0200 | [diff] [blame] | 42 | .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 Paalanen | b1e5614 | 2020-12-08 14:13:56 +0200 | [diff] [blame] | 49 | .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 Paalanen | fbd4160 | 2020-12-04 15:20:11 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | struct 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 Paalanen | b1e5614 | 2020-12-08 14:13:56 +0200 | [diff] [blame] | 67 | bool gl_shadow_fb; |
Pekka Paalanen | fbd4160 | 2020-12-04 15:20:11 +0200 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | static 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 | |
| 87 | static enum test_result_code |
| 88 | fixture_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 Paalanen | b1e5614 | 2020-12-08 14:13:56 +0200 | [diff] [blame] | 132 | 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. |
Pekka Paalanen | d2cfbff | 2021-04-15 16:32:28 +0300 | [diff] [blame] | 142 | * |
| 143 | * The quirk also ensures the shadow framebuffer is created |
| 144 | * even if not needed. |
Pekka Paalanen | b1e5614 | 2020-12-08 14:13:56 +0200 | [diff] [blame] | 145 | */ |
| 146 | setup.test_quirks.gl_force_full_redraw_of_shadow_fb = true; |
Pekka Paalanen | f1fb48e | 2021-03-01 11:31:59 +0200 | [diff] [blame] | 147 | |
| 148 | /* To skip instead of fail the test if shadow not available */ |
| 149 | setup.test_quirks.required_capabilities = WESTON_CAP_COLOR_OPS; |
Pekka Paalanen | b1e5614 | 2020-12-08 14:13:56 +0200 | [diff] [blame] | 150 | } |
| 151 | |
Pekka Paalanen | fbd4160 | 2020-12-04 15:20:11 +0200 | [diff] [blame] | 152 | return weston_test_harness_execute_as_client(harness, &setup); |
| 153 | } |
| 154 | DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args, meta); |
| 155 | |
| 156 | static void |
| 157 | commit_buffer_with_damage(struct surface *surface, |
| 158 | struct buffer *buffer, |
| 159 | struct rectangle damage) |
| 160 | { |
| 161 | wl_surface_attach(surface->wl_surface, buffer->proxy, 0, 0); |
| 162 | wl_surface_damage(surface->wl_surface, damage.x, damage.y, |
| 163 | damage.width, damage.height); |
| 164 | wl_surface_commit(surface->wl_surface); |
| 165 | } |
| 166 | |
| 167 | /* |
| 168 | * Test that Weston repaints exactly the damage a client sends to it. |
| 169 | * |
| 170 | * NOTE: This relies on the Weston implementation detail that Weston actually |
| 171 | * will repaint exactly the client's damage and nothing more. This is not |
| 172 | * generally true of Wayland compositors. |
| 173 | */ |
| 174 | TEST(output_damage) |
| 175 | { |
| 176 | #define COUNT_BUFS 3 |
| 177 | const struct setup_args *oargs; |
| 178 | struct client *client; |
| 179 | bool match = true; |
| 180 | char *refname; |
| 181 | int ret; |
| 182 | struct buffer *buf[COUNT_BUFS]; |
| 183 | pixman_color_t colors[COUNT_BUFS]; |
| 184 | static const struct rectangle damages[COUNT_BUFS] = { |
| 185 | { 0 /* full damage */ }, |
| 186 | { .x = 10, .y = 10, .width = 20, .height = 10 }, |
| 187 | { .x = 43, .y = 47, .width = 5, .height = 50 }, |
| 188 | }; |
| 189 | int i; |
| 190 | const int width = 140; |
| 191 | const int height = 110; |
| 192 | |
| 193 | color_rgb888(&colors[0], 100, 100, 100); /* grey */ |
| 194 | color_rgb888(&colors[1], 0, 255, 255); /* cyan */ |
| 195 | color_rgb888(&colors[2], 0, 255, 0); /* green */ |
| 196 | |
| 197 | oargs = &my_setup_args[get_test_fixture_index()]; |
| 198 | |
| 199 | ret = asprintf(&refname, "output-damage_%d-%s", |
| 200 | oargs->scale, oargs->transform_name); |
| 201 | assert(ret); |
| 202 | |
| 203 | testlog("%s: %s\n", get_test_name(), refname); |
| 204 | |
| 205 | client = create_client(); |
| 206 | client->surface = create_test_surface(client); |
| 207 | client->surface->width = width; |
| 208 | client->surface->height = height; |
| 209 | |
| 210 | for (i = 0; i < COUNT_BUFS; i++) { |
| 211 | buf[i] = create_shm_buffer_a8r8g8b8(client, width, height); |
| 212 | fill_image_with_color(buf[i]->image, &colors[i]); |
| 213 | } |
| 214 | |
| 215 | client->surface->buffer = buf[0]; |
| 216 | move_client(client, 19, 19); |
| 217 | |
| 218 | /* |
| 219 | * Each time we commit a buffer with a different color, the damage box |
| 220 | * should color just the box on the output. |
| 221 | */ |
| 222 | for (i = 1; i < COUNT_BUFS; i++) { |
| 223 | commit_buffer_with_damage(client->surface, buf[i], damages[i]); |
| 224 | if (!verify_screen_content(client, refname, i, NULL, i)) |
| 225 | match = false; |
| 226 | } |
| 227 | |
| 228 | assert(match); |
| 229 | |
| 230 | for (i = 0; i < COUNT_BUFS; i++) |
| 231 | buffer_destroy(buf[i]); |
| 232 | |
| 233 | client->surface->buffer = NULL; |
| 234 | client_destroy(client); |
Pekka Paalanen | b0eb059 | 2021-06-11 16:40:34 +0300 | [diff] [blame] | 235 | free(refname); |
Pekka Paalanen | fbd4160 | 2020-12-04 15:20:11 +0200 | [diff] [blame] | 236 | } |