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