drm/vkms: add function to get plane formats
PATCH v2 1/2 drm/vkms: add function to get plane formats
Move the logic to get the plane formats depending on the plane type to its own function.
Refactor, no functional changes.
--- drivers/gpu/drm/vkms/vkms_plane.c | 37 ++++++++++++++++--------------- 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/gpu/drm/vkms/vkms_plane.c +19 -18
@@ -83,6 +83,23 @@ static void vkms_plane_reset(struct drm_plane *plane)__drm_gem_reset_shadow_plane (plane, &vkms_state->base); } +static void vkms_formats_for_plane_type (enum drm_plane_type type, +const u32 **formats,int *nformats) +{ +switch (type) { +case DRM_PLANE_TYPE_CURSOR : +case DRM_PLANE_TYPE_OVERLAY : + *formats = vkms_plane_formats; + *nformats =ARRAY_SIZE (vkms_plane_formats); +break ; +case DRM_PLANE_TYPE_PRIMARY : +default : + *formats = vkms_formats; + *nformats =ARRAY_SIZE (vkms_formats); +break ; + } +} +static const struct drm_plane_funcs vkms_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane,
@@ -167,24 +184,8 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,const u32 *formats;int nformats; -switch (type) { -case DRM_PLANE_TYPE_PRIMARY : - formats = vkms_formats; - nformats =ARRAY_SIZE (vkms_formats); - funcs = &vkms_primary_helper_funcs; -break ; -case DRM_PLANE_TYPE_CURSOR : -case DRM_PLANE_TYPE_OVERLAY : - formats = vkms_plane_formats; - nformats =ARRAY_SIZE (vkms_plane_formats); - funcs = &vkms_primary_helper_funcs; -break ; -default : - formats = vkms_formats; - nformats =ARRAY_SIZE (vkms_formats); - funcs = &vkms_primary_helper_funcs; -break ; - } + funcs = &vkms_primary_helper_funcs; +vkms_formats_for_plane_type (type, &formats, &nformats); plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 1 << index, &vkms_plane_funcs,
Signature · 1 line
2.25.1
PATCH v2 2/2 drm/vkms: set plane modifiers
Where no modifiers are exposed, usually linear modifier is assumed. However, userspace code is starting to expect IN_FORMATS even when the only supported modifiers are linear [1].
To avoid possible issues, explicitly set the DRM_FORMAT_MOD_LINEAR modifier.
---
v2: Implement format_mod_supported (Simon Ser)
--- drivers/gpu/drm/vkms/vkms_plane.c | 34 ++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
drivers/gpu/drm/vkms/vkms_plane.c +33 -1
@@ -20,6 +20,11 @@ static const u32 vkms_plane_formats[] = { DRM_FORMAT_XRGB8888 }; +static const u64 vkms_plane_modifiers[] = { +DRM_FORMAT_MOD_LINEAR , +DRM_FORMAT_MOD_INVALID +}; +static struct drm_plane_state *vkms_plane_duplicate_state (struct drm_plane *plane) {
@@ -100,12 +105,39 @@ static void vkms_formats_for_plane_type(enum drm_plane_type type, } } +static bool vkms_format_mod_supported (struct drm_plane *plane,u32 format, +u64 modifier) +{ +bool modifier_found = false; +unsigned int i; +const u32 *formats; +int nformats; + +for (i =0 ; i <ARRAY_SIZE (vkms_plane_modifiers) -1 ; i++) { +if (vkms_plane_modifiers[i] == modifier) + modifier_found = true; + } + +if (!modifier_found) +return false; + +vkms_formats_for_plane_type (plane->type, &formats, &nformats); + +for (i =0 ; i < nformats; i++) { +if (formats[i] == format) +return true; + } + +return false; +} +static const struct drm_plane_funcs vkms_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane, .reset = vkms_plane_reset, .atomic_duplicate_state = vkms_plane_duplicate_state, .atomic_destroy_state = vkms_plane_destroy_state, + .format_mod_supported = vkms_format_mod_supported, }; static void vkms_plane_atomic_update(struct drm_plane *plane,
@@ -190,7 +222,7 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 1 << index, &vkms_plane_funcs, formats, nformats, -NULL , type,NULL ); + vkms_plane_modifiers, type,NULL );if (IS_ERR (plane))return plane;
Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] drm/vkms: set plane modifiers
Overall looks good, but it is a bit repetitive to copy & paste this in all drivers. It'd be nice to provide a core helper to do this, and then drivers can just set format_mod_supported to the helper if they don't have more involved logic. Thoughts?
See drm_plane_check_pixel_format, where the logic is already implemented.
Alternatively… We can just support a missing format_mod_supported in create_in_format_blob. This sounds like this was the original intention of db1689aa61bd ("drm: Create a format/modifier blob") and drm_plane_check_pixel_format.