summaryrefslogtreecommitdiff
path: root/src/cairo-path-fixed.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-path-fixed.c
parentf5a1cdf283a6aa1f4409ccbf3c2274fb587724fe (diff)
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-path-fixed.c')
-rw-r--r--src/cairo-path-fixed.c201
1 files changed, 138 insertions, 63 deletions
diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index 0a550399c..9819353b3 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -96,25 +96,32 @@ _cairo_path_fixed_init (cairo_path_fixed_t *path)
path->last_move_point = path->current_point;
path->has_current_point = FALSE;
path->has_curve_to = FALSE;
- path->is_region = TRUE;
- path->is_box = TRUE;
+ path->is_rectilinear = TRUE;
+ path->maybe_fill_region = TRUE;
+ path->is_empty_fill = TRUE;
}
cairo_status_t
_cairo_path_fixed_init_copy (cairo_path_fixed_t *path,
- cairo_path_fixed_t *other)
+ const cairo_path_fixed_t *other)
{
cairo_path_buf_t *buf, *other_buf;
unsigned int num_points, num_ops, buf_size;
- _cairo_path_fixed_init (path);
+ VG (VALGRIND_MAKE_MEM_UNDEFINED (path, sizeof (cairo_path_fixed_t)));
+
+ cairo_list_init (&path->buf.base.link);
+
+ path->buf.base.op = path->buf.op;
+ path->buf.base.points = path->buf.points;
path->current_point = other->current_point;
- path->has_current_point = other->has_current_point;
path->last_move_point = other->last_move_point;
+ path->has_current_point = other->has_current_point;
path->has_curve_to = other->has_curve_to;
- path->is_box = other->is_box;
- path->is_region = other->is_region;
+ path->is_rectilinear = other->is_rectilinear;
+ path->maybe_fill_region = other->maybe_fill_region;
+ path->is_empty_fill = other->is_empty_fill;
path->buf.base.num_ops = other->buf.base.num_ops;
path->buf.base.num_points = other->buf.base.num_points;
@@ -214,9 +221,10 @@ _cairo_path_fixed_equal (const cairo_path_fixed_t *a,
return TRUE;
/* use the flags to quickly differentiate based on contents */
- if (a->has_curve_to != b->has_curve_to ||
- a->is_region != b->is_region ||
- a->is_box != b->is_box)
+ if (a->is_empty_fill != b->is_empty_fill ||
+ a->has_curve_to != b->has_curve_to ||
+ a->maybe_fill_region != b->maybe_fill_region ||
+ a->is_rectilinear != b->is_rectilinear)
{
return FALSE;
}
@@ -378,15 +386,16 @@ _cairo_path_fixed_move_to (cairo_path_fixed_t *path,
if (unlikely (status))
return status;
- if (path->has_current_point && path->is_box) {
+ if (path->has_current_point && path->is_rectilinear) {
/* a move-to is first an implicit close */
- path->is_box = path->current_point.x == path->last_move_point.x ||
- path->current_point.y == path->last_move_point.y;
- path->is_region &= path->is_box;
+ path->is_rectilinear = path->current_point.x == path->last_move_point.x ||
+ path->current_point.y == path->last_move_point.y;
+ path->maybe_fill_region &= path->is_rectilinear;
}
- if (path->is_region) {
- path->is_region = _cairo_fixed_is_integer (x) &&
- _cairo_fixed_is_integer (y);
+ if (path->maybe_fill_region) {
+ path->maybe_fill_region =
+ _cairo_fixed_is_integer (path->last_move_point.x) &&
+ _cairo_fixed_is_integer (path->last_move_point.y);
}
}
@@ -437,14 +446,18 @@ _cairo_path_fixed_line_to (cairo_path_fixed_t *path,
status = _cairo_path_fixed_move_to (path, point.x, point.y);
} else {
status = _cairo_path_fixed_add (path, CAIRO_PATH_OP_LINE_TO, &point, 1);
- if (path->is_box) {
- path->is_box = path->current_point.x == x ||
- path->current_point.y == y;
- path->is_region &= path->is_box;
+ if (path->is_rectilinear) {
+ path->is_rectilinear = path->current_point.x == x ||
+ path->current_point.y == y;
+ path->maybe_fill_region &= path->is_rectilinear;
+ }
+ if (path->maybe_fill_region) {
+ path->maybe_fill_region = _cairo_fixed_is_integer (x) &&
+ _cairo_fixed_is_integer (y);
}
- if (path->is_region) {
- path->is_region = _cairo_fixed_is_integer (x) &&
- _cairo_fixed_is_integer (y);
+ if (path->is_empty_fill) {
+ path->is_empty_fill = path->current_point.x == x &&
+ path->current_point.y == y;
}
}
@@ -495,9 +508,10 @@ _cairo_path_fixed_curve_to (cairo_path_fixed_t *path,
path->current_point = point[2];
path->has_current_point = TRUE;
+ path->is_empty_fill = FALSE;
path->has_curve_to = TRUE;
- path->is_box = FALSE;
- path->is_region = FALSE;
+ path->is_rectilinear = FALSE;
+ path->maybe_fill_region = FALSE;
return CAIRO_STATUS_SUCCESS;
}
@@ -732,49 +746,77 @@ _cairo_path_fixed_interpret (const cairo_path_fixed_t *path,
return CAIRO_STATUS_SUCCESS;
}
+typedef struct _cairo_path_fixed_append_closure {
+ cairo_point_t offset;
+ cairo_path_fixed_t *path;
+} cairo_path_fixed_append_closure_t;
+
static cairo_status_t
-_append_move_to (void *closure,
+_append_move_to (void *abstract_closure,
const cairo_point_t *point)
{
- return _cairo_path_fixed_move_to (closure, point->x, point->y);
+ cairo_path_fixed_append_closure_t *closure = abstract_closure;
+
+ return _cairo_path_fixed_move_to (closure->path,
+ point->x + closure->offset.x,
+ point->y + closure->offset.y);
}
static cairo_status_t
-_append_line_to (void *closure,
+_append_line_to (void *abstract_closure,
const cairo_point_t *point)
{
- return _cairo_path_fixed_line_to (closure, point->x, point->y);
+ cairo_path_fixed_append_closure_t *closure = abstract_closure;
+
+ return _cairo_path_fixed_line_to (closure->path,
+ point->x + closure->offset.x,
+ point->y + closure->offset.y);
}
static cairo_status_t
-_append_curve_to (void *closure,
+_append_curve_to (void *abstract_closure,
const cairo_point_t *p0,
const cairo_point_t *p1,
const cairo_point_t *p2)
{
- return _cairo_path_fixed_curve_to (closure,
- p0->x, p0->y,
- p1->x, p1->y,
- p2->x, p2->y);
+ cairo_path_fixed_append_closure_t *closure = abstract_closure;
+
+ return _cairo_path_fixed_curve_to (closure->path,
+ p0->x + closure->offset.x,
+ p0->y + closure->offset.y,
+ p1->x + closure->offset.x,
+ p1->y + closure->offset.y,
+ p2->x + closure->offset.x,
+ p2->y + closure->offset.y);
}
static cairo_status_t
-_append_close_path (void *closure)
+_append_close_path (void *abstract_closure)
{
- return _cairo_path_fixed_close_path (closure);
+ cairo_path_fixed_append_closure_t *closure = abstract_closure;
+
+ return _cairo_path_fixed_close_path (closure->path);
}
cairo_status_t
-_cairo_path_fixed_append (cairo_path_fixed_t *path,
- const cairo_path_fixed_t *other,
- cairo_direction_t dir)
+_cairo_path_fixed_append (cairo_path_fixed_t *path,
+ const cairo_path_fixed_t *other,
+ cairo_direction_t dir,
+ cairo_fixed_t tx,
+ cairo_fixed_t ty)
{
+ cairo_path_fixed_append_closure_t closure;
+
+ closure.path = path;
+ closure.offset.x = tx;
+ closure.offset.y = ty;
+
return _cairo_path_fixed_interpret (other, dir,
_append_move_to,
_append_line_to,
_append_curve_to,
_append_close_path,
- path);
+ &closure);
}
static void
@@ -787,6 +829,13 @@ _cairo_path_fixed_offset_and_scale (cairo_path_fixed_t *path,
cairo_path_buf_t *buf;
unsigned int i;
+ if (path->maybe_fill_region) {
+ path->maybe_fill_region = _cairo_fixed_is_integer (offx) &&
+ _cairo_fixed_is_integer (offy) &&
+ _cairo_fixed_is_integer (scalex) &&
+ _cairo_fixed_is_integer (scaley);
+ }
+
cairo_path_foreach_buf_start (buf, path) {
for (i = 0; i < buf->num_points; i++) {
if (scalex != CAIRO_FIXED_ONE)
@@ -800,6 +849,36 @@ _cairo_path_fixed_offset_and_scale (cairo_path_fixed_t *path,
} cairo_path_foreach_buf_end (buf, path);
}
+void
+_cairo_path_fixed_translate (cairo_path_fixed_t *path,
+ cairo_fixed_t offx,
+ cairo_fixed_t offy)
+{
+ cairo_path_buf_t *buf;
+ unsigned int i;
+
+ if (offx == 0 && offy == 0)
+ return;
+
+ if (path->maybe_fill_region &&
+ ! (_cairo_fixed_is_integer (offx) && _cairo_fixed_is_integer (offy)))
+ {
+ path->maybe_fill_region = FALSE;
+ }
+
+ path->last_move_point.x += offx;
+ path->last_move_point.y += offx;
+ path->current_point.x += offx;
+ path->current_point.y += offx;
+
+ cairo_path_foreach_buf_start (buf, path) {
+ for (i = 0; i < buf->num_points; i++) {
+ buf->points[i].x += offx;
+ buf->points[i].y += offy;
+ }
+ } cairo_path_foreach_buf_end (buf, path);
+}
+
/**
* _cairo_path_fixed_transform:
* @path: a #cairo_path_fixed_t to be transformed
@@ -811,12 +890,14 @@ _cairo_path_fixed_offset_and_scale (cairo_path_fixed_t *path,
**/
void
_cairo_path_fixed_transform (cairo_path_fixed_t *path,
- cairo_matrix_t *matrix)
+ const cairo_matrix_t *matrix)
{
cairo_path_buf_t *buf;
unsigned int i;
double dx, dy;
+ /* XXX current_point, last_move_to */
+
if (matrix->yx == 0.0 && matrix->xy == 0.0) {
/* Fast path for the common case of scale+transform */
_cairo_path_fixed_offset_and_scale (path,
@@ -827,6 +908,7 @@ _cairo_path_fixed_transform (cairo_path_fixed_t *path,
return;
}
+ path->maybe_fill_region = FALSE;
cairo_path_foreach_buf_start (buf, path) {
for (i = 0; i < buf->num_points; i++) {
dx = _cairo_fixed_to_double (buf->points[i].x);
@@ -841,20 +923,22 @@ _cairo_path_fixed_transform (cairo_path_fixed_t *path,
}
cairo_bool_t
-_cairo_path_fixed_is_equal (cairo_path_fixed_t *path,
- cairo_path_fixed_t *other)
+_cairo_path_fixed_is_equal (const cairo_path_fixed_t *path,
+ const cairo_path_fixed_t *other)
{
- cairo_path_buf_t *path_buf, *other_buf;
+ const cairo_path_buf_t *path_buf, *other_buf;
if (path->current_point.x != other->current_point.x ||
path->current_point.y != other->current_point.y ||
path->has_current_point != other->has_current_point ||
path->has_curve_to != other->has_curve_to ||
- path->is_box != other->is_box ||
- path->is_region != other->is_region ||
+ path->is_rectilinear != other->is_rectilinear ||
+ path->maybe_fill_region != other->maybe_fill_region ||
path->last_move_point.x != other->last_move_point.x ||
path->last_move_point.y != other->last_move_point.y)
+ {
return FALSE;
+ }
other_buf = cairo_path_head (other);
cairo_path_foreach_buf_start (path_buf, path) {
@@ -970,25 +1054,16 @@ _cairo_path_fixed_interpret_flat (const cairo_path_fixed_t *path,
&flattener);
}
-cairo_bool_t
-_cairo_path_fixed_is_empty (cairo_path_fixed_t *path)
-{
- if (cairo_path_head (path)->num_ops == 0)
- return TRUE;
-
- return FALSE;
-}
-
/*
* Check whether the given path contains a single rectangle.
*/
cairo_bool_t
-_cairo_path_fixed_is_box (cairo_path_fixed_t *path,
+_cairo_path_fixed_is_box (const cairo_path_fixed_t *path,
cairo_box_t *box)
{
- cairo_path_buf_t *buf = cairo_path_head (path);
+ const cairo_path_buf_t *buf = cairo_path_head (path);
- if (! path->is_box)
+ if (! path->is_rectilinear)
return FALSE;
/* Do we have the right number of ops? */
@@ -1058,12 +1133,12 @@ _cairo_path_fixed_is_box (cairo_path_fixed_t *path,
* </programlisting></informalexample>
*/
cairo_bool_t
-_cairo_path_fixed_is_rectangle (cairo_path_fixed_t *path,
+_cairo_path_fixed_is_rectangle (const cairo_path_fixed_t *path,
cairo_box_t *box)
{
- cairo_path_buf_t *buf;
+ const cairo_path_buf_t *buf;
- if (!_cairo_path_fixed_is_box (path, box))
+ if (! _cairo_path_fixed_is_box (path, box))
return FALSE;
buf = cairo_path_head (path);
@@ -1075,7 +1150,7 @@ _cairo_path_fixed_is_rectangle (cairo_path_fixed_t *path,
void
_cairo_path_fixed_iter_init (cairo_path_fixed_iter_t *iter,
- cairo_path_fixed_t *path)
+ const cairo_path_fixed_t *path)
{
iter->buf = cairo_path_head (path);
iter->n_op = 0;