diff --git a/libweston/pixel-formats.c b/libweston/pixel-formats.c index 3da4b5e2..1e8e5099 100644 --- a/libweston/pixel-formats.c +++ b/libweston/pixel-formats.c @@ -40,6 +40,7 @@ #include "shared/helpers.h" #include "shared/string-helpers.h" #include "shared/weston-drm-fourcc.h" +#include "shared/xalloc.h" #include "wayland-util.h" #include "pixel-formats.h" @@ -776,3 +777,21 @@ pixel_format_get_shm_format(const struct pixel_format_info *info) return info->format; } + +WL_EXPORT const struct pixel_format_info ** +pixel_format_get_array(const uint32_t *drm_formats, unsigned int formats_count) +{ + const struct pixel_format_info **formats; + unsigned int i; + + formats = xcalloc(formats_count, sizeof(*formats)); + for (i = 0; i < formats_count; i++) { + formats[i] = pixel_format_get_info(drm_formats[i]); + if (!formats[i]) { + free(formats); + return NULL; + } + } + + return formats; +} diff --git a/libweston/pixel-formats.h b/libweston/pixel-formats.h index 7a9e0902..3fc79972 100644 --- a/libweston/pixel-formats.h +++ b/libweston/pixel-formats.h @@ -354,3 +354,17 @@ pixel_format_get_modifier(uint64_t modifier); */ uint32_t pixel_format_get_shm_format(const struct pixel_format_info *info); + +/** + * Get pixel format array for an array of DRM format codes + * + * Given an array of DRM format codes, return an array of corresponding pixel + * format info pointers. + * + * @param formats Array of DRM format codes to get info for + * @param formats_count Number of entries in formats. + * @returns An array of pixel format info pointers, or NULL if any format could + * not be found. Must be freed by the caller. + */ +const struct pixel_format_info ** +pixel_format_get_array(const uint32_t *formats, unsigned int formats_count);