backend/drm: introduce wlr_drm_connector.name

The DRM backend is a little special when it comes to wlr_outputs: the
wlr_drm_connectors are long-lived and are created even when no screen is
connected.

A wlr_drm_connector only advertises a wlr_output to the compositor when
a screen is connected. As such, most of wlr_output's state is invalid
when the connector is disconnected.

We want to stop using wlr_output state on disconnected connectors.
Introduce wlr_drm_connector.name which is always valid regardless of the
connector status to avoid reading wlr_output.name when disconnected.
This commit is contained in:
Simon Ser 2020-12-09 15:11:06 +01:00
parent c89b131f29
commit 019ffe8a5b
3 changed files with 13 additions and 13 deletions

View file

@ -33,7 +33,7 @@ static bool atomic_commit(struct atomic *atom,
int ret = drmModeAtomicCommit(drm->fd, atom->req, flags, drm);
if (ret) {
wlr_log_errno(WLR_ERROR, "%s: Atomic %s failed (%s)",
conn->output.name,
conn->name,
(flags & DRM_MODE_ATOMIC_TEST_ONLY) ? "test" : "commit",
(flags & DRM_MODE_ATOMIC_ALLOW_MODESET) ? "modeset" : "pageflip");
return false;

View file

@ -1087,8 +1087,7 @@ static void realloc_crtcs(struct wlr_drm_backend *drm) {
connectors[i] = conn;
wlr_log(WLR_DEBUG, " '%s' crtc=%d state=%d desired_enabled=%d",
conn->output.name,
conn->crtc ? (int)(conn->crtc - drm->crtcs) : -1,
conn->name, conn->crtc ? (int)(conn->crtc - drm->crtcs) : -1,
conn->state, conn->desired_enabled);
if (conn->crtc) {
@ -1146,9 +1145,7 @@ static void realloc_crtcs(struct wlr_drm_backend *drm) {
bool prev_enabled = conn->crtc;
wlr_log(WLR_DEBUG, " '%s' crtc=%zd state=%d desired_enabled=%d",
conn->output.name,
connector_match[i],
conn->state, conn->desired_enabled);
conn->name, connector_match[i], conn->state, conn->desired_enabled);
// We don't need to change anything.
if (prev_enabled && connector_match[i] == conn->crtc - drm->crtcs) {
@ -1265,7 +1262,7 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
wlr_conn->state = WLR_DRM_CONN_DISCONNECTED;
wlr_conn->id = drm_conn->connector_id;
snprintf(wlr_conn->output.name, sizeof(wlr_conn->output.name),
snprintf(wlr_conn->name, sizeof(wlr_conn->name),
"%s-%"PRIu32, conn_get_name(drm_conn->connector_type),
drm_conn->connector_type_id);
@ -1274,7 +1271,7 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
}
wl_list_insert(drm->outputs.prev, &wlr_conn->link);
wlr_log(WLR_INFO, "Found connector '%s'", wlr_conn->output.name);
wlr_log(WLR_INFO, "Found connector '%s'", wlr_conn->name);
} else {
seen[index] = true;
}
@ -1310,10 +1307,13 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
if (wlr_conn->state == WLR_DRM_CONN_DISCONNECTED &&
drm_conn->connection == DRM_MODE_CONNECTED) {
wlr_log(WLR_INFO, "'%s' connected", wlr_conn->output.name);
wlr_log(WLR_INFO, "'%s' connected", wlr_conn->name);
wlr_log(WLR_DEBUG, "Current CRTC: %d",
wlr_conn->crtc ? (int)wlr_conn->crtc->id : -1);
strncpy(wlr_conn->output.name, wlr_conn->name,
sizeof(wlr_conn->output.name) - 1);
wlr_conn->output.phys_width = drm_conn->mmWidth;
wlr_conn->output.phys_height = drm_conn->mmHeight;
wlr_log(WLR_INFO, "Physical size: %"PRId32"x%"PRId32,
@ -1379,7 +1379,7 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
} else if ((wlr_conn->state == WLR_DRM_CONN_CONNECTED ||
wlr_conn->state == WLR_DRM_CONN_NEEDS_MODESET) &&
drm_conn->connection != DRM_MODE_CONNECTED) {
wlr_log(WLR_INFO, "'%s' disconnected", wlr_conn->output.name);
wlr_log(WLR_INFO, "'%s' disconnected", wlr_conn->name);
drm_connector_cleanup(wlr_conn);
}
@ -1400,7 +1400,7 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
continue;
}
wlr_log(WLR_INFO, "'%s' disappeared", conn->output.name);
wlr_log(WLR_INFO, "'%s' disappeared", conn->name);
drm_connector_cleanup(conn);
wlr_output_destroy(&conn->output);

View file

@ -157,8 +157,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);
#define wlr_drm_conn_log(conn, verb, fmt, ...) \
wlr_log(verb, "connector %s: " fmt, conn->output.name, ##__VA_ARGS__)
wlr_log(verb, "connector %s: " fmt, conn->name, ##__VA_ARGS__)
#define wlr_drm_conn_log_errno(conn, verb, fmt, ...) \
wlr_log_errno(verb, "connector %s: " fmt, conn->output.name, ##__VA_ARGS__)
wlr_log_errno(verb, "connector %s: " fmt, conn->name, ##__VA_ARGS__)
#endif