summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Hasselmann <mathias@pergamaunz.(none)>2007-03-13 23:38:20 +0100
committerBehdad Esfahbod <behdad@behdad.org>2007-04-08 21:10:12 -0400
commit0e7df34e07d7816b29c1ac1f67608b87c5e0efc2 (patch)
tree2cc4832f61bb1cea40d813a9fa9f2b32e06643de
parentced7b4a4ab4b5a8d639bfca0dd5db38f1ae4825d (diff)
Make region of cairo_clip_t static
-rw-r--r--src/cairo-clip-private.h3
-rw-r--r--src/cairo-clip.c87
-rw-r--r--src/cairo-surface.c4
3 files changed, 49 insertions, 45 deletions
diff --git a/src/cairo-clip-private.h b/src/cairo-clip-private.h
index d2811d5df..a2e8d9bc6 100644
--- a/src/cairo-clip-private.h
+++ b/src/cairo-clip-private.h
@@ -72,7 +72,8 @@ struct _cairo_clip {
/*
* A clip region that can be placed in the surface
*/
- pixman_region16_t *region;
+ pixman_region16_t region;
+ cairo_bool_t has_region;
/*
* If the surface supports path clipping, we store the list of
* clipping paths that has been set here as a linked list.
diff --git a/src/cairo-clip.c b/src/cairo-clip.c
index efecd89ef..81f41739e 100644
--- a/src/cairo-clip.c
+++ b/src/cairo-clip.c
@@ -61,7 +61,7 @@ _cairo_clip_init (cairo_clip_t *clip, cairo_surface_t *target)
clip->serial = 0;
- clip->region = NULL;
+ clip->has_region = FALSE;
clip->path = NULL;
}
@@ -74,9 +74,10 @@ _cairo_clip_fini (cairo_clip_t *clip)
clip->serial = 0;
- if (clip->region)
- pixman_region_destroy (clip->region);
- clip->region = NULL;
+ if (clip->has_region) {
+ pixman_region_uninit (&clip->region);
+ clip->has_region = FALSE;
+ }
_cairo_clip_path_destroy (clip->path);
clip->path = NULL;
@@ -92,11 +93,11 @@ _cairo_clip_init_copy (cairo_clip_t *clip, cairo_clip_t *other)
clip->serial = other->serial;
- if (other->region == NULL) {
- clip->region = other->region;
+ if (other->has_region) {
+ pixman_region_copy (&clip->region, &other->region);
+ clip->has_region = TRUE;
} else {
- clip->region = pixman_region_create ();
- pixman_region_copy (clip->region, other->region);
+ clip->has_region = FALSE;
}
clip->path = _cairo_clip_path_reference (other->path);
@@ -111,9 +112,10 @@ _cairo_clip_reset (cairo_clip_t *clip)
clip->serial = 0;
- if (clip->region)
- pixman_region_destroy (clip->region);
- clip->region = NULL;
+ if (clip->has_region) {
+ pixman_region_uninit (&clip->region);
+ clip->has_region = FALSE;
+ }
_cairo_clip_path_destroy (clip->path);
clip->path = NULL;
@@ -170,7 +172,7 @@ _cairo_clip_intersect_to_rectangle (cairo_clip_t *clip,
return status;
}
- if (clip->region) {
+ if (clip->has_region) {
pixman_region16_t *intersection;
cairo_status_t status = CAIRO_STATUS_SUCCESS;
pixman_region_status_t pixman_status;
@@ -180,7 +182,7 @@ _cairo_clip_intersect_to_rectangle (cairo_clip_t *clip,
return CAIRO_STATUS_NO_MEMORY;
pixman_status = pixman_region_intersect (intersection,
- clip->region,
+ &clip->region,
intersection);
if (pixman_status == PIXMAN_REGION_STATUS_SUCCESS)
_cairo_region_extents_rectangle (intersection, rectangle);
@@ -210,8 +212,8 @@ _cairo_clip_intersect_to_region (cairo_clip_t *clip,
/* Intersect clip path into region. */
}
- if (clip->region)
- pixman_region_intersect (region, clip->region, region);
+ if (clip->has_region)
+ pixman_region_intersect (region, &clip->region, region);
if (clip->surface) {
pixman_region16_t *clip_rect;
@@ -329,42 +331,43 @@ _cairo_clip_path_destroy (cairo_clip_path_t *clip_path)
free (clip_path);
}
-static cairo_status_t
+static cairo_int_status_t
_cairo_clip_intersect_region (cairo_clip_t *clip,
cairo_traps_t *traps,
cairo_surface_t *target)
{
- pixman_region16_t *region;
- cairo_status_t status;
+ pixman_region16_t region;
+ cairo_int_status_t status;
if (clip->mode != CAIRO_CLIP_MODE_REGION)
return CAIRO_INT_STATUS_UNSUPPORTED;
status = _cairo_traps_extract_region (traps, &region);
+
if (status)
return status;
- if (region == NULL)
- return CAIRO_INT_STATUS_UNSUPPORTED;
-
status = CAIRO_STATUS_SUCCESS;
- if (clip->region == NULL) {
- clip->region = region;
+
+ if (!clip->has_region) {
+ pixman_region_copy (&clip->region, &region);
+ clip->has_region = TRUE;
} else {
- pixman_region16_t *intersection = pixman_region_create();
-
- if (pixman_region_intersect (intersection,
- clip->region, region)
- == PIXMAN_REGION_STATUS_SUCCESS) {
- pixman_region_destroy (clip->region);
- clip->region = intersection;
- } else {
- status = CAIRO_STATUS_NO_MEMORY;
- }
- pixman_region_destroy (region);
+ pixman_region16_t intersection;
+ pixman_region_init (&intersection, NULL);
+
+ if (PIXMAN_REGION_STATUS_SUCCESS ==
+ pixman_region_intersect (&intersection, &clip->region, &region)) {
+ pixman_region_copy (&clip->region, &intersection);
+ } else {
+ status = CAIRO_STATUS_NO_MEMORY;
+ }
+
+ pixman_region_uninit (&intersection);
}
clip->serial = _cairo_surface_allocate_clip_serial (target);
+ pixman_region_uninit (&region);
return status;
}
@@ -509,8 +512,8 @@ _cairo_clip_translate (cairo_clip_t *clip,
cairo_fixed_t tx,
cairo_fixed_t ty)
{
- if (clip->region) {
- pixman_region_translate (clip->region,
+ if (clip->has_region) {
+ pixman_region_translate (&clip->region,
_cairo_fixed_integer_part (tx),
_cairo_fixed_integer_part (ty));
}
@@ -560,9 +563,9 @@ _cairo_clip_init_deep_copy (cairo_clip_t *clip,
/* We should reapply the original clip path in this case, and let
* whatever the right handling is happen */
} else {
- if (other->region) {
- clip->region = pixman_region_create ();
- pixman_region_copy (clip->region, other->region);
+ if (other->has_region) {
+ pixman_region_copy (&clip->region, &other->region);
+ clip->has_region = TRUE;
}
if (other->surface) {
@@ -613,16 +616,16 @@ _cairo_clip_copy_rectangle_list (cairo_clip_t *clip, cairo_gstate_t *gstate)
if (clip->path || clip->surface)
return (cairo_rectangle_list_t*) &_cairo_rectangles_not_representable;
- n_boxes = clip->region ? pixman_region_num_rects (clip->region) : 1;
+ n_boxes = clip->has_region ? pixman_region_num_rects (&clip->region) : 1;
rectangles = malloc (sizeof (cairo_rectangle_t)*n_boxes);
if (rectangles == NULL)
return (cairo_rectangle_list_t*) &_cairo_rectangles_nil;
- if (clip->region) {
+ if (clip->has_region) {
pixman_box16_t *boxes;
int i;
- boxes = pixman_region_rects (clip->region);
+ boxes = pixman_region_rects (&clip->region);
for (i = 0; i < n_boxes; ++i) {
if (!_cairo_clip_rect_to_user(gstate, boxes[i].x1, boxes[i].y1,
boxes[i].x2 - boxes[i].x1,
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 115824d44..9b69b6589 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -1704,9 +1704,9 @@ _cairo_surface_set_clip (cairo_surface_t *surface, cairo_clip_t *clip)
clip->path,
clip->serial);
- if (clip->region)
+ if (clip->has_region)
return _cairo_surface_set_clip_region (surface,
- clip->region,
+ &clip->region,
clip->serial);
}