compositor-drm: Try to preserve existing output routing
authorDaniel Stone <daniels@collabora.com>
Mon, 16 Jan 2017 14:33:38 +0000 (14:33 +0000)
committerDaniel Stone <daniels@collabora.com>
Mon, 27 Feb 2017 21:38:51 +0000 (21:38 +0000)
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@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
libweston/compositor-drm.c

index a2a07cf..f94b9a4 100644 (file)
@@ -1821,16 +1821,20 @@ 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++) {
@@ -1840,11 +1844,21 @@ find_crtc_for_connector(struct drm_backend *b,
                        if (drm_output_find_by_crtc(b, resources->crtcs[i]))
                                continue;
 
-                       return i;
+                       /* 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 */