From 5dc1d4671dd2ca3c1f0f09587c463fdbb542f0a4 Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Sun, 3 Jul 2022 12:20:41 -0400 Subject: [PATCH] wlr_scene: Maintain damage highlight regions per output The logic doesn't support handling multiple outputs so let's not break the assumption and handle damages per output much like how damage_ring is done. --- include/wlr/types/wlr_scene.h | 3 ++- types/scene/wlr_scene.c | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/include/wlr/types/wlr_scene.h b/include/wlr/types/wlr_scene.h index 95f18f37..85d0f94e 100644 --- a/include/wlr/types/wlr_scene.h +++ b/include/wlr/types/wlr_scene.h @@ -93,7 +93,6 @@ struct wlr_scene { struct wl_listener presentation_destroy; enum wlr_scene_debug_damage_option debug_damage_option; - struct wl_list damage_highlight_regions; }; /** A scene-graph node displaying a single surface. */ @@ -178,6 +177,8 @@ struct wlr_scene_output { struct wl_listener output_mode; struct wl_listener output_damage; struct wl_listener output_needs_frame; + + struct wl_list damage_highlight_regions; }; /** A layer shell scene helper */ diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index 828d06e6..68b05b7c 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -74,12 +74,6 @@ struct highlight_region { struct wl_list link; }; -static void highlight_region_destroy(struct highlight_region *damage) { - wl_list_remove(&damage->link); - pixman_region32_fini(&damage->region); - free(damage); -} - void wlr_scene_node_destroy(struct wlr_scene_node *node) { if (node == NULL) { return; @@ -119,11 +113,6 @@ void wlr_scene_node_destroy(struct wlr_scene_node *node) { wlr_scene_output_destroy(scene_output); } - struct highlight_region *damage, *tmp_damage; - wl_list_for_each_safe(damage, tmp_damage, &scene->damage_highlight_regions, link) { - highlight_region_destroy(damage); - } - wl_list_remove(&scene->presentation_destroy.link); } else { assert(node->parent); @@ -158,7 +147,6 @@ struct wlr_scene *wlr_scene_create(void) { wl_list_init(&scene->outputs); wl_list_init(&scene->presentation_destroy.link); - wl_list_init(&scene->damage_highlight_regions); char *debug_damage = getenv("WLR_SCENE_DEBUG_DAMAGE"); if (debug_damage) { @@ -1028,6 +1016,7 @@ struct wlr_scene_output *wlr_scene_output_create(struct wlr_scene *scene, wlr_addon_init(&scene_output->addon, &output->addons, scene, &output_addon_impl); wlr_damage_ring_init(&scene_output->damage_ring); + wl_list_init(&scene_output->damage_highlight_regions); int prev_output_index = -1; struct wl_list *prev_output_link = &scene->outputs; @@ -1065,6 +1054,12 @@ struct wlr_scene_output *wlr_scene_output_create(struct wlr_scene *scene, return scene_output; } +static void highlight_region_destroy(struct highlight_region *damage) { + wl_list_remove(&damage->link); + pixman_region32_fini(&damage->region); + free(damage); +} + void wlr_scene_output_destroy(struct wlr_scene_output *scene_output) { if (scene_output == NULL) { return; @@ -1074,6 +1069,11 @@ void wlr_scene_output_destroy(struct wlr_scene_output *scene_output) { scene_node_update_outputs(&scene_output->scene->tree.node, scene_output); + struct highlight_region *damage, *tmp_damage; + wl_list_for_each_safe(damage, tmp_damage, &scene_output->damage_highlight_regions, link) { + highlight_region_destroy(damage); + } + wlr_addon_finish(&scene_output->addon); wlr_damage_ring_finish(&scene_output->damage_ring); wl_list_remove(&scene_output->link); @@ -1219,7 +1219,7 @@ bool wlr_scene_output_commit(struct wlr_scene_output *scene_output) { struct timespec now; if (debug_damage == WLR_SCENE_DEBUG_DAMAGE_HIGHLIGHT) { - struct wl_list *regions = &scene_output->scene->damage_highlight_regions; + struct wl_list *regions = &scene_output->damage_highlight_regions; clock_gettime(CLOCK_MONOTONIC, &now); // add the current frame's damage if there is damage @@ -1292,7 +1292,7 @@ bool wlr_scene_output_commit(struct wlr_scene_output *scene_output) { if (debug_damage == WLR_SCENE_DEBUG_DAMAGE_HIGHLIGHT) { struct highlight_region *damage; - wl_list_for_each(damage, &scene_output->scene->damage_highlight_regions, link) { + wl_list_for_each(damage, &scene_output->damage_highlight_regions, link) { struct timespec time_diff; timespec_sub(&time_diff, &now, &damage->when); int64_t time_diff_ms = timespec_to_msec(&time_diff); @@ -1340,7 +1340,7 @@ bool wlr_scene_output_commit(struct wlr_scene_output *scene_output) { } if (debug_damage == WLR_SCENE_DEBUG_DAMAGE_HIGHLIGHT && - !wl_list_empty(&scene_output->scene->damage_highlight_regions)) { + !wl_list_empty(&scene_output->damage_highlight_regions)) { wlr_output_schedule_frame(scene_output->output); }