From 4bec6927346fb0a9836ef9f92655ffb26665e8e1 Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Wed, 19 Apr 2023 15:17:31 +0200 Subject: [PATCH] Drop wlr_client_buffer usage --- include/sway/surface.h | 3 +++ include/sway/tree/view.h | 3 ++- sway/desktop/output.c | 7 ++++--- sway/desktop/render.c | 16 ++++++++++++---- sway/desktop/surface.c | 18 ++++++++++++++++++ sway/server.c | 3 +-- sway/tree/view.c | 5 ++--- 7 files changed, 42 insertions(+), 13 deletions(-) diff --git a/include/sway/surface.h b/include/sway/surface.h index a7a8ec3f..fb3dda57 100644 --- a/include/sway/surface.h +++ b/include/sway/surface.h @@ -1,10 +1,13 @@ #ifndef _SWAY_SURFACE_H #define _SWAY_SURFACE_H #include +#include struct sway_surface { struct wlr_surface *wlr_surface; + struct wlr_raster *raster; + struct wl_listener commit; struct wl_listener destroy; /** diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 7fc2d95d..94916b49 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -2,6 +2,7 @@ #define _SWAY_VIEW_H #include #include +#include #include "sway/config.h" #if HAVE_XWAYLAND #include @@ -57,7 +58,7 @@ struct sway_view_impl { }; struct sway_saved_buffer { - struct wlr_client_buffer *buffer; + struct wlr_raster *raster; int x, y; int width, height; enum wl_output_transform transform; diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 2255b551..a207ed8b 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -509,7 +509,8 @@ static bool scan_out_fullscreen_view(struct sway_output *output, return false; } - if (surface->buffer == NULL) { + struct wlr_raster *raster = wlr_raster_from_surface(surface); + if (raster == NULL || raster->buffer == NULL) { return false; } @@ -522,7 +523,7 @@ static bool scan_out_fullscreen_view(struct sway_output *output, return false; } - wlr_output_attach_buffer(wlr_output, &surface->buffer->base); + wlr_output_attach_buffer(wlr_output, raster->buffer); if (!wlr_output_test(wlr_output)) { return false; } diff --git a/sway/desktop/render.c b/sway/desktop/render.c index a4d633e0..615a440a 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -142,7 +142,13 @@ static void render_surface_iterator(struct sway_output *output, const pixman_region32_t *output_damage = data->damage; float alpha = data->alpha; - struct wlr_texture *texture = wlr_surface_get_texture(surface); + struct wlr_raster *raster = wlr_raster_from_surface(surface); + if (!raster) { + return; + } + + struct wlr_texture *texture = wlr_raster_create_texture( + raster, wlr_output->renderer); if (!texture) { return; } @@ -303,7 +309,9 @@ static void render_saved_view(struct sway_view *view, struct sway_saved_buffer *saved_buf; wl_list_for_each(saved_buf, &view->saved_buffers, link) { - if (!saved_buf->buffer->texture) { + struct wlr_texture *texture = wlr_raster_create_texture( + saved_buf->raster, wlr_output->renderer); + if (!texture) { continue; } @@ -343,7 +351,7 @@ static void render_saved_view(struct sway_view *view, } scale_box(&dst_box, wlr_output->scale); - render_texture(wlr_output, damage, saved_buf->buffer->texture, + render_texture(wlr_output, damage, texture, &saved_buf->source_box, &dst_box, matrix, alpha); } diff --git a/sway/desktop/surface.c b/sway/desktop/surface.c index 68772ee0..510db010 100644 --- a/sway/desktop/surface.c +++ b/sway/desktop/surface.c @@ -11,15 +11,28 @@ static void handle_destroy(struct wl_listener *listener, void *data) { struct sway_surface *surface = wl_container_of(listener, surface, destroy); surface->wlr_surface->data = NULL; + wl_list_remove(&surface->commit.link); wl_list_remove(&surface->destroy.link); if (surface->frame_done_timer) { wl_event_source_remove(surface->frame_done_timer); } + wlr_raster_unlock(surface->raster); + free(surface); } +static void handle_commit(struct wl_listener *listener, void *data) { + struct sway_surface *surface = wl_container_of(listener, surface, commit); + + // update the surface raster every surface commit + struct wlr_raster *raster = wlr_raster_from_surface(surface->wlr_surface); + + wlr_raster_unlock(surface->raster); + surface->raster = raster; +} + static int surface_frame_done_timer_handler(void *data) { struct sway_surface *surface = data; @@ -40,11 +53,16 @@ void handle_compositor_new_surface(struct wl_listener *listener, void *data) { surface->destroy.notify = handle_destroy; wl_signal_add(&wlr_surface->events.destroy, &surface->destroy); + surface->commit.notify = handle_commit; + wl_signal_add(&wlr_surface->events.commit, &surface->commit); + surface->frame_done_timer = wl_event_loop_add_timer(server.wl_event_loop, surface_frame_done_timer_handler, surface); if (!surface->frame_done_timer) { wl_resource_post_no_memory(wlr_surface->resource); } + + surface->raster = wlr_raster_from_surface(wlr_surface); } void surface_update_outputs(struct wlr_surface *surface) { diff --git a/sway/server.c b/sway/server.c index 0cf767b7..85705416 100644 --- a/sway/server.c +++ b/sway/server.c @@ -103,8 +103,7 @@ bool server_init(struct sway_server *server) { return false; } - server->compositor = wlr_compositor_create(server->wl_display, 5, - server->renderer); + server->compositor = wlr_compositor_create(server->wl_display, 5, NULL); server->compositor_new_surface.notify = handle_compositor_new_surface; wl_signal_add(&server->compositor->events.new_surface, &server->compositor_new_surface); diff --git a/sway/tree/view.c b/sway/tree/view.c index ec54fed8..fdb175b1 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -1412,7 +1412,7 @@ void view_remove_saved_buffer(struct sway_view *view) { } struct sway_saved_buffer *saved_buf, *tmp; wl_list_for_each_safe(saved_buf, tmp, &view->saved_buffers, link) { - wlr_buffer_unlock(&saved_buf->buffer->base); + wlr_raster_unlock(saved_buf->raster); wl_list_remove(&saved_buf->link); free(saved_buf); } @@ -1423,9 +1423,8 @@ static void view_save_buffer_iterator(struct wlr_surface *surface, struct sway_view *view = data; if (surface && wlr_surface_has_buffer(surface)) { - wlr_buffer_lock(&surface->buffer->base); struct sway_saved_buffer *saved_buffer = calloc(1, sizeof(struct sway_saved_buffer)); - saved_buffer->buffer = surface->buffer; + saved_buffer->raster = wlr_raster_from_surface(surface); saved_buffer->width = surface->current.width; saved_buffer->height = surface->current.height; saved_buffer->x = view->container->surface_x + sx;