2 * Copyright © 2014 Intel Corporation
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:
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
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
24 * Damien Lespiau <damien.lespiau@intel.com>
33 #include "igt_debugfs.h"
44 igt_display_t display;
45 igt_pipe_crc_t *pipe_crc;
48 static color_t red = { 1.0f, 0.0f, 0.0f };
49 static color_t green = { 0.0f, 1.0f, 0.0f };
50 static color_t blue = { 0.0f, 0.0f, 1.0f };
53 * Common code across all tests, acting on data_t
55 static void test_init(data_t *data, enum pipe pipe)
57 data->pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
60 static void test_fini(data_t *data)
62 igt_pipe_crc_free(data->pipe_crc);
66 test_grab_crc(data_t *data, igt_output_t *output, color_t *fb_color,
67 igt_crc_t *crc /* out */)
70 drmModeModeInfo *mode;
74 primary = igt_output_get_plane(output, 0);
76 mode = igt_output_get_mode(output);
77 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
80 fb_color->red, fb_color->green, fb_color->blue,
82 igt_plane_set_fb(primary, &fb);
84 igt_display_commit(&data->display);
86 igt_pipe_crc_collect_crc(data->pipe_crc, crc);
88 igt_plane_set_fb(primary, NULL);
89 igt_display_commit(&data->display);
91 igt_remove_fb(data->drm_fd, &fb);
93 crc_str = igt_crc_to_string(crc);
94 igt_debug("CRC for a (%.02f,%.02f,%.02f) fb: %s\n", fb_color->red,
95 fb_color->green, fb_color->blue, crc_str);
100 * Plane position test.
101 * - We start by grabbing a reference CRC of a full green fb being scanned
102 * out on the primary plane
103 * - Then we scannout 2 planes:
104 * - the primary plane uses a green fb with a black rectangle
105 * - a plane, on top of the primary plane, with a green fb that is set-up
106 * to cover the black rectangle of the primary plane fb
107 * The resulting CRC should be identical to the reference CRC
112 igt_crc_t reference_crc;
116 * create a green fb with a black rectangle at (rect_x,rect_y) and of size
120 create_fb_for_mode__position(data_t *data, drmModeModeInfo *mode,
121 double rect_x, double rect_y,
122 double rect_w, double rect_h,
123 struct igt_fb *fb /* out */)
128 fb_id = igt_create_fb(data->drm_fd,
129 mode->hdisplay, mode->vdisplay,
135 cr = igt_get_cairo_ctx(data->drm_fd, fb);
136 igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
138 igt_paint_color(cr, rect_x, rect_y, rect_w, rect_h, 0.0, 0.0, 0.0);
139 igt_assert(cairo_status(cr) == 0);
144 TEST_POSITION_FULLY_COVERED = 1 << 0,
148 test_plane_position_with_output(data_t *data,
150 enum igt_plane plane,
151 igt_output_t *output,
154 test_position_t test = { .data = data };
155 igt_plane_t *primary, *sprite;
156 struct igt_fb primary_fb, sprite_fb;
157 drmModeModeInfo *mode;
160 igt_info("Testing connector %s using pipe %c plane %d\n",
161 igt_output_name(output), pipe_name(pipe), plane);
163 test_init(data, pipe);
165 test_grab_crc(data, output, &green, &test.reference_crc);
167 igt_output_set_pipe(output, pipe);
169 mode = igt_output_get_mode(output);
170 primary = igt_output_get_plane(output, 0);
171 sprite = igt_output_get_plane(output, plane);
173 create_fb_for_mode__position(data, mode, 100, 100, 64, 64,
175 igt_plane_set_fb(primary, &primary_fb);
177 igt_create_color_fb(data->drm_fd,
178 64, 64, /* width, height */
183 igt_plane_set_fb(sprite, &sprite_fb);
185 if (flags & TEST_POSITION_FULLY_COVERED)
186 igt_plane_set_position(sprite, 100, 100);
188 igt_plane_set_position(sprite, 132, 132);
190 igt_display_commit(&data->display);
192 igt_pipe_crc_collect_crc(data->pipe_crc, &crc);
194 if (flags & TEST_POSITION_FULLY_COVERED)
195 igt_assert(igt_crc_equal(&test.reference_crc, &crc));
197 igt_assert(!igt_crc_equal(&test.reference_crc, &crc));
199 igt_plane_set_fb(primary, NULL);
200 igt_plane_set_fb(sprite, NULL);
202 /* reset the constraint on the pipe */
203 igt_output_set_pipe(output, PIPE_ANY);
209 test_plane_position(data_t *data, enum pipe pipe, enum igt_plane plane,
212 igt_output_t *output;
214 igt_skip_on(pipe >= data->display.n_pipes);
215 igt_skip_on(plane >= data->display.pipes[pipe].n_planes);
217 for_each_connected_output(&data->display, output)
218 test_plane_position_with_output(data, pipe, plane, output,
223 * Plane panning test.
224 * - We start by grabbing reference CRCs of a full red and a full blue fb
225 * being scanned out on the primary plane
226 * - Then we create a big fb, sized (2 * hdisplay, 2 * vdisplay) and:
227 * - fill the top left quarter with red
228 * - fill the bottom right quarter with blue
229 * - The TEST_PANNING_TOP_LEFT test makes sure that with panning at (0, 0)
230 * we do get the same CRC than the full red fb.
231 * - The TEST_PANNING_BOTTOM_RIGHT test makes sure that with panning at
232 * (vdisplay, hdisplay) we do get the same CRC than the full blue fb.
236 igt_crc_t red_crc, blue_crc;
240 create_fb_for_mode__panning(data_t *data, drmModeModeInfo *mode,
241 struct igt_fb *fb /* out */)
246 fb_id = igt_create_fb(data->drm_fd,
247 mode->hdisplay * 2, mode->vdisplay * 2,
253 cr = igt_get_cairo_ctx(data->drm_fd, fb);
255 igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
259 mode->hdisplay, mode->vdisplay,
260 mode->hdisplay, mode->vdisplay,
263 igt_assert(cairo_status(cr) == 0);
268 TEST_PANNING_TOP_LEFT = 1 << 0,
269 TEST_PANNING_BOTTOM_RIGHT = 1 << 1,
273 test_plane_panning_with_output(data_t *data,
275 enum igt_plane plane,
276 igt_output_t *output,
279 test_panning_t test = { .data = data };
280 igt_plane_t *primary;
281 struct igt_fb primary_fb;
282 drmModeModeInfo *mode;
285 fprintf(stdout, "Testing connector %s using pipe %c plane %d\n",
286 igt_output_name(output), pipe_name(pipe), plane);
288 test_init(data, pipe);
290 test_grab_crc(data, output, &red, &test.red_crc);
291 test_grab_crc(data, output, &blue, &test.blue_crc);
293 igt_output_set_pipe(output, pipe);
295 mode = igt_output_get_mode(output);
296 primary = igt_output_get_plane(output, 0);
298 create_fb_for_mode__panning(data, mode, &primary_fb);
299 igt_plane_set_fb(primary, &primary_fb);
301 if (flags & TEST_PANNING_TOP_LEFT)
302 igt_plane_set_panning(primary, 0, 0);
304 igt_plane_set_panning(primary, mode->hdisplay, mode->vdisplay);
306 igt_plane_set_position(primary, 0, 0);
308 igt_display_commit(&data->display);
310 igt_pipe_crc_collect_crc(data->pipe_crc, &crc);
312 if (flags & TEST_PANNING_TOP_LEFT)
313 igt_assert(igt_crc_equal(&test.red_crc, &crc));
315 igt_assert(igt_crc_equal(&test.blue_crc, &crc));
317 igt_plane_set_fb(primary, NULL);
319 /* reset states to neutral values, assumed by other tests */
320 igt_output_set_pipe(output, PIPE_ANY);
321 igt_plane_set_panning(primary, 0, 0);
327 test_plane_panning(data_t *data, enum pipe pipe, enum igt_plane plane,
330 igt_output_t *output;
332 igt_skip_on(pipe >= data->display.n_pipes);
333 igt_skip_on(plane >= data->display.pipes[pipe].n_planes);
335 for_each_connected_output(&data->display, output)
336 test_plane_panning_with_output(data, pipe, plane, output,
341 run_tests_for_pipe_plane(data_t *data, enum pipe pipe, enum igt_plane plane)
343 igt_subtest_f("plane-position-covered-pipe-%c-plane-%d",
344 pipe_name(pipe), plane)
345 test_plane_position(data, pipe, plane,
346 TEST_POSITION_FULLY_COVERED);
348 igt_subtest_f("plane-position-hole-pipe-%c-plane-%d",
349 pipe_name(pipe), plane)
350 test_plane_position(data, pipe, plane, 0);
352 igt_subtest_f("plane-panning-top-left-pipe-%c-plane-%d",
353 pipe_name(pipe), plane)
354 test_plane_panning(data, pipe, plane, TEST_PANNING_TOP_LEFT);
356 igt_subtest_f("plane-panning-bottom-right-pipe-%c-plane-%d",
357 pipe_name(pipe), plane)
358 test_plane_panning(data, pipe, plane,
359 TEST_PANNING_BOTTOM_RIGHT);
364 run_tests_for_pipe(data_t *data, enum pipe pipe)
368 for (plane = 1; plane < IGT_MAX_PLANES; plane++)
369 run_tests_for_pipe_plane(data, pipe, plane);
377 igt_skip_on_simulation();
380 data.drm_fd = drm_open_any();
382 igt_set_vt_graphics_mode();
384 igt_require_pipe_crc();
385 igt_display_init(&data.display, data.drm_fd);
388 for (int pipe = 0; pipe < 3; pipe++)
389 run_tests_for_pipe(&data, pipe);
392 igt_display_fini(&data.display);