[PATCH weston] compositor-drm: Try to preserve existing output routing

Daniel Stone daniels at collabora.com
Mon Jan 16 14:40:44 UTC 2017


Previously in picking CRTC -> encoder -> connecting routing, we went for
the first triplet we found which claimed to work.

Preserving the existing routing means that startup will be faster: on a
multi-head system, changing the routing implies disabling both CRTCs,
then re-enabling them with a new configuration, which may involve
retraining links etc.

Furthermore, the existing routing may be set for a reason; each
CRTC/encoder is not necessarily as capable as the other, so the routing
may be configured to stay within such device limits.

Try where possible to respect the routing we pick up, rather than
blithely configuring our own.

Signed-off-by: Daniel Stone <daniels at collabora.com>
---
 libweston/compositor-drm.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index ecc872e..030f82f 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -1794,26 +1794,43 @@ find_crtc_for_connector(struct drm_backend *b,
 			drmModeRes *resources, drmModeConnector *connector)
 {
 	drmModeEncoder *encoder;
-	uint32_t possible_crtcs;
 	int i, j;
+	int ret = -1;
 
 	for (j = 0; j < connector->count_encoders; j++) {
+		uint32_t possible_crtcs, encoder_id, crtc_id;
+
 		encoder = drmModeGetEncoder(b->drm.fd, connector->encoders[j]);
 		if (encoder == NULL) {
 			weston_log("Failed to get encoder.\n");
-			return -1;
+			continue;
 		}
+		encoder_id = encoder->encoder_id;
 		possible_crtcs = encoder->possible_crtcs;
+		crtc_id = encoder->crtc_id;
 		drmModeFreeEncoder(encoder);
 
 		for (i = 0; i < resources->count_crtcs; i++) {
-			if (possible_crtcs & (1 << i) &&
-			    !(b->crtc_allocator & (1 << resources->crtcs[i])))
+			if (!(possible_crtcs & (1 << i)))
+				continue;
+			if (b->crtc_allocator & (1 << resources->crtcs[i]))
+				continue;
+
+			/* Try to preserve the existing
+			 * CRTC -> encoder -> connector routing; it makes
+			 * initialisation faster, and also since we have a
+			 * very dumb picking algorithm, may preserve a better
+			 * choice. */
+			if (!connector->encoder_id ||
+			    (encoder_id == connector->encoder_id &&
+			     crtc_id == resources->crtcs[i]))
 				return i;
+
+			ret = i;
 		}
 	}
 
-	return -1;
+	return ret;
 }
 
 /* Init output state that depends on gl or gbm */
-- 
2.9.3



More information about the wayland-devel mailing list