[Pixman] [PATCH 3/7] Extend gradient-crash-test

Søren Sandmann sandmann at daimi.au.dk
Tue Dec 14 12:02:13 PST 2010


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

Test the gradients with various transformations, and test cases where
the gradients are specified with two identical points.
---
 test/Makefile.am           |    5 ++-
 test/gradient-crash-test.c |  124 +++++++++++++++++++++++++++++--------------
 2 files changed, 87 insertions(+), 42 deletions(-)

diff --git a/test/Makefile.am b/test/Makefile.am
index 79a1223..4f950d9 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -14,6 +14,7 @@ TESTPROGRAMS =			\
 	trap-crasher		\
 	alpha-loop		\
 	scaling-crash-test	\
+	gradient-crash-test	\
 	alphamap		\
 	blitters-test		\
 	scaling-test		\
@@ -22,7 +23,6 @@ TESTPROGRAMS =			\
 
 a1_trap_test_LDADD = $(TEST_LDADD)
 fetch_test_LDADD = $(TEST_LDADD)
-gradient_crash_test_LDADD = $(TEST_LDADD)
 trap_crasher_LDADD = $(TEST_LDADD)
 oob_test_LDADD = $(TEST_LDADD)
 scaling_crash_test_LDADD = $(TEST_LDADD)
@@ -49,6 +49,9 @@ alpha_loop_SOURCES = alpha-loop.c utils.c utils.h
 composite_LDADD = $(TEST_LDADD)
 composite_SOURCES = composite.c utils.c utils.h
 
+gradient_crash_test_LDADD = $(TEST_LDADD)
+gradient_crash_test_SOURCES = gradient-crash-test.c utils.c utils.h
+
 # GTK using test programs
 
 if HAVE_GTK
diff --git a/test/gradient-crash-test.c b/test/gradient-crash-test.c
index 804f83b..395c469 100644
--- a/test/gradient-crash-test.c
+++ b/test/gradient-crash-test.c
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include "pixman.h"
+#include <fenv.h>
+#include "utils.h"
 
 int
 main (int argc, char **argv)
@@ -11,8 +12,14 @@ main (int argc, char **argv)
     uint32_t *dest = malloc (WIDTH * HEIGHT * 4);
     pixman_image_t *src_img;
     pixman_image_t *dest_img;
-    int i, j;
+    int i, j, k, p;
 
+    typedef struct
+    {
+	pixman_point_fixed_t p0;
+	pixman_point_fixed_t p1;
+    } point_pair_t;
+    
     pixman_gradient_stop_t onestop[1] =
 	{
 	    { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } },
@@ -30,29 +37,56 @@ main (int argc, char **argv)
 	    { pixman_int_to_fixed (1), { 0xffff, 0x1111, 0x1111, 0x1111 } }
 	};
 
-    pixman_point_fixed_t p1 = { pixman_double_to_fixed (0), 0 };
-    pixman_point_fixed_t p2 = { pixman_double_to_fixed (WIDTH / 8.),
-				pixman_int_to_fixed (0) };
-
-#if 0
-    pixman_transform_t trans = {
-	{ { pixman_double_to_fixed (2), pixman_double_to_fixed (0.5), pixman_double_to_fixed (-100), },
-	  { pixman_double_to_fixed (0), pixman_double_to_fixed (3), pixman_double_to_fixed (0), },
-	  { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) } 
-	}
-    };
-#else
-    pixman_transform_t trans = {
-	{ { pixman_fixed_1, 0, 0 },
-	  { 0, pixman_fixed_1, 0 },
-	  { 0, 0, pixman_fixed_1 } }
+    point_pair_t point_pairs [] =
+	{ { { pixman_double_to_fixed (0), 0 },
+	    { pixman_double_to_fixed (WIDTH / 8.), pixman_int_to_fixed (0) } },
+	  { { pixman_double_to_fixed (WIDTH / 2.0), pixman_double_to_fixed (HEIGHT / 2.0) },
+	    { pixman_double_to_fixed (WIDTH / 2.0), pixman_double_to_fixed (HEIGHT / 2.0) } }
+	};
+    
+    pixman_transform_t transformations[] = {
+	{
+	    { { pixman_double_to_fixed (2), pixman_double_to_fixed (0.5), pixman_double_to_fixed (-100), },
+	      { pixman_double_to_fixed (0), pixman_double_to_fixed (3), pixman_double_to_fixed (0), },
+	      { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) } 
+	    }
+	},
+	{
+	    { { pixman_double_to_fixed (1), pixman_double_to_fixed (0), pixman_double_to_fixed (0), },
+	      { pixman_double_to_fixed (0), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
+	      { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) } 
+	    }
+	},
+	{
+	    { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
+	      { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
+	      { pixman_double_to_fixed (2), pixman_double_to_fixed (1.000), pixman_double_to_fixed (1.0) } 
+	    }
+	},
+	{
+	    { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
+	      { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
+	      { pixman_double_to_fixed (0), pixman_double_to_fixed (0), pixman_double_to_fixed (0) } 
+	    }
+	},
+	{
+	    { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
+	      { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
+	      { pixman_double_to_fixed (2), pixman_double_to_fixed (-1), pixman_double_to_fixed (0) } 
+	    }
+	},
+	{
+	    { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (3), },
+	      { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
+	      { pixman_double_to_fixed (2), pixman_double_to_fixed (-1), pixman_double_to_fixed (0) } 
+	    }
+	},
     };
-#endif
-
-    pixman_point_fixed_t c_inner;
-    pixman_point_fixed_t c_outer;
+    
     pixman_fixed_t r_inner;
     pixman_fixed_t r_outer;
+
+    enable_fp_exceptions();
     
     for (i = 0; i < WIDTH * HEIGHT; ++i)
 	dest[i] = 0x4f00004f; /* pale blue */
@@ -62,10 +96,6 @@ main (int argc, char **argv)
 					 dest,
 					 WIDTH * 4);
 
-    c_inner.x = pixman_double_to_fixed (50.0);
-    c_inner.y = pixman_double_to_fixed (50.0);
-    c_outer.x = pixman_double_to_fixed (50.0);
-    c_outer.y = pixman_double_to_fixed (50.0);
     r_inner = 0;
     r_outer = pixman_double_to_fixed (50.0);
     
@@ -73,6 +103,7 @@ main (int argc, char **argv)
     {
 	pixman_gradient_stop_t *stops;
         int num_stops;
+
 	if (i == 0)
 	{
 	    stops = onestop;
@@ -91,23 +122,34 @@ main (int argc, char **argv)
 	
 	for (j = 0; j < 3; ++j)
 	{
-	    if (j == 0)
-	        src_img = pixman_image_create_conical_gradient (&c_inner, r_inner,
-								stops, num_stops);
-	    else if (j == 1)
-	        src_img = pixman_image_create_radial_gradient  (&c_inner, &c_outer,
-								r_inner, r_outer,
-								stops, num_stops);
-	    else
-	        src_img = pixman_image_create_linear_gradient  (&p1, &p2,
-								stops, num_stops);
-	    pixman_image_set_transform (src_img, &trans);
-	    pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NONE);
-	    pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img,
-				    0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT);
+	    for (p = 0; p < ARRAY_LENGTH (point_pairs); ++p)
+	    {
+		point_pair_t *pair = &(point_pairs[p]);
+
+		if (j == 0)
+		    src_img = pixman_image_create_conical_gradient (&(pair->p0), r_inner,
+								    stops, num_stops);
+		else if (j == 1)
+		    src_img = pixman_image_create_radial_gradient  (&(pair->p0), &(pair->p1),
+								    r_inner, r_outer,
+								    stops, num_stops);
+		else
+		    src_img = pixman_image_create_linear_gradient  (&(pair->p0), &(pair->p1),
+								    stops, num_stops);
+		
+		for (k = 0; k < ARRAY_LENGTH (transformations); ++k)
+		{
+		    pixman_image_set_transform (src_img, &transformations[k]);
+		    
+		    pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NONE);
+		    pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img,
+					    0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT);
+		}
+
+		pixman_image_unref (src_img);
+	    }
 
 	}
-	pixman_image_unref (src_img);
     }
 
     pixman_image_unref (dest_img);
-- 
1.6.0.6



More information about the Pixman mailing list