From a670ee7940342333abd91b351e42992bba6d635e Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sat, 19 Dec 2020 15:54:53 +0100 Subject: [PATCH] backend/x11: remove swapchain Rely on wlr_output's generic swapchain handling. We still need a renderer for cursor readback, sadly. --- backend/x11/backend.c | 43 ----------------------- backend/x11/output.c | 80 +++---------------------------------------- include/backend/x11.h | 5 --- 3 files changed, 4 insertions(+), 124 deletions(-) diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 6faad6df..6c0e5a0b 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -27,14 +27,12 @@ #include #include #include -#include #include #include "backend/backend.h" #include "backend/x11.h" #include "render/allocator.h" #include "render/drm_format_set.h" -#include "render/wlr_renderer.h" #include "types/wlr_buffer.h" #include "util/signal.h" @@ -202,7 +200,6 @@ static void backend_destroy(struct wlr_backend *backend) { 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); #if HAS_XCB_ERRORS xcb_errors_context_free(x11->errors_context); @@ -620,46 +617,6 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, goto error_event; } - const struct wlr_drm_format_set *pixmap_formats; - if (x11->have_dri3 && (allocator->buffer_caps & WLR_BUFFER_CAP_DMABUF)) { - pixmap_formats = &x11->dri3_formats; - } else if (x11->have_shm && (allocator->buffer_caps & WLR_BUFFER_CAP_SHM)) { - pixmap_formats = &x11->shm_formats; - } else { - wlr_log(WLR_ERROR, - "Failed to create allocator (DRI3 and SHM unavailable)"); - goto error_event; - } - - const struct wlr_drm_format_set *render_formats = - wlr_renderer_get_render_formats(renderer); - if (render_formats == NULL) { - wlr_log(WLR_ERROR, "Failed to get available DRM formats from renderer"); - return false; - } - const struct wlr_drm_format *render_format = - wlr_drm_format_set_get(render_formats, x11->x11_format->drm); - if (render_format == NULL) { - wlr_log(WLR_ERROR, "Renderer doesn't support DRM format 0x%"PRIX32, - x11->x11_format->drm); - return false; - } - - const struct wlr_drm_format *pixmap_format = wlr_drm_format_set_get( - pixmap_formats, x11->x11_format->drm); - if (pixmap_format == NULL) { - wlr_log(WLR_ERROR, "X11 server doesn't support DRM format 0x%"PRIX32, - x11->x11_format->drm); - return false; - } - - x11->drm_format = wlr_drm_format_intersect(pixmap_format, render_format); - if (x11->drm_format == NULL) { - wlr_log(WLR_ERROR, "Failed to intersect X11 and render modifiers for " - "format 0x%"PRIX32, x11->x11_format->drm); - 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 = diff --git a/backend/x11/output.c b/backend/x11/output.c index 73266581..835df3b7 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -19,9 +19,7 @@ #include #include -#include "backend/backend.h" #include "backend/x11.h" -#include "render/swapchain.h" #include "render/wlr_renderer.h" #include "types/wlr_buffer.h" #include "util/signal.h" @@ -83,9 +81,7 @@ static void output_destroy(struct wlr_output *wlr_output) { } wl_list_remove(&output->link); - wlr_buffer_unlock(output->back_buffer); - wlr_swapchain_destroy(output->swapchain); - wlr_swapchain_destroy(output->cursor.swapchain); + if (output->cursor.pic != XCB_NONE) { xcb_render_free_picture(x11->xcb, output->cursor.pic); } @@ -97,26 +93,6 @@ static void output_destroy(struct wlr_output *wlr_output) { free(output); } -static bool output_attach_render(struct wlr_output *wlr_output, - int *buffer_age) { - struct wlr_x11_output *output = get_x11_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); - if (!output->back_buffer) { - wlr_log(WLR_ERROR, "Failed to acquire swapchain buffer"); - return false; - } - - if (!wlr_renderer_bind_buffer(renderer, output->back_buffer)) { - wlr_log(WLR_ERROR, "Failed to bind buffer to renderer"); - return false; - } - - return true; -} - static bool output_test(struct wlr_output *wlr_output) { if (wlr_output->pending.committed & WLR_OUTPUT_STATE_ENABLED) { wlr_log(WLR_DEBUG, "Cannot disable an X11 output"); @@ -273,24 +249,11 @@ static struct wlr_x11_buffer *get_or_create_x11_buffer( static bool output_commit_buffer(struct wlr_x11_output *output) { struct wlr_x11_backend *x11 = output->x11; - struct wlr_renderer *renderer = wlr_backend_get_renderer(&x11->backend); - struct wlr_buffer *buffer = NULL; - switch (output->wlr_output.pending.buffer_type) { - case WLR_OUTPUT_STATE_BUFFER_RENDER: - assert(output->back_buffer != NULL); - - wlr_renderer_bind_buffer(renderer, NULL); - - buffer = output->back_buffer; - output->back_buffer = NULL; - break; - case WLR_OUTPUT_STATE_BUFFER_SCANOUT: - buffer = wlr_buffer_lock(output->wlr_output.pending.buffer); - break; - } - assert(buffer != NULL); + assert(output->wlr_output.pending.buffer_type == + WLR_OUTPUT_STATE_BUFFER_SCANOUT); + struct wlr_buffer *buffer = output->wlr_output.pending.buffer; struct wlr_x11_buffer *x11_buffer = get_or_create_x11_buffer(output, buffer); if (!x11_buffer) { @@ -338,15 +301,10 @@ static bool output_commit_buffer(struct wlr_x11_output *output) { xcb_xfixes_destroy_region(x11->xcb, region); } - wlr_buffer_unlock(buffer); - - wlr_swapchain_set_buffer_submitted(output->swapchain, x11_buffer->buffer); - return true; error: destroy_x11_buffer(x11_buffer); - wlr_buffer_unlock(buffer); return false; } @@ -393,11 +351,6 @@ static bool output_commit(struct wlr_output *wlr_output) { return true; } -static void output_rollback_render(struct wlr_output *wlr_output) { - struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); - wlr_renderer_bind_buffer(renderer, NULL); -} - static void update_x11_output_cursor(struct wlr_x11_output *output, int32_t hotspot_x, int32_t hotspot_y) { struct wlr_x11_backend *x11 = output->x11; @@ -530,10 +483,8 @@ static const struct wlr_drm_format_set *output_get_primary_formats( static const struct wlr_output_impl output_impl = { .destroy = output_destroy, - .attach_render = output_attach_render, .test = output_test, .commit = output_commit, - .rollback_render = output_rollback_render, .set_cursor = output_set_cursor, .move_cursor = output_move_cursor, .get_primary_formats = output_get_primary_formats, @@ -541,7 +492,6 @@ static const struct wlr_output_impl output_impl = { struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) { struct wlr_x11_backend *x11 = get_x11_backend_from_backend(backend); - struct wlr_allocator *allocator = backend_get_allocator(backend); if (!x11->started) { ++x11->requested_outputs; @@ -561,14 +511,6 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) { wlr_output_update_custom_mode(wlr_output, 1024, 768, 0); - output->swapchain = wlr_swapchain_create(allocator, - wlr_output->width, wlr_output->height, x11->drm_format); - if (!output->swapchain) { - wlr_log(WLR_ERROR, "Failed to create swapchain"); - free(output); - return NULL; - } - snprintf(wlr_output->name, sizeof(wlr_output->name), "X11-%zd", ++x11->last_output_num); parse_xcb_setup(wlr_output, x11->xcb); @@ -653,8 +595,6 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) { void handle_x11_configure_notify(struct wlr_x11_output *output, xcb_configure_notify_event_t *ev) { - struct wlr_allocator *allocator = backend_get_allocator(&output->x11->backend); - // ignore events that set an invalid size: if (ev->width == 0 || ev->height == 0) { wlr_log(WLR_DEBUG, @@ -663,18 +603,6 @@ void handle_x11_configure_notify(struct wlr_x11_output *output, return; } - if (output->swapchain->width != ev->width || - output->swapchain->height != ev->height) { - struct wlr_swapchain *swapchain = wlr_swapchain_create( - allocator, ev->width, ev->height, - output->x11->drm_format); - if (!swapchain) { - return; - } - wlr_swapchain_destroy(output->swapchain); - output->swapchain = swapchain; - } - wlr_output_update_custom_mode(&output->wlr_output, ev->width, ev->height, 0); diff --git a/include/backend/x11.h b/include/backend/x11.h index bb2bbeb8..fadcbedc 100644 --- a/include/backend/x11.h +++ b/include/backend/x11.h @@ -21,7 +21,6 @@ #include #include #include -#include #define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f @@ -35,9 +34,6 @@ struct wlr_x11_output { xcb_window_t win; xcb_present_event_t present_event_id; - struct wlr_swapchain *swapchain; - struct wlr_buffer *back_buffer; - struct wlr_pointer pointer; struct wlr_input_device pointer_dev; @@ -93,7 +89,6 @@ struct wlr_x11_backend { 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; struct {