[PATCH v6 1/5] drm: Add function to convert rect in 16.16 fixed format to regular format

Ville Syrjälä ville.syrjala at linux.intel.com
Tue Dec 15 14:44:07 UTC 2020


On Mon, Dec 14, 2020 at 09:49:08AM -0800, José Roberto de Souza wrote:
> Much more clear to read one function call than four lines doing this
> conversion.
> 
> Cc: dri-devel at lists.freedesktop.org
> Cc: Gwan-gyeong Mun <gwan-gyeong.mun at intel.com>
> Signed-off-by: José Roberto de Souza <jose.souza at intel.com>
> ---
>  drivers/gpu/drm/drm_rect.c | 15 +++++++++++++++
>  include/drm/drm_rect.h     |  2 ++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_rect.c b/drivers/gpu/drm/drm_rect.c
> index 0460e874896e..24345704b353 100644
> --- a/drivers/gpu/drm/drm_rect.c
> +++ b/drivers/gpu/drm/drm_rect.c
> @@ -373,3 +373,18 @@ void drm_rect_rotate_inv(struct drm_rect *r,
>  	}
>  }
>  EXPORT_SYMBOL(drm_rect_rotate_inv);
> +
> +/**
> + * drm_rect_convert_16_16_to_regular - Convert a rect in 16.16 fixed point form
> + * to regular form.
> + * @in: rect in 16.16 fixed point form
> + * @out: rect to be stored the converted value
> + */
> +void drm_rect_convert_16_16_to_regular(struct drm_rect *in, struct drm_rect *out)
> +{
> +	out->x1 = in->x1 >> 16;
> +	out->y1 = in->y1 >> 16;
> +	out->x2 = in->x2 >> 16;
> +	out->y2 = in->y2 >> 16;
> +}

That's not the same as what we do in most places. We truncate
the width/height, not x2/y2. Doing it on x2/y2 may increase
the width/height.

So I suggest something more like:

static inline void drm_rect_fp_to_int(struct drm_rect *r)
{
	drm_rect_init(r, r->x1 >> 16, r->y1 >> 16,
		      drm_rect_width(r) >> 16,
		      drm_rect_height(r) >> 16);
}

to match the current way of doing things.

-- 
Ville Syrjälä
Intel


More information about the dri-devel mailing list