[Intel-gfx] [RFC 1/3] drm: Add colorspace property

Uma Shankar uma.shankar at intel.com
Tue Jul 24 15:45:50 UTC 2018


This patch adds a colorspace property, enabling
userspace to switch to various supported colorspaces.
This will help enable BT2020 along with other colorspaces.

Signed-off-by: Uma Shankar <uma.shankar at intel.com>
---
 drivers/gpu/drm/drm_atomic.c    |  4 ++++
 drivers/gpu/drm/drm_connector.c | 31 +++++++++++++++++++++++++++++++
 include/drm/drm_connector.h     |  7 +++++++
 include/drm/drm_mode_config.h   |  6 ++++++
 include/uapi/drm/drm_mode.h     | 11 +++++++++++
 5 files changed, 59 insertions(+)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 3eb061e..f065e6f 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1397,6 +1397,8 @@ static int drm_atomic_connector_set_property(struct drm_connector *connector,
 		state->picture_aspect_ratio = val;
 	} else if (property == config->content_type_property) {
 		state->content_type = val;
+	} else if (property == config->colorspace_property) {
+		state->colorspace = val;
 	} else if (property == connector->scaling_mode_property) {
 		state->scaling_mode = val;
 	} else if (property == connector->content_protection_property) {
@@ -1502,6 +1504,8 @@ static void drm_atomic_connector_print_state(struct drm_printer *p,
 		*val = state->picture_aspect_ratio;
 	} else if (property == config->content_type_property) {
 		*val = state->content_type;
+	} else if (property == config->colorspace_property) {
+		*val = state->colorspace;
 	} else if (property == connector->scaling_mode_property) {
 		*val = state->scaling_mode;
 	} else if (property == connector->content_protection_property) {
diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index 5ada064..cfe1d79 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -805,6 +805,25 @@ int drm_display_info_set_bus_formats(struct drm_display_info *info,
 };
 DRM_ENUM_NAME_FN(drm_get_content_protection_name, drm_cp_enum_list)
 
+static const struct drm_prop_enum_list colorspace[] = {
+	/* Standard Definition Colorimetry based on IEC 61966-2-4 */
+	{ EXTENDED_COLORIMETRY_XV_YCC_601, "601" },
+	/* High Definition Colorimetry based on IEC 61966-2-4 */
+	{ EXTENDED_COLORIMETRY_XV_YCC_709, "709" },
+	/* Colorimetry based on IEC 61966-2-1/Amendment 1 */
+	{ EXTENDED_COLORIMETRY_S_YCC_601, "s601" },
+	/* Colorimetry based on IEC 61966-2-5 [33] */
+	{ EXTENDED_COLORIMETRY_ADOBE_YCC_601, "adobe601" },
+	/* Colorimetry based on IEC 61966-2-5 */
+	{ EXTENDED_COLORIMETRY_ADOBE_RGB, "adobe_rgb" },
+	/* Colorimetry based on ITU-R BT.2020 */
+	{ EXTENDED_COLORIMETRY_BT2020_RGB, "BT2020_rgb" },
+	/* Colorimetry based on ITU-R BT.2020 */
+	{ EXTENDED_COLORIMETRY_BT2020_YCC, "BT2020_ycc" },
+	/* Colorimetry based on ITU-R BT.2020 */
+	{ EXTENDED_COLORIMETRY_BT2020_CYCC, "BT2020_cycc" },
+};
+
 /**
  * DOC: standard connector properties
  *
@@ -951,6 +970,12 @@ int drm_display_info_set_bus_formats(struct drm_display_info *info,
  *	can also expose this property to external outputs, in which case they
  *	must support "None", which should be the default (since external screens
  *	have a built-in scaler).
+ *
+ * colorspace:
+ *	This property helps select a suitable colorspace based on the sink
+ *	capability. Modern sink devices support wider gamut like BT2020.
+ *	This helps switch to BT2020 mode if the BT2020 encoded video stream
+ *	is being played by the user, same for any other colorspace.
  */
 
 int drm_connector_create_standard_properties(struct drm_device *dev)
@@ -999,6 +1024,12 @@ int drm_connector_create_standard_properties(struct drm_device *dev)
 		return -ENOMEM;
 	dev->mode_config.non_desktop_property = prop;
 
+	prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
+					colorspace, ARRAY_SIZE(colorspace));
+	if (!prop)
+		return -ENOMEM;
+	dev->mode_config.colorspace_property = prop;
+
 	return 0;
 }
 
diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
index a5179eb..306b536 100644
--- a/include/drm/drm_connector.h
+++ b/include/drm/drm_connector.h
@@ -443,6 +443,13 @@ struct drm_connector_state {
 	unsigned int content_protection;
 
 	/**
+	 * @colorspace: Connector property to request colorspace
+	 * change. This is most commonly used to switch to wider color
+	 * gamuts like BT2020.
+	 */
+	enum extended_colorimetry colorspace;
+
+	/**
 	 * @writeback_job: Writeback job for writeback connectors
 	 *
 	 * Holds the framebuffer and out-fence for a writeback connector. As
diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h
index a0b202e..3afe30b 100644
--- a/include/drm/drm_mode_config.h
+++ b/include/drm/drm_mode_config.h
@@ -841,6 +841,12 @@ struct drm_mode_config {
 	uint32_t cursor_width, cursor_height;
 
 	/**
+	 * @colorspace_property: Connector property to set the suitable
+	 * colorspace supported by the sink.
+	 */
+	struct drm_property *colorspace_property;
+
+	/**
 	 * @suspend_state:
 	 *
 	 * Atomic state when suspended.
diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h
index 8d67243..c9d14ca 100644
--- a/include/uapi/drm/drm_mode.h
+++ b/include/uapi/drm/drm_mode.h
@@ -209,6 +209,17 @@
 #define DRM_MODE_CONTENT_PROTECTION_DESIRED     1
 #define DRM_MODE_CONTENT_PROTECTION_ENABLED     2
 
+enum extended_colorimetry {
+	EXTENDED_COLORIMETRY_XV_YCC_601 = 0,
+	EXTENDED_COLORIMETRY_XV_YCC_709,
+	EXTENDED_COLORIMETRY_S_YCC_601,
+	EXTENDED_COLORIMETRY_ADOBE_YCC_601,
+	EXTENDED_COLORIMETRY_ADOBE_RGB,
+	EXTENDED_COLORIMETRY_BT2020_RGB,
+	EXTENDED_COLORIMETRY_BT2020_YCC,
+	EXTENDED_COLORIMETRY_BT2020_CYCC,
+};
+
 struct drm_mode_modeinfo {
 	__u32 clock;
 	__u16 hdisplay;
-- 
1.9.1



More information about the Intel-gfx mailing list