Add support for the zpos plane property. Depending on the plane type: - Primary and cursor planes: Create an immutable zpos property. The primary plane is always at the bottom and the cursor plane is always on the top. - Overlay planes: Create a mutable zpos property allowing to change their order but always keep them between the primary and cursor planes. As documented, "vkms_crtc_state.active_planes" must be sorted by zpos. This is achieved by inserting them in the array at their normalized_zpos index. Signed-off-by: José Expósito <jose.exposito89@xxxxxxxxx> --- drivers/gpu/drm/vkms/vkms_crtc.c | 3 +-- drivers/gpu/drm/vkms/vkms_drv.c | 1 + drivers/gpu/drm/vkms/vkms_plane.c | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index 57bbd32e9beb..4f23488b15f3 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -207,7 +207,6 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc, return -ENOMEM; vkms_state->num_active_planes = i; - i = 0; drm_for_each_plane_mask(plane, crtc->dev, crtc_state->plane_mask) { plane_state = drm_atomic_get_existing_plane_state(crtc_state->state, plane); @@ -215,7 +214,7 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc, if (!plane_state->visible) continue; - vkms_state->active_planes[i++] = + vkms_state->active_planes[plane_state->normalized_zpos] = to_vkms_plane_state(plane_state); } diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index bb98f6c6c561..a97b338318c6 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -157,6 +157,7 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) * fbdev helpers. We have to go with 0, meaning "pick the default", * which ix XRGB8888 in all cases. */ dev->mode_config.preferred_depth = 0; + dev->mode_config.normalize_zpos = true; dev->mode_config.helper_private = &vkms_mode_config_helpers; return vkms_output_init(vkmsdev, 0); diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c index 32409e15244b..f491abb35d4a 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -81,6 +81,8 @@ static void vkms_plane_reset(struct drm_plane *plane) } __drm_gem_reset_shadow_plane(plane, &vkms_state->base); + vkms_state->base.base.zpos = drm_plane_index(plane); + vkms_state->base.base.normalized_zpos = drm_plane_index(plane); } static const struct drm_plane_funcs vkms_plane_funcs = { @@ -158,6 +160,24 @@ static const struct drm_plane_helper_funcs vkms_primary_helper_funcs = { DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, }; +static int vkms_plane_create_zpos_property(struct vkms_device *vkmsdev, + struct vkms_plane *plane) +{ + int ret; + unsigned int zpos = drm_plane_index(&plane->base); + int overlay_max_zpos = vkmsdev->config->num_overlay_planes; + + if (plane->base.type == DRM_PLANE_TYPE_OVERLAY) { + ret = drm_plane_create_zpos_property(&plane->base, zpos, + 1, overlay_max_zpos); + } else { + ret = drm_plane_create_zpos_immutable_property(&plane->base, + zpos); + } + + return ret; +} + struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, enum drm_plane_type type, int index) { @@ -166,6 +186,7 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, struct vkms_plane *plane; const u32 *formats; int nformats; + int ret; switch (type) { case DRM_PLANE_TYPE_PRIMARY: @@ -195,5 +216,9 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, drm_plane_helper_add(&plane->base, funcs); + ret = vkms_plane_create_zpos_property(vkmsdev, plane); + if (ret) + return ERR_PTR(ret); + return plane; } -- 2.25.1