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 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197
|
/*
* Copyright © 2015 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.
*
*/
/**
* TEST: kms color
* Category: Display
* Description: Test Color Features at Pipe level
* Driver requirement: i915, xe
* Mega feature: Color Management
*/
#include "kms_color_helper.h"
/**
* SUBTEST: degamma
* Description: Verify that degamma LUT transformation works correctly
*
* SUBTEST: gamma
* Description: Verify that gamma LUT transformation works correctly
*
* SUBTEST: legacy-gamma
* Description: Verify that legacy gamma LUT transformation works correctly
*
* SUBTEST: legacy-gamma-reset
* Description: Verify that setting the legacy gamma LUT resets the gamma LUT
* set through GAMMA_LUT property
*
* SUBTEST: ctm-%s
* Description: Check the color transformation %arg[1]
*
* arg[1]:
*
* @0-25: for 0.25 transparency
* @0-50: for 0.50 transparency
* @0-75: for 0.75 transparency
* @blue-to-red: from blue to red
* @green-to-red: from green to red
* @max: for maximum transparency
* @negative: for negative transparency
* @red-to-blue: from red to blue
* @signed: for correct signed handling
*/
/**
* SUBTEST: deep-color
* Description: Verify that deep color works correctly
*
* SUBTEST: invalid-%s-sizes
* Description: Negative check for %arg[1] sizes
*
* arg[1]:
*
* @ctm-matrix: Color transformation matrix
* @degamma-lut: Degamma LUT
* @gamma-lut: Gamma LUT
*/
IGT_TEST_DESCRIPTION("Test Color Features at Pipe level");
static bool test_pipe_degamma(data_t *data,
igt_plane_t *primary)
{
igt_output_t *output = data->output;
igt_display_t *display = &data->display;
gamma_lut_t *degamma_linear, *degamma_full;
color_t red_green_blue[] = {
{ 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
};
drmModeModeInfo *mode = data->mode;
struct igt_fb fb_modeset, fb;
igt_crc_t crc_fullgamma, crc_fullcolors;
int fb_id, fb_modeset_id;
bool ret;
igt_require(igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_DEGAMMA_LUT));
igt_require(igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_GAMMA_LUT));
degamma_linear = generate_table(data->degamma_lut_size, 1.0);
degamma_full = generate_table_max(data->degamma_lut_size);
igt_output_set_pipe(output, primary->pipe->pipe);
igt_output_override_mode(output, mode);
/* Create a framebuffer at the size of the output. */
fb_id = igt_create_fb(data->drm_fd,
mode->hdisplay,
mode->vdisplay,
data->drm_format,
DRM_FORMAT_MOD_LINEAR,
&fb);
igt_assert(fb_id);
fb_modeset_id = igt_create_fb(data->drm_fd,
mode->hdisplay,
mode->vdisplay,
data->drm_format,
DRM_FORMAT_MOD_LINEAR,
&fb_modeset);
igt_assert(fb_modeset_id);
igt_plane_set_fb(primary, &fb_modeset);
disable_ctm(primary->pipe);
disable_gamma(primary->pipe);
set_degamma(data, primary->pipe, degamma_linear);
igt_display_commit(&data->display);
/* Draw solid colors with linear degamma transformation. */
paint_rectangles(data, mode, red_green_blue, &fb);
igt_plane_set_fb(primary, &fb);
igt_display_commit(&data->display);
igt_wait_for_vblank(data->drm_fd,
display->pipes[primary->pipe->pipe].crtc_offset);
igt_pipe_crc_collect_crc(data->pipe_crc, &crc_fullcolors);
/*
* Draw a gradient with degamma LUT to remap all
* values to max red/green/blue.
*/
paint_gradient_rectangles(data, mode, red_green_blue, &fb);
igt_plane_set_fb(primary, &fb);
set_degamma(data, primary->pipe, degamma_full);
igt_display_commit(&data->display);
igt_wait_for_vblank(data->drm_fd,
display->pipes[primary->pipe->pipe].crtc_offset);
igt_pipe_crc_collect_crc(data->pipe_crc, &crc_fullgamma);
/*
* Verify that the CRC of the software computed output is
* equal to the CRC of the degamma LUT transformation output.
*/
ret = igt_skip_crc_compare || igt_check_crc_equal(&crc_fullgamma, &crc_fullcolors);
disable_degamma(primary->pipe);
igt_plane_set_fb(primary, NULL);
igt_output_set_pipe(output, PIPE_NONE);
igt_display_commit(&data->display);
igt_remove_fb(data->drm_fd, &fb);
igt_remove_fb(data->drm_fd, &fb_modeset);
free_lut(degamma_linear);
free_lut(degamma_full);
return ret;
}
/*
* Draw 3 gradient rectangles in red, green and blue, with a maxed out gamma
* LUT and verify we have the same CRC as drawing solid color rectangles.
*/
static bool test_pipe_gamma(data_t *data,
igt_plane_t *primary)
{
igt_output_t *output = data->output;
igt_display_t *display = &data->display;
gamma_lut_t *gamma_full;
color_t red_green_blue[] = {
{ 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
};
drmModeModeInfo *mode = data->mode;
struct igt_fb fb_modeset, fb;
igt_crc_t crc_fullgamma, crc_fullcolors;
int fb_id, fb_modeset_id;
bool ret;
igt_require(igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_GAMMA_LUT));
gamma_full = generate_table_max(data->gamma_lut_size);
igt_output_set_pipe(output, primary->pipe->pipe);
igt_output_override_mode(output, mode);
/* Create a framebuffer at the size of the output. */
fb_id = igt_create_fb(data->drm_fd,
mode->hdisplay,
mode->vdisplay,
data->drm_format,
DRM_FORMAT_MOD_LINEAR,
&fb);
igt_assert(fb_id);
fb_modeset_id = igt_create_fb(data->drm_fd,
mode->hdisplay,
mode->vdisplay,
data->drm_format,
DRM_FORMAT_MOD_LINEAR,
&fb_modeset);
igt_assert(fb_modeset_id);
igt_plane_set_fb(primary, &fb_modeset);
disable_ctm(primary->pipe);
disable_degamma(primary->pipe);
set_gamma(data, primary->pipe, gamma_full);
igt_display_commit(&data->display);
/* Draw solid colors with no gamma transformation. */
paint_rectangles(data, mode, red_green_blue, &fb);
igt_plane_set_fb(primary, &fb);
igt_display_commit(&data->display);
igt_wait_for_vblank(data->drm_fd,
display->pipes[primary->pipe->pipe].crtc_offset);
igt_pipe_crc_collect_crc(data->pipe_crc, &crc_fullcolors);
/*
* Draw a gradient with gamma LUT to remap all values
* to max red/green/blue.
*/
paint_gradient_rectangles(data, mode, red_green_blue, &fb);
igt_plane_set_fb(primary, &fb);
igt_display_commit(&data->display);
igt_wait_for_vblank(data->drm_fd,
display->pipes[primary->pipe->pipe].crtc_offset);
igt_pipe_crc_collect_crc(data->pipe_crc, &crc_fullgamma);
/*
* Verify that the CRC of the software computed output is
* equal to the CRC of the gamma LUT transformation output.
*/
ret = igt_skip_crc_compare || igt_check_crc_equal(&crc_fullgamma, &crc_fullcolors);
disable_gamma(primary->pipe);
igt_plane_set_fb(primary, NULL);
igt_output_set_pipe(output, PIPE_NONE);
igt_display_commit(&data->display);
igt_remove_fb(data->drm_fd, &fb);
igt_remove_fb(data->drm_fd, &fb_modeset);
free_lut(gamma_full);
return ret;
}
/*
* Draw 3 gradient rectangles in red, green and blue, with a maxed out legacy
* gamma LUT and verify we have the same CRC as drawing solid color rectangles
* with linear legacy gamma LUT.
*/
static bool test_pipe_legacy_gamma(data_t *data,
igt_plane_t *primary)
{
igt_output_t *output = data->output;
igt_display_t *display = &data->display;
color_t red_green_blue[] = {
{ 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
};
drmModeCrtc *kms_crtc;
uint32_t i, legacy_lut_size;
uint16_t *red_lut, *green_lut, *blue_lut;
drmModeModeInfo *mode = data->mode;
struct igt_fb fb_modeset, fb;
igt_crc_t crc_fullgamma, crc_fullcolors;
int fb_id, fb_modeset_id;
bool ret;
kms_crtc = drmModeGetCrtc(data->drm_fd, primary->pipe->crtc_id);
legacy_lut_size = kms_crtc->gamma_size;
drmModeFreeCrtc(kms_crtc);
igt_require(legacy_lut_size > 0);
red_lut = malloc(sizeof(uint16_t) * legacy_lut_size);
green_lut = malloc(sizeof(uint16_t) * legacy_lut_size);
blue_lut = malloc(sizeof(uint16_t) * legacy_lut_size);
igt_output_set_pipe(output, primary->pipe->pipe);
igt_output_override_mode(output, mode);
/* Create a framebuffer at the size of the output. */
fb_id = igt_create_fb(data->drm_fd,
mode->hdisplay,
mode->vdisplay,
DRM_FORMAT_XRGB8888,
DRM_FORMAT_MOD_LINEAR,
&fb);
igt_assert(fb_id);
fb_modeset_id = igt_create_fb(data->drm_fd,
mode->hdisplay,
mode->vdisplay,
DRM_FORMAT_XRGB8888,
DRM_FORMAT_MOD_LINEAR,
&fb_modeset);
igt_assert(fb_modeset_id);
igt_plane_set_fb(primary, &fb_modeset);
disable_degamma(primary->pipe);
disable_gamma(primary->pipe);
disable_ctm(primary->pipe);
igt_display_commit(&data->display);
/* Draw solid colors with no gamma transformation. */
paint_rectangles(data, mode, red_green_blue, &fb);
igt_plane_set_fb(primary, &fb);
igt_display_commit(&data->display);
igt_wait_for_vblank(data->drm_fd,
display->pipes[primary->pipe->pipe].crtc_offset);
igt_pipe_crc_collect_crc(data->pipe_crc, &crc_fullcolors);
/*
* Draw a gradient with gamma LUT to remap all values
* to max red/green/blue.
*/
paint_gradient_rectangles(data, mode, red_green_blue, &fb);
igt_plane_set_fb(primary, &fb);
red_lut[0] = green_lut[0] = blue_lut[0] = 0;
for (i = 1; i < legacy_lut_size; i++)
red_lut[i] = green_lut[i] = blue_lut[i] = 0xffff;
igt_assert_eq(drmModeCrtcSetGamma(data->drm_fd, primary->pipe->crtc_id,
legacy_lut_size, red_lut, green_lut, blue_lut), 0);
igt_display_commit(&data->display);
igt_wait_for_vblank(data->drm_fd,
display->pipes[primary->pipe->pipe].crtc_offset);
igt_pipe_crc_collect_crc(data->pipe_crc, &crc_fullgamma);
/*
* Verify that the CRC of the software computed output is
* equal to the CRC of the gamma LUT transformation output.
*/
ret = igt_skip_crc_compare || igt_check_crc_equal(&crc_fullgamma, &crc_fullcolors);
/* Reset output. */
for (i = 1; i < legacy_lut_size; i++)
red_lut[i] = green_lut[i] = blue_lut[i] = i << 8;
igt_assert_eq(drmModeCrtcSetGamma(data->drm_fd, primary->pipe->crtc_id,
legacy_lut_size, red_lut, green_lut, blue_lut), 0);
igt_display_commit(&data->display);
igt_plane_set_fb(primary, NULL);
igt_output_set_pipe(output, PIPE_NONE);
igt_display_commit(&data->display);
igt_remove_fb(data->drm_fd, &fb);
igt_remove_fb(data->drm_fd, &fb_modeset);
free(red_lut);
free(green_lut);
free(blue_lut);
return ret;
}
/*
* Verify that setting the legacy gamma LUT resets the gamma LUT set
* through the GAMMA_LUT property.
*/
static bool test_pipe_legacy_gamma_reset(data_t *data,
igt_plane_t *primary)
{
static const double ctm_identity[] = {
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
};
drmModeCrtc *kms_crtc;
gamma_lut_t *degamma_linear = NULL, *gamma_zero;
uint32_t i, legacy_lut_size;
uint16_t *red_lut, *green_lut, *blue_lut;
struct drm_color_lut *lut;
drmModePropertyBlobPtr blob;
igt_output_t *output = data->output;
bool ret = true;
igt_require(igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_GAMMA_LUT));
if (igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_DEGAMMA_LUT))
degamma_linear = generate_table(data->degamma_lut_size, 1.0);
gamma_zero = generate_table_zero(data->gamma_lut_size);
igt_output_set_pipe(output, primary->pipe->pipe);
/* Ensure we have a clean state to start with. */
disable_degamma(primary->pipe);
disable_ctm(primary->pipe);
disable_gamma(primary->pipe);
igt_display_commit(&data->display);
/*
* Set a degama & gamma LUT and a CTM using the
* properties and verify the content of the
* properties.
*/
if (igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_DEGAMMA_LUT))
set_degamma(data, primary->pipe, degamma_linear);
if (igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_CTM))
set_ctm(primary->pipe, ctm_identity);
set_gamma(data, primary->pipe, gamma_zero);
igt_display_commit(&data->display);
if (igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_DEGAMMA_LUT)) {
blob = get_blob(data, primary->pipe, IGT_CRTC_DEGAMMA_LUT);
igt_assert(blob &&
blob->length == (sizeof(struct drm_color_lut) *
data->degamma_lut_size));
drmModeFreePropertyBlob(blob);
}
if (igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_CTM)) {
blob = get_blob(data, primary->pipe, IGT_CRTC_CTM);
igt_assert(blob &&
blob->length == sizeof(struct drm_color_ctm));
drmModeFreePropertyBlob(blob);
}
blob = get_blob(data, primary->pipe, IGT_CRTC_GAMMA_LUT);
igt_assert(blob &&
blob->length == (sizeof(struct drm_color_lut) *
data->gamma_lut_size));
lut = (struct drm_color_lut *) blob->data;
for (i = 0; i < data->gamma_lut_size; i++)
ret &=(lut[i].red == 0 &&
lut[i].green == 0 &&
lut[i].blue == 0);
drmModeFreePropertyBlob(blob);
if(!ret)
goto end;
/*
* Set a gamma LUT using the legacy ioctl and verify
* the content of the GAMMA_LUT property is changed
* and that CTM and DEGAMMA_LUT are empty.
*/
kms_crtc = drmModeGetCrtc(data->drm_fd, primary->pipe->crtc_id);
legacy_lut_size = kms_crtc->gamma_size;
drmModeFreeCrtc(kms_crtc);
red_lut = malloc(sizeof(uint16_t) * legacy_lut_size);
igt_assert(red_lut);
green_lut = malloc(sizeof(uint16_t) * legacy_lut_size);
igt_assert(green_lut);
blue_lut = malloc(sizeof(uint16_t) * legacy_lut_size);
igt_assert(blue_lut);
for (i = 0; i < legacy_lut_size; i++)
red_lut[i] = green_lut[i] = blue_lut[i] = 0xffff;
igt_assert_eq(drmModeCrtcSetGamma(data->drm_fd,
primary->pipe->crtc_id,
legacy_lut_size,
red_lut, green_lut, blue_lut), 0);
igt_display_commit(&data->display);
if (igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_DEGAMMA_LUT))
igt_assert(get_blob(data, primary->pipe,
IGT_CRTC_DEGAMMA_LUT) == NULL);
if (igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_CTM))
igt_assert(get_blob(data, primary->pipe, IGT_CRTC_CTM) == NULL);
blob = get_blob(data, primary->pipe, IGT_CRTC_GAMMA_LUT);
igt_assert(blob &&
blob->length == (sizeof(struct drm_color_lut) *
legacy_lut_size));
lut = (struct drm_color_lut *) blob->data;
for (i = 0; i < legacy_lut_size; i++)
ret &= (lut[i].red == 0xffff &&
lut[i].green == 0xffff &&
lut[i].blue == 0xffff);
drmModeFreePropertyBlob(blob);
free(red_lut);
free(green_lut);
free(blue_lut);
end:
igt_plane_set_fb(primary, NULL);
igt_output_set_pipe(output, PIPE_NONE);
igt_display_commit(&data->display);
free_lut(degamma_linear);
free_lut(gamma_zero);
return ret;
}
/*
* Draw 3 rectangles using before colors with the ctm matrix apply and verify
* the CRC is equal to using after colors with an identify ctm matrix.
*/
static bool test_pipe_ctm(data_t *data,
igt_plane_t *primary,
const color_t *before,
const color_t *after,
const double *ctm_matrix)
{
static const double ctm_identity[] = {
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
};
gamma_lut_t *degamma_linear = NULL, *gamma_linear = NULL;
igt_output_t *output = data->output;
bool ret = true;
igt_display_t *display = &data->display;
drmModeModeInfo *mode = data->mode;
struct igt_fb fb_modeset, fb;
igt_crc_t crc_software, crc_hardware;
int fb_id, fb_modeset_id;
igt_require(igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_CTM));
igt_output_set_pipe(output, primary->pipe->pipe);
igt_output_override_mode(output, mode);
/* Create a framebuffer at the size of the output. */
fb_id = igt_create_fb(data->drm_fd,
mode->hdisplay,
mode->vdisplay,
data->drm_format,
DRM_FORMAT_MOD_LINEAR,
&fb);
igt_assert(fb_id);
fb_modeset_id = igt_create_fb(data->drm_fd,
mode->hdisplay,
mode->vdisplay,
data->drm_format,
DRM_FORMAT_MOD_LINEAR,
&fb_modeset);
igt_assert(fb_modeset_id);
igt_plane_set_fb(primary, &fb_modeset);
disable_degamma(primary->pipe);
disable_gamma(primary->pipe);
/*
* Only program LUT's for intel, but not for max CTM as limitation of
* representing intermediate values between 0 and 1.0 causes
* rounding issues and inaccuracies leading to crc mismatch.
*/
if (is_intel_device(data->drm_fd) && memcmp(before, after, sizeof(color_t))) {
igt_require(igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_GAMMA_LUT));
gamma_linear = generate_table(256, 1.0);
set_gamma(data, primary->pipe, gamma_linear);
}
igt_debug("color before[0] %f,%f,%f\n", before[0].r, before[0].g, before[0].b);
igt_debug("color before[1] %f,%f,%f\n", before[1].r, before[1].g, before[1].b);
igt_debug("color before[2] %f,%f,%f\n", before[2].r, before[2].g, before[2].b);
igt_debug("color after[0] %f,%f,%f\n", after[0].r, after[0].g, after[0].b);
igt_debug("color after[1] %f,%f,%f\n", after[1].r, after[1].g, after[1].b);
igt_debug("color after[2] %f,%f,%f\n", after[2].r, after[2].g, after[2].b);
disable_ctm(primary->pipe);
igt_display_commit(&data->display);
paint_rectangles(data, mode, after, &fb);
igt_plane_set_fb(primary, &fb);
set_ctm(primary->pipe, ctm_identity);
igt_display_commit(&data->display);
igt_wait_for_vblank(data->drm_fd,
display->pipes[primary->pipe->pipe].crtc_offset);
igt_pipe_crc_collect_crc(data->pipe_crc, &crc_software);
/* With CTM transformation. */
paint_rectangles(data, mode, before, &fb);
igt_plane_set_fb(primary, &fb);
set_ctm(primary->pipe, ctm_matrix);
igt_display_commit(&data->display);
igt_wait_for_vblank(data->drm_fd,
display->pipes[primary->pipe->pipe].crtc_offset);
igt_pipe_crc_collect_crc(data->pipe_crc, &crc_hardware);
/*
* Verify that the CRC of the software computed output is
* equal to the CRC of the CTM matrix transformation output.
*/
ret &= igt_skip_crc_compare || igt_check_crc_equal(&crc_software, &crc_hardware);
disable_ctm(primary->pipe);
igt_plane_set_fb(primary, NULL);
igt_output_set_pipe(output, PIPE_NONE);
igt_display_commit(&data->display);
igt_remove_fb(data->drm_fd, &fb);
igt_remove_fb(data->drm_fd, &fb_modeset);
free_lut(degamma_linear);
free_lut(gamma_linear);
return ret;
}
/*
* Hardware computes CRC based on the number of bits it is working with (8,
* 10, 12, 16 bits), meaning with a framebuffer of 8bits per color will
* usually leave the remaining lower bits at 0.
*
* We're programming the gamma LUT in order to get rid of those lower bits so
* we can compare the CRC of a framebuffer without any transformation to a CRC
* with transformation applied and verify the CRCs match.
*
* This test is currently disabled as the CRC computed on Intel hardware seems
* to include data on the lower bits, this is preventing us to CRC checks.
*/
#if 0
static void test_pipe_limited_range_ctm(data_t *data,
igt_plane_t *primary)
{
double limited_result = 235.0 / 255.0;
static const color_t red_green_blue_limited[] = {
{ limited_result, 0.0, 0.0 },
{ 0.0, limited_result, 0.0 },
{ 0.0, 0.0, limited_result },
};
static const color_t red_green_blue_full[] = {
{ 0.5, 0.0, 0.0 },
{ 0.0, 0.5, 0.0 },
{ 0.0, 0.0, 0.5 },
};
static const double ctm[] = {
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
};
gamma_lut_t *degamma_linear, *gamma_linear;
igt_output_t *output;
bool has_broadcast_rgb_output = false;
igt_display_t *display = &data->display;
degamma_linear = generate_table(data->degamma_lut_size, 1.0);
gamma_linear = generate_table(data->gamma_lut_size, 1.0);
for_each_valid_output_on_pipe(&data->display, primary->pipe->pipe, output) {
drmModeModeInfo *mode;
struct igt_fb fb_modeset, fb;
igt_crc_t crc_full, crc_limited;
int fb_id, fb_modeset_id;
if (!igt_output_has_prop(output, IGT_CONNECTOR_BROADCAST_RGB))
continue;
has_broadcast_rgb_output = true;
igt_output_set_pipe(output, primary->pipe->pipe);
mode = igt_output_get_mode(output);
/* Create a framebuffer at the size of the output. */
fb_id = igt_create_fb(data->drm_fd,
mode->hdisplay,
mode->vdisplay,
DRM_FORMAT_XRGB8888,
DRM_FORMAT_MOD_LINEAR,
&fb);
igt_assert(fb_id);
fb_modeset_id = igt_create_fb(data->drm_fd,
mode->hdisplay,
mode->vdisplay,
DRM_FORMAT_XRGB8888,
DRM_FORMAT_MOD_LINEAR,
&fb_modeset);
igt_assert(fb_modeset_id);
igt_plane_set_fb(primary, &fb_modeset);
set_degamma(data, primary->pipe, degamma_linear);
set_gamma(data, primary->pipe, gamma_linear);
set_ctm(primary->pipe, ctm);
igt_output_set_prop_value(output, IGT_CONNECTOR_BROADCAST_RGB, BROADCAST_RGB_FULL);
paint_rectangles(data, mode, red_green_blue_limited, &fb);
igt_plane_set_fb(primary, &fb);
igt_display_commit(&data->display);
igt_wait_for_vblank(data->drm_fd,
display->pipes[primary->pipe->pipe].crtc_offset);
igt_pipe_crc_collect_crc(data->pipe_crc, &crc_full);
/* Set the output into limited range. */
igt_output_set_prop_value(output, IGT_CONNECTOR_BROADCAST_RGB, BROADCAST_RGB_16_235);
paint_rectangles(data, mode, red_green_blue_full, &fb);
igt_plane_set_fb(primary, &fb);
igt_display_commit(&data->display);
igt_wait_for_vblank(data->drm_fd,
display->pipes[primary->pipe->pipe].crtc_offset);
igt_pipe_crc_collect_crc(data->pipe_crc, &crc_limited);
/* And reset.. */
igt_output_set_prop_value(output, IGT_CONNECTOR_BROADCAST_RGB, BROADCAST_RGB_FULL);
igt_plane_set_fb(primary, NULL);
igt_output_set_pipe(output, PIPE_NONE);
/* Verify that the CRC of the software computed output is
* equal to the CRC of the CTM matrix transformation output.
*/
igt_assert_crc_equal(&crc_full, &crc_limited);
igt_remove_fb(data->drm_fd, &fb);
igt_remove_fb(data->drm_fd, &fb_modeset);
}
free_lut(gamma_linear);
free_lut(degamma_linear);
igt_require(has_broadcast_rgb_output);
}
#endif
static void
prep_pipe(data_t *data, enum pipe p)
{
igt_require_pipe(&data->display, p);
if (igt_pipe_obj_has_prop(&data->display.pipes[p], IGT_CRTC_DEGAMMA_LUT_SIZE)) {
data->degamma_lut_size =
igt_pipe_obj_get_prop(&data->display.pipes[p],
IGT_CRTC_DEGAMMA_LUT_SIZE);
igt_assert_lt(0, data->degamma_lut_size);
}
if (igt_pipe_obj_has_prop(&data->display.pipes[p], IGT_CRTC_GAMMA_LUT_SIZE)) {
data->gamma_lut_size =
igt_pipe_obj_get_prop(&data->display.pipes[p],
IGT_CRTC_GAMMA_LUT_SIZE);
igt_assert_lt(0, data->gamma_lut_size);
}
}
static void test_setup(data_t *data, enum pipe p)
{
igt_pipe_t *pipe;
prep_pipe(data, p);
igt_require_pipe_crc(data->drm_fd);
pipe = &data->display.pipes[p];
igt_require(pipe->n_planes >= 0);
data->primary = igt_pipe_get_plane_type(pipe, DRM_PLANE_TYPE_PRIMARY);
data->pipe_crc = igt_pipe_crc_new(data->drm_fd,
data->primary->pipe->pipe,
IGT_PIPE_CRC_SOURCE_AUTO);
igt_display_reset(&data->display);
}
static void test_cleanup(data_t *data)
{
igt_pipe_crc_free(data->pipe_crc);
data->pipe_crc = NULL;
}
static void
run_gamma_degamma_tests_for_pipe(data_t *data, enum pipe p,
bool (*test_t)(data_t*, igt_plane_t*))
{
test_setup(data, p);
/*
* We assume an 8bits depth per color for degamma/gamma LUTs
* for CRC checks with framebuffer references.
*/
data->color_depth = 8;
data->drm_format = DRM_FORMAT_XRGB8888;
data->mode = igt_output_get_mode(data->output);
igt_require(pipe_output_combo_valid(data, p));
igt_assert(test_t(data, data->primary));
test_cleanup(data);
}
static void transform_color(color_t *color, const double *ctm, double offset)
{
color_t tmp = *color;
color->r = ctm[0] * tmp.r + ctm[1] * tmp.g + ctm[2] * tmp.b + offset;
color->g = ctm[3] * tmp.r + ctm[4] * tmp.g + ctm[5] * tmp.b + offset;
color->b = ctm[6] * tmp.r + ctm[7] * tmp.g + ctm[8] * tmp.b + offset;
}
static void
run_ctm_tests_for_pipe(data_t *data, enum pipe p,
const color_t *fb_colors,
const double *ctm,
int iter)
{
bool success = false;
double delta;
int i;
test_setup(data, p);
/*
* We assume an 8bits depth per color for degamma/gamma LUTs
* for CRC checks with framebuffer references.
*/
data->color_depth = 8;
delta = 1.0 / (1 << data->color_depth);
data->drm_format = DRM_FORMAT_XRGB8888;
data->mode = igt_output_get_mode(data->output);
igt_require(pipe_output_combo_valid(data, p));
if (!iter)
iter = 1;
/*
* We tests a few values around the expected result because
* it depends on the hardware we're dealing with, we can either
* get clamped or rounded values and we also need to account
* for odd number of items in the LUTs.
*/
for (i = 0; i < iter; i++) {
color_t expected_colors[3] = {
fb_colors[0],
fb_colors[1],
fb_colors[2],
};
transform_color(&expected_colors[0], ctm, delta * (i - (iter / 2)));
transform_color(&expected_colors[1], ctm, delta * (i - (iter / 2)));
transform_color(&expected_colors[2], ctm, delta * (i - (iter / 2)));
if (test_pipe_ctm(data, data->primary, fb_colors,
expected_colors, ctm)) {
success = true;
break;
}
}
igt_assert(success);
test_cleanup(data);
}
static void
run_deep_color_tests_for_pipe(data_t *data, enum pipe p)
{
igt_output_t *output;
static const color_t blue_green_blue[] = {
{ 0.0, 0.0, 1.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
};
static const color_t red_green_blue[] = {
{ 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
};
static const double ctm[] = {
0.0, 0.0, 0.0,
0.0, 1.0, 0.0,
1.0, 0.0, 1.0,
};
if (is_intel_device(data->drm_fd))
igt_require_f((intel_display_ver(data->devid) >= 11),
"At least GEN 11 is required to validate Deep-color.\n");
test_setup(data, p);
for_each_valid_output_on_pipe(&data->display, p, output) {
uint64_t max_bpc = get_max_bpc(output);
bool ret;
if (!max_bpc) {
igt_info("Output %s: Doesn't support \"max bpc\" property.\n",
igt_output_name(output));
continue;
}
if (!panel_supports_deep_color(data->drm_fd, output->name)) {
igt_info("Output %s: Doesn't support deep-color.\n",
igt_output_name(output));
continue;
}
/*
* In intel driver, for MST streams pipe_bpp is
* restricted to 8bpc. So, deep-color >= 10bpc
* will never work for DP-MST even if the panel
* supports 10bpc. Once KMD FIXME, is resolved
* this MST constraint can be removed.
*/
if (is_intel_device(data->drm_fd) && igt_check_output_is_dp_mst(output)) {
igt_info("Output %s: DP-MST doesn't support deep-color on Intel hardware.\n",
igt_output_name(output));
continue;
}
igt_display_reset(&data->display);
igt_output_set_prop_value(output, IGT_CONNECTOR_MAX_BPC, 10);
igt_output_set_pipe(output, p);
if (is_intel_device(data->drm_fd) &&
!igt_max_bpc_constraint(&data->display, p, output, 10)) {
igt_info("Output %s: Doesn't support 10-bpc.\n",
igt_output_name(output));
continue;
}
data->color_depth = 10;
data->drm_format = DRM_FORMAT_XRGB2101010;
data->output = output;
data->mode = malloc(sizeof(drmModeModeInfo));
igt_assert(data->mode);
memcpy(data->mode, igt_output_get_mode(data->output), sizeof(drmModeModeInfo));
igt_dynamic_f("pipe-%s-%s-gamma", kmstest_pipe_name(p), output->name) {
igt_display_reset(&data->display);
igt_output_set_prop_value(output, IGT_CONNECTOR_MAX_BPC, 10);
ret = test_pipe_gamma(data, data->primary);
igt_output_set_prop_value(output, IGT_CONNECTOR_MAX_BPC, max_bpc);
igt_assert(ret);
}
igt_dynamic_f("pipe-%s-%s-degamma", kmstest_pipe_name(p), output->name) {
igt_display_reset(&data->display);
igt_output_set_prop_value(output, IGT_CONNECTOR_MAX_BPC, 10);
ret = test_pipe_degamma(data, data->primary);
igt_output_set_prop_value(output, IGT_CONNECTOR_MAX_BPC, max_bpc);
igt_assert(ret);
}
igt_dynamic_f("pipe-%s-%s-ctm", kmstest_pipe_name(p), output->name) {
igt_display_reset(&data->display);
igt_output_set_prop_value(output, IGT_CONNECTOR_MAX_BPC, 10);
ret = test_pipe_ctm(data, data->primary,
red_green_blue,
blue_green_blue, ctm);
igt_output_set_prop_value(output, IGT_CONNECTOR_MAX_BPC, max_bpc);
igt_assert(ret);
}
free(data->mode);
break;
}
test_cleanup(data);
}
static void
run_invalid_tests_for_pipe(data_t *data)
{
enum pipe pipe;
struct {
const char *name;
void (*test_t) (data_t *data, enum pipe pipe);
const char *desc;
} tests[] = {
{ "invalid-gamma-lut-sizes", invalid_gamma_lut_sizes,
"Negative check for invalid gamma lut sizes" },
{ "invalid-degamma-lut-sizes", invalid_degamma_lut_sizes,
"Negative check for invalid degamma lut sizes" },
{ "invalid-ctm-matrix-sizes", invalid_ctm_matrix_sizes,
"Negative check for color tranformation matrix sizes" },
};
int i;
for (i = 0; i < ARRAY_SIZE(tests); i++) {
igt_describe_f("%s", tests[i].desc);
igt_subtest_with_dynamic_f("%s", tests[i].name) {
for_each_pipe(&data->display, pipe) {
igt_dynamic_f("pipe-%s", kmstest_pipe_name(pipe)) {
prep_pipe(data, pipe);
tests[i].test_t(data, pipe);
}
}
}
}
}
static void
run_tests_for_pipe(data_t *data)
{
enum pipe pipe;
static const struct {
const char *name;
bool (*test_t)(data_t*, igt_plane_t*);
const char *desc;
} gamma_degamma_tests[] = {
{ .name = "degamma",
.test_t = test_pipe_degamma,
.desc = "Verify that degamma LUT transformation works correctly",
},
{ .name = "gamma",
.test_t = test_pipe_gamma,
.desc = "Verify that gamma LUT transformation works correctly",
},
{ .name = "legacy-gamma",
.test_t = test_pipe_legacy_gamma,
.desc = "Verify that legacy gamma LUT transformation works correctly",
},
{ .name = "legacy-gamma-reset",
.test_t = test_pipe_legacy_gamma_reset,
.desc = "Verify that setting the legacy gamma LUT resets the gamma LUT set through GAMMA_LUT property",
},
};
static const color_t colors_rgb[] = {
{ 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
};
static const color_t colors_cmy[] = {
{ 0.0, 1.0, 1.0 },
{ 1.0, 0.0, 1.0 },
{ 1.0, 1.0, 0.0 }
};
static const struct {
const char *name;
int iter;
const color_t *fb_colors;
double ctm[9];
const char *desc;
} ctm_tests[] = {
{ .name = "ctm-red-to-blue",
.fb_colors = colors_rgb,
.ctm = {
0.0, 0.0, 0.0,
0.0, 1.0, 0.0,
1.0, 0.0, 1.0,
},
.desc = "Check the color transformation from red to blue",
},
{ .name = "ctm-green-to-red",
.fb_colors = colors_rgb,
.ctm = {
1.0, 1.0, 0.0,
0.0, 0.0, 0.0,
0.0, 0.0, 1.0,
},
.desc = "Check the color transformation from green to red",
},
{ .name = "ctm-blue-to-red",
.fb_colors = colors_rgb,
.ctm = {
1.0, 0.0, 1.0,
0.0, 1.0, 0.0,
0.0, 0.0, 0.0,
},
.desc = "Check the color transformation from blue to red",
},
{ .name = "ctm-max",
.fb_colors = colors_rgb,
.ctm = { 100.0, 0.0, 0.0,
0.0, 100.0, 0.0,
0.0, 0.0, 100.0,
},
.desc = "Check the color transformation for maximum transparency",
},
{ .name = "ctm-negative",
.fb_colors = colors_rgb,
.ctm = {
-1.0, 0.0, 0.0,
0.0, -1.0, 0.0,
0.0, 0.0, -1.0,
},
.desc = "Check the color transformation for negative transparency",
},
{ .name = "ctm-0-25",
.iter = 5,
.fb_colors = colors_rgb,
.ctm = {
0.25, 0.0, 0.0,
0.0, 0.25, 0.0,
0.0, 0.0, 0.25,
},
.desc = "Check the color transformation for 0.25 transparency",
},
{ .name = "ctm-0-50",
.iter = 5,
.fb_colors = colors_rgb,
.ctm = {
0.5, 0.0, 0.0,
0.0, 0.5, 0.0,
0.0, 0.0, 0.5,
},
.desc = "Check the color transformation for 0.5 transparency",
},
{ .name = "ctm-0-75",
.iter = 7,
.fb_colors = colors_rgb,
.ctm = {
0.75, 0.0, 0.0,
0.0, 0.75, 0.0,
0.0, 0.0, 0.75,
},
.desc = "Check the color transformation for 0.75 transparency",
},
{ .name = "ctm-signed",
.fb_colors = colors_cmy,
.iter = 3,
.ctm = {
-0.25, 0.75, 0.75,
0.75, -0.25, 0.75,
0.75, 0.75, -0.25,
},
.desc = "Check the color transformation for correct signed handling",
},
};
int i;
for (i = 0; i < ARRAY_SIZE(gamma_degamma_tests); i++) {
igt_describe_f("%s", gamma_degamma_tests[i].desc);
igt_subtest_with_dynamic_f("%s", gamma_degamma_tests[i].name) {
for_each_pipe_with_valid_output(&data->display, pipe, data->output) {
igt_dynamic_f("pipe-%s-%s", kmstest_pipe_name(pipe),
igt_output_name(data->output))
run_gamma_degamma_tests_for_pipe(data, pipe,
gamma_degamma_tests[i].test_t);
}
}
}
for (i = 0; i < ARRAY_SIZE(ctm_tests); i++) {
igt_describe_f("%s", ctm_tests[i].desc);
igt_subtest_with_dynamic_f("%s", ctm_tests[i].name) {
for_each_pipe_with_valid_output(&data->display, pipe, data->output) {
igt_dynamic_f("pipe-%s-%s", kmstest_pipe_name(pipe),
igt_output_name(data->output))
run_ctm_tests_for_pipe(data, pipe,
ctm_tests[i].fb_colors,
ctm_tests[i].ctm,
ctm_tests[i].iter);
if (igt_run_in_simulation())
break;
}
}
}
igt_fixture
igt_require(data->display.is_atomic);
igt_describe("Verify that deep color works correctly");
igt_subtest_with_dynamic("deep-color") {
for_each_pipe(&data->display, pipe) {
run_deep_color_tests_for_pipe(data, pipe);
if (igt_run_in_simulation())
break;
}
}
}
igt_main
{
data_t data = {};
igt_fixture {
data.drm_fd = drm_open_driver_master(DRIVER_ANY);
if (is_intel_device(data.drm_fd))
data.devid = intel_get_drm_devid(data.drm_fd);
kmstest_set_vt_graphics_mode();
igt_display_require(&data.display, data.drm_fd);
}
igt_subtest_group
run_tests_for_pipe(&data);
igt_subtest_group
run_invalid_tests_for_pipe(&data);
igt_fixture {
igt_display_fini(&data.display);
drm_close_driver(data.drm_fd);
}
}
|