From 4b81d4e5602a5b09ce084ef10656ac2e76b09987 Mon Sep 17 00:00:00 2001 From: Kieran Bingham Date: Mon, 21 Dec 2020 03:57:29 +0200 Subject: [PATCH] FROMLIST: drm: Extend color correction to support 3D-CLU Extend the existing color management properties to support provision of a 3D cubic look up table, allowing for color specific adjustments. Signed-off-by: Kieran Bingham Co-developed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Change-Id: I0bda1203a10f0df978b767d29baf06b390c0867e Link: https: //lore.kernel.org/dri-devel/20201221015730.28333-4-laurent.pinchart+renesas@ideasonboard.com/ Signed-off-by: Andy Yan --- drivers/gpu/drm/drm_atomic_helper.c | 3 ++ drivers/gpu/drm/drm_atomic_state_helper.c | 7 ++++ drivers/gpu/drm/drm_atomic_uapi.c | 14 ++++++++ drivers/gpu/drm/drm_color_mgmt.c | 41 +++++++++++++++++++---- drivers/gpu/drm/drm_mode_config.c | 16 +++++++++ drivers/gpu/drm/rockchip/Kconfig | 7 ++++ include/drm/drm_crtc.h | 11 +++++- include/drm/drm_mode_config.h | 13 +++++++ 8 files changed, 104 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 8a871e5c3e26..caa69a093605 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -3544,6 +3544,9 @@ int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc, replaced = drm_property_replace_blob(&crtc_state->degamma_lut, NULL); replaced |= drm_property_replace_blob(&crtc_state->ctm, NULL); replaced |= drm_property_replace_blob(&crtc_state->gamma_lut, blob); +#if defined(CONFIG_ROCKCHIP_DRM_CUBIC_LUT) + replaced |= drm_property_replace_blob(&crtc_state->cubic_lut, NULL); +#endif crtc_state->color_mgmt_changed |= replaced; ret = drm_atomic_commit(state); diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/drm_atomic_state_helper.c index 9ad74045158e..c29183d2aa4e 100644 --- a/drivers/gpu/drm/drm_atomic_state_helper.c +++ b/drivers/gpu/drm/drm_atomic_state_helper.c @@ -141,6 +141,10 @@ void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc, drm_property_blob_get(state->ctm); if (state->gamma_lut) drm_property_blob_get(state->gamma_lut); +#if defined(CONFIG_ROCKCHIP_DRM_CUBIC_LUT) + if (state->cubic_lut) + drm_property_blob_get(state->cubic_lut); +#endif state->mode_changed = false; state->active_changed = false; state->planes_changed = false; @@ -213,6 +217,9 @@ void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state) drm_property_blob_put(state->degamma_lut); drm_property_blob_put(state->ctm); drm_property_blob_put(state->gamma_lut); +#if defined(CONFIG_ROCKCHIP_DRM_CUBIC_LUT) + drm_property_blob_put(state->cubic_lut); +#endif } EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state); diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c index 25c269bc4681..975ece7e00a4 100644 --- a/drivers/gpu/drm/drm_atomic_uapi.c +++ b/drivers/gpu/drm/drm_atomic_uapi.c @@ -459,6 +459,16 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc, &replaced); state->color_mgmt_changed |= replaced; return ret; +#if defined(CONFIG_ROCKCHIP_DRM_CUBIC_LUT) + } else if (property == config->cubic_lut_property) { + ret = drm_atomic_replace_property_blob_from_id(dev, + &state->cubic_lut, + val, + -1, sizeof(struct drm_color_lut), + &replaced); + state->color_mgmt_changed |= replaced; + return ret; +#endif } else if (property == config->prop_out_fence_ptr) { s32 __user *fence_ptr = u64_to_user_ptr(val); @@ -501,6 +511,10 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc, *val = (state->ctm) ? state->ctm->base.id : 0; else if (property == config->gamma_lut_property) *val = (state->gamma_lut) ? state->gamma_lut->base.id : 0; +#if defined(CONFIG_ROCKCHIP_DRM_CUBIC_LUT) + else if (property == config->cubic_lut_property) + *val = (state->cubic_lut) ? state->cubic_lut->base.id : 0; +#endif else if (property == config->prop_out_fence_ptr) *val = 0; else if (crtc->funcs->atomic_get_property) diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c index 138ff34b31db..7b270b68ade4 100644 --- a/drivers/gpu/drm/drm_color_mgmt.c +++ b/drivers/gpu/drm/drm_color_mgmt.c @@ -33,7 +33,7 @@ /** * DOC: overview * - * Color management or color space adjustments is supported through a set of 5 + * Color management or color space adjustments is supported through a set of 7 * properties on the &drm_crtc object. They are set up by calling * drm_crtc_enable_color_mgmt(). * @@ -60,7 +60,7 @@ * “CTM”: * Blob property to set the current transformation matrix (CTM) apply to * pixel data after the lookup through the degamma LUT and before the - * lookup through the gamma LUT. The data is interpreted as a struct + * lookup through the cubic LUT. The data is interpreted as a struct * &drm_color_ctm. * * Setting this to NULL (blob property value set to 0) means a @@ -68,13 +68,40 @@ * boot-up state too. Drivers can access the blob for the color conversion * matrix through &drm_crtc_state.ctm. * + * ”CUBIC_LUT”: + * Blob property to set the cubic (3D) lookup table performing color + * mapping after the transformation matrix and before the lookup through + * the gamma LUT. Unlike the degamma and gamma LUTs that map color + * components independently, the 3D LUT converts an input color to an + * output color by indexing into the 3D table using the color components + * as a 3D coordinate. The LUT is subsampled as 8-bit (or more) precision + * would require too much storage space in the hardware, so the precision + * of the color components is reduced before the look up, and the low + * order bits may be used to interpolate between the nearest points in 3D + * space. + * + * The data is interpreted as an array of &struct drm_color_lut elements. + * Hardware might choose not to use the full precision of the LUT + * elements. + * + * Setting this to NULL (blob property value set to 0) means the output + * color is identical to the input color. This is generally the driver + * boot-up state too. Drivers can access this blob through + * &drm_crtc_state.cubic_lut. + * + * ”CUBIC_LUT_SIZE”: + * Unsigned range property to give the size of the lookup table to be set + * on the CUBIC_LUT property (the size depends on the underlying hardware). + * If drivers support multiple LUT sizes then they should publish the + * largest size, and sub-sample smaller sized LUTs appropriately. + * * “GAMMA_LUT”: * Blob property to set the gamma lookup table (LUT) mapping pixel data - * after the transformation matrix to data sent to the connector. The - * data is interpreted as an array of &struct drm_color_lut elements. - * Hardware might choose not to use the full precision of the LUT elements - * nor use all the elements of the LUT (for example the hardware might - * choose to interpolate between LUT[0] and LUT[4]). + * after the cubic LUT to data sent to the connector. The data is + * interpreted as an array of &struct drm_color_lut elements. Hardware + * might choose not to use the full precision of the LUT elements nor use + * all the elements of the LUT (for example the hardware might choose to + * interpolate between LUT[0] and LUT[4]). * * Setting this to NULL (blob property value set to 0) means a * linear/pass-thru gamma table should be used. This is generally the diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c index f1affc1bb679..f7f21dfc4f47 100644 --- a/drivers/gpu/drm/drm_mode_config.c +++ b/drivers/gpu/drm/drm_mode_config.c @@ -364,6 +364,22 @@ static int drm_mode_create_standard_properties(struct drm_device *dev) return -ENOMEM; dev->mode_config.gamma_lut_size_property = prop; +#if defined(CONFIG_ROCKCHIP_DRM_CUBIC_LUT) + prop = drm_property_create(dev, + DRM_MODE_PROP_BLOB, + "CUBIC_LUT", 0); + if (!prop) + return -ENOMEM; + dev->mode_config.cubic_lut_property = prop; + + prop = drm_property_create_range(dev, + DRM_MODE_PROP_IMMUTABLE, + "CUBIC_LUT_SIZE", 0, UINT_MAX); + if (!prop) + return -ENOMEM; + dev->mode_config.cubic_lut_size_property = prop; +#endif + prop = drm_property_create(dev, DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_BLOB, "IN_FORMATS", 0); diff --git a/drivers/gpu/drm/rockchip/Kconfig b/drivers/gpu/drm/rockchip/Kconfig index 310aa1546893..9fff103a4557 100644 --- a/drivers/gpu/drm/rockchip/Kconfig +++ b/drivers/gpu/drm/rockchip/Kconfig @@ -20,6 +20,13 @@ config DRM_ROCKCHIP if DRM_ROCKCHIP +config ROCKCHIP_DRM_CUBIC_LUT + bool "Support 3D cubic LUT" + depends on NO_GKI + help + This add properties to support provision of a 3D cubic + look up table, allowing for color specific adjustments. + config ROCKCHIP_ANALOGIX_DP bool "Rockchip specific extensions for Analogix DP driver" help diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 59b51a09cae6..3a3d9d887cad 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -287,7 +287,16 @@ struct drm_crtc_state { * NULL) is an array of &struct drm_color_lut. */ struct drm_property_blob *gamma_lut; - +#if defined(CONFIG_ROCKCHIP_DRM_CUBIC_LUT) + /** + * @cubic_lut: + * + * Cubic Lookup table for converting pixel data. See + * drm_crtc_enable_color_mgmt(). The blob (if not NULL) is a 3D array + * of &struct drm_color_lut. + */ + struct drm_property_blob *cubic_lut; +#endif /** * @target_vblank: * diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h index a18f73eb3cf6..76d114569484 100644 --- a/include/drm/drm_mode_config.h +++ b/include/drm/drm_mode_config.h @@ -794,6 +794,19 @@ struct drm_mode_config { */ struct drm_property *gamma_lut_size_property; +#if defined(CONFIG_ROCKCHIP_DRM_CUBIC_LUT) + /** + * @cubic_lut_property: Optional CRTC property to set the 3D LUT used to + * convert color spaces. + */ + struct drm_property *cubic_lut_property; + /** + * @cubic_lut_size_property: Optional CRTC property for the size of the + * 3D LUT as supported by the driver (read-only). + */ + struct drm_property *cubic_lut_size_property; +#endif + /** * @suggested_x_property: Optional connector property with a hint for * the position of the output on the host's screen.