From f5ed7431e53794c13ac9412e1148f485c8507d6f Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Wed, 26 Sep 2018 14:26:53 +0300 Subject: [PATCH] pixel-formats: search by name Add a function to find a format description by the DRM format name. This will be useful when parsing configuration strings. While at it, fix the two function formattings in pixel-formats.h to match everything else in the file. Signed-off-by: Pekka Paalanen --- libweston/pixel-formats.c | 16 ++++++++++++++++ libweston/pixel-formats.h | 24 ++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/libweston/pixel-formats.c b/libweston/pixel-formats.c index 7197455e..c64a9b9e 100644 --- a/libweston/pixel-formats.c +++ b/libweston/pixel-formats.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include "helpers.h" @@ -387,6 +388,21 @@ pixel_format_get_info(uint32_t format) return NULL; } +WL_EXPORT const struct pixel_format_info * +pixel_format_get_info_by_drm_name(const char *drm_format_name) +{ + const struct pixel_format_info *info; + unsigned int i; + + for (i = 0; i < ARRAY_LENGTH(pixel_format_table); i++) { + info = &pixel_format_table[i]; + if (strcasecmp(info->drm_format_name, drm_format_name) == 0) + return info; + } + + 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 10b9084d..1f0ec1bb 100644 --- a/libweston/pixel-formats.h +++ b/libweston/pixel-formats.h @@ -112,7 +112,26 @@ struct pixel_format_info { * @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(uint32_t format); +const struct pixel_format_info * +pixel_format_get_info(uint32_t format); + +/** + * Get pixel format information for a named DRM format + * + * Given a DRM format name, return a pixel format info structure describing + * the properties of that format. + * + * The DRM format name is the preprocessor token name from drm_fourcc.h + * without the DRM_FORMAT_ prefix. The search is also case-insensitive. + * Both "xrgb8888" and "XRGB8888" searches will find DRM_FORMAT_XRGB8888 + * for example. + * + * @param drm_format_name DRM format name to get info for (not NULL) + * @returns A pixel format structure (must not be freed), or NULL if the + * name could not be found + */ +const struct pixel_format_info * +pixel_format_get_info_by_drm_name(const char *drm_format_name); /** * Get number of planes used by a pixel format @@ -140,7 +159,8 @@ pixel_format_get_plane_count(const struct pixel_format_info *format); * @param format Pixel format info structure * @returns True if the format is opaque, or false if it has significant alpha */ -bool pixel_format_is_opaque(const struct pixel_format_info *format); +bool +pixel_format_is_opaque(const struct pixel_format_info *format); /** * Get compatible opaque equivalent for a format