[Pixman] [PATCH 07/11] fast: Replace the fetcher_info_t table with a pixman_iter_info_t table

Søren Sandmann Pedersen soren.sandmann at gmail.com
Wed May 22 06:45:16 PDT 2013


Similar to the SSE2 and MMX patches, this commit replaces a table of
fetcher_info_t with a table of pixman_iter_info_t, and similar to the
noop patch, both fast_src_iter_init() and fast_dest_iter_init() are
now doing exactly the same thing, so their code can be shared in a new
function called fast_iter_init_common().
---
 pixman/pixman-fast-path.c | 107 +++++++++++++++++++---------------------------
 1 file changed, 45 insertions(+), 62 deletions(-)

diff --git a/pixman/pixman-fast-path.c b/pixman/pixman-fast-path.c
index 247aea6..047675c 100644
--- a/pixman/pixman-fast-path.c
+++ b/pixman/pixman-fast-path.c
@@ -2261,46 +2261,55 @@ fast_write_back_r5g6b5 (pixman_iter_t *iter)
     }
 }
 
-typedef struct
+static void
+iter_init_bits_stride (pixman_iter_t *iter, const pixman_iter_info_t *info)
 {
-    pixman_format_code_t	format;
-    pixman_iter_get_scanline_t	get_scanline;
-    pixman_iter_write_back_t	write_back;
-} fetcher_info_t;
+    pixman_image_t *image = iter->image;
+    uint8_t *b = (uint8_t *)image->bits.bits;
+    int s = image->bits.rowstride * 4;
+
+    iter->bits = b + s * iter->y + iter->x * PIXMAN_FORMAT_BPP (info->format) / 8;
+    iter->stride = s;
+}
+
+#define IMAGE_FLAGS							\
+    (FAST_PATH_STANDARD_FLAGS | FAST_PATH_ID_TRANSFORM |		\
+     FAST_PATH_BITS_IMAGE | FAST_PATH_SAMPLES_COVER_CLIP_NEAREST)
 
-static const fetcher_info_t fetchers[] =
+static const pixman_iter_info_t fast_iters[] = 
 {
-    { PIXMAN_r5g6b5, fast_fetch_r5g6b5, fast_write_back_r5g6b5 },
-    { PIXMAN_null }
+    { PIXMAN_r5g6b5, IMAGE_FLAGS, ITER_NARROW | ITER_SRC,
+      iter_init_bits_stride, fast_fetch_r5g6b5, NULL },
+
+    { PIXMAN_r5g6b5, FAST_PATH_STD_DEST_FLAGS,
+      ITER_NARROW | ITER_DEST,
+      iter_init_bits_stride, fast_fetch_r5g6b5, fast_write_back_r5g6b5 },
+    
+    { PIXMAN_r5g6b5, FAST_PATH_STD_DEST_FLAGS,
+      ITER_NARROW | ITER_DEST | ITER_IGNORE_RGB | ITER_IGNORE_ALPHA,
+      iter_init_bits_stride, fast_dest_fetch_noop, fast_write_back_r5g6b5 },
+
+    { PIXMAN_null },
 };
 
 static pixman_bool_t
-fast_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
+fast_iter_init_common (pixman_implementation_t *imp, pixman_iter_t *iter)
 {
-    pixman_image_t *image = iter->image;
-
-#define FLAGS								\
-    (FAST_PATH_STANDARD_FLAGS | FAST_PATH_ID_TRANSFORM |		\
-     FAST_PATH_BITS_IMAGE | FAST_PATH_SAMPLES_COVER_CLIP_NEAREST)
+    const pixman_iter_info_t *info;
 
-    if ((iter->iter_flags & ITER_NARROW)			&&
-	(iter->image_flags & FLAGS) == FLAGS)
+    for (info = fast_iters; info->format != PIXMAN_null; ++info)
     {
-	const fetcher_info_t *f;
-
-	for (f = &fetchers[0]; f->format != PIXMAN_null; f++)
+	if ((info->format == PIXMAN_any ||
+	     info->format == iter->image->common.extended_format_code)	 &&
+	    (info->image_flags & iter->image_flags) == info->image_flags &&
+	    (info->iter_flags & iter->iter_flags) == info->iter_flags)
 	{
-	    if (image->common.extended_format_code == f->format)
-	    {
-		uint8_t *b = (uint8_t *)image->bits.bits;
-		int s = image->bits.rowstride * 4;
-
-		iter->bits = b + s * iter->y + iter->x * PIXMAN_FORMAT_BPP (f->format) / 8;
-		iter->stride = s;
+	    iter->get_scanline = info->get_scanline;
+	    iter->write_back = info->write_back;
 
-		iter->get_scanline = f->get_scanline;
-		return TRUE;
-	    }
+	    if (info->initializer)
+		info->initializer (iter, info);
+	    return TRUE;
 	}
     }
 
@@ -2308,42 +2317,16 @@ fast_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
 }
 
 static pixman_bool_t
-fast_dest_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
+fast_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
 {
-    pixman_image_t *image = iter->image;
-
-    if ((iter->iter_flags & ITER_NARROW)		&&
-	(iter->image_flags & FAST_PATH_STD_DEST_FLAGS) == FAST_PATH_STD_DEST_FLAGS)
-    {
-	const fetcher_info_t *f;
-
-	for (f = &fetchers[0]; f->format != PIXMAN_null; f++)
-	{
-	    if (image->common.extended_format_code == f->format)
-	    {
-		uint8_t *b = (uint8_t *)image->bits.bits;
-		int s = image->bits.rowstride * 4;
-
-		iter->bits = b + s * iter->y + iter->x * PIXMAN_FORMAT_BPP (f->format) / 8;
-		iter->stride = s;
-
-		if ((iter->iter_flags & (ITER_IGNORE_RGB | ITER_IGNORE_ALPHA)) ==
-		    (ITER_IGNORE_RGB | ITER_IGNORE_ALPHA))
-		{
-		    iter->get_scanline = fast_dest_fetch_noop;
-		}
-		else
-		{
-		    iter->get_scanline = f->get_scanline;
-		}
-		iter->write_back = f->write_back;
-		return TRUE;
-	    }
-	}
-    }
-    return FALSE;
+    return fast_iter_init_common (imp, iter);
 }
 
+static pixman_bool_t
+fast_dest_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
+{
+    return fast_iter_init_common (imp, iter);
+}
 
 pixman_implementation_t *
 _pixman_implementation_create_fast_path (pixman_implementation_t *fallback)
-- 
1.7.11.7



More information about the Pixman mailing list