summaryrefslogtreecommitdiff
path: root/lib/igt_fb.c
diff options
context:
space:
mode:
authorPaul Kocialkowski <paul.kocialkowski@bootlin.com>2019-01-10 17:33:52 +0100
committerPaul Kocialkowski <paul.kocialkowski@bootlin.com>2019-02-26 09:45:54 +0100
commit7a8456beff7e4b57715f181a5a6c2d2cc7fce18b (patch)
treef8b49e71a52daeb40c5cfc82d5026f8a59bb285a /lib/igt_fb.c
parent34a21dfb6a02c3becd0639b30ec43ad42bb493dd (diff)
lib/igt_fb: Add a helper to fill-in the available DRM formats
Introduce a helper to allocate and fill-in a list of available DRM formats, which is useful for picking one at random in tests. Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com> Reviewed-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Maxime Ripard <maxime.ripard@bootlin.com>
Diffstat (limited to 'lib/igt_fb.c')
-rw-r--r--lib/igt_fb.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 48f7921e..0b59ff47 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -2743,3 +2743,38 @@ int igt_format_plane_bpp(uint32_t drm_format, int plane)
return format->plane_bpp[plane];
}
+
+/**
+ * igt_format_array_fill:
+ * @formats_array: a pointer to the formats array pointer to be allocated
+ * @count: a pointer to the number of elements contained in the allocated array
+ * @allow_yuv: a boolean indicating whether YUV formats should be included
+ *
+ * This functions allocates and fills a @formats_array that lists the DRM
+ * formats current available.
+ */
+void igt_format_array_fill(uint32_t **formats_array, unsigned int *count,
+ bool allow_yuv)
+{
+ const struct format_desc_struct *format;
+ unsigned int index = 0;
+
+ *count = 0;
+
+ for_each_format(format) {
+ if (!allow_yuv && igt_format_is_yuv(format->drm_id))
+ continue;
+
+ (*count)++;
+ }
+
+ *formats_array = calloc(*count, sizeof(uint32_t));
+ igt_assert(*formats_array);
+
+ for_each_format(format) {
+ if (!allow_yuv && igt_format_is_yuv(format->drm_id))
+ continue;
+
+ (*formats_array)[index++] = format->drm_id;
+ }
+}