aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-05-18 10:34:24 +0200
committerDrew DeVault <sir@cmpwn.com>2020-05-26 20:01:38 +0200
commit47e52128237a5b4f1a2de228e8b1d54921b77e37 (patch)
tree1615356e76772e0df781cdde5c8c804303d297a9 /backend
parent0758a4fc9dac7a887517a40f31daaaf12540b7f5 (diff)
backend/drm: rollback atomic blobs
If the atomic commit fails or is test-only, rollback wlr_drm_crtc.{mode_id,gamma_lut} blob IDs to their previous value. This prevents the next commits from failing or applying test-only state.
Diffstat (limited to 'backend')
-rw-r--r--backend/drm/atomic.c49
1 files changed, 36 insertions, 13 deletions
diff --git a/backend/drm/atomic.c b/backend/drm/atomic.c
index 67dfce02..3c8f5e62 100644
--- a/backend/drm/atomic.c
+++ b/backend/drm/atomic.c
@@ -103,6 +103,27 @@ static bool create_gamma_lut_blob(struct wlr_drm_backend *drm,
return true;
}
+static void commit_blob(struct wlr_drm_backend *drm,
+ uint32_t *current, uint32_t next) {
+ if (*current == next) {
+ return;
+ }
+ if (*current != 0) {
+ drmModeDestroyPropertyBlob(drm->fd, *current);
+ }
+ *current = next;
+}
+
+static void rollback_blob(struct wlr_drm_backend *drm,
+ uint32_t *current, uint32_t next) {
+ if (*current == next) {
+ return;
+ }
+ if (next != 0) {
+ drmModeDestroyPropertyBlob(drm->fd, next);
+ }
+}
+
static void plane_disable(struct atomic *atom, struct wlr_drm_plane *plane) {
uint32_t id = plane->id;
const union wlr_drm_plane_props *props = &plane->props;
@@ -149,16 +170,14 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
struct wlr_output *output = &conn->output;
struct wlr_drm_crtc *crtc = conn->crtc;
+ uint32_t mode_id = crtc->mode_id;
if (crtc->pending & WLR_DRM_CRTC_MODE) {
- if (crtc->mode_id != 0) {
- drmModeDestroyPropertyBlob(drm->fd, crtc->mode_id);
- }
-
- if (!create_mode_blob(drm, crtc, &crtc->mode_id)) {
+ if (!create_mode_blob(drm, crtc, &mode_id)) {
return false;
}
}
+ uint32_t gamma_lut = crtc->gamma_lut;
if (output->pending.committed & WLR_OUTPUT_STATE_GAMMA_LUT) {
// Fallback to legacy gamma interface when gamma properties are not
// available (can happen on older Intel GPUs that support gamma but not
@@ -170,13 +189,8 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
return false;
}
} else {
- if (crtc->gamma_lut != 0) {
- drmModeDestroyPropertyBlob(drm->fd, crtc->gamma_lut);
- }
-
- wlr_log(WLR_ERROR, "setting gamma LUT %zu", output->pending.gamma_lut_size);
if (!create_gamma_lut_blob(drm, output->pending.gamma_lut_size,
- output->pending.gamma_lut, &crtc->gamma_lut)) {
+ output->pending.gamma_lut, &gamma_lut)) {
return false;
}
}
@@ -197,11 +211,11 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
atomic_add(&atom, conn->id, conn->props.link_status,
DRM_MODE_LINK_STATUS_GOOD);
}
- atomic_add(&atom, crtc->id, crtc->props.mode_id, crtc->mode_id);
+ atomic_add(&atom, crtc->id, crtc->props.mode_id, mode_id);
atomic_add(&atom, crtc->id, crtc->props.active, crtc->active);
if (crtc->active) {
if (crtc->props.gamma_lut != 0) {
- atomic_add(&atom, crtc->id, crtc->props.gamma_lut, crtc->gamma_lut);
+ atomic_add(&atom, crtc->id, crtc->props.gamma_lut, gamma_lut);
}
set_plane_props(&atom, drm, crtc->primary, crtc->id, 0, 0);
if (crtc->cursor) {
@@ -221,6 +235,15 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
bool ok = atomic_commit(&atom, conn, flags);
atomic_finish(&atom);
+
+ if (ok && !(flags & DRM_MODE_ATOMIC_TEST_ONLY)) {
+ commit_blob(drm, &crtc->mode_id, mode_id);
+ commit_blob(drm, &crtc->gamma_lut, gamma_lut);
+ } else {
+ rollback_blob(drm, &crtc->mode_id, mode_id);
+ rollback_blob(drm, &crtc->gamma_lut, gamma_lut);
+ }
+
return ok;
}