diff mbox

[1/9] drm/imx: ipuv3-plane: make sure x/y offsets are even in case of chroma subsampling

Message ID 20161018160757.11595-1-p.zabel@pengutronix.de (mailing list archive)
State New, archived
Headers show

Commit Message

Philipp Zabel Oct. 18, 2016, 4:07 p.m. UTC
Odd x/y offsets are not allowed for chroma subsampled planar YUV
formats.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/gpu/drm/imx/ipuv3-plane.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Ying Liu Oct. 19, 2016, 7:12 a.m. UTC | #1
On Wed, Oct 19, 2016 at 12:07 AM, Philipp Zabel <p.zabel@pengutronix.de> wrote:
> Odd x/y offsets are not allowed for chroma subsampled planar YUV
> formats.
>
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  drivers/gpu/drm/imx/ipuv3-plane.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c b/drivers/gpu/drm/imx/ipuv3-plane.c
> index 5c34299..3a03fd8 100644
> --- a/drivers/gpu/drm/imx/ipuv3-plane.c
> +++ b/drivers/gpu/drm/imx/ipuv3-plane.c
> @@ -259,6 +259,7 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
>         struct drm_framebuffer *fb = state->fb;
>         struct drm_framebuffer *old_fb = old_state->fb;
>         unsigned long eba, ubo, vbo, old_ubo, old_vbo;
> +       int hsub, vsub;
>
>         /* Ok to disable */
>         if (!fb)
> @@ -372,6 +373,13 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
>
>                 if (old_fb && old_fb->pitches[1] != fb->pitches[1])
>                         crtc_state->mode_changed = true;
> +
> +               /* x and y offsets must be even in case of chroma subsampling */

True for x offsets, but not for y offsets, e.g., NV16.

Regards,
Liu Ying

> +               hsub = drm_format_horz_chroma_subsampling(fb->pixel_format);
> +               vsub = drm_format_vert_chroma_subsampling(fb->pixel_format);
> +               if (((state->src_x >> 16) & (hsub - 1)) ||
> +                   ((state->src_y >> 16) & (vsub - 1)))
> +                       return -EINVAL;
>         }
>
>         return 0;
> --
> 2.9.3
>
Ville Syrjala Oct. 19, 2016, 7:58 a.m. UTC | #2
On Tue, Oct 18, 2016 at 06:07:49PM +0200, Philipp Zabel wrote:
> Odd x/y offsets are not allowed for chroma subsampled planar YUV
> formats.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  drivers/gpu/drm/imx/ipuv3-plane.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c b/drivers/gpu/drm/imx/ipuv3-plane.c
> index 5c34299..3a03fd8 100644
> --- a/drivers/gpu/drm/imx/ipuv3-plane.c
> +++ b/drivers/gpu/drm/imx/ipuv3-plane.c
> @@ -259,6 +259,7 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
>  	struct drm_framebuffer *fb = state->fb;
>  	struct drm_framebuffer *old_fb = old_state->fb;
>  	unsigned long eba, ubo, vbo, old_ubo, old_vbo;
> +	int hsub, vsub;
>  
>  	/* Ok to disable */
>  	if (!fb)
> @@ -372,6 +373,13 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
>  
>  		if (old_fb && old_fb->pitches[1] != fb->pitches[1])
>  			crtc_state->mode_changed = true;
> +
> +		/* x and y offsets must be even in case of chroma subsampling */
> +		hsub = drm_format_horz_chroma_subsampling(fb->pixel_format);
> +		vsub = drm_format_vert_chroma_subsampling(fb->pixel_format);
> +		if (((state->src_x >> 16) & (hsub - 1)) ||
> +		    ((state->src_y >> 16) & (vsub - 1)))

BTW you should use clipped coordinates all over instead of the raw
user coordinates. I see you're rejecting negative crtc user coordinates
and whanot so I guess it sort of works, but that's not how it's supposed
to be done. drm_plane_helper_check_state() should give you most of
what's needed.

> +			return -EINVAL;
>  	}
>  
>  	return 0;
> -- 
> 2.9.3
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
Philipp Zabel Oct. 19, 2016, 9:30 a.m. UTC | #3
Am Mittwoch, den 19.10.2016, 15:12 +0800 schrieb Ying Liu:
> On Wed, Oct 19, 2016 at 12:07 AM, Philipp Zabel <p.zabel@pengutronix.de> wrote:
> > Odd x/y offsets are not allowed for chroma subsampled planar YUV
> > formats.
> >
> > Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> > ---
> >  drivers/gpu/drm/imx/ipuv3-plane.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c b/drivers/gpu/drm/imx/ipuv3-plane.c
> > index 5c34299..3a03fd8 100644
> > --- a/drivers/gpu/drm/imx/ipuv3-plane.c
> > +++ b/drivers/gpu/drm/imx/ipuv3-plane.c
> > @@ -259,6 +259,7 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
> >         struct drm_framebuffer *fb = state->fb;
> >         struct drm_framebuffer *old_fb = old_state->fb;
> >         unsigned long eba, ubo, vbo, old_ubo, old_vbo;
> > +       int hsub, vsub;
> >
> >         /* Ok to disable */
> >         if (!fb)
> > @@ -372,6 +373,13 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
> >
> >                 if (old_fb && old_fb->pitches[1] != fb->pitches[1])
> >                         crtc_state->mode_changed = true;
> > +
> > +               /* x and y offsets must be even in case of chroma subsampling */
> 
> True for x offsets, but not for y offsets, e.g., NV16.

That should be ok, for NV16 vsub==1, so (y&(vsub-1)) will always be
false. Only for 4:2:0 subsampled formats is vsub==2, and then
(y&(vsub-1)) will only be true if y is odd.
I'll change the comment to:
		/*
		 * The x/y offsets must be even in case of horizontal/vertical
		 * chroma subsampling.
		 */

regards
Philipp
Philipp Zabel Oct. 19, 2016, 9:30 a.m. UTC | #4
Am Mittwoch, den 19.10.2016, 10:58 +0300 schrieb Ville Syrjälä:
> On Tue, Oct 18, 2016 at 06:07:49PM +0200, Philipp Zabel wrote:
> > Odd x/y offsets are not allowed for chroma subsampled planar YUV
> > formats.
> > 
> > Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> > ---
> >  drivers/gpu/drm/imx/ipuv3-plane.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c b/drivers/gpu/drm/imx/ipuv3-plane.c
> > index 5c34299..3a03fd8 100644
> > --- a/drivers/gpu/drm/imx/ipuv3-plane.c
> > +++ b/drivers/gpu/drm/imx/ipuv3-plane.c
> > @@ -259,6 +259,7 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
> >  	struct drm_framebuffer *fb = state->fb;
> >  	struct drm_framebuffer *old_fb = old_state->fb;
> >  	unsigned long eba, ubo, vbo, old_ubo, old_vbo;
> > +	int hsub, vsub;
> >  
> >  	/* Ok to disable */
> >  	if (!fb)
> > @@ -372,6 +373,13 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
> >  
> >  		if (old_fb && old_fb->pitches[1] != fb->pitches[1])
> >  			crtc_state->mode_changed = true;
> > +
> > +		/* x and y offsets must be even in case of chroma subsampling */
> > +		hsub = drm_format_horz_chroma_subsampling(fb->pixel_format);
> > +		vsub = drm_format_vert_chroma_subsampling(fb->pixel_format);
> > +		if (((state->src_x >> 16) & (hsub - 1)) ||
> > +		    ((state->src_y >> 16) & (vsub - 1)))
> 
> BTW you should use clipped coordinates all over instead of the raw
> user coordinates. I see you're rejecting negative crtc user coordinates
> and whanot so I guess it sort of works, but that's not how it's supposed
> to be done. drm_plane_helper_check_state() should give you most of
> what's needed.

Thank you for the pointer, I'll add a patch to use
drm_plane_helper_check_state.

regards
Philipp
diff mbox

Patch

diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c b/drivers/gpu/drm/imx/ipuv3-plane.c
index 5c34299..3a03fd8 100644
--- a/drivers/gpu/drm/imx/ipuv3-plane.c
+++ b/drivers/gpu/drm/imx/ipuv3-plane.c
@@ -259,6 +259,7 @@  static int ipu_plane_atomic_check(struct drm_plane *plane,
 	struct drm_framebuffer *fb = state->fb;
 	struct drm_framebuffer *old_fb = old_state->fb;
 	unsigned long eba, ubo, vbo, old_ubo, old_vbo;
+	int hsub, vsub;
 
 	/* Ok to disable */
 	if (!fb)
@@ -372,6 +373,13 @@  static int ipu_plane_atomic_check(struct drm_plane *plane,
 
 		if (old_fb && old_fb->pitches[1] != fb->pitches[1])
 			crtc_state->mode_changed = true;
+
+		/* x and y offsets must be even in case of chroma subsampling */
+		hsub = drm_format_horz_chroma_subsampling(fb->pixel_format);
+		vsub = drm_format_vert_chroma_subsampling(fb->pixel_format);
+		if (((state->src_x >> 16) & (hsub - 1)) ||
+		    ((state->src_y >> 16) & (vsub - 1)))
+			return -EINVAL;
 	}
 
 	return 0;