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, enum pipe pipe,
67 color_t *fb_color, igt_crc_t *crc /* out */)
70 drmModeModeInfo *mode;
74 igt_output_set_pipe(output, pipe);
76 primary = igt_output_get_plane(output, 0);
78 mode = igt_output_get_mode(output);
79 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
82 fb_color->red, fb_color->green, fb_color->blue,
84 igt_plane_set_fb(primary, &fb);
86 igt_display_commit(&data->display);
88 igt_pipe_crc_collect_crc(data->pipe_crc, crc);
90 igt_plane_set_fb(primary, NULL);
91 igt_display_commit(&data->display);
93 igt_remove_fb(data->drm_fd, &fb);
95 crc_str = igt_crc_to_string(crc);
96 igt_debug("CRC for a (%.02f,%.02f,%.02f) fb: %s\n", fb_color->red,
97 fb_color->green, fb_color->blue, crc_str);
102 * Plane position test.
103 * - We start by grabbing a reference CRC of a full green fb being scanned
104 * out on the primary plane
105 * - Then we scannout 2 planes:
106 * - the primary plane uses a green fb with a black rectangle
107 * - a plane, on top of the primary plane, with a green fb that is set-up
108 * to cover the black rectangle of the primary plane fb
109 * The resulting CRC should be identical to the reference CRC
114 igt_crc_t reference_crc;
118 * create a green fb with a black rectangle at (rect_x,rect_y) and of size
122 create_fb_for_mode__position(data_t *data, drmModeModeInfo *mode,
123 double rect_x, double rect_y,
124 double rect_w, double rect_h,
125 struct igt_fb *fb /* out */)
130 fb_id = igt_create_fb(data->drm_fd,
131 mode->hdisplay, mode->vdisplay,
137 cr = igt_get_cairo_ctx(data->drm_fd, fb);
138 igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
140 igt_paint_color(cr, rect_x, rect_y, rect_w, rect_h, 0.0, 0.0, 0.0);
141 igt_assert(cairo_status(cr) == 0);
146 TEST_POSITION_FULLY_COVERED = 1 << 0,
150 test_plane_position_with_output(data_t *data,
152 enum igt_plane plane,
153 igt_output_t *output,
156 test_position_t test = { .data = data };
157 igt_plane_t *primary, *sprite;
158 struct igt_fb primary_fb, sprite_fb;
159 drmModeModeInfo *mode;
162 igt_info("Testing connector %s using pipe %c plane %d\n",
163 igt_output_name(output), pipe_name(pipe), plane);
165 test_init(data, pipe);
167 test_grab_crc(data, output, pipe, &green, &test.reference_crc);
169 igt_output_set_pipe(output, pipe);
171 mode = igt_output_get_mode(output);
172 primary = igt_output_get_plane(output, 0);
173 sprite = igt_output_get_plane(output, plane);
175 create_fb_for_mode__position(data, mode, 100, 100, 64, 64,
177 igt_plane_set_fb(primary, &primary_fb);
179 igt_create_color_fb(data->drm_fd,
180 64, 64, /* width, height */
185 igt_plane_set_fb(sprite, &sprite_fb);
187 if (flags & TEST_POSITION_FULLY_COVERED)
188 igt_plane_set_position(sprite, 100, 100);
190 igt_plane_set_position(sprite, 132, 132);
192 igt_display_commit(&data->display);
194 igt_pipe_crc_collect_crc(data->pipe_crc, &crc);
196 if (flags & TEST_POSITION_FULLY_COVERED)
197 igt_assert(igt_crc_equal(&test.reference_crc, &crc));
199 igt_assert(!igt_crc_equal(&test.reference_crc, &crc));
201 igt_plane_set_fb(primary, NULL);
202 igt_plane_set_fb(sprite, NULL);
204 /* reset the constraint on the pipe */
205 igt_output_set_pipe(output, PIPE_ANY);
211 test_plane_position(data_t *data, enum pipe pipe, enum igt_plane plane,
214 igt_output_t *output;
216 igt_skip_on(pipe >= data->display.n_pipes);
217 igt_skip_on(plane >= data->display.pipes[pipe].n_planes);
219 for_each_connected_output(&data->display, output)
220 test_plane_position_with_output(data, pipe, plane, output,
225 * Plane panning test.
226 * - We start by grabbing reference CRCs of a full red and a full blue fb
227 * being scanned out on the primary plane
228 * - Then we create a big fb, sized (2 * hdisplay, 2 * vdisplay) and:
229 * - fill the top left quarter with red
230 * - fill the bottom right quarter with blue
231 * - The TEST_PANNING_TOP_LEFT test makes sure that with panning at (0, 0)
232 * we do get the same CRC than the full red fb.
233 * - The TEST_PANNING_BOTTOM_RIGHT test makes sure that with panning at
234 * (vdisplay, hdisplay) we do get the same CRC than the full blue fb.
238 igt_crc_t red_crc, blue_crc;
242 create_fb_for_mode__panning(data_t *data, drmModeModeInfo *mode,
243 struct igt_fb *fb /* out */)
248 fb_id = igt_create_fb(data->drm_fd,
249 mode->hdisplay * 2, mode->vdisplay * 2,
255 cr = igt_get_cairo_ctx(data->drm_fd, fb);
257 igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
261 mode->hdisplay, mode->vdisplay,
262 mode->hdisplay, mode->vdisplay,
265 igt_assert(cairo_status(cr) == 0);
270 TEST_PANNING_TOP_LEFT = 1 << 0,
271 TEST_PANNING_BOTTOM_RIGHT = 1 << 1,
275 test_plane_panning_with_output(data_t *data,
277 enum igt_plane plane,
278 igt_output_t *output,
281 test_panning_t test = { .data = data };
282 igt_plane_t *primary;
283 struct igt_fb primary_fb;
284 drmModeModeInfo *mode;
287 igt_info("Testing connector %s using pipe %c plane %d\n", igt_output_name(output), pipe_name(pipe), plane);
289 test_init(data, pipe);
291 test_grab_crc(data, output, pipe, &red, &test.red_crc);
292 test_grab_crc(data, output, pipe, &blue, &test.blue_crc);
294 igt_output_set_pipe(output, pipe);
296 mode = igt_output_get_mode(output);
297 primary = igt_output_get_plane(output, 0);
299 create_fb_for_mode__panning(data, mode, &primary_fb);
300 igt_plane_set_fb(primary, &primary_fb);
302 if (flags & TEST_PANNING_TOP_LEFT)
303 igt_plane_set_panning(primary, 0, 0);
305 igt_plane_set_panning(primary, mode->hdisplay, mode->vdisplay);
307 igt_plane_set_position(primary, 0, 0);
309 igt_display_commit(&data->display);
311 igt_pipe_crc_collect_crc(data->pipe_crc, &crc);
313 if (flags & TEST_PANNING_TOP_LEFT)
314 igt_assert(igt_crc_equal(&test.red_crc, &crc));
316 igt_assert(igt_crc_equal(&test.blue_crc, &crc));
318 igt_plane_set_fb(primary, NULL);
320 /* reset states to neutral values, assumed by other tests */
321 igt_output_set_pipe(output, PIPE_ANY);
322 igt_plane_set_panning(primary, 0, 0);
328 test_plane_panning(data_t *data, enum pipe pipe, enum igt_plane plane,
331 igt_output_t *output;
333 igt_skip_on(pipe >= data->display.n_pipes);
334 igt_skip_on(plane >= data->display.pipes[pipe].n_planes);
336 for_each_connected_output(&data->display, output)
337 test_plane_panning_with_output(data, pipe, plane, output,
342 run_tests_for_pipe_plane(data_t *data, enum pipe pipe, enum igt_plane plane)
344 igt_subtest_f("plane-position-covered-pipe-%c-plane-%d",
345 pipe_name(pipe), plane)
346 test_plane_position(data, pipe, plane,
347 TEST_POSITION_FULLY_COVERED);
349 igt_subtest_f("plane-position-hole-pipe-%c-plane-%d",
350 pipe_name(pipe), plane)
351 test_plane_position(data, pipe, plane, 0);
353 igt_subtest_f("plane-panning-top-left-pipe-%c-plane-%d",
354 pipe_name(pipe), plane)
355 test_plane_panning(data, pipe, plane, TEST_PANNING_TOP_LEFT);
357 igt_subtest_f("plane-panning-bottom-right-pipe-%c-plane-%d",
358 pipe_name(pipe), plane)
359 test_plane_panning(data, pipe, plane,
360 TEST_PANNING_BOTTOM_RIGHT);
365 run_tests_for_pipe(data_t *data, enum pipe pipe)
369 for (plane = 1; plane < IGT_MAX_PLANES; plane++)
370 run_tests_for_pipe_plane(data, pipe, plane);
378 igt_skip_on_simulation();
381 data.drm_fd = drm_open_any();
383 igt_set_vt_graphics_mode();
385 igt_require_pipe_crc();
386 igt_display_init(&data.display, data.drm_fd);
389 for (int pipe = 0; pipe < 3; pipe++)
390 run_tests_for_pipe(&data, pipe);
393 igt_display_fini(&data.display);