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
18161816 <td valign="top" >Description/Restrictions</td>
18171817 </tr>
18181818 <tr>
1819− <td rowspan="37" valign="top" >DRM</td>
1819+ <td rowspan="42" valign="top" >DRM</td>
18201820 <td valign="top" >Generic</td>
18211821 <td valign="top" >“rotation”</td>
18221822 <td valign="top" >BITMASK</td>
@@ -2068,7 +2068,7 @@ void intel_crt_init(struct drm_device *dev) · 245 unmodified lines
20682068 <td valign="top" >property to suggest an Y offset for a connector</td>
20692069 </tr>
20702070 <tr>
2071− <td rowspan="3" valign="top" >Optional</td>
2071+ <td rowspan="8" valign="top" >Optional</td>
20722072 <td valign="top" >“scaling mode”</td>
20732073 <td valign="top" >ENUM</td>
20742074 <td valign="top" >{ "None", "Full", "Center", "Full aspect" }</td>
@@ -2092,6 +2092,61 @@ void intel_crt_init(struct drm_device *dev) · 17 unmodified lines
20922092 <td valign="top" >TBD</td>
20932093 </tr>
20942094 <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>
20952150 <td rowspan="20" valign="top" >i915</td>
20962151 <td rowspan="2" valign="top" >Generic</td>
20972152 <td valign="top" >"Broadcast RGB"</td>
drivers/gpu/drm/drm_atomic.c+86−2
@@ -28,6 +28,7 @@ · 27 unmodified lines
2828
2929 #include <drm/drmP.h>
3030 #include <drm/drm_atomic.h>
31+#include <drm/drm_mode.h>
3132 #include <drm/drm_plane_helper.h>
3233
3334 /**
@@ -387,6 +388,59 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state, · 353 unmodified lines
387388 }
388389 EXPORT_SYMBOL(drm_atomic_set_mode_prop_for_crtc);
389390
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+
390444 /**
391445 * drm_atomic_crtc_set_property - set property on CRTC
392446 * @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
409463 {
410464 struct drm_device *dev = crtc->dev;
411465 struct drm_mode_config *config = &dev->mode_config;
466+ bool replaced = false;
412467 int ret;
413468
414469 if (property == config->prop_active)
@@ -419,8 +474,31 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc, · 4 unmodified lines
419474 ret = drm_atomic_set_mode_prop_for_crtc(state, mode);
420475 drm_property_unreference_blob(mode);
421476 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)
424502 return crtc->funcs->atomic_set_property(crtc, state, property, val);
425503 else
426504 return -EINVAL;
@@ -456,6 +534,12 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc, · 29 unmodified lines
456534 *val = state->active;
457535 else if (property == config->prop_mode_id)
458536 *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;
459543 else if (crtc->funcs->atomic_get_property)
460544 return crtc->funcs->atomic_get_property(crtc, state, property, val);
461545 else
drivers/gpu/drm/drm_atomic_helper.c+109−1
@@ -2495,8 +2495,12 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_dpms); · 2494 unmodified lines
24952495 */
24962496 void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)
24972497 {
2498− if (crtc->state)
2498+ if (crtc->state) {
24992499 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+ }
25002504 kfree(crtc->state);
25012505 crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL);
25022506
@@ -2520,10 +2524,17 @@ void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc, · 17 unmodified lines
25202524
25212525 if (state->mode_blob)
25222526 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);
25232533 state->mode_changed = false;
25242534 state->active_changed = false;
25252535 state->planes_changed = false;
25262536 state->connectors_changed = false;
2537+ state->color_mgmt_changed = false;
25272538 state->event = NULL;
25282539 }
25292540 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
25642575 struct drm_crtc_state *state)
25652576 {
25662577 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);
25672581 }
25682582 EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state);
25692583
@@ -2877,3 +2891,97 @@ void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector, · 307 unmodified lines
28772891 kfree(state);
28782892 }
28792893 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);
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
15631563 return -ENOMEM;
15641564 dev->mode_config.prop_mode_id = prop;
15651565
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+
15661601 return 0;
15671602 }
15681603
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
10751075 return drm_plane_helper_commit(plane, plane_state, old_fb);
10761076 }
10771077 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);
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
146146 struct drm_connector_state *state);
147147 void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
148148 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);
149152
150153 /**
151154 * 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
305305 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
306306 * @active_changed: crtc_state->active has been toggled.
307307 * @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)
308310 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
309311 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
310312 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
@@ -312,6 +314,11 @@ struct drm_plane_helper_funcs; · 1 unmodified line
312314 * update to ensure framebuffer cleanup isn't done too early
313315 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
314316 * @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
315322 * @event: optional pointer to a DRM event to signal upon completion of the
316323 * state update
317324 * @state: backpointer to global drm_atomic_state
@@ -333,6 +340,7 @@ struct drm_crtc_state { · 15 unmodified lines
333340 bool mode_changed : 1;
334341 bool active_changed : 1;
335342 bool connectors_changed : 1;
343+ bool color_mgmt_changed : 1;
336344
337345 /* attached planes bitmask:
338346 * WARNING: transitional helpers do not maintain plane_mask so
@@ -355,6 +363,11 @@ struct drm_crtc_state { · 16 unmodified lines
355363 /* blob property to expose current mode to atomic userspace */
356364 struct drm_property_blob *mode_blob;
357365
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+
358371 struct drm_pending_vblank_event *event;
359372
360373 struct drm_atomic_state *state;
@@ -757,7 +770,7 @@ struct drm_crtc { · 396 unmodified lines
757770 int x, y;
758771 const struct drm_crtc_funcs *funcs;
759772
760− /* CRTC gamma size for reporting to userspace */
773+ /* Legacy FB CRTC gamma size for reporting to userspace */
761774 uint32_t gamma_size;
762775 uint16_t *gamma_store;
763776
@@ -2027,6 +2040,15 @@ struct drm_mode_config_funcs { · 1263 unmodified lines
20272040 * @property_blob_list: list of all the blob property objects
20282041 * @blob_lock: mutex for blob property allocation and management
20292042 * @*_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
20302052 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
20312053 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
20322054 * @async_page_flip: does this device support async flips on the primary plane?
@@ -2128,6 +2150,13 @@ struct drm_mode_config { · 95 unmodified lines
21282150 struct drm_property *aspect_ratio_property;
21292151 struct drm_property *dirty_info_property;
21302152
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+
21312160 /* properties for virtual machine layout */
21322161 struct drm_property *suggested_x_property;
21332162 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
25502579 return mo ? obj_to_property(mo) : NULL;
25512580 }
25522581
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+
25532597 /* Plane list iterator for legacy (overlay only) planes. */
25542598 #define drm_for_each_legacy_plane(plane, dev) \
25552599 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
4848 struct drm_display_mode *mode,
4949 int x, int y,
5050 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);
5154 extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc);
5255 extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder);
5356
include/uapi/drm/drm_mode.h+15−0
@@ -487,6 +487,21 @@ struct drm_mode_crtc_lut { · 486 unmodified lines
487487 __u64 blue;
488488 };
489489
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+
490505 #define DRM_MODE_PAGE_FLIP_EVENT 0x01
491506 #define DRM_MODE_PAGE_FLIP_ASYNC 0x02
492507 #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