pixman: Branch 'master' - 2 commits
Søren Sandmann Pedersen
sandmann at kemper.freedesktop.org
Tue Jul 7 21:28:02 PDT 2009
pixman/pixman-region.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++---
test/region-test.c | 31 +++++++++++++++++++++++++++---
2 files changed, 75 insertions(+), 6 deletions(-)
New commits:
commit 4e41905bacbf533740e999ba79e0620f358c0597
Author: Søren Sandmann Pedersen <sandmann at redhat.com>
Date: Wed Jul 8 00:08:49 2009 -0400
Eliminate empty rectangles in pixman_region_init_rects().
Otherwise they show up in the validated regions.
diff --git a/pixman/pixman-region.c b/pixman/pixman-region.c
index 59b8ac2..0e1791c 100644
--- a/pixman/pixman-region.c
+++ b/pixman/pixman-region.c
@@ -2088,7 +2088,9 @@ PIXMAN_EXPORT pixman_bool_t
PREFIX(_init_rects) (region_type_t *region,
box_type_t *boxes, int count)
{
- int overlap;
+ box_type_t *rects;
+ int displacement;
+ int i;
/* if it's 1, then we just want to set the extents, so call
* the existing method. */
@@ -2114,11 +2116,53 @@ PREFIX(_init_rects) (region_type_t *region,
if (!pixman_rect_alloc(region, count))
return FALSE;
+ rects = PIXREGION_RECTS(region);
+
/* Copy in the rects */
- memcpy (PIXREGION_RECTS(region), boxes, sizeof(box_type_t) * count);
+ memcpy (rects, boxes, sizeof(box_type_t) * count);
region->data->numRects = count;
+ /* Eliminate empty rectangles */
+ displacement = 0;
+
+ for (i = 0; i < count; ++i)
+ {
+ box_type_t *box = &rects[i];
+
+ if (box->x1 == box->x2 || box->y1 == box->y2)
+ displacement++;
+ else if (displacement)
+ rects[i - displacement] = rects[i];
+ }
+
+ region->data->numRects -= displacement;
+
+ /* If eliminating empty rectangles caused there
+ * to be only 0 or 1 rectangles, deal with that.
+ */
+ if (region->data->numRects == 0)
+ {
+ freeData (region);
+ region->data = NULL;
+
+ good (region);
+
+ return TRUE;
+ }
+
+ if (region->data->numRects == 1)
+ {
+ region->extents = rects[0];
+
+ freeData (region);
+ region->data = NULL;
+
+ good (region);
+
+ return TRUE;
+ }
+
/* Validate */
region->extents.x1 = region->extents.x2 = 0;
- return validate (region, &overlap);
+ return validate (region, &i);
}
diff --git a/test/region-test.c b/test/region-test.c
index 3e00dec..26e5338 100644
--- a/test/region-test.c
+++ b/test/region-test.c
@@ -34,10 +34,15 @@ main ()
pixman_region32_init_rects (&r1, boxes, 2);
b = pixman_region32_rectangles (&r1, &i);
+
+ assert (i == 1);
+
while (--i)
{
assert (b[i].x1 < b[i].x2);
assert (b[i].y1 < b[i].y2);
}
+
+ return 0;
}
commit 967ff0bdc7f46806b7a6d16332ad39cf2c1f01c1
Author: Søren Sandmann Pedersen <sandmann at redhat.com>
Date: Tue Jul 7 22:55:32 2009 -0400
Add an initialization with an empty rectangle to region-test.c
This should produce a valid region without empty rectangles in
it. Currently it doesn't.
diff --git a/test/region-test.c b/test/region-test.c
index e214e9b..3e00dec 100644
--- a/test/region-test.c
+++ b/test/region-test.c
@@ -3,21 +3,41 @@
#include <stdio.h>
#include "pixman.h"
-/* This used to go into an infinite loop before pixman-region.c
- * was fixed to not use explict "short" variables
- */
int
main ()
{
pixman_region32_t r1;
pixman_region32_t r2;
pixman_region32_t r3;
+ pixman_box32_t boxes[] = {
+ { 10, 10, 20, 20 },
+ { 30, 30, 30, 40 },
+ };
+ int i;
+ pixman_box32_t *b;
+ /* This used to go into an infinite loop before pixman-region.c
+ * was fixed to not use explict "short" variables
+ */
pixman_region32_init_rect (&r1, 0, 0, 20, 64000);
pixman_region32_init_rect (&r2, 0, 0, 20, 64000);
pixman_region32_init_rect (&r3, 0, 0, 20, 64000);
pixman_region32_subtract (&r1, &r2, &r3);
+
+ /* This would produce a region containing an empty
+ * rectangle in it. Such regions are considered malformed,
+ * but using an empty rectangle for initialization should
+ * work.
+ */
+ pixman_region32_init_rects (&r1, boxes, 2);
+
+ b = pixman_region32_rectangles (&r1, &i);
+ while (--i)
+ {
+ assert (b[i].x1 < b[i].x2);
+ assert (b[i].y1 < b[i].y2);
+ }
}
More information about the xorg-commit
mailing list