aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2021-04-28 23:22:46 +0200
committerKenny Levinsen <kl@kl.wtf>2021-05-21 22:13:54 +0200
commitbcabe34a2edc71fef338cd770e851a43b68484cf (patch)
treed6131bf082fd021b603d1c7048bedb503ba57594 /backend
parent7ec5bf6b10d2a7e1d9cdfdfeed44ac6db8bdcc99 (diff)
backend: automatically create renderer
If a backend accepts buffers (as indicated by get_buffer_caps) but doesn't implement get_renderer, automatically create a renderer.
Diffstat (limited to 'backend')
-rw-r--r--backend/backend.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/backend/backend.c b/backend/backend.c
index 503b6b7d..f7c618f3 100644
--- a/backend/backend.c
+++ b/backend/backend.c
@@ -15,6 +15,7 @@
#include <wlr/backend/session.h>
#include <wlr/backend/wayland.h>
#include <wlr/config.h>
+#include <wlr/render/wlr_renderer.h>
#include <wlr/util/log.h>
#include "backend/backend.h"
#include "backend/multi.h"
@@ -35,6 +36,7 @@ void wlr_backend_init(struct wlr_backend *backend,
void wlr_backend_finish(struct wlr_backend *backend) {
wlr_signal_emit_safe(&backend->events.destroy, backend);
+ wlr_renderer_destroy(backend->renderer);
}
bool wlr_backend_start(struct wlr_backend *backend) {
@@ -56,10 +58,32 @@ void wlr_backend_destroy(struct wlr_backend *backend) {
}
}
+static bool backend_create_renderer(struct wlr_backend *backend) {
+ if (backend->renderer != NULL) {
+ return true;
+ }
+
+ backend->renderer = wlr_renderer_autocreate(backend);
+ if (backend->renderer == NULL) {
+ return false;
+ }
+
+ return true;
+}
+
struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend) {
if (backend->impl->get_renderer) {
return backend->impl->get_renderer(backend);
}
+ if (backend_get_buffer_caps(backend) != 0) {
+ // If the backend is capable of presenting buffers, automatically create
+ // the renderer if necessary.
+ if (!backend_create_renderer(backend)) {
+ wlr_log(WLR_ERROR, "Failed to create backend renderer");
+ return NULL;
+ }
+ return backend->renderer;
+ }
return NULL;
}