backend/drm: don't unset mode/CRTC when disabling output

Closes: https://github.com/swaywm/wlroots/issues/2203
This commit is contained in:
Simon Ser 2020-05-18 15:37:19 +02:00
parent dcae6f1431
commit bfd7625813
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
4 changed files with 36 additions and 37 deletions

View file

@ -56,7 +56,7 @@ 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, static bool create_mode_blob(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc, uint32_t *blob_id) { struct wlr_drm_crtc *crtc, uint32_t *blob_id) {
if (!crtc->pending.active) { if (crtc->pending.mode == NULL) {
*blob_id = 0; *blob_id = 0;
return true; return true;
} }
@ -170,6 +170,11 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
struct wlr_output *output = &conn->output; struct wlr_output *output = &conn->output;
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
uint32_t active = output->enabled;
if (output->pending.committed & WLR_OUTPUT_STATE_ENABLED) {
active = output->pending.enabled;
}
uint32_t mode_id = crtc->mode_id; uint32_t mode_id = crtc->mode_id;
if (crtc->pending_modeset) { if (crtc->pending_modeset) {
if (!create_mode_blob(drm, crtc, &mode_id)) { if (!create_mode_blob(drm, crtc, &mode_id)) {
@ -213,15 +218,14 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
struct atomic atom; struct atomic atom;
atomic_begin(&atom); atomic_begin(&atom);
atomic_add(&atom, conn->id, conn->props.crtc_id, atomic_add(&atom, conn->id, conn->props.crtc_id,
crtc->pending.active ? crtc->id : 0); mode_id != 0 ? crtc->id : 0);
if (crtc->pending_modeset && crtc->pending.active && if (crtc->pending_modeset && active && conn->props.link_status != 0) {
conn->props.link_status != 0) {
atomic_add(&atom, conn->id, conn->props.link_status, atomic_add(&atom, conn->id, conn->props.link_status,
DRM_MODE_LINK_STATUS_GOOD); DRM_MODE_LINK_STATUS_GOOD);
} }
atomic_add(&atom, crtc->id, crtc->props.mode_id, mode_id); atomic_add(&atom, crtc->id, crtc->props.mode_id, mode_id);
atomic_add(&atom, crtc->id, crtc->props.active, crtc->pending.active); atomic_add(&atom, crtc->id, crtc->props.active, active);
if (crtc->pending.active) { if (mode_id != 0) {
if (crtc->props.gamma_lut != 0) { if (crtc->props.gamma_lut != 0) {
atomic_add(&atom, crtc->id, crtc->props.gamma_lut, gamma_lut); atomic_add(&atom, crtc->id, crtc->props.gamma_lut, gamma_lut);
} }

View file

@ -366,7 +366,6 @@ static bool drm_crtc_page_flip(struct wlr_drm_connector *conn) {
return false; return false;
} }
assert(crtc->pending.active);
assert(plane_get_next_fb(crtc->primary)->type != WLR_DRM_FB_TYPE_NONE); assert(plane_get_next_fb(crtc->primary)->type != WLR_DRM_FB_TYPE_NONE);
if (!drm_crtc_commit(conn, DRM_MODE_PAGE_FLIP_EVENT)) { if (!drm_crtc_commit(conn, DRM_MODE_PAGE_FLIP_EVENT)) {
return false; return false;
@ -547,22 +546,13 @@ static bool drm_connector_commit(struct wlr_output *output) {
return false; return false;
} }
if (output->pending.committed & if (output->pending.committed & WLR_OUTPUT_STATE_MODE) {
(WLR_OUTPUT_STATE_MODE | WLR_OUTPUT_STATE_ENABLED)) { assert((output->pending.committed & WLR_OUTPUT_STATE_ENABLED) ?
struct wlr_output_mode *wlr_mode = output->current_mode; output->pending.enabled : output->enabled);
bool enable = (output->pending.committed & WLR_OUTPUT_STATE_ENABLED) ? struct wlr_output_mode *wlr_mode = drm_connector_get_pending_mode(conn);
output->pending.enabled : output->enabled; if (wlr_mode == NULL) {
if (!enable) { return false;
wlr_mode = NULL;
}
if (output->pending.committed & WLR_OUTPUT_STATE_MODE) {
assert(enable);
wlr_mode = drm_connector_get_pending_mode(conn);
if (wlr_mode == NULL) {
return false;
}
} }
if (!drm_connector_set_mode(conn, wlr_mode)) { if (!drm_connector_set_mode(conn, wlr_mode)) {
@ -574,7 +564,8 @@ static bool drm_connector_commit(struct wlr_output *output) {
return false; return false;
} }
} else if (output->pending.committed & } else if (output->pending.committed &
(WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED | (WLR_OUTPUT_STATE_ENABLE |
WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED |
WLR_OUTPUT_STATE_GAMMA_LUT)) { WLR_OUTPUT_STATE_GAMMA_LUT)) {
assert(conn->crtc != NULL); assert(conn->crtc != NULL);
// TODO: maybe request a page-flip event here? // TODO: maybe request a page-flip event here?
@ -694,7 +685,6 @@ static bool drm_connector_init_renderer(struct wlr_drm_connector *conn,
struct wlr_drm_plane *plane = crtc->primary; struct wlr_drm_plane *plane = crtc->primary;
crtc->pending_modeset = true; crtc->pending_modeset = true;
crtc->pending.active = true;
crtc->pending.mode = mode; crtc->pending.mode = mode;
int width = mode->wlr_mode.width; int width = mode->wlr_mode.width;
@ -725,7 +715,6 @@ static bool drm_connector_init_renderer(struct wlr_drm_connector *conn,
modifiers = false; modifiers = false;
crtc->pending_modeset = true; crtc->pending_modeset = true;
crtc->pending.active = true;
crtc->pending.mode = mode; crtc->pending.mode = mode;
if (!drm_plane_init_surface(plane, drm, width, height, format, if (!drm_plane_init_surface(plane, drm, width, height, format,
@ -773,7 +762,7 @@ bool drm_connector_set_mode(struct wlr_drm_connector *conn,
if (wlr_mode == NULL) { if (wlr_mode == NULL) {
if (conn->crtc != NULL) { if (conn->crtc != NULL) {
conn->crtc->pending_modeset = true; conn->crtc->pending_modeset = true;
conn->crtc->pending.active = false; conn->crtc->pending.mode = NULL;
if (!drm_crtc_commit(conn, 0)) { if (!drm_crtc_commit(conn, 0)) {
return false; return false;
} }

View file

@ -14,8 +14,24 @@ static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
struct wlr_drm_plane *cursor = crtc->cursor; struct wlr_drm_plane *cursor = crtc->cursor;
bool enabled = output->enabled;
if (output->pending.committed & WLR_OUTPUT_STATE_ENABLED) {
enabled = output->pending.enabled;
}
if (output->pending.committed & WLR_OUTPUT_STATE_ENABLED) {
uint32_t dpms = output->pending.enabled ?
DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF;
if (drmModeConnectorSetProperty(drm->fd, conn->id, conn->props.dpms,
dpms) != 0) {
wlr_log_errno(WLR_ERROR, "%s: failed to set DPMS property",
conn->output.name);
return false;
}
}
uint32_t fb_id = 0; uint32_t fb_id = 0;
if (crtc->pending.active) { if (enabled) {
struct wlr_drm_fb *fb = plane_get_next_fb(crtc->primary); struct wlr_drm_fb *fb = plane_get_next_fb(crtc->primary);
struct gbm_bo *bo = drm_fb_acquire(fb, drm, &crtc->primary->mgpu_surf); struct gbm_bo *bo = drm_fb_acquire(fb, drm, &crtc->primary->mgpu_surf);
if (!bo) { if (!bo) {
@ -38,15 +54,6 @@ static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
mode = &crtc->pending.mode->drm_mode; mode = &crtc->pending.mode->drm_mode;
} }
uint32_t dpms = crtc->pending.active ?
DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF;
if (drmModeConnectorSetProperty(drm->fd, conn->id, conn->props.dpms,
dpms) != 0) {
wlr_log_errno(WLR_ERROR, "%s: failed to set DPMS property",
conn->output.name);
return false;
}
if (drmModeSetCrtc(drm->fd, crtc->id, fb_id, 0, 0, if (drmModeSetCrtc(drm->fd, crtc->id, fb_id, 0, 0,
conns, conns_len, mode)) { conns, conns_len, mode)) {
wlr_log_errno(WLR_ERROR, "%s: failed to set CRTC", wlr_log_errno(WLR_ERROR, "%s: failed to set CRTC",

View file

@ -43,7 +43,6 @@ struct wlr_drm_plane {
}; };
struct wlr_drm_crtc_state { struct wlr_drm_crtc_state {
bool active;
struct wlr_drm_mode *mode; struct wlr_drm_mode *mode;
}; };