diff mbox series

[1/3] drm/rect: Return scaling factor and error code separately

Message ID 20190919141904.15840-1-ville.syrjala@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [1/3] drm/rect: Return scaling factor and error code separately | expand

Commit Message

Ville Syrjälä Sept. 19, 2019, 2:19 p.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

We may want to dump out the calculated scaling factor(s) when
they exceed the limits. To achieve that we need to return the
error code and scaling factor separately.

Side note: the code in dpu_plane_validate_multirect_v2()
looks rather dubious on account of it not using fixed point
numbers. Not sure the rounding behaviour we have really
satisfies what it's trying to do. Maybe it should just do
(src_w!=dst_w || src_h!=dst_h) ?

Cc: Jeykumar Sankaran <jsanka@codeaurora.org>
Suggested-by: Sean Paul <sean@poorly.run>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_atomic_helper.c         |  8 ++---
 drivers/gpu/drm/drm_rect.c                  | 34 ++++++++++++---------
 drivers/gpu/drm/i915/display/intel_sprite.c | 12 ++++----
 drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c   |  8 +++--
 include/drm/drm_rect.h                      |  6 ++--
 5 files changed, 39 insertions(+), 29 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index c861a871299d..c60db3bf2a83 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -765,7 +765,7 @@  int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state,
 	struct drm_rect *dst = &plane_state->dst;
 	unsigned int rotation = plane_state->rotation;
 	struct drm_rect clip = {};
-	int hscale, vscale;
+	int hscale, vscale, ret;
 
 	WARN_ON(plane_state->crtc && plane_state->crtc != crtc_state->crtc);
 
@@ -791,9 +791,9 @@  int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state,
 	drm_rect_rotate(src, fb->width << 16, fb->height << 16, rotation);
 
 	/* Check scaling */
-	hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
-	vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
-	if (hscale < 0 || vscale < 0) {
+	ret = drm_rect_calc_hscale(src, dst, min_scale, max_scale, &hscale);
+	ret |= drm_rect_calc_vscale(src, dst, min_scale, max_scale, &vscale);
+	if (ret) {
 		DRM_DEBUG_KMS("Invalid scaling of plane\n");
 		drm_rect_debug_print("src: ", &plane_state->src, true);
 		drm_rect_debug_print("dst: ", &plane_state->dst, false);
diff --git a/drivers/gpu/drm/drm_rect.c b/drivers/gpu/drm/drm_rect.c
index b8363aaa9032..f014107d11a5 100644
--- a/drivers/gpu/drm/drm_rect.c
+++ b/drivers/gpu/drm/drm_rect.c
@@ -145,6 +145,7 @@  static int drm_calc_scale(int src, int dst)
  * @dst: destination window rectangle
  * @min_hscale: minimum allowed horizontal scaling factor
  * @max_hscale: maximum allowed horizontal scaling factor
+ * @hscale: calculated horizontal scaling factor
  *
  * Calculate the horizontal scaling factor as
  * (@src width) / (@dst width).
@@ -154,23 +155,25 @@  static int drm_calc_scale(int src, int dst)
  * pessimistic limit calculation.
  *
  * RETURNS:
- * The horizontal scaling factor, or errno of out of limits.
+ * Zero on success, or errno on out of limits.
  */
 int drm_rect_calc_hscale(const struct drm_rect *src,
 			 const struct drm_rect *dst,
-			 int min_hscale, int max_hscale)
+			 int min_hscale, int max_hscale,
+			 int *hscale)
 {
 	int src_w = drm_rect_width(src);
 	int dst_w = drm_rect_width(dst);
-	int hscale = drm_calc_scale(src_w, dst_w);
 
-	if (hscale < 0 || dst_w == 0)
-		return hscale;
+	*hscale = drm_calc_scale(src_w, dst_w);
 
-	if (hscale < min_hscale || hscale > max_hscale)
+	if (*hscale < 0 || dst_w == 0)
+		return *hscale;
+
+	if (*hscale < min_hscale || *hscale > max_hscale)
 		return -ERANGE;
 
-	return hscale;
+	return 0;
 }
 EXPORT_SYMBOL(drm_rect_calc_hscale);
 
@@ -180,6 +183,7 @@  EXPORT_SYMBOL(drm_rect_calc_hscale);
  * @dst: destination window rectangle
  * @min_vscale: minimum allowed vertical scaling factor
  * @max_vscale: maximum allowed vertical scaling factor
+ * @hscale: calculated vertical scaling factor
  *
  * Calculate the vertical scaling factor as
  * (@src height) / (@dst height).
@@ -189,23 +193,25 @@  EXPORT_SYMBOL(drm_rect_calc_hscale);
  * pessimistic limit calculation.
  *
  * RETURNS:
- * The vertical scaling factor, or errno of out of limits.
+ * Zero on success, or errno on out of limits.
  */
 int drm_rect_calc_vscale(const struct drm_rect *src,
 			 const struct drm_rect *dst,
-			 int min_vscale, int max_vscale)
+			 int min_vscale, int max_vscale,
+			 int *vscale)
 {
 	int src_h = drm_rect_height(src);
 	int dst_h = drm_rect_height(dst);
-	int vscale = drm_calc_scale(src_h, dst_h);
 
-	if (vscale < 0 || dst_h == 0)
-		return vscale;
+	*vscale = drm_calc_scale(src_h, dst_h);
+
+	if (*vscale < 0 || dst_h == 0)
+		return *vscale;
 
-	if (vscale < min_vscale || vscale > max_vscale)
+	if (*vscale < min_vscale || *vscale > max_vscale)
 		return -ERANGE;
 
-	return vscale;
+	return 0;
 }
 EXPORT_SYMBOL(drm_rect_calc_vscale);
 
diff --git a/drivers/gpu/drm/i915/display/intel_sprite.c b/drivers/gpu/drm/i915/display/intel_sprite.c
index 7a7078d0ba23..a854bd5194dc 100644
--- a/drivers/gpu/drm/i915/display/intel_sprite.c
+++ b/drivers/gpu/drm/i915/display/intel_sprite.c
@@ -361,12 +361,12 @@  skl_program_scaler(struct intel_plane *plane,
 	u16 y_vphase, uv_rgb_vphase;
 	int hscale, vscale;
 
-	hscale = drm_rect_calc_hscale(&plane_state->base.src,
-				      &plane_state->base.dst,
-				      0, INT_MAX);
-	vscale = drm_rect_calc_vscale(&plane_state->base.src,
-				      &plane_state->base.dst,
-				      0, INT_MAX);
+	drm_rect_calc_hscale(&plane_state->base.src,
+			     &plane_state->base.dst,
+			     0, INT_MAX, &hscale);
+	drm_rect_calc_vscale(&plane_state->base.src,
+			     &plane_state->base.dst,
+			     0, INT_MAX, &vscale);
 
 	/* TODO: handle sub-pixel coordinates */
 	if (drm_format_info_is_yuv_semiplanar(fb->format) &&
diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
index 58d5acbcfc5c..528242052118 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
@@ -658,7 +658,7 @@  int dpu_plane_validate_multirect_v2(struct dpu_multirect_plane_states *plane)
 	}
 
 	for (i = 0; i < R_MAX; i++) {
-		int width_threshold;
+		int width_threshold, ret, hscale, vscale;
 
 		pstate[i] = to_dpu_plane_state(drm_state[i]);
 		dpu_plane[i] = to_dpu_plane(drm_state[i]->plane);
@@ -676,8 +676,10 @@  int dpu_plane_validate_multirect_v2(struct dpu_multirect_plane_states *plane)
 
 		dst[i] = drm_plane_state_dest(drm_state[i]);
 
-		if (drm_rect_calc_hscale(&src[i], &dst[i], 1, 1) != 1 ||
-		    drm_rect_calc_vscale(&src[i], &dst[i], 1, 1) != 1) {
+		ret = drm_rect_calc_hscale(&src[i], &dst[i], 1, 1, &hscale);
+		ret |= drm_rect_calc_vscale(&src[i], &dst[i], 1, 1, &vscale);
+
+		if (ret || hscale != 1 || vscale != 1) {
 			DPU_ERROR_PLANE(dpu_plane[i],
 				"scaling is not supported in multirect mode\n");
 			return -EINVAL;
diff --git a/include/drm/drm_rect.h b/include/drm/drm_rect.h
index 6195820aa5c5..34a88ba9ca7b 100644
--- a/include/drm/drm_rect.h
+++ b/include/drm/drm_rect.h
@@ -178,10 +178,12 @@  bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
 			  const struct drm_rect *clip);
 int drm_rect_calc_hscale(const struct drm_rect *src,
 			 const struct drm_rect *dst,
-			 int min_hscale, int max_hscale);
+			 int min_hscale, int max_hscale,
+			 int *hscale);
 int drm_rect_calc_vscale(const struct drm_rect *src,
 			 const struct drm_rect *dst,
-			 int min_vscale, int max_vscale);
+			 int min_vscale, int max_vscale,
+			 int *vscale);
 void drm_rect_debug_print(const char *prefix,
 			  const struct drm_rect *r, bool fixed_point);
 void drm_rect_rotate(struct drm_rect *r,