From 713a4363e5f2f1403bd373116985ee1eada5222c Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 20 Jan 2022 12:10:42 +0100 Subject: [PATCH] vulkan/wsi/wayland: remove format switch from wl_shm_format_for_vk_format Instead of maintaining two similar switches (one for DRM formats, one for wl_shm formats), only maintain a single switch (for DRM) and convert DRM formats to enum wl_shm_format. This reduces the risk to have inconsistencies between these two functions. Signed-off-by: Simon Ser Reviewed-by: Georg Lehmann Reviewed-by: Daniel Stone Part-of: --- src/vulkan/wsi/wsi_common_wayland.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index 6c77ce4..b66a495 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -456,23 +456,19 @@ wl_drm_format_for_vk_format(VkFormat vk_format, bool alpha) static enum wl_shm_format wl_shm_format_for_vk_format(VkFormat vk_format, bool alpha) { - switch (vk_format) { - case VK_FORMAT_R8G8B8A8_UNORM: - case VK_FORMAT_R8G8B8A8_SRGB: - return alpha ? WL_SHM_FORMAT_ABGR8888 : WL_SHM_FORMAT_XBGR8888; - case VK_FORMAT_B8G8R8A8_UNORM: - case VK_FORMAT_B8G8R8A8_SRGB: - return alpha ? WL_SHM_FORMAT_ARGB8888 : WL_SHM_FORMAT_XRGB8888; - case VK_FORMAT_R8G8B8_UNORM: - case VK_FORMAT_R8G8B8_SRGB: - return WL_SHM_FORMAT_XBGR8888; - case VK_FORMAT_B8G8R8_UNORM: - case VK_FORMAT_B8G8R8_SRGB: - return WL_SHM_FORMAT_XRGB8888; + uint32_t drm_format = wl_drm_format_for_vk_format(vk_format, alpha); + if (drm_format == DRM_FORMAT_INVALID) { + return 0; + } + /* wl_shm formats are identical to DRM, except ARGB8888 and XRGB8888 */ + switch (drm_format) { + case DRM_FORMAT_ARGB8888: + return WL_SHM_FORMAT_ARGB8888; + case DRM_FORMAT_XRGB8888: + return WL_SHM_FORMAT_XRGB8888; default: - assert(!"Unsupported Vulkan format"); - return 0; + return drm_format; } } -- 2.7.4