diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2011-07-24 17:31:39 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2011-07-24 17:31:39 +0100 |
commit | 52e3814824235ff236bc013f9adc85ed85eb8fb8 (patch) | |
tree | 4f77010fb8655525c87a1b032863cab299b7ae76 /src | |
parent | 4c72c4df661b4cc24f40d8719da15a13adc7bb9b (diff) |
clip: Skip processing of rectangle-intersection if it wholly subsumes the clip
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'src')
-rw-r--r-- | src/cairo-clip-boxes.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/cairo-clip-boxes.c b/src/cairo-clip-boxes.c index 663e92bea..52843fa34 100644 --- a/src/cairo-clip-boxes.c +++ b/src/cairo-clip-boxes.c @@ -157,6 +157,7 @@ _cairo_clip_intersect_rectangle_box (cairo_clip_t *clip, const cairo_box_t *box) { cairo_box_t extents_box; + cairo_bool_t changed = FALSE; int i, j; if (clip == NULL) { @@ -178,6 +179,18 @@ _cairo_clip_intersect_rectangle_box (cairo_clip_t *clip, return clip; } + /* Does the new box wholly subsume the clip? Perform a cheap check + * for the common condition of a single clip rectangle. + */ + if (clip->num_boxes == 1 && + clip->boxes[0].p1.x >= box->p1.x && + clip->boxes[0].p1.y >= box->p1.y && + clip->boxes[0].p2.x <= box->p2.x && + clip->boxes[0].p2.y <= box->p2.y) + { + return clip; + } + for (i = j = 0; i < clip->num_boxes; i++) { cairo_box_t *b = &clip->boxes[j]; @@ -185,14 +198,14 @@ _cairo_clip_intersect_rectangle_box (cairo_clip_t *clip, *b = clip->boxes[i]; if (box->p1.x > b->p1.x) - b->p1.x = box->p1.x; + b->p1.x = box->p1.x, changed = TRUE; if (box->p2.x < b->p2.x) - b->p2.x = box->p2.x; + b->p2.x = box->p2.x, changed = TRUE; if (box->p1.y > b->p1.y) - b->p1.y = box->p1.y; + b->p1.y = box->p1.y, changed = TRUE; if (box->p2.y < b->p2.y) - b->p2.y = box->p2.y; + b->p2.y = box->p2.y, changed = TRUE; j += b->p2.x > b->p1.x && b->p2.y > b->p1.y; } @@ -201,6 +214,9 @@ _cairo_clip_intersect_rectangle_box (cairo_clip_t *clip, if (clip->num_boxes == 0) return _cairo_clip_set_all_clipped (clip); + if (! changed) + return clip; + extents_box = clip->boxes[0]; for (i = 1; i < clip->num_boxes; i++) { if (clip->boxes[i].p1.x < extents_box.p1.x) |