From 6dfc8ce00b3627834cdb928a7c02b8957d607407 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sat, 19 Dec 2020 15:46:14 +0100 Subject: [PATCH] backend/x11: implement get_drm_fd --- backend/x11/backend.c | 18 ++++++++++++++++-- include/backend/x11.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 1fde98c6..84938de3 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -188,6 +188,8 @@ static void backend_destroy(struct wlr_backend *backend) { xcb_errors_context_free(x11->errors_context); #endif + close(x11->drm_fd); + if (x11->xlib_conn) { XCloseDisplay(x11->xlib_conn); } @@ -200,10 +202,16 @@ static struct wlr_renderer *backend_get_renderer( return x11->renderer; } +static int backend_get_drm_fd(struct wlr_backend *backend) { + struct wlr_x11_backend *x11 = get_x11_backend_from_backend(backend); + return x11->drm_fd; +} + 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, }; bool wlr_backend_is_x11(struct wlr_backend *backend) { @@ -519,12 +527,18 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, // DRI3 may return a render node (Xwayland) or an authenticated primary // node (plain Glamor). - int drm_fd = query_dri3_drm_fd(x11); - if (drm_fd < 0) { + x11->drm_fd = query_dri3_drm_fd(x11); + if (x11->drm_fd < 0) { wlr_log(WLR_ERROR, "Failed to query DRI3 DRM FD"); goto error_event; } + int drm_fd = fcntl(x11->drm_fd, F_DUPFD_CLOEXEC, 0); + if (drm_fd < 0) { + wlr_log(WLR_ERROR, "fcntl(F_DUPFD_CLOEXEC) failed"); + goto error_event; + } + struct wlr_gbm_allocator *gbm_alloc = wlr_gbm_allocator_create(drm_fd); if (gbm_alloc == NULL) { wlr_log(WLR_ERROR, "Failed to create GBM allocator"); diff --git a/include/backend/x11.h b/include/backend/x11.h index 44f3693b..85836ad4 100644 --- a/include/backend/x11.h +++ b/include/backend/x11.h @@ -76,6 +76,7 @@ struct wlr_x11_backend { struct wlr_keyboard keyboard; struct wlr_input_device keyboard_dev; + int drm_fd; struct wlr_renderer *renderer; struct wlr_drm_format_set dri3_formats; const struct wlr_x11_format *x11_format;