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
This commit is contained in:
Simon Zeni 2021-11-15 13:32:52 -05:00 committed by Simon Ser
parent cbecc5cbae
commit 5865af75cf
5 changed files with 31 additions and 19 deletions

View File

@ -4,6 +4,7 @@
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h>
@ -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;

View File

@ -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;

View File

@ -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) {

View File

@ -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");

View File

@ -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);