From c8a9ea3903fbb5f81dad87a1d6ccb50e38d66e3f Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 5 May 2018 18:51:13 +0100 Subject: [PATCH 1/7] Implement full damage tracking --- sway/desktop/output.c | 142 +++++++++++++++++++++++++++++++----------- 1 file changed, 106 insertions(+), 36 deletions(-) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 9b0f1ae3..9eeed9b9 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -163,14 +163,38 @@ static void scale_box(struct wlr_box *box, float scale) { struct render_data { struct root_geometry root_geo; struct sway_output *output; + pixman_region32_t *damage; float alpha; }; +static void scissor_output(struct wlr_output *wlr_output, + pixman_box32_t *rect) { + struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); + assert(renderer); + + struct wlr_box box = { + .x = rect->x1, + .y = rect->y1, + .width = rect->x2 - rect->x1, + .height = rect->y2 - rect->y1, + }; + + int ow, oh; + wlr_output_transformed_resolution(wlr_output, &ow, &oh); + + enum wl_output_transform transform = + wlr_output_transform_invert(wlr_output->transform); + wlr_box_transform(&box, transform, ow, oh, &box); + + wlr_renderer_scissor(renderer, &box); +} + static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy, void *_data) { struct render_data *data = _data; struct wlr_output *wlr_output = data->output->wlr_output; float rotation = data->root_geo.rotation; + pixman_region32_t *output_damage = data->damage; float alpha = data->alpha; if (!wlr_surface_has_buffer(surface)) { @@ -184,6 +208,18 @@ static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy, return; } + scale_box(&box, wlr_output->scale); + + pixman_region32_t damage; + pixman_region32_init(&damage); + pixman_region32_union_rect(&damage, &damage, box.x, box.y, + box.width, box.height); + pixman_region32_intersect(&damage, &damage, output_damage); + bool damaged = pixman_region32_not_empty(&damage); + if (!damaged) { + goto damage_finish; + } + struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); if (!sway_assert(renderer != NULL, @@ -191,34 +227,53 @@ static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy, return; } - scale_box(&box, wlr_output->scale); - float matrix[9]; enum wl_output_transform transform = wlr_output_transform_invert(surface->current->transform); wlr_matrix_project_box(matrix, &box, transform, rotation, wlr_output->transform_matrix); - wlr_render_texture_with_matrix(renderer, surface->texture, - matrix, alpha); + int nrects; + pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); + for (int i = 0; i < nrects; ++i) { + scissor_output(wlr_output, &rects[i]); + wlr_render_texture_with_matrix(renderer, surface->texture, matrix, + alpha); + } + +damage_finish: + pixman_region32_fini(&damage); } static void render_layer(struct sway_output *output, - struct wl_list *layer_surfaces) { - struct render_data data = { .output = output, .alpha = 1.0f }; + pixman_region32_t *damage, struct wl_list *layer_surfaces) { + struct render_data data = { + .output = output, + .damage = damage, + .alpha = 1.0f, + }; layer_for_each_surface(layer_surfaces, &data.root_geo, render_surface_iterator, &data); } static void render_unmanaged(struct sway_output *output, - struct wl_list *unmanaged) { - struct render_data data = { .output = output, .alpha = 1.0f }; + pixman_region32_t *damage, struct wl_list *unmanaged) { + struct render_data data = { + .output = output, + .damage = damage, + .alpha = 1.0f, + }; unmanaged_for_each_surface(unmanaged, output, &data.root_geo, render_surface_iterator, &data); } -static void render_view(struct sway_view *view, struct sway_output *output) { - struct render_data data = { .output = output, .alpha = view->swayc->alpha }; +static void render_view(struct sway_view *view, struct sway_output *output, + pixman_region32_t *damage) { + struct render_data data = { + .output = output, + .damage = damage, + .alpha = view->swayc->alpha, + }; output_view_for_each_surface( view, &data.root_geo, render_surface_iterator, &data); } @@ -381,7 +436,7 @@ static void render_container_simple_border_pixel(struct sway_output *output, } static void render_container(struct sway_output *output, - struct sway_container *con); + pixman_region32_t *damage, struct sway_container *con); /** * Render a container's children using a L_HORIZ or L_VERT layout. @@ -390,7 +445,7 @@ static void render_container(struct sway_output *output, * they'll apply their own borders to their children. */ static void render_container_simple(struct sway_output *output, - struct sway_container *con) { + pixman_region32_t *damage, struct sway_container *con) { struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *focus = seat_get_focus(seat); @@ -419,9 +474,9 @@ static void render_container_simple(struct sway_output *output, render_container_simple_border_pixel(output, child, colors); } } - render_view(child->sway_view, output); + render_view(child->sway_view, output, damage); } else { - render_container(output, child); + render_container(output, damage, child); } } } @@ -430,7 +485,7 @@ static void render_container_simple(struct sway_output *output, * Render a container's children using the L_TABBED layout. */ static void render_container_tabbed(struct sway_output *output, - struct sway_container *con) { + pixman_region32_t *damage, struct sway_container *con) { // TODO } @@ -438,23 +493,23 @@ static void render_container_tabbed(struct sway_output *output, * Render a container's children using the L_STACKED layout. */ static void render_container_stacked(struct sway_output *output, - struct sway_container *con) { + pixman_region32_t *damage, struct sway_container *con) { // TODO } static void render_container(struct sway_output *output, - struct sway_container *con) { + pixman_region32_t *damage, struct sway_container *con) { switch (con->layout) { case L_NONE: case L_HORIZ: case L_VERT: - render_container_simple(output, con); + render_container_simple(output, damage, con); break; case L_STACKED: - render_container_stacked(output, con); + render_container_stacked(output, damage, con); break; case L_TABBED: - render_container_tabbed(output, con); + render_container_tabbed(output, damage, con); break; case L_FLOATING: // TODO @@ -496,37 +551,51 @@ static void render_output(struct sway_output *output, struct timespec *when, goto renderer_end; } - // TODO: don't damage the whole output - int width, height; - wlr_output_transformed_resolution(wlr_output, &width, &height); - pixman_region32_union_rect(damage, damage, 0, 0, width, height); + wlr_renderer_clear(renderer, (float[]){1, 1, 0, 0}); struct sway_container *workspace = output_get_active_workspace(output); if (workspace->sway_workspace->fullscreen) { float clear_color[] = {0.0f, 0.0f, 0.0f, 1.0f}; - wlr_renderer_clear(renderer, clear_color); + + int nrects; + pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects); + for (int i = 0; i < nrects; ++i) { + scissor_output(wlr_output, &rects[i]); + wlr_renderer_clear(renderer, clear_color); + } + // TODO: handle views smaller than the output - render_view(workspace->sway_workspace->fullscreen, output); + render_view(workspace->sway_workspace->fullscreen, output, damage); if (workspace->sway_workspace->fullscreen->type == SWAY_VIEW_XWAYLAND) { - render_unmanaged(output, - &root_container.sway_root->xwayland_unmanaged); + render_unmanaged(output, damage, + &root_container.sway_root->xwayland_unmanaged); } } else { float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f}; - wlr_renderer_clear(renderer, clear_color); - render_layer(output, - &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]); - render_layer(output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]); + int nrects; + pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects); + for (int i = 0; i < nrects; ++i) { + scissor_output(wlr_output, &rects[i]); + wlr_renderer_clear(renderer, clear_color); + } - render_container(output, workspace); + render_layer(output, damage, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]); + render_layer(output, damage, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]); - render_unmanaged(output, &root_container.sway_root->xwayland_unmanaged); - render_layer(output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); + render_container(output, damage, workspace); + + render_unmanaged(output, damage, + &root_container.sway_root->xwayland_unmanaged); + render_layer(output, damage, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); } - render_layer(output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); + render_layer(output, damage, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); renderer_end: if (root_container.sway_root->debug_tree) { @@ -534,6 +603,7 @@ renderer_end: wlr_output->transform_matrix, 0, 0, 1); } + wlr_renderer_scissor(renderer, NULL); wlr_renderer_end(renderer); if (!wlr_output_damage_swap_buffers(output->damage, when, damage)) { return; From 98f7ee8f59fb3242b4689f54d30d78a478d89b1b Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 5 May 2018 19:23:55 +0100 Subject: [PATCH 2/7] Render borders with damage --- sway/desktop/output.c | 167 +++++++++++++++++++++++------------------- 1 file changed, 91 insertions(+), 76 deletions(-) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 9eeed9b9..47461736 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -189,6 +189,36 @@ static void scissor_output(struct wlr_output *wlr_output, wlr_renderer_scissor(renderer, &box); } +static void render_texture(struct wlr_output *wlr_output, + pixman_region32_t *output_damage, struct wlr_texture *texture, + const struct wlr_box *_box, const float matrix[static 9], float alpha) { + struct wlr_renderer *renderer = + wlr_backend_get_renderer(wlr_output->backend); + + struct wlr_box box = *_box; + scale_box(&box, wlr_output->scale); + + pixman_region32_t damage; + pixman_region32_init(&damage); + pixman_region32_union_rect(&damage, &damage, box.x, box.y, + box.width, box.height); + pixman_region32_intersect(&damage, &damage, output_damage); + bool damaged = pixman_region32_not_empty(&damage); + if (!damaged) { + goto damage_finish; + } + + int nrects; + pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); + for (int i = 0; i < nrects; ++i) { + scissor_output(wlr_output, &rects[i]); + wlr_render_texture_with_matrix(renderer, texture, matrix, alpha); + } + +damage_finish: + pixman_region32_fini(&damage); +} + static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy, void *_data) { struct render_data *data = _data; @@ -208,41 +238,14 @@ static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy, return; } - scale_box(&box, wlr_output->scale); - - pixman_region32_t damage; - pixman_region32_init(&damage); - pixman_region32_union_rect(&damage, &damage, box.x, box.y, - box.width, box.height); - pixman_region32_intersect(&damage, &damage, output_damage); - bool damaged = pixman_region32_not_empty(&damage); - if (!damaged) { - goto damage_finish; - } - - struct wlr_renderer *renderer = - wlr_backend_get_renderer(wlr_output->backend); - if (!sway_assert(renderer != NULL, - "expected the output backend to have a renderer")) { - return; - } - float matrix[9]; enum wl_output_transform transform = wlr_output_transform_invert(surface->current->transform); wlr_matrix_project_box(matrix, &box, transform, rotation, wlr_output->transform_matrix); - int nrects; - pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); - for (int i = 0; i < nrects; ++i) { - scissor_output(wlr_output, &rects[i]); - wlr_render_texture_with_matrix(renderer, surface->texture, matrix, - alpha); - } - -damage_finish: - pixman_region32_fini(&damage); + render_texture(wlr_output, output_damage, surface->texture, &box, matrix, + alpha); } static void render_layer(struct sway_output *output, @@ -278,14 +281,44 @@ static void render_view(struct sway_view *view, struct sway_output *output, view, &data.root_geo, render_surface_iterator, &data); } +static void render_rect(struct wlr_output *wlr_output, + pixman_region32_t *output_damage, const struct wlr_box *_box, + float color[static 4]) { + struct wlr_renderer *renderer = + wlr_backend_get_renderer(wlr_output->backend); + + struct wlr_box box = *_box; + scale_box(&box, wlr_output->scale); + + pixman_region32_t damage; + pixman_region32_init(&damage); + pixman_region32_union_rect(&damage, &damage, box.x, box.y, + box.width, box.height); + pixman_region32_intersect(&damage, &damage, output_damage); + bool damaged = pixman_region32_not_empty(&damage); + if (!damaged) { + goto damage_finish; + } + + int nrects; + pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); + for (int i = 0; i < nrects; ++i) { + scissor_output(wlr_output, &rects[i]); + wlr_render_rect(renderer, &box, color, + wlr_output->transform_matrix); + } + +damage_finish: + pixman_region32_fini(&damage); +} + /** * Render decorations for a view with "border normal". */ static void render_container_simple_border_normal(struct sway_output *output, + pixman_region32_t *output_damage, struct sway_container *con, struct border_colors *colors, struct wlr_texture *title_texture) { - struct wlr_renderer *renderer = - wlr_backend_get_renderer(output->wlr_output->backend); struct wlr_box box; float color[4]; @@ -296,9 +329,7 @@ static void render_container_simple_border_normal(struct sway_output *output, box.y = con->y + 1; box.width = con->sway_view->border_thickness; box.height = con->height - 1; - scale_box(&box, output->wlr_output->scale); - wlr_render_rect(renderer, &box, color, - output->wlr_output->transform_matrix); + render_rect(output->wlr_output, output_damage, &box, color); // Child border - right edge if (con->parent->children->length == 1 && con->parent->layout == L_HORIZ) { @@ -311,9 +342,7 @@ static void render_container_simple_border_normal(struct sway_output *output, box.y = con->y + 1; box.width = con->sway_view->border_thickness; box.height = con->height - 1; - scale_box(&box, output->wlr_output->scale); - wlr_render_rect(renderer, &box, color, - output->wlr_output->transform_matrix); + render_rect(output->wlr_output, output_damage, &box, color); // Child border - bottom edge if (con->parent->children->length == 1 && con->parent->layout == L_VERT) { @@ -326,9 +355,7 @@ static void render_container_simple_border_normal(struct sway_output *output, box.y = con->y + con->height - con->sway_view->border_thickness; box.width = con->width; box.height = con->sway_view->border_thickness; - scale_box(&box, output->wlr_output->scale); - wlr_render_rect(renderer, &box, color, - output->wlr_output->transform_matrix); + render_rect(output->wlr_output, output_damage, &box, color); // Single pixel bar above title memcpy(&color, colors->border, sizeof(float) * 4); @@ -337,18 +364,14 @@ static void render_container_simple_border_normal(struct sway_output *output, box.y = con->y; box.width = con->width; box.height = 1; - scale_box(&box, output->wlr_output->scale); - wlr_render_rect(renderer, &box, color, - output->wlr_output->transform_matrix); + render_rect(output->wlr_output, output_damage, &box, color); // Single pixel bar below title box.x = con->x + con->sway_view->border_thickness; box.y = con->sway_view->y - 1; box.width = con->width - con->sway_view->border_thickness * 2; box.height = 1; - scale_box(&box, output->wlr_output->scale); - wlr_render_rect(renderer, &box, color, - output->wlr_output->transform_matrix); + render_rect(output->wlr_output, output_damage, &box, color); // Title background memcpy(&color, colors->background, sizeof(float) * 4); @@ -357,20 +380,20 @@ static void render_container_simple_border_normal(struct sway_output *output, box.y = con->y + 1; box.width = con->width - con->sway_view->border_thickness * 2; box.height = con->sway_view->y - con->y - 2; - scale_box(&box, output->wlr_output->scale); - wlr_render_rect(renderer, &box, color, - output->wlr_output->transform_matrix); + render_rect(output->wlr_output, output_damage, &box, color); // Title text if (title_texture) { - struct wlr_box scissor_box; - wlr_box_transform(&box, - wlr_output_transform_invert(output->wlr_output->transform), - output->swayc->width, output->swayc->height, &scissor_box); - wlr_renderer_scissor(renderer, &scissor_box); - wlr_render_texture(renderer, title_texture, - output->wlr_output->transform_matrix, box.x, box.y, 1); - wlr_renderer_scissor(renderer, NULL); + struct wlr_box texture_box = { .x = box.x, .y = box.y }; + wlr_texture_get_size(title_texture, + &texture_box.width, &texture_box.height); + + float matrix[9]; + wlr_matrix_project_box(matrix, &texture_box, WL_OUTPUT_TRANSFORM_NORMAL, + 0.0, output->wlr_output->transform_matrix); + + render_texture(output->wlr_output, output_damage, title_texture, &box, + matrix, 1.0); } } @@ -378,9 +401,8 @@ static void render_container_simple_border_normal(struct sway_output *output, * Render decorations for a view with "border pixel". */ static void render_container_simple_border_pixel(struct sway_output *output, - struct sway_container *con, struct border_colors *colors) { - struct wlr_renderer *renderer = - wlr_backend_get_renderer(output->wlr_output->backend); + pixman_region32_t *output_damage, struct sway_container *con, + struct border_colors *colors) { struct wlr_box box; float color[4]; @@ -391,9 +413,7 @@ static void render_container_simple_border_pixel(struct sway_output *output, box.y = con->y; box.width = con->sway_view->border_thickness; box.height = con->height; - scale_box(&box, output->wlr_output->scale); - wlr_render_rect(renderer, &box, color, - output->wlr_output->transform_matrix); + render_rect(output->wlr_output, output_damage, &box, color); // Child border - right edge if (con->parent->children->length == 1 && con->parent->layout == L_HORIZ) { @@ -406,18 +426,14 @@ static void render_container_simple_border_pixel(struct sway_output *output, box.y = con->y; box.width = con->sway_view->border_thickness; box.height = con->height; - scale_box(&box, output->wlr_output->scale); - wlr_render_rect(renderer, &box, color, - output->wlr_output->transform_matrix); + render_rect(output->wlr_output, output_damage, &box, color); // Child border - top edge box.x = con->x; box.y = con->y; box.width = con->width; box.height = con->sway_view->border_thickness; - scale_box(&box, output->wlr_output->scale); - wlr_render_rect(renderer, &box, color, - output->wlr_output->transform_matrix); + render_rect(output->wlr_output, output_damage, &box, color); // Child border - bottom edge if (con->parent->children->length == 1 && con->parent->layout == L_VERT) { @@ -430,9 +446,7 @@ static void render_container_simple_border_pixel(struct sway_output *output, box.y = con->y + con->height - con->sway_view->border_thickness; box.width = con->width; box.height = con->sway_view->border_thickness; - scale_box(&box, output->wlr_output->scale); - wlr_render_rect(renderer, &box, color, - output->wlr_output->transform_matrix); + render_rect(output->wlr_output, output_damage, &box, color); } static void render_container(struct sway_output *output, @@ -468,10 +482,11 @@ static void render_container_simple(struct sway_output *output, } if (child->sway_view->border == B_NORMAL) { - render_container_simple_border_normal(output, child, - colors, title_texture); + render_container_simple_border_normal(output, damage, + child, colors, title_texture); } else { - render_container_simple_border_pixel(output, child, colors); + render_container_simple_border_pixel(output, damage, child, + colors); } } render_view(child->sway_view, output, damage); @@ -551,7 +566,7 @@ static void render_output(struct sway_output *output, struct timespec *when, goto renderer_end; } - wlr_renderer_clear(renderer, (float[]){1, 1, 0, 0}); + //wlr_renderer_clear(renderer, (float[]){1, 1, 0, 0}); struct sway_container *workspace = output_get_active_workspace(output); From bec80f15519f686c64485685289155568c9bfa9e Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 5 May 2018 19:43:12 +0100 Subject: [PATCH 3/7] Damage borders when damaging view --- include/sway/output.h | 4 ++-- include/sway/tree/view.h | 2 +- sway/desktop/output.c | 17 +++++++++++++---- sway/desktop/wl_shell.c | 2 +- sway/desktop/xdg_shell_v6.c | 2 +- sway/desktop/xwayland.c | 2 +- sway/tree/container.c | 11 ++++++----- sway/tree/view.c | 26 +++++++++++++++----------- 8 files changed, 40 insertions(+), 26 deletions(-) diff --git a/include/sway/output.h b/include/sway/output.h index 56571548..be19d7b2 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -37,8 +37,8 @@ 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_view(struct sway_output *output, struct sway_view *view, - bool whole); +void output_damage_from_view(struct sway_output *output, + struct sway_view *view); void output_damage_whole_container(struct sway_output *output, struct sway_container *con); diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 9d4256f7..4ecd8c44 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -184,7 +184,7 @@ void view_set_fullscreen(struct sway_view *view, bool fullscreen); void view_close(struct sway_view *view); -void view_damage(struct sway_view *view, bool whole); +void view_damage_from(struct sway_view *view); void view_for_each_surface(struct sway_view *view, wlr_surface_iterator_func_t iterator, void *user_data); diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 47461736..907ad6c9 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -784,8 +784,8 @@ void output_damage_surface(struct sway_output *output, double ox, double oy, damage_surface_iterator, &data); } -void output_damage_view(struct sway_output *output, struct sway_view *view, - bool whole) { +static void output_damage_view(struct sway_output *output, + struct sway_view *view, bool whole) { if (!sway_assert(view->swayc != NULL, "expected a view in the tree")) { return; } @@ -805,6 +805,11 @@ void output_damage_view(struct sway_output *output, struct sway_view *view, damage_surface_iterator, &data); } +void output_damage_from_view(struct sway_output *output, + struct sway_view *view) { + output_damage_view(output, view, false); +} + static void output_damage_whole_container_iterator(struct sway_container *con, void *data) { struct sway_output *output = data; @@ -827,8 +832,12 @@ void output_damage_whole_container(struct sway_output *output, }; wlr_output_damage_add_box(output->damage, &box); - container_descendants(con, C_VIEW, output_damage_whole_container_iterator, - output); + if (con->type == C_VIEW) { + output_damage_whole_container_iterator(con, output); + } else { + container_descendants(con, C_VIEW, + output_damage_whole_container_iterator, output); + } } static void damage_handle_destroy(struct wl_listener *listener, void *data) { diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c index e97a898e..99e8947b 100644 --- a/sway/desktop/wl_shell.c +++ b/sway/desktop/wl_shell.c @@ -85,7 +85,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { // TODO: Let floating views do whatever view_update_size(view, wl_shell_view->pending_width, wl_shell_view->pending_height); - view_damage(view, false); + view_damage_from(view); } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index fcee8ce9..8ecb330d 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -177,7 +177,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { view_update_size(view, xdg_shell_v6_view->pending_width, xdg_shell_v6_view->pending_height); view_update_title(view, false); - view_damage(view, false); + view_damage_from(view); } static void handle_new_popup(struct wl_listener *listener, void *data) { diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index b4eda71f..8f935760 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -222,7 +222,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { // TODO: Let floating views do whatever view_update_size(view, xwayland_view->pending_width, xwayland_view->pending_height); - view_damage(view, false); + view_damage_from(view); view_update_title(view, false); } diff --git a/sway/tree/container.c b/sway/tree/container.c index 38db29c2..cc3bde0a 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -547,12 +547,13 @@ bool container_has_child(struct sway_container *con, return container_find(con, find_child_func, child); } -void container_damage_whole(struct sway_container *con) { - struct sway_container *output = con; - if (output->type != C_OUTPUT) { - output = container_parent(output, C_OUTPUT); +void container_damage_whole(struct sway_container *container) { + for (int i = 0; i < root_container.children->length; ++i) { + struct sway_container *cont = root_container.children->items[i]; + if (cont->type == C_OUTPUT) { + output_damage_whole_container(cont->sway_output, container); + } } - output_damage_whole_container(output->sway_output, con); } static void update_title_texture(struct sway_container *con, diff --git a/sway/tree/view.c b/sway/tree/view.c index fe944466..afd7eade 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -199,11 +199,11 @@ void view_close(struct sway_view *view) { } } -void view_damage(struct sway_view *view, bool whole) { +void view_damage_from(struct sway_view *view) { for (int i = 0; i < root_container.children->length; ++i) { struct sway_container *cont = root_container.children->items[i]; if (cont->type == C_OUTPUT) { - output_damage_view(cont->sway_output, view, whole); + output_damage_from_view(cont->sway_output, view); } } } @@ -333,7 +333,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { arrange_children_of(cont->parent); input_manager_set_focus(input_manager, cont); - view_damage(view, true); + container_damage_whole(cont); view_handle_container_reparent(&view->container_reparent, NULL); view_execute_criteria(view); @@ -351,7 +351,7 @@ void view_unmap(struct sway_view *view) { ws->sway_workspace->fullscreen = NULL; } - view_damage(view, true); + container_damage_whole(view->swayc); wl_list_remove(&view->surface_new_subsurface.link); wl_list_remove(&view->container_reparent.link); @@ -380,10 +380,10 @@ void view_update_position(struct sway_view *view, double ox, double oy) { // TODO: Only allow this if the view is floating (this function will only be // called in response to wayland clients wanting to reposition themselves). - view_damage(view, true); + container_damage_whole(view->swayc); view->swayc->x = ox; view->swayc->y = oy; - view_damage(view, true); + container_damage_whole(view->swayc); } void view_update_size(struct sway_view *view, int width, int height) { @@ -391,11 +391,11 @@ void view_update_size(struct sway_view *view, int width, int height) { return; } - view_damage(view, true); + container_damage_whole(view->swayc); // Should we update the swayc width/height here too? view->width = width; view->height = height; - view_damage(view, true); + container_damage_whole(view->swayc); } @@ -414,7 +414,7 @@ static void view_child_handle_surface_commit(struct wl_listener *listener, struct sway_view_child *child = wl_container_of(listener, child, surface_commit); // TODO: only accumulate damage from the child - view_damage(child->view, false); + view_damage_from(child->view); } static void view_child_handle_surface_new_subsurface( @@ -476,12 +476,16 @@ void view_child_init(struct sway_view_child *child, view_init_subsurfaces(child->view, surface); // TODO: only damage the whole child - view_damage(child->view, true); + if (child->view->swayc) { + container_damage_whole(child->view->swayc); + } } void view_child_destroy(struct sway_view_child *child) { // TODO: only damage the whole child - view_damage(child->view, true); + if (child->view->swayc) { + container_damage_whole(child->view->swayc); + } wl_list_remove(&child->surface_commit.link); wl_list_remove(&child->surface_destroy.link); From 70b80b4698449f5bc3e2c5bf755439249db2fc29 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 5 May 2018 19:49:02 +0100 Subject: [PATCH 4/7] Damage container on focus --- sway/input/seat.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sway/input/seat.c b/sway/input/seat.c index 443fe367..2c279ff2 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -530,6 +530,7 @@ void seat_set_focus_warp(struct sway_seat *seat, if (container->type == C_VIEW) { seat_send_focus(seat, container); } + container_damage_whole(container); } // clean up unfocused empty workspace on new output @@ -575,6 +576,10 @@ void seat_set_focus_warp(struct sway_seat *seat, } } + if (last_focus) { + container_damage_whole(last_focus); + } + if (last_focus && last_focus->type == C_VIEW && !input_manager_has_focus(seat->input, last_focus)) { struct sway_view *view = last_focus->sway_view; From c0f5d740a5b1ca4db6d1ef2a38dc8a29b63a3a0c Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 5 May 2018 20:18:01 +0100 Subject: [PATCH 5/7] Damage container when updating title --- sway/tree/container.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sway/tree/container.c b/sway/tree/container.c index cc3bde0a..db02c69c 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -621,6 +621,7 @@ void container_update_title_textures(struct sway_container *container) { &config->border_colors.unfocused); update_title_texture(container, &container->title_urgent, &config->border_colors.urgent); + container_damage_whole(container); } void container_calculate_title_height(struct sway_container *container) { From 90614f3a6399b0f86b4dea2256ea42703c13edd4 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 7 May 2018 16:56:25 +0100 Subject: [PATCH 6/7] Accumulate surface damage even if whole=true --- sway/desktop/output.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 907ad6c9..d1c6dbf9 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -748,28 +748,28 @@ static void damage_surface_iterator(struct wlr_surface *surface, int sx, int sy, scale_box(&box, output->wlr_output->scale); + int center_x = box.x + box.width/2; + int center_y = box.y + box.height/2; + + pixman_region32_t damage; + pixman_region32_init(&damage); + pixman_region32_copy(&damage, &surface->current->surface_damage); + wlr_region_scale(&damage, &damage, output->wlr_output->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); - } else { - int center_x = box.x + box.width/2; - int center_y = box.y + box.height/2; - - pixman_region32_t damage; - pixman_region32_init(&damage); - pixman_region32_copy(&damage, &surface->current->surface_damage); - wlr_region_scale(&damage, &damage, output->wlr_output->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); } } From 44fcc06efd1a3d4bc37141c723c6654f60d8f923 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 10 May 2018 23:20:00 +0100 Subject: [PATCH 7/7] Fix damage tracking on HiDPI --- sway/desktop/output.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index d1c6dbf9..c150270e 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -191,17 +191,14 @@ static void scissor_output(struct wlr_output *wlr_output, static void render_texture(struct wlr_output *wlr_output, pixman_region32_t *output_damage, struct wlr_texture *texture, - const struct wlr_box *_box, const float matrix[static 9], float alpha) { + const struct wlr_box *box, const float matrix[static 9], float alpha) { struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); - struct wlr_box box = *_box; - scale_box(&box, wlr_output->scale); - pixman_region32_t damage; pixman_region32_init(&damage); - pixman_region32_union_rect(&damage, &damage, box.x, box.y, - box.width, box.height); + pixman_region32_union_rect(&damage, &damage, box->x, box->y, + box->width, box->height); pixman_region32_intersect(&damage, &damage, output_damage); bool damaged = pixman_region32_not_empty(&damage); if (!damaged) { @@ -238,6 +235,8 @@ static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy, return; } + scale_box(&box, wlr_output->scale); + float matrix[9]; enum wl_output_transform transform = wlr_output_transform_invert(surface->current->transform); @@ -384,7 +383,11 @@ static void render_container_simple_border_normal(struct sway_output *output, // Title text if (title_texture) { - struct wlr_box texture_box = { .x = box.x, .y = box.y }; + float output_scale = output->wlr_output->scale; + struct wlr_box texture_box = { + .x = box.x * output_scale, + .y = box.y * output_scale, + }; wlr_texture_get_size(title_texture, &texture_box.width, &texture_box.height); @@ -392,8 +395,8 @@ static void render_container_simple_border_normal(struct sway_output *output, wlr_matrix_project_box(matrix, &texture_box, WL_OUTPUT_TRANSFORM_NORMAL, 0.0, output->wlr_output->transform_matrix); - render_texture(output->wlr_output, output_damage, title_texture, &box, - matrix, 1.0); + render_texture(output->wlr_output, output_damage, title_texture, + &texture_box, matrix, 1.0); } } @@ -566,7 +569,7 @@ static void render_output(struct sway_output *output, struct timespec *when, goto renderer_end; } - //wlr_renderer_clear(renderer, (float[]){1, 1, 0, 0}); + //wlr_renderer_clear(renderer, (float[]){1, 1, 0, 1}); struct sway_container *workspace = output_get_active_workspace(output);