diff options
Diffstat (limited to 'backend')
-rw-r--r-- | backend/drm/backend.c | 93 | ||||
-rw-r--r-- | backend/drm/drm.c | 15 | ||||
-rw-r--r-- | backend/drm/drm.h | 3 |
3 files changed, 61 insertions, 50 deletions
diff --git a/backend/drm/backend.c b/backend/drm/backend.c index 6f5b0596..ea14d41c 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -15,24 +15,26 @@ #include <backend/udev.h> #include "drm.h" -static bool wlr_drm_backend_init(struct wlr_backend_state *state) { - wlr_drm_scan_connectors(state); +static bool wlr_drm_backend_init(struct wlr_backend_state *drm) { + wlr_drm_scan_connectors(drm); return true; } -static void wlr_drm_backend_destroy(struct wlr_backend_state *state) { - if (!state) { +static void wlr_drm_backend_destroy(struct wlr_backend_state *drm) { + if (!drm) { return; } - for (size_t i = 0; state->outputs && i < state->outputs->length; ++i) { - struct wlr_output_state *output = state->outputs->items[i]; + + for (size_t i = 0; drm->outputs && i < drm->outputs->length; ++i) { + struct wlr_output_state *output = drm->outputs->items[i]; wlr_output_destroy(output->base); } - wlr_udev_signal_remove(state->udev, &state->drm_invalidated); - wlr_drm_renderer_free(&state->renderer); - wlr_session_close_file(state->session, state->fd); - wl_event_source_remove(state->drm_event); - free(state); + + wlr_udev_signal_remove(drm->udev, &drm->drm_invalidated); + wlr_drm_renderer_free(&drm->renderer); + wlr_session_close_file(drm->session, drm->fd); + wl_event_source_remove(drm->drm_event); + free(drm); } static struct wlr_backend_impl backend_impl = { @@ -76,73 +78,68 @@ static void drm_invalidated(struct wl_listener *listener, void *data) { struct wlr_backend *wlr_drm_backend_create(struct wl_display *display, struct wlr_session *session, struct wlr_udev *udev, int gpu_fd) { - assert(display && session && gpu_fd > 0); + assert(display && session && gpu_fd >= 0); char *name = drmGetDeviceNameFromFd2(gpu_fd); drmVersion *version = drmGetVersion(gpu_fd); - wlr_log(L_INFO, "Initalizing DRM backend for %s (%s)", name, version->name); - free(name); drmFreeVersion(version); - struct wlr_backend_state *state = calloc(1, sizeof(struct wlr_backend_state)); - if (!state) { - wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno)); + struct wlr_backend_state *drm = calloc(1, sizeof(*drm)); + if (!drm) { + wlr_log_errno(L_ERROR, "Allocation failed"); return NULL; } - struct wlr_backend *backend = wlr_backend_create(&backend_impl, state); + struct wlr_backend *backend = wlr_backend_create(&backend_impl, drm); if (!backend) { - wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno)); + wlr_log_errno(L_ERROR, "Allocation failed"); return NULL; } - state->base = backend; - state->session = session; - state->udev = udev; - state->outputs = list_create(); - if (!state->outputs) { + drm->base = backend; + drm->session = session; + drm->udev = udev; + drm->outputs = list_create(); + if (!drm->outputs) { wlr_log(L_ERROR, "Failed to allocate list"); goto error_backend; } - state->fd = gpu_fd; + drm->fd = gpu_fd; struct stat st; - if (fstat(state->fd, &st) < 0) { - wlr_log(L_ERROR, "Stat failed: %s", strerror(errno)); + if (fstat(drm->fd, &st) < 0) { + wlr_log_errno(L_ERROR, "Stat failed"); } - state->dev = st.st_rdev; + drm->dev = st.st_rdev; - state->drm_invalidated.notify = drm_invalidated; - wlr_udev_signal_add(udev, state->dev, &state->drm_invalidated); + drm->drm_invalidated.notify = drm_invalidated; + wlr_udev_signal_add(udev, drm->dev, &drm->drm_invalidated); - state->display = display; + drm->display = display; struct wl_event_loop *event_loop = wl_display_get_event_loop(display); - state->drm_event = wl_event_loop_add_fd(event_loop, state->fd, + drm->drm_event = wl_event_loop_add_fd(event_loop, drm->fd, WL_EVENT_READABLE, wlr_drm_event, NULL); - if (!state->drm_event) { + if (!drm->drm_event) { wlr_log(L_ERROR, "Failed to create DRM event source"); goto error_fd; } - state->session_signal.notify = session_signal; - wl_signal_add(&session->session_signal, &state->session_signal); + drm->session_signal.notify = session_signal; + wl_signal_add(&session->session_signal, &drm->session_signal); - if (drmSetClientCap(state->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1)) { - wlr_log(L_INFO, "DRM universal planes unsupported"); - } - if (drmSetClientCap(state->fd, DRM_CLIENT_CAP_ATOMIC, 1)) { - wlr_log(L_INFO, "Atomic modesetting unsupported"); + if (!wlr_drm_check_features(drm)) { + goto error_event; } - wlr_drm_init_resources(state); + if (!wlr_drm_resources_init(drm)) { + goto error_event; + } - // TODO: what is the difference between the per-output renderer and this - // one? - if (!wlr_drm_renderer_init(&state->renderer, state->fd)) { + if (!wlr_drm_renderer_init(&drm->renderer, drm->fd)) { wlr_log(L_ERROR, "Failed to initialize renderer"); goto error_event; } @@ -150,12 +147,12 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display, return backend; error_event: - wl_event_source_remove(state->drm_event); + wl_event_source_remove(drm->drm_event); error_fd: - wlr_session_close_file(state->session, state->fd); - list_free(state->outputs); + wlr_session_close_file(drm->session, drm->fd); + list_free(drm->outputs); error_backend: - free(state); + free(drm); free(backend); return NULL; } diff --git a/backend/drm/drm.c b/backend/drm/drm.c index d617473c..d2a4f06b 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -18,6 +18,19 @@ #include "drm.h" #include "drm-util.h" +bool wlr_drm_check_features(struct wlr_backend_state *drm) { + if (drmSetClientCap(drm->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1)) { + wlr_log(L_INFO, "DRM universal planes unsupported"); + return false; + } + + if (drmSetClientCap(drm->fd, DRM_CLIENT_CAP_ATOMIC, 1)) { + wlr_log(L_INFO, "Atomic modesetting unsupported"); + } + + return true; +} + static int cmp_plane(const void *arg1, const void *arg2) { const struct wlr_drm_plane *a = arg1; @@ -112,7 +125,7 @@ error_res: return false; } -bool wlr_drm_init_resources(struct wlr_backend_state *drm) { +bool wlr_drm_resources_init(struct wlr_backend_state *drm) { drmModeRes *res = drmModeGetResources(drm->fd); if (!res) { wlr_log_errno(L_ERROR, "Failed to get DRM resources"); diff --git a/backend/drm/drm.h b/backend/drm/drm.h index 921ad78a..ed431680 100644 --- a/backend/drm/drm.h +++ b/backend/drm/drm.h @@ -151,7 +151,8 @@ struct wlr_output_state { bool cleanup; }; -bool wlr_drm_init_resources(struct wlr_backend_state *drm); +bool wlr_drm_check_features(struct wlr_backend_state *drm); +bool wlr_drm_resources_init(struct wlr_backend_state *drm); void wlr_drm_output_cleanup(struct wlr_output_state *output, bool restore); void wlr_drm_scan_connectors(struct wlr_backend_state *state); |