From 26024ad434f84defb4523676e03e2ef4e8fee9cc Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 4 Oct 2018 23:35:07 +1000 Subject: [PATCH] Don't schedule unnecessary output frames, and simplify damage functions The `whole` argument has been removed from damage_surface_iterator because it was never used. As this function now only deals with partial damaging, it's been changed to return early if there is no damage and avoids scheduling a frame unnecessarily. With the removal of the `whole` argument, output_damage_from_view just called output_damage_view with the same arguments, so I've combined these into the one function and renamed it to output_damage_view_surfaces. Lastly, output_damage_whole_container_iterator is now removed as it was never used. output_damage_whole_container just damages the container including decorations and doesn't care about surfaces. --- include/sway/output.h | 2 +- sway/desktop/output.c | 73 +++++++++++++++---------------------------- sway/tree/view.c | 2 +- 3 files changed, 28 insertions(+), 49 deletions(-) diff --git a/include/sway/output.h b/include/sway/output.h index 19a611755..32e9926c2 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -75,7 +75,7 @@ void output_damage_whole(struct sway_output *output); void output_damage_surface(struct sway_output *output, double ox, double oy, struct wlr_surface *surface, bool whole); -void output_damage_from_view(struct sway_output *output, +void output_damage_view_surfaces(struct sway_output *output, struct sway_view *view); void output_damage_box(struct sway_output *output, struct wlr_box *box); diff --git a/sway/desktop/output.c b/sway/desktop/output.c index cfb5a710f..5187fe8e1 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -392,44 +392,37 @@ void output_damage_whole(struct sway_output *output) { static void damage_surface_iterator(struct sway_output *output, struct wlr_surface *surface, struct wlr_box *_box, float rotation, - void *_data) { - bool *data = _data; - bool whole = *data; - + void *data) { + if (!pixman_region32_not_empty(&surface->buffer_damage)) { + return; + } struct wlr_box box = *_box; scale_box(&box, output->wlr_output->scale); int center_x = box.x + box.width/2; int center_y = box.y + box.height/2; - if (pixman_region32_not_empty(&surface->buffer_damage)) { - enum wl_output_transform transform = - wlr_output_transform_invert(surface->current.transform); + enum wl_output_transform transform = + wlr_output_transform_invert(surface->current.transform); - pixman_region32_t damage; - pixman_region32_init(&damage); - pixman_region32_copy(&damage, &surface->buffer_damage); - wlr_region_transform(&damage, &damage, transform, - surface->current.buffer_width, surface->current.buffer_height); - wlr_region_scale(&damage, &damage, - output->wlr_output->scale / (float)surface->current.scale); - if (ceil(output->wlr_output->scale) > surface->current.scale) { - // When scaling up a surface, it'll become blurry so we need to - // expand the damage region - wlr_region_expand(&damage, &damage, - ceil(output->wlr_output->scale) - surface->current.scale); - } - pixman_region32_translate(&damage, box.x, box.y); - wlr_region_rotated_bounds(&damage, &damage, rotation, - center_x, center_y); - wlr_output_damage_add(output->damage, &damage); - pixman_region32_fini(&damage); - } - - if (whole) { - wlr_box_rotated_bounds(&box, rotation, &box); - wlr_output_damage_add_box(output->damage, &box); + pixman_region32_t damage; + pixman_region32_init(&damage); + pixman_region32_copy(&damage, &surface->buffer_damage); + wlr_region_transform(&damage, &damage, transform, + surface->current.buffer_width, surface->current.buffer_height); + wlr_region_scale(&damage, &damage, + output->wlr_output->scale / (float)surface->current.scale); + if (ceil(output->wlr_output->scale) > surface->current.scale) { + // When scaling up a surface, it'll become blurry so we need to + // expand the damage region + wlr_region_expand(&damage, &damage, + ceil(output->wlr_output->scale) - surface->current.scale); } + pixman_region32_translate(&damage, box.x, box.y); + wlr_region_rotated_bounds(&damage, &damage, rotation, + center_x, center_y); + wlr_output_damage_add(output->damage, &damage); + pixman_region32_fini(&damage); wlr_output_schedule_frame(output->wlr_output); } @@ -440,17 +433,12 @@ void output_damage_surface(struct sway_output *output, double ox, double oy, damage_surface_iterator, &whole); } -static void output_damage_view(struct sway_output *output, - struct sway_view *view, bool whole) { +void output_damage_view_surfaces(struct sway_output *output, + struct sway_view *view) { if (!view_is_visible(view)) { return; } - output_view_for_each_surface(output, view, damage_surface_iterator, &whole); -} - -void output_damage_from_view(struct sway_output *output, - struct sway_view *view) { - output_damage_view(output, view, false); + output_view_for_each_surface(output, view, damage_surface_iterator, NULL); } // Expecting an unscaled box in layout coordinates @@ -463,15 +451,6 @@ void output_damage_box(struct sway_output *output, struct wlr_box *_box) { wlr_output_damage_add_box(output->damage, &box); } -static void output_damage_whole_container_iterator(struct sway_container *con, - void *data) { - if (!sway_assert(con->view, "expected a view")) { - return; - } - struct sway_output *output = data; - output_damage_view(output, con->view, true); -} - void output_damage_whole_container(struct sway_output *output, struct sway_container *con) { // Pad the box by 1px, because the width is a double and might be a fraction diff --git a/sway/tree/view.c b/sway/tree/view.c index 73ce55ac4..48612c51f 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -371,7 +371,7 @@ void view_close_popups(struct sway_view *view) { void view_damage_from(struct sway_view *view) { for (int i = 0; i < root->outputs->length; ++i) { struct sway_output *output = root->outputs->items[i]; - output_damage_from_view(output, view); + output_damage_view_surfaces(output, view); } }