From db4c7d7237ac297cfdd22b9a1d856d9999399ff2 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Tue, 28 Nov 2017 16:11:00 +0200 Subject: [PATCH] compositor-drm: preserve CRTC routing harder 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 Acked-by: Derek Foreman Reviewed-by: Daniel Stone --- 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 d983e1c..851446b 100644 --- a/libweston/compositor-drm.c +++ b/libweston/compositor-drm.c @@ -4788,7 +4788,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); @@ -4829,12 +4831,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.7.4