diff options
-rw-r--r-- | backend/backend.c | 24 | ||||
-rw-r--r-- | include/wlr/backend.h | 4 |
2 files changed, 28 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; } diff --git a/include/wlr/backend.h b/include/wlr/backend.h index b56e789c..020be18d 100644 --- a/include/wlr/backend.h +++ b/include/wlr/backend.h @@ -25,6 +25,10 @@ struct wlr_backend { /** Raised when new outputs are added, passed the wlr_output */ struct wl_signal new_output; } events; + + // Private state + + struct wlr_renderer *renderer; }; /** |