From 5617d5c88548b4f22f8c665e0337298bc2f8d63f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 4 Feb 2022 12:10:09 +0100 Subject: [PATCH] vulkan/wsi/wayland: de-duplicate wsi_wl_display_add_wl_shm_format Re-use wsi_wl_display_add_drm_format_modifier from wsi_wl_display_add_wl_shm_format instead of maintaining two separate switches for DRM and shm formats. Signed-off-by: Simon Ser Reviewed-by: Georg Lehmann Acked-by: Daniel Stone Part-of: --- src/vulkan/wsi/wsi_common_wayland.c | 68 +++++++++++-------------------------- 1 file changed, 19 insertions(+), 49 deletions(-) diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index 223bb0a..84355b0 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -349,61 +349,31 @@ wsi_wl_display_add_drm_format_modifier(struct wsi_wl_display *display, } } -static void -wsi_wl_display_add_wl_shm_format(struct wsi_wl_display *display, - struct u_vector *formats, - enum wl_shm_format wl_shm_format) +static uint32_t +drm_format_for_wl_shm_format(enum wl_shm_format shm_format) { - switch (wl_shm_format) { - case WL_SHM_FORMAT_XBGR8888: - wsi_wl_display_add_vk_format(display, formats, - VK_FORMAT_R8G8B8_SRGB, - WSI_WL_FMT_ALPHA | WSI_WL_FMT_OPAQUE); - wsi_wl_display_add_vk_format(display, formats, - VK_FORMAT_R8G8B8_UNORM, - WSI_WL_FMT_ALPHA | WSI_WL_FMT_OPAQUE); - wsi_wl_display_add_vk_format(display, formats, - VK_FORMAT_R8G8B8A8_SRGB, - WSI_WL_FMT_OPAQUE); - wsi_wl_display_add_vk_format(display, formats, - VK_FORMAT_R8G8B8A8_UNORM, - WSI_WL_FMT_OPAQUE); - break; - case WL_SHM_FORMAT_ABGR8888: - wsi_wl_display_add_vk_format(display, formats, - VK_FORMAT_R8G8B8A8_SRGB, - WSI_WL_FMT_ALPHA); - wsi_wl_display_add_vk_format(display, formats, - VK_FORMAT_R8G8B8A8_UNORM, - WSI_WL_FMT_ALPHA); - break; - case WL_SHM_FORMAT_XRGB8888: - wsi_wl_display_add_vk_format(display, formats, - VK_FORMAT_B8G8R8_SRGB, - WSI_WL_FMT_ALPHA | WSI_WL_FMT_OPAQUE); - wsi_wl_display_add_vk_format(display, formats, - VK_FORMAT_B8G8R8_UNORM, - WSI_WL_FMT_ALPHA | WSI_WL_FMT_OPAQUE); - wsi_wl_display_add_vk_format(display, formats, - VK_FORMAT_B8G8R8A8_SRGB, - WSI_WL_FMT_OPAQUE); - wsi_wl_display_add_vk_format(display, formats, - VK_FORMAT_B8G8R8A8_UNORM, - WSI_WL_FMT_OPAQUE); - break; + /* wl_shm formats are identical to DRM, except ARGB8888 and XRGB8888 */ + switch (shm_format) { case WL_SHM_FORMAT_ARGB8888: - wsi_wl_display_add_vk_format(display, formats, - VK_FORMAT_B8G8R8A8_SRGB, - WSI_WL_FMT_ALPHA); - wsi_wl_display_add_vk_format(display, formats, - VK_FORMAT_B8G8R8A8_UNORM, - WSI_WL_FMT_ALPHA); - break; + return DRM_FORMAT_ARGB8888; + case WL_SHM_FORMAT_XRGB8888: + return DRM_FORMAT_XRGB8888; default: - break; /* Ignore */ + return shm_format; } } +static void +wsi_wl_display_add_wl_shm_format(struct wsi_wl_display *display, + struct u_vector *formats, + enum wl_shm_format shm_format) +{ + uint32_t drm_format = drm_format_for_wl_shm_format(shm_format); + + wsi_wl_display_add_drm_format_modifier(display, formats, drm_format, + DRM_FORMAT_MOD_INVALID); +} + static uint32_t wl_drm_format_for_vk_format(VkFormat vk_format, bool alpha) { -- 2.7.4