Mesa (main): vulkan/wsi/wayland: de-duplicate wsi_wl_display_add_wl_shm_format

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Feb 15 12:18:02 UTC 2022


Module: Mesa
Branch: main
Commit: 5617d5c88548b4f22f8c665e0337298bc2f8d63f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=5617d5c88548b4f22f8c665e0337298bc2f8d63f

Author: Simon Ser <contact at emersion.fr>
Date:   Fri Feb  4 12:10:09 2022 +0100

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 <contact at emersion.fr>
Reviewed-by: Georg Lehmann <dadschoorse at gmail.com>
Acked-by: Daniel Stone <daniels at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14874>

---

 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 223bb0a01df..84355b049c9 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)
 {



More information about the mesa-commit mailing list