Maarten Lankhorst | d097564 | 2018-10-01 17:48:12 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2018 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Maarten Lankhorst <maarten.lankhorst@linux.intel.com> |
| 25 | */ |
| 26 | |
| 27 | #include "igt.h" |
| 28 | |
| 29 | IGT_TEST_DESCRIPTION("Test plane alpha and blending mode properties"); |
| 30 | |
| 31 | typedef struct { |
| 32 | int gfx_fd; |
| 33 | igt_display_t display; |
| 34 | struct igt_fb xrgb_fb, argb_fb_0, argb_fb_cov_0, argb_fb_7e, argb_fb_cov_7e, argb_fb_fc, argb_fb_cov_fc, argb_fb_100, black_fb, gray_fb; |
| 35 | igt_crc_t ref_crc; |
| 36 | igt_pipe_crc_t *pipe_crc; |
| 37 | } data_t; |
| 38 | |
| 39 | static void __draw_gradient(struct igt_fb *fb, int w, int h, double a, cairo_t *cr) |
| 40 | { |
| 41 | cairo_pattern_t *pat; |
| 42 | |
| 43 | pat = cairo_pattern_create_linear(0, 0, w, h); |
| 44 | cairo_pattern_add_color_stop_rgba(pat, 0.00, 0.00, 0.00, 0.00, 1.); |
| 45 | cairo_pattern_add_color_stop_rgba(pat, 0.25, 1.00, 1.00, 0.00, 1.); |
| 46 | cairo_pattern_add_color_stop_rgba(pat, 0.50, 0.00, 1.00, 1.00, 1.); |
| 47 | cairo_pattern_add_color_stop_rgba(pat, 0.75, 1.00, 0.00, 1.00, 1.); |
| 48 | cairo_pattern_add_color_stop_rgba(pat, 1.00, 1.00, 1.00, 1.00, 1.); |
| 49 | |
| 50 | cairo_rectangle(cr, 0, 0, w, h); |
| 51 | cairo_set_source(cr, pat); |
| 52 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 53 | cairo_paint_with_alpha(cr, a); |
| 54 | cairo_pattern_destroy(pat); |
| 55 | } |
| 56 | |
| 57 | static void draw_gradient(struct igt_fb *fb, int w, int h, double a) |
| 58 | { |
| 59 | cairo_t *cr = igt_get_cairo_ctx(fb->fd, fb); |
| 60 | |
| 61 | __draw_gradient(fb, w, h, a, cr); |
| 62 | |
| 63 | igt_put_cairo_ctx(fb->fd, fb, cr); |
| 64 | } |
| 65 | |
| 66 | static void draw_gradient_coverage(struct igt_fb *fb, int w, int h, uint8_t a) |
| 67 | { |
| 68 | cairo_t *cr = igt_get_cairo_ctx(fb->fd, fb); |
| 69 | uint8_t *data = cairo_image_surface_get_data(fb->cairo_surface); |
| 70 | uint32_t stride = fb->strides[0]; |
| 71 | int i; |
| 72 | |
| 73 | __draw_gradient(fb, w, h, 1., cr); |
| 74 | |
| 75 | for (; h--; data += stride) |
| 76 | for (i = 0; i < w; i++) |
| 77 | data[i * 4 + 3] = a; |
| 78 | |
| 79 | igt_put_cairo_ctx(fb->fd, fb, cr); |
| 80 | } |
| 81 | |
| 82 | static void draw_squares(struct igt_fb *fb, int w, int h, double a) |
| 83 | { |
| 84 | cairo_t *cr = igt_get_cairo_ctx(fb->fd, fb); |
| 85 | |
| 86 | igt_paint_color_alpha(cr, 0, 0, w / 2, h / 2, 1., 0., 0., a); |
| 87 | igt_paint_color_alpha(cr, w / 2, 0, w / 2, h / 2, 0., 1., 0., a); |
| 88 | igt_paint_color_alpha(cr, 0, h / 2, w / 2, h / 2, 0., 0., 1., a); |
| 89 | igt_paint_color_alpha(cr, w / 2, h / 2, w / 4, h / 2, 1., 1., 1., a); |
| 90 | igt_paint_color_alpha(cr, 3 * w / 4, h / 2, w / 4, h / 2, 0., 0., 0., a); |
| 91 | |
| 92 | igt_put_cairo_ctx(fb->fd, fb, cr); |
| 93 | } |
| 94 | |
| 95 | static void draw_squares_coverage(struct igt_fb *fb, int w, int h, uint8_t as) |
| 96 | { |
| 97 | cairo_t *cr = igt_get_cairo_ctx(fb->fd, fb); |
| 98 | int i, j; |
| 99 | uint32_t *data = (void *)cairo_image_surface_get_data(fb->cairo_surface); |
| 100 | uint32_t stride = fb->strides[0] / 4; |
| 101 | uint32_t a = as << 24; |
| 102 | |
| 103 | for (j = 0; j < h / 2; j++) { |
| 104 | for (i = 0; i < w / 2; i++) |
| 105 | data[j * stride + i] = a | 0xff0000; |
| 106 | |
| 107 | for (; i < w; i++) |
| 108 | data[j * stride + i] = a | 0xff00; |
| 109 | } |
| 110 | |
| 111 | for (j = h / 2; j < h; j++) { |
| 112 | for (i = 0; i < w / 2; i++) |
| 113 | data[j * stride + i] = a | 0xff; |
| 114 | |
| 115 | for (; i < 3 * w / 4; i++) |
| 116 | data[j * stride + i] = a | 0xffffff; |
| 117 | |
| 118 | for (; i < w; i++) |
| 119 | data[j * stride + i] = a; |
| 120 | } |
| 121 | |
| 122 | igt_put_cairo_ctx(fb->fd, fb, cr); |
| 123 | } |
| 124 | |
| 125 | static void reset_alpha(igt_display_t *display, enum pipe pipe) |
| 126 | { |
| 127 | igt_plane_t *plane; |
| 128 | |
| 129 | for_each_plane_on_pipe(display, pipe, plane) { |
| 130 | if (igt_plane_has_prop(plane, IGT_PLANE_ALPHA)) |
| 131 | igt_plane_set_prop_value(plane, IGT_PLANE_ALPHA, 0xffff); |
| 132 | |
| 133 | if (igt_plane_has_prop(plane, IGT_PLANE_PIXEL_BLEND_MODE)) |
| 134 | igt_plane_set_prop_enum(plane, IGT_PLANE_PIXEL_BLEND_MODE, "Pre-multiplied"); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | static bool has_multiplied_alpha(data_t *data, igt_plane_t *plane) |
| 139 | { |
| 140 | int ret; |
| 141 | |
| 142 | igt_plane_set_prop_value(plane, IGT_PLANE_ALPHA, 0x8080); |
| 143 | igt_plane_set_fb(plane, &data->argb_fb_100); |
| 144 | ret = igt_display_try_commit_atomic(&data->display, |
| 145 | DRM_MODE_ATOMIC_TEST_ONLY | DRM_MODE_ATOMIC_ALLOW_MODESET, NULL); |
| 146 | igt_plane_set_prop_value(plane, IGT_PLANE_ALPHA, 0xffff); |
| 147 | igt_plane_set_fb(plane, NULL); |
| 148 | |
| 149 | return ret == 0; |
| 150 | } |
| 151 | |
| 152 | static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe) |
| 153 | { |
| 154 | drmModeModeInfo *mode; |
| 155 | igt_display_t *display = &data->display; |
| 156 | int w, h; |
| 157 | igt_plane_t *primary = igt_pipe_get_plane_type(&display->pipes[pipe], DRM_PLANE_TYPE_PRIMARY); |
| 158 | |
| 159 | igt_display_reset(display); |
| 160 | igt_output_set_pipe(output, pipe); |
| 161 | |
| 162 | /* create the pipe_crc object for this pipe */ |
| 163 | igt_pipe_crc_free(data->pipe_crc); |
| 164 | data->pipe_crc = igt_pipe_crc_new(data->gfx_fd, pipe, INTEL_PIPE_CRC_SOURCE_AUTO); |
| 165 | |
| 166 | mode = igt_output_get_mode(output); |
| 167 | w = mode->hdisplay; |
| 168 | h = mode->vdisplay; |
| 169 | |
| 170 | /* recreate all fbs if incompatible */ |
| 171 | if (data->xrgb_fb.width != w || data->xrgb_fb.height != h) { |
| 172 | cairo_t *cr; |
| 173 | |
| 174 | igt_remove_fb(data->gfx_fd, &data->xrgb_fb); |
| 175 | igt_remove_fb(data->gfx_fd, &data->argb_fb_0); |
| 176 | igt_remove_fb(data->gfx_fd, &data->argb_fb_cov_0); |
| 177 | igt_remove_fb(data->gfx_fd, &data->argb_fb_7e); |
| 178 | igt_remove_fb(data->gfx_fd, &data->argb_fb_fc); |
| 179 | igt_remove_fb(data->gfx_fd, &data->argb_fb_cov_7e); |
| 180 | igt_remove_fb(data->gfx_fd, &data->argb_fb_cov_fc); |
| 181 | igt_remove_fb(data->gfx_fd, &data->argb_fb_100); |
| 182 | igt_remove_fb(data->gfx_fd, &data->black_fb); |
| 183 | igt_remove_fb(data->gfx_fd, &data->gray_fb); |
| 184 | |
| 185 | igt_create_fb(data->gfx_fd, w, h, |
| 186 | DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE, |
| 187 | &data->xrgb_fb); |
| 188 | draw_gradient(&data->xrgb_fb, w, h, 1.); |
| 189 | |
| 190 | igt_create_fb(data->gfx_fd, w, h, |
| 191 | DRM_FORMAT_ARGB8888, LOCAL_DRM_FORMAT_MOD_NONE, |
| 192 | &data->argb_fb_cov_0); |
| 193 | draw_gradient_coverage(&data->argb_fb_cov_0, w, h, 0); |
| 194 | |
| 195 | igt_create_fb(data->gfx_fd, w, h, |
| 196 | DRM_FORMAT_ARGB8888, LOCAL_DRM_FORMAT_MOD_NONE, |
| 197 | &data->argb_fb_0); |
| 198 | |
| 199 | cr = igt_get_cairo_ctx(data->gfx_fd, &data->argb_fb_0); |
| 200 | igt_paint_color_alpha(cr, 0, 0, w, h, 0., 0., 0., 1.0); |
| 201 | igt_put_cairo_ctx(data->gfx_fd, &data->argb_fb_0, cr); |
| 202 | |
| 203 | igt_create_fb(data->gfx_fd, w, h, |
| 204 | DRM_FORMAT_ARGB8888, LOCAL_DRM_FORMAT_MOD_NONE, |
| 205 | &data->argb_fb_7e); |
| 206 | draw_squares(&data->argb_fb_7e, w, h, 126. / 255.); |
| 207 | |
| 208 | igt_create_fb(data->gfx_fd, w, h, |
| 209 | DRM_FORMAT_ARGB8888, LOCAL_DRM_FORMAT_MOD_NONE, |
| 210 | &data->argb_fb_cov_7e); |
| 211 | draw_squares_coverage(&data->argb_fb_cov_7e, w, h, 0x7e); |
| 212 | |
| 213 | igt_create_fb(data->gfx_fd, w, h, |
| 214 | DRM_FORMAT_ARGB8888, LOCAL_DRM_FORMAT_MOD_NONE, |
| 215 | &data->argb_fb_fc); |
| 216 | draw_squares(&data->argb_fb_fc, w, h, 252. / 255.); |
| 217 | |
| 218 | igt_create_fb(data->gfx_fd, w, h, |
| 219 | DRM_FORMAT_ARGB8888, LOCAL_DRM_FORMAT_MOD_NONE, |
| 220 | &data->argb_fb_cov_fc); |
| 221 | draw_squares_coverage(&data->argb_fb_cov_fc, w, h, 0xfc); |
| 222 | |
| 223 | igt_create_fb(data->gfx_fd, w, h, |
| 224 | DRM_FORMAT_ARGB8888, LOCAL_DRM_FORMAT_MOD_NONE, |
| 225 | &data->argb_fb_100); |
| 226 | draw_gradient(&data->argb_fb_100, w, h, 1.); |
| 227 | |
| 228 | igt_create_fb(data->gfx_fd, w, h, |
| 229 | DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE, |
| 230 | &data->black_fb); |
| 231 | |
| 232 | igt_create_color_fb(data->gfx_fd, w, h, |
| 233 | DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE, |
| 234 | .5, .5, .5, &data->gray_fb); |
| 235 | } |
| 236 | |
| 237 | igt_plane_set_fb(primary, &data->black_fb); |
| 238 | /* reset alpha property to default */ |
| 239 | reset_alpha(display, pipe); |
| 240 | } |
| 241 | |
| 242 | static void basic_alpha(data_t *data, enum pipe pipe, igt_plane_t *plane) |
| 243 | { |
| 244 | igt_display_t *display = &data->display; |
| 245 | igt_crc_t ref_crc, crc; |
| 246 | int i; |
| 247 | |
| 248 | /* Testcase 1: alpha = 0.0, plane should be transparant. */ |
| 249 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 250 | igt_pipe_crc_start(data->pipe_crc); |
| 251 | igt_pipe_crc_get_single(data->pipe_crc, &ref_crc); |
| 252 | |
| 253 | igt_plane_set_fb(plane, &data->argb_fb_0); |
| 254 | |
| 255 | /* transparant fb should be transparant, no matter what.. */ |
| 256 | for (i = 7; i < 256; i += 8) { |
| 257 | igt_plane_set_prop_value(plane, IGT_PLANE_ALPHA, i | (i << 8)); |
| 258 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 259 | |
| 260 | igt_pipe_crc_get_current(display->drm_fd, data->pipe_crc, &crc); |
| 261 | igt_assert_crc_equal(&ref_crc, &crc); |
| 262 | } |
| 263 | |
| 264 | /* And test alpha = 0, should give same CRC, but doesn't on some i915 platforms. */ |
| 265 | igt_plane_set_prop_value(plane, IGT_PLANE_ALPHA, 0); |
| 266 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 267 | |
| 268 | igt_pipe_crc_get_current(display->drm_fd, data->pipe_crc, &crc); |
Maarten Lankhorst | d097564 | 2018-10-01 17:48:12 +0200 | [diff] [blame] | 269 | igt_assert_crc_equal(&ref_crc, &crc); |
Maarten Lankhorst | ee9a10a | 2018-10-03 10:59:45 +0200 | [diff] [blame] | 270 | |
| 271 | igt_pipe_crc_stop(data->pipe_crc); |
Maarten Lankhorst | d097564 | 2018-10-01 17:48:12 +0200 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static void argb_opaque(data_t *data, enum pipe pipe, igt_plane_t *plane) |
| 275 | { |
| 276 | igt_display_t *display = &data->display; |
| 277 | igt_crc_t ref_crc, crc; |
| 278 | |
| 279 | /* alpha = 1.0, plane should be fully opaque, test with an opaque fb */ |
| 280 | igt_plane_set_fb(plane, &data->xrgb_fb); |
| 281 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 282 | igt_pipe_crc_collect_crc(data->pipe_crc, &ref_crc); |
| 283 | |
| 284 | igt_plane_set_fb(plane, &data->argb_fb_100); |
| 285 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 286 | igt_pipe_crc_collect_crc(data->pipe_crc, &crc); |
| 287 | |
| 288 | igt_assert_crc_equal(&ref_crc, &crc); |
| 289 | } |
| 290 | |
| 291 | static void argb_transparant(data_t *data, enum pipe pipe, igt_plane_t *plane) |
| 292 | { |
| 293 | igt_display_t *display = &data->display; |
| 294 | igt_crc_t ref_crc, crc; |
| 295 | |
| 296 | /* alpha = 1.0, plane should be fully opaque, test with a transparant fb */ |
| 297 | igt_plane_set_fb(plane, NULL); |
| 298 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 299 | igt_pipe_crc_collect_crc(data->pipe_crc, &ref_crc); |
| 300 | |
| 301 | igt_plane_set_fb(plane, &data->argb_fb_0); |
| 302 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 303 | igt_pipe_crc_collect_crc(data->pipe_crc, &crc); |
| 304 | |
| 305 | igt_assert_crc_equal(&ref_crc, &crc); |
| 306 | } |
| 307 | |
| 308 | static void constant_alpha_min(data_t *data, enum pipe pipe, igt_plane_t *plane) |
| 309 | { |
| 310 | igt_display_t *display = &data->display; |
| 311 | igt_crc_t ref_crc, crc; |
| 312 | |
| 313 | igt_plane_set_fb(plane, NULL); |
| 314 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 315 | igt_pipe_crc_collect_crc(data->pipe_crc, &ref_crc); |
| 316 | |
| 317 | igt_plane_set_prop_enum(plane, IGT_PLANE_PIXEL_BLEND_MODE, "None"); |
| 318 | igt_plane_set_prop_value(plane, IGT_PLANE_ALPHA, 0); |
| 319 | igt_plane_set_fb(plane, &data->argb_fb_100); |
| 320 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 321 | igt_pipe_crc_collect_crc(data->pipe_crc, &crc); |
| 322 | igt_assert_crc_equal(&ref_crc, &crc); |
| 323 | |
| 324 | igt_plane_set_fb(plane, &data->argb_fb_0); |
| 325 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 326 | igt_pipe_crc_collect_crc(data->pipe_crc, &crc); |
| 327 | igt_assert_crc_equal(&ref_crc, &crc); |
| 328 | } |
| 329 | |
| 330 | static void constant_alpha_mid(data_t *data, enum pipe pipe, igt_plane_t *plane) |
| 331 | { |
| 332 | igt_display_t *display = &data->display; |
| 333 | igt_crc_t ref_crc, crc; |
| 334 | |
| 335 | if (plane->type != DRM_PLANE_TYPE_PRIMARY) |
| 336 | igt_plane_set_fb(igt_pipe_get_plane_type(&display->pipes[pipe], DRM_PLANE_TYPE_PRIMARY), &data->gray_fb); |
| 337 | |
| 338 | igt_plane_set_prop_enum(plane, IGT_PLANE_PIXEL_BLEND_MODE, "None"); |
| 339 | igt_plane_set_prop_value(plane, IGT_PLANE_ALPHA, 0x7fff); |
| 340 | igt_plane_set_fb(plane, &data->xrgb_fb); |
| 341 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 342 | igt_pipe_crc_collect_crc(data->pipe_crc, &ref_crc); |
| 343 | |
| 344 | igt_plane_set_fb(plane, &data->argb_fb_cov_0); |
| 345 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 346 | igt_pipe_crc_collect_crc(data->pipe_crc, &crc); |
| 347 | igt_assert_crc_equal(&ref_crc, &crc); |
| 348 | |
| 349 | igt_plane_set_fb(plane, &data->argb_fb_100); |
| 350 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 351 | igt_pipe_crc_collect_crc(data->pipe_crc, &crc); |
| 352 | igt_assert_crc_equal(&ref_crc, &crc); |
| 353 | } |
| 354 | |
| 355 | static void constant_alpha_max(data_t *data, enum pipe pipe, igt_plane_t *plane) |
| 356 | { |
| 357 | igt_display_t *display = &data->display; |
| 358 | igt_crc_t ref_crc, crc; |
| 359 | |
| 360 | if (plane->type != DRM_PLANE_TYPE_PRIMARY) |
| 361 | igt_plane_set_fb(igt_pipe_get_plane_type(&display->pipes[pipe], DRM_PLANE_TYPE_PRIMARY), &data->gray_fb); |
| 362 | |
| 363 | igt_plane_set_fb(plane, &data->argb_fb_100); |
| 364 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 365 | igt_pipe_crc_collect_crc(data->pipe_crc, &ref_crc); |
| 366 | |
| 367 | igt_plane_set_prop_enum(plane, IGT_PLANE_PIXEL_BLEND_MODE, "None"); |
| 368 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 369 | igt_pipe_crc_collect_crc(data->pipe_crc, &crc); |
| 370 | igt_assert_crc_equal(&ref_crc, &crc); |
| 371 | |
| 372 | igt_plane_set_fb(plane, &data->argb_fb_cov_0); |
| 373 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 374 | igt_pipe_crc_collect_crc(data->pipe_crc, &crc); |
| 375 | igt_assert_crc_equal(&ref_crc, &crc); |
| 376 | |
| 377 | igt_plane_set_fb(plane, &data->xrgb_fb); |
| 378 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 379 | igt_pipe_crc_collect_crc(data->pipe_crc, &crc); |
| 380 | igt_assert_crc_equal(&ref_crc, &crc); |
| 381 | |
| 382 | igt_plane_set_fb(plane, NULL); |
| 383 | } |
| 384 | |
| 385 | static void alpha_7efc(data_t *data, enum pipe pipe, igt_plane_t *plane) |
| 386 | { |
| 387 | igt_display_t *display = &data->display; |
| 388 | igt_crc_t ref_crc = {}, crc = {}; |
| 389 | int i; |
| 390 | |
| 391 | if (plane->type != DRM_PLANE_TYPE_PRIMARY) |
| 392 | igt_plane_set_fb(igt_pipe_get_plane_type(&display->pipes[pipe], DRM_PLANE_TYPE_PRIMARY), &data->gray_fb); |
| 393 | |
Maarten Lankhorst | ee9a10a | 2018-10-03 10:59:45 +0200 | [diff] [blame] | 394 | igt_display_commit2(display, COMMIT_ATOMIC); |
Maarten Lankhorst | d097564 | 2018-10-01 17:48:12 +0200 | [diff] [blame] | 395 | igt_pipe_crc_start(data->pipe_crc); |
| 396 | |
| 397 | /* for coverage, plane alpha and fb alpha should be swappable, so swap fb and alpha */ |
| 398 | for (i = 0; i < 256; i += 8) { |
| 399 | igt_plane_set_prop_value(plane, IGT_PLANE_ALPHA, ((i/2) << 8) | (i/2)); |
| 400 | igt_plane_set_fb(plane, &data->argb_fb_fc); |
| 401 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 402 | |
| 403 | igt_pipe_crc_get_current(display->drm_fd, data->pipe_crc, &ref_crc); |
| 404 | |
| 405 | igt_plane_set_prop_value(plane, IGT_PLANE_ALPHA, (i << 8) | i); |
| 406 | igt_plane_set_fb(plane, &data->argb_fb_7e); |
| 407 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 408 | |
| 409 | igt_pipe_crc_get_current(display->drm_fd, data->pipe_crc, &crc); |
| 410 | igt_assert_crc_equal(&ref_crc, &crc); |
| 411 | } |
Maarten Lankhorst | ee9a10a | 2018-10-03 10:59:45 +0200 | [diff] [blame] | 412 | |
| 413 | igt_pipe_crc_stop(data->pipe_crc); |
Maarten Lankhorst | d097564 | 2018-10-01 17:48:12 +0200 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | static void coverage_7efc(data_t *data, enum pipe pipe, igt_plane_t *plane) |
| 417 | { |
| 418 | igt_display_t *display = &data->display; |
| 419 | igt_crc_t ref_crc = {}, crc = {}; |
| 420 | int i; |
| 421 | |
| 422 | igt_plane_set_prop_enum(plane, IGT_PLANE_PIXEL_BLEND_MODE, "Coverage"); |
Maarten Lankhorst | ee9a10a | 2018-10-03 10:59:45 +0200 | [diff] [blame] | 423 | igt_display_commit2(display, COMMIT_ATOMIC); |
Maarten Lankhorst | d097564 | 2018-10-01 17:48:12 +0200 | [diff] [blame] | 424 | igt_pipe_crc_start(data->pipe_crc); |
| 425 | |
| 426 | /* for coverage, plane alpha and fb alpha should be swappable, so swap fb and alpha */ |
| 427 | for (i = 0; i < 256; i += 8) { |
| 428 | igt_plane_set_prop_value(plane, IGT_PLANE_ALPHA, ((i/2) << 8) | (i/2)); |
| 429 | igt_plane_set_fb(plane, &data->argb_fb_cov_fc); |
| 430 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 431 | |
| 432 | igt_pipe_crc_get_current(display->drm_fd, data->pipe_crc, &ref_crc); |
| 433 | |
| 434 | igt_plane_set_prop_value(plane, IGT_PLANE_ALPHA, (i << 8) | i); |
| 435 | igt_plane_set_fb(plane, &data->argb_fb_cov_7e); |
| 436 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 437 | |
| 438 | igt_pipe_crc_get_current(display->drm_fd, data->pipe_crc, &crc); |
| 439 | igt_assert_crc_equal(&ref_crc, &crc); |
| 440 | } |
Maarten Lankhorst | ee9a10a | 2018-10-03 10:59:45 +0200 | [diff] [blame] | 441 | |
| 442 | igt_pipe_crc_stop(data->pipe_crc); |
Maarten Lankhorst | d097564 | 2018-10-01 17:48:12 +0200 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | static void coverage_premult_constant(data_t *data, enum pipe pipe, igt_plane_t *plane) |
| 446 | { |
| 447 | igt_display_t *display = &data->display; |
| 448 | igt_crc_t ref_crc = {}, crc = {}; |
| 449 | |
| 450 | /* Set a background color on the primary fb for testing */ |
| 451 | if (plane->type != DRM_PLANE_TYPE_PRIMARY) |
| 452 | igt_plane_set_fb(igt_pipe_get_plane_type(&display->pipes[pipe], DRM_PLANE_TYPE_PRIMARY), &data->gray_fb); |
| 453 | |
| 454 | igt_plane_set_prop_enum(plane, IGT_PLANE_PIXEL_BLEND_MODE, "Coverage"); |
| 455 | igt_plane_set_fb(plane, &data->argb_fb_cov_7e); |
| 456 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 457 | igt_pipe_crc_start(data->pipe_crc); |
| 458 | igt_pipe_crc_get_single(data->pipe_crc, &ref_crc); |
| 459 | |
| 460 | igt_plane_set_prop_enum(plane, IGT_PLANE_PIXEL_BLEND_MODE, "Pre-multiplied"); |
| 461 | igt_plane_set_fb(plane, &data->argb_fb_7e); |
| 462 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 463 | igt_pipe_crc_get_current(display->drm_fd, data->pipe_crc, &crc); |
| 464 | igt_assert_crc_equal(&ref_crc, &crc); |
| 465 | |
| 466 | igt_plane_set_prop_enum(plane, IGT_PLANE_PIXEL_BLEND_MODE, "None"); |
| 467 | igt_plane_set_prop_value(plane, IGT_PLANE_ALPHA, 0x7e7e); |
| 468 | igt_plane_set_fb(plane, &data->argb_fb_cov_7e); |
| 469 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 470 | igt_pipe_crc_get_current(display->drm_fd, data->pipe_crc, &crc); |
| 471 | igt_assert_crc_equal(&ref_crc, &crc); |
Maarten Lankhorst | ee9a10a | 2018-10-03 10:59:45 +0200 | [diff] [blame] | 472 | |
| 473 | igt_pipe_crc_stop(data->pipe_crc); |
Maarten Lankhorst | d097564 | 2018-10-01 17:48:12 +0200 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | static void run_test_on_pipe_planes(data_t *data, enum pipe pipe, bool blend, |
| 477 | bool must_multiply, |
| 478 | void(*test)(data_t *, enum pipe, igt_plane_t *)) |
| 479 | { |
| 480 | igt_display_t *display = &data->display; |
| 481 | igt_output_t *output = igt_get_single_output_for_pipe(display, pipe); |
| 482 | igt_plane_t *plane; |
| 483 | bool found = false; |
| 484 | bool multiply = false; |
| 485 | |
| 486 | for_each_plane_on_pipe(display, pipe, plane) { |
| 487 | if (!igt_plane_has_prop(plane, IGT_PLANE_ALPHA)) |
| 488 | continue; |
| 489 | |
| 490 | if (blend && !igt_plane_has_prop(plane, IGT_PLANE_PIXEL_BLEND_MODE)) |
| 491 | continue; |
| 492 | |
| 493 | prepare_crtc(data, output, pipe); |
| 494 | |
| 495 | /* reset plane alpha properties between each plane */ |
| 496 | reset_alpha(display, pipe); |
| 497 | |
| 498 | found = true; |
| 499 | if (must_multiply && !has_multiplied_alpha(data, plane)) |
| 500 | continue; |
| 501 | multiply = true; |
| 502 | |
| 503 | igt_info("Testing plane %u\n", plane->index); |
| 504 | test(data, pipe, plane); |
| 505 | igt_plane_set_fb(plane, NULL); |
| 506 | } |
| 507 | |
| 508 | igt_require_f(found, "No planes with %s property found\n", |
| 509 | blend ? "pixel blending mode" : "alpha"); |
| 510 | igt_require_f(multiply, "Multiplied (plane x pixel) alpha not available\n"); |
| 511 | } |
| 512 | |
| 513 | static void run_subtests(data_t *data, enum pipe pipe) |
| 514 | { |
| 515 | igt_fixture { |
| 516 | bool found = false; |
| 517 | igt_plane_t *plane; |
| 518 | |
| 519 | igt_display_require_output_on_pipe(&data->display, pipe); |
| 520 | for_each_plane_on_pipe(&data->display, pipe, plane) { |
| 521 | if (!igt_plane_has_prop(plane, IGT_PLANE_ALPHA)) |
| 522 | continue; |
| 523 | |
| 524 | found = true; |
| 525 | break; |
| 526 | } |
| 527 | |
| 528 | igt_require_f(found, "Found no plane on pipe %s with alpha blending supported\n", |
| 529 | kmstest_pipe_name(pipe)); |
| 530 | } |
| 531 | |
| 532 | igt_subtest_f("pipe-%s-alpha-basic", kmstest_pipe_name(pipe)) |
| 533 | run_test_on_pipe_planes(data, pipe, false, true, basic_alpha); |
| 534 | |
| 535 | igt_subtest_f("pipe-%s-alpha-7efc", kmstest_pipe_name(pipe)) |
| 536 | run_test_on_pipe_planes(data, pipe, false, true, alpha_7efc); |
| 537 | |
| 538 | igt_subtest_f("pipe-%s-coverage-7efc", kmstest_pipe_name(pipe)) |
| 539 | run_test_on_pipe_planes(data, pipe, true, true, coverage_7efc); |
| 540 | |
| 541 | igt_subtest_f("pipe-%s-coverage-vs-premult-vs-constant", kmstest_pipe_name(pipe)) |
| 542 | run_test_on_pipe_planes(data, pipe, true, false, coverage_premult_constant); |
| 543 | |
| 544 | igt_subtest_f("pipe-%s-alpha-transparant-fb", kmstest_pipe_name(pipe)) |
| 545 | run_test_on_pipe_planes(data, pipe, false, false, argb_transparant); |
| 546 | |
| 547 | igt_subtest_f("pipe-%s-alpha-opaque-fb", kmstest_pipe_name(pipe)) |
| 548 | run_test_on_pipe_planes(data, pipe, false, false, argb_opaque); |
| 549 | |
| 550 | igt_subtest_f("pipe-%s-constant-alpha-min", kmstest_pipe_name(pipe)) |
| 551 | run_test_on_pipe_planes(data, pipe, true, false, constant_alpha_min); |
| 552 | |
| 553 | igt_subtest_f("pipe-%s-constant-alpha-mid", kmstest_pipe_name(pipe)) |
| 554 | run_test_on_pipe_planes(data, pipe, true, false, constant_alpha_mid); |
| 555 | |
| 556 | igt_subtest_f("pipe-%s-constant-alpha-max", kmstest_pipe_name(pipe)) |
| 557 | run_test_on_pipe_planes(data, pipe, true, false, constant_alpha_max); |
| 558 | } |
| 559 | |
| 560 | igt_main |
| 561 | { |
| 562 | data_t data = {}; |
| 563 | enum pipe pipe; |
| 564 | |
| 565 | igt_fixture { |
Maarten Lankhorst | d097564 | 2018-10-01 17:48:12 +0200 | [diff] [blame] | 566 | data.gfx_fd = drm_open_driver(DRIVER_ANY); |
| 567 | igt_require_pipe_crc(data.gfx_fd); |
Daniel Vetter | 88a50c7 | 2018-11-22 10:36:57 +0100 | [diff] [blame] | 568 | igt_display_require(&data.display, data.gfx_fd); |
Maarten Lankhorst | d097564 | 2018-10-01 17:48:12 +0200 | [diff] [blame] | 569 | igt_require(data.display.is_atomic); |
| 570 | } |
| 571 | |
| 572 | for_each_pipe_static(pipe) |
| 573 | igt_subtest_group |
| 574 | run_subtests(&data, pipe); |
| 575 | |
| 576 | igt_fixture |
| 577 | igt_display_fini(&data.display); |
| 578 | } |