sse2: Replace the fetcher_info_t table with a pixman_iter_info_t table
authorSøren Sandmann Pedersen <ssp@redhat.com>
Tue, 21 May 2013 07:29:09 +0000 (03:29 -0400)
committerSøren Sandmann Pedersen <ssp@redhat.com>
Wed, 22 May 2013 13:43:20 +0000 (09:43 -0400)
Similar to the changes to noop, put all the iterators into a table of
pixman_iter_info_t and then do a generic search of that table during
iterator initialization.

pixman/pixman-sse2.c

index 863bc18..344cc46 100644 (file)
@@ -6340,47 +6340,53 @@ sse2_fetch_a8 (pixman_iter_t *iter, const uint32_t *mask)
     return iter->buffer;
 }
 
-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;
-} 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;
+}
 
-static const fetcher_info_t fetchers[] =
+#define IMAGE_FLAGS                                                    \
+    (FAST_PATH_STANDARD_FLAGS | FAST_PATH_ID_TRANSFORM |               \
+     FAST_PATH_BITS_IMAGE | FAST_PATH_SAMPLES_COVER_CLIP_NEAREST)
+
+static const pixman_iter_info_t sse2_iters[] = 
 {
-    { PIXMAN_x8r8g8b8,         sse2_fetch_x8r8g8b8 },
-    { PIXMAN_r5g6b5,           sse2_fetch_r5g6b5 },
-    { PIXMAN_a8,               sse2_fetch_a8 },
-    { PIXMAN_null }
+    { PIXMAN_x8r8g8b8, IMAGE_FLAGS, ITER_NARROW,
+      iter_init_bits_stride, sse2_fetch_x8r8g8b8, NULL
+    },
+    { PIXMAN_r5g6b5, IMAGE_FLAGS, ITER_NARROW,
+      iter_init_bits_stride, sse2_fetch_r5g6b5, NULL
+    },
+    { PIXMAN_a8, IMAGE_FLAGS, ITER_NARROW,
+      iter_init_bits_stride, sse2_fetch_a8, NULL
+    },
+    { PIXMAN_null },
 };
 
 static pixman_bool_t
 sse2_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
 {
-    pixman_image_t *image = iter->image;
+    const pixman_iter_info_t *info;
 
-#define FLAGS                                                          \
-    (FAST_PATH_STANDARD_FLAGS | FAST_PATH_ID_TRANSFORM |               \
-     FAST_PATH_BITS_IMAGE | FAST_PATH_SAMPLES_COVER_CLIP_NEAREST)
-
-    if ((iter->iter_flags & ITER_NARROW)                       &&
-       (iter->image_flags & FLAGS) == FLAGS)
+    for (info = sse2_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;
        }
     }