Commit 7a8456be authored by Paul Kocialkowski's avatar Paul Kocialkowski

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's avatarPaul Kocialkowski <>
Reviewed-by: Lyude Paul's avatarLyude Paul <>
Reviewed-by: default avatarMaxime Ripard <>
parent 34a21dfb
......@@ -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))
*formats_array = calloc(*count, sizeof(uint32_t));
for_each_format(format) {
if (!allow_yuv && igt_format_is_yuv(format->drm_id))
(*formats_array)[index++] = format->drm_id;
......@@ -182,6 +182,8 @@ 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);
int igt_format_plane_bpp(uint32_t drm_format, int plane);
void igt_format_array_fill(uint32_t **formats_array, unsigned int *count,
bool allow_yuv);
#endif /* __IGT_FB_H__ */
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment