compositor-drm: Remove crtc_allocator

crtc_allocator was used as a bitmask of CRTC IDs, so we didn't try to
use the same CRTC for multiple outputs. Unfortunately, this only works
to the extent that CRTC object IDs fit within the bitmask; though they
were previously, they are not guaranteed to be under 32 or even 64.

Replace the only use of crtc_allocator with a list walk across outputs.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Reported-by: Peter Senna Tschudin <peter.senna@collabora.com>
diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index 7f1eeda..5f1ca95 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -94,7 +94,6 @@
 		char *filename;
 	} drm;
 	struct gbm_device *gbm;
-	uint32_t crtc_allocator;
 	uint32_t connector_allocator;
 	struct wl_listener session_listener;
 	uint32_t gbm_format;
@@ -239,6 +238,25 @@
 	return !!(sprite->possible_crtcs & (1 << output->pipe));
 }
 
+static struct drm_output *
+drm_output_find_by_crtc(struct drm_backend *b, uint32_t crtc_id)
+{
+	struct drm_output *output;
+
+	wl_list_for_each(output, &b->compositor->output_list, base.link) {
+		if (output->crtc_id == crtc_id)
+			return output;
+	}
+
+	wl_list_for_each(output, &b->compositor->pending_output_list,
+			 base.link) {
+		if (output->crtc_id == crtc_id)
+			return output;
+	}
+
+	return NULL;
+}
+
 static void
 drm_fb_destroy_callback(struct gbm_bo *bo, void *data)
 {
@@ -1819,9 +1837,13 @@
 		drmModeFreeEncoder(encoder);
 
 		for (i = 0; i < resources->count_crtcs; i++) {
-			if (possible_crtcs & (1 << i) &&
-			    !(b->crtc_allocator & (1 << resources->crtcs[i])))
-				return i;
+			if (!(possible_crtcs & (1 << i)))
+				continue;
+
+			if (drm_output_find_by_crtc(b, resources->crtcs[i]))
+				continue;
+
+			return i;
 		}
 	}
 
@@ -2507,7 +2529,6 @@
 	if (output->backlight)
 		backlight_destroy(output->backlight);
 
-	b->crtc_allocator &= ~(1 << output->crtc_id);
 	b->connector_allocator &= ~(1 << output->connector_id);
 
 	free(output);
@@ -2585,7 +2606,6 @@
 	output->disable_pending = 0;
 	output->original_crtc = NULL;
 
-	b->crtc_allocator |= (1 << output->crtc_id);
 	b->connector_allocator |= (1 << output->connector_id);
 
 	weston_output_init(&output->base, b->compositor);