diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2011-07-14 21:19:54 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2011-07-19 21:14:34 +0100 |
commit | b132fae5e843c329d1414d1a65b2e8d66b99852f (patch) | |
tree | 7df5e21300eefe3abcc30616b22d7f5d3248b4d4 /src/cairo-boxes.c | |
parent | f58ade7bace8c82d0ea6740f56d227696181d616 (diff) | |
download | cairo-b132fae5e843c329d1414d1a65b2e8d66b99852f.tar.gz |
clip: Rudimentary support for clip-polygon extraction
Step 1, fix the failings sighted recently by tracking clip-boxes as an
explicit property of the clipping and of composition.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'src/cairo-boxes.c')
-rw-r--r-- | src/cairo-boxes.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/cairo-boxes.c b/src/cairo-boxes.c index 31bfc0e4e..130a44c76 100644 --- a/src/cairo-boxes.c +++ b/src/cairo-boxes.c @@ -53,6 +53,15 @@ _cairo_boxes_init (cairo_boxes_t *boxes) } void +_cairo_boxes_init_with_clip (cairo_boxes_t *boxes, + cairo_clip_t *clip) +{ + _cairo_boxes_init (boxes); + if (clip) + _cairo_boxes_limit (boxes, clip->boxes, clip->num_boxes); +} + +void _cairo_boxes_init_for_array (cairo_boxes_t *boxes, cairo_box_t *array, int num_boxes) @@ -156,8 +165,19 @@ _cairo_boxes_add_internal (cairo_boxes_t *boxes, cairo_status_t _cairo_boxes_add (cairo_boxes_t *boxes, + cairo_antialias_t antialias, const cairo_box_t *box) { + cairo_box_t b; + + if (antialias == CAIRO_ANTIALIAS_NONE) { + b.p1.x = _cairo_fixed_round_down (box->p1.x); + b.p1.y = _cairo_fixed_round_down (box->p1.y); + b.p2.x = _cairo_fixed_round_down (box->p2.x); + b.p2.y = _cairo_fixed_round_down (box->p2.y); + box = &b; + } + if (box->p1.y == box->p2.y) return CAIRO_STATUS_SUCCESS; @@ -247,6 +267,11 @@ _cairo_boxes_extents (const cairo_boxes_t *boxes, cairo_box_t box; int i; + if (boxes->num_boxes == 0) { + extents->x = extents->y = extents->width = extents->height = 0; + return; + } + box.p1.y = box.p1.x = INT_MAX; box.p2.y = box.p2.x = INT_MIN; @@ -283,11 +308,41 @@ _cairo_boxes_clear (cairo_boxes_t *boxes) boxes->tail = &boxes->chunks; boxes->chunks.next = 0; boxes->chunks.count = 0; + boxes->chunks.base = boxes->boxes_embedded; + boxes->chunks.size = ARRAY_LENGTH (boxes->boxes_embedded); boxes->num_boxes = 0; boxes->is_pixel_aligned = TRUE; } +cairo_box_t * +_cairo_boxes_to_array (const cairo_boxes_t *boxes, + int *num_boxes, + cairo_bool_t force_allocation) +{ + const struct _cairo_boxes_chunk *chunk; + cairo_box_t *box; + int i, j; + + *num_boxes = boxes->num_boxes; + if (boxes->chunks.next == NULL && ! force_allocation) + return boxes->chunks.base; + + box = _cairo_malloc_ab (boxes->num_boxes, sizeof (cairo_box_t)); + if (box == NULL) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return NULL; + } + + j = 0; + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) + box[j++] = chunk->base[i]; + } + + return box; +} + void _cairo_boxes_fini (cairo_boxes_t *boxes) { @@ -298,3 +353,26 @@ _cairo_boxes_fini (cairo_boxes_t *boxes) free (chunk); } } + +void +_cairo_debug_print_boxes (FILE *stream, const cairo_boxes_t *boxes) +{ + cairo_rectangle_int_t extents; + const struct _cairo_boxes_chunk *chunk; + int i; + + _cairo_boxes_extents (boxes, &extents); + fprintf (stream, "boxes x %d: (%d, %d) x (%d, %d)\n", + boxes->num_boxes, + extents.x, extents.y, extents.width, extents.height); + + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + fprintf (stderr, " box[%d]: (%f, %f), (%f, %f)\n", i, + _cairo_fixed_to_double (chunk->base[i].p1.x), + _cairo_fixed_to_double (chunk->base[i].p1.y), + _cairo_fixed_to_double (chunk->base[i].p2.x), + _cairo_fixed_to_double (chunk->base[i].p2.y)); + } + } +} |