backend/headless: use common renderer and allocator
Instead of managing our own renderer and allocator, let the common code do it. Because wlr_headless_backend_create_with_renderer needs to re-use the parent renderer, we have to hand-roll some of the renderer initialization.
This commit is contained in:
parent
349553d011
commit
c82f37542d
|
@ -9,6 +9,7 @@
|
||||||
#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/gbm_allocator.h"
|
#include "render/gbm_allocator.h"
|
||||||
|
@ -54,7 +55,7 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_list_remove(&backend->display_destroy.link);
|
wl_list_remove(&backend->display_destroy.link);
|
||||||
wl_list_remove(&backend->renderer_destroy.link);
|
wl_list_remove(&backend->parent_renderer_destroy.link);
|
||||||
|
|
||||||
struct wlr_headless_output *output, *output_tmp;
|
struct wlr_headless_output *output, *output_tmp;
|
||||||
wl_list_for_each_safe(output, output_tmp, &backend->outputs, link) {
|
wl_list_for_each_safe(output, output_tmp, &backend->outputs, link) {
|
||||||
|
@ -71,11 +72,6 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
|
||||||
|
|
||||||
free(backend->format);
|
free(backend->format);
|
||||||
|
|
||||||
if (!backend->has_parent_renderer) {
|
|
||||||
wlr_renderer_destroy(backend->renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
wlr_allocator_destroy(backend->allocator);
|
|
||||||
close(backend->drm_fd);
|
close(backend->drm_fd);
|
||||||
free(backend);
|
free(backend);
|
||||||
}
|
}
|
||||||
|
@ -84,7 +80,11 @@ static struct wlr_renderer *backend_get_renderer(
|
||||||
struct wlr_backend *wlr_backend) {
|
struct wlr_backend *wlr_backend) {
|
||||||
struct wlr_headless_backend *backend =
|
struct wlr_headless_backend *backend =
|
||||||
headless_backend_from_backend(wlr_backend);
|
headless_backend_from_backend(wlr_backend);
|
||||||
return backend->renderer;
|
if (backend->parent_renderer != NULL) {
|
||||||
|
return backend->parent_renderer;
|
||||||
|
} else {
|
||||||
|
return wlr_backend->renderer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int backend_get_drm_fd(struct wlr_backend *wlr_backend) {
|
static int backend_get_drm_fd(struct wlr_backend *wlr_backend) {
|
||||||
|
@ -93,7 +93,7 @@ static int backend_get_drm_fd(struct wlr_backend *wlr_backend) {
|
||||||
return backend->drm_fd;
|
return backend->drm_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t backend_get_buffer_caps(struct wlr_backend *wlr_backend) {
|
static uint32_t get_buffer_caps(struct wlr_backend *wlr_backend) {
|
||||||
return WLR_BUFFER_CAP_DATA_PTR
|
return WLR_BUFFER_CAP_DATA_PTR
|
||||||
| WLR_BUFFER_CAP_DMABUF
|
| WLR_BUFFER_CAP_DMABUF
|
||||||
| WLR_BUFFER_CAP_SHM;
|
| WLR_BUFFER_CAP_SHM;
|
||||||
|
@ -104,7 +104,7 @@ static const struct wlr_backend_impl backend_impl = {
|
||||||
.destroy = backend_destroy,
|
.destroy = backend_destroy,
|
||||||
.get_renderer = backend_get_renderer,
|
.get_renderer = backend_get_renderer,
|
||||||
.get_drm_fd = backend_get_drm_fd,
|
.get_drm_fd = backend_get_drm_fd,
|
||||||
.get_buffer_caps = backend_get_buffer_caps,
|
.get_buffer_caps = get_buffer_caps,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
||||||
|
@ -115,16 +115,18 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
||||||
|
|
||||||
static void handle_renderer_destroy(struct wl_listener *listener, void *data) {
|
static void handle_renderer_destroy(struct wl_listener *listener, void *data) {
|
||||||
struct wlr_headless_backend *backend =
|
struct wlr_headless_backend *backend =
|
||||||
wl_container_of(listener, backend, renderer_destroy);
|
wl_container_of(listener, backend, parent_renderer_destroy);
|
||||||
backend_destroy(&backend->backend);
|
backend_destroy(&backend->backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool backend_init(struct wlr_headless_backend *backend,
|
static bool backend_init(struct wlr_headless_backend *backend,
|
||||||
struct wl_display *display, struct wlr_renderer *renderer) {
|
struct wl_display *display, struct wlr_renderer *renderer) {
|
||||||
wlr_backend_init(&backend->backend, &backend_impl);
|
wlr_backend_init(&backend->backend, &backend_impl);
|
||||||
|
|
||||||
backend->display = display;
|
backend->display = display;
|
||||||
wl_list_init(&backend->outputs);
|
wl_list_init(&backend->outputs);
|
||||||
wl_list_init(&backend->input_devices);
|
wl_list_init(&backend->input_devices);
|
||||||
|
wl_list_init(&backend->parent_renderer_destroy.link);
|
||||||
|
|
||||||
if (renderer == NULL) {
|
if (renderer == NULL) {
|
||||||
renderer = wlr_renderer_autocreate(&backend->backend);
|
renderer = wlr_renderer_autocreate(&backend->backend);
|
||||||
|
@ -132,17 +134,20 @@ static bool backend_init(struct wlr_headless_backend *backend,
|
||||||
wlr_log(WLR_ERROR, "Failed to create renderer");
|
wlr_log(WLR_ERROR, "Failed to create renderer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
backend->backend.renderer = renderer;
|
||||||
|
} else {
|
||||||
|
backend->parent_renderer = renderer;
|
||||||
|
backend->parent_renderer_destroy.notify = handle_renderer_destroy;
|
||||||
|
wl_signal_add(&renderer->events.destroy, &backend->parent_renderer_destroy);
|
||||||
}
|
}
|
||||||
backend->renderer = renderer;
|
|
||||||
|
|
||||||
backend->allocator = wlr_allocator_autocreate(&backend->backend, renderer);
|
if (backend_get_allocator(&backend->backend) == NULL) {
|
||||||
if (!backend->allocator) {
|
|
||||||
wlr_log(WLR_ERROR, "Failed to create allocator");
|
wlr_log(WLR_ERROR, "Failed to create allocator");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct wlr_drm_format_set *formats =
|
const struct wlr_drm_format_set *formats =
|
||||||
wlr_renderer_get_render_formats(backend->renderer);
|
wlr_renderer_get_render_formats(renderer);
|
||||||
if (formats == NULL) {
|
if (formats == NULL) {
|
||||||
wlr_log(WLR_ERROR, "Failed to get available DMA-BUF formats from renderer");
|
wlr_log(WLR_ERROR, "Failed to get available DMA-BUF formats from renderer");
|
||||||
return false;
|
return false;
|
||||||
|
@ -158,8 +163,6 @@ static bool backend_init(struct wlr_headless_backend *backend,
|
||||||
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);
|
||||||
|
|
||||||
wl_list_init(&backend->renderer_destroy.link);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +249,6 @@ struct wlr_backend *wlr_headless_backend_create_with_renderer(
|
||||||
wlr_log(WLR_ERROR, "Failed to allocate wlr_headless_backend");
|
wlr_log(WLR_ERROR, "Failed to allocate wlr_headless_backend");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
backend->has_parent_renderer = true;
|
|
||||||
|
|
||||||
int drm_fd = wlr_renderer_get_drm_fd(renderer);
|
int drm_fd = wlr_renderer_get_drm_fd(renderer);
|
||||||
if (drm_fd < 0) {
|
if (drm_fd < 0) {
|
||||||
|
@ -263,9 +265,6 @@ struct wlr_backend *wlr_headless_backend_create_with_renderer(
|
||||||
goto error_init;
|
goto error_init;
|
||||||
}
|
}
|
||||||
|
|
||||||
backend->renderer_destroy.notify = handle_renderer_destroy;
|
|
||||||
wl_signal_add(&renderer->events.destroy, &backend->renderer_destroy);
|
|
||||||
|
|
||||||
return &backend->backend;
|
return &backend->backend;
|
||||||
|
|
||||||
error_init:
|
error_init:
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <wlr/interfaces/wlr_output.h>
|
#include <wlr/interfaces/wlr_output.h>
|
||||||
#include <wlr/render/wlr_renderer.h>
|
#include <wlr/render/wlr_renderer.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
#include "backend/backend.h"
|
||||||
#include "backend/headless.h"
|
#include "backend/headless.h"
|
||||||
#include "render/swapchain.h"
|
#include "render/swapchain.h"
|
||||||
#include "render/wlr_renderer.h"
|
#include "render/wlr_renderer.h"
|
||||||
|
@ -19,13 +20,14 @@ static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width,
|
||||||
int32_t height, int32_t refresh) {
|
int32_t height, int32_t refresh) {
|
||||||
struct wlr_headless_output *output =
|
struct wlr_headless_output *output =
|
||||||
headless_output_from_output(wlr_output);
|
headless_output_from_output(wlr_output);
|
||||||
|
struct wlr_allocator *allocator = backend_get_allocator(wlr_output->backend);
|
||||||
|
|
||||||
if (refresh <= 0) {
|
if (refresh <= 0) {
|
||||||
refresh = HEADLESS_DEFAULT_REFRESH;
|
refresh = HEADLESS_DEFAULT_REFRESH;
|
||||||
}
|
}
|
||||||
|
|
||||||
wlr_swapchain_destroy(output->swapchain);
|
wlr_swapchain_destroy(output->swapchain);
|
||||||
output->swapchain = wlr_swapchain_create(output->backend->allocator,
|
output->swapchain = wlr_swapchain_create(allocator,
|
||||||
width, height, output->backend->format);
|
width, height, output->backend->format);
|
||||||
if (!output->swapchain) {
|
if (!output->swapchain) {
|
||||||
wlr_output_destroy(wlr_output);
|
wlr_output_destroy(wlr_output);
|
||||||
|
@ -42,6 +44,7 @@ static bool output_attach_render(struct wlr_output *wlr_output,
|
||||||
int *buffer_age) {
|
int *buffer_age) {
|
||||||
struct wlr_headless_output *output =
|
struct wlr_headless_output *output =
|
||||||
headless_output_from_output(wlr_output);
|
headless_output_from_output(wlr_output);
|
||||||
|
struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
|
||||||
|
|
||||||
wlr_buffer_unlock(output->back_buffer);
|
wlr_buffer_unlock(output->back_buffer);
|
||||||
output->back_buffer = wlr_swapchain_acquire(output->swapchain, buffer_age);
|
output->back_buffer = wlr_swapchain_acquire(output->swapchain, buffer_age);
|
||||||
|
@ -50,8 +53,7 @@ static bool output_attach_render(struct wlr_output *wlr_output,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wlr_renderer_bind_buffer(output->backend->renderer,
|
if (!wlr_renderer_bind_buffer(renderer, output->back_buffer)) {
|
||||||
output->back_buffer)) {
|
|
||||||
wlr_log(WLR_ERROR, "Failed to bind buffer to renderer");
|
wlr_log(WLR_ERROR, "Failed to bind buffer to renderer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -75,6 +77,7 @@ static bool output_test(struct wlr_output *wlr_output) {
|
||||||
static bool output_commit(struct wlr_output *wlr_output) {
|
static bool output_commit(struct wlr_output *wlr_output) {
|
||||||
struct wlr_headless_output *output =
|
struct wlr_headless_output *output =
|
||||||
headless_output_from_output(wlr_output);
|
headless_output_from_output(wlr_output);
|
||||||
|
struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
|
||||||
|
|
||||||
if (!output_test(wlr_output)) {
|
if (!output_test(wlr_output)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -95,7 +98,7 @@ static bool output_commit(struct wlr_output *wlr_output) {
|
||||||
case WLR_OUTPUT_STATE_BUFFER_RENDER:
|
case WLR_OUTPUT_STATE_BUFFER_RENDER:
|
||||||
assert(output->back_buffer != NULL);
|
assert(output->back_buffer != NULL);
|
||||||
|
|
||||||
wlr_renderer_bind_buffer(output->backend->renderer, NULL);
|
wlr_renderer_bind_buffer(renderer, NULL);
|
||||||
|
|
||||||
buffer = output->back_buffer;
|
buffer = output->back_buffer;
|
||||||
output->back_buffer = NULL;
|
output->back_buffer = NULL;
|
||||||
|
@ -120,8 +123,9 @@ static bool output_commit(struct wlr_output *wlr_output) {
|
||||||
static void output_rollback_render(struct wlr_output *wlr_output) {
|
static void output_rollback_render(struct wlr_output *wlr_output) {
|
||||||
struct wlr_headless_output *output =
|
struct wlr_headless_output *output =
|
||||||
headless_output_from_output(wlr_output);
|
headless_output_from_output(wlr_output);
|
||||||
|
struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
|
||||||
|
|
||||||
wlr_renderer_bind_buffer(output->backend->renderer, NULL);
|
wlr_renderer_bind_buffer(renderer, NULL);
|
||||||
|
|
||||||
wlr_buffer_unlock(output->back_buffer);
|
wlr_buffer_unlock(output->back_buffer);
|
||||||
output->back_buffer = NULL;
|
output->back_buffer = NULL;
|
||||||
|
@ -178,6 +182,7 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend,
|
||||||
unsigned int width, unsigned int height) {
|
unsigned int width, unsigned int height) {
|
||||||
struct wlr_headless_backend *backend =
|
struct wlr_headless_backend *backend =
|
||||||
headless_backend_from_backend(wlr_backend);
|
headless_backend_from_backend(wlr_backend);
|
||||||
|
struct wlr_allocator *allocator = backend_get_allocator(wlr_backend);
|
||||||
|
|
||||||
struct wlr_headless_output *output =
|
struct wlr_headless_output *output =
|
||||||
calloc(1, sizeof(struct wlr_headless_output));
|
calloc(1, sizeof(struct wlr_headless_output));
|
||||||
|
@ -190,7 +195,7 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend,
|
||||||
backend->display);
|
backend->display);
|
||||||
struct wlr_output *wlr_output = &output->wlr_output;
|
struct wlr_output *wlr_output = &output->wlr_output;
|
||||||
|
|
||||||
output->swapchain = wlr_swapchain_create(backend->allocator,
|
output->swapchain = wlr_swapchain_create(allocator,
|
||||||
width, height, backend->format);
|
width, height, backend->format);
|
||||||
if (!output->swapchain) {
|
if (!output->swapchain) {
|
||||||
goto error;
|
goto error;
|
||||||
|
|
|
@ -9,16 +9,14 @@
|
||||||
struct wlr_headless_backend {
|
struct wlr_headless_backend {
|
||||||
struct wlr_backend backend;
|
struct wlr_backend backend;
|
||||||
int drm_fd;
|
int drm_fd;
|
||||||
struct wlr_renderer *renderer;
|
|
||||||
struct wlr_allocator *allocator;
|
|
||||||
struct wlr_drm_format *format;
|
struct wlr_drm_format *format;
|
||||||
struct wl_display *display;
|
struct wl_display *display;
|
||||||
struct wl_list outputs;
|
struct wl_list outputs;
|
||||||
size_t last_output_num;
|
size_t last_output_num;
|
||||||
struct wl_list input_devices;
|
struct wl_list input_devices;
|
||||||
struct wl_listener display_destroy;
|
struct wl_listener display_destroy;
|
||||||
struct wl_listener renderer_destroy;
|
struct wlr_renderer *parent_renderer;
|
||||||
bool has_parent_renderer;
|
struct wl_listener parent_renderer_destroy;
|
||||||
bool started;
|
bool started;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue