Skip to content

Commit 80f690e

Browse files
Jyri Sarhavsyrjala
authored andcommitted
drm: Add optional COLOR_ENCODING and COLOR_RANGE properties to drm_plane
Add a standard optional properties to support different non RGB color encodings in DRM planes. COLOR_ENCODING select the supported non RGB color encoding, for instance ITU-R BT.709 YCbCr. COLOR_RANGE selects the value ranges within the selected color encoding. The properties are stored to drm_plane object to allow different set of supported encoding for different planes on the device. v2: Add/fix kerneldocs, verify bitmasks (danvet) Cc: Harry Wentland <harry.wentland@amd.com> Cc: Daniel Vetter <daniel@ffwll.ch> Cc: Daniel Stone <daniel@fooishbar.org> Cc: Russell King - ARM Linux <linux@armlinux.org.uk> Cc: Ilia Mirkin <imirkin@alum.mit.edu> Cc: Hans Verkuil <hverkuil@xs4all.nl> Cc: Uma Shankar <uma.shankar@intel.com> Cc: Shashank Sharma <shashank.sharma@intel.com> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Signed-off-by: Jyri Sarha <jsarha@ti.com> [vsyrjala v2: Add/fix kerneldocs, verify bitmasks] Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20180219202823.10508-1-ville.syrjala@linux.intel.com Acked-by: Harry Wentland <harry.wentland@amd.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent 9ffef62 commit 80f690e

4 files changed

Lines changed: 162 additions & 0 deletions

File tree

‎drivers/gpu/drm/drm_atomic.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,10 @@ static int drm_atomic_plane_set_property(struct drm_plane *plane,
759759
state->rotation = val;
760760
} else if (property == plane->zpos_property) {
761761
state->zpos = val;
762+
} else if (property == plane->color_encoding_property) {
763+
state->color_encoding = val;
764+
} else if (property == plane->color_range_property) {
765+
state->color_range = val;
762766
} else if (plane->funcs->atomic_set_property) {
763767
return plane->funcs->atomic_set_property(plane, state,
764768
property, val);
@@ -818,6 +822,10 @@ drm_atomic_plane_get_property(struct drm_plane *plane,
818822
*val = state->rotation;
819823
} else if (property == plane->zpos_property) {
820824
*val = state->zpos;
825+
} else if (property == plane->color_encoding_property) {
826+
*val = state->color_encoding;
827+
} else if (property == plane->color_range_property) {
828+
*val = state->color_range;
821829
} else if (plane->funcs->atomic_get_property) {
822830
return plane->funcs->atomic_get_property(plane, state, property, val);
823831
} else {

‎drivers/gpu/drm/drm_color_mgmt.c‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@
8888
* drm_mode_crtc_set_gamma_size(). Drivers which support both should use
8989
* drm_atomic_helper_legacy_gamma_set() to alias the legacy gamma ramp with the
9090
* "GAMMA_LUT" property above.
91+
*
92+
* Support for different non RGB color encodings is controlled through
93+
* &drm_plane specific COLOR_ENCODING and COLOR_RANGE properties. They
94+
* are set up by calling drm_plane_create_color_properties().
95+
*
96+
* "COLOR_ENCODING"
97+
* Optional plane enum property to support different non RGB
98+
* color encodings. The driver can provide a subset of standard
99+
* enum values supported by the DRM plane.
100+
*
101+
* "COLOR_RANGE"
102+
* Optional plane enum property to support different non RGB
103+
* color parameter ranges. The driver can provide a subset of
104+
* standard enum values supported by the DRM plane.
91105
*/
92106

93107
/**
@@ -339,3 +353,92 @@ int drm_mode_gamma_get_ioctl(struct drm_device *dev,
339353
drm_modeset_unlock(&crtc->mutex);
340354
return ret;
341355
}
356+
357+
static const char * const color_encoding_name[] = {
358+
[DRM_COLOR_YCBCR_BT601] = "ITU-R BT.601 YCbCr",
359+
[DRM_COLOR_YCBCR_BT709] = "ITU-R BT.709 YCbCr",
360+
[DRM_COLOR_YCBCR_BT2020] = "ITU-R BT.2020 YCbCr",
361+
};
362+
363+
static const char * const color_range_name[] = {
364+
[DRM_COLOR_YCBCR_FULL_RANGE] = "YCbCr full range",
365+
[DRM_COLOR_YCBCR_LIMITED_RANGE] = "YCbCr limited range",
366+
};
367+
368+
/**
369+
* drm_plane_create_color_properties - color encoding related plane properties
370+
* @plane: plane object
371+
* @supported_encodings: bitfield indicating supported color encodings
372+
* @supported_ranges: bitfileld indicating supported color ranges
373+
* @default_encoding: default color encoding
374+
* @default_range: default color range
375+
*
376+
* Create and attach plane specific COLOR_ENCODING and COLOR_RANGE
377+
* properties to @plane. The supported encodings and ranges should
378+
* be provided in supported_encodings and supported_ranges bitmasks.
379+
* Each bit set in the bitmask indicates that its number as enum
380+
* value is supported.
381+
*/
382+
int drm_plane_create_color_properties(struct drm_plane *plane,
383+
u32 supported_encodings,
384+
u32 supported_ranges,
385+
enum drm_color_encoding default_encoding,
386+
enum drm_color_range default_range)
387+
{
388+
struct drm_device *dev = plane->dev;
389+
struct drm_property *prop;
390+
struct drm_prop_enum_list enum_list[max(DRM_COLOR_ENCODING_MAX,
391+
DRM_COLOR_RANGE_MAX)];
392+
int i, len;
393+
394+
if (WARN_ON(supported_encodings == 0 ||
395+
(supported_encodings & -BIT(DRM_COLOR_ENCODING_MAX)) != 0 ||
396+
(supported_encodings & BIT(default_encoding)) == 0))
397+
return -EINVAL;
398+
399+
if (WARN_ON(supported_ranges == 0 ||
400+
(supported_ranges & -BIT(DRM_COLOR_RANGE_MAX)) != 0 ||
401+
(supported_ranges & BIT(default_range)) == 0))
402+
return -EINVAL;
403+
404+
len = 0;
405+
for (i = 0; i < DRM_COLOR_ENCODING_MAX; i++) {
406+
if ((supported_encodings & BIT(i)) == 0)
407+
continue;
408+
409+
enum_list[len].type = i;
410+
enum_list[len].name = color_encoding_name[i];
411+
len++;
412+
}
413+
414+
prop = drm_property_create_enum(dev, 0, "COLOR_ENCODING",
415+
enum_list, len);
416+
if (!prop)
417+
return -ENOMEM;
418+
plane->color_encoding_property = prop;
419+
drm_object_attach_property(&plane->base, prop, default_encoding);
420+
if (plane->state)
421+
plane->state->color_encoding = default_encoding;
422+
423+
len = 0;
424+
for (i = 0; i < DRM_COLOR_RANGE_MAX; i++) {
425+
if ((supported_ranges & BIT(i)) == 0)
426+
continue;
427+
428+
enum_list[len].type = i;
429+
enum_list[len].name = color_range_name[i];
430+
len++;
431+
}
432+
433+
prop = drm_property_create_enum(dev, 0, "COLOR_RANGE",
434+
enum_list, len);
435+
if (!prop)
436+
return -ENOMEM;
437+
plane->color_range_property = prop;
438+
drm_object_attach_property(&plane->base, prop, default_range);
439+
if (plane->state)
440+
plane->state->color_range = default_range;
441+
442+
return 0;
443+
}
444+
EXPORT_SYMBOL(drm_plane_create_color_properties);

‎include/drm/drm_color_mgmt.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/ctype.h>
2727

2828
struct drm_crtc;
29+
struct drm_plane;
2930

3031
uint32_t drm_color_lut_extract(uint32_t user_input, uint32_t bit_precision);
3132

@@ -37,4 +38,22 @@ void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
3738
int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
3839
int gamma_size);
3940

41+
enum drm_color_encoding {
42+
DRM_COLOR_YCBCR_BT601,
43+
DRM_COLOR_YCBCR_BT709,
44+
DRM_COLOR_YCBCR_BT2020,
45+
DRM_COLOR_ENCODING_MAX,
46+
};
47+
48+
enum drm_color_range {
49+
DRM_COLOR_YCBCR_LIMITED_RANGE,
50+
DRM_COLOR_YCBCR_FULL_RANGE,
51+
DRM_COLOR_RANGE_MAX,
52+
};
53+
54+
int drm_plane_create_color_properties(struct drm_plane *plane,
55+
u32 supported_encodings,
56+
u32 supported_ranges,
57+
enum drm_color_encoding default_encoding,
58+
enum drm_color_range default_range);
4059
#endif

‎include/drm/drm_plane.h‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/list.h>
2727
#include <linux/ctype.h>
2828
#include <drm/drm_mode_object.h>
29+
#include <drm/drm_color_mgmt.h>
2930

3031
struct drm_crtc;
3132
struct drm_printer;
@@ -112,6 +113,20 @@ struct drm_plane_state {
112113
unsigned int zpos;
113114
unsigned int normalized_zpos;
114115

116+
/**
117+
* @color_encoding:
118+
*
119+
* Color encoding for non RGB formats
120+
*/
121+
enum drm_color_encoding color_encoding;
122+
123+
/**
124+
* @color_range:
125+
*
126+
* Color range for non RGB formats
127+
*/
128+
enum drm_color_range color_range;
129+
115130
/* Clipped coordinates */
116131
struct drm_rect src, dst;
117132

@@ -558,6 +573,23 @@ struct drm_plane {
558573

559574
struct drm_property *zpos_property;
560575
struct drm_property *rotation_property;
576+
577+
/**
578+
* @color_encoding_property:
579+
*
580+
* Optional "COLOR_ENCODING" enum property for specifying
581+
* color encoding for non RGB formats.
582+
* See drm_plane_create_color_properties().
583+
*/
584+
struct drm_property *color_encoding_property;
585+
/**
586+
* @color_range_property:
587+
*
588+
* Optional "COLOR_RANGE" enum property for specifying
589+
* color range for non RGB formats.
590+
* See drm_plane_create_color_properties().
591+
*/
592+
struct drm_property *color_range_property;
561593
};
562594

563595
#define obj_to_plane(x) container_of(x, struct drm_plane, base)

0 commit comments

Comments
 (0)