[1/5] drm/rect: Round above 1 << 16 upwards to correct scale calculation functions.
diff mbox

Message ID 20180503112217.37292-2-maarten.lankhorst@linux.intel.com
State New
Headers show

Commit Message

Maarten Lankhorst May 3, 2018, 11:22 a.m. UTC
When calculating limits we want to be as pessimistic as possible,
so we have to explicitly say whether we want to round up or down
to accurately calculate whether we are below min_scale or above
max_scale.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 drivers/gpu/drm/drm_rect.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

Comments

Ville Syrjala May 3, 2018, 1:28 p.m. UTC | #1
On Thu, May 03, 2018 at 01:22:13PM +0200, Maarten Lankhorst wrote:
> When calculating limits we want to be as pessimistic as possible,
> so we have to explicitly say whether we want to round up or down
> to accurately calculate whether we are below min_scale or above
> max_scale.
> 
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
>  drivers/gpu/drm/drm_rect.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_rect.c b/drivers/gpu/drm/drm_rect.c
> index a3783ecea297..4735526297aa 100644
> --- a/drivers/gpu/drm/drm_rect.c
> +++ b/drivers/gpu/drm/drm_rect.c
> @@ -106,7 +106,10 @@ static int drm_calc_scale(int src, int dst)
>  	if (dst == 0)
>  		return 0;
>  
> -	scale = src / dst;
> +	if (src > (dst << 16))
> +		return DIV_ROUND_UP(src, dst);
> +	else
> +		scale = src / dst;
>  
>  	return scale;
>  }
> @@ -121,6 +124,9 @@ static int drm_calc_scale(int src, int dst)
>   * Calculate the horizontal scaling factor as
>   * (@src width) / (@dst width).
>   *
> + * If the scale is below 1 << 16, round down, if above up. This will

The "if above up" part doesn't read all that well to me. Maybe write it
out fully "If the scale is above 1 << 16, round up"?

Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

> + * calculate the scale with the most pessimistic limit calculation.
> + *
>   * RETURNS:
>   * The horizontal scaling factor, or errno of out of limits.
>   */
> @@ -152,6 +158,9 @@ EXPORT_SYMBOL(drm_rect_calc_hscale);
>   * Calculate the vertical scaling factor as
>   * (@src height) / (@dst height).
>   *
> + * If the scale is below 1 << 16, round down, if above up. This will
> + * calculate the scale with the most pessimistic limit calculation.
> + *
>   * RETURNS:
>   * The vertical scaling factor, or errno of out of limits.
>   */
> @@ -189,6 +198,9 @@ EXPORT_SYMBOL(drm_rect_calc_vscale);
>   * If the calculated scaling factor is above @max_vscale,
>   * decrease the height of rectangle @src to compensate.
>   *
> + * If the scale is below 1 << 16, round down, if above up. This will
> + * calculate the scale with the most pessimistic limit calculation.
> + *
>   * RETURNS:
>   * The horizontal scaling factor.
>   */
> @@ -239,6 +251,9 @@ EXPORT_SYMBOL(drm_rect_calc_hscale_relaxed);
>   * If the calculated scaling factor is above @max_vscale,
>   * decrease the height of rectangle @src to compensate.
>   *
> + * If the scale is below 1 << 16, round down, if above up. This will
> + * calculate the scale with the most pessimistic limit calculation.
> + *
>   * RETURNS:
>   * The vertical scaling factor.
>   */
> -- 
> 2.17.0

Patch
diff mbox

diff --git a/drivers/gpu/drm/drm_rect.c b/drivers/gpu/drm/drm_rect.c
index a3783ecea297..4735526297aa 100644
--- a/drivers/gpu/drm/drm_rect.c
+++ b/drivers/gpu/drm/drm_rect.c
@@ -106,7 +106,10 @@  static int drm_calc_scale(int src, int dst)
 	if (dst == 0)
 		return 0;
 
-	scale = src / dst;
+	if (src > (dst << 16))
+		return DIV_ROUND_UP(src, dst);
+	else
+		scale = src / dst;
 
 	return scale;
 }
@@ -121,6 +124,9 @@  static int drm_calc_scale(int src, int dst)
  * Calculate the horizontal scaling factor as
  * (@src width) / (@dst width).
  *
+ * If the scale is below 1 << 16, round down, if above up. This will
+ * calculate the scale with the most pessimistic limit calculation.
+ *
  * RETURNS:
  * The horizontal scaling factor, or errno of out of limits.
  */
@@ -152,6 +158,9 @@  EXPORT_SYMBOL(drm_rect_calc_hscale);
  * Calculate the vertical scaling factor as
  * (@src height) / (@dst height).
  *
+ * If the scale is below 1 << 16, round down, if above up. This will
+ * calculate the scale with the most pessimistic limit calculation.
+ *
  * RETURNS:
  * The vertical scaling factor, or errno of out of limits.
  */
@@ -189,6 +198,9 @@  EXPORT_SYMBOL(drm_rect_calc_vscale);
  * If the calculated scaling factor is above @max_vscale,
  * decrease the height of rectangle @src to compensate.
  *
+ * If the scale is below 1 << 16, round down, if above up. This will
+ * calculate the scale with the most pessimistic limit calculation.
+ *
  * RETURNS:
  * The horizontal scaling factor.
  */
@@ -239,6 +251,9 @@  EXPORT_SYMBOL(drm_rect_calc_hscale_relaxed);
  * If the calculated scaling factor is above @max_vscale,
  * decrease the height of rectangle @src to compensate.
  *
+ * If the scale is below 1 << 16, round down, if above up. This will
+ * calculate the scale with the most pessimistic limit calculation.
+ *
  * RETURNS:
  * The vertical scaling factor.
  */