[Pixman] [PATCH 6/8] perfstat: Don't call pixman_fill() directly inside pixman_image_composite()

Taekyun Kim podain77 at gmail.com
Mon Sep 19 07:08:24 PDT 2011


From: Taekyun Kim <tkq.kim at samsung.com>

We can avoid accumulating perfstat data twice for some solid fill
functions.
---
 pixman/pixman-fast-path.c |  360 +++++++++++++++++++++++----------------------
 pixman/pixman-sse2.c      |    8 +-
 2 files changed, 191 insertions(+), 177 deletions(-)

diff --git a/pixman/pixman-fast-path.c b/pixman/pixman-fast-path.c
index 1431b4d..14ad07c 100644
--- a/pixman/pixman-fast-path.c
+++ b/pixman/pixman-fast-path.c
@@ -1114,6 +1114,187 @@ fast_composite_over_n_1_0565 (pixman_implementation_t *imp,
  * Simple bitblt
  */
 
+#ifdef WORDS_BIGENDIAN
+#define A1_FILL_MASK(n, offs) (((1 << (n)) - 1) << (32 - (offs) - (n)))
+#else
+#define A1_FILL_MASK(n, offs) (((1 << (n)) - 1) << (offs))
+#endif
+
+static force_inline void
+pixman_fill1_line (uint32_t *dst, int offs, int width, int v)
+{
+    if (offs)
+    {
+	int leading_pixels = 32 - offs;
+	if (leading_pixels >= width)
+	{
+	    if (v)
+		*dst |= A1_FILL_MASK (width, offs);
+	    else
+		*dst &= ~A1_FILL_MASK (width, offs);
+	    return;
+	}
+	else
+	{
+	    if (v)
+		*dst++ |= A1_FILL_MASK (leading_pixels, offs);
+	    else
+		*dst++ &= ~A1_FILL_MASK (leading_pixels, offs);
+	    width -= leading_pixels;
+	}
+    }
+    while (width >= 32)
+    {
+	if (v)
+	    *dst++ = 0xFFFFFFFF;
+	else
+	    *dst++ = 0;
+	width -= 32;
+    }
+    if (width > 0)
+    {
+	if (v)
+	    *dst |= A1_FILL_MASK (width, 0);
+	else
+	    *dst &= ~A1_FILL_MASK (width, 0);
+    }
+}
+
+static void
+pixman_fill1 (uint32_t *bits,
+              int       stride,
+              int       x,
+              int       y,
+              int       width,
+              int       height,
+              uint32_t  xor)
+{
+    uint32_t *dst = bits + y * stride + (x >> 5);
+    int offs = x & 31;
+
+    if (xor & 1)
+    {
+	while (height--)
+	{
+	    pixman_fill1_line (dst, offs, width, 1);
+	    dst += stride;
+	}
+    }
+    else
+    {
+	while (height--)
+	{
+	    pixman_fill1_line (dst, offs, width, 0);
+	    dst += stride;
+	}
+    }
+}
+
+static void
+pixman_fill8 (uint32_t *bits,
+              int       stride,
+              int       x,
+              int       y,
+              int       width,
+              int       height,
+              uint32_t xor)
+{
+    int byte_stride = stride * (int) sizeof (uint32_t);
+    uint8_t *dst = (uint8_t *) bits;
+    uint8_t v = xor & 0xff;
+    int i;
+
+    dst = dst + y * byte_stride + x;
+
+    while (height--)
+    {
+	for (i = 0; i < width; ++i)
+	    dst[i] = v;
+
+	dst += byte_stride;
+    }
+}
+
+static void
+pixman_fill16 (uint32_t *bits,
+               int       stride,
+               int       x,
+               int       y,
+               int       width,
+               int       height,
+               uint32_t xor)
+{
+    int short_stride =
+	(stride * (int)sizeof (uint32_t)) / (int)sizeof (uint16_t);
+    uint16_t *dst = (uint16_t *)bits;
+    uint16_t v = xor & 0xffff;
+    int i;
+
+    dst = dst + y * short_stride + x;
+
+    while (height--)
+    {
+	for (i = 0; i < width; ++i)
+	    dst[i] = v;
+
+	dst += short_stride;
+    }
+}
+
+static void
+pixman_fill32 (uint32_t *bits,
+               int       stride,
+               int       x,
+               int       y,
+               int       width,
+               int       height,
+               uint32_t  xor)
+{
+    int i;
+
+    bits = bits + y * stride + x;
+
+    while (height--)
+    {
+	for (i = 0; i < width; ++i)
+	    bits[i] = xor;
+
+	bits += stride;
+    }
+}
+
+static pixman_bool_t
+pixman_fill_fast_path (uint32_t    *bits,
+		       int	    stride,
+		       int	    bpp,
+		       int	    x,
+		       int	    y,
+		       int	    width,
+		       int	    height,
+		       uint32_t	    xor)
+{
+    switch (bpp)
+    {
+    case 1:
+	pixman_fill1 (bits, stride, x, y, width, height, xor);
+	return TRUE;
+
+    case 8:
+	pixman_fill8 (bits, stride, x, y, width, height, xor);
+	return TRUE;
+
+    case 16:
+	pixman_fill16 (bits, stride, x, y, width, height, xor);
+	return TRUE;
+
+    case 32:
+	pixman_fill32 (bits, stride, x, y, width, height, xor);
+	return TRUE;
+    }
+
+    return FALSE;
+}
+
 static void
 fast_composite_solid_fill (pixman_implementation_t *imp,
                            pixman_composite_info_t *info)
@@ -1137,11 +1318,11 @@ fast_composite_solid_fill (pixman_implementation_t *imp,
 	src = CONVERT_8888_TO_0565 (src);
     }
 
-    pixman_fill (dest_image->bits.bits, dest_image->bits.rowstride,
-                 PIXMAN_FORMAT_BPP (dest_image->bits.format),
-                 dest_x, dest_y,
-                 width, height,
-                 src);
+    pixman_fill_fast_path (dest_image->bits.bits, dest_image->bits.rowstride,
+			   PIXMAN_FORMAT_BPP (dest_image->bits.format),
+			   dest_x, dest_y,
+			   width, height,
+			   src);
 }
 
 static void
@@ -1790,155 +1971,6 @@ static const pixman_fast_path_t c_fast_paths[] =
     {   PIXMAN_OP_NONE	},
 };
 
-#ifdef WORDS_BIGENDIAN
-#define A1_FILL_MASK(n, offs) (((1 << (n)) - 1) << (32 - (offs) - (n)))
-#else
-#define A1_FILL_MASK(n, offs) (((1 << (n)) - 1) << (offs))
-#endif
-
-static force_inline void
-pixman_fill1_line (uint32_t *dst, int offs, int width, int v)
-{
-    if (offs)
-    {
-	int leading_pixels = 32 - offs;
-	if (leading_pixels >= width)
-	{
-	    if (v)
-		*dst |= A1_FILL_MASK (width, offs);
-	    else
-		*dst &= ~A1_FILL_MASK (width, offs);
-	    return;
-	}
-	else
-	{
-	    if (v)
-		*dst++ |= A1_FILL_MASK (leading_pixels, offs);
-	    else
-		*dst++ &= ~A1_FILL_MASK (leading_pixels, offs);
-	    width -= leading_pixels;
-	}
-    }
-    while (width >= 32)
-    {
-	if (v)
-	    *dst++ = 0xFFFFFFFF;
-	else
-	    *dst++ = 0;
-	width -= 32;
-    }
-    if (width > 0)
-    {
-	if (v)
-	    *dst |= A1_FILL_MASK (width, 0);
-	else
-	    *dst &= ~A1_FILL_MASK (width, 0);
-    }
-}
-
-static void
-pixman_fill1 (uint32_t *bits,
-              int       stride,
-              int       x,
-              int       y,
-              int       width,
-              int       height,
-              uint32_t  xor)
-{
-    uint32_t *dst = bits + y * stride + (x >> 5);
-    int offs = x & 31;
-
-    if (xor & 1)
-    {
-	while (height--)
-	{
-	    pixman_fill1_line (dst, offs, width, 1);
-	    dst += stride;
-	}
-    }
-    else
-    {
-	while (height--)
-	{
-	    pixman_fill1_line (dst, offs, width, 0);
-	    dst += stride;
-	}
-    }
-}
-
-static void
-pixman_fill8 (uint32_t *bits,
-              int       stride,
-              int       x,
-              int       y,
-              int       width,
-              int       height,
-              uint32_t xor)
-{
-    int byte_stride = stride * (int) sizeof (uint32_t);
-    uint8_t *dst = (uint8_t *) bits;
-    uint8_t v = xor & 0xff;
-    int i;
-
-    dst = dst + y * byte_stride + x;
-
-    while (height--)
-    {
-	for (i = 0; i < width; ++i)
-	    dst[i] = v;
-
-	dst += byte_stride;
-    }
-}
-
-static void
-pixman_fill16 (uint32_t *bits,
-               int       stride,
-               int       x,
-               int       y,
-               int       width,
-               int       height,
-               uint32_t xor)
-{
-    int short_stride =
-	(stride * (int)sizeof (uint32_t)) / (int)sizeof (uint16_t);
-    uint16_t *dst = (uint16_t *)bits;
-    uint16_t v = xor & 0xffff;
-    int i;
-
-    dst = dst + y * short_stride + x;
-
-    while (height--)
-    {
-	for (i = 0; i < width; ++i)
-	    dst[i] = v;
-
-	dst += short_stride;
-    }
-}
-
-static void
-pixman_fill32 (uint32_t *bits,
-               int       stride,
-               int       x,
-               int       y,
-               int       width,
-               int       height,
-               uint32_t  xor)
-{
-    int i;
-
-    bits = bits + y * stride + x;
-
-    while (height--)
-    {
-	for (i = 0; i < width; ++i)
-	    bits[i] = xor;
-
-	bits += stride;
-    }
-}
-
 static pixman_bool_t
 fast_path_fill (pixman_implementation_t *imp,
                 uint32_t *               bits,
@@ -1950,28 +1982,10 @@ fast_path_fill (pixman_implementation_t *imp,
                 int                      height,
                 uint32_t		 xor)
 {
-    switch (bpp)
+    if (!pixman_fill_fast_path (bits, stride, bpp, x, y, width, height, xor))
     {
-    case 1:
-	pixman_fill1 (bits, stride, x, y, width, height, xor);
-	break;
-
-    case 8:
-	pixman_fill8 (bits, stride, x, y, width, height, xor);
-	break;
-
-    case 16:
-	pixman_fill16 (bits, stride, x, y, width, height, xor);
-	break;
-
-    case 32:
-	pixman_fill32 (bits, stride, x, y, width, height, xor);
-	break;
-
-    default:
 	return _pixman_implementation_fill (
 	    imp->delegate, bits, stride, bpp, x, y, width, height, xor);
-	break;
     }
 
     return TRUE;
diff --git a/pixman/pixman-sse2.c b/pixman/pixman-sse2.c
index 2be0a73..431ea6e 100644
--- a/pixman/pixman-sse2.c
+++ b/pixman/pixman-sse2.c
@@ -4083,8 +4083,8 @@ sse2_composite_in_n_8 (pixman_implementation_t *imp,
 
     if (src == 0x00)
     {
-	pixman_fill (dest_image->bits.bits, dest_image->bits.rowstride,
-		     8, dest_x, dest_y, width, height, src);
+	pixman_fill_sse2 (dest_image->bits.bits, dest_image->bits.rowstride,
+			  8, dest_x, dest_y, width, height, src);
 
 	return;
     }
@@ -4318,8 +4318,8 @@ sse2_composite_add_n_8 (pixman_implementation_t *imp,
 
     if (src == 0xff)
     {
-	pixman_fill (dest_image->bits.bits, dest_image->bits.rowstride,
-		     8, dest_x, dest_y, width, height, 0xff);
+	pixman_fill_sse2 (dest_image->bits.bits, dest_image->bits.rowstride,
+			  8, dest_x, dest_y, width, height, 0xff);
 
 	return;
     }
-- 
1.7.1



More information about the Pixman mailing list