drm: Add chroma siting properties
authorDom Cobley <popcornmix@gmail.com>
Wed, 26 Jan 2022 15:58:13 +0000 (15:58 +0000)
committerDom Cobley <popcornmix@gmail.com>
Mon, 19 Feb 2024 11:31:25 +0000 (11:31 +0000)
Signed-off-by: Dom Cobley <popcornmix@gmail.com>
drivers/gpu/drm/drm_atomic_state_helper.c
drivers/gpu/drm/drm_atomic_uapi.c
drivers/gpu/drm/drm_color_mgmt.c
include/drm/drm_color_mgmt.h
include/drm/drm_plane.h

index 784e63d..d7c761d 100644 (file)
@@ -267,6 +267,20 @@ void __drm_atomic_helper_plane_state_reset(struct drm_plane_state *plane_state,
                        plane_state->color_range = val;
        }
 
+       if (plane->chroma_siting_h_property) {
+               if (!drm_object_property_get_default_value(&plane->base,
+                                                          plane->chroma_siting_h_property,
+                                                          &val))
+                       plane_state->chroma_siting_h = val;
+       }
+
+       if (plane->chroma_siting_v_property) {
+               if (!drm_object_property_get_default_value(&plane->base,
+                                                          plane->chroma_siting_v_property,
+                                                          &val))
+                       plane_state->chroma_siting_v = val;
+       }
+
        if (plane->zpos_property) {
                if (!drm_object_property_get_default_value(&plane->base,
                                                           plane->zpos_property,
index 98d3b10..9fd2c64 100644 (file)
@@ -580,6 +580,10 @@ static int drm_atomic_plane_set_property(struct drm_plane *plane,
                state->color_encoding = val;
        } else if (property == plane->color_range_property) {
                state->color_range = val;
+       } else if (property == plane->chroma_siting_h_property) {
+               state->chroma_siting_h = val;
+       } else if (property == plane->chroma_siting_v_property) {
+               state->chroma_siting_v = val;
        } else if (property == config->prop_fb_damage_clips) {
                ret = drm_atomic_replace_property_blob_from_id(dev,
                                        &state->fb_damage_clips,
@@ -646,6 +650,10 @@ drm_atomic_plane_get_property(struct drm_plane *plane,
                *val = state->color_encoding;
        } else if (property == plane->color_range_property) {
                *val = state->color_range;
+       } else if (property == plane->chroma_siting_h_property) {
+               *val = state->chroma_siting_h;
+       } else if (property == plane->chroma_siting_v_property) {
+               *val = state->chroma_siting_v;
        } else if (property == config->prop_fb_damage_clips) {
                *val = (state->fb_damage_clips) ?
                        state->fb_damage_clips->base.id : 0;
index 996f124..973c6ae 100644 (file)
@@ -591,6 +591,42 @@ int drm_plane_create_color_properties(struct drm_plane *plane,
 EXPORT_SYMBOL(drm_plane_create_color_properties);
 
 /**
+ * drm_plane_create_chroma_siting_properties - chroma siting related plane properties
+ * @plane: plane object
+ *
+ * Create and attach plane specific CHROMA_SITING
+ * properties to @plane.
+ */
+int drm_plane_create_chroma_siting_properties(struct drm_plane *plane,
+                                               int32_t default_chroma_siting_h,
+                                               int32_t default_chroma_siting_v)
+{
+       struct drm_device *dev = plane->dev;
+       struct drm_property *prop;
+
+       prop = drm_property_create_range(dev, 0, "CHROMA_SITING_H",
+                                       0, 1<<16);
+       if (!prop)
+               return -ENOMEM;
+       plane->chroma_siting_h_property = prop;
+       drm_object_attach_property(&plane->base, prop, default_chroma_siting_h);
+
+       prop = drm_property_create_range(dev, 0, "CHROMA_SITING_V",
+                                       0, 1<<16);
+       if (!prop)
+               return -ENOMEM;
+       plane->chroma_siting_v_property = prop;
+       drm_object_attach_property(&plane->base, prop, default_chroma_siting_v);
+
+       if (plane->state) {
+               plane->state->chroma_siting_h = default_chroma_siting_h;
+               plane->state->chroma_siting_v = default_chroma_siting_v;
+       }
+       return 0;
+}
+EXPORT_SYMBOL(drm_plane_create_chroma_siting_properties);
+
+/**
  * drm_color_lut_check - check validity of lookup table
  * @lut: property blob containing LUT to check
  * @tests: bitmask of tests to run
index 6b5eec1..5810aa8 100644 (file)
@@ -94,6 +94,9 @@ int drm_plane_create_color_properties(struct drm_plane *plane,
                                      enum drm_color_encoding default_encoding,
                                      enum drm_color_range default_range);
 
+int drm_plane_create_chroma_siting_properties(struct drm_plane *plane,
+                                               int32_t default_chroma_siting_h, int32_t default_chroma_siting_v);
+
 /**
  * enum drm_color_lut_tests - hw-specific LUT tests to perform
  *
index fef7752..e4000d2 100644 (file)
@@ -178,6 +178,24 @@ struct drm_plane_state {
        enum drm_color_range color_range;
 
        /**
+        * @chroma_siting_h:
+        *
+        * Location of chroma samples horizontally compared to luma
+        * 0 means chroma is sited with left luma
+        * 0x8000 is interstitial. 0x10000 is sited with right luma
+        */
+       int32_t chroma_siting_h;
+
+       /**
+        * @chroma_siting_v:
+        *
+        * Location of chroma samples vertically compared to luma
+        * 0 means chroma is sited with top luma
+        * 0x8000 is interstitial. 0x10000 is sited with bottom luma
+        */
+       int32_t chroma_siting_v;
+
+       /**
         * @fb_damage_clips:
         *
         * Blob representing damage (area in plane framebuffer that changed
@@ -758,6 +776,24 @@ struct drm_plane {
         * scaling.
         */
        struct drm_property *scaling_filter_property;
+
+       /**
+        * @chroma_siting_h_property:
+        *
+        * Optional "CHROMA_SITING_H" property for specifying
+        * chroma siting for YUV formats.
+        * See drm_plane_create_chroma_siting_properties().
+        */
+       struct drm_property *chroma_siting_h_property;
+
+       /**
+        * @chroma_siting_v_property:
+        *
+        * Optional "CHROMA_SITING_V" property for specifying
+        * chroma siting for YUV formats.
+        * See drm_plane_create_chroma_siting_properties().
+        */
+       struct drm_property *chroma_siting_v_property;
 };
 
 #define obj_to_plane(x) container_of(x, struct drm_plane, base)