diff --git a/src/loader/loader_wayland_helper.c b/src/loader/loader_wayland_helper.c index ffbbca83658..5953f3e7bed 100644 --- a/src/loader/loader_wayland_helper.c +++ b/src/loader/loader_wayland_helper.c @@ -23,6 +23,8 @@ #include #include +#include "util/perf/cpu_trace.h" + #include "loader_wayland_helper.h" #ifndef HAVE_WL_DISPATCH_QUEUE_TIMEOUT @@ -141,3 +143,23 @@ wl_display_create_queue_with_name(struct wl_display *display, const char *name) return wl_display_create_queue(display); } #endif + +int +loader_wayland_dispatch(struct wl_display *wl_display, + struct wl_event_queue *queue, + struct timespec *end_time) +{ + struct timespec current_time; + struct timespec remaining_timeout; + + MESA_TRACE_FUNC(); + + if (!end_time) + return wl_display_dispatch_queue(wl_display, queue); + + clock_gettime(CLOCK_MONOTONIC, ¤t_time); + timespec_sub_saturate(&remaining_timeout, end_time, ¤t_time); + return wl_display_dispatch_queue_timeout(wl_display, + queue, + &remaining_timeout); +} diff --git a/src/loader/loader_wayland_helper.h b/src/loader/loader_wayland_helper.h index 56f47e31858..45f412a6c7b 100644 --- a/src/loader/loader_wayland_helper.h +++ b/src/loader/loader_wayland_helper.h @@ -40,4 +40,9 @@ wl_display_create_queue_with_name(struct wl_display *display, const char *name); #endif +int +loader_wayland_dispatch(struct wl_display *display, + struct wl_event_queue *queue, + struct timespec *end_time); + #endif diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index b9d103bc256..3c7ced0aaf0 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -1738,12 +1738,9 @@ dispatch_present_id_queue(struct wsi_swapchain *wsi_chain, struct timespec *end_ */ pthread_mutex_unlock(&chain->present_ids.lock); - struct timespec current_time, remaining_timeout; - clock_gettime(CLOCK_MONOTONIC, ¤t_time); - timespec_sub_saturate(&remaining_timeout, end_time, ¤t_time); - ret = wl_display_dispatch_queue_timeout(wl_display, - chain->present_ids.queue, - &remaining_timeout); + ret = loader_wayland_dispatch(wl_display, + chain->present_ids.queue, + end_time); pthread_mutex_lock(&chain->present_ids.lock); @@ -1770,7 +1767,6 @@ wsi_wl_swapchain_wait_for_present(struct wsi_swapchain *wsi_chain, uint64_t timeout) { struct wsi_wl_swapchain *chain = (struct wsi_wl_swapchain *)wsi_chain; - struct timespec end_time; VkResult ret; int err; @@ -1880,14 +1876,10 @@ wsi_wl_swapchain_acquire_next_image_implicit(struct wsi_swapchain *wsi_chain, } } - struct timespec current_time, remaining_timeout; - clock_gettime(CLOCK_MONOTONIC, ¤t_time); - timespec_sub_saturate(&remaining_timeout, &end_time, ¤t_time); - /* Try to dispatch potential events. */ - int ret = wl_display_dispatch_queue_timeout(wsi_wl_surface->display->wl_display, - wsi_wl_surface->display->queue, - &remaining_timeout); + int ret = loader_wayland_dispatch(wsi_wl_surface->display->wl_display, + wsi_wl_surface->display->queue, + &end_time); if (ret == -1) return VK_ERROR_OUT_OF_DATE_KHR;