aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2024-02-27 11:45:42 +0100
committerSimon Ser <contact@emersion.fr>2024-02-27 11:46:19 +0100
commitd83c15c318e60c7136c5abb5eac55189144d7bbd (patch)
tree8e9d320444844426fb8f2c490ae63e828678988e
parent4b1713d20315f6756fe130853f05c4e62f63ab28 (diff)
backend/drm: use CRTC pointers instead of indices in realloc_crtcs()
Improves readability, no functional change.
-rw-r--r--backend/drm/drm.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index 4e2b3b84..9558b0b0 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -1271,23 +1271,19 @@ static void realloc_crtcs(struct wlr_drm_backend *drm,
drm->num_crtcs, previous_match, new_match);
// Converts our crtc=>connector result into a connector=>crtc one.
- ssize_t connector_match[num_connectors];
+ struct wlr_drm_crtc *connector_match[num_connectors];
for (size_t i = 0 ; i < num_connectors; ++i) {
- connector_match[i] = -1;
+ connector_match[i] = NULL;
}
for (size_t i = 0; i < drm->num_crtcs; ++i) {
if (new_match[i] != UNMATCHED) {
- connector_match[new_match[i]] = i;
+ connector_match[new_match[i]] = &drm->crtcs[i];
}
}
for (size_t i = 0; i < num_connectors; ++i) {
struct wlr_drm_connector *conn = connectors[i];
-
- struct wlr_drm_crtc *new_crtc = NULL;
- if (connector_match[i] >= 0) {
- new_crtc = &drm->crtcs[connector_match[i]];
- }
+ struct wlr_drm_crtc *new_crtc = connector_match[i];
char old_crtc_str[16], new_crtc_str[16];
format_nullable_crtc(old_crtc_str, sizeof(old_crtc_str), conn->crtc);
@@ -1313,13 +1309,13 @@ static void realloc_crtcs(struct wlr_drm_backend *drm,
if (conn->status != DRM_MODE_CONNECTED || !conn->output.enabled) {
continue;
}
- if (connector_match[i] == -1) {
+ if (connector_match[i] == NULL) {
wlr_log(WLR_DEBUG, "Could not match a CRTC for previously connected output; "
"keeping old configuration");
return;
}
assert(conn->crtc != NULL);
- if (connector_match[i] != conn->crtc - drm->crtcs) {
+ if (connector_match[i] != conn->crtc) {
wlr_log(WLR_DEBUG, "Cannot switch CRTC for enabled output; "
"keeping old configuration");
return;
@@ -1330,14 +1326,14 @@ static void realloc_crtcs(struct wlr_drm_backend *drm,
for (size_t i = 0; i < num_connectors; ++i) {
struct wlr_drm_connector *conn = connectors[i];
- if (conn->crtc != NULL && connector_match[i] == conn->crtc - drm->crtcs) {
+ if (conn->crtc != NULL && connector_match[i]) {
// We don't need to change anything
continue;
}
dealloc_crtc(conn);
- if (connector_match[i] >= 0) {
- conn->crtc = &drm->crtcs[connector_match[i]];
+ if (connector_match[i] != NULL) {
+ conn->crtc = connector_match[i];
}
}
}