backend/drm: remove wlr_drm_crtc_state.active

Replace it with drm_connector_state_active, which figures out
whether the connector is active depending on the wlr_output_state
to be applied.
This commit is contained in:
Simon Ser 2021-04-06 17:14:17 +02:00 committed by Kenny Levinsen
parent 485ecc11a6
commit dfea0ff31d
4 changed files with 26 additions and 20 deletions

View file

@ -55,13 +55,14 @@ 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->pending.active) {
struct wlr_drm_connector *conn, const struct wlr_output_state *state,
uint32_t *blob_id) {
if (!drm_connector_state_active(conn, state)) {
*blob_id = 0;
return true;
}
if (drmModeCreatePropertyBlob(drm->fd, &crtc->pending.mode->drm_mode,
if (drmModeCreatePropertyBlob(drm->fd, &conn->crtc->pending.mode->drm_mode,
sizeof(drmModeModeInfo), blob_id)) {
wlr_log_errno(WLR_ERROR, "Unable to create mode property blob");
return false;
@ -170,10 +171,11 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc = conn->crtc;
bool modeset = drm_connector_state_is_modeset(state);
bool active = drm_connector_state_active(conn, state);
uint32_t mode_id = crtc->mode_id;
if (modeset) {
if (!create_mode_blob(drm, crtc, &mode_id)) {
if (!create_mode_blob(drm, conn, state, &mode_id)) {
return false;
}
}
@ -213,16 +215,14 @@ 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->pending.active ? crtc->id : 0);
if (modeset && crtc->pending.active &&
conn->props.link_status != 0) {
atomic_add(&atom, conn->id, conn->props.crtc_id, active ? crtc->id : 0);
if (modeset && 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->pending.active);
if (crtc->pending.active) {
atomic_add(&atom, crtc->id, crtc->props.active, active);
if (active) {
if (crtc->props.gamma_lut != 0) {
atomic_add(&atom, crtc->id, crtc->props.gamma_lut, gamma_lut);
}

View file

@ -363,7 +363,7 @@ static bool drm_crtc_page_flip(struct wlr_drm_connector *conn,
return false;
}
assert(crtc->pending.active);
assert(drm_connector_state_active(conn, state));
assert(plane_get_next_fb(crtc->primary));
if (!drm_crtc_commit(conn, state, DRM_MODE_PAGE_FLIP_EVENT)) {
return false;
@ -680,7 +680,6 @@ static bool drm_connector_init_renderer(struct wlr_drm_connector *conn,
}
struct wlr_drm_plane *plane = crtc->primary;
crtc->pending.active = true;
crtc->pending.mode = mode;
int width = mode->wlr_mode.width;
@ -703,7 +702,6 @@ static bool drm_connector_init_renderer(struct wlr_drm_connector *conn,
"retrying without modifiers");
modifiers = false;
crtc->pending.active = true;
crtc->pending.mode = mode;
if (!drm_plane_init_surface(plane, drm, width, height, format,
@ -752,7 +750,6 @@ bool drm_connector_set_mode(struct wlr_drm_connector *conn,
if (wlr_mode == NULL) {
if (conn->crtc != NULL) {
conn->crtc->pending.active = false;
if (!drm_crtc_commit(conn, state, 0)) {
return false;
}
@ -1042,6 +1039,14 @@ bool drm_connector_state_is_modeset(const struct wlr_output_state *state) {
(WLR_OUTPUT_STATE_ENABLED | WLR_OUTPUT_STATE_MODE);
}
bool drm_connector_state_active(struct wlr_drm_connector *conn,
const struct wlr_output_state *state) {
if (state->committed & WLR_OUTPUT_STATE_ENABLED) {
return state->enabled;
}
return conn->output.enabled;
}
static const int32_t subpixel_map[] = {
[DRM_MODE_SUBPIXEL_UNKNOWN] = WL_OUTPUT_SUBPIXEL_UNKNOWN,
[DRM_MODE_SUBPIXEL_HORIZONTAL_RGB] = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB,
@ -1060,7 +1065,6 @@ static void dealloc_crtc(struct wlr_drm_connector *conn) {
wlr_drm_conn_log(conn, WLR_DEBUG, "De-allocating CRTC %zu",
conn->crtc - drm->crtcs);
conn->crtc->pending.active = false;
struct wlr_output_state state = {
.committed = WLR_OUTPUT_STATE_ENABLED,
.enabled = false,

View file

@ -15,8 +15,10 @@ static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc = conn->crtc;
struct wlr_drm_plane *cursor = crtc->cursor;
bool active = drm_connector_state_active(conn, state);
uint32_t fb_id = 0;
if (crtc->pending.active) {
if (active) {
struct wlr_drm_fb *fb = plane_get_next_fb(crtc->primary);
if (fb == NULL) {
wlr_log(WLR_ERROR, "%s: failed to acquire primary FB",
@ -30,14 +32,13 @@ static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
uint32_t *conns = NULL;
size_t conns_len = 0;
drmModeModeInfo *mode = NULL;
if (crtc->pending.active) {
if (active) {
conns = &conn->id;
conns_len = 1;
mode = &crtc->pending.mode->drm_mode;
}
uint32_t dpms = crtc->pending.active ?
DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF;
uint32_t dpms = active ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF;
if (drmModeConnectorSetProperty(drm->fd, conn->id, conn->props.dpms,
dpms) != 0) {
wlr_drm_conn_log_errno(conn, WLR_ERROR,

View file

@ -42,7 +42,6 @@ struct wlr_drm_plane {
};
struct wlr_drm_crtc_state {
bool active;
struct wlr_drm_mode *mode;
};
@ -160,6 +159,8 @@ size_t drm_crtc_get_gamma_lut_size(struct wlr_drm_backend *drm,
struct wlr_drm_fb *plane_get_next_fb(struct wlr_drm_plane *plane);
bool drm_connector_state_is_modeset(const struct wlr_output_state *state);
bool drm_connector_state_active(struct wlr_drm_connector *conn,
const struct wlr_output_state *state);
#define wlr_drm_conn_log(conn, verb, fmt, ...) \
wlr_log(verb, "connector %s: " fmt, conn->name, ##__VA_ARGS__)