xf86-video-intel: 2 commits - src/sna/sna_video.c src/sna/sna_video.h src/sna/sna_video_overlay.c src/sna/sna_video_textured.c

Chris Wilson ickle at kemper.freedesktop.org
Wed Nov 9 02:33:23 PST 2011


 src/sna/sna_video.c          |  159 +++++++++++++++++--------------------------
 src/sna/sna_video.h          |   14 ++-
 src/sna/sna_video_overlay.c  |   13 +--
 src/sna/sna_video_textured.c |   16 +---
 4 files changed, 84 insertions(+), 118 deletions(-)

New commits:
commit f62b9f94f64f402e731463205635d386386e274e
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Nov 9 10:15:11 2011 +0000

    sna/video: Pass cropped source dimensions along with frame data
    
    So pack all the relevant details into the same structure.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/sna/sna_video.c b/src/sna/sna_video.c
index 063aca9..fd5f3f1 100644
--- a/src/sna/sna_video.c
+++ b/src/sna/sna_video.c
@@ -114,15 +114,14 @@ void sna_video_frame_fini(struct sna *sna,
 Bool
 sna_video_clip_helper(ScrnInfoPtr scrn,
 		      struct sna_video *video,
+		      struct sna_video_frame *frame,
 		      xf86CrtcPtr * crtc_ret,
 		      BoxPtr dst,
 		      short src_x, short src_y,
 		      short drw_x, short drw_y,
 		      short src_w, short src_h,
 		      short drw_w, short drw_h,
-		      int id,
-		      int *top, int* left, int* npixels, int *nlines,
-		      RegionPtr reg, INT32 width, INT32 height)
+		      RegionPtr reg)
 {
 	Bool ret;
 	RegionRec crtc_region_local;
@@ -156,18 +155,18 @@ sna_video_clip_helper(ScrnInfoPtr scrn,
 	*crtc_ret = crtc;
 
 	ret = xf86XVClipVideoHelper(dst, &x1, &x2, &y1, &y2,
-				    crtc_region, width, height);
+				    crtc_region, frame->width, frame->height);
 	if (crtc_region != reg)
 		RegionUninit(&crtc_region_local);
 
-	*top = y1 >> 16;
-	*left = (x1 >> 16) & ~1;
-	*npixels = ALIGN(((x2 + 0xffff) >> 16), 2) - *left;
-	if (is_planar_fourcc(id)) {
-		*top &= ~1;
-		*nlines = ALIGN(((y2 + 0xffff) >> 16), 2) - *top;
+	frame->top = y1 >> 16;
+	frame->left = (x1 >> 16) & ~1;
+	frame->npixels = ALIGN(((x2 + 0xffff) >> 16), 2) - frame->left;
+	if (is_planar_fourcc(frame->id)) {
+		frame->top &= ~1;
+		frame->nlines = ALIGN(((y2 + 0xffff) >> 16), 2) - frame->top;
 	} else
-		*nlines = ((y2 + 0xffff) >> 16) - *top;
+		frame->nlines = ((y2 + 0xffff) >> 16) - frame->top;
 
 	return ret;
 }
@@ -314,22 +313,22 @@ static void sna_memcpy_plane(uint8_t *dst, const uint8_t *src,
 static void
 sna_copy_planar_data(struct sna_video *video,
 		     const struct sna_video_frame *frame,
-		     const uint8_t *src, uint8_t *dst,
-		     int top, int left, int h, int w)
+		     const uint8_t *src, uint8_t *dst)
 {
-	int pitch;
 	uint8_t *d;
+	int w = frame->npixels;
+	int h = frame->nlines;
+	int pitch;
 
 	pitch = ALIGN(frame->width, 4);
-	sna_memcpy_plane(dst, src + top * pitch + left,
-			 h, w, frame->pitch[1], pitch,
-			 video->rotation);
+	sna_memcpy_plane(dst, src + frame->top * pitch + frame->left,
+			 h, w, frame->pitch[1], pitch, video->rotation);
 
 	src += frame->height * pitch; /* move over Luma plane */
 
 	/* align to beginning of chroma planes */
 	pitch = ALIGN((frame->width >> 1), 0x4);
-	src += (top >> 1) * pitch + (left >> 1);
+	src += (frame->top >> 1) * pitch + (frame->left >> 1);
 	w >>= 1;
 	h >>= 1;
 
@@ -353,14 +352,15 @@ static void
 sna_copy_packed_data(struct sna_video *video,
 		     const struct sna_video_frame *frame,
 		     const uint8_t *buf,
-		     uint8_t *dst,
-		     int top, int left, int h, int w)
+		     uint8_t *dst)
 {
 	int pitch = frame->width << 1;
 	const uint8_t *src, *s;
+	int w = frame->npixels;
+	int h = frame->nlines;
 	int i, j;
 
-	src = buf + (top * pitch) + (left << 1);
+	src = buf + (frame->top * pitch) + (frame->left << 1);
 
 	switch (video->rotation) {
 	case RR_Rotate_0:
@@ -383,7 +383,7 @@ sna_copy_packed_data(struct sna_video *video,
 			src += pitch;
 		}
 		h >>= 1;
-		src = buf + (top * pitch) + (left << 1);
+		src = buf + (frame->top * pitch) + (frame->left << 1);
 		for (i = 0; i < h; i += 2) {
 			for (j = 0; j < w; j += 2) {
 				/* Copy U */
@@ -419,7 +419,7 @@ sna_copy_packed_data(struct sna_video *video,
 			src += pitch;
 		}
 		h >>= 1;
-		src = buf + (top * pitch) + (left << 1);
+		src = buf + (frame->top * pitch) + (frame->left << 1);
 		for (i = 0; i < h; i += 2) {
 			for (j = 0; j < w; j += 2) {
 				/* Copy U */
@@ -438,8 +438,6 @@ Bool
 sna_video_copy_data(struct sna *sna,
 		    struct sna_video *video,
 		    struct sna_video_frame *frame,
-		    int top, int left,
-		    int npixels, int nlines,
 		    const uint8_t *buf)
 {
 	uint8_t *dst;
@@ -457,7 +455,7 @@ sna_video_copy_data(struct sna *sna,
 			};
 			if (pitch[0] == frame->pitch[0] &&
 			    pitch[1] == frame->pitch[1] &&
-			    top == 0 && left == 0) {
+			    frame->top == 0 && frame->left == 0) {
 				kgem_bo_write(&sna->kgem, frame->bo,
 					      buf,
 					      pitch[1]*frame->height +
@@ -473,8 +471,8 @@ sna_video_copy_data(struct sna *sna,
 		} else {
 			if (frame->width*2 == frame->pitch[0]) {
 				kgem_bo_write(&sna->kgem, frame->bo,
-					      buf + (top * frame->width*2) + (left << 1),
-					      frame->height*frame->width*2);
+					      buf + (frame->top * frame->width*2) + (frame->left << 1),
+					      frame->nlines*frame->width*2);
 				return TRUE;
 			}
 		}
@@ -486,11 +484,9 @@ sna_video_copy_data(struct sna *sna,
 		return FALSE;
 
 	if (is_planar_fourcc(frame->id))
-		sna_copy_planar_data(video, frame, buf, dst,
-				     top, left, nlines, npixels);
+		sna_copy_planar_data(video, frame, buf, dst);
 	else
-		sna_copy_packed_data(video, frame, buf, dst,
-				     top, left, nlines, npixels);
+		sna_copy_packed_data(video, frame, buf, dst);
 
 	munmap(dst, video->buf->size);
 	return TRUE;
diff --git a/src/sna/sna_video.h b/src/sna/sna_video.h
index 41874b9..ab8289b 100644
--- a/src/sna/sna_video.h
+++ b/src/sna/sna_video.h
@@ -68,8 +68,13 @@ struct sna_video_frame {
 	uint32_t size;
 	uint32_t UBufOffset;
 	uint32_t VBufOffset;
+
 	uint16_t width, height;
 	uint16_t pitch[2];
+
+	/* extents */
+	uint16_t top, left;
+	uint16_t npixels, nlines;
 };
 
 void sna_video_init(struct sna *sna, ScreenPtr screen);
@@ -97,15 +102,14 @@ static inline int is_planar_fourcc(int id)
 Bool
 sna_video_clip_helper(ScrnInfoPtr scrn,
 		      struct sna_video *adaptor_priv,
+		      struct sna_video_frame *frame,
 		      xf86CrtcPtr * crtc_ret,
 		      BoxPtr dst,
 		      short src_x, short src_y,
 		      short drw_x, short drw_y,
 		      short src_w, short src_h,
 		      short drw_w, short drw_h,
-		      int id,
-		      int *top, int* left, int* npixels, int *nlines,
-		      RegionPtr reg, INT32 width, INT32 height);
+		      RegionPtr reg);
 
 void
 sna_video_frame_init(struct sna *sna,
@@ -117,8 +121,6 @@ Bool
 sna_video_copy_data(struct sna *sna,
 		    struct sna_video *video,
 		    struct sna_video_frame *frame,
-		    int top, int left,
-		    int npixels, int nlines,
 		    const uint8_t *buf);
 
 void sna_video_frame_fini(struct sna *sna,
diff --git a/src/sna/sna_video_overlay.c b/src/sna/sna_video_overlay.c
index a20c111..491baa8 100644
--- a/src/sna/sna_video_overlay.c
+++ b/src/sna/sna_video_overlay.c
@@ -467,7 +467,6 @@ sna_video_overlay_put_image(ScrnInfoPtr scrn,
 	struct sna_video_frame frame;
 	BoxRec dstBox;
 	xf86CrtcPtr crtc;
-	int top, left, npixels, nlines;
 
 	DBG(("%s: src: (%d,%d)(%d,%d), dst: (%d,%d)(%d,%d), width %d, height %d\n",
 	     __FUNCTION__,
@@ -483,15 +482,16 @@ sna_video_overlay_put_image(ScrnInfoPtr scrn,
 	if (src_h >= (drw_h * 8))
 		drw_h = src_h / 7;
 
+	sna_video_frame_init(sna, video, id, width, height, &frame);
+
 	if (!sna_video_clip_helper(scrn,
 				   video,
+				   &frame,
 				   &crtc,
 				   &dstBox,
 				   src_x, src_y, drw_x, drw_y,
 				   src_w, src_h, drw_w, drw_h,
-				   id,
-				   &top, &left, &npixels, &nlines, clip,
-				   width, height))
+				   clip))
 		return Success;
 
 	if (!crtc) {
@@ -502,12 +502,9 @@ sna_video_overlay_put_image(ScrnInfoPtr scrn,
 		return Success;
 	}
 
-	sna_video_frame_init(sna, video, id, width, height, &frame);
-
 	/* overlay can't handle rotation natively, store it for the copy func */
 	video->rotation = crtc->rotation;
-	if (!sna_video_copy_data(sna, video, &frame,
-				 top, left, npixels, nlines, buf)) {
+	if (!sna_video_copy_data(sna, video, &frame, buf)) {
 		DBG(("%s: failed to copy video data\n", __FUNCTION__));
 		return BadAlloc;
 	}
diff --git a/src/sna/sna_video_textured.c b/src/sna/sna_video_textured.c
index 64d54ec..3461dc5 100644
--- a/src/sna/sna_video_textured.c
+++ b/src/sna/sna_video_textured.c
@@ -237,22 +237,20 @@ sna_video_textured_put_image(ScrnInfoPtr scrn,
 	PixmapPtr pixmap = get_drawable_pixmap(drawable);
 	BoxRec dstBox;
 	xf86CrtcPtr crtc;
-	int top, left, npixels, nlines;
 	Bool flush = false;
 
 	if (!sna_pixmap(pixmap))
 		return BadAlloc;
 
-	if (!sna_video_clip_helper(scrn, video, &crtc, &dstBox,
+	sna_video_frame_init(sna, video, id, width, height, &frame);
+
+	if (!sna_video_clip_helper(scrn, video, &frame,
+				   &crtc, &dstBox,
 				   src_x, src_y, drw_x, drw_y,
 				   src_w, src_h, drw_w, drw_h,
-				   id,
-				   &top, &left, &npixels, &nlines,
-				   clip, width, height))
+				   clip))
 		return Success;
 
-	sna_video_frame_init(sna, video, id, width, height, &frame);
-
 	if (xvmc_passthrough(id)) {
 		if (IS_I915G(sna) || IS_I915GM(sna)) {
 			/* XXX: i915 is not support and needs some
@@ -264,9 +262,7 @@ sna_video_textured_put_image(ScrnInfoPtr scrn,
 		if (frame.bo == NULL)
 			return BadAlloc;
 	} else {
-		if (!sna_video_copy_data(sna, video, &frame,
-					 top, left, npixels, nlines,
-					 buf))
+		if (!sna_video_copy_data(sna, video, &frame, buf))
 			return BadAlloc;
 	}
 
commit 5809b1ad934d6e19dbcf00f1b59e156761ec16b6
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Nov 9 09:41:53 2011 +0000

    sna/video: Tidy up copy routines
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/sna/sna_video.c b/src/sna/sna_video.c
index d1d5b52..063aca9 100644
--- a/src/sna/sna_video.c
+++ b/src/sna/sna_video.c
@@ -314,60 +314,60 @@ static void sna_memcpy_plane(uint8_t *dst, const uint8_t *src,
 static void
 sna_copy_planar_data(struct sna_video *video,
 		     const struct sna_video_frame *frame,
-		     const uint8_t *src,
-		     uint8_t *dst,
-		     int srcPitch, int srcPitch2,
-		     int srcH, int top, int left, int h, int w)
+		     const uint8_t *src, uint8_t *dst,
+		     int top, int left, int h, int w)
 {
+	int pitch;
 	uint8_t *d;
 
-	sna_memcpy_plane(dst, src + top * srcPitch + left,
-			 h, w, frame->pitch[1], srcPitch,
+	pitch = ALIGN(frame->width, 4);
+	sna_memcpy_plane(dst, src + top * pitch + left,
+			 h, w, frame->pitch[1], pitch,
 			 video->rotation);
 
-	src += srcH * srcPitch; /* move over Luma plane */
+	src += frame->height * pitch; /* move over Luma plane */
+
+	/* align to beginning of chroma planes */
+	pitch = ALIGN((frame->width >> 1), 0x4);
+	src += (top >> 1) * pitch + (left >> 1);
+	w >>= 1;
+	h >>= 1;
 
 	if (frame->id == FOURCC_I420)
 		d = dst + frame->UBufOffset;
 	else
 		d = dst + frame->VBufOffset;
 
-	sna_memcpy_plane(d, src + (top >> 1) * srcPitch2 + (left >> 1),
-			 h / 2, w / 2, frame->pitch[0], srcPitch2,
-			 video->rotation);
-
-	src += (srcH >> 1) * srcPitch2; /* move over Chroma plane */
+	sna_memcpy_plane(d, src, h, w, frame->pitch[0], pitch, video->rotation);
+	src += (frame->height >> 1) * pitch; /* move over Chroma plane */
 
 	if (frame->id == FOURCC_I420)
 		d = dst + frame->VBufOffset;
 	else
 		d = dst + frame->UBufOffset;
 
-	sna_memcpy_plane(d, src + (top >> 1) * srcPitch2 + (left >> 1),
-			 h / 2, w / 2, frame->pitch[0], srcPitch2,
-			 video->rotation);
+	sna_memcpy_plane(d, src, h, w, frame->pitch[0], pitch, video->rotation);
 }
 
 static void
 sna_copy_packed_data(struct sna_video *video,
 		     const struct sna_video_frame *frame,
-		     unsigned char *buf,
-		     unsigned char *dst,
-		     int srcPitch,
+		     const uint8_t *buf,
+		     uint8_t *dst,
 		     int top, int left, int h, int w)
 {
-	unsigned char *src;
-	unsigned char *s;
+	int pitch = frame->width << 1;
+	const uint8_t *src, *s;
 	int i, j;
 
-	src = buf + (top * srcPitch) + (left << 1);
+	src = buf + (top * pitch) + (left << 1);
 
 	switch (video->rotation) {
 	case RR_Rotate_0:
 		w <<= 1;
 		for (i = 0; i < h; i++) {
 			memcpy(dst, src, w);
-			src += srcPitch;
+			src += pitch;
 			dst += frame->pitch[0];
 		}
 		break;
@@ -377,25 +377,20 @@ sna_copy_packed_data(struct sna_video *video,
 			s = src;
 			for (j = 0; j < w; j++) {
 				/* Copy Y */
-				dst[(i + 0) + ((w - j - 1) * frame->pitch[0])] = *s++;
-				(void)*s++;
+				dst[(i + 0) + ((w - j - 1) * frame->pitch[0])] = *s;
+				s += 2;
 			}
-			src += srcPitch;
+			src += pitch;
 		}
 		h >>= 1;
-		src = buf + (top * srcPitch) + (left << 1);
+		src = buf + (top * pitch) + (left << 1);
 		for (i = 0; i < h; i += 2) {
 			for (j = 0; j < w; j += 2) {
 				/* Copy U */
-				dst[((i * 2) + 1) + ((w - j - 1) * frame->pitch[0])] =
-				    src[(j * 2) + 1 + (i * srcPitch)];
-				dst[((i * 2) + 1) + ((w - j - 2) * frame->pitch[0])] =
-				    src[(j * 2) + 1 + ((i + 1) * srcPitch)];
-				/* Copy V */
-				dst[((i * 2) + 3) + ((w - j - 1) * frame->pitch[0])] =
-				    src[(j * 2) + 3 + (i * srcPitch)];
-				dst[((i * 2) + 3) + ((w - j - 2) * frame->pitch[0])] =
-				    src[(j * 2) + 3 + ((i + 1) * srcPitch)];
+				dst[((i * 2) + 1) + ((w - j - 1) * frame->pitch[0])] = src[(j * 2) + 1 + (i * pitch)];
+				dst[((i * 2) + 1) + ((w - j - 2) * frame->pitch[0])] = src[(j * 2) + 1 + ((i + 1) * pitch)];
+				/* Copy V */ dst[((i * 2) + 3) + ((w - j - 1) * frame->pitch[0])] = src[(j * 2) + 3 + (i * pitch)];
+				dst[((i * 2) + 3) + ((w - j - 2) * frame->pitch[0])] = src[(j * 2) + 3 + ((i + 1) * pitch)];
 			}
 		}
 		break;
@@ -404,16 +399,12 @@ sna_copy_packed_data(struct sna_video *video,
 		for (i = 0; i < h; i++) {
 			s = src;
 			for (j = 0; j < w; j += 4) {
-				dst[(w - j - 4) + ((h - i - 1) * frame->pitch[0])] =
-				    *s++;
-				dst[(w - j - 3) + ((h - i - 1) * frame->pitch[0])] =
-				    *s++;
-				dst[(w - j - 2) + ((h - i - 1) * frame->pitch[0])] =
-				    *s++;
-				dst[(w - j - 1) + ((h - i - 1) * frame->pitch[0])] =
-				    *s++;
+				dst[(w - j - 4) + ((h - i - 1) * frame->pitch[0])] = *s++;
+				dst[(w - j - 3) + ((h - i - 1) * frame->pitch[0])] = *s++;
+				dst[(w - j - 2) + ((h - i - 1) * frame->pitch[0])] = *s++;
+				dst[(w - j - 1) + ((h - i - 1) * frame->pitch[0])] = *s++;
 			}
-			src += srcPitch;
+			src += pitch;
 		}
 		break;
 	case RR_Rotate_270:
@@ -422,27 +413,21 @@ sna_copy_packed_data(struct sna_video *video,
 			s = src;
 			for (j = 0; j < w; j++) {
 				/* Copy Y */
-				dst[(h - i - 2) + (j * frame->pitch[0])] = *s++;
-				(void)*s++;
+				dst[(h - i - 2) + (j * frame->pitch[0])] = *s;
+				s += 2;
 			}
-			src += srcPitch;
+			src += pitch;
 		}
 		h >>= 1;
-		src = buf + (top * srcPitch) + (left << 1);
+		src = buf + (top * pitch) + (left << 1);
 		for (i = 0; i < h; i += 2) {
 			for (j = 0; j < w; j += 2) {
 				/* Copy U */
-				dst[(((h - i) * 2) - 3) + (j * frame->pitch[0])] =
-				    src[(j * 2) + 1 + (i * srcPitch)];
-				dst[(((h - i) * 2) - 3) +
-				    ((j + 1) * frame->pitch[0])] =
-				    src[(j * 2) + 1 + ((i + 1) * srcPitch)];
+				dst[(((h - i) * 2) - 3) + (j * frame->pitch[0])] = src[(j * 2) + 1 + (i * pitch)];
+				dst[(((h - i) * 2) - 3) + ((j + 1) * frame->pitch[0])] = src[(j * 2) + 1 + ((i + 1) * pitch)];
 				/* Copy V */
-				dst[(((h - i) * 2) - 1) + (j * frame->pitch[0])] =
-				    src[(j * 2) + 3 + (i * srcPitch)];
-				dst[(((h - i) * 2) - 1) +
-				    ((j + 1) * frame->pitch[0])] =
-				    src[(j * 2) + 3 + ((i + 1) * srcPitch)];
+				dst[(((h - i) * 2) - 1) + (j * frame->pitch[0])] = src[(j * 2) + 3 + (i * pitch)];
+				dst[(((h - i) * 2) - 1) + ((j + 1) * frame->pitch[0])] = src[(j * 2) + 3 + ((i + 1) * pitch)];
 			}
 		}
 		break;
@@ -455,9 +440,9 @@ sna_video_copy_data(struct sna *sna,
 		    struct sna_video_frame *frame,
 		    int top, int left,
 		    int npixels, int nlines,
-		    unsigned char *buf)
+		    const uint8_t *buf)
 {
-	unsigned char *dst;
+	uint8_t *dst;
 
 	frame->bo = sna_video_buffer(sna, video, frame);
 	if (frame->bo == NULL)
@@ -500,22 +485,12 @@ sna_video_copy_data(struct sna *sna,
 	if (dst == NULL)
 		return FALSE;
 
-	if (is_planar_fourcc(frame->id)) {
-		int srcPitch = ALIGN(frame->width, 0x4);
-		int srcPitch2 = ALIGN((frame->width >> 1), 0x4);
-
-		sna_copy_planar_data(video, frame,
-				     buf, dst,
-				     srcPitch, srcPitch2,
-				     frame->height, top, left, nlines, npixels);
-	} else {
-		int srcPitch = frame->width << 1;
-
-		sna_copy_packed_data(video, frame,
-				     buf, dst,
-				     srcPitch,
+	if (is_planar_fourcc(frame->id))
+		sna_copy_planar_data(video, frame, buf, dst,
+				     top, left, nlines, npixels);
+	else
+		sna_copy_packed_data(video, frame, buf, dst,
 				     top, left, nlines, npixels);
-	}
 
 	munmap(dst, video->buf->size);
 	return TRUE;
diff --git a/src/sna/sna_video.h b/src/sna/sna_video.h
index bf4f6a4..41874b9 100644
--- a/src/sna/sna_video.h
+++ b/src/sna/sna_video.h
@@ -119,7 +119,7 @@ sna_video_copy_data(struct sna *sna,
 		    struct sna_video_frame *frame,
 		    int top, int left,
 		    int npixels, int nlines,
-		    unsigned char *buf);
+		    const uint8_t *buf);
 
 void sna_video_frame_fini(struct sna *sna,
 			  struct sna_video *video,


More information about the xorg-commit mailing list