From c7f5de6d63fbaa59c3d95aea90f2a1d0f549cca8 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Fri, 2 Sep 2022 14:43:56 +0300 Subject: [PATCH] libweston: add pixel_format_get_shm_format() This will be useful for client code that wants to create a wl_shm buffer with a DRM format code. The test suite will be using this. Signed-off-by: Pekka Paalanen --- libweston/pixel-formats.c | 16 ++++++++++++++++ libweston/pixel-formats.h | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/libweston/pixel-formats.c b/libweston/pixel-formats.c index fc33997d..3da4b5e2 100644 --- a/libweston/pixel-formats.c +++ b/libweston/pixel-formats.c @@ -760,3 +760,19 @@ pixel_format_get_modifier(uint64_t modifier) return mod_str; } + +WL_EXPORT uint32_t +pixel_format_get_shm_format(const struct pixel_format_info *info) +{ + /* Only these two format codes differ between wl_shm and DRM fourcc */ + switch (info->format) { + case DRM_FORMAT_ARGB8888: + return WL_SHM_FORMAT_ARGB8888; + case DRM_FORMAT_XRGB8888: + return WL_SHM_FORMAT_XRGB8888; + default: + break; + } + + return info->format; +} diff --git a/libweston/pixel-formats.h b/libweston/pixel-formats.h index 849cc8a2..7a9e0902 100644 --- a/libweston/pixel-formats.h +++ b/libweston/pixel-formats.h @@ -345,3 +345,12 @@ pixel_format_height_for_plane(const struct pixel_format_info *format, */ char * pixel_format_get_modifier(uint64_t modifier); + +/** + * Return the wl_shm format code + * + * @param info Pixel format info structure + * @returns The wl_shm format code for this pixel format. + */ +uint32_t +pixel_format_get_shm_format(const struct pixel_format_info *info);