From d2aa62a074b3bf4ce6d22c2bf42f62fad3a925d5 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Wed, 20 Jul 2022 15:11:10 +0300 Subject: [PATCH] libweston: add pixel_format_get_info_by_pixman() Sometimes you will have a pixman_image_t and you need the corresponding drm_fourcc format. Signed-off-by: Pekka Paalanen --- libweston/pixel-formats.c | 13 +++++++++++++ libweston/pixel-formats.h | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/libweston/pixel-formats.c b/libweston/pixel-formats.c index 261946c7..fc33997d 100644 --- a/libweston/pixel-formats.c +++ b/libweston/pixel-formats.c @@ -636,6 +636,19 @@ pixel_format_get_info_by_drm_name(const char *drm_format_name) return NULL; } +WL_EXPORT const struct pixel_format_info * +pixel_format_get_info_by_pixman(pixman_format_code_t pixman_format) +{ + unsigned int i; + + for (i = 0; i < ARRAY_LENGTH(pixel_format_table); i++) { + if (pixel_format_table[i].pixman_format == pixman_format) + return &pixel_format_table[i]; + } + + return NULL; +} + WL_EXPORT unsigned int pixel_format_get_plane_count(const struct pixel_format_info *info) { diff --git a/libweston/pixel-formats.h b/libweston/pixel-formats.h index bbd1bff8..849cc8a2 100644 --- a/libweston/pixel-formats.h +++ b/libweston/pixel-formats.h @@ -190,6 +190,19 @@ pixel_format_get_info_count(void); const struct pixel_format_info * pixel_format_get_info_by_drm_name(const char *drm_format_name); +/** + * Get pixel format information for a Pixman format code + * + * Given a Pixman format code, return a pixel format info structure describing + * the properties of that format. + * + * @param pixman_format Pixman format code to get info for + * @returns A pixel format structure (must not be freed), or NULL if the + * format could not be found + */ +const struct pixel_format_info * +pixel_format_get_info_by_pixman(pixman_format_code_t pixman_format); + /** * Get number of planes used by a pixel format *