From: Pekka Paalanen <pekka.paala...@collabora.co.uk>

If we are processing a connector that does not have an existing routing,
it is possible we pick a CRTC that was previously routed to a connector
we have not enabled yet. If that happens, the latter connector cannot
preserve its routing.

Check that no other connector we might enable later had this CRTC
before.

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
---
 libweston/compositor-drm.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index f1270390..82f014d7 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -4804,7 +4804,9 @@ drm_output_pick_crtc(struct drm_output *output, 
drmModeRes *resources)
        unsigned j, n = 0;
        uint32_t crtc_id;
        int best_crtc_index = -1;
+       int fallback_crtc_index = -1;
        int i;
+       bool match;
 
        backend = to_drm_backend(output->base.compositor);
 
@@ -4845,12 +4847,37 @@ drm_output_pick_crtc(struct drm_output *output, 
drmModeRes *resources)
                                return i;
                }
 
-               best_crtc_index = i;
+               /* Check if any other head had existing routing to this CRTC.
+                * If they did, this is not the best CRTC as it might be needed
+                * for another output we haven't enabled yet. */
+               match = false;
+               wl_list_for_each(base, &backend->compositor->head_list,
+                                compositor_link) {
+                       head = to_drm_head(base);
+
+                       if (head->base.output == &output->base)
+                               continue;
+
+                       if (weston_head_is_enabled(&head->base))
+                               continue;
+
+                       if (head->inherited_crtc_id == crtc_id) {
+                               match = true;
+                               break;
+                       }
+               }
+               if (!match)
+                       best_crtc_index = i;
+
+               fallback_crtc_index = i;
        }
 
        if (best_crtc_index != -1)
                return best_crtc_index;
 
+       if (fallback_crtc_index != -1)
+               return fallback_crtc_index;
+
        /* Likely possible_crtcs was empty due to asking for clones,
         * but since the DRM documentation says the kernel lies, let's
         * pick one crtc anyway. Trial and error is the only way to
-- 
2.13.6

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to