diff options
author | Søren Sandmann Pedersen <sandmann@redhat.com> | 2009-07-08 00:08:49 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <sandmann@redhat.com> | 2009-07-08 00:08:49 -0400 |
commit | 4e41905bacbf533740e999ba79e0620f358c0597 (patch) | |
tree | f6e07d04cc2fe4222cb01fdc8cfe9219e0f93244 /pixman/pixman-region.c | |
parent | 967ff0bdc7f46806b7a6d16332ad39cf2c1f01c1 (diff) |
Eliminate empty rectangles in pixman_region_init_rects().
Otherwise they show up in the validated regions.
Diffstat (limited to 'pixman/pixman-region.c')
-rw-r--r-- | pixman/pixman-region.c | 50 |
1 files changed, 47 insertions, 3 deletions
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); } |