aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/wayland/backend.c62
-rw-r--r--backend/wayland/output.c39
2 files changed, 43 insertions, 58 deletions
diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c
index 0365aab2..dfe69356 100644
--- a/backend/wayland/backend.c
+++ b/backend/wayland/backend.c
@@ -6,8 +6,6 @@
#include <stdlib.h>
#include <unistd.h>
-#include <wlr/config.h>
-
#include <drm_fourcc.h>
#include <wayland-server-core.h>
#include <xf86drm.h>
@@ -17,11 +15,10 @@
#include <wlr/interfaces/wlr_output.h>
#include <wlr/util/log.h>
+#include "backend/backend.h"
#include "backend/wayland.h"
#include "render/drm_format_set.h"
-#include "render/gbm_allocator.h"
#include "render/pixel_format.h"
-#include "render/shm_allocator.h"
#include "render/wlr_renderer.h"
#include "types/wlr_buffer.h"
#include "util/signal.h"
@@ -309,24 +306,22 @@ static void backend_destroy(struct wlr_backend *backend) {
wlr_input_device_destroy(input_device);
}
+ struct wlr_wl_buffer *buffer, *tmp_buffer;
+ wl_list_for_each_safe(buffer, tmp_buffer, &wl->buffers, link) {
+ destroy_wl_buffer(buffer);
+ }
+
wlr_backend_finish(backend);
wl_list_remove(&wl->local_display_destroy.link);
wl_event_source_remove(wl->remote_display_src);
- wlr_renderer_destroy(wl->renderer);
- wlr_allocator_destroy(wl->allocator);
close(wl->drm_fd);
wlr_drm_format_set_finish(&wl->shm_formats);
wlr_drm_format_set_finish(&wl->linux_dmabuf_v1_formats);
- struct wlr_wl_buffer *buffer, *tmp_buffer;
- wl_list_for_each_safe(buffer, tmp_buffer, &wl->buffers, link) {
- destroy_wl_buffer(buffer);
- }
-
destroy_wl_seats(wl);
if (wl->zxdg_decoration_manager_v1) {
zxdg_decoration_manager_v1_destroy(wl->zxdg_decoration_manager_v1);
@@ -355,17 +350,12 @@ static void backend_destroy(struct wlr_backend *backend) {
free(wl);
}
-static struct wlr_renderer *backend_get_renderer(struct wlr_backend *backend) {
- struct wlr_wl_backend *wl = get_wl_backend_from_backend(backend);
- return wl->renderer;
-}
-
static int backend_get_drm_fd(struct wlr_backend *backend) {
struct wlr_wl_backend *wl = get_wl_backend_from_backend(backend);
return wl->drm_fd;
}
-static uint32_t backend_get_buffer_caps(struct wlr_backend *backend) {
+static uint32_t get_buffer_caps(struct wlr_backend *backend) {
struct wlr_wl_backend *wl = get_wl_backend_from_backend(backend);
return (wl->zwp_linux_dmabuf_v1 ? WLR_BUFFER_CAP_DMABUF : 0)
| (wl->shm ? WLR_BUFFER_CAP_SHM : 0);
@@ -374,9 +364,8 @@ static uint32_t backend_get_buffer_caps(struct wlr_backend *backend) {
static const struct wlr_backend_impl backend_impl = {
.start = backend_start,
.destroy = backend_destroy,
- .get_renderer = backend_get_renderer,
.get_drm_fd = backend_get_drm_fd,
- .get_buffer_caps = backend_get_buffer_caps,
+ .get_buffer_caps = get_buffer_caps,
};
bool wlr_backend_is_wl(struct wlr_backend *b) {
@@ -456,20 +445,13 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
wl->drm_fd = -1;
}
- wl->renderer = wlr_renderer_autocreate(&wl->backend);
- if (wl->renderer == NULL) {
- wlr_log(WLR_ERROR, "Failed to create renderer");
- goto error_renderer;
- }
-
- uint32_t caps = renderer_get_render_buffer_caps(wl->renderer);
-
- wl->allocator = wlr_allocator_autocreate(&wl->backend, wl->renderer);
- if (wl->allocator == NULL) {
- wlr_log(WLR_ERROR, "Failed to create allocator");
- goto error_allocator;
+ 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;
}
+ uint32_t caps = renderer_get_render_buffer_caps(renderer);
const struct wlr_drm_format_set *remote_formats;
if ((caps & WLR_BUFFER_CAP_DMABUF) && wl->zwp_linux_dmabuf_v1) {
remote_formats = &wl->linux_dmabuf_v1_formats;
@@ -478,14 +460,14 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
} else {
wlr_log(WLR_ERROR,
"Failed to get remote formats (DRI3 and SHM unavailable)");
- goto error_allocator;
+ goto error_drm_fd;
}
const struct wlr_drm_format_set *render_formats =
- wlr_renderer_get_render_formats(wl->renderer);
+ wlr_renderer_get_render_formats(renderer);
if (render_formats == NULL) {
wlr_log(WLR_ERROR, "Failed to get available render-capable formats");
- goto error_allocator;
+ goto error_drm_fd;
}
uint32_t fmt = DRM_FORMAT_ARGB8888;
@@ -495,21 +477,21 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
if (remote_format == NULL) {
wlr_log(WLR_ERROR, "Remote compositor doesn't support DRM format "
"0x%"PRIX32, fmt);
- goto error_allocator;
+ goto error_drm_fd;
}
const struct wlr_drm_format *render_format =
wlr_drm_format_set_get(render_formats, fmt);
if (render_format == NULL) {
wlr_log(WLR_ERROR, "Renderer doesn't support DRM format 0x%"PRIX32, fmt);
- goto error_allocator;
+ goto error_drm_fd;
}
wl->format = wlr_drm_format_intersect(remote_format, render_format);
if (wl->format == NULL) {
wlr_log(WLR_ERROR, "Failed to intersect remote and render modifiers "
"for format 0x%"PRIX32, fmt);
- goto error_allocator;
+ goto error_drm_fd;
}
wl->local_display_destroy.notify = handle_display_destroy;
@@ -517,10 +499,7 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
return &wl->backend;
-error_allocator:
- wlr_allocator_destroy(wl->allocator);
-error_renderer:
- wlr_renderer_destroy(wl->renderer);
+error_drm_fd:
close(wl->drm_fd);
error_remote_display_src:
wl_event_source_remove(wl->remote_display_src);
@@ -536,6 +515,7 @@ error_registry:
error_display:
wl_display_disconnect(wl->remote_display);
error_wl:
+ wlr_backend_finish(&wl->backend);
free(wl);
return NULL;
}
diff --git a/backend/wayland/output.c b/backend/wayland/output.c
index 3d5d2e31..ae2f942e 100644
--- a/backend/wayland/output.c
+++ b/backend/wayland/output.c
@@ -15,6 +15,7 @@
#include <wlr/types/wlr_matrix.h>
#include <wlr/util/log.h>
+#include "backend/backend.h"
#include "backend/wayland.h"
#include "render/pixel_format.h"
#include "render/swapchain.h"
@@ -99,10 +100,11 @@ static const struct wp_presentation_feedback_listener
static bool output_set_custom_mode(struct wlr_output *wlr_output,
int32_t width, int32_t height, int32_t refresh) {
struct wlr_wl_output *output = get_wl_output_from_output(wlr_output);
+ struct wlr_allocator *allocator = backend_get_allocator(wlr_output->backend);
if (wlr_output->width != width || wlr_output->height != height) {
- struct wlr_swapchain *swapchain = wlr_swapchain_create(
- output->backend->allocator, width, height, output->backend->format);
+ struct wlr_swapchain *swapchain = wlr_swapchain_create(allocator,
+ width, height, output->backend->format);
if (swapchain == NULL) {
return false;
}
@@ -117,6 +119,7 @@ static bool output_set_custom_mode(struct wlr_output *wlr_output,
static bool output_attach_render(struct wlr_output *wlr_output,
int *buffer_age) {
struct wlr_wl_output *output = get_wl_output_from_output(wlr_output);
+ struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
wlr_buffer_unlock(output->back_buffer);
output->back_buffer = wlr_swapchain_acquire(output->swapchain, buffer_age);
@@ -125,8 +128,7 @@ static bool output_attach_render(struct wlr_output *wlr_output,
return false;
}
- if (!wlr_renderer_bind_buffer(output->backend->renderer,
- output->back_buffer)) {
+ if (!wlr_renderer_bind_buffer(renderer, output->back_buffer)) {
wlr_log(WLR_ERROR, "Failed to bind buffer to renderer");
return false;
}
@@ -296,6 +298,7 @@ static bool output_test(struct wlr_output *wlr_output) {
static bool output_commit(struct wlr_output *wlr_output) {
struct wlr_wl_output *output =
get_wl_output_from_output(wlr_output);
+ struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
if (!output_test(wlr_output)) {
return false;
@@ -336,7 +339,7 @@ static bool output_commit(struct wlr_output *wlr_output) {
assert(output->back_buffer != NULL);
wlr_buffer = output->back_buffer;
- wlr_renderer_bind_buffer(output->backend->renderer, NULL);
+ wlr_renderer_bind_buffer(renderer, NULL);
break;
case WLR_OUTPUT_STATE_BUFFER_SCANOUT:;
wlr_buffer = wlr_output->pending.buffer;
@@ -397,8 +400,8 @@ static bool output_commit(struct wlr_output *wlr_output) {
}
static void output_rollback_render(struct wlr_output *wlr_output) {
- struct wlr_wl_output *output = get_wl_output_from_output(wlr_output);
- wlr_renderer_bind_buffer(output->backend->renderer, NULL);
+ struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
+ wlr_renderer_bind_buffer(renderer, NULL);
}
static bool output_set_cursor(struct wlr_output *wlr_output,
@@ -407,6 +410,8 @@ static bool output_set_cursor(struct wlr_output *wlr_output,
int32_t hotspot_x, int32_t hotspot_y, bool update_texture) {
struct wlr_wl_output *output = get_wl_output_from_output(wlr_output);
struct wlr_wl_backend *backend = output->backend;
+ struct wlr_renderer *renderer = wlr_backend_get_renderer(&backend->backend);
+ struct wlr_allocator *allocator = backend_get_allocator(&backend->backend);
struct wlr_box hotspot = { .x = hotspot_x, .y = hotspot_y };
wlr_box_transform(&hotspot, &hotspot,
@@ -437,9 +442,8 @@ static bool output_set_cursor(struct wlr_output *wlr_output,
output->cursor.swapchain->width != width ||
output->cursor.swapchain->height != height) {
wlr_swapchain_destroy(output->cursor.swapchain);
- output->cursor.swapchain = wlr_swapchain_create(
- output->backend->allocator, width, height,
- output->backend->format);
+ output->cursor.swapchain = wlr_swapchain_create(allocator,
+ width, height, output->backend->format);
if (output->cursor.swapchain == NULL) {
return false;
}
@@ -451,7 +455,7 @@ static bool output_set_cursor(struct wlr_output *wlr_output,
return false;
}
- if (!wlr_renderer_bind_buffer(output->backend->renderer, wlr_buffer)) {
+ if (!wlr_renderer_bind_buffer(renderer, wlr_buffer)) {
return false;
}
@@ -475,12 +479,12 @@ static bool output_set_cursor(struct wlr_output *wlr_output,
float matrix[9];
wlr_matrix_project_box(matrix, &cursor_box, transform, 0, output_matrix);
- wlr_renderer_begin(backend->renderer, width, height);
- wlr_renderer_clear(backend->renderer, (float[]){ 0.0, 0.0, 0.0, 0.0 });
- wlr_render_texture_with_matrix(backend->renderer, texture, matrix, 1.0);
- wlr_renderer_end(backend->renderer);
+ wlr_renderer_begin(renderer, width, height);
+ wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 0.0 });
+ wlr_render_texture_with_matrix(renderer, texture, matrix, 1.0);
+ wlr_renderer_end(renderer);
- wlr_renderer_bind_buffer(output->backend->renderer, NULL);
+ wlr_renderer_bind_buffer(renderer, NULL);
struct wlr_wl_buffer *buffer =
get_or_create_wl_buffer(output->backend, wlr_buffer);
@@ -681,7 +685,8 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *wlr_backend) {
&xdg_toplevel_listener, output);
wl_surface_commit(output->surface);
- output->swapchain = wlr_swapchain_create(output->backend->allocator,
+ struct wlr_allocator *allocator = backend_get_allocator(&backend->backend);
+ output->swapchain = wlr_swapchain_create(allocator,
wlr_output->width, wlr_output->height, output->backend->format);
if (output->swapchain == NULL) {
goto error;