1From 5e62ced887937b5ed0e5c861e6c98db322e2cbd4 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 06/93] 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-internal.h | 2 ++ 12 libweston/backend-drm/drm.c | 25 +++++++++++++++++++++++-- 13 2 files changed, 25 insertions(+), 2 deletions(-) 14 15diff --git a/libweston/backend-drm/drm-internal.h b/libweston/backend-drm/drm-internal.h 16index 1ee1974..f4b8ed8 100644 17--- a/libweston/backend-drm/drm-internal.h 18+++ b/libweston/backend-drm/drm-internal.h 19@@ -532,6 +532,8 @@ struct drm_crtc { 20 uint32_t crtc_id; /* object ID to pass to DRM functions */ 21 int pipe; /* index of CRTC in resource array / bitmasks */ 22 23+ uint32_t primary_plane_id; 24+ 25 /* Holds the properties for the CRTC */ 26 struct drm_property_info props_crtc[WDRM_CRTC__COUNT]; 27 }; 28diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c 29index 7d607ca..8969a76 100644 30--- a/libweston/backend-drm/drm.c 31+++ b/libweston/backend-drm/drm.c 32@@ -184,6 +184,11 @@ drm_plane_is_available(struct drm_plane *plane, struct drm_output *output) 33 if (plane->state_cur->output && plane->state_cur->output != output) 34 return false; 35 36+ /* The plane is not the primary plane for this CRTC. */ 37+ if (plane->type == WDRM_PLANE_TYPE_PRIMARY && 38+ plane->plane_id != output->crtc->primary_plane_id) 39+ return false; 40+ 41 /* Check whether the plane can be used with this CRTC; possible_crtcs 42 * is a bitmask of CRTC indices (pipe), rather than CRTC object ID. */ 43 return !!(plane->possible_crtcs & (1 << output->crtc->pipe)); 44@@ -942,14 +947,16 @@ drm_plane_destroy(struct drm_plane *plane) 45 * @param device DRM device 46 */ 47 static void 48-create_sprites(struct drm_device *device) 49+create_sprites(struct drm_device *device, drmModeRes *resources) 50 { 51 struct drm_backend *b = device->backend; 52 drmModePlaneRes *kplane_res; 53 drmModePlane *kplane; 54 struct drm_plane *drm_plane; 55+ struct drm_crtc *drm_crtc; 56 uint32_t i; 57 uint32_t next_plane_idx = 0; 58+ int crtc_pipe = -1; 59 kplane_res = drmModeGetPlaneResources(device->drm.fd); 60 61 if (!kplane_res) { 62@@ -968,6 +975,20 @@ create_sprites(struct drm_device *device) 63 if (!drm_plane) 64 continue; 65 66+ /** 67+ * HACK: Assuming Nth primary plane (or cursor) is the primary 68+ * plane for the Nth crtc. 69+ * See: 70+ * https://lore.kernel.org/dri-devel/20200807090706.GA2352366@phenom.ffwll.local/ 71+ */ 72+ if (drm_plane->type == WDRM_PLANE_TYPE_PRIMARY) { 73+ crtc_pipe ++; 74+ drm_crtc = drm_crtc_find(device, 75+ resources->crtcs[crtc_pipe]); 76+ assert(drm_crtc); 77+ drm_crtc->primary_plane_id = kplane->plane_id; 78+ } 79+ 80 if (drm_plane->type == WDRM_PLANE_TYPE_OVERLAY) 81 weston_compositor_stack_plane(b->compositor, 82 &drm_plane->base, 83@@ -3208,7 +3229,7 @@ drm_backend_create(struct weston_compositor *compositor, 84 } 85 86 wl_list_init(&device->plane_list); 87- create_sprites(b->drm); 88+ create_sprites(b->drm, res); 89 90 if (udev_input_init(&b->input, 91 compositor, b->udev, seat_id, 92-- 932.20.1 94 95