From d18f1022752902e72bc9b97b521e85bc5cb4e195 Mon Sep 17 00:00:00 2001 From: Leandro Ribeiro Date: Wed, 4 Aug 2021 20:33:41 -0300 Subject: [PATCH] vulkan/wsi/wayland: add helper function find_format() There are some places in the code in which we search for a certain format in the u_vector. This new function help us to avoid repetition. Signed-off-by: Leandro Ribeiro Reviewed-by: Simon Ser Acked-by: Daniel Stone Part-of: --- src/vulkan/wsi/wsi_common_wayland.c | 44 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index ec55bdf4e18..4ad33e46941 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -83,15 +83,26 @@ struct wsi_wayland { VkPhysicalDevice physical_device; }; +static struct wsi_wl_format * +find_format(struct u_vector *formats, VkFormat format) +{ + struct wsi_wl_format *f; + + u_vector_foreach(f, formats) + if (f->vk_format == format) + return f; + + return NULL; +} + static struct wsi_wl_format * wsi_wl_display_add_vk_format(struct wsi_wl_display *display, struct u_vector *formats, VkFormat format) { /* Don't add a format that's already in the list */ - struct wsi_wl_format *f; - u_vector_foreach(f, formats) - if (f->vk_format == format) - return f; + struct wsi_wl_format *f = find_format(formats, format); + if (f) + return f; /* Don't add formats that aren't renderable. */ VkFormatProperties props; @@ -495,14 +506,12 @@ wsi_wl_display_init(struct wsi_wayland *wsi_wl, * can find it. Some apps get confused if SRGB is first in the list. */ struct wsi_wl_format *first_fmt = u_vector_head(&display->formats); - struct wsi_wl_format *iter_fmt, tmp_fmt; - u_vector_foreach(iter_fmt, &display->formats) { - if (iter_fmt->vk_format == VK_FORMAT_B8G8R8A8_UNORM) { - tmp_fmt = *iter_fmt; - *iter_fmt = *first_fmt; - *first_fmt = tmp_fmt; - break; - } + struct wsi_wl_format *f, tmp_fmt; + f = find_format(&display->formats, VK_FORMAT_B8G8R8A8_UNORM); + if (f) { + tmp_fmt = *f; + *f = *first_fmt; + *first_fmt = tmp_fmt; } } @@ -1190,15 +1199,8 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, * support them. */ if (chain->display->wl_dmabuf && chain->base.wsi->supports_modifiers) { - struct wsi_wl_format *f; - bool found = false; - u_vector_foreach(f, &chain->display->formats) { - if (f->vk_format == chain->vk_format) { - found = true; - break; - } - } - if (found) { + struct wsi_wl_format *f = find_format(&chain->display->formats, chain->vk_format); + if (f) { chain->drm_modifiers = u_vector_tail(&f->modifiers); chain->num_drm_modifiers = u_vector_length(&f->modifiers); }