[cairo-commit] 4 commits - src/cairo-analysis-surface.c src/cairo-clip.c src/cairo-surface-fallback.c src/cairo-traps.c
Chris Wilson
ickle at kemper.freedesktop.org
Wed Sep 24 03:46:04 PDT 2008
src/cairo-analysis-surface.c | 47 ++++++++++---------------------------------
src/cairo-clip.c | 22 ++++++++++++++++----
src/cairo-surface-fallback.c | 16 ++------------
src/cairo-traps.c | 12 +++++++---
4 files changed, 41 insertions(+), 56 deletions(-)
New commits:
commit b9c92842d9c091e34738d14f7baf6f357a1f085c
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed Sep 24 11:38:21 2008 +0100
[trap] Trivial reject if trapezoid is entirely above or below
Also check whether is vertically within limits.
diff --git a/src/cairo-traps.c b/src/cairo-traps.c
index 40bc214..3a38c69 100644
--- a/src/cairo-traps.c
+++ b/src/cairo-traps.c
@@ -183,6 +183,10 @@ _cairo_traps_add_trap (cairo_traps_t *traps,
return;
}
+ /* And reject if the trapezoid is entirely above or below */
+ if (top > traps->limits.p2.y || bottom < traps->limits.p1.y)
+ return;
+
/* Otherwise, clip the trapezoid to the limits. We only clip
* where an edge is entirely outside the limits. If we wanted
* to be more clever, we could handle cases where a trapezoid
commit 911d5f1a254f800fe18f4554b738006aa0a693a2
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed Sep 24 11:34:27 2008 +0100
[traps] Adjust lines if either point is on the boundary.
If either point lies on the limit and the other outside, adjust the line
to be parallel to the boundary. This adjusts the previous test where both
points needed to be entirely outside.
diff --git a/src/cairo-traps.c b/src/cairo-traps.c
index c7dc947..40bc214 100644
--- a/src/cairo-traps.c
+++ b/src/cairo-traps.c
@@ -195,15 +195,15 @@ _cairo_traps_add_trap (cairo_traps_t *traps,
if (bottom > traps->limits.p2.y)
bottom = traps->limits.p2.y;
- if (left->p1.x < traps->limits.p1.x &&
- left->p2.x < traps->limits.p1.x)
+ if (left->p1.x <= traps->limits.p1.x &&
+ left->p2.x <= traps->limits.p1.x)
{
left->p1.x = traps->limits.p1.x;
left->p2.x = traps->limits.p1.x;
}
- if (right->p1.x > traps->limits.p2.x &&
- right->p2.x > traps->limits.p2.x)
+ if (right->p1.x >= traps->limits.p2.x &&
+ right->p2.x >= traps->limits.p2.x)
{
right->p1.x = traps->limits.p2.x;
right->p2.x = traps->limits.p2.x;
commit 7357e80054b80a9906783ed910282bb79f31cdfd
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed Sep 24 11:32:11 2008 +0100
[clip] Limit traps.
Apply prior knowledge to limit the traps during clipping to avoid
generating extra work.
diff --git a/src/cairo-clip.c b/src/cairo-clip.c
index 5ab0066..cff8e40 100644
--- a/src/cairo-clip.c
+++ b/src/cairo-clip.c
@@ -148,7 +148,10 @@ _cairo_clip_path_intersect_to_rectangle (cairo_clip_path_t *clip_path,
cairo_box_t extents;
cairo_rectangle_int_t extents_rect;
+ _cairo_box_from_rectangle (&extents, rectangle);
+
_cairo_traps_init (&traps);
+ _cairo_traps_limit (&traps, &extents);
status = _cairo_path_fixed_fill_to_traps (&clip_path->path,
clip_path->fill_rule,
@@ -436,9 +439,8 @@ _cairo_clip_intersect_mask (cairo_clip_t *clip,
/* Intersect with the target surface rectangle so we don't use
* more memory and time than we need to. */
-
status = _cairo_surface_get_extents (target, &target_rect);
- if (!status)
+ if (status == CAIRO_STATUS_SUCCESS)
_cairo_rectangle_intersect (&surface_rect, &target_rect);
if (surface_rect.width == 0 || surface_rect.height == 0) {
@@ -561,6 +563,7 @@ _cairo_clip_clip (cairo_clip_t *clip,
cairo_surface_t *target)
{
cairo_status_t status;
+ cairo_rectangle_int_t rectangle;
cairo_traps_t traps;
if (clip->all_clipped)
@@ -582,6 +585,17 @@ _cairo_clip_clip (cairo_clip_t *clip,
return status;
_cairo_traps_init (&traps);
+
+ /* Limit the traps to the target surface
+ * - so we don't add more traps than needed. */
+ status = _cairo_surface_get_extents (target, &rectangle);
+ if (status == CAIRO_STATUS_SUCCESS) {
+ cairo_box_t box;
+
+ _cairo_box_from_rectangle (&box, &rectangle);
+ _cairo_traps_limit (&traps, &box);
+ }
+
status = _cairo_path_fixed_fill_to_traps (path,
fill_rule,
tolerance,
commit c36a242303c99f59ba210d6c0dae831b2efb83fc
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed Sep 24 11:12:05 2008 +0100
[traps] Replace open-coding of box->rectangle->box
Use the utility functions _cairo_box_from_rectangle and
_cairo_box_round_to_rectangle() instead of open-coding. Simultaneously
tweak the whitespace so that all users of traps look similar.
diff --git a/src/cairo-analysis-surface.c b/src/cairo-analysis-surface.c
index abed123..0b74a5e 100644
--- a/src/cairo-analysis-surface.c
+++ b/src/cairo-analysis-surface.c
@@ -403,7 +403,6 @@ _cairo_analysis_surface_stroke (void *abstract_surface,
cairo_analysis_surface_t *surface = abstract_surface;
cairo_status_t status, backend_status;
cairo_traps_t traps;
- cairo_box_t box;
cairo_rectangle_int_t extents;
if (!surface->target->backend->stroke)
@@ -434,10 +433,9 @@ _cairo_analysis_surface_stroke (void *abstract_surface,
_cairo_rectangle_intersect (&extents, &surface->current_clip);
if (_cairo_operator_bounded_by_mask (op)) {
- box.p1.x = _cairo_fixed_from_int (extents.x);
- box.p1.y = _cairo_fixed_from_int (extents.y);
- box.p2.x = _cairo_fixed_from_int (extents.x + extents.width);
- box.p2.y = _cairo_fixed_from_int (extents.y + extents.height);
+ cairo_box_t box;
+
+ _cairo_box_from_rectangle (&box, &extents);
_cairo_traps_init (&traps);
_cairo_traps_limit (&traps, &box);
@@ -451,19 +449,10 @@ _cairo_analysis_surface_stroke (void *abstract_surface,
return status;
}
- if (traps.num_traps == 0) {
- extents.x = 0;
- extents.y = 0;
- extents.width = 0;
- extents.height = 0;
- } else {
- _cairo_traps_extents (&traps, &box);
- extents.x = _cairo_fixed_integer_floor (box.p1.x);
- extents.y = _cairo_fixed_integer_floor (box.p1.y);
- extents.width = _cairo_fixed_integer_ceil (box.p2.x) - extents.x;
- extents.height = _cairo_fixed_integer_ceil (box.p2.y) - extents.y;
- }
+ _cairo_traps_extents (&traps, &box);
_cairo_traps_fini (&traps);
+
+ _cairo_box_round_to_rectangle (&box, &extents);
}
status = _cairo_analysis_surface_add_operation (surface, &extents, backend_status);
@@ -483,7 +472,6 @@ _cairo_analysis_surface_fill (void *abstract_surface,
cairo_analysis_surface_t *surface = abstract_surface;
cairo_status_t status, backend_status;
cairo_traps_t traps;
- cairo_box_t box;
cairo_rectangle_int_t extents;
if (!surface->target->backend->fill)
@@ -513,10 +501,9 @@ _cairo_analysis_surface_fill (void *abstract_surface,
_cairo_rectangle_intersect (&extents, &surface->current_clip);
if (_cairo_operator_bounded_by_mask (op)) {
- box.p1.x = _cairo_fixed_from_int (extents.x);
- box.p1.y = _cairo_fixed_from_int (extents.y);
- box.p2.x = _cairo_fixed_from_int (extents.x + extents.width);
- box.p2.y = _cairo_fixed_from_int (extents.y + extents.height);
+ cairo_box_t box;
+
+ _cairo_box_from_rectangle (&box, &extents);
_cairo_traps_init (&traps);
_cairo_traps_limit (&traps, &box);
@@ -529,20 +516,10 @@ _cairo_analysis_surface_fill (void *abstract_surface,
return status;
}
- if (traps.num_traps == 0) {
- extents.x = 0;
- extents.y = 0;
- extents.width = 0;
- extents.height = 0;
- } else {
- _cairo_traps_extents (&traps, &box);
- extents.x = _cairo_fixed_integer_floor (box.p1.x);
- extents.y = _cairo_fixed_integer_floor (box.p1.y);
- extents.width = _cairo_fixed_integer_ceil (box.p2.x) - extents.x;
- extents.height = _cairo_fixed_integer_ceil (box.p2.y) - extents.y;
- }
-
+ _cairo_traps_extents (&traps, &box);
_cairo_traps_fini (&traps);
+
+ _cairo_box_round_to_rectangle (&box, &extents);
}
status = _cairo_analysis_surface_add_operation (surface, &extents, backend_status);
diff --git a/src/cairo-clip.c b/src/cairo-clip.c
index 5de3667..5ab0066 100644
--- a/src/cairo-clip.c
+++ b/src/cairo-clip.c
@@ -160,11 +160,11 @@ _cairo_clip_path_intersect_to_rectangle (cairo_clip_path_t *clip_path,
}
_cairo_traps_extents (&traps, &extents);
+ _cairo_traps_fini (&traps);
+
_cairo_box_round_to_rectangle (&extents, &extents_rect);
_cairo_rectangle_intersect (rectangle, &extents_rect);
- _cairo_traps_fini (&traps);
-
clip_path = clip_path->prev;
}
diff --git a/src/cairo-surface-fallback.c b/src/cairo-surface-fallback.c
index c7c7b11..dc96a04 100644
--- a/src/cairo-surface-fallback.c
+++ b/src/cairo-surface-fallback.c
@@ -697,10 +697,7 @@ _cairo_surface_fallback_paint (cairo_surface_t *surface,
if (status)
return status;
- box.p1.x = _cairo_fixed_from_int (extents.x);
- box.p1.y = _cairo_fixed_from_int (extents.y);
- box.p2.x = _cairo_fixed_from_int (extents.x + extents.width);
- box.p2.y = _cairo_fixed_from_int (extents.y + extents.height);
+ _cairo_box_from_rectangle (&box, &extents);
_cairo_traps_init_box (&traps, &box);
@@ -822,10 +819,7 @@ _cairo_surface_fallback_stroke (cairo_surface_t *surface,
if (extents.width == 0 || extents.height == 0)
return CAIRO_STATUS_SUCCESS;
- box.p1.x = _cairo_fixed_from_int (extents.x);
- box.p1.y = _cairo_fixed_from_int (extents.y);
- box.p2.x = _cairo_fixed_from_int (extents.x + extents.width);
- box.p2.y = _cairo_fixed_from_int (extents.y + extents.height);
+ _cairo_box_from_rectangle (&box, &extents);
_cairo_traps_init (&traps);
_cairo_traps_limit (&traps, &box);
@@ -885,13 +879,9 @@ _cairo_surface_fallback_fill (cairo_surface_t *surface,
if (extents.width == 0 || extents.height == 0)
return CAIRO_STATUS_SUCCESS;
- box.p1.x = _cairo_fixed_from_int (extents.x);
- box.p1.y = _cairo_fixed_from_int (extents.y);
- box.p2.x = _cairo_fixed_from_int (extents.x + extents.width);
- box.p2.y = _cairo_fixed_from_int (extents.y + extents.height);
+ _cairo_box_from_rectangle (&box, &extents);
_cairo_traps_init (&traps);
-
_cairo_traps_limit (&traps, &box);
status = _cairo_path_fixed_fill_to_traps (path,
More information about the cairo-commit
mailing list