diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2009-07-24 13:51:23 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2009-08-29 08:08:28 +0100 |
commit | 9d51c03bad5f10257e248f43375062902482c0c4 (patch) | |
tree | 9cb2893ef2340889596b3883ee6f8082d14d5192 /src/cairo-region.c | |
parent | f8bb3617c3a7ec598c42eff1f8562e3ccc95127f (diff) |
[traps] Compute extents on demand.
Diffstat (limited to 'src/cairo-region.c')
-rw-r--r-- | src/cairo-region.c | 47 |
1 files changed, 18 insertions, 29 deletions
diff --git a/src/cairo-region.c b/src/cairo-region.c index d6fff7f7..9983481c 100644 --- a/src/cairo-region.c +++ b/src/cairo-region.c @@ -144,23 +144,28 @@ cairo_region_create (void) } slim_hidden_def (cairo_region_create); -cairo_status_t -_cairo_region_init_rectangles (cairo_region_t *region, - const cairo_rectangle_int_t *rects, - int count) +cairo_region_t * +cairo_region_create_rectangles (const 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_status_t status; + cairo_region_t *region; int i; - status = CAIRO_STATUS_SUCCESS; - CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 0); + region = _cairo_malloc (sizeof (cairo_region_t)); + if (unlikely (region == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_region_t *) &_cairo_region_nil; + } if (count > ARRAY_LENGTH (stack_pboxes)) { pboxes = _cairo_malloc_ab (count, sizeof (pixman_box32_t)); - if (unlikely (pboxes == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); + if (unlikely (pboxes == NULL)) { + free (region); + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_region_t *) &_cairo_region_nil; + } } for (i = 0; i < count; i++) { @@ -170,35 +175,19 @@ _cairo_region_init_rectangles (cairo_region_t *region, pboxes[i].y2 = rects[i].y + rects[i].height; } - if (! pixman_region32_init_rects (®ion->rgn, pboxes, count)) - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + i = pixman_region32_init_rects (®ion->rgn, pboxes, count); if (pboxes != stack_pboxes) free (pboxes); - return region->status = status; -} - -cairo_region_t * -cairo_region_create_rectangles (const cairo_rectangle_int_t *rects, - int count) -{ - cairo_region_t *region; - cairo_status_t status; - - region = _cairo_malloc (sizeof (cairo_region_t)); - if (unlikely (region == NULL)) { + if (unlikely (i == 0)) { + free (region); _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); return (cairo_region_t *) &_cairo_region_nil; } - status = _cairo_region_init_rectangles (region, rects, count); - if (unlikely (status)) { - cairo_region_destroy (region); - return (cairo_region_t *) &_cairo_region_nil; - } - CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 1); + region->status = CAIRO_STATUS_SUCCESS; return region; } slim_hidden_def (cairo_region_create_rectangles); |