[Intel-gfx] [PATCH 07/22] Xv: introduce planar memcpy helper

Daniel Vetter daniel.vetter at ffwll.ch
Fri Jul 3 10:11:43 CEST 2009


Reduced 3 copies of the same code to one.

Just a resend, rebased on top of current master because of conflicts
with Barry Scott's patch.

Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
---
 src/i830_video.c |  176 +++++++++++++++++-------------------------------------
 1 files changed, 54 insertions(+), 122 deletions(-)

diff --git a/src/i830_video.c b/src/i830_video.c
index ba8c40e..7c23d2e 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -1358,6 +1358,55 @@ I830CopyPackedData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 	drm_intel_bo_unmap(pPriv->buf);
 }
 
+static void i830_memcpy_plane(unsigned char *dst, unsigned char *src,
+		int height, int width,
+		int dstPitch, int srcPitch, Rotation rotation)
+{
+    int i, j = 0;
+    unsigned char *s;
+
+    switch (rotation) {
+    case RR_Rotate_0:
+	/* optimise for the case of no clipping */
+	if (srcPitch == dstPitch && srcPitch == width)
+	    memcpy (dst, src, srcPitch * height);
+	else
+	    for (i = 0; i < height; i++) {
+		memcpy(dst, src, width);
+		src += srcPitch;
+		dst += dstPitch;
+	    }
+	break;
+    case RR_Rotate_90:
+	for (i = 0; i < height; i++) {
+	    s = src;
+	    for (j = 0; j < width; j++) {
+		dst[(i) + ((width - j - 1) * dstPitch)] = *s++;
+	    }
+	    src += srcPitch;
+	}
+	break;
+    case RR_Rotate_180:
+	for (i = 0; i < height; i++) {
+	    s = src;
+	    for (j = 0; j < width; j++) {
+		dst[(width - j - 1) + ((height - i - 1) * dstPitch)] = *s++;
+	    }
+	    src += srcPitch;
+	}
+	break;
+    case RR_Rotate_270:
+	for (i = 0; i < height; i++) {
+	    s = src;
+	    for (j = 0; j < width; j++) {
+		dst[(height - i - 1) + (j * dstPitch)] = *s++;
+	    }
+	    src += srcPitch;
+	}
+	break;
+    }
+}
+
 static void
 I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 		   unsigned char *buf, int srcPitch,
@@ -1365,9 +1414,7 @@ I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 		   int h, int w, int id)
 {
     I830Ptr pI830 = I830PTR(pScrn);
-    int i, j = 0;
     unsigned char *src1, *src2, *src3, *dst_base, *dst1, *dst2, *dst3;
-    unsigned char *s;
     int dstPitch2 = dstPitch << 1;
 
 #if 0
@@ -1397,46 +1444,7 @@ I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
     else
 	dst1 = dst_base + pPriv->YBuf1offset;
 
-    switch (pPriv->rotation) {
-    case RR_Rotate_0:
-       /* optimise for the case of no clipping */
-	if (srcPitch == dstPitch2 && srcPitch == w)
-	    memcpy (dst1, src1, srcPitch * h);
-	else
-	    for (i = 0; i < h; i++) {
-		memcpy(dst1, src1, w);
-		src1 += srcPitch;
-		dst1 += dstPitch2;
-	    }
-	break;
-    case RR_Rotate_90:
-	for (i = 0; i < h; i++) {
-	    s = src1;
-	    for (j = 0; j < w; j++) {
-		dst1[(i) + ((w - j - 1) * dstPitch2)] = *s++;
-	    }
-	    src1 += srcPitch;
-	}
-	break;
-    case RR_Rotate_180:
-	for (i = 0; i < h; i++) {
-	    s = src1;
-	    for (j = 0; j < w; j++) {
-		dst1[(w - j - 1) + ((h - i - 1) * dstPitch2)] = *s++;
-	    }
-	    src1 += srcPitch;
-	}
-	break;
-    case RR_Rotate_270:
-	for (i = 0; i < h; i++) {
-	    s = src1;
-	    for (j = 0; j < w; j++) {
-		dst1[(h - i - 1) + (j * dstPitch2)] = *s++;
-	    }
-	    src1 += srcPitch;
-	}
-	break;
-    }
+    i830_memcpy_plane(dst1, src1, h, w, dstPitch2, srcPitch, pPriv->rotation);
 
     /* Copy V data for YV12, or U data for I420 */
     src2 = buf +                            /* start of YUV data */
@@ -1460,46 +1468,8 @@ I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 	    dst2 = dst_base + pPriv->VBuf1offset;
     }
 
-    switch (pPriv->rotation) {
-    case RR_Rotate_0:
-       /* optimise for the case of no clipping */
-	if (srcPitch2 == dstPitch && srcPitch2 == (w/2))
-	    memcpy (dst2, src2, h/2 * srcPitch2);
-	else
-	    for (i = 0; i < h / 2; i++) {
-		memcpy(dst2, src2, w / 2);
-		src2 += srcPitch2;
-		dst2 += dstPitch;
-	    }
-	break;
-    case RR_Rotate_90:
-	for (i = 0; i < (h/2); i++) {
-	    s = src2;
-	    for (j = 0; j < (w/2); j++) {
-		dst2[(i) + (((w/2) - j - 1) * (dstPitch))] = *s++;
-	    }
-	    src2 += srcPitch2;
-	}
-	break;
-    case RR_Rotate_180:
-	for (i = 0; i < (h/2); i++) {
-	    s = src2;
-	    for (j = 0; j < (w/2); j++) {
-		dst2[((w/2) - j - 1) + (((h/2) - i - 1) * dstPitch)] = *s++;
-	    }
-	    src2 += srcPitch2;
-	}
-	break;
-    case RR_Rotate_270:
-	for (i = 0; i < (h/2); i++) {
-	    s = src2;
-	    for (j = 0; j < (w/2); j++) {
-		dst2[((h/2) - i - 1) + (j * dstPitch)] = *s++;
-	    }
-	    src2 += srcPitch2;
-	}
-	break;
-    }
+    i830_memcpy_plane(dst2, src2, h/2, w/2,
+		    dstPitch, srcPitch2, pPriv->rotation);
 
     /* Copy U data for YV12, or V data for I420 */
     src3 = buf +                            /* start of YUV data */
@@ -1523,46 +1493,8 @@ I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 	    dst3 = dst_base + pPriv->UBuf1offset;
     }
 
-    switch (pPriv->rotation) {
-    case RR_Rotate_0:
-       /* optimise for the case of no clipping */
-	if (srcPitch2 == dstPitch && srcPitch2 == (w/2))
-	    memcpy (dst3, src3, srcPitch2 * h/2);
-	else
-	    for (i = 0; i < h / 2; i++) {
-		memcpy(dst3, src3, w / 2);
-		src3 += srcPitch2;
-		dst3 += dstPitch;
-	    }
-	break;
-    case RR_Rotate_90:
-	for (i = 0; i < (h/2); i++) {
-	    s = src3;
-	    for (j = 0; j < (w/2); j++) {
-		dst3[(i) + (((w/2) - j - 1) * (dstPitch))] = *s++;
-	    }
-	    src3 += srcPitch2;
-	}
-	break;
-    case RR_Rotate_180:
-	for (i = 0; i < (h/2); i++) {
-	    s = src3;
-	    for (j = 0; j < (w/2); j++) {
-		dst3[((w/2) - j - 1) + (((h/2) - i - 1) * dstPitch)] = *s++;
-	    }
-	    src3 += srcPitch2;
-	}
-	break;
-    case RR_Rotate_270:
-	for (i = 0; i < (h/2); i++) {
-	    s = src3;
-	    for (j = 0; j < (w/2); j++) {
-		dst3[((h/2) - i - 1) + (j * dstPitch)] = *s++;
-	    }
-	    src3 += srcPitch2;
-	}
-	break;
-    }
+    i830_memcpy_plane(dst3, src3, h/2, w/2,
+		    dstPitch, srcPitch2, pPriv->rotation);
 
     if (pPriv->textured)
 	drm_intel_bo_unmap(pPriv->buf);
-- 
1.6.3.3




More information about the Intel-gfx mailing list