From 9583195e965c3eb61afdb064b1c13917c38a2dd5 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Fri, 29 Mar 2024 17:36:09 +0100 Subject: [PATCH] gdk/wayland: Make the surface handle empty commits In order to avoid some code duplication and ensure the Cairo and Vulkan implementations behave like the GL one. --- gdk/wayland/gdkcairocontext-wayland.c | 11 +---------- gdk/wayland/gdkglcontext-wayland.c | 9 +-------- gdk/wayland/gdkprivate-wayland.h | 2 +- gdk/wayland/gdksurface-wayland.c | 16 +++++++++++++++- gdk/wayland/gdkvulkancontext-wayland.c | 10 +--------- 5 files changed, 19 insertions(+), 29 deletions(-) diff --git a/gdk/wayland/gdkcairocontext-wayland.c b/gdk/wayland/gdkcairocontext-wayland.c index a078526544..cc8419701b 100644 --- a/gdk/wayland/gdkcairocontext-wayland.c +++ b/gdk/wayland/gdkcairocontext-wayland.c @@ -198,17 +198,8 @@ static void gdk_wayland_cairo_context_empty_frame (GdkDrawContext *draw_context) { GdkSurface *surface = gdk_draw_context_get_surface (draw_context); - GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface); - if (!impl->has_pending_subsurface_commits) - return; - - gdk_wayland_surface_sync (surface); - gdk_wayland_surface_request_frame (surface); - - gdk_profiler_add_mark (GDK_PROFILER_CURRENT_TIME, 0, "Wayland surface commit", NULL); - gdk_wayland_surface_commit (surface); - gdk_wayland_surface_notify_committed (surface); + gdk_wayland_surface_handle_empty_frame (surface); } static void diff --git a/gdk/wayland/gdkglcontext-wayland.c b/gdk/wayland/gdkglcontext-wayland.c index 13b17cd60c..633be27024 100644 --- a/gdk/wayland/gdkglcontext-wayland.c +++ b/gdk/wayland/gdkglcontext-wayland.c @@ -88,14 +88,7 @@ gdk_wayland_gl_context_empty_frame (GdkDrawContext *draw_context) { GdkSurface *surface = gdk_draw_context_get_surface (draw_context); - if (gdk_wayland_surface_needs_commit (surface)) - { - gdk_wayland_surface_sync (surface); - gdk_wayland_surface_request_frame (surface); - - gdk_wayland_surface_commit (surface); - gdk_wayland_surface_notify_committed (surface); - } + gdk_wayland_surface_handle_empty_frame (surface); } static void diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h index 9dade70f73..9fcfacd711 100644 --- a/gdk/wayland/gdkprivate-wayland.h +++ b/gdk/wayland/gdkprivate-wayland.h @@ -131,7 +131,7 @@ guint _gdk_wayland_cursor_get_next_image_index (GdkWaylandDisplay *display, guint *next_image_delay); void gdk_wayland_surface_sync (GdkSurface *surface); -gboolean gdk_wayland_surface_needs_commit (GdkSurface *surface); +void gdk_wayland_surface_handle_empty_frame (GdkSurface *surface); void gdk_wayland_surface_commit (GdkSurface *surface); void gdk_wayland_surface_notify_committed (GdkSurface *surface); void gdk_wayland_surface_request_frame (GdkSurface *surface); diff --git a/gdk/wayland/gdksurface-wayland.c b/gdk/wayland/gdksurface-wayland.c index 0aae4f6946..ce5f0558f8 100644 --- a/gdk/wayland/gdksurface-wayland.c +++ b/gdk/wayland/gdksurface-wayland.c @@ -775,7 +775,7 @@ gdk_wayland_surface_sync (GdkSurface *surface) gdk_wayland_surface_sync_viewport (surface); } -gboolean +static gboolean gdk_wayland_surface_needs_commit (GdkSurface *surface) { GdkWaylandSurface *self = GDK_WAYLAND_SURFACE (surface); @@ -787,6 +787,20 @@ gdk_wayland_surface_needs_commit (GdkSurface *surface) self->viewport_dirty; } +void +gdk_wayland_surface_handle_empty_frame (GdkSurface *surface) +{ + if (!gdk_wayland_surface_needs_commit (surface)) + return; + + gdk_wayland_surface_sync (surface); + gdk_wayland_surface_request_frame (surface); + + gdk_profiler_add_mark (GDK_PROFILER_CURRENT_TIME, 0, "Wayland surface commit", NULL); + gdk_wayland_surface_commit (surface); + gdk_wayland_surface_notify_committed (surface); +} + static void gdk_wayland_surface_fractional_scale_preferred_scale_cb (void *data, struct wp_fractional_scale_v1 *fractional_scale, diff --git a/gdk/wayland/gdkvulkancontext-wayland.c b/gdk/wayland/gdkvulkancontext-wayland.c index 75893050dc..ca1db019ef 100644 --- a/gdk/wayland/gdkvulkancontext-wayland.c +++ b/gdk/wayland/gdkvulkancontext-wayland.c @@ -77,16 +77,8 @@ static void gdk_vulkan_context_wayland_empty_frame (GdkDrawContext *context) { GdkSurface *surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context)); - GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface); - if (!impl->has_pending_subsurface_commits) - return; - - gdk_wayland_surface_sync (surface); - gdk_wayland_surface_request_frame (surface); - - gdk_wayland_surface_commit (surface); - gdk_wayland_surface_notify_committed (surface); + gdk_wayland_surface_handle_empty_frame (surface); } static void