summaryrefslogtreecommitdiff
path: root/src/cairo.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2009-07-23 15:32:13 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2009-07-23 15:32:14 +0100
commitbed2701e1c89095878d549cbca8f22d84f3dda3c (patch)
tree974807761b6d839839ecad9961eae8d567898dcc /src/cairo.c
parentf5a1cdf283a6aa1f4409ccbf3c2274fb587724fe (diff)
downloadcairo-bed2701e1c89095878d549cbca8f22d84f3dda3c.tar.gz
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of the operation state, is cumbersome and a hindrance to providing true proxy surface support. For example, the clip must be copied from the surface onto the fallback image, but this was forgotten causing undue hassle in each backend. Another example is the contortion the meta surface endures to ensure the clip is correctly recorded. By contrast passing the clip along with the operation is quite simple and enables us to write generic handlers for providing surface wrappers. (And in the future, we should be able to write more esoteric wrappers, e.g. automatic 2x FSAA, trivially.) In brief, instead of the surface automatically applying the clip before calling the backend, the backend can call into a generic helper to apply clipping. For raster surfaces, clip regions are handled automatically as part of the composite interface. For vector surfaces, a clip helper is introduced to replay and callback into an intersect_clip_path() function as necessary. Whilst this is not primarily a performance related change (the change should just move the computation of the clip from the moment it is applied by the user to the moment it is required by the backend), it is important to track any potential regression: ppc: Speedups ======== image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup ▌ image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup ▎ image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup ▏ image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup ▏ Slowdowns ========= image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown ▏
Diffstat (limited to 'src/cairo.c')
-rw-r--r--src/cairo.c83
1 files changed, 56 insertions, 27 deletions
diff --git a/src/cairo.c b/src/cairo.c
index 3e590496a..2470b0d69 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -44,6 +44,10 @@
#define CAIRO_TOLERANCE_MINIMUM _cairo_fixed_to_double(1)
+#if !defined(INFINITY)
+#define INFINITY HUGE_VAL
+#endif
+
static const cairo_t _cairo_nil = {
CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */
CAIRO_STATUS_NO_MEMORY, /* status */
@@ -57,7 +61,8 @@ static const cairo_t _cairo_nil = {
FALSE, /* has_current_point */
FALSE, /* has_curve_to */
FALSE, /* is_box */
- FALSE, /* is_region */
+ FALSE, /* maybe_fill_region */
+ TRUE, /* is_empty_fill */
{{{NULL,NULL}}} /* link */
}}
};
@@ -496,25 +501,28 @@ cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
{
cairo_status_t status;
cairo_rectangle_int_t extents;
+ const cairo_rectangle_int_t *clip_extents;
cairo_surface_t *parent_surface, *group_surface = NULL;
+ cairo_bool_t is_empty;
if (unlikely (cr->status))
return;
parent_surface = _cairo_gstate_get_target (cr->gstate);
- /* Get the extents that we'll use in creating our new group surface */
- status = _cairo_surface_get_extents (parent_surface, &extents);
- if (unlikely (status))
- goto bail;
- status = _cairo_clip_intersect_to_rectangle (_cairo_gstate_get_clip (cr->gstate), &extents);
- if (unlikely (status))
- goto bail;
- group_surface = cairo_surface_create_similar (parent_surface,
- content,
- extents.width,
- extents.height);
- status = cairo_surface_status (group_surface);
+ /* Get the extents that we'll use in creating our new group surface */
+ is_empty = _cairo_surface_get_extents (parent_surface, &extents);
+ clip_extents = _cairo_clip_get_extents (_cairo_gstate_get_clip (cr->gstate));
+ if (clip_extents != NULL)
+ is_empty = _cairo_rectangle_intersect (&extents, clip_extents);
+
+ group_surface = _cairo_surface_create_similar_solid (parent_surface,
+ content,
+ extents.width,
+ extents.height,
+ CAIRO_COLOR_TRANSPARENT,
+ TRUE);
+ status = group_surface->status;
if (unlikely (status))
goto bail;
@@ -2340,7 +2348,7 @@ cairo_in_stroke (cairo_t *cr, double x, double y)
cairo_bool_t inside = FALSE;
if (unlikely (cr->status))
- return 0;
+ return FALSE;
status = _cairo_gstate_in_stroke (cr->gstate,
cr->path,
@@ -2370,16 +2378,10 @@ cairo_in_stroke (cairo_t *cr, double x, double y)
cairo_bool_t
cairo_in_fill (cairo_t *cr, double x, double y)
{
- cairo_bool_t inside;
-
if (unlikely (cr->status))
- return 0;
-
- _cairo_gstate_in_fill (cr->gstate,
- cr->path,
- x, y, &inside);
+ return FALSE;
- return inside;
+ return _cairo_gstate_in_fill (cr->gstate, cr->path, x, y);
}
/**
@@ -2600,8 +2602,6 @@ cairo_clip_extents (cairo_t *cr,
double *x1, double *y1,
double *x2, double *y2)
{
- cairo_status_t status;
-
if (unlikely (cr->status)) {
if (x1)
*x1 = 0.0;
@@ -2615,9 +2615,38 @@ cairo_clip_extents (cairo_t *cr,
return;
}
- status = _cairo_gstate_clip_extents (cr->gstate, x1, y1, x2, y2);
- if (unlikely (status))
- _cairo_set_error (cr, status);
+ if (! _cairo_gstate_clip_extents (cr->gstate, x1, y1, x2, y2)) {
+ *x1 = -INFINITY;
+ *y1 = -INFINITY;
+ *x2 = +INFINITY;
+ *y2 = +INFINITY;
+ }
+}
+
+/**
+ * cairo_in_clip:
+ * @cr: a cairo context
+ * @x: X coordinate of the point to test
+ * @y: Y coordinate of the point to test
+ *
+ * Tests whether the given point is inside the area that would be
+ * visible through the current clip, i.e. the area that would be filled by
+ * a cairo_paint() operation.
+ *
+ * See cairo_clip(), and cairo_clip_preserve().
+ *
+ * Return value: A non-zero value if the point is inside, or zero if
+ * outside.
+ *
+ * Since: 1.10
+ **/
+cairo_bool_t
+cairo_in_clip (cairo_t *cr, double x, double y)
+{
+ if (unlikely (cr->status))
+ return FALSE;
+
+ return _cairo_gstate_in_clip (cr->gstate, x, y);
}
static cairo_rectangle_list_t *