aboutsummaryrefslogtreecommitdiffstats
path: root/sway/desktop/render.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/desktop/render.c')
-rw-r--r--sway/desktop/render.c140
1 files changed, 88 insertions, 52 deletions
diff --git a/sway/desktop/render.c b/sway/desktop/render.c
index bd85282c..17fc8f6f 100644
--- a/sway/desktop/render.c
+++ b/sway/desktop/render.c
@@ -7,7 +7,6 @@
7#include <wayland-server-core.h> 7#include <wayland-server-core.h>
8#include <wlr/render/gles2.h> 8#include <wlr/render/gles2.h>
9#include <wlr/render/wlr_renderer.h> 9#include <wlr/render/wlr_renderer.h>
10#include <wlr/types/wlr_box.h>
11#include <wlr/types/wlr_buffer.h> 10#include <wlr/types/wlr_buffer.h>
12#include <wlr/types/wlr_matrix.h> 11#include <wlr/types/wlr_matrix.h>
13#include <wlr/types/wlr_output_damage.h> 12#include <wlr/types/wlr_output_damage.h>
@@ -32,6 +31,7 @@
32struct render_data { 31struct render_data {
33 pixman_region32_t *damage; 32 pixman_region32_t *damage;
34 float alpha; 33 float alpha;
34 struct wlr_box *clip_box;
35}; 35};
36 36
37/** 37/**
@@ -104,9 +104,6 @@ static void render_texture(struct wlr_output *wlr_output,
104 wlr_backend_get_renderer(wlr_output->backend); 104 wlr_backend_get_renderer(wlr_output->backend);
105 struct sway_output *output = wlr_output->data; 105 struct sway_output *output = wlr_output->data;
106 106
107 struct wlr_gles2_texture_attribs attribs;
108 wlr_gles2_texture_get_attribs(texture, &attribs);
109
110 pixman_region32_t damage; 107 pixman_region32_t damage;
111 pixman_region32_init(&damage); 108 pixman_region32_init(&damage);
112 pixman_region32_union_rect(&damage, &damage, dst_box->x, dst_box->y, 109 pixman_region32_union_rect(&damage, &damage, dst_box->x, dst_box->y,
@@ -133,9 +130,9 @@ damage_finish:
133 pixman_region32_fini(&damage); 130 pixman_region32_fini(&damage);
134} 131}
135 132
136static void render_surface_iterator(struct sway_output *output, struct sway_view *view, 133static void render_surface_iterator(struct sway_output *output,
137 struct wlr_surface *surface, struct wlr_box *_box, float rotation, 134 struct sway_view *view, struct wlr_surface *surface,
138 void *_data) { 135 struct wlr_box *_box, void *_data) {
139 struct render_data *data = _data; 136 struct render_data *data = _data;
140 struct wlr_output *wlr_output = output->wlr_output; 137 struct wlr_output *wlr_output = output->wlr_output;
141 pixman_region32_t *output_damage = data->damage; 138 pixman_region32_t *output_damage = data->damage;
@@ -149,15 +146,23 @@ static void render_surface_iterator(struct sway_output *output, struct sway_view
149 struct wlr_fbox src_box; 146 struct wlr_fbox src_box;
150 wlr_surface_get_buffer_source_box(surface, &src_box); 147 wlr_surface_get_buffer_source_box(surface, &src_box);
151 148
152 struct wlr_box dst_box = *_box; 149 struct wlr_box proj_box = *_box;
153 scale_box(&dst_box, wlr_output->scale); 150 scale_box(&proj_box, wlr_output->scale);
154 151
155 float matrix[9]; 152 float matrix[9];
156 enum wl_output_transform transform = 153 enum wl_output_transform transform =
157 wlr_output_transform_invert(surface->current.transform); 154 wlr_output_transform_invert(surface->current.transform);
158 wlr_matrix_project_box(matrix, &dst_box, transform, rotation, 155 wlr_matrix_project_box(matrix, &proj_box, transform, 0.0,
159 wlr_output->transform_matrix); 156 wlr_output->transform_matrix);
160 157
158 struct wlr_box dst_box = *_box;
159 struct wlr_box *clip_box = data->clip_box;
160 if (clip_box != NULL) {
161 dst_box.width = fmin(dst_box.width, clip_box->width);
162 dst_box.height = fmin(dst_box.height, clip_box->height);
163 }
164 scale_box(&dst_box, wlr_output->scale);
165
161 render_texture(wlr_output, output_damage, texture, 166 render_texture(wlr_output, output_damage, texture,
162 &src_box, &dst_box, matrix, alpha); 167 &src_box, &dst_box, matrix, alpha);
163 168
@@ -256,6 +261,14 @@ static void render_view_toplevels(struct sway_view *view,
256 .damage = damage, 261 .damage = damage,
257 .alpha = alpha, 262 .alpha = alpha,
258 }; 263 };
264 struct wlr_box clip_box;
265 if (!container_is_current_floating(view->container)) {
266 // As we pass the geometry offsets to the surface iterator, we will
267 // need to account for the offsets in the clip dimensions.
268 clip_box.width = view->container->current.content_width + view->geometry.x;
269 clip_box.height = view->container->current.content_height + view->geometry.y;
270 data.clip_box = &clip_box;
271 }
259 // Render all toplevels without descending into popups 272 // Render all toplevels without descending into popups
260 double ox = view->container->surface_x - 273 double ox = view->container->surface_x -
261 output->lx - view->geometry.x; 274 output->lx - view->geometry.x;
@@ -282,17 +295,18 @@ static void render_saved_view(struct sway_view *view,
282 if (wl_list_empty(&view->saved_buffers)) { 295 if (wl_list_empty(&view->saved_buffers)) {
283 return; 296 return;
284 } 297 }
298
299 bool floating = container_is_current_floating(view->container);
300
285 struct sway_saved_buffer *saved_buf; 301 struct sway_saved_buffer *saved_buf;
286 wl_list_for_each(saved_buf, &view->saved_buffers, link) { 302 wl_list_for_each(saved_buf, &view->saved_buffers, link) {
287 if (!saved_buf->buffer->texture) { 303 if (!saved_buf->buffer->texture) {
288 continue; 304 continue;
289 } 305 }
290 306
291 struct wlr_box box = { 307 struct wlr_box proj_box = {
292 .x = view->container->surface_x - output->lx - 308 .x = saved_buf->x - view->saved_geometry.x - output->lx,
293 view->saved_geometry.x + saved_buf->x, 309 .y = saved_buf->y - view->saved_geometry.y - output->ly,
294 .y = view->container->surface_y - output->ly -
295 view->saved_geometry.y + saved_buf->y,
296 .width = saved_buf->width, 310 .width = saved_buf->width,
297 .height = saved_buf->height, 311 .height = saved_buf->height,
298 }; 312 };
@@ -303,20 +317,31 @@ static void render_saved_view(struct sway_view *view,
303 }; 317 };
304 318
305 struct wlr_box intersection; 319 struct wlr_box intersection;
306 bool intersects = wlr_box_intersection(&intersection, &output_box, &box); 320 bool intersects = wlr_box_intersection(&intersection, &output_box, &proj_box);
307 if (!intersects) { 321 if (!intersects) {
308 continue; 322 continue;
309 } 323 }
310 324
311 scale_box(&box, wlr_output->scale); 325 struct wlr_box dst_box = proj_box;
326 scale_box(&proj_box, wlr_output->scale);
312 327
313 float matrix[9]; 328 float matrix[9];
314 enum wl_output_transform transform = wlr_output_transform_invert(saved_buf->transform); 329 enum wl_output_transform transform = wlr_output_transform_invert(saved_buf->transform);
315 wlr_matrix_project_box(matrix, &box, transform, 0, 330 wlr_matrix_project_box(matrix, &proj_box, transform, 0,
316 wlr_output->transform_matrix); 331 wlr_output->transform_matrix);
317 332
333 if (!floating) {
334 dst_box.width = fmin(dst_box.width,
335 view->container->current.content_width -
336 (saved_buf->x - view->container->current.content_x) + view->saved_geometry.x);
337 dst_box.height = fmin(dst_box.height,
338 view->container->current.content_height -
339 (saved_buf->y - view->container->current.content_y) + view->saved_geometry.y);
340 }
341 scale_box(&dst_box, wlr_output->scale);
342
318 render_texture(wlr_output, damage, saved_buf->buffer->texture, 343 render_texture(wlr_output, damage, saved_buf->buffer->texture,
319 &saved_buf->source_box, &box, matrix, alpha); 344 &saved_buf->source_box, &dst_box, matrix, alpha);
320 } 345 }
321 346
322 // FIXME: we should set the surface that this saved buffer originates from 347 // FIXME: we should set the surface that this saved buffer originates from
@@ -348,8 +373,8 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
348 if (state->border_left) { 373 if (state->border_left) {
349 memcpy(&color, colors->child_border, sizeof(float) * 4); 374 memcpy(&color, colors->child_border, sizeof(float) * 4);
350 premultiply_alpha(color, con->alpha); 375 premultiply_alpha(color, con->alpha);
351 box.x = state->x; 376 box.x = floor(state->x);
352 box.y = state->content_y; 377 box.y = floor(state->content_y);
353 box.width = state->border_thickness; 378 box.width = state->border_thickness;
354 box.height = state->content_height; 379 box.height = state->content_height;
355 scale_box(&box, output_scale); 380 scale_box(&box, output_scale);
@@ -361,14 +386,14 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
361 container_current_parent_layout(con); 386 container_current_parent_layout(con);
362 387
363 if (state->border_right) { 388 if (state->border_right) {
364 if (!container_is_floating(con) && siblings->length == 1 && layout == L_HORIZ) { 389 if (!container_is_current_floating(con) && siblings->length == 1 && layout == L_HORIZ) {
365 memcpy(&color, colors->indicator, sizeof(float) * 4); 390 memcpy(&color, colors->indicator, sizeof(float) * 4);
366 } else { 391 } else {
367 memcpy(&color, colors->child_border, sizeof(float) * 4); 392 memcpy(&color, colors->child_border, sizeof(float) * 4);
368 } 393 }
369 premultiply_alpha(color, con->alpha); 394 premultiply_alpha(color, con->alpha);
370 box.x = state->content_x + state->content_width; 395 box.x = floor(state->content_x + state->content_width);
371 box.y = state->content_y; 396 box.y = floor(state->content_y);
372 box.width = state->border_thickness; 397 box.width = state->border_thickness;
373 box.height = state->content_height; 398 box.height = state->content_height;
374 scale_box(&box, output_scale); 399 scale_box(&box, output_scale);
@@ -376,14 +401,14 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
376 } 401 }
377 402
378 if (state->border_bottom) { 403 if (state->border_bottom) {
379 if (!container_is_floating(con) && siblings->length == 1 && layout == L_VERT) { 404 if (!container_is_current_floating(con) && siblings->length == 1 && layout == L_VERT) {
380 memcpy(&color, colors->indicator, sizeof(float) * 4); 405 memcpy(&color, colors->indicator, sizeof(float) * 4);
381 } else { 406 } else {
382 memcpy(&color, colors->child_border, sizeof(float) * 4); 407 memcpy(&color, colors->child_border, sizeof(float) * 4);
383 } 408 }
384 premultiply_alpha(color, con->alpha); 409 premultiply_alpha(color, con->alpha);
385 box.x = state->x; 410 box.x = floor(state->x);
386 box.y = state->content_y + state->content_height; 411 box.y = floor(state->content_y + state->content_height);
387 box.width = state->width; 412 box.width = state->width;
388 box.height = state->border_thickness; 413 box.height = state->border_thickness;
389 scale_box(&box, output_scale); 414 scale_box(&box, output_scale);
@@ -464,9 +489,10 @@ static void render_titlebar(struct sway_output *output,
464 int ob_marks_x = 0; // output-buffer-local 489 int ob_marks_x = 0; // output-buffer-local
465 int ob_marks_width = 0; // output-buffer-local 490 int ob_marks_width = 0; // output-buffer-local
466 if (config->show_marks && marks_texture) { 491 if (config->show_marks && marks_texture) {
467 struct wlr_box texture_box; 492 struct wlr_box texture_box = {
468 wlr_texture_get_size(marks_texture, 493 .width = marks_texture->width,
469 &texture_box.width, &texture_box.height); 494 .height = marks_texture->height,
495 };
470 ob_marks_width = texture_box.width; 496 ob_marks_width = texture_box.width;
471 497
472 // The marks texture might be shorter than the config->font_height, in 498 // The marks texture might be shorter than the config->font_height, in
@@ -517,15 +543,23 @@ static void render_titlebar(struct sway_output *output,
517 int ob_title_x = 0; // output-buffer-local 543 int ob_title_x = 0; // output-buffer-local
518 int ob_title_width = 0; // output-buffer-local 544 int ob_title_width = 0; // output-buffer-local
519 if (title_texture) { 545 if (title_texture) {
520 struct wlr_box texture_box; 546 struct wlr_box texture_box = {
521 wlr_texture_get_size(title_texture, 547 .width = title_texture->width,
522 &texture_box.width, &texture_box.height); 548 .height = title_texture->height,
549 };
550
551 // The effective output may be NULL when con is not on any output.
552 // This can happen because we render all children of containers,
553 // even those that are out of the bounds of any output.
554 struct sway_output *effective = container_get_effective_output(con);
555 float title_scale = effective ? effective->wlr_output->scale : output_scale;
556 texture_box.width = texture_box.width * output_scale / title_scale;
557 texture_box.height = texture_box.height * output_scale / title_scale;
523 ob_title_width = texture_box.width; 558 ob_title_width = texture_box.width;
524 559
525 // The title texture might be shorter than the config->font_height, 560 // The title texture might be shorter than the config->font_height,
526 // in which case we need to pad it above and below. 561 // in which case we need to pad it above and below.
527 int ob_padding_above = round((config->font_baseline - 562 int ob_padding_above = round((titlebar_v_padding -
528 con->title_baseline + titlebar_v_padding -
529 titlebar_border_thickness) * output_scale); 563 titlebar_border_thickness) * output_scale);
530 int ob_padding_below = ob_bg_height - ob_padding_above - 564 int ob_padding_below = ob_bg_height - ob_padding_above -
531 texture_box.height; 565 texture_box.height;
@@ -660,8 +694,8 @@ static void render_top_border(struct sway_output *output,
660 // Child border - top edge 694 // Child border - top edge
661 memcpy(&color, colors->child_border, sizeof(float) * 4); 695 memcpy(&color, colors->child_border, sizeof(float) * 4);
662 premultiply_alpha(color, con->alpha); 696 premultiply_alpha(color, con->alpha);
663 box.x = state->x; 697 box.x = floor(state->x);
664 box.y = state->y; 698 box.y = floor(state->y);
665 box.width = state->width; 699 box.width = state->width;
666 box.height = state->border_thickness; 700 box.height = state->border_thickness;
667 scale_box(&box, output_scale); 701 scale_box(&box, output_scale);
@@ -716,8 +750,8 @@ static void render_containers_linear(struct sway_output *output,
716 } 750 }
717 751
718 if (state->border == B_NORMAL) { 752 if (state->border == B_NORMAL) {
719 render_titlebar(output, damage, child, state->x, 753 render_titlebar(output, damage, child, floor(state->x),
720 state->y, state->width, colors, 754 floor(state->y), state->width, colors,
721 title_texture, marks_texture); 755 title_texture, marks_texture);
722 } else if (state->border == B_PIXEL) { 756 } else if (state->border == B_PIXEL) {
723 render_top_border(output, damage, child, colors); 757 render_top_border(output, damage, child, colors);
@@ -771,7 +805,7 @@ static void render_containers_tabbed(struct sway_output *output,
771 marks_texture = child->marks_unfocused; 805 marks_texture = child->marks_unfocused;
772 } 806 }
773 807
774 int x = cstate->x + tab_width * i; 808 int x = floor(cstate->x + tab_width * i);
775 809
776 // Make last tab use the remaining width of the parent 810 // Make last tab use the remaining width of the parent
777 if (i == parent->children->length - 1) { 811 if (i == parent->children->length - 1) {
@@ -884,8 +918,8 @@ static void render_container(struct sway_output *output,
884 struct parent_data data = { 918 struct parent_data data = {
885 .layout = con->current.layout, 919 .layout = con->current.layout,
886 .box = { 920 .box = {
887 .x = con->current.x, 921 .x = floor(con->current.x),
888 .y = con->current.y, 922 .y = floor(con->current.y),
889 .width = con->current.width, 923 .width = con->current.width,
890 .height = con->current.height, 924 .height = con->current.height,
891 }, 925 },
@@ -901,8 +935,8 @@ static void render_workspace(struct sway_output *output,
901 struct parent_data data = { 935 struct parent_data data = {
902 .layout = ws->current.layout, 936 .layout = ws->current.layout,
903 .box = { 937 .box = {
904 .x = ws->current.x, 938 .x = floor(ws->current.x),
905 .y = ws->current.y, 939 .y = floor(ws->current.y),
906 .width = ws->current.width, 940 .width = ws->current.width,
907 .height = ws->current.height, 941 .height = ws->current.height,
908 }, 942 },
@@ -936,8 +970,8 @@ static void render_floating_container(struct sway_output *soutput,
936 } 970 }
937 971
938 if (con->current.border == B_NORMAL) { 972 if (con->current.border == B_NORMAL) {
939 render_titlebar(soutput, damage, con, con->current.x, 973 render_titlebar(soutput, damage, con, floor(con->current.x),
940 con->current.y, con->current.width, colors, 974 floor(con->current.y), con->current.width, colors,
941 title_texture, marks_texture); 975 title_texture, marks_texture);
942 } else if (con->current.border == B_PIXEL) { 976 } else if (con->current.border == B_PIXEL) {
943 render_top_border(soutput, damage, con, colors); 977 render_top_border(soutput, damage, con, colors);
@@ -959,7 +993,7 @@ static void render_floating(struct sway_output *soutput,
959 } 993 }
960 for (int k = 0; k < ws->current.floating->length; ++k) { 994 for (int k = 0; k < ws->current.floating->length; ++k) {
961 struct sway_container *floater = ws->current.floating->items[k]; 995 struct sway_container *floater = ws->current.floating->items[k];
962 if (floater->fullscreen_mode != FULLSCREEN_NONE) { 996 if (floater->current.fullscreen_mode != FULLSCREEN_NONE) {
963 continue; 997 continue;
964 } 998 }
965 render_floating_container(soutput, damage, floater); 999 render_floating_container(soutput, damage, floater);
@@ -999,6 +1033,12 @@ void output_render(struct sway_output *output, struct timespec *when,
999 1033
1000 wlr_renderer_begin(renderer, wlr_output->width, wlr_output->height); 1034 wlr_renderer_begin(renderer, wlr_output->width, wlr_output->height);
1001 1035
1036 if (debug.damage == DAMAGE_RERENDER) {
1037 int width, height;
1038 wlr_output_transformed_resolution(wlr_output, &width, &height);
1039 pixman_region32_union_rect(damage, damage, 0, 0, width, height);
1040 }
1041
1002 if (!pixman_region32_not_empty(damage)) { 1042 if (!pixman_region32_not_empty(damage)) {
1003 // Output isn't damaged but needs buffer swap 1043 // Output isn't damaged but needs buffer swap
1004 goto renderer_end; 1044 goto renderer_end;
@@ -1006,10 +1046,6 @@ void output_render(struct sway_output *output, struct timespec *when,
1006 1046
1007 if (debug.damage == DAMAGE_HIGHLIGHT) { 1047 if (debug.damage == DAMAGE_HIGHLIGHT) {
1008 wlr_renderer_clear(renderer, (float[]){1, 1, 0, 1}); 1048 wlr_renderer_clear(renderer, (float[]){1, 1, 0, 1});
1009 } else if (debug.damage == DAMAGE_RERENDER) {
1010 int width, height;
1011 wlr_output_transformed_resolution(wlr_output, &width, &height);
1012 pixman_region32_union_rect(damage, damage, 0, 0, width, height);
1013 } 1049 }
1014 1050
1015 if (output_has_opaque_overlay_layer_surface(output)) { 1051 if (output_has_opaque_overlay_layer_surface(output)) {
@@ -1110,7 +1146,7 @@ renderer_end:
1110 wlr_region_transform(&frame_damage, &output->damage->current, 1146 wlr_region_transform(&frame_damage, &output->damage->current,
1111 transform, width, height); 1147 transform, width, height);
1112 1148
1113 if (debug.damage == DAMAGE_HIGHLIGHT) { 1149 if (debug.damage != DAMAGE_DEFAULT) {
1114 pixman_region32_union_rect(&frame_damage, &frame_damage, 1150 pixman_region32_union_rect(&frame_damage, &frame_damage,
1115 0, 0, wlr_output->width, wlr_output->height); 1151 0, 0, wlr_output->width, wlr_output->height);
1116 } 1152 }