History

drm: introduce pipe color correction properties

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

Lionel Landwerlin committed 10 years ago

Commit 5488dc11 parent 9b8d1e59 files · +386 −6Browse files

Unified · Split

9 files
  1. Documentation/DocBook/gpu.tmpl +57 −2
  2. drivers/gpu/drm/drm_atomic.c +86 −2
  3. drivers/gpu/drm/drm_atomic_helper.c +109 −1
  4. drivers/gpu/drm/drm_crtc.c +35 −0
  5. drivers/gpu/drm/drm_crtc_helper.c +33 −0
  6. include/drm/drm_atomic_helper.h +3 −0
  7. include/drm/drm_crtc.h +45 −1
  8. include/drm/drm_crtc_helper.h +3 −0
  9. include/uapi/drm/drm_mode.h +15 −0
Documentation/DocBook/gpu.tmpl+57−2
@@ -1816,7 +1816,7 @@ void intel_crt_init(struct drm_device *dev) · 1815 unmodified lines
1816 <td valign="top" >Description/Restrictions</td>1816 <td valign="top" >Description/Restrictions</td>
1817 </tr>1817 </tr>
1818 <tr>1818 <tr>
1819 <td rowspan="37" valign="top" >DRM</td>1819 <td rowspan="42" valign="top" >DRM</td>
1820 <td valign="top" >Generic</td>1820 <td valign="top" >Generic</td>
1821 <td valign="top" >“rotation”</td>1821 <td valign="top" >“rotation”</td>
1822 <td valign="top" >BITMASK</td>1822 <td valign="top" >BITMASK</td>
@@ -2068,7 +2068,7 @@ void intel_crt_init(struct drm_device *dev) · 245 unmodified lines
2068 <td valign="top" >property to suggest an Y offset for a connector</td>2068 <td valign="top" >property to suggest an Y offset for a connector</td>
2069 </tr>2069 </tr>
2070 <tr>2070 <tr>
2071 <td rowspan="3" valign="top" >Optional</td>2071 <td rowspan="8" valign="top" >Optional</td>
2072 <td valign="top" >“scaling mode”</td>2072 <td valign="top" >“scaling mode”</td>
2073 <td valign="top" >ENUM</td>2073 <td valign="top" >ENUM</td>
2074 <td valign="top" >{ "None", "Full", "Center", "Full aspect" }</td>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 <td valign="top" >TBD</td>2092 <td valign="top" >TBD</td>
2093 </tr>2093 </tr>
2094 <tr>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 <td rowspan="20" valign="top" >i915</td>2150 <td rowspan="20" valign="top" >i915</td>
2096 <td rowspan="2" valign="top" >Generic</td>2151 <td rowspan="2" valign="top" >Generic</td>
2097 <td valign="top" >"Broadcast RGB"</td>2152 <td valign="top" >"Broadcast RGB"</td>
drivers/gpu/drm/drm_atomic.c+86−2
@@ -28,6 +28,7 @@ · 27 unmodified lines
28 28
29#include <drm/drmP.h>29#include <drm/drmP.h>
30#include <drm/drm_atomic.h>30#include <drm/drm_atomic.h>
31#include <drm/drm_mode.h>
31#include <drm/drm_plane_helper.h>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}
388EXPORT_SYMBOL(drm_atomic_set_mode_prop_for_crtc);389EXPORT_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 */
401static void
402drm_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
421static int
422drm_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 * drm_atomic_crtc_set_property - set property on CRTC445 * drm_atomic_crtc_set_property - set property on CRTC
392 * @crtc: the drm CRTC to set a property on446 * @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 struct drm_device *dev = crtc->dev;464 struct drm_device *dev = crtc->dev;
411 struct drm_mode_config *config = &dev->mode_config;465 struct drm_mode_config *config = &dev->mode_config;
466 bool replaced = false;
412 int ret;467 int ret;
413 468
414 if (property == config->prop_active)469 if (property == config->prop_active)
@@ -419,8 +474,31 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc, · 4 unmodified lines
419 ret = drm_atomic_set_mode_prop_for_crtc(state, mode);474 ret = drm_atomic_set_mode_prop_for_crtc(state, mode);
420 drm_property_unreference_blob(mode);475 drm_property_unreference_blob(mode);
421 return ret;476 return ret;
422 }477 } else if (property == config->degamma_lut_property) {
423 else if (crtc->funcs->atomic_set_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 return crtc->funcs->atomic_set_property(crtc, state, property, val);502 return crtc->funcs->atomic_set_property(crtc, state, property, val);
425 else503 else
426 return -EINVAL;504 return -EINVAL;
@@ -456,6 +534,12 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc, · 29 unmodified lines
456 *val = state->active;534 *val = state->active;
457 else if (property == config->prop_mode_id)535 else if (property == config->prop_mode_id)
458 *val = (state->mode_blob) ? state->mode_blob->base.id : 0;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 else if (crtc->funcs->atomic_get_property)543 else if (crtc->funcs->atomic_get_property)
460 return crtc->funcs->atomic_get_property(crtc, state, property, val);544 return crtc->funcs->atomic_get_property(crtc, state, property, val);
461 else545 else
drivers/gpu/drm/drm_atomic_helper.c+109−1
@@ -2495,8 +2495,12 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_dpms); · 2494 unmodified lines
2495 */2495 */
2496void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)2496void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)
2497{2497{
2498 if (crtc->state)2498 if (crtc->state) {
2499 drm_property_unreference_blob(crtc->state->mode_blob);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 kfree(crtc->state);2504 kfree(crtc->state);
2501 crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL);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 if (state->mode_blob)2525 if (state->mode_blob)
2522 drm_property_reference_blob(state->mode_blob);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 state->mode_changed = false;2533 state->mode_changed = false;
2524 state->active_changed = false;2534 state->active_changed = false;
2525 state->planes_changed = false;2535 state->planes_changed = false;
2526 state->connectors_changed = false;2536 state->connectors_changed = false;
2537 state->color_mgmt_changed = false;
2527 state->event = NULL;2538 state->event = NULL;
2528}2539}
2529EXPORT_SYMBOL(__drm_atomic_helper_crtc_duplicate_state);2540EXPORT_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 struct drm_crtc_state *state)2575 struct drm_crtc_state *state)
2565{2576{
2566 drm_property_unreference_blob(state->mode_blob);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}
2568EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state);2582EXPORT_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 kfree(state);2891 kfree(state);
2878}2892}
2879EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);2893EXPORT_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 */
2908void 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;
2941retry:
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;
2973fail:
2974 if (ret == -EDEADLK)
2975 goto backoff;
2976
2977 drm_atomic_state_free(state);
2978 drm_property_unreference_blob(blob);
2979
2980 return;
2981backoff:
2982 drm_atomic_state_clear(state);
2983 drm_atomic_legacy_backoff(state);
2984
2985 goto retry;
2986}
2987EXPORT_SYMBOL(drm_atomic_helper_legacy_gamma_set);
drivers/gpu/drm/drm_crtc.c+35−0
@@ -1563,6 +1563,41 @@ static int drm_mode_create_standard_properties(struct drm_device *dev) · 1562 unmodified lines
1563 return -ENOMEM;1563 return -ENOMEM;
1564 dev->mode_config.prop_mode_id = prop;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 return 0;1601 return 0;
1567}1602}
1568 1603
drivers/gpu/drm/drm_crtc_helper.c+33−0
@@ -1075,3 +1075,36 @@ int drm_helper_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, · 1074 unmodified lines
1075 return drm_plane_helper_commit(plane, plane_state, old_fb);1075 return drm_plane_helper_commit(plane, plane_state, old_fb);
1076}1076}
1077EXPORT_SYMBOL(drm_helper_crtc_mode_set_base);1077EXPORT_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 */
1089void 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}
1110EXPORT_SYMBOL(drm_helper_crtc_enable_color_mgmt);
include/drm/drm_atomic_helper.h+3−0
@@ -146,6 +146,9 @@ __drm_atomic_helper_connector_destroy_state(struct drm_connector *connector, · 145 unmodified lines
146 struct drm_connector_state *state);146 struct drm_connector_state *state);
147void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,147void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
148 struct drm_connector_state *state);148 struct drm_connector_state *state);
149void 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 * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC154 * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC
include/drm/drm_crtc.h+45−1
@@ -305,6 +305,8 @@ struct drm_plane_helper_funcs; · 304 unmodified lines
305 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed305 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
306 * @active_changed: crtc_state->active has been toggled.306 * @active_changed: crtc_state->active has been toggled.
307 * @connectors_changed: connectors to this crtc have been updated307 * @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 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes310 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
309 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors311 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
310 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders312 * @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 * update to ensure framebuffer cleanup isn't done too early314 * update to ensure framebuffer cleanup isn't done too early
313 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings315 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
314 * @mode: current mode timings316 * @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 * @event: optional pointer to a DRM event to signal upon completion of the322 * @event: optional pointer to a DRM event to signal upon completion of the
316 * state update323 * state update
317 * @state: backpointer to global drm_atomic_state324 * @state: backpointer to global drm_atomic_state
@@ -333,6 +340,7 @@ struct drm_crtc_state { · 15 unmodified lines
333 bool mode_changed : 1;340 bool mode_changed : 1;
334 bool active_changed : 1;341 bool active_changed : 1;
335 bool connectors_changed : 1;342 bool connectors_changed : 1;
343 bool color_mgmt_changed : 1;
336 344
337 /* attached planes bitmask:345 /* attached planes bitmask:
338 * WARNING: transitional helpers do not maintain plane_mask so346 * WARNING: transitional helpers do not maintain plane_mask so
@@ -355,6 +363,11 @@ struct drm_crtc_state { · 16 unmodified lines
355 /* blob property to expose current mode to atomic userspace */363 /* blob property to expose current mode to atomic userspace */
356 struct drm_property_blob *mode_blob;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 struct drm_pending_vblank_event *event;371 struct drm_pending_vblank_event *event;
359 372
360 struct drm_atomic_state *state;373 struct drm_atomic_state *state;
@@ -757,7 +770,7 @@ struct drm_crtc { · 396 unmodified lines
757 int x, y;770 int x, y;
758 const struct drm_crtc_funcs *funcs;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 uint32_t gamma_size;774 uint32_t gamma_size;
762 uint16_t *gamma_store;775 uint16_t *gamma_store;
763 776
@@ -2027,6 +2040,15 @@ struct drm_mode_config_funcs { · 1263 unmodified lines
2027 * @property_blob_list: list of all the blob property objects2040 * @property_blob_list: list of all the blob property objects
2028 * @blob_lock: mutex for blob property allocation and management2041 * @blob_lock: mutex for blob property allocation and management
2029 * @*_property: core property tracking2042 * @*_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 * @preferred_depth: preferred RBG pixel depth, used by fb helpers2052 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2031 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering2053 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2032 * @async_page_flip: does this device support async flips on the primary plane?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 struct drm_property *aspect_ratio_property;2150 struct drm_property *aspect_ratio_property;
2129 struct drm_property *dirty_info_property;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 /* properties for virtual machine layout */2160 /* properties for virtual machine layout */
2132 struct drm_property *suggested_x_property;2161 struct drm_property *suggested_x_property;
2133 struct drm_property *suggested_y_property;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 return mo ? obj_to_property(mo) : NULL;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 */
2586static 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/* Plane list iterator for legacy (overlay only) planes. */2597/* Plane list iterator for legacy (overlay only) planes. */
2554#define drm_for_each_legacy_plane(plane, dev) \2598#define drm_for_each_legacy_plane(plane, dev) \
2555 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \2599 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
include/drm/drm_crtc_helper.h+3−0
@@ -48,6 +48,9 @@ extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, · 47 unmodified lines
48 struct drm_display_mode *mode,48 struct drm_display_mode *mode,
49 int x, int y,49 int x, int y,
50 struct drm_framebuffer *old_fb);50 struct drm_framebuffer *old_fb);
51extern void drm_helper_crtc_enable_color_mgmt(struct drm_crtc *crtc,
52 int degamma_lut_size,
53 int gamma_lut_size);
51extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc);54extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc);
52extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder);55extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder);
53 56
include/uapi/drm/drm_mode.h+15−0
@@ -487,6 +487,21 @@ struct drm_mode_crtc_lut { · 486 unmodified lines
487 __u64 blue;487 __u64 blue;
488};488};
489 489
490struct drm_color_ctm {
491 /* Conversion matrix in S31.32 format. */
492 __s64 matrix[9];
493};
494
495struct 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#define DRM_MODE_PAGE_FLIP_EVENT 0x01505#define DRM_MODE_PAGE_FLIP_EVENT 0x01
491#define DRM_MODE_PAGE_FLIP_ASYNC 0x02506#define DRM_MODE_PAGE_FLIP_ASYNC 0x02
492#define DRM_MODE_PAGE_FLIP_FLAGS (DRM_MODE_PAGE_FLIP_EVENT|DRM_MODE_PAGE_FLIP_ASYNC)507#define DRM_MODE_PAGE_FLIP_FLAGS (DRM_MODE_PAGE_FLIP_EVENT|DRM_MODE_PAGE_FLIP_ASYNC)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t