summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <sandmann@daimi.au.dk>2009-02-18 08:01:19 -0500
committerSøren Sandmann Pedersen <sandmann@daimi.au.dk>2009-03-28 18:02:57 -0400
commitbf6d9bc1758ac1971485b6565d29934d6b06bef2 (patch)
treee42df01c3c449819ae60966cebafa7a2569c7e22
parente6d82afcab01cc91b88185abc8d1bfb9df5c2c19 (diff)
[region] Delete cairo_region_create_rectangles()
It was only used in _cairo_traps_extract_region() which could be simplified significantly by calling cairo_region_union_rect() repeatedly instead.
-rw-r--r--src/cairo-region.c44
-rw-r--r--src/cairo-traps.c60
-rw-r--r--src/cairo.h4
-rw-r--r--src/cairoint.h1
4 files changed, 23 insertions, 86 deletions
diff --git a/src/cairo-region.c b/src/cairo-region.c
index 5d01d370..bc6598ac 100644
--- a/src/cairo-region.c
+++ b/src/cairo-region.c
@@ -74,50 +74,6 @@ cairo_region_create_rect (cairo_rectangle_int_t *rect)
return region;
}
-cairo_region_t *
-cairo_region_create_rectangles (cairo_rectangle_int_t *rects,
- int count)
-{
- pixman_box32_t stack_pboxes[CAIRO_STACK_ARRAY_LENGTH (pixman_box32_t)];
- pixman_box32_t *pboxes = stack_pboxes;
- cairo_region_t *region;
- int i;
-
- region = _cairo_malloc (sizeof (cairo_region_t));
-
- if (!region)
- return (cairo_region_t *)&_cairo_region_nil;
-
- region->status = CAIRO_STATUS_SUCCESS;
-
- if (count > ARRAY_LENGTH (stack_pboxes)) {
- pboxes = _cairo_malloc_ab (count, sizeof (pixman_box32_t));
-
- if (unlikely (pboxes == NULL)) {
- free (region);
- return (cairo_region_t *)&_cairo_region_nil;
- }
- }
-
- for (i = 0; i < count; i++) {
- pboxes[i].x1 = rects[i].x;
- pboxes[i].y1 = rects[i].y;
- pboxes[i].x2 = rects[i].x + rects[i].width;
- pboxes[i].y2 = rects[i].y + rects[i].height;
- }
-
- if (! pixman_region32_init_rects (&region->rgn, pboxes, count)) {
- free (region);
-
- region = (cairo_region_t *)&_cairo_region_nil;
- }
-
- if (pboxes != stack_pboxes)
- free (pboxes);
-
- return region;
-}
-
void
cairo_region_destroy (cairo_region_t *region)
{
diff --git a/src/cairo-traps.c b/src/cairo-traps.c
index 73bb124e..2fc2fac2 100644
--- a/src/cairo-traps.c
+++ b/src/cairo-traps.c
@@ -610,17 +610,12 @@ cairo_int_status_t
_cairo_traps_extract_region (const cairo_traps_t *traps,
cairo_region_t **region)
{
- cairo_rectangle_int_t stack_rects[CAIRO_STACK_ARRAY_LENGTH (cairo_rectangle_int_t)];
- cairo_rectangle_int_t *rects = stack_rects;
- int i, rect_count;
- cairo_int_status_t status;
-
- if (traps->num_traps == 0) {
- *region = cairo_region_create ();
- return CAIRO_STATUS_SUCCESS;
- }
+ cairo_int_status_t status = CAIRO_STATUS_SUCCESS;
+ cairo_region_t *r;
+ int i;
- for (i = 0; i < traps->num_traps; i++) {
+ for (i = 0; i < traps->num_traps; i++)
+ {
if (traps->traps[i].left.p1.x != traps->traps[i].left.p2.x ||
traps->traps[i].right.p1.x != traps->traps[i].right.p2.x ||
! _cairo_fixed_is_integer (traps->traps[i].top) ||
@@ -632,17 +627,12 @@ _cairo_traps_extract_region (const cairo_traps_t *traps,
}
}
- if (traps->num_traps > ARRAY_LENGTH (stack_rects)) {
- rects = _cairo_malloc_ab (traps->num_traps,
- sizeof (cairo_rectangle_int_t));
-
- if (unlikely (rects == NULL))
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
- }
-
- rect_count = 0;
-
- for (i = 0; i < traps->num_traps; i++) {
+ r = cairo_region_create ();
+
+ for (i = 0; i < traps->num_traps; i++)
+ {
+ cairo_rectangle_int_t rect;
+
int x1 = _cairo_fixed_integer_part (traps->traps[i].left.p1.x);
int y1 = _cairo_fixed_integer_part (traps->traps[i].top);
int x2 = _cairo_fixed_integer_part (traps->traps[i].right.p1.x);
@@ -654,26 +644,22 @@ _cairo_traps_extract_region (const cairo_traps_t *traps,
if (x1 == x2 || y1 == y2)
continue;
- rects[rect_count].x = x1;
- rects[rect_count].y = y1;
- rects[rect_count].width = x2 - x1;
- rects[rect_count].height = y2 - y1;
+ rect.x = x1;
+ rect.y = y1;
+ rect.width = x2 - x1;
+ rect.height = y2 - y1;
- rect_count++;
+ status = cairo_region_union_rect (r, &rect);
+ if (unlikely (status))
+ {
+ cairo_region_destroy (r);
+ r = NULL;
+ break;
+ }
}
- *region = cairo_region_create_rectangles (rects, rect_count);
- status = cairo_region_status (*region);
+ *region = r;
- if (rects != stack_rects)
- free (rects);
-
- if (unlikely (status))
- {
- cairo_region_destroy (*region);
- *region = NULL;
- }
-
return status;
}
diff --git a/src/cairo.h b/src/cairo.h
index adf34b97..16b203dc 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -2371,10 +2371,6 @@ cairo_public cairo_region_t *
cairo_region_create_rect (cairo_rectangle_int_t *rect);
cairo_public cairo_region_t *
-cairo_region_create_rectangles (cairo_rectangle_int_t *rects,
- int count);
-
-cairo_public cairo_region_t *
cairo_region_copy (cairo_region_t *original);
cairo_public void
diff --git a/src/cairoint.h b/src/cairoint.h
index 9d02d350..fbf8e350 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -2696,7 +2696,6 @@ slim_hidden_proto (cairo_user_to_device_distance);
slim_hidden_proto (cairo_version_string);
slim_hidden_proto (cairo_region_create);
slim_hidden_proto (cairo_region_create_rect);
-slim_hidden_proto (cairo_region_create_rectangles);
slim_hidden_proto (cairo_region_copy);
slim_hidden_proto (cairo_region_destroy);
slim_hidden_proto (cairo_region_status);