[Pixman] [PATCH 4/7] Move delegation of src/dest iter init into pixman-implementation.c

Søren Sandmann sandmann at cs.au.dk
Sat Sep 15 16:54:31 PDT 2012


From: Søren Sandmann Pedersen <ssp at redhat.com>

Instead of relying on each implementation to delegate when an iterator
can't be initialized, change the type of iterator initializers to
boolean and make pixman-implementation.c do the delegation whenever an
iterator initializer returns FALSE.
---
 pixman/pixman-general.c        |   10 +++++++-
 pixman/pixman-implementation.c |   42 ++++++++++++++++++++-------------------
 pixman/pixman-mmx.c            |    6 ++--
 pixman/pixman-noop.c           |   14 ++++++++----
 pixman/pixman-private.h        |    8 +++---
 pixman/pixman-sse2.c           |    6 ++--
 6 files changed, 49 insertions(+), 37 deletions(-)

diff --git a/pixman/pixman-general.c b/pixman/pixman-general.c
index 6c6bda0..42a84a0 100644
--- a/pixman/pixman-general.c
+++ b/pixman/pixman-general.c
@@ -37,7 +37,7 @@
 #include <string.h>
 #include "pixman-private.h"
 
-static void
+static pixman_bool_t
 general_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
 {
     pixman_image_t *image = iter->image;
@@ -54,18 +54,24 @@ general_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
 	_pixman_bits_image_src_iter_init (image, iter);
     else
 	_pixman_log_error (FUNC, "Pixman bug: unknown image type\n");
+
+    return TRUE;
 }
 
-static void
+static pixman_bool_t
 general_dest_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
 {
     if (iter->image->type == BITS)
     {
 	_pixman_bits_image_dest_iter_init (iter->image, iter);
+
+	return TRUE;
     }
     else
     {
 	_pixman_log_error (FUNC, "Trying to write to a non-writable image");
+
+	return FALSE;
     }
 }
 
diff --git a/pixman/pixman-implementation.c b/pixman/pixman-implementation.c
index 5607f9d..18da162 100644
--- a/pixman/pixman-implementation.c
+++ b/pixman/pixman-implementation.c
@@ -27,20 +27,6 @@
 #include <stdlib.h>
 #include "pixman-private.h"
 
-static void
-delegate_src_iter_init (pixman_implementation_t *imp,
-			pixman_iter_t *	         iter)
-{
-    imp->delegate->src_iter_init (imp->delegate, iter);
-}
-
-static void
-delegate_dest_iter_init (pixman_implementation_t *imp,
-			 pixman_iter_t *	  iter)
-{
-    imp->delegate->dest_iter_init (imp->delegate, iter);
-}
-
 pixman_implementation_t *
 _pixman_implementation_create (pixman_implementation_t *delegate,
 			       const pixman_fast_path_t *fast_paths)
@@ -63,8 +49,8 @@ _pixman_implementation_create (pixman_implementation_t *delegate,
      */
     imp->blt = NULL;
     imp->fill = NULL;
-    imp->src_iter_init = delegate_src_iter_init;
-    imp->dest_iter_init = delegate_dest_iter_init;
+    imp->src_iter_init = NULL;
+    imp->dest_iter_init = NULL;
 
     imp->fast_paths = fast_paths;
 
@@ -173,7 +159,7 @@ _pixman_implementation_fill (pixman_implementation_t *imp,
     return FALSE;
 }
 
-void
+pixman_bool_t
 _pixman_implementation_src_iter_init (pixman_implementation_t	*imp,
 				      pixman_iter_t             *iter,
 				      pixman_image_t		*image,
@@ -194,10 +180,18 @@ _pixman_implementation_src_iter_init (pixman_implementation_t	*imp,
     iter->iter_flags = iter_flags;
     iter->image_flags = image_flags;
 
-    (*imp->src_iter_init) (imp, iter);
+    while (imp)
+    {
+	if (imp->src_iter_init && (*imp->src_iter_init) (imp, iter))
+	    return TRUE;
+
+	imp = imp->delegate;
+    }
+
+    return FALSE;
 }
 
-void
+pixman_bool_t
 _pixman_implementation_dest_iter_init (pixman_implementation_t	*imp,
 				       pixman_iter_t            *iter,
 				       pixman_image_t		*image,
@@ -218,7 +212,15 @@ _pixman_implementation_dest_iter_init (pixman_implementation_t	*imp,
     iter->iter_flags = iter_flags;
     iter->image_flags = image_flags;
 
-    (*imp->dest_iter_init) (imp, iter);
+    while (imp)
+    {
+	if (imp->dest_iter_init && (*imp->dest_iter_init) (imp, iter))
+	    return TRUE;
+
+	imp = imp->delegate;
+    }
+
+    return FALSE;
 }
 
 pixman_bool_t
diff --git a/pixman/pixman-mmx.c b/pixman/pixman-mmx.c
index 5deb9a4..c02595d 100644
--- a/pixman/pixman-mmx.c
+++ b/pixman/pixman-mmx.c
@@ -3914,7 +3914,7 @@ static const fetcher_info_t fetchers[] =
     { PIXMAN_null }
 };
 
-static void
+static pixman_bool_t
 mmx_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
 {
     pixman_image_t *image = iter->image;
@@ -3939,12 +3939,12 @@ mmx_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
 		iter->stride = s;
 
 		iter->get_scanline = f->get_scanline;
-		return;
+		return TRUE;
 	    }
 	}
     }
 
-    imp->delegate->src_iter_init (imp->delegate, iter);
+    return FALSE;
 }
 
 static const pixman_fast_path_t mmx_fast_paths[] =
diff --git a/pixman/pixman-noop.c b/pixman/pixman-noop.c
index 7b017e8..7b9759f 100644
--- a/pixman/pixman-noop.c
+++ b/pixman/pixman-noop.c
@@ -59,7 +59,7 @@ get_scanline_null (pixman_iter_t *iter, const uint32_t *mask)
     return NULL;
 }
 
-static void
+static pixman_bool_t
 noop_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
 {
     pixman_image_t *image = iter->image;
@@ -117,11 +117,13 @@ noop_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
     }
     else
     {
-	(* imp->delegate->src_iter_init) (imp->delegate, iter);
+	return FALSE;
     }
+
+    return TRUE;
 }
 
-static void
+static pixman_bool_t
 noop_dest_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
 {
     pixman_image_t *image = iter->image;
@@ -138,10 +140,12 @@ noop_dest_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
 
 	iter->get_scanline = _pixman_iter_get_scanline_noop;
 	iter->write_back = dest_write_back_direct;
+
+	return TRUE;
     }
     else
     {
-	(* imp->delegate->dest_iter_init) (imp->delegate, iter);
+	return FALSE;
     }
 }
 
@@ -156,7 +160,7 @@ _pixman_implementation_create_noop (pixman_implementation_t *fallback)
 {
     pixman_implementation_t *imp =
 	_pixman_implementation_create (fallback, noop_fast_paths);
-
+ 
     imp->src_iter_init = noop_src_iter_init;
     imp->dest_iter_init = noop_dest_iter_init;
 
diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
index dbfa829..fe5f7c6 100644
--- a/pixman/pixman-private.h
+++ b/pixman/pixman-private.h
@@ -445,8 +445,8 @@ typedef pixman_bool_t (*pixman_fill_func_t) (pixman_implementation_t *imp,
 					     int                      width,
 					     int                      height,
 					     uint32_t                 xor);
-typedef void (*pixman_iter_init_func_t) (pixman_implementation_t *imp,
-                                         pixman_iter_t           *iter);
+typedef pixman_bool_t (*pixman_iter_init_func_t) (pixman_implementation_t *imp,
+						  pixman_iter_t           *iter);
 
 void _pixman_setup_combiner_functions_32 (pixman_implementation_t *imp);
 void _pixman_setup_combiner_functions_64 (pixman_implementation_t *imp);
@@ -521,7 +521,7 @@ _pixman_implementation_fill (pixman_implementation_t *imp,
                              int                      height,
                              uint32_t                 xor);
 
-void
+pixman_bool_t
 _pixman_implementation_src_iter_init (pixman_implementation_t       *imp,
 				      pixman_iter_t                 *iter,
 				      pixman_image_t                *image,
@@ -533,7 +533,7 @@ _pixman_implementation_src_iter_init (pixman_implementation_t       *imp,
 				      iter_flags_t                   flags,
 				      uint32_t                       image_flags);
 
-void
+pixman_bool_t
 _pixman_implementation_dest_iter_init (pixman_implementation_t       *imp,
 				       pixman_iter_t                 *iter,
 				       pixman_image_t                *image,
diff --git a/pixman/pixman-sse2.c b/pixman/pixman-sse2.c
index 428db73..e273a95 100644
--- a/pixman/pixman-sse2.c
+++ b/pixman/pixman-sse2.c
@@ -6024,7 +6024,7 @@ static const fetcher_info_t fetchers[] =
     { PIXMAN_null }
 };
 
-static void
+static pixman_bool_t
 sse2_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
 {
     pixman_image_t *image = iter->image;
@@ -6049,12 +6049,12 @@ sse2_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
 		iter->stride = s;
 
 		iter->get_scanline = f->get_scanline;
-		return;
+		return TRUE;
 	    }
 	}
     }
 
-    imp->delegate->src_iter_init (imp->delegate, iter);
+    return FALSE;
 }
 
 #if defined(__GNUC__) && !defined(__x86_64__) && !defined(__amd64__)
-- 
1.7.4



More information about the Pixman mailing list