backend-drm: Teach drm_property_info_populate() to retrieve range values
authorMarius Vlad <marius.vlad@collabora.com>
Fri, 1 Nov 2019 10:00:09 +0000 (12:00 +0200)
committerDaniel Stone <daniels@collabora.com>
Mon, 11 Nov 2019 16:51:48 +0000 (16:51 +0000)
Useful for zpos range values.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Suggested-by: Daniel Stone <daniel.stone@collabora.com>
libweston/backend-drm/drm-internal.h
libweston/backend-drm/kms.c

index b55061ab65d7f837f777ac25c3bc77c3dd61a8e1..29b68e38c2127f4a5e648036aa09b6c4aad02485 100644 (file)
@@ -144,8 +144,11 @@ struct drm_property_enum_info {
 struct drm_property_info {
        const char *name; /**< name as string (static, not freed) */
        uint32_t prop_id; /**< KMS property object ID */
+       uint32_t flags;
        unsigned int num_enum_values; /**< number of enum values */
        struct drm_property_enum_info *enum_values; /**< array of enum values */
+       unsigned int num_range_values;
+       uint64_t range_values[2];
 };
 
 /**
@@ -579,6 +582,9 @@ uint64_t
 drm_property_get_value(struct drm_property_info *info,
                       const drmModeObjectProperties *props,
                       uint64_t def);
+uint64_t *
+drm_property_get_range_values(struct drm_property_info *info,
+                             const drmModeObjectProperties *props);
 int
 drm_plane_populate_formats(struct drm_plane *plane, const drmModePlane *kplane,
                           const drmModeObjectProperties *props);
index 4c942a3d3b60f60d99c1ac44289c32dddc4685b6..4cb242d3adfe7481223dbf7c4dc64d594629eed3 100644 (file)
@@ -202,6 +202,42 @@ drm_property_get_value(struct drm_property_info *info,
        return def;
 }
 
+/**
+ * Get the current range values of a KMS property
+ *
+ * Given a drmModeObjectGetProperties return, as well as the drm_property_info
+ * for the target property, return the current range values of that property,
+ *
+ * If the property is not present, or there's no it is not a prop range then
+ * NULL will be returned.
+ *
+ * @param info Internal structure for property to look up
+ * @param props Raw KMS properties for the target object
+ */
+uint64_t *
+drm_property_get_range_values(struct drm_property_info *info,
+                             const drmModeObjectProperties *props)
+{
+       unsigned int i;
+
+       if (info->prop_id == 0)
+               return NULL;
+
+       for (i = 0; i < props->count_props; i++) {
+
+               if (props->props[i] != info->prop_id)
+                       continue;
+
+               if (!(info->flags & DRM_MODE_PROP_RANGE) &&
+                   !(info->flags & DRM_MODE_PROP_SIGNED_RANGE))
+                       continue;
+
+               return info->range_values;
+       }
+
+       return NULL;
+}
+
 /**
  * Cache DRM property values
  *
@@ -294,6 +330,15 @@ drm_property_info_populate(struct drm_backend *b,
                }
 
                info[j].prop_id = props->props[i];
+               info[j].flags = prop->flags;
+
+               if (prop->flags & DRM_MODE_PROP_RANGE ||
+                   prop->flags & DRM_MODE_PROP_SIGNED_RANGE) {
+                       info[j].num_range_values = prop->count_values;
+                       for (int i = 0; i < prop->count_values; i++)
+                               info[j].range_values[i] = prop->values[i];
+               }
+
 
                if (info[j].num_enum_values == 0) {
                        drmModeFreeProperty(prop);