From 4154f874187e48c8af26ad4889238c01e5ac147a Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 22 Apr 2023 16:10:24 +0200 Subject: [PATCH 1/6] surface: Stop tracking the active update area It's unused. --- gdk/gdksurface.c | 12 +++--------- gdk/gdksurfaceprivate.h | 4 ---- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c index 7120da78db..279bafd6ad 100644 --- a/gdk/gdksurface.c +++ b/gdk/gdksurface.c @@ -1346,25 +1346,19 @@ gdk_surface_process_updates_internal (GdkSurface *surface) */ if (surface->update_area) { - g_assert (surface->active_update_area == NULL); /* No reentrancy */ + cairo_region_t *expose_region; - surface->active_update_area = surface->update_area; + expose_region = surface->update_area; surface->update_area = NULL; if (GDK_SURFACE_IS_MAPPED (surface)) { - cairo_region_t *expose_region; gboolean handled; - expose_region = cairo_region_copy (surface->active_update_area); - g_signal_emit (surface, signals[RENDER], 0, expose_region, &handled); - - cairo_region_destroy (expose_region); } - cairo_region_destroy (surface->active_update_area); - surface->active_update_area = NULL; + cairo_region_destroy (expose_region); } surface->in_update = FALSE; diff --git a/gdk/gdksurfaceprivate.h b/gdk/gdksurfaceprivate.h index 24562c7848..8b210439a5 100644 --- a/gdk/gdksurfaceprivate.h +++ b/gdk/gdksurfaceprivate.h @@ -55,10 +55,6 @@ struct _GdkSurface cairo_region_t *update_area; guint update_freeze_count; GdkFrameClockPhase pending_phases; - /* This is the update_area that was in effect when the current expose - started. It may be smaller than the expose area if we'e painting - more than we have to, but it represents the "true" damage. */ - cairo_region_t *active_update_area; GdkToplevelState pending_set_flags; GdkToplevelState pending_unset_flags; From 040af44b005b4a4ef7290f9b15a4d7f4d4234351 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 22 Apr 2023 16:24:16 +0200 Subject: [PATCH 2/6] surface: Remove in_update tracking It's 2023, we use frame clocks now and don't have nested surface drawing anymore. --- gdk/gdksurface.c | 10 +--------- gdk/gdksurfaceprivate.h | 1 - 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c index 279bafd6ad..2de27870cc 100644 --- a/gdk/gdksurface.c +++ b/gdk/gdksurface.c @@ -1338,8 +1338,6 @@ gdk_surface_process_updates_internal (GdkSurface *surface) /* Ensure the surface lives while updating it */ g_object_ref (surface); - surface->in_update = TRUE; - /* If an update got queued during update processing, we can get a * surface in the update queue that has an empty update_area. * just ignore it. @@ -1361,8 +1359,6 @@ gdk_surface_process_updates_internal (GdkSurface *surface) cairo_region_destroy (expose_region); } - surface->in_update = FALSE; - g_object_unref (surface); } @@ -1433,11 +1429,7 @@ gdk_surface_paint_on_clock (GdkFrameClock *clock, if (surface->update_area && !surface->update_freeze_count && - !gdk_surface_is_toplevel_frozen (surface) && - - /* Don't recurse into process_updates_internal, we'll - * do the update later when idle instead. */ - !surface->in_update) + !gdk_surface_is_toplevel_frozen (surface)) { surface->pending_phases &= ~GDK_FRAME_CLOCK_PHASE_PAINT; gdk_surface_process_updates_internal (surface); diff --git a/gdk/gdksurfaceprivate.h b/gdk/gdksurfaceprivate.h index 8b210439a5..a8587a8442 100644 --- a/gdk/gdksurfaceprivate.h +++ b/gdk/gdksurfaceprivate.h @@ -67,7 +67,6 @@ struct _GdkSurface guint modal_hint : 1; guint destroyed : 2; - guint in_update : 1; guint frame_clock_events_paused : 1; guint autohide : 1; guint shortcuts_inhibited : 1; From be0ed15b40cf2090feeb65a4c5916e251504136c Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 22 Apr 2023 16:27:27 +0200 Subject: [PATCH 3/6] surface: Stop maintaining an unused linked list wat? --- gdk/gdksurface.c | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c index 2de27870cc..d34fbf3519 100644 --- a/gdk/gdksurface.c +++ b/gdk/gdksurface.c @@ -1270,40 +1270,6 @@ gdk_surface_create_vulkan_context (GdkSurface *surface, NULL); } -/* Code for dirty-region queueing - */ -static GSList *update_surfaces = NULL; - -static void -gdk_surface_add_update_surface (GdkSurface *surface) -{ - GSList *tmp; - - /* Check whether "surface" is already in "update_surfaces" list. - * It could be added during execution of gtk_widget_destroy() when - * setting focus widget to NULL and redrawing old focus widget. - * See bug 711552. - */ - tmp = g_slist_find (update_surfaces, surface); - if (tmp != NULL) - return; - - update_surfaces = g_slist_prepend (update_surfaces, g_object_ref (surface)); -} - -static void -gdk_surface_remove_update_surface (GdkSurface *surface) -{ - GSList *link; - - link = g_slist_find (update_surfaces, surface); - if (link != NULL) - { - update_surfaces = g_slist_delete_link (update_surfaces, link); - g_object_unref (surface); - } -} - static gboolean gdk_surface_is_toplevel_frozen (GdkSurface *surface) { @@ -1433,7 +1399,6 @@ gdk_surface_paint_on_clock (GdkFrameClock *clock, { surface->pending_phases &= ~GDK_FRAME_CLOCK_PHASE_PAINT; gdk_surface_process_updates_internal (surface); - gdk_surface_remove_update_surface (surface); } g_object_unref (surface); @@ -1484,7 +1449,6 @@ impl_surface_add_update_area (GdkSurface *impl_surface, cairo_region_union (impl_surface->update_area, region); else { - gdk_surface_add_update_surface (impl_surface); impl_surface->update_area = cairo_region_copy (region); gdk_surface_schedule_update (impl_surface); } @@ -1568,8 +1532,6 @@ _gdk_surface_clear_update_area (GdkSurface *surface) if (surface->update_area) { - gdk_surface_remove_update_surface (surface); - cairo_region_destroy (surface->update_area); surface->update_area = NULL; } From 823eb4c6d9c03772bdac7cb21e8b3e53c36b5f9c Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 22 Apr 2023 16:29:58 +0200 Subject: [PATCH 4/6] surface: Fold function into its only caller No other changes --- gdk/gdksurface.c | 57 ++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c index d34fbf3519..385f5e3e91 100644 --- a/gdk/gdksurface.c +++ b/gdk/gdksurface.c @@ -1298,36 +1298,6 @@ gdk_surface_schedule_update (GdkSurface *surface) GDK_FRAME_CLOCK_PHASE_PAINT); } -static void -gdk_surface_process_updates_internal (GdkSurface *surface) -{ - /* Ensure the surface lives while updating it */ - g_object_ref (surface); - - /* If an update got queued during update processing, we can get a - * surface in the update queue that has an empty update_area. - * just ignore it. - */ - if (surface->update_area) - { - cairo_region_t *expose_region; - - expose_region = surface->update_area; - surface->update_area = NULL; - - if (GDK_SURFACE_IS_MAPPED (surface)) - { - gboolean handled; - - g_signal_emit (surface, signals[RENDER], 0, expose_region, &handled); - } - - cairo_region_destroy (expose_region); - } - - g_object_unref (surface); -} - static void gdk_surface_layout_on_clock (GdkFrameClock *clock, void *data) @@ -1398,7 +1368,32 @@ gdk_surface_paint_on_clock (GdkFrameClock *clock, !gdk_surface_is_toplevel_frozen (surface)) { surface->pending_phases &= ~GDK_FRAME_CLOCK_PHASE_PAINT; - gdk_surface_process_updates_internal (surface); + + /* Ensure the surface lives while updating it */ + g_object_ref (surface); + + /* If an update got queued during update processing, we can get a + * surface in the update queue that has an empty update_area. + * just ignore it. + */ + if (surface->update_area) + { + cairo_region_t *expose_region; + + expose_region = surface->update_area; + surface->update_area = NULL; + + if (GDK_SURFACE_IS_MAPPED (surface)) + { + gboolean handled; + + g_signal_emit (surface, signals[RENDER], 0, expose_region, &handled); + } + + cairo_region_destroy (expose_region); + } + + g_object_unref (surface); } g_object_unref (surface); From 893862a51a5a8734575000f2c66a5556d52a9f83 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 22 Apr 2023 16:33:35 +0200 Subject: [PATCH 5/6] surface: Refactor code Move the early exit conditions to the top and turn them into early exits instead of nesting if statements. --- gdk/gdksurface.c | 50 +++++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c index 385f5e3e91..34052799e8 100644 --- a/gdk/gdksurface.c +++ b/gdk/gdksurface.c @@ -1355,47 +1355,37 @@ gdk_surface_paint_on_clock (GdkFrameClock *clock, void *data) { GdkSurface *surface = GDK_SURFACE (data); + cairo_region_t *expose_region; g_return_if_fail (GDK_IS_SURFACE (surface)); - if (GDK_SURFACE_DESTROYED (surface)) + if (GDK_SURFACE_DESTROYED (surface) || + !surface->update_area || + surface->update_freeze_count || + gdk_surface_is_toplevel_frozen (surface)) return; g_object_ref (surface); - if (surface->update_area && - !surface->update_freeze_count && - !gdk_surface_is_toplevel_frozen (surface)) + surface->pending_phases &= ~GDK_FRAME_CLOCK_PHASE_PAINT; + + /* Ensure the surface lives while updating it */ + g_object_ref (surface); + + expose_region = surface->update_area; + surface->update_area = NULL; + + if (GDK_SURFACE_IS_MAPPED (surface)) { - surface->pending_phases &= ~GDK_FRAME_CLOCK_PHASE_PAINT; + gboolean handled; - /* Ensure the surface lives while updating it */ - g_object_ref (surface); - - /* If an update got queued during update processing, we can get a - * surface in the update queue that has an empty update_area. - * just ignore it. - */ - if (surface->update_area) - { - cairo_region_t *expose_region; - - expose_region = surface->update_area; - surface->update_area = NULL; - - if (GDK_SURFACE_IS_MAPPED (surface)) - { - gboolean handled; - - g_signal_emit (surface, signals[RENDER], 0, expose_region, &handled); - } - - cairo_region_destroy (expose_region); - } - - g_object_unref (surface); + g_signal_emit (surface, signals[RENDER], 0, expose_region, &handled); } + cairo_region_destroy (expose_region); + + g_object_unref (surface); + g_object_unref (surface); } From 104b5ef157b53c8fd766eb157485e58758b4c3dc Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 22 Apr 2023 16:35:16 +0200 Subject: [PATCH 6/6] surface: reformat function Make the function follow usual coding conventions. And while doing that, remove duplicate functionality. --- gdk/gdksurface.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c index 34052799e8..4a3409508e 100644 --- a/gdk/gdksurface.c +++ b/gdk/gdksurface.c @@ -1365,13 +1365,7 @@ gdk_surface_paint_on_clock (GdkFrameClock *clock, gdk_surface_is_toplevel_frozen (surface)) return; - g_object_ref (surface); - surface->pending_phases &= ~GDK_FRAME_CLOCK_PHASE_PAINT; - - /* Ensure the surface lives while updating it */ - g_object_ref (surface); - expose_region = surface->update_area; surface->update_area = NULL; @@ -1379,14 +1373,14 @@ gdk_surface_paint_on_clock (GdkFrameClock *clock, { gboolean handled; + g_object_ref (surface); + g_signal_emit (surface, signals[RENDER], 0, expose_region, &handled); + + g_object_unref (surface); } cairo_region_destroy (expose_region); - - g_object_unref (surface); - - g_object_unref (surface); } /*