Patch based on a previous series by Shashank Sharma. This introduces optional properties to enable color correction at the pipe level. It relies on 3 transformations applied to every pixels displayed. First a lookup into a degamma table, then a multiplication of the rgb components by a 3x3 matrix and finally another lookup into a gamma table. The following properties can be added to a pipe : - DEGAMMA_LUT : blob containing degamma LUT - DEGAMMA_LUT_SIZE : number of elements in DEGAMMA_LUT - CTM : transformation matrix applied after the degamma LUT - GAMMA_LUT : blob containing gamma LUT - GAMMA_LUT_SIZE : number of elements in GAMMA_LUT DEGAMMA_LUT_SIZE and GAMMA_LUT_SIZE are read only properties, set by the driver to tell userspace applications what sizes should be the lookup tables in DEGAMMA_LUT and GAMMA_LUT. A helper is also provided so legacy gamma correction is redirected through these new properties. v2: Register LUT size properties as range v3: Fix round in drm_color_lut_get_value() helper More docs on how degamma/gamma properties are used v4: Update contributors v5: Rename CTM_MATRIX property to CTM (Doh!) Add legacy gamma_set atomic helper Describe CTM/LUT acronyms in the kernel doc v6: Fix missing blob unref in drm_atomic_helper_crtc_reset
Unified · Split
| @@ -1816,7 +1816,7 @@ void intel_crt_init(struct drm_device *dev) · 1815 unmodified lines | ||
| 1816 | 1816 | <td valign="top" >Description/Restrictions</td> |
| 1817 | 1817 | </tr> |
| 1818 | 1818 | <tr> |
| 1819 | − <td rowspan="37" valign="top" >DRM</td> | |
| 1819 | + <td rowspan="42" valign="top" >DRM</td> | |
| 1820 | 1820 | <td valign="top" >Generic</td> |
| 1821 | 1821 | <td valign="top" >“rotation”</td> |
| 1822 | 1822 | <td valign="top" >BITMASK</td> |
| @@ -2068,7 +2068,7 @@ void intel_crt_init(struct drm_device *dev) · 245 unmodified lines | ||
| 2068 | 2068 | <td valign="top" >property to suggest an Y offset for a connector</td> |
| 2069 | 2069 | </tr> |
| 2070 | 2070 | <tr> |
| 2071 | − <td rowspan="3" valign="top" >Optional</td> | |
| 2071 | + <td rowspan="8" valign="top" >Optional</td> | |
| 2072 | 2072 | <td valign="top" >“scaling mode”</td> |
| 2073 | 2073 | <td valign="top" >ENUM</td> |
| 2074 | 2074 | <td valign="top" >{ "None", "Full", "Center", "Full aspect" }</td> |
| @@ -2092,6 +2092,61 @@ void intel_crt_init(struct drm_device *dev) · 17 unmodified lines | ||
| 2092 | 2092 | <td valign="top" >TBD</td> |
| 2093 | 2093 | </tr> |
| 2094 | 2094 | <tr> |
| 2095 | + <td valign="top" >“DEGAMMA_LUT”</td> | |
| 2096 | + <td valign="top" >BLOB</td> | |
| 2097 | + <td valign="top" >0</td> | |
| 2098 | + <td valign="top" >CRTC</td> | |
| 2099 | + <td valign="top" >DRM property to set the degamma lookup table | |
| 2100 | + (LUT) mapping pixel data from the framebuffer before it is | |
| 2101 | + given to the transformation matrix. The data is an interpreted | |
| 2102 | + as an array of struct drm_color_lut elements. Hardware might | |
| 2103 | + choose not to use the full precision of the LUT elements nor | |
| 2104 | + use all the elements of the LUT (for example the hardware | |
| 2105 | + might choose to interpolate between LUT[0] and LUT[4]). </td> | |
| 2106 | + </tr> | |
| 2107 | + <tr> | |
| 2108 | + <td valign="top" >“DEGAMMA_LUT_SIZE”</td> | |
| 2109 | + <td valign="top" >RANGE | IMMUTABLE</td> | |
| 2110 | + <td valign="top" >Min=0, Max=UINT_MAX</td> | |
| 2111 | + <td valign="top" >CRTC</td> | |
| 2112 | + <td valign="top" >DRM property to gives the size of the lookup | |
| 2113 | + table to be set on the DEGAMMA_LUT property (the size depends | |
| 2114 | + on the underlying hardware).</td> | |
| 2115 | + </tr> | |
| 2116 | + <tr> | |
| 2117 | + <td valign="top" >“CTM”</td> | |
| 2118 | + <td valign="top" >BLOB</td> | |
| 2119 | + <td valign="top" >0</td> | |
| 2120 | + <td valign="top" >CRTC</td> | |
| 2121 | + <td valign="top" >DRM property to set the current | |
| 2122 | + transformation matrix (CTM) apply to pixel data after the | |
| 2123 | + lookup through the degamma LUT and before the lookup through | |
| 2124 | + the gamma LUT. The data is an interpreted as a struct | |
| 2125 | + drm_color_ctm.</td> | |
| 2126 | + </tr> | |
| 2127 | + <tr> | |
| 2128 | + <td valign="top" >“GAMMA_LUT”</td> | |
| 2129 | + <td valign="top" >BLOB</td> | |
| 2130 | + <td valign="top" >0</td> | |
| 2131 | + <td valign="top" >CRTC</td> | |
| 2132 | + <td valign="top" >DRM property to set the gamma lookup table | |
| 2133 | + (LUT) mapping pixel data after to the transformation matrix to | |
| 2134 | + data sent to the connector. The data is an interpreted as an | |
| 2135 | + array of struct drm_color_lut elements. Hardware might choose | |
| 2136 | + not to use the full precision of the LUT elements nor use all | |
| 2137 | + the elements of the LUT (for example the hardware might choose | |
| 2138 | + to interpolate between LUT[0] and LUT[4]).</td> | |
| 2139 | + </tr> | |
| 2140 | + <tr> | |
| 2141 | + <td valign="top" >“GAMMA_LUT_SIZE”</td> | |
| 2142 | + <td valign="top" >RANGE | IMMUTABLE</td> | |
| 2143 | + <td valign="top" >Min=0, Max=UINT_MAX</td> | |
| 2144 | + <td valign="top" >CRTC</td> | |
| 2145 | + <td valign="top" >DRM property to gives the size of the lookup | |
| 2146 | + table to be set on the GAMMA_LUT property (the size depends on | |
| 2147 | + the underlying hardware).</td> | |
| 2148 | + </tr> | |
| 2149 | + <tr> | |
| 2095 | 2150 | <td rowspan="20" valign="top" >i915</td> |
| 2096 | 2151 | <td rowspan="2" valign="top" >Generic</td> |
| 2097 | 2152 | <td valign="top" >"Broadcast RGB"</td> |
| @@ -28,6 +28,7 @@ · 27 unmodified lines | ||
| 28 | 28 | |
| 29 | 29 | #include <drm/drmP.h> |
| 30 | 30 | #include <drm/drm_atomic.h> |
| 31 | +#include <drm/drm_mode.h> | |
| 31 | 32 | #include <drm/drm_plane_helper.h> |
| 32 | 33 | |
| 33 | 34 | /** |
| @@ -387,6 +388,59 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state, · 353 unmodified lines | ||
| 387 | 388 | } |
| 388 | 389 | EXPORT_SYMBOL(drm_atomic_set_mode_prop_for_crtc); |
| 389 | 390 | |
| 391 | +/** | |
| 392 | + * drm_atomic_replace_property_blob - replace a blob property | |
| 393 | + * @blob: a pointer to the member blob to be replaced | |
| 394 | + * @new_blob: the new blob to replace with | |
| 395 | + * @expected_size: the expected size of the new blob | |
| 396 | + * @replaced: whether the blob has been replaced | |
| 397 | + * | |
| 398 | + * RETURNS: | |
| 399 | + * Zero on success, error code on failure | |
| 400 | + */ | |
| 401 | +static void | |
| 402 | +drm_atomic_replace_property_blob(struct drm_property_blob **blob, | |
| 403 | + struct drm_property_blob *new_blob, | |
| 404 | + bool *replaced) | |
| 405 | +{ | |
| 406 | + struct drm_property_blob *old_blob = *blob; | |
| 407 | + | |
| 408 | + if (old_blob == new_blob) | |
| 409 | + return; | |
| 410 | + | |
| 411 | + if (old_blob) | |
| 412 | + drm_property_unreference_blob(old_blob); | |
| 413 | + if (new_blob) | |
| 414 | + drm_property_reference_blob(new_blob); | |
| 415 | + *blob = new_blob; | |
| 416 | + *replaced = true; | |
| 417 | + | |
| 418 | + return; | |
| 419 | +} | |
| 420 | + | |
| 421 | +static int | |
| 422 | +drm_atomic_replace_property_blob_from_id(struct drm_crtc *crtc, | |
| 423 | + struct drm_property_blob **blob, | |
| 424 | + uint64_t blob_id, | |
| 425 | + ssize_t expected_size, | |
| 426 | + bool *replaced) | |
| 427 | +{ | |
| 428 | + struct drm_device *dev = crtc->dev; | |
| 429 | + struct drm_property_blob *new_blob = NULL; | |
| 430 | + | |
| 431 | + if (blob_id != 0) { | |
| 432 | + new_blob = drm_property_lookup_blob(dev, blob_id); | |
| 433 | + if (new_blob == NULL) | |
| 434 | + return -EINVAL; | |
| 435 | + if (expected_size > 0 && expected_size != new_blob->length) | |
| 436 | + return -EINVAL; | |
| 437 | + } | |
| 438 | + | |
| 439 | + drm_atomic_replace_property_blob(blob, new_blob, replaced); | |
| 440 | + | |
| 441 | + return 0; | |
| 442 | +} | |
| 443 | + | |
| 390 | 444 | /** |
| 391 | 445 | * drm_atomic_crtc_set_property - set property on CRTC |
| 392 | 446 | * @crtc: the drm CRTC to set a property on |
| @@ -409,6 +463,7 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc, · 16 unmodified lines | ||
| 409 | 463 | { |
| 410 | 464 | struct drm_device *dev = crtc->dev; |
| 411 | 465 | struct drm_mode_config *config = &dev->mode_config; |
| 466 | + bool replaced = false; | |
| 412 | 467 | int ret; |
| 413 | 468 | |
| 414 | 469 | if (property == config->prop_active) |
| @@ -419,8 +474,31 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc, · 4 unmodified lines | ||
| 419 | 474 | ret = drm_atomic_set_mode_prop_for_crtc(state, mode); |
| 420 | 475 | drm_property_unreference_blob(mode); |
| 421 | 476 | return ret; |
| 422 | − } | |
| 423 | − else if (crtc->funcs->atomic_set_property) | |
| 477 | + } else if (property == config->degamma_lut_property) { | |
| 478 | + ret = drm_atomic_replace_property_blob_from_id(crtc, | |
| 479 | + &state->degamma_lut, | |
| 480 | + val, | |
| 481 | + -1, | |
| 482 | + &replaced); | |
| 483 | + state->color_mgmt_changed = replaced; | |
| 484 | + return ret; | |
| 485 | + } else if (property == config->ctm_property) { | |
| 486 | + ret = drm_atomic_replace_property_blob_from_id(crtc, | |
| 487 | + &state->ctm, | |
| 488 | + val, | |
| 489 | + sizeof(struct drm_color_ctm), | |
| 490 | + &replaced); | |
| 491 | + state->color_mgmt_changed = replaced; | |
| 492 | + return ret; | |
| 493 | + } else if (property == config->gamma_lut_property) { | |
| 494 | + ret = drm_atomic_replace_property_blob_from_id(crtc, | |
| 495 | + &state->gamma_lut, | |
| 496 | + val, | |
| 497 | + -1, | |
| 498 | + &replaced); | |
| 499 | + state->color_mgmt_changed = replaced; | |
| 500 | + return ret; | |
| 501 | + } else if (crtc->funcs->atomic_set_property) | |
| 424 | 502 | return crtc->funcs->atomic_set_property(crtc, state, property, val); |
| 425 | 503 | else |
| 426 | 504 | return -EINVAL; |
| @@ -456,6 +534,12 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc, · 29 unmodified lines | ||
| 456 | 534 | *val = state->active; |
| 457 | 535 | else if (property == config->prop_mode_id) |
| 458 | 536 | *val = (state->mode_blob) ? state->mode_blob->base.id : 0; |
| 537 | + else if (property == config->degamma_lut_property) | |
| 538 | + *val = (state->degamma_lut) ? state->degamma_lut->base.id : 0; | |
| 539 | + else if (property == config->ctm_property) | |
| 540 | + *val = (state->ctm) ? state->ctm->base.id : 0; | |
| 541 | + else if (property == config->gamma_lut_property) | |
| 542 | + *val = (state->gamma_lut) ? state->gamma_lut->base.id : 0; | |
| 459 | 543 | else if (crtc->funcs->atomic_get_property) |
| 460 | 544 | return crtc->funcs->atomic_get_property(crtc, state, property, val); |
| 461 | 545 | else |
| @@ -2495,8 +2495,12 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_dpms); · 2494 unmodified lines | ||
| 2495 | 2495 | */ |
| 2496 | 2496 | void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc) |
| 2497 | 2497 | { |
| 2498 | − if (crtc->state) | |
| 2498 | + if (crtc->state) { | |
| 2499 | 2499 | drm_property_unreference_blob(crtc->state->mode_blob); |
| 2500 | + drm_property_unreference_blob(crtc->state->degamma_lut); | |
| 2501 | + drm_property_unreference_blob(crtc->state->ctm); | |
| 2502 | + drm_property_unreference_blob(crtc->state->gamma_lut); | |
| 2503 | + } | |
| 2500 | 2504 | kfree(crtc->state); |
| 2501 | 2505 | crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL); |
| 2502 | 2506 | |
| @@ -2520,10 +2524,17 @@ void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc, · 17 unmodified lines | ||
| 2520 | 2524 | |
| 2521 | 2525 | if (state->mode_blob) |
| 2522 | 2526 | drm_property_reference_blob(state->mode_blob); |
| 2527 | + if (state->degamma_lut) | |
| 2528 | + drm_property_reference_blob(state->degamma_lut); | |
| 2529 | + if (state->ctm) | |
| 2530 | + drm_property_reference_blob(state->ctm); | |
| 2531 | + if (state->gamma_lut) | |
| 2532 | + drm_property_reference_blob(state->gamma_lut); | |
| 2523 | 2533 | state->mode_changed = false; |
| 2524 | 2534 | state->active_changed = false; |
| 2525 | 2535 | state->planes_changed = false; |
| 2526 | 2536 | state->connectors_changed = false; |
| 2537 | + state->color_mgmt_changed = false; | |
| 2527 | 2538 | state->event = NULL; |
| 2528 | 2539 | } |
| 2529 | 2540 | EXPORT_SYMBOL(__drm_atomic_helper_crtc_duplicate_state); |
| @@ -2564,6 +2575,9 @@ void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc, · 34 unmodified lines | ||
| 2564 | 2575 | struct drm_crtc_state *state) |
| 2565 | 2576 | { |
| 2566 | 2577 | drm_property_unreference_blob(state->mode_blob); |
| 2578 | + drm_property_unreference_blob(state->degamma_lut); | |
| 2579 | + drm_property_unreference_blob(state->ctm); | |
| 2580 | + drm_property_unreference_blob(state->gamma_lut); | |
| 2567 | 2581 | } |
| 2568 | 2582 | EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state); |
| 2569 | 2583 | |
| @@ -2877,3 +2891,97 @@ void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector, · 307 unmodified lines | ||
| 2877 | 2891 | kfree(state); |
| 2878 | 2892 | } |
| 2879 | 2893 | EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state); |
| 2894 | + | |
| 2895 | +/** | |
| 2896 | + * drm_atomic_helper_legacy_gamma_set - set the legacy gamma correction table | |
| 2897 | + * @crtc: CRTC object | |
| 2898 | + * @red: red correction table | |
| 2899 | + * @green: green correction table | |
| 2900 | + * @blue: green correction table | |
| 2901 | + * @start: | |
| 2902 | + * @size: size of the tables | |
| 2903 | + * | |
| 2904 | + * Implements support for legacy gamma correction table for drivers | |
| 2905 | + * that support color management through the DEGAMMA_LUT/GAMMA_LUT | |
| 2906 | + * properties. | |
| 2907 | + */ | |
| 2908 | +void drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc, | |
| 2909 | + u16 *red, u16 *green, u16 *blue, | |
| 2910 | + uint32_t start, uint32_t size) | |
| 2911 | +{ | |
| 2912 | + struct drm_device *dev = crtc->dev; | |
| 2913 | + struct drm_mode_config *config = &dev->mode_config; | |
| 2914 | + struct drm_atomic_state *state; | |
| 2915 | + struct drm_crtc_state *crtc_state; | |
| 2916 | + struct drm_property_blob *blob = NULL; | |
| 2917 | + struct drm_color_lut *blob_data; | |
| 2918 | + int i, ret = 0; | |
| 2919 | + | |
| 2920 | + state = drm_atomic_state_alloc(crtc->dev); | |
| 2921 | + if (!state) | |
| 2922 | + return; | |
| 2923 | + | |
| 2924 | + blob = drm_property_create_blob(dev, | |
| 2925 | + sizeof(struct drm_color_lut) * size, | |
| 2926 | + NULL); | |
| 2927 | + if (!blob) { | |
| 2928 | + ret = -ENOMEM; | |
| 2929 | + goto fail; | |
| 2930 | + } | |
| 2931 | + | |
| 2932 | + /* Prepare GAMMA_LUT with the legacy values. */ | |
| 2933 | + blob_data = (struct drm_color_lut *) blob->data; | |
| 2934 | + for (i = 0; i < size; i++) { | |
| 2935 | + blob_data[i].red = red[i]; | |
| 2936 | + blob_data[i].green = green[i]; | |
| 2937 | + blob_data[i].blue = blue[i]; | |
| 2938 | + } | |
| 2939 | + | |
| 2940 | + state->acquire_ctx = crtc->dev->mode_config.acquire_ctx; | |
| 2941 | +retry: | |
| 2942 | + crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
| 2943 | + if (IS_ERR(crtc_state)) { | |
| 2944 | + ret = PTR_ERR(crtc_state); | |
| 2945 | + goto fail; | |
| 2946 | + } | |
| 2947 | + | |
| 2948 | + /* Reset DEGAMMA_LUT and CTM properties. */ | |
| 2949 | + ret = drm_atomic_crtc_set_property(crtc, crtc_state, | |
| 2950 | + config->degamma_lut_property, 0); | |
| 2951 | + if (ret) | |
| 2952 | + goto fail; | |
| 2953 | + | |
| 2954 | + ret = drm_atomic_crtc_set_property(crtc, crtc_state, | |
| 2955 | + config->ctm_property, 0); | |
| 2956 | + if (ret) | |
| 2957 | + goto fail; | |
| 2958 | + | |
| 2959 | + ret = drm_atomic_crtc_set_property(crtc, crtc_state, | |
| 2960 | + config->gamma_lut_property, blob->base.id); | |
| 2961 | + if (ret) | |
| 2962 | + goto fail; | |
| 2963 | + | |
| 2964 | + ret = drm_atomic_commit(state); | |
| 2965 | + if (ret) | |
| 2966 | + goto fail; | |
| 2967 | + | |
| 2968 | + /* Driver takes ownership of state on successful commit. */ | |
| 2969 | + | |
| 2970 | + drm_property_unreference_blob(blob); | |
| 2971 | + | |
| 2972 | + return; | |
| 2973 | +fail: | |
| 2974 | + if (ret == -EDEADLK) | |
| 2975 | + goto backoff; | |
| 2976 | + | |
| 2977 | + drm_atomic_state_free(state); | |
| 2978 | + drm_property_unreference_blob(blob); | |
| 2979 | + | |
| 2980 | + return; | |
| 2981 | +backoff: | |
| 2982 | + drm_atomic_state_clear(state); | |
| 2983 | + drm_atomic_legacy_backoff(state); | |
| 2984 | + | |
| 2985 | + goto retry; | |
| 2986 | +} | |
| 2987 | +EXPORT_SYMBOL(drm_atomic_helper_legacy_gamma_set); | |
| @@ -1563,6 +1563,41 @@ static int drm_mode_create_standard_properties(struct drm_device *dev) · 1562 unmodified lines | ||
| 1563 | 1563 | return -ENOMEM; |
| 1564 | 1564 | dev->mode_config.prop_mode_id = prop; |
| 1565 | 1565 | |
| 1566 | + prop = drm_property_create(dev, | |
| 1567 | + DRM_MODE_PROP_BLOB, | |
| 1568 | + "DEGAMMA_LUT", 0); | |
| 1569 | + if (!prop) | |
| 1570 | + return -ENOMEM; | |
| 1571 | + dev->mode_config.degamma_lut_property = prop; | |
| 1572 | + | |
| 1573 | + prop = drm_property_create_range(dev, | |
| 1574 | + DRM_MODE_PROP_IMMUTABLE, | |
| 1575 | + "DEGAMMA_LUT_SIZE", 0, UINT_MAX); | |
| 1576 | + if (!prop) | |
| 1577 | + return -ENOMEM; | |
| 1578 | + dev->mode_config.degamma_lut_size_property = prop; | |
| 1579 | + | |
| 1580 | + prop = drm_property_create(dev, | |
| 1581 | + DRM_MODE_PROP_BLOB, | |
| 1582 | + "CTM", 0); | |
| 1583 | + if (!prop) | |
| 1584 | + return -ENOMEM; | |
| 1585 | + dev->mode_config.ctm_property = prop; | |
| 1586 | + | |
| 1587 | + prop = drm_property_create(dev, | |
| 1588 | + DRM_MODE_PROP_BLOB, | |
| 1589 | + "GAMMA_LUT", 0); | |
| 1590 | + if (!prop) | |
| 1591 | + return -ENOMEM; | |
| 1592 | + dev->mode_config.gamma_lut_property = prop; | |
| 1593 | + | |
| 1594 | + prop = drm_property_create_range(dev, | |
| 1595 | + DRM_MODE_PROP_IMMUTABLE, | |
| 1596 | + "GAMMA_LUT_SIZE", 0, UINT_MAX); | |
| 1597 | + if (!prop) | |
| 1598 | + return -ENOMEM; | |
| 1599 | + dev->mode_config.gamma_lut_size_property = prop; | |
| 1600 | + | |
| 1566 | 1601 | return 0; |
| 1567 | 1602 | } |
| 1568 | 1603 | |
| @@ -1075,3 +1075,36 @@ int drm_helper_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, · 1074 unmodified lines | ||
| 1075 | 1075 | return drm_plane_helper_commit(plane, plane_state, old_fb); |
| 1076 | 1076 | } |
| 1077 | 1077 | EXPORT_SYMBOL(drm_helper_crtc_mode_set_base); |
| 1078 | + | |
| 1079 | +/** | |
| 1080 | + * drm_helper_crtc_enable_color_mgmt - enable color management properties | |
| 1081 | + * @crtc: DRM CRTC | |
| 1082 | + * @degamma_lut_size: the size of the degamma lut (before CSC) | |
| 1083 | + * @gamma_lut_size: the size of the gamma lut (after CSC) | |
| 1084 | + * | |
| 1085 | + * This function lets the driver enable the color correction properties on a | |
| 1086 | + * CRTC. This includes 3 degamma, csc and gamma properties that userspace can | |
| 1087 | + * set and 2 size properties to inform the userspace of the lut sizes. | |
| 1088 | + */ | |
| 1089 | +void drm_helper_crtc_enable_color_mgmt(struct drm_crtc *crtc, | |
| 1090 | + int degamma_lut_size, | |
| 1091 | + int gamma_lut_size) | |
| 1092 | +{ | |
| 1093 | + struct drm_device *dev = crtc->dev; | |
| 1094 | + struct drm_mode_config *config = &dev->mode_config; | |
| 1095 | + | |
| 1096 | + drm_object_attach_property(&crtc->base, | |
| 1097 | + config->degamma_lut_property, 0); | |
| 1098 | + drm_object_attach_property(&crtc->base, | |
| 1099 | + config->ctm_property, 0); | |
| 1100 | + drm_object_attach_property(&crtc->base, | |
| 1101 | + config->gamma_lut_property, 0); | |
| 1102 | + | |
| 1103 | + drm_object_attach_property(&crtc->base, | |
| 1104 | + config->degamma_lut_size_property, | |
| 1105 | + degamma_lut_size); | |
| 1106 | + drm_object_attach_property(&crtc->base, | |
| 1107 | + config->gamma_lut_size_property, | |
| 1108 | + gamma_lut_size); | |
| 1109 | +} | |
| 1110 | +EXPORT_SYMBOL(drm_helper_crtc_enable_color_mgmt); | |
| @@ -146,6 +146,9 @@ __drm_atomic_helper_connector_destroy_state(struct drm_connector *connector, · 145 unmodified lines | ||
| 146 | 146 | struct drm_connector_state *state); |
| 147 | 147 | void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector, |
| 148 | 148 | struct drm_connector_state *state); |
| 149 | +void drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc, | |
| 150 | + u16 *red, u16 *green, u16 *blue, | |
| 151 | + uint32_t start, uint32_t size); | |
| 149 | 152 | |
| 150 | 153 | /** |
| 151 | 154 | * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC |
| @@ -305,6 +305,8 @@ struct drm_plane_helper_funcs; · 304 unmodified lines | ||
| 305 | 305 | * @mode_changed: crtc_state->mode or crtc_state->enable has been changed |
| 306 | 306 | * @active_changed: crtc_state->active has been toggled. |
| 307 | 307 | * @connectors_changed: connectors to this crtc have been updated |
| 308 | + * @color_mgmt_changed: color management properties have changed (degamma or | |
| 309 | + * gamma LUT or CSC matrix) | |
| 308 | 310 | * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes |
| 309 | 311 | * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors |
| 310 | 312 | * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders |
| @@ -312,6 +314,11 @@ struct drm_plane_helper_funcs; · 1 unmodified line | ||
| 312 | 314 | * update to ensure framebuffer cleanup isn't done too early |
| 313 | 315 | * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings |
| 314 | 316 | * @mode: current mode timings |
| 317 | + * @degamma_lut: Lookup table for converting framebuffer pixel data | |
| 318 | + * before apply the conversion matrix | |
| 319 | + * @ctm: Transformation matrix | |
| 320 | + * @gamma_lut: Lookup table for converting pixel data after the | |
| 321 | + * conversion matrix | |
| 315 | 322 | * @event: optional pointer to a DRM event to signal upon completion of the |
| 316 | 323 | * state update |
| 317 | 324 | * @state: backpointer to global drm_atomic_state |
| @@ -333,6 +340,7 @@ struct drm_crtc_state { · 15 unmodified lines | ||
| 333 | 340 | bool mode_changed : 1; |
| 334 | 341 | bool active_changed : 1; |
| 335 | 342 | bool connectors_changed : 1; |
| 343 | + bool color_mgmt_changed : 1; | |
| 336 | 344 | |
| 337 | 345 | /* attached planes bitmask: |
| 338 | 346 | * WARNING: transitional helpers do not maintain plane_mask so |
| @@ -355,6 +363,11 @@ struct drm_crtc_state { · 16 unmodified lines | ||
| 355 | 363 | /* blob property to expose current mode to atomic userspace */ |
| 356 | 364 | struct drm_property_blob *mode_blob; |
| 357 | 365 | |
| 366 | + /* blob property to expose color management to userspace */ | |
| 367 | + struct drm_property_blob *degamma_lut; | |
| 368 | + struct drm_property_blob *ctm; | |
| 369 | + struct drm_property_blob *gamma_lut; | |
| 370 | + | |
| 358 | 371 | struct drm_pending_vblank_event *event; |
| 359 | 372 | |
| 360 | 373 | struct drm_atomic_state *state; |
| @@ -757,7 +770,7 @@ struct drm_crtc { · 396 unmodified lines | ||
| 757 | 770 | int x, y; |
| 758 | 771 | const struct drm_crtc_funcs *funcs; |
| 759 | 772 | |
| 760 | − /* CRTC gamma size for reporting to userspace */ | |
| 773 | + /* Legacy FB CRTC gamma size for reporting to userspace */ | |
| 761 | 774 | uint32_t gamma_size; |
| 762 | 775 | uint16_t *gamma_store; |
| 763 | 776 | |
| @@ -2027,6 +2040,15 @@ struct drm_mode_config_funcs { · 1263 unmodified lines | ||
| 2027 | 2040 | * @property_blob_list: list of all the blob property objects |
| 2028 | 2041 | * @blob_lock: mutex for blob property allocation and management |
| 2029 | 2042 | * @*_property: core property tracking |
| 2043 | + * @degamma_lut_property: LUT used to convert the framebuffer's colors to linear | |
| 2044 | + * gamma | |
| 2045 | + * @degamma_lut_size_property: size of the degamma LUT as supported by the | |
| 2046 | + * driver (read-only) | |
| 2047 | + * @ctm_property: Matrix used to convert colors after the lookup in the | |
| 2048 | + * degamma LUT | |
| 2049 | + * @gamma_lut_property: LUT used to convert the colors, after the CSC matrix, to | |
| 2050 | + * the gamma space of the connected screen (read-only) | |
| 2051 | + * @gamma_lut_size_property: size of the gamma LUT as supported by the driver | |
| 2030 | 2052 | * @preferred_depth: preferred RBG pixel depth, used by fb helpers |
| 2031 | 2053 | * @prefer_shadow: hint to userspace to prefer shadow-fb rendering |
| 2032 | 2054 | * @async_page_flip: does this device support async flips on the primary plane? |
| @@ -2128,6 +2150,13 @@ struct drm_mode_config { · 95 unmodified lines | ||
| 2128 | 2150 | struct drm_property *aspect_ratio_property; |
| 2129 | 2151 | struct drm_property *dirty_info_property; |
| 2130 | 2152 | |
| 2153 | + /* Optional color correction properties */ | |
| 2154 | + struct drm_property *degamma_lut_property; | |
| 2155 | + struct drm_property *degamma_lut_size_property; | |
| 2156 | + struct drm_property *ctm_property; | |
| 2157 | + struct drm_property *gamma_lut_property; | |
| 2158 | + struct drm_property *gamma_lut_size_property; | |
| 2159 | + | |
| 2131 | 2160 | /* properties for virtual machine layout */ |
| 2132 | 2161 | struct drm_property *suggested_x_property; |
| 2133 | 2162 | struct drm_property *suggested_y_property; |
| @@ -2550,6 +2579,21 @@ static inline struct drm_property *drm_property_find(struct drm_device *dev, · 416 unmodified lines | ||
| 2550 | 2579 | return mo ? obj_to_property(mo) : NULL; |
| 2551 | 2580 | } |
| 2552 | 2581 | |
| 2582 | +/* | |
| 2583 | + * Extract a degamma/gamma LUT value provided by user and round it to the | |
| 2584 | + * precision supported by the hardware. | |
| 2585 | + */ | |
| 2586 | +static inline uint32_t drm_color_lut_extract(uint32_t user_input, | |
| 2587 | + uint32_t bit_precision) | |
| 2588 | +{ | |
| 2589 | + uint32_t val = user_input + (1 << (16 - bit_precision - 1)); | |
| 2590 | + uint32_t max = 0xffff >> (16 - bit_precision); | |
| 2591 | + | |
| 2592 | + val >>= 16 - bit_precision; | |
| 2593 | + | |
| 2594 | + return clamp_val(val, 0, max); | |
| 2595 | +} | |
| 2596 | + | |
| 2553 | 2597 | /* Plane list iterator for legacy (overlay only) planes. */ |
| 2554 | 2598 | #define drm_for_each_legacy_plane(plane, dev) \ |
| 2555 | 2599 | list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \ |
| @@ -48,6 +48,9 @@ extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, · 47 unmodified lines | ||
| 48 | 48 | struct drm_display_mode *mode, |
| 49 | 49 | int x, int y, |
| 50 | 50 | struct drm_framebuffer *old_fb); |
| 51 | +extern void drm_helper_crtc_enable_color_mgmt(struct drm_crtc *crtc, | |
| 52 | + int degamma_lut_size, | |
| 53 | + int gamma_lut_size); | |
| 51 | 54 | extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc); |
| 52 | 55 | extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder); |
| 53 | 56 | |
| @@ -487,6 +487,21 @@ struct drm_mode_crtc_lut { · 486 unmodified lines | ||
| 487 | 487 | __u64 blue; |
| 488 | 488 | }; |
| 489 | 489 | |
| 490 | +struct drm_color_ctm { | |
| 491 | + /* Conversion matrix in S31.32 format. */ | |
| 492 | + __s64 matrix[9]; | |
| 493 | +}; | |
| 494 | + | |
| 495 | +struct drm_color_lut { | |
| 496 | + /* | |
| 497 | + * Data is U0.16 fixed point format. | |
| 498 | + */ | |
| 499 | + __u16 red; | |
| 500 | + __u16 green; | |
| 501 | + __u16 blue; | |
| 502 | + __u16 reserved; | |
| 503 | +}; | |
| 504 | + | |
| 490 | 505 | #define DRM_MODE_PAGE_FLIP_EVENT 0x01 |
| 491 | 506 | #define DRM_MODE_PAGE_FLIP_ASYNC 0x02 |
| 492 | 507 | #define DRM_MODE_PAGE_FLIP_FLAGS (DRM_MODE_PAGE_FLIP_EVENT|DRM_MODE_PAGE_FLIP_ASYNC) |