backend/drm: introduce pending and current CRTC state

Previously, we only had the pending state (crtc->pending, crtc->mode and
crtc->active). This causes issues when a commit fails: the pending state
is left as-is, and the next commit may read stale data from it.

This will also cause issues when implementing test-only commits: we need
to rollback the pending CRTC state after a test-only commit.

Introduce separate pending and current CRTC states. Properly update the
current state after a commit.
This commit is contained in:
Simon Ser 2020-05-18 14:27:42 +02:00 committed by Drew DeVault
parent d6cc718472
commit 15d8f1806e
4 changed files with 37 additions and 26 deletions

View file

@ -56,12 +56,12 @@ static void atomic_add(struct atomic *atom, uint32_t id, uint32_t prop, uint64_t
static bool create_mode_blob(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc, uint32_t *blob_id) {
if (!crtc->active) {
if (!crtc->pending.active) {
*blob_id = 0;
return true;
}
if (drmModeCreatePropertyBlob(drm->fd, &crtc->mode,
if (drmModeCreatePropertyBlob(drm->fd, &crtc->pending.mode->drm_mode,
sizeof(drmModeModeInfo), blob_id)) {
wlr_log_errno(WLR_ERROR, "Unable to create mode property blob");
return false;
@ -171,7 +171,7 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc = conn->crtc;
uint32_t mode_id = crtc->mode_id;
if (crtc->pending & WLR_DRM_CRTC_MODE) {
if (crtc->pending_modeset) {
if (!create_mode_blob(drm, crtc, &mode_id)) {
return false;
}
@ -196,8 +196,7 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
}
}
bool modeset = crtc->pending & WLR_DRM_CRTC_MODE;
if (modeset) {
if (crtc->pending_modeset) {
flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
} else {
flags |= DRM_MODE_ATOMIC_NONBLOCK;
@ -206,14 +205,15 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
struct atomic atom;
atomic_begin(&atom);
atomic_add(&atom, conn->id, conn->props.crtc_id,
crtc->active ? crtc->id : 0);
if (modeset && crtc->active && conn->props.link_status != 0) {
crtc->pending.active ? crtc->id : 0);
if (crtc->pending_modeset && crtc->pending.active &&
conn->props.link_status != 0) {
atomic_add(&atom, conn->id, conn->props.link_status,
DRM_MODE_LINK_STATUS_GOOD);
}
atomic_add(&atom, crtc->id, crtc->props.mode_id, mode_id);
atomic_add(&atom, crtc->id, crtc->props.active, crtc->active);
if (crtc->active) {
atomic_add(&atom, crtc->id, crtc->props.active, crtc->pending.active);
if (crtc->pending.active) {
if (crtc->props.gamma_lut != 0) {
atomic_add(&atom, crtc->id, crtc->props.gamma_lut, gamma_lut);
}