[igt-dev] [PATCH i-g-t v3 08/21] lib/igt_fb: Add a helper to fill-in the available DRM formats

Lyude Paul lyude at redhat.com
Tue Jan 15 20:49:54 UTC 2019


On Fri, 2019-01-11 at 10:05 +0100, Paul Kocialkowski wrote:
> 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 at bootlin.com>
> ---
>  lib/igt_fb.c | 34 ++++++++++++++++++++++++++++++++++
>  lib/igt_fb.h |  2 ++
>  2 files changed, 36 insertions(+)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index 86ceb028bdae..8adf3295df56 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -2420,3 +2420,37 @@ 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));
Probably a good idea to put an igt_assert() after this to make sure that
formats_array got allocated properly. With that fixed:

Reviewed-by: Lyude Paul <lyude at redhat.com>
> +
> +	for_each_format(format) {
> +		if (!allow_yuv && igt_format_is_yuv(format->drm_id))
> +			continue;
> +
> +		(*formats_array)[index++] = format->drm_id;
> +	}
> +}
> diff --git a/lib/igt_fb.h b/lib/igt_fb.h
> index a39c4d2fe30e..c6edddec1d76 100644
> --- a/lib/igt_fb.h
> +++ b/lib/igt_fb.h
> @@ -176,6 +176,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__ */
>  
-- 
Cheers,
	Lyude Paul



More information about the igt-dev mailing list