backend: create renderer and allocator in wlr_backend_autocreate
Instead of ensuring the renderer and allocator are initialized in each backend, do it in wlr_backend_autocreate. This allows compositors to create backends without any renderer/allocator if they side-step wlr_backend_autocreate. Since the wlr_backend_get_renderer and backend_get_allocator end up calling wlr_renderer_autocreate and wlr_allocator_autocreate, it sounds like a good idea to centralize all of the opimionated bits in one place.
This commit is contained in:
parent
20d9448257
commit
3d0848daae
|
@ -209,6 +209,21 @@ static size_t parse_outputs_env(const char *name) {
|
||||||
return outputs;
|
return outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct wlr_backend *ensure_backend_renderer_and_allocator(
|
||||||
|
struct wlr_backend *backend) {
|
||||||
|
struct wlr_renderer *renderer = wlr_backend_get_renderer(backend);
|
||||||
|
if (renderer == NULL) {
|
||||||
|
wlr_backend_destroy(backend);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
struct wlr_allocator *allocator = backend_get_allocator(backend);
|
||||||
|
if (allocator == NULL) {
|
||||||
|
wlr_backend_destroy(backend);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return backend;
|
||||||
|
}
|
||||||
|
|
||||||
static struct wlr_backend *attempt_wl_backend(struct wl_display *display) {
|
static struct wlr_backend *attempt_wl_backend(struct wl_display *display) {
|
||||||
struct wlr_backend *backend = wlr_wl_backend_create(display, NULL);
|
struct wlr_backend *backend = wlr_wl_backend_create(display, NULL);
|
||||||
if (backend == NULL) {
|
if (backend == NULL) {
|
||||||
|
@ -220,7 +235,7 @@ static struct wlr_backend *attempt_wl_backend(struct wl_display *display) {
|
||||||
wlr_wl_output_create(backend);
|
wlr_wl_output_create(backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
return backend;
|
return ensure_backend_renderer_and_allocator(backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WLR_HAS_X11_BACKEND
|
#if WLR_HAS_X11_BACKEND
|
||||||
|
@ -236,7 +251,7 @@ static struct wlr_backend *attempt_x11_backend(struct wl_display *display,
|
||||||
wlr_x11_output_create(backend);
|
wlr_x11_output_create(backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
return backend;
|
return ensure_backend_renderer_and_allocator(backend);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -252,7 +267,7 @@ static struct wlr_backend *attempt_headless_backend(
|
||||||
wlr_headless_add_output(backend, 1280, 720);
|
wlr_headless_add_output(backend, 1280, 720);
|
||||||
}
|
}
|
||||||
|
|
||||||
return backend;
|
return ensure_backend_renderer_and_allocator(backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wlr_backend *attempt_noop_backend(struct wl_display *display) {
|
static struct wlr_backend *attempt_noop_backend(struct wl_display *display) {
|
||||||
|
@ -297,7 +312,7 @@ static struct wlr_backend *attempt_drm_backend(struct wl_display *display,
|
||||||
wlr_multi_backend_add(backend, drm);
|
wlr_multi_backend_add(backend, drm);
|
||||||
}
|
}
|
||||||
|
|
||||||
return primary_drm;
|
return ensure_backend_renderer_and_allocator(primary_drm);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <wlr/interfaces/wlr_output.h>
|
#include <wlr/interfaces/wlr_output.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include <xf86drm.h>
|
#include <xf86drm.h>
|
||||||
#include "backend/backend.h"
|
|
||||||
#include "backend/drm/drm.h"
|
#include "backend/drm/drm.h"
|
||||||
#include "util/signal.h"
|
#include "util/signal.h"
|
||||||
|
|
||||||
|
@ -258,12 +257,6 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_renderer *renderer = wlr_backend_get_renderer(&drm->backend);
|
|
||||||
struct wlr_allocator *allocator = backend_get_allocator(&drm->backend);
|
|
||||||
if (renderer == NULL || allocator == NULL) {
|
|
||||||
goto error_mgpu_renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
drm->session_destroy.notify = handle_session_destroy;
|
drm->session_destroy.notify = handle_session_destroy;
|
||||||
wl_signal_add(&session->events.destroy, &drm->session_destroy);
|
wl_signal_add(&session->events.destroy, &drm->session_destroy);
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,8 @@
|
||||||
#include <wlr/render/wlr_renderer.h>
|
#include <wlr/render/wlr_renderer.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include <xf86drm.h>
|
#include <xf86drm.h>
|
||||||
#include "backend/backend.h"
|
|
||||||
#include "backend/headless.h"
|
#include "backend/headless.h"
|
||||||
#include "render/drm_format_set.h"
|
#include "render/drm_format_set.h"
|
||||||
#include "render/wlr_renderer.h"
|
|
||||||
#include "util/signal.h"
|
#include "util/signal.h"
|
||||||
|
|
||||||
struct wlr_headless_backend *headless_backend_from_backend(
|
struct wlr_headless_backend *headless_backend_from_backend(
|
||||||
|
@ -137,11 +135,6 @@ static bool backend_init(struct wlr_headless_backend *backend,
|
||||||
wl_signal_add(&renderer->events.destroy, &backend->parent_renderer_destroy);
|
wl_signal_add(&renderer->events.destroy, &backend->parent_renderer_destroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (backend_get_allocator(&backend->backend) == NULL) {
|
|
||||||
wlr_log(WLR_ERROR, "Failed to create allocator");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
backend->display_destroy.notify = handle_display_destroy;
|
backend->display_destroy.notify = handle_display_destroy;
|
||||||
wl_display_add_destroy_listener(display, &backend->display_destroy);
|
wl_display_add_destroy_listener(display, &backend->display_destroy);
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,9 @@
|
||||||
#include <wlr/interfaces/wlr_output.h>
|
#include <wlr/interfaces/wlr_output.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
|
||||||
#include "backend/backend.h"
|
|
||||||
#include "backend/wayland.h"
|
#include "backend/wayland.h"
|
||||||
#include "render/drm_format_set.h"
|
#include "render/drm_format_set.h"
|
||||||
#include "render/pixel_format.h"
|
#include "render/pixel_format.h"
|
||||||
#include "render/wlr_renderer.h"
|
|
||||||
#include "util/signal.h"
|
#include "util/signal.h"
|
||||||
|
|
||||||
#include "drm-client-protocol.h"
|
#include "drm-client-protocol.h"
|
||||||
|
@ -444,19 +442,11 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
|
||||||
wl->drm_fd = -1;
|
wl->drm_fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_renderer *renderer = wlr_backend_get_renderer(&wl->backend);
|
|
||||||
struct wlr_allocator *allocator = backend_get_allocator(&wl->backend);
|
|
||||||
if (renderer == NULL || allocator == NULL) {
|
|
||||||
goto error_drm_fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
wl->local_display_destroy.notify = handle_display_destroy;
|
wl->local_display_destroy.notify = handle_display_destroy;
|
||||||
wl_display_add_destroy_listener(display, &wl->local_display_destroy);
|
wl_display_add_destroy_listener(display, &wl->local_display_destroy);
|
||||||
|
|
||||||
return &wl->backend;
|
return &wl->backend;
|
||||||
|
|
||||||
error_drm_fd:
|
|
||||||
close(wl->drm_fd);
|
|
||||||
error_remote_display_src:
|
error_remote_display_src:
|
||||||
wl_event_source_remove(wl->remote_display_src);
|
wl_event_source_remove(wl->remote_display_src);
|
||||||
error_registry:
|
error_registry:
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include <wlr/interfaces/wlr_pointer.h>
|
#include <wlr/interfaces/wlr_pointer.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
|
||||||
#include "backend/backend.h"
|
|
||||||
#include "backend/x11.h"
|
#include "backend/x11.h"
|
||||||
#include "render/drm_format_set.h"
|
#include "render/drm_format_set.h"
|
||||||
#include "util/signal.h"
|
#include "util/signal.h"
|
||||||
|
@ -611,12 +610,6 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_renderer *renderer = wlr_backend_get_renderer(&x11->backend);
|
|
||||||
struct wlr_allocator *allocator = backend_get_allocator(&x11->backend);
|
|
||||||
if (renderer == NULL || allocator == NULL) {
|
|
||||||
goto error_event;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Windows can only display buffers with the depth they were created with
|
// Windows can only display buffers with the depth they were created with
|
||||||
// TODO: look into changing the window's depth at runtime
|
// TODO: look into changing the window's depth at runtime
|
||||||
const struct wlr_drm_format *dri3_format =
|
const struct wlr_drm_format *dri3_format =
|
||||||
|
|
Loading…
Reference in New Issue