[PATCH weston v9 2/9] compositor-drm: preserve CRTC routing harder

Pekka Paalanen ppaalanen at gmail.com
Thu Apr 19 12:09:12 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>
Acked-by: Derek Foreman <derekf at osg.samsung.com>
---
 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 0f6cfb16..43f5c8e0 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -4786,7 +4786,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);
 
@@ -4827,12 +4829,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.16.1



More information about the wayland-devel mailing list