blob: 42af2fb88f0774f9750486c2751280c67ce42249 [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
Damien Lespiauc5b96152014-07-09 11:05:06 +010066test_grab_crc(data_t *data, igt_output_t *output, enum pipe pipe,
67 color_t *fb_color, igt_crc_t *crc /* out */)
Damien Lespiaude538cf2014-07-07 13:30:41 +010068{
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
Damien Lespiauc5b96152014-07-09 11:05:06 +010074 igt_output_set_pipe(output, pipe);
75
Damien Lespiaude538cf2014-07-07 13:30:41 +010076 primary = igt_output_get_plane(output, 0);
77
78 mode = igt_output_get_mode(output);
79 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
80 DRM_FORMAT_XRGB8888,
81 false, /* tiled */
82 fb_color->red, fb_color->green, fb_color->blue,
83 &fb);
84 igt_plane_set_fb(primary, &fb);
85
86 igt_display_commit(&data->display);
87
88 igt_pipe_crc_collect_crc(data->pipe_crc, crc);
89
90 igt_plane_set_fb(primary, NULL);
91 igt_display_commit(&data->display);
92
93 igt_remove_fb(data->drm_fd, &fb);
Damien Lespiau8d60b822014-07-07 14:41:15 +010094
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);
98 free(crc_str);
Damien Lespiaude538cf2014-07-07 13:30:41 +010099}
100
Damien Lespiau0d5de662014-02-06 21:20:35 +0000101/*
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
110 */
111
112typedef struct {
113 data_t *data;
Damien Lespiau0d5de662014-02-06 21:20:35 +0000114 igt_crc_t reference_crc;
115} test_position_t;
116
117/*
118 * create a green fb with a black rectangle at (rect_x,rect_y) and of size
119 * (rect_w,rect_h)
120 */
121static void
122create_fb_for_mode__position(data_t *data, drmModeModeInfo *mode,
123 double rect_x, double rect_y,
124 double rect_w, double rect_h,
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100125 struct igt_fb *fb /* out */)
Damien Lespiau0d5de662014-02-06 21:20:35 +0000126{
127 unsigned int fb_id;
128 cairo_t *cr;
129
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100130 fb_id = igt_create_fb(data->drm_fd,
Damien Lespiau0d5de662014-02-06 21:20:35 +0000131 mode->hdisplay, mode->vdisplay,
Daniel Vetter70182162014-03-23 16:36:40 +0100132 DRM_FORMAT_XRGB8888,
Damien Lespiau0d5de662014-02-06 21:20:35 +0000133 false /* tiling */,
134 fb);
135 igt_assert(fb_id);
136
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100137 cr = igt_get_cairo_ctx(data->drm_fd, fb);
138 igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
Damien Lespiau0d5de662014-02-06 21:20:35 +0000139 0.0, 1.0, 0.0);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100140 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 +0000141 igt_assert(cairo_status(cr) == 0);
142 cairo_destroy(cr);
143}
144
Damien Lespiau0d5de662014-02-06 21:20:35 +0000145enum {
146 TEST_POSITION_FULLY_COVERED = 1 << 0,
147};
148
149static void
150test_plane_position_with_output(data_t *data,
151 enum pipe pipe,
152 enum igt_plane plane,
153 igt_output_t *output,
154 unsigned int flags)
155{
156 test_position_t test = { .data = data };
157 igt_plane_t *primary, *sprite;
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100158 struct igt_fb primary_fb, sprite_fb;
Damien Lespiau0d5de662014-02-06 21:20:35 +0000159 drmModeModeInfo *mode;
160 igt_crc_t crc;
161
Daniel Vetterdd8fba42014-08-12 11:00:37 +0200162 igt_info("Testing connector %s using pipe %s plane %d\n",
163 igt_output_name(output), kmstest_pipe_name(pipe), plane);
Damien Lespiau0d5de662014-02-06 21:20:35 +0000164
Damien Lespiaude538cf2014-07-07 13:30:41 +0100165 test_init(data, pipe);
166
Damien Lespiauc5b96152014-07-09 11:05:06 +0100167 test_grab_crc(data, output, pipe, &green, &test.reference_crc);
Damien Lespiaude538cf2014-07-07 13:30:41 +0100168
169 igt_output_set_pipe(output, pipe);
Damien Lespiau0d5de662014-02-06 21:20:35 +0000170
171 mode = igt_output_get_mode(output);
Damien Lespiau2043e6b2014-02-11 17:45:48 +0000172 primary = igt_output_get_plane(output, 0);
173 sprite = igt_output_get_plane(output, plane);
Damien Lespiau0d5de662014-02-06 21:20:35 +0000174
175 create_fb_for_mode__position(data, mode, 100, 100, 64, 64,
176 &primary_fb);
177 igt_plane_set_fb(primary, &primary_fb);
178
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100179 igt_create_color_fb(data->drm_fd,
Damien Lespiau0d5de662014-02-06 21:20:35 +0000180 64, 64, /* width, height */
181 DRM_FORMAT_XRGB8888,
182 false, /* tiled */
183 0.0, 1.0, 0.0,
184 &sprite_fb);
185 igt_plane_set_fb(sprite, &sprite_fb);
186
187 if (flags & TEST_POSITION_FULLY_COVERED)
188 igt_plane_set_position(sprite, 100, 100);
189 else
190 igt_plane_set_position(sprite, 132, 132);
191
192 igt_display_commit(&data->display);
193
Damien Lespiaude538cf2014-07-07 13:30:41 +0100194 igt_pipe_crc_collect_crc(data->pipe_crc, &crc);
Damien Lespiau0d5de662014-02-06 21:20:35 +0000195
196 if (flags & TEST_POSITION_FULLY_COVERED)
197 igt_assert(igt_crc_equal(&test.reference_crc, &crc));
198 else
199 igt_assert(!igt_crc_equal(&test.reference_crc, &crc));
200
201 igt_plane_set_fb(primary, NULL);
202 igt_plane_set_fb(sprite, NULL);
203
Damien Lespiaude538cf2014-07-07 13:30:41 +0100204 /* reset the constraint on the pipe */
205 igt_output_set_pipe(output, PIPE_ANY);
206
207 test_fini(data);
Damien Lespiau0d5de662014-02-06 21:20:35 +0000208}
209
210static void
211test_plane_position(data_t *data, enum pipe pipe, enum igt_plane plane,
212 unsigned int flags)
213{
214 igt_output_t *output;
215
216 igt_skip_on(pipe >= data->display.n_pipes);
217 igt_skip_on(plane >= data->display.pipes[pipe].n_planes);
218
219 for_each_connected_output(&data->display, output)
220 test_plane_position_with_output(data, pipe, plane, output,
221 flags);
222}
223
Yi Sunb5333b42014-05-23 08:28:47 +0800224/*
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.
235 */
236typedef struct {
237 data_t *data;
238 igt_crc_t red_crc, blue_crc;
239} test_panning_t;
240
241static void
242create_fb_for_mode__panning(data_t *data, drmModeModeInfo *mode,
243 struct igt_fb *fb /* out */)
244{
245 unsigned int fb_id;
246 cairo_t *cr;
247
248 fb_id = igt_create_fb(data->drm_fd,
249 mode->hdisplay * 2, mode->vdisplay * 2,
250 DRM_FORMAT_XRGB8888,
251 false /* tiling */,
252 fb);
253 igt_assert(fb_id);
254
255 cr = igt_get_cairo_ctx(data->drm_fd, fb);
256
257 igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
258 1.0, 0.0, 0.0);
259
260 igt_paint_color(cr,
261 mode->hdisplay, mode->vdisplay,
262 mode->hdisplay, mode->vdisplay,
263 0.0, 0.0, 1.0);
264
265 igt_assert(cairo_status(cr) == 0);
266 cairo_destroy(cr);
267}
268
269enum {
270 TEST_PANNING_TOP_LEFT = 1 << 0,
271 TEST_PANNING_BOTTOM_RIGHT = 1 << 1,
272};
273
274static void
275test_plane_panning_with_output(data_t *data,
276 enum pipe pipe,
277 enum igt_plane plane,
278 igt_output_t *output,
279 unsigned int flags)
280{
281 test_panning_t test = { .data = data };
282 igt_plane_t *primary;
283 struct igt_fb primary_fb;
284 drmModeModeInfo *mode;
285 igt_crc_t crc;
286
Daniel Vetterdd8fba42014-08-12 11:00:37 +0200287 igt_info("Testing connector %s using pipe %s plane %d\n",
288 igt_output_name(output), kmstest_pipe_name(pipe), plane);
Yi Sunb5333b42014-05-23 08:28:47 +0800289
290 test_init(data, pipe);
291
Damien Lespiauc5b96152014-07-09 11:05:06 +0100292 test_grab_crc(data, output, pipe, &red, &test.red_crc);
293 test_grab_crc(data, output, pipe, &blue, &test.blue_crc);
Yi Sunb5333b42014-05-23 08:28:47 +0800294
295 igt_output_set_pipe(output, pipe);
296
297 mode = igt_output_get_mode(output);
298 primary = igt_output_get_plane(output, 0);
299
300 create_fb_for_mode__panning(data, mode, &primary_fb);
301 igt_plane_set_fb(primary, &primary_fb);
302
303 if (flags & TEST_PANNING_TOP_LEFT)
304 igt_plane_set_panning(primary, 0, 0);
305 else
306 igt_plane_set_panning(primary, mode->hdisplay, mode->vdisplay);
307
308 igt_plane_set_position(primary, 0, 0);
309
310 igt_display_commit(&data->display);
311
312 igt_pipe_crc_collect_crc(data->pipe_crc, &crc);
313
314 if (flags & TEST_PANNING_TOP_LEFT)
315 igt_assert(igt_crc_equal(&test.red_crc, &crc));
316 else
317 igt_assert(igt_crc_equal(&test.blue_crc, &crc));
318
319 igt_plane_set_fb(primary, NULL);
320
321 /* reset states to neutral values, assumed by other tests */
322 igt_output_set_pipe(output, PIPE_ANY);
323 igt_plane_set_panning(primary, 0, 0);
324
325 test_fini(data);
326}
327
328static void
329test_plane_panning(data_t *data, enum pipe pipe, enum igt_plane plane,
330 unsigned int flags)
331{
332 igt_output_t *output;
333
334 igt_skip_on(pipe >= data->display.n_pipes);
335 igt_skip_on(plane >= data->display.pipes[pipe].n_planes);
336
337 for_each_connected_output(&data->display, output)
338 test_plane_panning_with_output(data, pipe, plane, output,
339 flags);
340}
341
Damien Lespiau0d5de662014-02-06 21:20:35 +0000342static void
343run_tests_for_pipe_plane(data_t *data, enum pipe pipe, enum igt_plane plane)
344{
Daniel Vetterdd8fba42014-08-12 11:00:37 +0200345 igt_subtest_f("plane-position-covered-pipe-%s-plane-%d",
346 kmstest_pipe_name(pipe), plane)
Damien Lespiau0d5de662014-02-06 21:20:35 +0000347 test_plane_position(data, pipe, plane,
348 TEST_POSITION_FULLY_COVERED);
349
Daniel Vetterdd8fba42014-08-12 11:00:37 +0200350 igt_subtest_f("plane-position-hole-pipe-%s-plane-%d",
351 kmstest_pipe_name(pipe), plane)
Damien Lespiau0d5de662014-02-06 21:20:35 +0000352 test_plane_position(data, pipe, plane, 0);
Yi Sunb5333b42014-05-23 08:28:47 +0800353
Daniel Vetterdd8fba42014-08-12 11:00:37 +0200354 igt_subtest_f("plane-panning-top-left-pipe-%s-plane-%d",
355 kmstest_pipe_name(pipe), plane)
Yi Sunb5333b42014-05-23 08:28:47 +0800356 test_plane_panning(data, pipe, plane, TEST_PANNING_TOP_LEFT);
357
Daniel Vetterdd8fba42014-08-12 11:00:37 +0200358 igt_subtest_f("plane-panning-bottom-right-pipe-%s-plane-%d",
359 kmstest_pipe_name(pipe), plane)
Yi Sunb5333b42014-05-23 08:28:47 +0800360 test_plane_panning(data, pipe, plane,
361 TEST_PANNING_BOTTOM_RIGHT);
362
Damien Lespiau0d5de662014-02-06 21:20:35 +0000363}
364
365static void
366run_tests_for_pipe(data_t *data, enum pipe pipe)
367{
368 int plane;
369
370 for (plane = 1; plane < IGT_MAX_PLANES; plane++)
371 run_tests_for_pipe_plane(data, pipe, plane);
372}
373
374static data_t data;
375
376igt_main
377{
378
379 igt_skip_on_simulation();
380
381 igt_fixture {
382 data.drm_fd = drm_open_any();
383
Daniel Vetter33f08842014-08-12 11:23:09 +0200384 kmstest_set_vt_graphics_mode();
Damien Lespiau0d5de662014-02-06 21:20:35 +0000385
Daniel Vetterf2e5dc02014-03-16 15:09:22 +0100386 igt_require_pipe_crc();
Damien Lespiau0d5de662014-02-06 21:20:35 +0000387 igt_display_init(&data.display, data.drm_fd);
388 }
389
390 for (int pipe = 0; pipe < 3; pipe++)
391 run_tests_for_pipe(&data, pipe);
392
393 igt_fixture {
394 igt_display_fini(&data.display);
395 }
396}