[Pixman] [PATCH 2/2] rework the gradient test to make use of the implementation switching stuff
Chris Toshok
toshok at gmail.com
Mon May 17 19:39:54 PDT 2010
compare (using memcmp) results using the "general" implementation as the
baseline. right now it just uses sse2/mmx/fast/general implementations.
---
test/gradient-test.c | 132 ++++++++++++++++++++++++++++++++++++--------------
1 files changed, 96 insertions(+), 36 deletions(-)
diff --git a/test/gradient-test.c b/test/gradient-test.c
index fc84844..6e354ec 100644
--- a/test/gradient-test.c
+++ b/test/gradient-test.c
@@ -1,16 +1,32 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "pixman.h"
#include "gtk-utils.h"
-int
-main (int argc, char **argv)
-{
#define WIDTH 400
#define HEIGHT 200
- uint32_t *dest = malloc (WIDTH * HEIGHT * 4);
- pixman_image_t *src_img;
+typedef enum {
+ LINEAR,
+ RADIAL,
+ CONICAL,
+ N_GRADIENTS
+} gradient_type;
+
+char *gradients[] = { "linear", "radial", "conical" };
+
+char *repeats[] = { "none", "normal", "pad", "repeat" };
+int n_repeats = sizeof (repeats) / sizeof (repeats[0]);
+char *imps[] = {"general", "fast", "sse2", "mmx"};
+int n_imps = sizeof (imps) / sizeof (imps[0]);
+
+int tests_run = 0;
+
+void
+draw_gradient (gradient_type g, pixman_repeat_t repeat, pixman_bool_t
transform, uint32_t *dest)
+{
+ pixman_image_t *src_img = NULL;
pixman_image_t *dest_img;
int i;
pixman_gradient_stop_t stops[2] =
@@ -21,26 +37,19 @@ main (int argc, char **argv)
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 } }
- };
-#endif
pixman_point_fixed_t c_inner;
pixman_point_fixed_t c_outer;
pixman_fixed_t r_inner;
pixman_fixed_t r_outer;
-
+
for (i = 0; i < WIDTH * HEIGHT; ++i)
dest[i] = 0x4f00004f; /* pale blue */
@@ -56,34 +65,85 @@ main (int argc, char **argv)
r_inner = 0;
r_outer = pixman_double_to_fixed (50.0);
- src_img = pixman_image_create_conical_gradient (&c_inner, r_inner,
- stops, 2);
-#if 0
- src_img = pixman_image_create_conical_gradient (&c_inner, r_inner,
- stops, 2);
- src_img = pixman_image_create_linear_gradient (&c_inner, &c_outer,
- r_inner, r_outer,
- stops, 2);
-#endif
-
- src_img = pixman_image_create_linear_gradient (&p1, &p2,
- stops, 2);
+ switch (g) {
+ case CONICAL:
+ src_img = pixman_image_create_conical_gradient (&c_inner, r_inner,
+ stops, 2);
+ break;
+ case RADIAL:
+ src_img = pixman_image_create_radial_gradient (&c_inner, &c_outer,
+ r_inner, r_outer,
+ stops, 2);
+ break;
+ case LINEAR:
+ src_img = pixman_image_create_linear_gradient (&p1, &p2,
+ stops, 2);
+ break;
+ default:
+ break;
+ }
- pixman_image_set_transform (src_img, &trans);
- pixman_image_set_repeat (src_img, PIXMAN_REPEAT_PAD);
+ if (transform)
+ pixman_image_set_transform (src_img, &trans);
+ pixman_image_set_repeat (src_img, repeat);
pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img,
0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT);
-
- printf ("0, 0: %x\n", dest[0]);
- printf ("10, 10: %x\n", dest[10 * 10 + 10]);
- printf ("w, h: %x\n", dest[(HEIGHT - 1) * 100 + (WIDTH - 1)]);
-
- show_image (dest_img);
-
+
pixman_image_unref (src_img);
pixman_image_unref (dest_img);
- free (dest);
+}
+
+pixman_bool_t
+test_gradients (uint32_t *default_dest, uint32_t *imp_dest,
pixman_bool_t transform, gradient_type g)
+{
+ int repeat;
+ int imp;
+ pixman_bool_t rv = TRUE;
+
+ for (repeat = 0; repeat < n_repeats; repeat ++) {
+ _pixman_debug_set_implementation ("general");
+ draw_gradient (g, (pixman_repeat_t)repeat, transform, default_dest);
+
+ for (imp = 0; imp < n_imps; imp++) {
+ _pixman_debug_set_implementation (imps[imp]);
+
+ draw_gradient (g, (pixman_repeat_t)repeat, transform, imp_dest);
+
+ tests_run ++;
+
+ if (memcmp (default_dest, imp_dest, WIDTH * HEIGHT * 4)) {
+ printf ("FAILED (gradient = %s, repeat = %s implementation
= %s, transformed = %s)\n",
+ gradients[g],
+ repeats[repeat],
+ imps[imp],
+ transform ? "true" : "false");
+ rv = FALSE;
+ }
+ }
+ }
+
+ return rv;
+}
+
+int
+main (int argc, char **argv)
+{
+ uint32_t *default_dest = malloc (WIDTH * HEIGHT * 4);
+ uint32_t *imp_dest = malloc (WIDTH * HEIGHT * 4);
+ pixman_bool_t pass = TRUE;
+ int g;
+
+ for (g = 0; g < N_GRADIENTS; g ++) {
+ pass = test_gradients (default_dest, imp_dest, FALSE,
(gradient_type)g) && pass;
+ pass = test_gradients (default_dest, imp_dest, TRUE,
(gradient_type)g) && pass;
+ }
+
+ if (pass)
+ printf ("all %d tests passed\n", tests_run);
+
+ free (default_dest);
+ free (imp_dest);
return 0;
}
--
1.6.4.2
More information about the Pixman
mailing list