[igt-dev] [PATCH v2 2/3] lib/kms: Remove special enum handling and replace with call to igt_plane_set_prop_enum, v2.
Maarten Lankhorst
maarten.lankhorst at linux.intel.com
Wed Aug 15 10:08:50 UTC 2018
We now have infrastructure for generic enum handling. This will make it easier
to write new tests without defining all enum constants beforehand.
Changes since v1:
- Fix compile error, sent old version by accident.
Signed-off-by: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
---
lib/igt_color_encoding.c | 20 +++++++++++
lib/igt_color_encoding.h | 3 ++
lib/igt_kms.c | 77 +++++-----------------------------------
3 files changed, 32 insertions(+), 68 deletions(-)
diff --git a/lib/igt_color_encoding.c b/lib/igt_color_encoding.c
index f445dbbc0250..03e16e0c9658 100644
--- a/lib/igt_color_encoding.c
+++ b/lib/igt_color_encoding.c
@@ -23,6 +23,7 @@
#include "igt_color_encoding.h"
#include "igt_matrix.h"
+#include "igt_core.h"
struct color_encoding {
float kr, kb;
@@ -141,3 +142,22 @@ struct igt_mat4 igt_rgb_to_ycbcr_matrix(enum igt_color_encoding color_encoding,
return igt_matrix_multiply(&r, &c);
}
+
+const char *igt_color_encoding_to_str(enum igt_color_encoding encoding)
+{
+ switch (encoding) {
+ case IGT_COLOR_YCBCR_BT601: return "ITU-R BT.601 YCbCr";
+ case IGT_COLOR_YCBCR_BT709: return "ITU-R BT.709 YCbCr";
+ case IGT_COLOR_YCBCR_BT2020: return "ITU-R BT.2020 YCbCr";
+ default: igt_assert(0); return NULL;
+ }
+}
+
+const char *igt_color_range_to_str(enum igt_color_range range)
+{
+ switch (range) {
+ case IGT_COLOR_YCBCR_LIMITED_RANGE: return "YCbCr limited range";
+ case IGT_COLOR_YCBCR_FULL_RANGE: return "YCbCr full range";
+ default: igt_assert(0); return NULL;
+ }
+}
diff --git a/lib/igt_color_encoding.h b/lib/igt_color_encoding.h
index 0d8c819322af..3884e4939f4c 100644
--- a/lib/igt_color_encoding.h
+++ b/lib/igt_color_encoding.h
@@ -41,6 +41,9 @@ enum igt_color_range {
IGT_NUM_COLOR_RANGES,
};
+const char *igt_color_encoding_to_str(enum igt_color_encoding encoding);
+const char *igt_color_range_to_str(enum igt_color_range range);
+
struct igt_mat4 igt_ycbcr_to_rgb_matrix(enum igt_color_encoding color_encoding,
enum igt_color_range color_range);
struct igt_mat4 igt_rgb_to_ycbcr_matrix(enum igt_color_encoding color_encoding,
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index e5272103e243..62d8468415c6 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -196,61 +196,6 @@ const char * const igt_connector_prop_names[IGT_NUM_CONNECTOR_PROPS] = {
[IGT_CONNECTOR_BROADCAST_RGB] = "Broadcast RGB",
};
-static const char * const igt_color_encoding_names[IGT_NUM_COLOR_ENCODINGS] = {
- [IGT_COLOR_YCBCR_BT601] = "ITU-R BT.601 YCbCr",
- [IGT_COLOR_YCBCR_BT709] = "ITU-R BT.709 YCbCr",
- [IGT_COLOR_YCBCR_BT2020] = "ITU-R BT.2020 YCbCr",
-};
-
-static const char * const igt_color_range_names[IGT_NUM_COLOR_RANGES] = {
- [IGT_COLOR_YCBCR_FULL_RANGE] = "YCbCr full range",
- [IGT_COLOR_YCBCR_LIMITED_RANGE] = "YCbCr limited range",
-};
-
-static void parse_enum_prop(drmModePropertyPtr prop,
- int num_enums,
- uint64_t values[],
- const char * const enum_names[])
-{
- igt_assert((prop->flags & ~(DRM_MODE_PROP_IMMUTABLE |
- DRM_MODE_PROP_ATOMIC)) == DRM_MODE_PROP_ENUM);
- igt_assert(prop->count_enums == prop->count_values);
- igt_assert(prop->count_enums >= 1);
- igt_assert(!!(prop->flags & DRM_MODE_PROP_IMMUTABLE) == (prop->count_enums == 1));
-
- for (int i = 0; i < prop->count_enums; i++) {
- for (int j = 0; j < num_enums; j++) {
- if (strcmp(prop->enums[i].name, enum_names[j]))
- continue;
-
- values[j] = prop->enums[i].value;
- }
- }
-}
-
-static void
-parse_color_encoding_prop(igt_plane_t *plane, drmModePropertyPtr prop)
-{
- parse_enum_prop(prop, ARRAY_SIZE(igt_color_encoding_names),
- plane->color_encoding.values,
- igt_color_encoding_names);
-}
-
-static void
-parse_color_range_prop(igt_plane_t *plane, drmModePropertyPtr prop)
-{
- parse_enum_prop(prop, ARRAY_SIZE(igt_color_range_names),
- plane->color_range.values,
- igt_color_range_names);
-}
-
-typedef void (*parse_plane_prop_t)(igt_plane_t *plane, drmModePropertyPtr prop);
-
-static const parse_plane_prop_t igt_parse_plane_prop[IGT_NUM_PLANE_PROPS] = {
- [IGT_PLANE_COLOR_ENCODING] = parse_color_encoding_prop,
- [IGT_PLANE_COLOR_RANGE] = parse_color_range_prop,
-};
-
/*
* Retrieve all the properies specified in props_name and store them into
* plane->props.
@@ -275,9 +220,6 @@ igt_fill_plane_props(igt_display_t *display, igt_plane_t *plane,
if (strcmp(prop->name, prop_names[j]) != 0)
continue;
- if (igt_parse_plane_prop[j])
- igt_parse_plane_prop[j](plane, prop);
-
plane->props[j] = props->props[i];
break;
}
@@ -1799,11 +1741,12 @@ static void igt_plane_reset(igt_plane_t *plane)
igt_plane_set_prop_value(plane, IGT_PLANE_CRTC_ID, 0);
if (igt_plane_has_prop(plane, IGT_PLANE_COLOR_ENCODING))
- igt_plane_set_prop_value(plane, IGT_PLANE_COLOR_ENCODING,
- plane->color_encoding.values[IGT_COLOR_YCBCR_BT601]);
+ igt_plane_set_prop_enum(plane, IGT_PLANE_COLOR_ENCODING,
+ igt_color_encoding_to_str(IGT_COLOR_YCBCR_BT601));
+
if (igt_plane_has_prop(plane, IGT_PLANE_COLOR_RANGE))
- igt_plane_set_prop_value(plane, IGT_PLANE_COLOR_RANGE,
- plane->color_range.values[IGT_COLOR_YCBCR_LIMITED_RANGE]);
+ igt_plane_set_prop_enum(plane, IGT_PLANE_COLOR_RANGE,
+ igt_color_range_to_str(IGT_COLOR_YCBCR_LIMITED_RANGE));
/* Use default rotation */
if (igt_plane_has_prop(plane, IGT_PLANE_ROTATION))
@@ -3722,13 +3665,11 @@ void igt_plane_set_fb(igt_plane_t *plane, struct igt_fb *fb)
igt_fb_set_size(fb, plane, fb->width, fb->height);
if (igt_plane_has_prop(plane, IGT_PLANE_COLOR_ENCODING))
- igt_plane_set_prop_value(plane,
- IGT_PLANE_COLOR_ENCODING,
- plane->color_encoding.values[fb->color_encoding]);
+ igt_plane_set_prop_enum(plane, IGT_PLANE_COLOR_ENCODING,
+ igt_color_encoding_to_str(fb->color_encoding));
if (igt_plane_has_prop(plane, IGT_PLANE_COLOR_RANGE))
- igt_plane_set_prop_value(plane,
- IGT_PLANE_COLOR_RANGE,
- plane->color_range.values[fb->color_range]);
+ igt_plane_set_prop_enum(plane, IGT_PLANE_COLOR_RANGE,
+ igt_color_range_to_str(fb->color_range));
} else {
igt_plane_set_size(plane, 0, 0);
--
2.18.0
More information about the igt-dev
mailing list