[PATCH weston v6 67/73] compositor-drm: preserve CRTC routing harder

Pekka Paalanen ppaalanen at gmail.com
Fri Feb 16 14:57:52 UTC 2018


From: Pekka Paalanen <pekka.paalanen at 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.paalanen at 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



More information about the wayland-devel mailing list