[igt-dev] [PATCH i-g-t 1/3] lib/igt_fb: add a helper to find drm_id from matching string

Abhinav Kumar quic_abhinavk at quicinc.com
Mon Aug 7 22:48:26 UTC 2023


In preparation to support multiple output formats for writeback,
add a helper which takes the drm format string from the format_desc
as input and returns the matching drm_id.

Signed-off-by: Abhinav Kumar <quic_abhinavk at quicinc.com>
---
 lib/igt_fb.c | 28 ++++++++++++++++++++++++++++
 lib/igt_fb.h |  3 +++
 2 files changed, 31 insertions(+)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 8f5e3db9f50b..55ef63cc71dc 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -384,6 +384,18 @@ static const struct format_desc_struct *lookup_drm_format(uint32_t drm_format)
 	return NULL;
 }
 
+static const struct format_desc_struct *lookup_drm_format_str(const char *name)
+{
+	const struct format_desc_struct *format;
+
+	for_each_format(format) {
+		if (!strcmp(format->name, name))
+			return format;
+	}
+
+	return NULL;
+}
+
 /**
  * igt_format_is_yuv_semiplanar:
  * @format: drm fourcc pixel format code
@@ -4657,6 +4669,22 @@ const char *igt_format_str(uint32_t drm_format)
 	return f ? f->name : "invalid";
 }
 
+/**
+ * igt_drm_format_str_to_format:
+ * @drm_format: name string of drm_format in format_desc[] table
+ *
+ * Returns:
+ * The drm_id for the format string from the format_desc[] table.
+ */
+uint32_t igt_drm_format_str_to_format(const char *drm_format)
+{
+	const struct format_desc_struct *f = lookup_drm_format_str(drm_format);
+
+	igt_assert_f(f, "can't find a DRM format for (%s)\n", drm_format);
+
+	return f->drm_id;
+}
+
 /**
  * igt_fb_supported_format:
  * @drm_format: drm fourcc to test.
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index 73bdfc8669d8..834aaef54dea 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -215,6 +215,9 @@ const char *igt_format_str(uint32_t drm_format);
 bool igt_fb_supported_format(uint32_t drm_format);
 bool igt_format_is_yuv(uint32_t drm_format);
 bool igt_format_is_yuv_semiplanar(uint32_t format);
+
+uint32_t igt_drm_format_str_to_format(const char *drm_format);
+
 bool igt_format_is_fp16(uint32_t drm_format);
 int igt_format_plane_bpp(uint32_t drm_format, int plane);
 void igt_format_array_fill(uint32_t **formats_array, unsigned int *count,
-- 
2.40.1



More information about the igt-dev mailing list