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 <pekka.paalanen@collabora.com>
This commit is contained in:
Pekka Paalanen 2022-09-02 14:43:56 +03:00
parent 3700c78131
commit c7f5de6d63
2 changed files with 25 additions and 0 deletions

View File

@ -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;
}

View File

@ -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);