1From b19a3ce2e942bd534760a4316e4a26a5dc113f67 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Fri, 2 Apr 2021 11:23:36 +0800
4Subject: [PATCH 05/79] backend-drm: Bind Nth primary plane to Nth CRTC
5
6The vop2 allows primary planes to bind with random CRTC, but we need to
7use the same pair as the driver registered.
8
9Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
10---
11 libweston/backend-drm/drm.c | 18 +++++++++++++++++-
12 1 file changed, 17 insertions(+), 1 deletion(-)
13
14diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c
15index 4278770..e557d41 100644
16--- a/libweston/backend-drm/drm.c
17+++ b/libweston/backend-drm/drm.c
18@@ -842,10 +842,26 @@ drm_output_find_special_plane(struct drm_backend *b, struct drm_output *output,
19 			      enum wdrm_plane_type type)
20 {
21 	struct drm_plane *plane;
22+	int num_primary;
23
24-	wl_list_for_each(plane, &b->plane_list, link) {
25+	num_primary = 0;
26+	wl_list_for_each_reverse(plane, &b->plane_list, link) {
27 		struct drm_output *tmp;
28 		bool found_elsewhere = false;
29+		bool is_primary = plane->type == WDRM_PLANE_TYPE_PRIMARY;
30+
31+		if (is_primary)
32+			num_primary ++;
33+
34+		/**
35+		 * HACK: Assuming Nth primary plane (or cursor) is the primary
36+		 * plane for the Nth crtc.
37+		 * See:
38+		 * https://lore.kernel.org/dri-devel/20200807090706.GA2352366@phenom.ffwll.local/
39+		 */
40+		if (type == WDRM_PLANE_TYPE_PRIMARY &&
41+		    num_primary - 1 != output->crtc->pipe)
42+			continue;
43
44 		if (plane->type != type)
45 			continue;
46--
472.20.1
48
49