[RFC 4/9] drm/drm_color_mgmt: add function to create 3D LUT modes supported
Jacopo Mondi
jacopo.mondi at ideasonboard.com
Wed Jun 21 08:10:26 UTC 2023
From: Melissa Wen <mwen at igalia.com>
DRM color function to create modes for lut3d mode property from an array
of drm_color_lut3d_mode modes supported by the HW and advertise to
userspace. Userspace can get the description of a specific mode in the
enum list from its blob data.
Signed-off-by: Melissa Wen <mwen at igalia.com>
---
drivers/gpu/drm/drm_color_mgmt.c | 43 +++++++++++++++++++++++++++++++-
include/drm/drm_color_mgmt.h | 4 +++
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c
index f92633b3b67e..6ce48007cdd4 100644
--- a/drivers/gpu/drm/drm_color_mgmt.c
+++ b/drivers/gpu/drm/drm_color_mgmt.c
@@ -104,7 +104,7 @@
* LUT3D property. A mode specifies size, stride, bit depth and color
* format and depends on the underlying hardware). If drivers support
* multiple 3D LUT modes, they should be declared in a array of
- * drm_color_lut3d_mode and they will be advertised as an enum.
+ * drm_mode_lut3d_mode and they will be advertised as an enum.
*
* “GAMMA_LUT”:
* Blob property to set the gamma lookup table (LUT) mapping pixel data
@@ -228,6 +228,47 @@ void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
}
EXPORT_SYMBOL(drm_crtc_enable_color_mgmt);
+int drm_crtc_create_lut3d_mode_property(struct drm_crtc *crtc,
+ const struct drm_mode_lut3d_mode modes[],
+ unsigned int num_modes)
+{
+ struct drm_device *dev = crtc->dev;
+ struct drm_property_blob *blob;
+ struct drm_property *prop;
+ char *name;
+ int ret;
+
+ if (dev->mode_config.lut3d_mode_property)
+ return 0;
+
+ prop = drm_property_create(dev, DRM_MODE_PROP_ENUM, "LUT3D_MODE", num_modes);
+ if (!prop)
+ return -EINVAL;
+
+ for (int i = 0; i < num_modes; i++) {
+ blob = drm_property_create_blob(dev, sizeof(modes[i]), &modes[i]);
+ if (IS_ERR(blob))
+ return PTR_ERR(blob);
+
+ name = kasprintf(GFP_KERNEL, "lut3d_%d_%dbit",
+ modes[i].lut_size, modes[i].bit_depth);
+ if (!name)
+ return -ENOMEM;
+
+ ret = drm_property_add_enum(prop, blob->base.id, name);
+ if (ret) {
+ drm_property_blob_put(blob);
+ kfree(name);
+ return ret;
+ }
+ kfree(name);
+ }
+ dev->mode_config.lut3d_mode_property = prop;
+
+ return 0;
+}
+EXPORT_SYMBOL(drm_crtc_create_lut3d_mode_property);
+
/**
* drm_mode_crtc_set_gamma_size - set the gamma table size
* @crtc: CRTC to set the gamma table size for
diff --git a/include/drm/drm_color_mgmt.h b/include/drm/drm_color_mgmt.h
index 81c298488b0c..af9305925572 100644
--- a/include/drm/drm_color_mgmt.h
+++ b/include/drm/drm_color_mgmt.h
@@ -59,6 +59,10 @@ void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
bool has_ctm,
uint gamma_lut_size);
+int drm_crtc_create_lut3d_mode_property(struct drm_crtc *crtc,
+ const struct drm_mode_lut3d_mode modes[],
+ unsigned int num_modes);
+
int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
int gamma_size);
--
2.40.1
More information about the wayland-devel
mailing list