[Intel-gfx] [PATCH 10/11] drm/i915: clamp sprite to viewable area

Jesse Barnes jbarnes at virtuousgeek.org
Tue Oct 25 11:47:05 CEST 2011


If we try to scan a sprite outside of the parent CRTC area, the display
engine will underflow and potentially blank the framebuffer.  So clamp
the position + size to the viewable area.

Signed-off-by: Jesse Barnes <jbarnes at virtuousgeek.org>
---
 drivers/gpu/drm/i915/intel_overlay2.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_overlay2.c b/drivers/gpu/drm/i915/intel_overlay2.c
index 8876857..90c4f59 100644
--- a/drivers/gpu/drm/i915/intel_overlay2.c
+++ b/drivers/gpu/drm/i915/intel_overlay2.c
@@ -173,6 +173,7 @@ snb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
 	u32 reg = DVSCNTR(pipe);
 	int ret = 0;
 	int x = src_x >> 16, y = src_y >> 16;
+	int active_w = crtc->mode.hdisplay, active_h = crtc->mode.vdisplay;
 
 	assert_pipe_enabled(dev_priv, pipe);
 
@@ -181,6 +182,15 @@ snb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
 
 	old_obj = intel_plane->obj;
 
+	if (crtc_x >= active_w || crtc_y >= active_h)
+		return -EINVAL;
+
+	/* Clamp the width & height into the visible area */
+	if (crtc_x + crtc_w > active_w)
+		crtc_w = active_w - crtc_x - 1;
+	if (crtc_y + crtc_h > active_h)
+		crtc_h = active_h - crtc_y - 1;
+
 	mutex_lock(&dev->struct_mutex);
 
 	dvscntr = I915_READ(reg);
@@ -242,7 +252,7 @@ snb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
 	I915_WRITE(DVSSTRIDE(pipe), fb->pitch);
 	I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
 	I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
-	I915_WRITE(DVSSIZE(pipe), (fb->height << 16) | fb->width);
+	I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
 	I915_WRITE(DVSSCALE(pipe), 0);
 	I915_WRITE(reg, dvscntr);
 	I915_WRITE(DVSSURF(pipe), start);
-- 
1.7.4.1




More information about the Intel-gfx mailing list