From a7bfecd541d2267e171701ffe7b6d7f890129010 Mon Sep 17 00:00:00 2001 From: Chao Guo Date: Fri, 1 Mar 2024 13:51:46 +0900 Subject: [PATCH] backend-drm: Add some underlay plane helper elements Add 'is_underlay' in drm_plane, which is used to indicate whether the HW plane is below the primary plane at the Z position. Add 'has_underlay' in drm_backend, which is used indicate that there are underlay planes in drm backend. Signed-off-by: Chao Guo Signed-off-by: Marius Vlad --- libweston/backend-drm/drm-internal.h | 7 ++++++- libweston/backend-drm/drm.c | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/libweston/backend-drm/drm-internal.h b/libweston/backend-drm/drm-internal.h index c62bde951..5b8635e8c 100644 --- a/libweston/backend-drm/drm-internal.h +++ b/libweston/backend-drm/drm-internal.h @@ -257,6 +257,9 @@ struct drm_backend { uint32_t pageflip_timeout; + /* True, if underlay planes exist. */ + bool has_underlay; + struct weston_log_scope *debug; }; @@ -414,6 +417,8 @@ struct drm_plane { uint32_t crtc_id; struct drm_property_info props[WDRM_PLANE__COUNT]; + /* True if the plane's zpos_max < primary plane's zpos_min. */ + bool is_underlay; /* The last state submitted to the kernel for this plane. */ struct drm_plane_state *state_cur; @@ -651,7 +656,7 @@ drm_output_get_plane_type_name(struct drm_plane *p) case WDRM_PLANE_TYPE_CURSOR: return "cursor"; case WDRM_PLANE_TYPE_OVERLAY: - return "overlay"; + return p->is_underlay ? "underlay" : "overlay"; default: assert(0); break; diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c index 558581140..6896ee7fe 100644 --- a/libweston/backend-drm/drm.c +++ b/libweston/backend-drm/drm.c @@ -1155,6 +1155,7 @@ drm_plane_create(struct drm_device *device, const drmModePlane *kplane) plane->possible_crtcs = kplane->possible_crtcs; plane->plane_id = kplane->plane_id; plane->crtc_id = kplane->crtc_id; + plane->is_underlay = false; weston_drm_format_array_init(&plane->formats); @@ -1328,6 +1329,7 @@ create_sprites(struct drm_device *device) struct drm_plane *drm_plane; uint32_t i; uint32_t next_plane_idx = 0; + uint64_t primary_plane_zpos_min = DRM_PLANE_ZPOS_INVALID_PLANE; kplane_res = drmModeGetPlaneResources(device->drm.fd); if (!kplane_res) { @@ -1350,11 +1352,30 @@ create_sprites(struct drm_device *device) weston_compositor_stack_plane(b->compositor, &drm_plane->base, NULL); + + if (drm_plane->type == WDRM_PLANE_TYPE_PRIMARY) + primary_plane_zpos_min = drm_plane->zpos_min; } - wl_list_for_each (drm_plane, &device->plane_list, link) + wl_list_for_each (drm_plane, &device->plane_list, link) { drm_plane->plane_idx = next_plane_idx++; + if (primary_plane_zpos_min != DRM_PLANE_ZPOS_INVALID_PLANE && + drm_plane->zpos_max != DRM_PLANE_ZPOS_INVALID_PLANE && + drm_plane->zpos_max < primary_plane_zpos_min) { + drm_plane->is_underlay = true; + b->has_underlay = true; + } + } + + if (b->has_underlay && !b->format->opaque_substitute) { + weston_log("WARNING: Unable to use hardware underlay " + "planes as the output format is opaque. In " + "order to make use of hardware overlay planes " + "adjust the output format.\n"); + b->has_underlay = false; + } + drmModeFreePlaneResources(kplane_res); } @@ -3974,6 +3995,7 @@ drm_backend_create(struct weston_compositor *compositor, b->compositor = compositor; b->pageflip_timeout = config->pageflip_timeout; b->use_pixman_shadow = config->use_pixman_shadow; + b->has_underlay = false; b->debug = weston_compositor_add_log_scope(compositor, "drm-backend", "Debug messages from DRM/KMS backend\n",