aboutsummaryrefslogtreecommitdiff
path: root/backend/drm
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2024-02-14 18:54:01 +0100
committerSimon Ser <contact@emersion.fr>2024-02-14 19:13:23 +0100
commit505175e56f42700649158bfd4ad622860ceaa80b (patch)
treee05675bd0404a8e72d04deb5d4b8d363f74fd334 /backend/drm
parent836cb820d0b25135cc861782df2781bf2d177795 (diff)
backend/drm: atomically reset state after VT switch
Allows the KMS driver to parallelize the modesets, so should be faster than going through each CRTC one by one.
Diffstat (limited to 'backend/drm')
-rw-r--r--backend/drm/atomic.c46
-rw-r--r--backend/drm/backend.c11
-rw-r--r--backend/drm/legacy.c14
-rw-r--r--backend/drm/libliftoff.c1
4 files changed, 58 insertions, 14 deletions
diff --git a/backend/drm/atomic.c b/backend/drm/atomic.c
index dcad7d3d..6588bdc0 100644
--- a/backend/drm/atomic.c
+++ b/backend/drm/atomic.c
@@ -61,19 +61,26 @@ static void atomic_begin(struct atomic *atom) {
}
}
-static bool atomic_commit(struct atomic *atom,
+static bool atomic_commit(struct atomic *atom, struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, struct wlr_drm_page_flip *page_flip,
uint32_t flags) {
- struct wlr_drm_backend *drm = conn->backend;
if (atom->failed) {
return false;
}
int ret = drmModeAtomicCommit(drm->fd, atom->req, flags, page_flip);
if (ret != 0) {
- wlr_drm_conn_log_errno(conn,
- (flags & DRM_MODE_ATOMIC_TEST_ONLY) ? WLR_DEBUG : WLR_ERROR,
- "Atomic commit failed");
+ enum wlr_log_importance log_level = WLR_ERROR;
+ if (flags & DRM_MODE_ATOMIC_TEST_ONLY) {
+ log_level = WLR_DEBUG;
+ }
+
+ if (conn != NULL) {
+ wlr_drm_conn_log_errno(conn, log_level, "Atomic commit failed");
+ } else {
+ wlr_log_errno(log_level, "Atomic commit failed");
+ }
+
char *flags_str = atomic_commit_flags_str(flags);
wlr_log(WLR_DEBUG, "(Atomic commit flags: %s)",
flags_str ? flags_str : "<error>");
@@ -369,7 +376,7 @@ static bool atomic_crtc_commit(struct wlr_drm_connector *conn,
}
}
- bool ok = atomic_commit(&atom, conn, page_flip, flags);
+ bool ok = atomic_commit(&atom, drm, conn, page_flip, flags);
atomic_finish(&atom);
if (ok && !test_only) {
@@ -392,6 +399,33 @@ static bool atomic_crtc_commit(struct wlr_drm_connector *conn,
return ok;
}
+bool drm_atomic_reset(struct wlr_drm_backend *drm) {
+ struct atomic atom;
+ atomic_begin(&atom);
+
+ for (size_t i = 0; i < drm->num_crtcs; i++) {
+ struct wlr_drm_crtc *crtc = &drm->crtcs[i];
+ atomic_add(&atom, crtc->id, crtc->props.mode_id, 0);
+ atomic_add(&atom, crtc->id, crtc->props.active, 0);
+ }
+
+ struct wlr_drm_connector *conn;
+ wl_list_for_each(conn, &drm->connectors, link) {
+ atomic_add(&atom, conn->id, conn->props.crtc_id, 0);
+ }
+
+ for (size_t i = 0; i < drm->num_planes; i++) {
+ plane_disable(&atom, &drm->planes[i]);
+ }
+
+ uint32_t flags = DRM_MODE_ATOMIC_ALLOW_MODESET;
+ bool ok = atomic_commit(&atom, drm, NULL, NULL, flags);
+ atomic_finish(&atom);
+
+ return ok;
+}
+
const struct wlr_drm_interface atomic_iface = {
.crtc_commit = atomic_crtc_commit,
+ .reset = drm_atomic_reset,
};
diff --git a/backend/drm/backend.c b/backend/drm/backend.c
index 84ae3738..43bfd9da 100644
--- a/backend/drm/backend.c
+++ b/backend/drm/backend.c
@@ -131,14 +131,9 @@ static void handle_session_active(struct wl_listener *listener, void *data) {
// configurations. The connector/CRTC mapping may have changed, so
// first disable all CRTCs, then light up the ones we were using
// before the VT switch.
- // TODO: use the atomic API to improve restoration after a VT switch
- for (size_t i = 0; i < drm->num_crtcs; i++) {
- struct wlr_drm_crtc *crtc = &drm->crtcs[i];
-
- if (drmModeSetCrtc(drm->fd, crtc->id, 0, 0, 0, NULL, 0, NULL) != 0) {
- wlr_log_errno(WLR_ERROR, "Failed to disable CRTC %"PRIu32" after VT switch",
- crtc->id);
- }
+ // TODO: better use the atomic API to improve restoration after a VT switch
+ if (!drm->iface->reset(drm)) {
+ wlr_log(WLR_ERROR, "Failed to reset state after VT switch");
}
struct wlr_drm_connector *conn;
diff --git a/backend/drm/legacy.c b/backend/drm/legacy.c
index 1c9ff46d..1e62f61f 100644
--- a/backend/drm/legacy.c
+++ b/backend/drm/legacy.c
@@ -227,6 +227,20 @@ bool drm_legacy_crtc_set_gamma(struct wlr_drm_backend *drm,
return true;
}
+static bool legacy_reset(struct wlr_drm_backend *drm) {
+ bool ok = true;
+ for (size_t i = 0; i < drm->num_crtcs; i++) {
+ struct wlr_drm_crtc *crtc = &drm->crtcs[i];
+ if (drmModeSetCrtc(drm->fd, crtc->id, 0, 0, 0, NULL, 0, NULL) != 0) {
+ wlr_log_errno(WLR_ERROR, "Failed to disable CRTC %"PRIu32,
+ crtc->id);
+ ok = false;
+ }
+ }
+ return ok;
+}
+
const struct wlr_drm_interface legacy_iface = {
.crtc_commit = legacy_crtc_commit,
+ .reset = legacy_reset,
};
diff --git a/backend/drm/libliftoff.c b/backend/drm/libliftoff.c
index a39f2493..534e5ef2 100644
--- a/backend/drm/libliftoff.c
+++ b/backend/drm/libliftoff.c
@@ -506,4 +506,5 @@ const struct wlr_drm_interface liftoff_iface = {
.init = init,
.finish = finish,
.crtc_commit = crtc_commit,
+ .reset = drm_atomic_reset,
};