1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
|
/*
* Copyright © 2014 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Authors:
* Damien Lespiau <damien.lespiau@intel.com>
*/
#include "igt.h"
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
/*
* Throw away enough lsbs in pixel formats tests
* to get a match despite some differences between
* the software and hardware YCbCr<->RGB conversion
* routines.
*/
#define LUT_MASK 0xf800
typedef struct {
float red;
float green;
float blue;
} color_t;
typedef struct {
int drm_fd;
igt_display_t display;
igt_pipe_crc_t *pipe_crc;
uint32_t crop;
} data_t;
static color_t red = { 1.0f, 0.0f, 0.0f };
static color_t green = { 0.0f, 1.0f, 0.0f };
static color_t blue = { 0.0f, 0.0f, 1.0f };
/*
* Common code across all tests, acting on data_t
*/
static void test_init(data_t *data, enum pipe pipe)
{
data->pipe_crc = igt_pipe_crc_new(data->drm_fd, pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
}
static void test_fini(data_t *data)
{
igt_pipe_crc_free(data->pipe_crc);
}
static void
test_grab_crc(data_t *data, igt_output_t *output, enum pipe pipe,
color_t *fb_color, igt_crc_t *crc /* out */)
{
struct igt_fb fb;
drmModeModeInfo *mode;
igt_plane_t *primary;
char *crc_str;
int ret;
igt_output_set_pipe(output, pipe);
primary = igt_output_get_plane(output, 0);
mode = igt_output_get_mode(output);
igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
DRM_FORMAT_XRGB8888,
LOCAL_DRM_FORMAT_MOD_NONE,
fb_color->red, fb_color->green, fb_color->blue,
&fb);
igt_plane_set_fb(primary, &fb);
ret = igt_display_try_commit2(&data->display, COMMIT_LEGACY);
igt_skip_on(ret != 0);
igt_pipe_crc_collect_crc(data->pipe_crc, crc);
igt_plane_set_fb(primary, NULL);
igt_display_commit(&data->display);
igt_remove_fb(data->drm_fd, &fb);
crc_str = igt_crc_to_string(crc);
igt_debug("CRC for a (%.02f,%.02f,%.02f) fb: %s\n", fb_color->red,
fb_color->green, fb_color->blue, crc_str);
free(crc_str);
}
/*
* Plane position test.
* - We start by grabbing a reference CRC of a full green fb being scanned
* out on the primary plane
* - Then we scannout 2 planes:
* - the primary plane uses a green fb with a black rectangle
* - a plane, on top of the primary plane, with a green fb that is set-up
* to cover the black rectangle of the primary plane fb
* The resulting CRC should be identical to the reference CRC
*/
typedef struct {
data_t *data;
igt_crc_t reference_crc;
} test_position_t;
/*
* create a green fb with a black rectangle at (rect_x,rect_y) and of size
* (rect_w,rect_h)
*/
static void
create_fb_for_mode__position(data_t *data, drmModeModeInfo *mode,
double rect_x, double rect_y,
double rect_w, double rect_h,
struct igt_fb *fb /* out */)
{
unsigned int fb_id;
cairo_t *cr;
fb_id = igt_create_fb(data->drm_fd,
mode->hdisplay, mode->vdisplay,
DRM_FORMAT_XRGB8888,
LOCAL_DRM_FORMAT_MOD_NONE,
fb);
igt_assert(fb_id);
cr = igt_get_cairo_ctx(data->drm_fd, fb);
igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
0.0, 1.0, 0.0);
igt_paint_color(cr, rect_x, rect_y, rect_w, rect_h, 0.0, 0.0, 0.0);
igt_put_cairo_ctx(data->drm_fd, fb, cr);
}
enum {
TEST_POSITION_FULLY_COVERED = 1 << 0,
TEST_DPMS = 1 << 1,
};
static void
test_plane_position_with_output(data_t *data,
enum pipe pipe,
int plane,
igt_output_t *output,
igt_crc_t *reference_crc,
unsigned int flags)
{
igt_plane_t *primary, *sprite;
struct igt_fb primary_fb, sprite_fb;
drmModeModeInfo *mode;
igt_crc_t crc, crc2;
igt_info("Testing connector %s using pipe %s plane %d\n",
igt_output_name(output), kmstest_pipe_name(pipe), plane);
igt_output_set_pipe(output, pipe);
mode = igt_output_get_mode(output);
primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
sprite = igt_output_get_plane(output, plane);
create_fb_for_mode__position(data, mode, 100, 100, 64, 64,
&primary_fb);
igt_plane_set_fb(primary, &primary_fb);
igt_create_color_fb(data->drm_fd,
64, 64, /* width, height */
DRM_FORMAT_XRGB8888,
LOCAL_DRM_FORMAT_MOD_NONE,
0.0, 1.0, 0.0,
&sprite_fb);
igt_plane_set_fb(sprite, &sprite_fb);
if (flags & TEST_POSITION_FULLY_COVERED)
igt_plane_set_position(sprite, 100, 100);
else
igt_plane_set_position(sprite, 132, 132);
igt_display_commit(&data->display);
igt_pipe_crc_collect_crc(data->pipe_crc, &crc);
if (flags & TEST_DPMS) {
kmstest_set_connector_dpms(data->drm_fd,
output->config.connector,
DRM_MODE_DPMS_OFF);
kmstest_set_connector_dpms(data->drm_fd,
output->config.connector,
DRM_MODE_DPMS_ON);
}
igt_pipe_crc_collect_crc(data->pipe_crc, &crc2);
if (flags & TEST_POSITION_FULLY_COVERED)
igt_assert_crc_equal(reference_crc, &crc);
else {
;/* FIXME: missing reference CRCs */
}
igt_assert_crc_equal(&crc, &crc2);
igt_plane_set_fb(primary, NULL);
igt_plane_set_fb(sprite, NULL);
/* reset the constraint on the pipe */
igt_output_set_pipe(output, PIPE_ANY);
}
static void
test_plane_position(data_t *data, enum pipe pipe, unsigned int flags)
{
int n_planes = data->display.pipes[pipe].n_planes;
igt_output_t *output;
igt_crc_t reference_crc;
output = igt_get_single_output_for_pipe(&data->display, pipe);
igt_require(output);
test_init(data, pipe);
test_grab_crc(data, output, pipe, &green, &reference_crc);
for (int plane = 1; plane < n_planes; plane++)
test_plane_position_with_output(data, pipe, plane,
output, &reference_crc,
flags);
test_fini(data);
}
/*
* Plane panning test.
* - We start by grabbing reference CRCs of a full red and a full blue fb
* being scanned out on the primary plane
* - Then we create a big fb, sized (2 * hdisplay, 2 * vdisplay) and:
* - fill the top left quarter with red
* - fill the bottom right quarter with blue
* - The TEST_PANNING_TOP_LEFT test makes sure that with panning at (0, 0)
* we do get the same CRC than the full red fb.
* - The TEST_PANNING_BOTTOM_RIGHT test makes sure that with panning at
* (vdisplay, hdisplay) we do get the same CRC than the full blue fb.
*/
static void
create_fb_for_mode__panning(data_t *data, drmModeModeInfo *mode,
struct igt_fb *fb /* out */)
{
unsigned int fb_id;
cairo_t *cr;
fb_id = igt_create_fb(data->drm_fd,
mode->hdisplay * 2, mode->vdisplay * 2,
DRM_FORMAT_XRGB8888,
LOCAL_DRM_FORMAT_MOD_NONE,
fb);
igt_assert(fb_id);
cr = igt_get_cairo_ctx(data->drm_fd, fb);
igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
1.0, 0.0, 0.0);
igt_paint_color(cr,
mode->hdisplay, mode->vdisplay,
mode->hdisplay, mode->vdisplay,
0.0, 0.0, 1.0);
igt_put_cairo_ctx(data->drm_fd, fb, cr);
}
enum {
TEST_PANNING_TOP_LEFT = 1 << 0,
TEST_PANNING_BOTTOM_RIGHT = 1 << 1,
TEST_SUSPEND_RESUME = 1 << 2,
};
static void
test_plane_panning_with_output(data_t *data,
enum pipe pipe,
int plane,
igt_output_t *output,
igt_crc_t *red_crc, igt_crc_t *blue_crc,
unsigned int flags)
{
igt_plane_t *primary;
struct igt_fb primary_fb;
drmModeModeInfo *mode;
igt_crc_t crc;
igt_info("Testing connector %s using pipe %s plane %d\n",
igt_output_name(output), kmstest_pipe_name(pipe), plane);
igt_output_set_pipe(output, pipe);
mode = igt_output_get_mode(output);
primary = igt_output_get_plane(output, 0);
create_fb_for_mode__panning(data, mode, &primary_fb);
igt_plane_set_fb(primary, &primary_fb);
if (flags & TEST_PANNING_TOP_LEFT)
igt_fb_set_position(&primary_fb, primary, 0, 0);
else
igt_fb_set_position(&primary_fb, primary, mode->hdisplay, mode->vdisplay);
igt_display_commit(&data->display);
if (flags & TEST_SUSPEND_RESUME)
igt_system_suspend_autoresume(SUSPEND_STATE_MEM,
SUSPEND_TEST_NONE);
igt_pipe_crc_collect_crc(data->pipe_crc, &crc);
if (flags & TEST_PANNING_TOP_LEFT)
igt_assert_crc_equal(red_crc, &crc);
else
igt_assert_crc_equal(blue_crc, &crc);
igt_plane_set_fb(primary, NULL);
/* reset states to neutral values, assumed by other tests */
igt_output_set_pipe(output, PIPE_ANY);
igt_fb_set_position(&primary_fb, primary, 0, 0);
}
static void
test_plane_panning(data_t *data, enum pipe pipe, unsigned int flags)
{
int n_planes = data->display.pipes[pipe].n_planes;
igt_output_t *output;
igt_crc_t red_crc;
igt_crc_t blue_crc;
output = igt_get_single_output_for_pipe(&data->display, pipe);
igt_require(output);
test_init(data, pipe);
test_grab_crc(data, output, pipe, &red, &red_crc);
test_grab_crc(data, output, pipe, &blue, &blue_crc);
for (int plane = 1; plane < n_planes; plane++)
test_plane_panning_with_output(data, pipe, plane, output,
&red_crc, &blue_crc, flags);
test_fini(data);
}
static const color_t colors[] = {
{ 1.0f, 0.0f, 0.0f, },
{ 0.0f, 1.0f, 0.0f, },
{ 0.0f, 0.0f, 1.0f, },
{ 1.0f, 1.0f, 1.0f, },
{ 0.0f, 0.0f, 0.0f, },
{ 0.0f, 1.0f, 1.0f, },
{ 1.0f, 0.0f, 1.0f, },
{ 1.0f, 1.0f, 0.0f, },
};
static void set_legacy_lut(data_t *data, enum pipe pipe,
uint16_t mask)
{
igt_pipe_t *pipe_obj = &data->display.pipes[pipe];
drmModeCrtc *crtc;
uint16_t *lut;
int i, lut_size;
crtc = drmModeGetCrtc(data->drm_fd, pipe_obj->crtc_id);
lut_size = crtc->gamma_size;
drmModeFreeCrtc(crtc);
lut = malloc(sizeof(uint16_t) * lut_size);
for (i = 0; i < lut_size; i++)
lut[i] = (i * 0xffff / (lut_size - 1)) & mask;
igt_assert_eq(drmModeCrtcSetGamma(data->drm_fd, pipe_obj->crtc_id,
lut_size, lut, lut, lut), 0);
free(lut);
}
static bool set_c8_legacy_lut(data_t *data, enum pipe pipe,
uint16_t mask)
{
igt_pipe_t *pipe_obj = &data->display.pipes[pipe];
drmModeCrtc *crtc;
uint16_t *r, *g, *b;
int i, lut_size;
crtc = drmModeGetCrtc(data->drm_fd, pipe_obj->crtc_id);
lut_size = crtc->gamma_size;
drmModeFreeCrtc(crtc);
if (lut_size != 256)
return false;
r = malloc(sizeof(uint16_t) * 3 * lut_size);
g = r + lut_size;
b = g + lut_size;
/* igt_fb uses RGB332 for C8 */
for (i = 0; i < lut_size; i++) {
r[i] = (((i & 0xe0) >> 5) * 0xffff / 0x7) & mask;
g[i] = (((i & 0x1c) >> 2) * 0xffff / 0x7) & mask;
b[i] = (((i & 0x03) >> 0) * 0xffff / 0x3) & mask;
}
igt_assert_eq(drmModeCrtcSetGamma(data->drm_fd, pipe_obj->crtc_id,
lut_size, r, g, b), 0);
free(r);
return true;
}
static void test_format_plane_color(data_t *data, enum pipe pipe,
igt_plane_t *plane,
uint32_t format, uint64_t modifier,
int width, int height,
enum igt_color_encoding color_encoding,
enum igt_color_range color_range,
int color, igt_crc_t *crc, struct igt_fb *fb)
{
const color_t *c = &colors[color];
struct igt_fb old_fb = *fb;
cairo_t *cr;
if (data->crop == 0 || format == DRM_FORMAT_XRGB8888) {
igt_create_fb_with_bo_size(data->drm_fd, width, height,
format, modifier, color_encoding,
color_range, fb, 0, 0);
cr = igt_get_cairo_ctx(data->drm_fd, fb);
igt_paint_color(cr, 0, 0, width, height,
c->red, c->green, c->blue);
igt_put_cairo_ctx(data->drm_fd, fb, cr);
} else {
igt_create_fb_with_bo_size(data->drm_fd,
width + data->crop * 2,
height + data->crop * 2,
format, modifier, color_encoding,
color_range, fb, 0, 0);
/*
* paint border in inverted color, then visible area in middle
* with correct color for clamping test
*/
cr = igt_get_cairo_ctx(data->drm_fd, fb);
igt_paint_color(cr, 0, 0,
width + data->crop * 2,
height + data->crop * 2,
1.0f - c->red,
1.0f - c->green,
1.0f - c->blue);
igt_paint_color(cr, data->crop, data->crop,
width, height,
c->red, c->green, c->blue);
igt_put_cairo_ctx(data->drm_fd, fb, cr);
}
igt_plane_set_fb(plane, fb);
/*
* if clamping test. DRM_FORMAT_XRGB8888 is used for reference color.
*/
if (data->crop != 0 && format != DRM_FORMAT_XRGB8888) {
igt_fb_set_position(fb, plane, data->crop, data->crop);
igt_fb_set_size(fb, plane, width, height);
igt_plane_set_size(plane, width, height);
}
igt_display_commit2(&data->display, data->display.is_atomic ? COMMIT_ATOMIC : COMMIT_UNIVERSAL);
igt_pipe_crc_get_current(data->display.drm_fd, data->pipe_crc, crc);
igt_remove_fb(data->drm_fd, &old_fb);
}
static int num_unique_crcs(const igt_crc_t crc[], int num_crc)
{
int num_unique_crc = 0;
for (int i = 0; i < num_crc; i++) {
int j;
for (j = i + 1; j < num_crc; j++) {
if (igt_check_crc_equal(&crc[i], &crc[j]))
break;
}
if (j == num_crc)
num_unique_crc++;
}
return num_unique_crc;
}
static bool test_format_plane_colors(data_t *data, enum pipe pipe,
igt_plane_t *plane,
uint32_t format, uint64_t modifier,
int width, int height,
enum igt_color_encoding encoding,
enum igt_color_range range,
igt_crc_t ref_crc[ARRAY_SIZE(colors)],
struct igt_fb *fb)
{
int crc_mismatch_count = 0;
unsigned int crc_mismatch_mask = 0;
bool result = true;
for (int i = 0; i < ARRAY_SIZE(colors); i++) {
igt_crc_t crc;
test_format_plane_color(data, pipe, plane,
format, modifier,
width, height,
encoding, range,
i, &crc, fb);
if (!igt_check_crc_equal(&crc, &ref_crc[i])) {
crc_mismatch_count++;
crc_mismatch_mask |= (1 << i);
result = false;
}
}
if (crc_mismatch_count)
igt_warn("CRC mismatches with format " IGT_FORMAT_FMT " on %s.%u with %d/%d solid colors tested (0x%X)\n",
IGT_FORMAT_ARGS(format), kmstest_pipe_name(pipe),
plane->index, crc_mismatch_count, (int)ARRAY_SIZE(colors), crc_mismatch_mask);
return result;
}
static bool test_format_plane_rgb(data_t *data, enum pipe pipe,
igt_plane_t *plane,
uint32_t format, uint64_t modifier,
int width, int height,
igt_crc_t ref_crc[ARRAY_SIZE(colors)],
struct igt_fb *fb)
{
igt_info("Testing format " IGT_FORMAT_FMT " / modifier 0x%" PRIx64 " on %s.%u\n",
IGT_FORMAT_ARGS(format), modifier,
kmstest_pipe_name(pipe), plane->index);
return test_format_plane_colors(data, pipe, plane,
format, modifier,
width, height,
IGT_COLOR_YCBCR_BT601,
IGT_COLOR_YCBCR_LIMITED_RANGE,
ref_crc, fb);
}
static bool test_format_plane_yuv(data_t *data, enum pipe pipe,
igt_plane_t *plane,
uint32_t format, uint64_t modifier,
int width, int height,
igt_crc_t ref_crc[ARRAY_SIZE(colors)],
struct igt_fb *fb)
{
bool result = true;
if (!igt_plane_has_prop(plane, IGT_PLANE_COLOR_ENCODING))
return true;
if (!igt_plane_has_prop(plane, IGT_PLANE_COLOR_RANGE))
return true;
for (enum igt_color_encoding e = 0; e < IGT_NUM_COLOR_ENCODINGS; e++) {
if (!igt_plane_try_prop_enum(plane,
IGT_PLANE_COLOR_ENCODING,
igt_color_encoding_to_str(e)))
continue;
for (enum igt_color_range r = 0; r < IGT_NUM_COLOR_RANGES; r++) {
if (!igt_plane_try_prop_enum(plane,
IGT_PLANE_COLOR_RANGE,
igt_color_range_to_str(r)))
continue;
igt_info("Testing format " IGT_FORMAT_FMT " / modifier 0x%" PRIx64 " (%s, %s) on %s.%u\n",
IGT_FORMAT_ARGS(format), modifier,
igt_color_encoding_to_str(e),
igt_color_range_to_str(r),
kmstest_pipe_name(pipe), plane->index);
result &= test_format_plane_colors(data, pipe, plane,
format, modifier,
width, height,
e, r, ref_crc, fb);
}
}
return result;
}
static bool test_format_plane(data_t *data, enum pipe pipe,
igt_output_t *output, igt_plane_t *plane)
{
struct igt_fb fb = {};
drmModeModeInfo *mode;
uint32_t format, ref_format;
uint64_t modifier, ref_modifier;
uint64_t width, height;
igt_crc_t ref_crc[ARRAY_SIZE(colors)];
bool result = true;
/*
* No clamping test for cursor plane
*/
if (data->crop != 0 && plane->type == DRM_PLANE_TYPE_CURSOR)
return true;
mode = igt_output_get_mode(output);
if (plane->type != DRM_PLANE_TYPE_CURSOR) {
width = mode->hdisplay;
height = mode->vdisplay;
ref_format = format = DRM_FORMAT_XRGB8888;
ref_modifier = modifier = DRM_FORMAT_MOD_NONE;
} else {
if (!plane->drm_plane) {
igt_debug("Only legacy cursor ioctl supported, skipping cursor plane\n");
return true;
}
do_or_die(drmGetCap(data->drm_fd, DRM_CAP_CURSOR_WIDTH, &width));
do_or_die(drmGetCap(data->drm_fd, DRM_CAP_CURSOR_HEIGHT, &height));
ref_format = format = DRM_FORMAT_ARGB8888;
ref_modifier = modifier = DRM_FORMAT_MOD_NONE;
}
igt_debug("Testing connector %s on %s plane %s.%u\n",
igt_output_name(output), kmstest_plane_type_name(plane->type),
kmstest_pipe_name(pipe), plane->index);
igt_pipe_crc_start(data->pipe_crc);
igt_info("Testing format " IGT_FORMAT_FMT " / modifier 0x%" PRIx64 " on %s.%u\n",
IGT_FORMAT_ARGS(format), modifier,
kmstest_pipe_name(pipe), plane->index);
if (data->display.is_atomic) {
struct igt_fb test_fb;
int ret;
igt_create_fb(data->drm_fd, 64, 64, format,
LOCAL_DRM_FORMAT_MOD_NONE, &test_fb);
igt_plane_set_fb(plane, &test_fb);
ret = igt_display_try_commit_atomic(&data->display, DRM_MODE_ATOMIC_TEST_ONLY, NULL);
if (!ret) {
width = test_fb.width;
height = test_fb.height;
}
igt_plane_set_fb(plane, NULL);
igt_remove_fb(data->drm_fd, &test_fb);
}
for (int i = 0; i < ARRAY_SIZE(colors); i++) {
test_format_plane_color(data, pipe, plane,
format, modifier,
width, height,
IGT_COLOR_YCBCR_BT709,
IGT_COLOR_YCBCR_LIMITED_RANGE,
i, &ref_crc[i], &fb);
}
/*
* Make sure we have some difference between the colors. This
* at least avoids claiming success when everything is just
* black all the time (eg. if the plane is never even on).
*/
igt_require(num_unique_crcs(ref_crc, ARRAY_SIZE(colors)) > 1);
for (int i = 0; i < plane->format_mod_count; i++) {
format = plane->formats[i];
modifier = plane->modifiers[i];
if (format == ref_format &&
modifier == ref_modifier)
continue;
if (format == DRM_FORMAT_C8) {
if (!set_c8_legacy_lut(data, pipe, LUT_MASK))
continue;
} else {
if (!igt_fb_supported_format(format))
continue;
}
if (igt_format_is_yuv(format))
result &= test_format_plane_yuv(data, pipe, plane,
format, modifier,
width, height,
ref_crc, &fb);
else
result &= test_format_plane_rgb(data, pipe, plane,
format, modifier,
width, height,
ref_crc, &fb);
if (format == DRM_FORMAT_C8)
set_legacy_lut(data, pipe, LUT_MASK);
}
igt_pipe_crc_stop(data->pipe_crc);
igt_plane_set_fb(plane, NULL);
igt_remove_fb(data->drm_fd, &fb);
return result;
}
static void
test_pixel_formats(data_t *data, enum pipe pipe)
{
struct igt_fb primary_fb;
igt_plane_t *primary;
drmModeModeInfo *mode;
bool result;
igt_output_t *output;
igt_plane_t *plane;
output = igt_get_single_output_for_pipe(&data->display, pipe);
igt_require(output);
mode = igt_output_get_mode(output);
igt_create_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE, &primary_fb);
igt_output_set_pipe(output, pipe);
primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
igt_plane_set_fb(primary, &primary_fb);
igt_display_commit2(&data->display, data->display.is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
set_legacy_lut(data, pipe, LUT_MASK);
test_init(data, pipe);
result = true;
for_each_plane_on_pipe(&data->display, pipe, plane)
result &= test_format_plane(data, pipe, output, plane);
test_fini(data);
set_legacy_lut(data, pipe, 0xffff);
igt_plane_set_fb(primary, NULL);
igt_output_set_pipe(output, PIPE_NONE);
igt_display_commit2(&data->display, data->display.is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
igt_remove_fb(data->drm_fd, &primary_fb);
igt_assert_f(result, "At least one CRC mismatch happened\n");
}
static void
run_tests_for_pipe_plane(data_t *data, enum pipe pipe)
{
igt_fixture {
igt_skip_on(pipe >= data->display.n_pipes);
igt_require(data->display.pipes[pipe].n_planes > 0);
}
igt_subtest_f("pixel-format-pipe-%s-planes",
kmstest_pipe_name(pipe))
test_pixel_formats(data, pipe);
igt_subtest_f("pixel-format-pipe-%s-planes-source-clamping",
kmstest_pipe_name(pipe)) {
data->crop = 4;
test_pixel_formats(data, pipe);
}
data->crop = 0;
igt_subtest_f("plane-position-covered-pipe-%s-planes",
kmstest_pipe_name(pipe))
test_plane_position(data, pipe, TEST_POSITION_FULLY_COVERED);
igt_subtest_f("plane-position-hole-pipe-%s-planes",
kmstest_pipe_name(pipe))
test_plane_position(data, pipe, 0);
igt_subtest_f("plane-position-hole-dpms-pipe-%s-planes",
kmstest_pipe_name(pipe))
test_plane_position(data, pipe, TEST_DPMS);
igt_subtest_f("plane-panning-top-left-pipe-%s-planes",
kmstest_pipe_name(pipe))
test_plane_panning(data, pipe, TEST_PANNING_TOP_LEFT);
igt_subtest_f("plane-panning-bottom-right-pipe-%s-planes",
kmstest_pipe_name(pipe))
test_plane_panning(data, pipe, TEST_PANNING_BOTTOM_RIGHT);
igt_subtest_f("plane-panning-bottom-right-suspend-pipe-%s-planes",
kmstest_pipe_name(pipe))
test_plane_panning(data, pipe, TEST_PANNING_BOTTOM_RIGHT |
TEST_SUSPEND_RESUME);
}
static data_t data;
igt_main
{
enum pipe pipe;
igt_skip_on_simulation();
igt_fixture {
data.drm_fd = drm_open_driver_master(DRIVER_ANY);
kmstest_set_vt_graphics_mode();
igt_require_pipe_crc(data.drm_fd);
igt_display_require(&data.display, data.drm_fd);
}
for_each_pipe_static(pipe)
run_tests_for_pipe_plane(&data, pipe);
igt_fixture {
igt_display_fini(&data.display);
}
}
|