pixman: Branch 'master' - 2 commits
Andrea Canciani
ranma42 at kemper.freedesktop.org
Wed Jun 9 08:32:01 PDT 2010
pixman/pixman-linear-gradient.c | 2
pixman/pixman-radial-gradient.c | 2
test/Makefile.am | 2
test/gradient-crash-test.c | 117 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 119 insertions(+), 4 deletions(-)
New commits:
commit 445eb6385f60d09058826b44894e17165c91381c
Author: Andrea Canciani <ranma42 at gmail.com>
Date: Wed Jun 9 16:35:37 2010 +0200
test: verify that gradients do not crash pixman
Test gradients under particular conditions (no stops, all the stops
at the same offset) to check that pixman does not misbehave.
diff --git a/test/Makefile.am b/test/Makefile.am
index d0019ef..20cb00f 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -10,6 +10,7 @@ TESTPROGRAMS = \
fetch-test \
oob-test \
window-test \
+ gradient-crash-test \
trap-crasher \
alphamap \
blitters-test \
@@ -19,6 +20,7 @@ TESTPROGRAMS = \
a1_trap_test_LDADD = $(TEST_LDADD)
fetch_test_LDADD = $(TEST_LDADD)
composite_LDADD = $(TEST_LDADD)
+gradient_crash_test_LDADD = $(TEST_LDADD)
trap_crasher_LDADD = $(TEST_LDADD)
oob_test_LDADD = $(TEST_LDADD)
window_test_LDADD = $(TEST_LDADD)
diff --git a/test/gradient-crash-test.c b/test/gradient-crash-test.c
new file mode 100644
index 0000000..804f83b
--- /dev/null
+++ b/test/gradient-crash-test.c
@@ -0,0 +1,117 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "pixman.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;
+ pixman_image_t *dest_img;
+ int i, j;
+
+ pixman_gradient_stop_t onestop[1] =
+ {
+ { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } },
+ };
+
+ pixman_gradient_stop_t subsetstops[2] =
+ {
+ { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } },
+ { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } },
+ };
+
+ pixman_gradient_stop_t stops01[2] =
+ {
+ { pixman_int_to_fixed (0), { 0xffff, 0xeeee, 0xeeee, 0xeeee } },
+ { 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 } }
+ };
+#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 */
+
+ dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
+ WIDTH, HEIGHT,
+ 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);
+
+ for (i = 0; i < 3; ++i)
+ {
+ pixman_gradient_stop_t *stops;
+ int num_stops;
+ if (i == 0)
+ {
+ stops = onestop;
+ num_stops = sizeof(onestop) / sizeof(onestop[0]);
+ }
+ else if (i == 1)
+ {
+ stops = subsetstops;
+ num_stops = sizeof(subsetstops) / sizeof(subsetstops[0]);
+ }
+ else
+ {
+ stops = stops01;
+ num_stops = sizeof(stops01) / sizeof(stops01[0]);
+ }
+
+ 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);
+
+ }
+ pixman_image_unref (src_img);
+ }
+
+ pixman_image_unref (dest_img);
+ free (dest);
+
+ return 0;
+}
commit de0320258167c24fc652d28f4aeca8713243323e
Author: Andrea Canciani <ranma42 at gmail.com>
Date: Tue Jun 8 20:36:15 2010 +0200
support single-stop gradients
Just like conical gradients, linear and radial gradients can now
have a single stop.
diff --git a/pixman/pixman-linear-gradient.c b/pixman/pixman-linear-gradient.c
index 47b2886..01588c1 100644
--- a/pixman/pixman-linear-gradient.c
+++ b/pixman/pixman-linear-gradient.c
@@ -265,8 +265,6 @@ pixman_image_create_linear_gradient (pixman_point_fixed_t * p1,
pixman_image_t *image;
linear_gradient_t *linear;
- return_val_if_fail (n_stops >= 2, NULL);
-
image = _pixman_image_allocate ();
if (!image)
diff --git a/pixman/pixman-radial-gradient.c b/pixman/pixman-radial-gradient.c
index 3cbede1..08d5f14 100644
--- a/pixman/pixman-radial-gradient.c
+++ b/pixman/pixman-radial-gradient.c
@@ -330,8 +330,6 @@ pixman_image_create_radial_gradient (pixman_point_fixed_t * inner,
pixman_image_t *image;
radial_gradient_t *radial;
- return_val_if_fail (n_stops >= 2, NULL);
-
image = _pixman_image_allocate ();
if (!image)
More information about the xorg-commit
mailing list