blob: 5f7bfc0587925b0d0a6135cce131b2b567d7d1cc [file] [log] [blame]
Damien Lespiau0d5de662014-02-06 21:20:35 +00001/*
2 * Copyright © 2014 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 * Damien Lespiau <damien.lespiau@intel.com>
25 */
26
27#include <errno.h>
28#include <stdbool.h>
29#include <stdio.h>
30#include <string.h>
31
Damien Lespiau0d5de662014-02-06 21:20:35 +000032#include "drmtest.h"
33#include "igt_debugfs.h"
34#include "igt_kms.h"
35
36typedef struct {
Damien Lespiaude538cf2014-07-07 13:30:41 +010037 float red;
38 float green;
39 float blue;
40} color_t;
41
42typedef struct {
Damien Lespiau0d5de662014-02-06 21:20:35 +000043 int drm_fd;
Damien Lespiau0d5de662014-02-06 21:20:35 +000044 igt_display_t display;
Damien Lespiaude538cf2014-07-07 13:30:41 +010045 igt_pipe_crc_t *pipe_crc;
Damien Lespiau0d5de662014-02-06 21:20:35 +000046} data_t;
47
Yi Sunb5333b42014-05-23 08:28:47 +080048static color_t red = { 1.0f, 0.0f, 0.0f };
Damien Lespiaude538cf2014-07-07 13:30:41 +010049static color_t green = { 0.0f, 1.0f, 0.0f };
Yi Sunb5333b42014-05-23 08:28:47 +080050static color_t blue = { 0.0f, 0.0f, 1.0f };
Damien Lespiaude538cf2014-07-07 13:30:41 +010051
52/*
53 * Common code across all tests, acting on data_t
54 */
55static void test_init(data_t *data, enum pipe pipe)
56{
57 data->pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
58}
59
60static void test_fini(data_t *data)
61{
62 igt_pipe_crc_free(data->pipe_crc);
63}
64
65static void
66test_grab_crc(data_t *data, igt_output_t *output, color_t *fb_color,
67 igt_crc_t *crc /* out */)
68{
69 struct igt_fb fb;
70 drmModeModeInfo *mode;
71 igt_plane_t *primary;
Damien Lespiau8d60b822014-07-07 14:41:15 +010072 char *crc_str;
Damien Lespiaude538cf2014-07-07 13:30:41 +010073
74 primary = igt_output_get_plane(output, 0);
75
76 mode = igt_output_get_mode(output);
77 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
78 DRM_FORMAT_XRGB8888,
79 false, /* tiled */
80 fb_color->red, fb_color->green, fb_color->blue,
81 &fb);
82 igt_plane_set_fb(primary, &fb);
83
84 igt_display_commit(&data->display);
85
86 igt_pipe_crc_collect_crc(data->pipe_crc, crc);
87
88 igt_plane_set_fb(primary, NULL);
89 igt_display_commit(&data->display);
90
91 igt_remove_fb(data->drm_fd, &fb);
Damien Lespiau8d60b822014-07-07 14:41:15 +010092
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);
96 free(crc_str);
Damien Lespiaude538cf2014-07-07 13:30:41 +010097}
98
Damien Lespiau0d5de662014-02-06 21:20:35 +000099/*
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
108 */
109
110typedef struct {
111 data_t *data;
Damien Lespiau0d5de662014-02-06 21:20:35 +0000112 igt_crc_t reference_crc;
113} test_position_t;
114
115/*
116 * create a green fb with a black rectangle at (rect_x,rect_y) and of size
117 * (rect_w,rect_h)
118 */
119static void
120create_fb_for_mode__position(data_t *data, drmModeModeInfo *mode,
121 double rect_x, double rect_y,
122 double rect_w, double rect_h,
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100123 struct igt_fb *fb /* out */)
Damien Lespiau0d5de662014-02-06 21:20:35 +0000124{
125 unsigned int fb_id;
126 cairo_t *cr;
127
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100128 fb_id = igt_create_fb(data->drm_fd,
Damien Lespiau0d5de662014-02-06 21:20:35 +0000129 mode->hdisplay, mode->vdisplay,
Daniel Vetter70182162014-03-23 16:36:40 +0100130 DRM_FORMAT_XRGB8888,
Damien Lespiau0d5de662014-02-06 21:20:35 +0000131 false /* tiling */,
132 fb);
133 igt_assert(fb_id);
134
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100135 cr = igt_get_cairo_ctx(data->drm_fd, fb);
136 igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
Damien Lespiau0d5de662014-02-06 21:20:35 +0000137 0.0, 1.0, 0.0);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100138 igt_paint_color(cr, rect_x, rect_y, rect_w, rect_h, 0.0, 0.0, 0.0);
Damien Lespiau0d5de662014-02-06 21:20:35 +0000139 igt_assert(cairo_status(cr) == 0);
140 cairo_destroy(cr);
141}
142
Damien Lespiau0d5de662014-02-06 21:20:35 +0000143enum {
144 TEST_POSITION_FULLY_COVERED = 1 << 0,
145};
146
147static void
148test_plane_position_with_output(data_t *data,
149 enum pipe pipe,
150 enum igt_plane plane,
151 igt_output_t *output,
152 unsigned int flags)
153{
154 test_position_t test = { .data = data };
155 igt_plane_t *primary, *sprite;
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100156 struct igt_fb primary_fb, sprite_fb;
Damien Lespiau0d5de662014-02-06 21:20:35 +0000157 drmModeModeInfo *mode;
158 igt_crc_t crc;
159
Daniel Vettere624fa82014-05-14 00:36:04 +0200160 igt_info("Testing connector %s using pipe %c plane %d\n",
161 igt_output_name(output), pipe_name(pipe), plane);
Damien Lespiau0d5de662014-02-06 21:20:35 +0000162
Damien Lespiaude538cf2014-07-07 13:30:41 +0100163 test_init(data, pipe);
164
165 test_grab_crc(data, output, &green, &test.reference_crc);
166
167 igt_output_set_pipe(output, pipe);
Damien Lespiau0d5de662014-02-06 21:20:35 +0000168
169 mode = igt_output_get_mode(output);
Damien Lespiau2043e6b2014-02-11 17:45:48 +0000170 primary = igt_output_get_plane(output, 0);
171 sprite = igt_output_get_plane(output, plane);
Damien Lespiau0d5de662014-02-06 21:20:35 +0000172
173 create_fb_for_mode__position(data, mode, 100, 100, 64, 64,
174 &primary_fb);
175 igt_plane_set_fb(primary, &primary_fb);
176
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100177 igt_create_color_fb(data->drm_fd,
Damien Lespiau0d5de662014-02-06 21:20:35 +0000178 64, 64, /* width, height */
179 DRM_FORMAT_XRGB8888,
180 false, /* tiled */
181 0.0, 1.0, 0.0,
182 &sprite_fb);
183 igt_plane_set_fb(sprite, &sprite_fb);
184
185 if (flags & TEST_POSITION_FULLY_COVERED)
186 igt_plane_set_position(sprite, 100, 100);
187 else
188 igt_plane_set_position(sprite, 132, 132);
189
190 igt_display_commit(&data->display);
191
Damien Lespiaude538cf2014-07-07 13:30:41 +0100192 igt_pipe_crc_collect_crc(data->pipe_crc, &crc);
Damien Lespiau0d5de662014-02-06 21:20:35 +0000193
194 if (flags & TEST_POSITION_FULLY_COVERED)
195 igt_assert(igt_crc_equal(&test.reference_crc, &crc));
196 else
197 igt_assert(!igt_crc_equal(&test.reference_crc, &crc));
198
199 igt_plane_set_fb(primary, NULL);
200 igt_plane_set_fb(sprite, NULL);
201
Damien Lespiaude538cf2014-07-07 13:30:41 +0100202 /* reset the constraint on the pipe */
203 igt_output_set_pipe(output, PIPE_ANY);
204
205 test_fini(data);
Damien Lespiau0d5de662014-02-06 21:20:35 +0000206}
207
208static void
209test_plane_position(data_t *data, enum pipe pipe, enum igt_plane plane,
210 unsigned int flags)
211{
212 igt_output_t *output;
213
214 igt_skip_on(pipe >= data->display.n_pipes);
215 igt_skip_on(plane >= data->display.pipes[pipe].n_planes);
216
217 for_each_connected_output(&data->display, output)
218 test_plane_position_with_output(data, pipe, plane, output,
219 flags);
220}
221
Yi Sunb5333b42014-05-23 08:28:47 +0800222/*
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.
233 */
234typedef struct {
235 data_t *data;
236 igt_crc_t red_crc, blue_crc;
237} test_panning_t;
238
239static void
240create_fb_for_mode__panning(data_t *data, drmModeModeInfo *mode,
241 struct igt_fb *fb /* out */)
242{
243 unsigned int fb_id;
244 cairo_t *cr;
245
246 fb_id = igt_create_fb(data->drm_fd,
247 mode->hdisplay * 2, mode->vdisplay * 2,
248 DRM_FORMAT_XRGB8888,
249 false /* tiling */,
250 fb);
251 igt_assert(fb_id);
252
253 cr = igt_get_cairo_ctx(data->drm_fd, fb);
254
255 igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
256 1.0, 0.0, 0.0);
257
258 igt_paint_color(cr,
259 mode->hdisplay, mode->vdisplay,
260 mode->hdisplay, mode->vdisplay,
261 0.0, 0.0, 1.0);
262
263 igt_assert(cairo_status(cr) == 0);
264 cairo_destroy(cr);
265}
266
267enum {
268 TEST_PANNING_TOP_LEFT = 1 << 0,
269 TEST_PANNING_BOTTOM_RIGHT = 1 << 1,
270};
271
272static void
273test_plane_panning_with_output(data_t *data,
274 enum pipe pipe,
275 enum igt_plane plane,
276 igt_output_t *output,
277 unsigned int flags)
278{
279 test_panning_t test = { .data = data };
280 igt_plane_t *primary;
281 struct igt_fb primary_fb;
282 drmModeModeInfo *mode;
283 igt_crc_t crc;
284
285 fprintf(stdout, "Testing connector %s using pipe %c plane %d\n",
286 igt_output_name(output), pipe_name(pipe), plane);
287
288 test_init(data, pipe);
289
290 test_grab_crc(data, output, &red, &test.red_crc);
291 test_grab_crc(data, output, &blue, &test.blue_crc);
292
293 igt_output_set_pipe(output, pipe);
294
295 mode = igt_output_get_mode(output);
296 primary = igt_output_get_plane(output, 0);
297
298 create_fb_for_mode__panning(data, mode, &primary_fb);
299 igt_plane_set_fb(primary, &primary_fb);
300
301 if (flags & TEST_PANNING_TOP_LEFT)
302 igt_plane_set_panning(primary, 0, 0);
303 else
304 igt_plane_set_panning(primary, mode->hdisplay, mode->vdisplay);
305
306 igt_plane_set_position(primary, 0, 0);
307
308 igt_display_commit(&data->display);
309
310 igt_pipe_crc_collect_crc(data->pipe_crc, &crc);
311
312 if (flags & TEST_PANNING_TOP_LEFT)
313 igt_assert(igt_crc_equal(&test.red_crc, &crc));
314 else
315 igt_assert(igt_crc_equal(&test.blue_crc, &crc));
316
317 igt_plane_set_fb(primary, NULL);
318
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);
322
323 test_fini(data);
324}
325
326static void
327test_plane_panning(data_t *data, enum pipe pipe, enum igt_plane plane,
328 unsigned int flags)
329{
330 igt_output_t *output;
331
332 igt_skip_on(pipe >= data->display.n_pipes);
333 igt_skip_on(plane >= data->display.pipes[pipe].n_planes);
334
335 for_each_connected_output(&data->display, output)
336 test_plane_panning_with_output(data, pipe, plane, output,
337 flags);
338}
339
Damien Lespiau0d5de662014-02-06 21:20:35 +0000340static void
341run_tests_for_pipe_plane(data_t *data, enum pipe pipe, enum igt_plane plane)
342{
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);
347
348 igt_subtest_f("plane-position-hole-pipe-%c-plane-%d",
349 pipe_name(pipe), plane)
350 test_plane_position(data, pipe, plane, 0);
Yi Sunb5333b42014-05-23 08:28:47 +0800351
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);
355
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);
360
Damien Lespiau0d5de662014-02-06 21:20:35 +0000361}
362
363static void
364run_tests_for_pipe(data_t *data, enum pipe pipe)
365{
366 int plane;
367
368 for (plane = 1; plane < IGT_MAX_PLANES; plane++)
369 run_tests_for_pipe_plane(data, pipe, plane);
370}
371
372static data_t data;
373
374igt_main
375{
376
377 igt_skip_on_simulation();
378
379 igt_fixture {
380 data.drm_fd = drm_open_any();
381
382 igt_set_vt_graphics_mode();
383
Daniel Vetterf2e5dc02014-03-16 15:09:22 +0100384 igt_require_pipe_crc();
Damien Lespiau0d5de662014-02-06 21:20:35 +0000385 igt_display_init(&data.display, data.drm_fd);
386 }
387
388 for (int pipe = 0; pipe < 3; pipe++)
389 run_tests_for_pipe(&data, pipe);
390
391 igt_fixture {
392 igt_display_fini(&data.display);
393 }
394}