summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-04-27 16:41:54 +0200
committerDrew DeVault <sir@cmpwn.com>2020-06-17 10:18:58 -0600
commite19bd1e47441e6292eb77d7caa8b3211666bef2e (patch)
treef86b9bc75ecb42e0eee529c131a3635514fae444
parent8fa74add82b4975ea1fb8d1e57308bd591e6d9d0 (diff)
Add support for viewporter
Depends on [1]. [1]: https://github.com/swaywm/wlroots/pull/2092
-rw-r--r--include/sway/tree/view.h1
-rw-r--r--sway/desktop/render.c31
-rw-r--r--sway/server.c2
-rw-r--r--sway/tree/view.c1
4 files changed, 24 insertions, 11 deletions
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
index 467bf78b5..6007ec49f 100644
--- a/include/sway/tree/view.h
+++ b/include/sway/tree/view.h
@@ -60,6 +60,7 @@ struct sway_saved_buffer {
int x, y;
int width, height;
enum wl_output_transform transform;
+ struct wlr_fbox source_box;
struct wl_list link; // sway_view::saved_buffers
};
diff --git a/sway/desktop/render.c b/sway/desktop/render.c
index 2996e135c..d3d927c83 100644
--- a/sway/desktop/render.c
+++ b/sway/desktop/render.c
@@ -98,7 +98,8 @@ static void set_scale_filter(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_fbox *src_box, const struct wlr_box *dst_box,
+ const float matrix[static 9], float alpha) {
struct wlr_renderer *renderer =
wlr_backend_get_renderer(wlr_output->backend);
struct sway_output *output = wlr_output->data;
@@ -108,8 +109,8 @@ static void render_texture(struct wlr_output *wlr_output,
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, dst_box->x, dst_box->y,
+ dst_box->width, dst_box->height);
pixman_region32_intersect(&damage, &damage, output_damage);
bool damaged = pixman_region32_not_empty(&damage);
if (!damaged) {
@@ -121,7 +122,11 @@ static void render_texture(struct wlr_output *wlr_output,
for (int i = 0; i < nrects; ++i) {
scissor_output(wlr_output, &rects[i]);
set_scale_filter(wlr_output, texture, output->scale_filter);
- wlr_render_texture_with_matrix(renderer, texture, matrix, alpha);
+ if (src_box != NULL) {
+ wlr_render_subtexture_with_matrix(renderer, texture, src_box, matrix, alpha);
+ } else {
+ wlr_render_texture_with_matrix(renderer, texture, matrix, alpha);
+ }
}
damage_finish:
@@ -141,16 +146,20 @@ static void render_surface_iterator(struct sway_output *output, struct sway_view
return;
}
- struct wlr_box box = *_box;
- scale_box(&box, wlr_output->scale);
+ struct wlr_fbox src_box;
+ wlr_surface_get_buffer_source_box(surface, &src_box);
+
+ struct wlr_box dst_box = *_box;
+ scale_box(&dst_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_matrix_project_box(matrix, &dst_box, transform, rotation,
wlr_output->transform_matrix);
- render_texture(wlr_output, output_damage, texture, &box, matrix, alpha);
+ render_texture(wlr_output, output_damage, texture,
+ &src_box, &dst_box, matrix, alpha);
wlr_presentation_surface_sampled_on_output(server.presentation, surface,
wlr_output);
@@ -317,7 +326,7 @@ static void render_saved_view(struct sway_view *view,
wlr_output->transform_matrix);
render_texture(wlr_output, damage, saved_buf->buffer->texture,
- &box, matrix, alpha);
+ &saved_buf->source_box, &box, matrix, alpha);
}
// FIXME: we should set the surface that this saved buffer originates from
@@ -497,7 +506,7 @@ static void render_titlebar(struct sway_output *output,
texture_box.width = ob_inner_width;
}
render_texture(output->wlr_output, output_damage, marks_texture,
- &texture_box, matrix, con->alpha);
+ NULL, &texture_box, matrix, con->alpha);
// Padding above
memcpy(&color, colors->background, sizeof(float) * 4);
@@ -565,7 +574,7 @@ static void render_titlebar(struct sway_output *output,
}
render_texture(output->wlr_output, output_damage, title_texture,
- &texture_box, matrix, con->alpha);
+ NULL, &texture_box, matrix, con->alpha);
// Padding above
memcpy(&color, colors->background, sizeof(float) * 4);
diff --git a/sway/server.c b/sway/server.c
index cf36962b4..724a0e25f 100644
--- a/sway/server.c
+++ b/sway/server.c
@@ -22,6 +22,7 @@
#include <wlr/types/wlr_screencopy_v1.h>
#include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_tablet_v2.h>
+#include <wlr/types/wlr_viewporter.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_decoration_v1.h>
#include <wlr/types/wlr_xdg_output_v1.h>
@@ -146,6 +147,7 @@ bool server_init(struct sway_server *server) {
wlr_screencopy_manager_v1_create(server->wl_display);
wlr_data_control_manager_v1_create(server->wl_display);
wlr_primary_selection_v1_device_manager_create(server->wl_display);
+ wlr_viewporter_create(server->wl_display);
server->socket = wl_display_add_socket_auto(server->wl_display);
if (!server->socket) {
diff --git a/sway/tree/view.c b/sway/tree/view.c
index ca5af10e8..e5d3948ce 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -1206,6 +1206,7 @@ static void view_save_buffer_iterator(struct wlr_surface *surface,
saved_buffer->x = sx;
saved_buffer->y = sy;
saved_buffer->transform = surface->current.transform;
+ wlr_surface_get_buffer_source_box(surface, &saved_buffer->source_box);
wl_list_insert(&view->saved_buffers, &saved_buffer->link);
}
}