backend/drm: drop wl_display argument

We can grab the event loop from the wlr_session instead.
This commit is contained in:
Simon Ser 2023-11-23 14:08:46 +01:00 committed by Kirill Primak
parent b62ac611c8
commit 54f9944b48
7 changed files with 15 additions and 37 deletions

View File

@ -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;

View File

@ -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:

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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

View File

@ -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);