From 5865af75cf8029cc703cda36b68daafcb658c97b Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Mon, 15 Nov 2021 13:32:52 -0500 Subject: [PATCH] sway: create wlr_renderer and wlr_allocator wlroots now required the compositor to create its own wlr_renderer and wlr_allocator to initialize the wlr_output --- include/sway/server.h | 3 +++ sway/desktop/output.c | 6 ++++++ sway/desktop/render.c | 16 ++++------------ sway/server.c | 22 +++++++++++++++++----- sway/tree/container.c | 3 +-- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/include/sway/server.h b/include/sway/server.h index f99bbda6..109097d7 100644 --- a/include/sway/server.h +++ b/include/sway/server.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,8 @@ struct sway_server { struct wlr_backend *noop_backend; // secondary headless backend used for creating virtual outputs on-the-fly struct wlr_backend *headless_backend; + struct wlr_renderer *renderer; + struct wlr_allocator *allocator; struct wlr_compositor *compositor; struct wl_listener compositor_new_surface; diff --git a/sway/desktop/output.c b/sway/desktop/output.c index edec71ad..cd9fd3a6 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -850,6 +850,12 @@ void handle_new_output(struct wl_listener *listener, void *data) { return; } + if (!wlr_output_init_render(wlr_output, server->allocator, + server->renderer)) { + sway_log(SWAY_ERROR, "Failed to init output render"); + return; + } + struct sway_output *output = output_create(wlr_output); if (!output) { return; diff --git a/sway/desktop/render.c b/sway/desktop/render.c index 17fc8f6f..6c8c77ed 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -52,7 +52,7 @@ static int scale_length(int length, int offset, float scale) { static void scissor_output(struct wlr_output *wlr_output, pixman_box32_t *rect) { - struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); + struct wlr_renderer *renderer = wlr_output->renderer; assert(renderer); struct wlr_box box = { @@ -100,8 +100,7 @@ static void render_texture(struct wlr_output *wlr_output, pixman_region32_t *output_damage, struct wlr_texture *texture, 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 wlr_renderer *renderer = wlr_output->renderer; struct sway_output *output = wlr_output->data; pixman_region32_t damage; @@ -218,8 +217,7 @@ void render_rect(struct sway_output *output, pixman_region32_t *output_damage, const struct wlr_box *_box, float color[static 4]) { struct wlr_output *wlr_output = output->wlr_output; - struct wlr_renderer *renderer = - wlr_backend_get_renderer(wlr_output->backend); + struct wlr_renderer *renderer = wlr_output->renderer; struct wlr_box box; memcpy(&box, _box, sizeof(struct wlr_box)); @@ -1013,13 +1011,7 @@ static void render_seatops(struct sway_output *output, void output_render(struct sway_output *output, struct timespec *when, pixman_region32_t *damage) { struct wlr_output *wlr_output = output->wlr_output; - - 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; - } + struct wlr_renderer *renderer = output->server->renderer; struct sway_workspace *workspace = output->current.active_workspace; if (workspace == NULL) { diff --git a/sway/server.c b/sway/server.c index b187fcd5..0d179c88 100644 --- a/sway/server.c +++ b/sway/server.c @@ -73,12 +73,23 @@ static void handle_drm_lease_request(struct wl_listener *listener, void *data) { bool server_init(struct sway_server *server) { sway_log(SWAY_DEBUG, "Initializing Wayland server"); - struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend); - assert(renderer); + server->renderer = wlr_renderer_autocreate(server->backend); + if (!server->renderer) { + sway_log(SWAY_ERROR, "Failed to create renderer"); + return false; + } - wlr_renderer_init_wl_display(renderer, server->wl_display); + wlr_renderer_init_wl_display(server->renderer, server->wl_display); - server->compositor = wlr_compositor_create(server->wl_display, renderer); + server->allocator = wlr_allocator_autocreate(server->backend, + server->renderer); + if (!server->allocator) { + sway_log(SWAY_ERROR, "Failed to create allocator"); + return false; + } + + server->compositor = wlr_compositor_create(server->wl_display, + server->renderer); server->compositor_new_surface.notify = handle_compositor_new_surface; wl_signal_add(&server->compositor->events.new_surface, &server->compositor_new_surface); @@ -212,7 +223,8 @@ bool server_init(struct sway_server *server) { root->noop_output = output_create(wlr_output); server->headless_backend = - wlr_headless_backend_create_with_renderer(server->wl_display, renderer); + wlr_headless_backend_create_with_renderer(server->wl_display, + server->renderer); if (!server->headless_backend) { sway_log(SWAY_INFO, "Failed to create secondary headless backend, " "starting without it"); diff --git a/sway/tree/container.c b/sway/tree/container.c index 943d3d53..eb88b47e 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -547,8 +547,7 @@ static void render_titlebar_text_texture(struct sway_output *output, cairo_surface_flush(surface); unsigned char *data = cairo_image_surface_get_data(surface); int stride = cairo_image_surface_get_stride(surface); - struct wlr_renderer *renderer = wlr_backend_get_renderer( - output->wlr_output->backend); + struct wlr_renderer *renderer = output->wlr_output->renderer; *texture = wlr_texture_from_pixels( renderer, DRM_FORMAT_ARGB8888, stride, width, height, data); cairo_surface_destroy(surface);