From 54f9944b4885e4a08c0f004136ef06f732b8308f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 23 Nov 2023 14:08:46 +0100 Subject: backend/drm: drop wl_display argument We can grab the event loop from the wlr_session instead. --- backend/backend.c | 12 +++++------- backend/drm/backend.c | 22 ++++------------------ backend/drm/drm.c | 2 +- backend/drm/monitor.c | 6 ++---- include/backend/drm/drm.h | 2 -- include/backend/drm/monitor.h | 3 +-- include/wlr/backend/drm.h | 5 ++--- 7 files changed, 15 insertions(+), 37 deletions(-) diff --git a/backend/backend.c b/backend/backend.c index 8a6ca7a5..58fd8de4 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -245,8 +245,7 @@ static struct wlr_backend *attempt_headless_backend( return backend; } -static struct wlr_backend *attempt_drm_backend(struct wl_display *display, - struct wlr_backend *backend, struct wlr_session *session) { +static struct wlr_backend *attempt_drm_backend(struct wlr_backend *backend, struct wlr_session *session) { #if WLR_HAS_DRM_BACKEND struct wlr_device *gpus[8]; ssize_t num_gpus = wlr_session_find_gpus(session, 8, gpus); @@ -264,8 +263,7 @@ static struct wlr_backend *attempt_drm_backend(struct wl_display *display, struct wlr_backend *primary_drm = NULL; for (size_t i = 0; i < (size_t)num_gpus; ++i) { - struct wlr_backend *drm = wlr_drm_backend_create(display, session, - gpus[i], primary_drm); + struct wlr_backend *drm = wlr_drm_backend_create(session, gpus[i], primary_drm); if (!drm) { wlr_log(WLR_ERROR, "Failed to create DRM backend"); continue; @@ -283,7 +281,7 @@ static struct wlr_backend *attempt_drm_backend(struct wl_display *display, } if (getenv("WLR_DRM_DEVICES") == NULL) { - drm_backend_monitor_create(backend, primary_drm, session, display); + drm_backend_monitor_create(backend, primary_drm, session); } return primary_drm; @@ -326,7 +324,7 @@ static bool attempt_backend_by_name(struct wl_display *display, backend = attempt_libinput_backend(*session_ptr); } else { // attempt_drm_backend() adds the multi drm backends itself - return attempt_drm_backend(display, multi, *session_ptr) != NULL; + return attempt_drm_backend(multi, *session_ptr) != NULL; } } else { wlr_log(WLR_ERROR, "unrecognized backend '%s'", name); @@ -431,7 +429,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, goto error; } - struct wlr_backend *primary_drm = attempt_drm_backend(display, multi, session); + struct wlr_backend *primary_drm = attempt_drm_backend(multi, session); if (primary_drm == NULL) { wlr_log(WLR_ERROR, "Failed to open any DRM device"); goto error; diff --git a/backend/drm/backend.c b/backend/drm/backend.c index 655a1856..b65dc10d 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -47,7 +47,6 @@ static void backend_destroy(struct wlr_backend *backend) { wlr_backend_finish(backend); - wl_list_remove(&drm->display_destroy.link); wl_list_remove(&drm->session_destroy.link); wl_list_remove(&drm->session_active.link); wl_list_remove(&drm->parent_destroy.link); @@ -180,22 +179,15 @@ static void handle_session_destroy(struct wl_listener *listener, void *data) { backend_destroy(&drm->backend); } -static void handle_display_destroy(struct wl_listener *listener, void *data) { - struct wlr_drm_backend *drm = - wl_container_of(listener, drm, display_destroy); - backend_destroy(&drm->backend); -} - static void handle_parent_destroy(struct wl_listener *listener, void *data) { struct wlr_drm_backend *drm = wl_container_of(listener, drm, parent_destroy); backend_destroy(&drm->backend); } -struct wlr_backend *wlr_drm_backend_create(struct wl_display *display, - struct wlr_session *session, struct wlr_device *dev, - struct wlr_backend *parent) { - assert(display && session && dev); +struct wlr_backend *wlr_drm_backend_create(struct wlr_session *session, + struct wlr_device *dev, struct wlr_backend *parent) { + assert(session && dev); assert(!parent || wlr_backend_is_drm(parent)); char *name = drmGetDeviceNameFromFd2(dev->fd); @@ -234,10 +226,7 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display, drm->dev_remove.notify = handle_dev_remove; wl_signal_add(&dev->events.remove, &drm->dev_remove); - drm->display = display; - - struct wl_event_loop *event_loop = wl_display_get_event_loop(display); - drm->drm_event = wl_event_loop_add_fd(event_loop, drm->fd, + drm->drm_event = wl_event_loop_add_fd(session->event_loop, drm->fd, WL_EVENT_READABLE, handle_drm_event, drm); if (!drm->drm_event) { wlr_log(WLR_ERROR, "Failed to create DRM event source"); @@ -288,9 +277,6 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display, drm->session_destroy.notify = handle_session_destroy; wl_signal_add(&session->events.destroy, &drm->session_destroy); - drm->display_destroy.notify = handle_display_destroy; - wl_display_add_destroy_listener(display, &drm->display_destroy); - return &drm->backend; error_mgpu_renderer: diff --git a/backend/drm/drm.c b/backend/drm/drm.c index e62dd638..5ad84235 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -1483,7 +1483,7 @@ static bool connect_drm_connector(struct wlr_drm_connector *wlr_conn, free(current_modeinfo); - wlr_output_init(output, &drm->backend, &output_impl, wl_display_get_event_loop(drm->display), &state); + wlr_output_init(output, &drm->backend, &output_impl, drm->session->event_loop, &state); wlr_output_state_finish(&state); // fill out the modes diff --git a/backend/drm/monitor.c b/backend/drm/monitor.c index 939a00ff..efd85374 100644 --- a/backend/drm/monitor.c +++ b/backend/drm/monitor.c @@ -25,8 +25,7 @@ static void handle_add_drm_card(struct wl_listener *listener, void *data) { } wlr_log(WLR_DEBUG, "Creating DRM backend for %s after hotplug", event->path); - struct wlr_backend *child_drm = wlr_drm_backend_create( - backend_monitor->display, backend_monitor->session, + struct wlr_backend *child_drm = wlr_drm_backend_create(backend_monitor->session, dev, backend_monitor->primary_drm); if (!child_drm) { wlr_log(WLR_ERROR, "Failed to create DRM backend after hotplug"); @@ -65,7 +64,7 @@ static void handle_multi_destroy(struct wl_listener *listener, void *data) { struct wlr_drm_backend_monitor *drm_backend_monitor_create( struct wlr_backend *multi, struct wlr_backend *primary_drm, - struct wlr_session *session, struct wl_display *display) { + struct wlr_session *session) { struct wlr_drm_backend_monitor *monitor = calloc(1, sizeof(*monitor)); if (!monitor) { wlr_log_errno(WLR_ERROR, "Allocation failed"); @@ -75,7 +74,6 @@ struct wlr_drm_backend_monitor *drm_backend_monitor_create( monitor->multi = multi; monitor->primary_drm = primary_drm; monitor->session = session; - monitor->display = display; monitor->session_add_drm_card.notify = handle_add_drm_card; wl_signal_add(&session->events.add_drm_card, &monitor->session_add_drm_card); diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index 39a247b1..4b75b8a4 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -91,10 +91,8 @@ struct wlr_drm_backend { size_t num_planes; struct wlr_drm_plane *planes; - struct wl_display *display; struct wl_event_source *drm_event; - struct wl_listener display_destroy; struct wl_listener session_destroy; struct wl_listener session_active; struct wl_listener parent_destroy; diff --git a/include/backend/drm/monitor.h b/include/backend/drm/monitor.h index bf5bda2d..51817193 100644 --- a/include/backend/drm/monitor.h +++ b/include/backend/drm/monitor.h @@ -10,7 +10,6 @@ struct wlr_drm_backend_monitor { struct wlr_backend *multi; struct wlr_backend *primary_drm; struct wlr_session *session; - struct wl_display *display; struct wl_listener multi_destroy; struct wl_listener primary_drm_destroy; @@ -20,6 +19,6 @@ struct wlr_drm_backend_monitor { struct wlr_drm_backend_monitor *drm_backend_monitor_create( struct wlr_backend *multi, struct wlr_backend *primary_drm, - struct wlr_session *session, struct wl_display *display); + struct wlr_session *session); #endif diff --git a/include/wlr/backend/drm.h b/include/wlr/backend/drm.h index e8f9f6a3..3ca6390a 100644 --- a/include/wlr/backend/drm.h +++ b/include/wlr/backend/drm.h @@ -36,9 +36,8 @@ struct wlr_drm_lease { * To slave this to another DRM backend, pass it as the parent (which _must_ be * a DRM backend, other kinds of backends raise SIGABRT). */ -struct wlr_backend *wlr_drm_backend_create(struct wl_display *display, - struct wlr_session *session, struct wlr_device *dev, - struct wlr_backend *parent); +struct wlr_backend *wlr_drm_backend_create(struct wlr_session *session, + struct wlr_device *dev, struct wlr_backend *parent); bool wlr_backend_is_drm(struct wlr_backend *backend); bool wlr_output_is_drm(struct wlr_output *output); -- cgit v1.2.3