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;
73 primary = igt_output_get_plane(output, 0);
75 mode = igt_output_get_mode(output);
76 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
79 fb_color->red, fb_color->green, fb_color->blue,
81 igt_plane_set_fb(primary, &fb);
83 igt_display_commit(&data->display);
85 igt_pipe_crc_collect_crc(data->pipe_crc, crc);
87 igt_plane_set_fb(primary, NULL);
88 igt_display_commit(&data->display);
90 igt_remove_fb(data->drm_fd, &fb);
94 * Plane position test.
95 * - We start by grabbing a reference CRC of a full green fb being scanned
96 * out on the primary plane
97 * - Then we scannout 2 planes:
98 * - the primary plane uses a green fb with a black rectangle
99 * - a plane, on top of the primary plane, with a green fb that is set-up
100 * to cover the black rectangle of the primary plane fb
101 * The resulting CRC should be identical to the reference CRC
106 igt_crc_t reference_crc;
110 * create a green fb with a black rectangle at (rect_x,rect_y) and of size
114 create_fb_for_mode__position(data_t *data, drmModeModeInfo *mode,
115 double rect_x, double rect_y,
116 double rect_w, double rect_h,
117 struct igt_fb *fb /* out */)
122 fb_id = igt_create_fb(data->drm_fd,
123 mode->hdisplay, mode->vdisplay,
129 cr = igt_get_cairo_ctx(data->drm_fd, fb);
130 igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
132 igt_paint_color(cr, rect_x, rect_y, rect_w, rect_h, 0.0, 0.0, 0.0);
133 igt_assert(cairo_status(cr) == 0);
138 TEST_POSITION_FULLY_COVERED = 1 << 0,
142 test_plane_position_with_output(data_t *data,
144 enum igt_plane plane,
145 igt_output_t *output,
148 test_position_t test = { .data = data };
149 igt_plane_t *primary, *sprite;
150 struct igt_fb primary_fb, sprite_fb;
151 drmModeModeInfo *mode;
154 igt_info("Testing connector %s using pipe %c plane %d\n",
155 igt_output_name(output), pipe_name(pipe), plane);
157 test_init(data, pipe);
159 test_grab_crc(data, output, &green, &test.reference_crc);
161 igt_output_set_pipe(output, pipe);
163 mode = igt_output_get_mode(output);
164 primary = igt_output_get_plane(output, 0);
165 sprite = igt_output_get_plane(output, plane);
167 create_fb_for_mode__position(data, mode, 100, 100, 64, 64,
169 igt_plane_set_fb(primary, &primary_fb);
171 igt_create_color_fb(data->drm_fd,
172 64, 64, /* width, height */
177 igt_plane_set_fb(sprite, &sprite_fb);
179 if (flags & TEST_POSITION_FULLY_COVERED)
180 igt_plane_set_position(sprite, 100, 100);
182 igt_plane_set_position(sprite, 132, 132);
184 igt_display_commit(&data->display);
186 igt_pipe_crc_collect_crc(data->pipe_crc, &crc);
188 if (flags & TEST_POSITION_FULLY_COVERED)
189 igt_assert(igt_crc_equal(&test.reference_crc, &crc));
191 igt_assert(!igt_crc_equal(&test.reference_crc, &crc));
193 igt_plane_set_fb(primary, NULL);
194 igt_plane_set_fb(sprite, NULL);
196 /* reset the constraint on the pipe */
197 igt_output_set_pipe(output, PIPE_ANY);
203 test_plane_position(data_t *data, enum pipe pipe, enum igt_plane plane,
206 igt_output_t *output;
208 igt_skip_on(pipe >= data->display.n_pipes);
209 igt_skip_on(plane >= data->display.pipes[pipe].n_planes);
211 for_each_connected_output(&data->display, output)
212 test_plane_position_with_output(data, pipe, plane, output,
217 * Plane panning test.
218 * - We start by grabbing reference CRCs of a full red and a full blue fb
219 * being scanned out on the primary plane
220 * - Then we create a big fb, sized (2 * hdisplay, 2 * vdisplay) and:
221 * - fill the top left quarter with red
222 * - fill the bottom right quarter with blue
223 * - The TEST_PANNING_TOP_LEFT test makes sure that with panning at (0, 0)
224 * we do get the same CRC than the full red fb.
225 * - The TEST_PANNING_BOTTOM_RIGHT test makes sure that with panning at
226 * (vdisplay, hdisplay) we do get the same CRC than the full blue fb.
230 igt_crc_t red_crc, blue_crc;
234 create_fb_for_mode__panning(data_t *data, drmModeModeInfo *mode,
235 struct igt_fb *fb /* out */)
240 fb_id = igt_create_fb(data->drm_fd,
241 mode->hdisplay * 2, mode->vdisplay * 2,
247 cr = igt_get_cairo_ctx(data->drm_fd, fb);
249 igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
253 mode->hdisplay, mode->vdisplay,
254 mode->hdisplay, mode->vdisplay,
257 igt_assert(cairo_status(cr) == 0);
262 TEST_PANNING_TOP_LEFT = 1 << 0,
263 TEST_PANNING_BOTTOM_RIGHT = 1 << 1,
267 test_plane_panning_with_output(data_t *data,
269 enum igt_plane plane,
270 igt_output_t *output,
273 test_panning_t test = { .data = data };
274 igt_plane_t *primary;
275 struct igt_fb primary_fb;
276 drmModeModeInfo *mode;
279 fprintf(stdout, "Testing connector %s using pipe %c plane %d\n",
280 igt_output_name(output), pipe_name(pipe), plane);
282 test_init(data, pipe);
284 test_grab_crc(data, output, &red, &test.red_crc);
285 test_grab_crc(data, output, &blue, &test.blue_crc);
287 igt_output_set_pipe(output, pipe);
289 mode = igt_output_get_mode(output);
290 primary = igt_output_get_plane(output, 0);
292 create_fb_for_mode__panning(data, mode, &primary_fb);
293 igt_plane_set_fb(primary, &primary_fb);
295 if (flags & TEST_PANNING_TOP_LEFT)
296 igt_plane_set_panning(primary, 0, 0);
298 igt_plane_set_panning(primary, mode->hdisplay, mode->vdisplay);
300 igt_plane_set_position(primary, 0, 0);
302 igt_display_commit(&data->display);
304 igt_pipe_crc_collect_crc(data->pipe_crc, &crc);
306 if (flags & TEST_PANNING_TOP_LEFT)
307 igt_assert(igt_crc_equal(&test.red_crc, &crc));
309 igt_assert(igt_crc_equal(&test.blue_crc, &crc));
311 igt_plane_set_fb(primary, NULL);
313 /* reset states to neutral values, assumed by other tests */
314 igt_output_set_pipe(output, PIPE_ANY);
315 igt_plane_set_panning(primary, 0, 0);
321 test_plane_panning(data_t *data, enum pipe pipe, enum igt_plane plane,
324 igt_output_t *output;
326 igt_skip_on(pipe >= data->display.n_pipes);
327 igt_skip_on(plane >= data->display.pipes[pipe].n_planes);
329 for_each_connected_output(&data->display, output)
330 test_plane_panning_with_output(data, pipe, plane, output,
335 run_tests_for_pipe_plane(data_t *data, enum pipe pipe, enum igt_plane plane)
337 igt_subtest_f("plane-position-covered-pipe-%c-plane-%d",
338 pipe_name(pipe), plane)
339 test_plane_position(data, pipe, plane,
340 TEST_POSITION_FULLY_COVERED);
342 igt_subtest_f("plane-position-hole-pipe-%c-plane-%d",
343 pipe_name(pipe), plane)
344 test_plane_position(data, pipe, plane, 0);
346 igt_subtest_f("plane-panning-top-left-pipe-%c-plane-%d",
347 pipe_name(pipe), plane)
348 test_plane_panning(data, pipe, plane, TEST_PANNING_TOP_LEFT);
350 igt_subtest_f("plane-panning-bottom-right-pipe-%c-plane-%d",
351 pipe_name(pipe), plane)
352 test_plane_panning(data, pipe, plane,
353 TEST_PANNING_BOTTOM_RIGHT);
358 run_tests_for_pipe(data_t *data, enum pipe pipe)
362 for (plane = 1; plane < IGT_MAX_PLANES; plane++)
363 run_tests_for_pipe_plane(data, pipe, plane);
371 igt_skip_on_simulation();
374 data.drm_fd = drm_open_any();
376 igt_set_vt_graphics_mode();
378 igt_require_pipe_crc();
379 igt_display_init(&data.display, data.drm_fd);
382 for (int pipe = 0; pipe < 3; pipe++)
383 run_tests_for_pipe(&data, pipe);
386 igt_display_fini(&data.display);