From 68c4f159585c2466e60220d14215340ae58dd958 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sat, 19 Dec 2020 15:30:25 +0100 Subject: [PATCH] backend/x11: implement get_dmabuf_primary_formats --- backend/x11/backend.c | 22 ++++++++++++++++++++++ backend/x11/output.c | 15 +++++++++++++++ include/backend/x11.h | 2 ++ 3 files changed, 39 insertions(+) diff --git a/backend/x11/backend.c b/backend/x11/backend.c index d914ffb1..6faad6df 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -198,6 +198,8 @@ static void backend_destroy(struct wlr_backend *backend) { } wl_list_remove(&x11->display_destroy.link); + wlr_drm_format_set_finish(&x11->primary_dri3_formats); + wlr_drm_format_set_finish(&x11->primary_shm_formats); wlr_drm_format_set_finish(&x11->dri3_formats); wlr_drm_format_set_finish(&x11->shm_formats); free(x11->drm_format); @@ -658,6 +660,26 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, return false; } + // Windows can only display buffers with the depth they were created with + // TODO: look into changing the window's depth at runtime + const struct wlr_drm_format *dri3_format = + wlr_drm_format_set_get(&x11->dri3_formats, x11->x11_format->drm); + if (x11->have_dri3 && dri3_format != NULL) { + wlr_drm_format_set_add(&x11->primary_dri3_formats, + dri3_format->format, DRM_FORMAT_MOD_INVALID); + for (size_t i = 0; i < dri3_format->len; i++) { + wlr_drm_format_set_add(&x11->primary_dri3_formats, + dri3_format->format, dri3_format->modifiers[i]); + } + } + + const struct wlr_drm_format *shm_format = + wlr_drm_format_set_get(&x11->shm_formats, x11->x11_format->drm); + if (x11->have_shm && shm_format != NULL) { + wlr_drm_format_set_add(&x11->primary_shm_formats, + shm_format->format, DRM_FORMAT_MOD_INVALID); + } + #if HAS_XCB_ERRORS if (xcb_errors_context_new(x11->xcb, &x11->errors_context) != 0) { wlr_log(WLR_ERROR, "Failed to create error context"); diff --git a/backend/x11/output.c b/backend/x11/output.c index 56161dee..73266581 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -23,6 +23,7 @@ #include "backend/x11.h" #include "render/swapchain.h" #include "render/wlr_renderer.h" +#include "types/wlr_buffer.h" #include "util/signal.h" #include "util/time.h" @@ -514,6 +515,19 @@ static bool output_move_cursor(struct wlr_output *_output, int x, int y) { return true; } +static const struct wlr_drm_format_set *output_get_primary_formats( + struct wlr_output *wlr_output, uint32_t buffer_caps) { + struct wlr_x11_output *output = get_x11_output_from_output(wlr_output); + struct wlr_x11_backend *x11 = output->x11; + + if (x11->have_dri3 && (buffer_caps & WLR_BUFFER_CAP_DMABUF)) { + return &output->x11->primary_dri3_formats; + } else if (x11->have_shm && (buffer_caps & WLR_BUFFER_CAP_SHM)) { + return &output->x11->primary_shm_formats; + } + return NULL; +} + static const struct wlr_output_impl output_impl = { .destroy = output_destroy, .attach_render = output_attach_render, @@ -522,6 +536,7 @@ static const struct wlr_output_impl output_impl = { .rollback_render = output_rollback_render, .set_cursor = output_set_cursor, .move_cursor = output_move_cursor, + .get_primary_formats = output_get_primary_formats, }; struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) { diff --git a/include/backend/x11.h b/include/backend/x11.h index fe818760..bb2bbeb8 100644 --- a/include/backend/x11.h +++ b/include/backend/x11.h @@ -91,6 +91,8 @@ struct wlr_x11_backend { struct wlr_drm_format_set dri3_formats; struct wlr_drm_format_set shm_formats; const struct wlr_x11_format *x11_format; + struct wlr_drm_format_set primary_dri3_formats; + struct wlr_drm_format_set primary_shm_formats; struct wlr_drm_format *drm_format; struct wl_event_source *event_source;