[cairo-commit] 3 commits - src/cairo-quartz-surface.c
Andrea Canciani
ranma42 at kemper.freedesktop.org
Tue Apr 27 03:28:36 PDT 2010
src/cairo-quartz-surface.c | 95 +++++++++++----------------------------------
1 file changed, 25 insertions(+), 70 deletions(-)
New commits:
commit ebe6f2ac6988991afde0d685bea9f207ed3360d8
Author: Andrea Canciani <ranma42 at gmail.com>
Date: Tue Apr 27 10:59:09 2010 +0200
quartz: Assert success of path creation
Path creation can only fail because of the callbacks, but in quartz
they all return CAIRO_STATUS_SUCCESS. Therefore we can just assert
that path creation was successful and simplify calling functions
(as they don't have to handle potential errors anymore).
diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index ad9f3a8..d32074e 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -355,18 +355,22 @@ _cairo_path_to_quartz_context_close_path (void *closure)
return CAIRO_STATUS_SUCCESS;
}
-static cairo_status_t
+static void
_cairo_quartz_cairo_path_to_quartz_context (cairo_path_fixed_t *path,
CGContextRef closure)
{
+ cairo_status_t status;
+
CGContextBeginPath (closure);
- return _cairo_path_fixed_interpret (path,
- CAIRO_DIRECTION_FORWARD,
- _cairo_path_to_quartz_context_move_to,
- _cairo_path_to_quartz_context_line_to,
- _cairo_path_to_quartz_context_curve_to,
- _cairo_path_to_quartz_context_close_path,
- closure);
+ status = _cairo_path_fixed_interpret (path,
+ CAIRO_DIRECTION_FORWARD,
+ _cairo_path_to_quartz_context_move_to,
+ _cairo_path_to_quartz_context_line_to,
+ _cairo_path_to_quartz_context_curve_to,
+ _cairo_path_to_quartz_context_close_path,
+ closure);
+
+ assert (status == CAIRO_STATUS_SUCCESS);
}
/*
@@ -1956,9 +1960,7 @@ _cairo_quartz_surface_fill_cg (void *abstract_surface,
action = _cairo_quartz_setup_source (surface, source);
- rv = _cairo_quartz_cairo_path_to_quartz_context (path, surface->cgContext);
- if (rv)
- goto BAIL;
+ _cairo_quartz_cairo_path_to_quartz_context (path, surface->cgContext);
if (!_cairo_operator_bounded_by_mask(op) && CGContextCopyPathPtr)
path_for_unbounded = CGContextCopyPathPtr (surface->cgContext);
@@ -1990,7 +1992,6 @@ _cairo_quartz_surface_fill_cg (void *abstract_surface,
rv = CAIRO_INT_STATUS_UNSUPPORTED;
}
- BAIL:
_cairo_quartz_teardown_source (surface, source);
CGContextRestoreGState (surface->cgContext);
@@ -2116,9 +2117,7 @@ _cairo_quartz_surface_stroke_cg (void *abstract_surface,
action = _cairo_quartz_setup_source (surface, source);
- rv = _cairo_quartz_cairo_path_to_quartz_context (path, surface->cgContext);
- if (rv)
- goto BAIL;
+ _cairo_quartz_cairo_path_to_quartz_context (path, surface->cgContext);
if (!_cairo_operator_bounded_by_mask (op) && CGContextCopyPathPtr)
path_for_unbounded = CGContextCopyPathPtr (surface->cgContext);
@@ -2146,7 +2145,6 @@ _cairo_quartz_surface_stroke_cg (void *abstract_surface,
rv = CAIRO_INT_STATUS_UNSUPPORTED;
}
- BAIL:
_cairo_quartz_teardown_source (surface, source);
CGContextRestoreGState (surface->cgContext);
@@ -2637,7 +2635,6 @@ _cairo_quartz_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clip
{
cairo_quartz_surface_t *surface =
cairo_container_of (clipper, cairo_quartz_surface_t, clipper);
- cairo_status_t status;
ND((stderr, "%p _cairo_quartz_surface_intersect_clip_path path: %p\n", surface, path));
@@ -2657,9 +2654,7 @@ _cairo_quartz_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clip
} else {
CGContextSetShouldAntialias (surface->cgContext, (antialias != CAIRO_ANTIALIAS_NONE));
- status = _cairo_quartz_cairo_path_to_quartz_context (path, surface->cgContext);
- if (status)
- return status;
+ _cairo_quartz_cairo_path_to_quartz_context (path, surface->cgContext);
if (fill_rule == CAIRO_FILL_RULE_WINDING)
CGContextClip (surface->cgContext);
commit f67b6009278ef3dfe91ddbffb989dcfeed174352
Author: Andrea Canciani <ranma42 at gmail.com>
Date: Sun Apr 4 11:50:41 2010 +0200
quartz: Simplify path creation
If paths are created before changing the ctm (when stroking) no
multiplication is needed in the path construction code.
diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 12131a2..ad9f3a8 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -300,25 +300,16 @@ _cairo_quartz_verify_surface_size(int width, int height)
* Cairo path -> Quartz path conversion helpers
*/
-typedef struct _quartz_stroke {
- CGContextRef cgContext;
- const cairo_matrix_t *ctm_inverse;
-} quartz_stroke_t;
-
/* cairo path -> execute in context */
static cairo_status_t
_cairo_path_to_quartz_context_move_to (void *closure,
const cairo_point_t *point)
{
//ND((stderr, "moveto: %f %f\n", _cairo_fixed_to_double(point->x), _cairo_fixed_to_double(point->y)));
- quartz_stroke_t *stroke = (quartz_stroke_t *)closure;
double x = _cairo_fixed_to_double (point->x);
double y = _cairo_fixed_to_double (point->y);
- if (stroke->ctm_inverse)
- cairo_matrix_transform_point (stroke->ctm_inverse, &x, &y);
-
- CGContextMoveToPoint (stroke->cgContext, x, y);
+ CGContextMoveToPoint (closure, x, y);
return CAIRO_STATUS_SUCCESS;
}
@@ -327,17 +318,10 @@ _cairo_path_to_quartz_context_line_to (void *closure,
const cairo_point_t *point)
{
//ND((stderr, "lineto: %f %f\n", _cairo_fixed_to_double(point->x), _cairo_fixed_to_double(point->y)));
- quartz_stroke_t *stroke = (quartz_stroke_t *)closure;
double x = _cairo_fixed_to_double (point->x);
double y = _cairo_fixed_to_double (point->y);
- if (stroke->ctm_inverse)
- cairo_matrix_transform_point (stroke->ctm_inverse, &x, &y);
-
- if (CGContextIsPathEmpty (stroke->cgContext))
- CGContextMoveToPoint (stroke->cgContext, x, y);
- else
- CGContextAddLineToPoint (stroke->cgContext, x, y);
+ CGContextAddLineToPoint (closure, x, y);
return CAIRO_STATUS_SUCCESS;
}
@@ -351,7 +335,6 @@ _cairo_path_to_quartz_context_curve_to (void *closure,
// _cairo_fixed_to_double(p0->x), _cairo_fixed_to_double(p0->y),
// _cairo_fixed_to_double(p1->x), _cairo_fixed_to_double(p1->y),
// _cairo_fixed_to_double(p2->x), _cairo_fixed_to_double(p2->y)));
- quartz_stroke_t *stroke = (quartz_stroke_t *)closure;
double x0 = _cairo_fixed_to_double (p0->x);
double y0 = _cairo_fixed_to_double (p0->y);
double x1 = _cairo_fixed_to_double (p1->x);
@@ -359,13 +342,7 @@ _cairo_path_to_quartz_context_curve_to (void *closure,
double x2 = _cairo_fixed_to_double (p2->x);
double y2 = _cairo_fixed_to_double (p2->y);
- if (stroke->ctm_inverse) {
- cairo_matrix_transform_point (stroke->ctm_inverse, &x0, &y0);
- cairo_matrix_transform_point (stroke->ctm_inverse, &x1, &y1);
- cairo_matrix_transform_point (stroke->ctm_inverse, &x2, &y2);
- }
-
- CGContextAddCurveToPoint (stroke->cgContext,
+ CGContextAddCurveToPoint (closure,
x0, y0, x1, y1, x2, y2);
return CAIRO_STATUS_SUCCESS;
}
@@ -374,22 +351,22 @@ static cairo_status_t
_cairo_path_to_quartz_context_close_path (void *closure)
{
//ND((stderr, "closepath\n"));
- quartz_stroke_t *stroke = (quartz_stroke_t *)closure;
- CGContextClosePath (stroke->cgContext);
+ CGContextClosePath (closure);
return CAIRO_STATUS_SUCCESS;
}
static cairo_status_t
_cairo_quartz_cairo_path_to_quartz_context (cairo_path_fixed_t *path,
- quartz_stroke_t *stroke)
+ CGContextRef closure)
{
+ CGContextBeginPath (closure);
return _cairo_path_fixed_interpret (path,
CAIRO_DIRECTION_FORWARD,
_cairo_path_to_quartz_context_move_to,
_cairo_path_to_quartz_context_line_to,
_cairo_path_to_quartz_context_curve_to,
_cairo_path_to_quartz_context_close_path,
- stroke);
+ closure);
}
/*
@@ -1958,7 +1935,6 @@ _cairo_quartz_surface_fill_cg (void *abstract_surface,
cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
cairo_int_status_t rv = CAIRO_STATUS_SUCCESS;
cairo_quartz_action_t action;
- quartz_stroke_t stroke;
CGPathRef path_for_unbounded = NULL;
ND((stderr, "%p _cairo_quartz_surface_fill op %d source->type %d\n", surface, op, source->type));
@@ -1980,11 +1956,7 @@ _cairo_quartz_surface_fill_cg (void *abstract_surface,
action = _cairo_quartz_setup_source (surface, source);
- CGContextBeginPath (surface->cgContext);
-
- stroke.cgContext = surface->cgContext;
- stroke.ctm_inverse = NULL;
- rv = _cairo_quartz_cairo_path_to_quartz_context (path, &stroke);
+ rv = _cairo_quartz_cairo_path_to_quartz_context (path, surface->cgContext);
if (rv)
goto BAIL;
@@ -2089,7 +2061,6 @@ _cairo_quartz_surface_stroke_cg (void *abstract_surface,
cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
cairo_int_status_t rv = CAIRO_STATUS_SUCCESS;
cairo_quartz_action_t action;
- quartz_stroke_t stroke;
CGAffineTransform origCTM, strokeTransform;
CGPathRef path_for_unbounded = NULL;
@@ -2145,11 +2116,7 @@ _cairo_quartz_surface_stroke_cg (void *abstract_surface,
action = _cairo_quartz_setup_source (surface, source);
- CGContextBeginPath (surface->cgContext);
-
- stroke.cgContext = surface->cgContext;
- stroke.ctm_inverse = NULL;
- rv = _cairo_quartz_cairo_path_to_quartz_context (path, &stroke);
+ rv = _cairo_quartz_cairo_path_to_quartz_context (path, surface->cgContext);
if (rv)
goto BAIL;
@@ -2670,7 +2637,6 @@ _cairo_quartz_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clip
{
cairo_quartz_surface_t *surface =
cairo_container_of (clipper, cairo_quartz_surface_t, clipper);
- quartz_stroke_t stroke;
cairo_status_t status;
ND((stderr, "%p _cairo_quartz_surface_intersect_clip_path path: %p\n", surface, path));
@@ -2689,15 +2655,9 @@ _cairo_quartz_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clip
CGContextRestoreGState (surface->cgContext);
CGContextSaveGState (surface->cgContext);
} else {
- CGContextBeginPath (surface->cgContext);
- stroke.cgContext = surface->cgContext;
- stroke.ctm_inverse = NULL;
-
CGContextSetShouldAntialias (surface->cgContext, (antialias != CAIRO_ANTIALIAS_NONE));
- /* path must not be empty. */
- CGContextMoveToPoint (surface->cgContext, 0, 0);
- status = _cairo_quartz_cairo_path_to_quartz_context (path, &stroke);
+ status = _cairo_quartz_cairo_path_to_quartz_context (path, surface->cgContext);
if (status)
return status;
commit 3b2ceff0502ba409c161e497ebe015e0a0a88847
Author: Andrea Canciani <ranma42 at gmail.com>
Date: Wed Apr 7 18:34:25 2010 +0200
quartz: Stroke without ctm_inverse multiplication
If the CTM is not changed before creating the path, no multiplication
needs to be made between points and the inverse of the CTM.
diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index ee686f3..12131a2 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -2145,13 +2145,10 @@ _cairo_quartz_surface_stroke_cg (void *abstract_surface,
action = _cairo_quartz_setup_source (surface, source);
- _cairo_quartz_cairo_matrix_to_quartz (ctm, &strokeTransform);
- CGContextConcatCTM (surface->cgContext, strokeTransform);
-
CGContextBeginPath (surface->cgContext);
stroke.cgContext = surface->cgContext;
- stroke.ctm_inverse = ctm_inverse;
+ stroke.ctm_inverse = NULL;
rv = _cairo_quartz_cairo_path_to_quartz_context (path, &stroke);
if (rv)
goto BAIL;
@@ -2159,6 +2156,9 @@ _cairo_quartz_surface_stroke_cg (void *abstract_surface,
if (!_cairo_operator_bounded_by_mask (op) && CGContextCopyPathPtr)
path_for_unbounded = CGContextCopyPathPtr (surface->cgContext);
+ _cairo_quartz_cairo_matrix_to_quartz (ctm, &strokeTransform);
+ CGContextConcatCTM (surface->cgContext, strokeTransform);
+
if (action == DO_SOLID || action == DO_PATTERN) {
CGContextStrokePath (surface->cgContext);
} else if (action == DO_IMAGE || action == DO_TILED_IMAGE) {
@@ -2186,12 +2186,12 @@ _cairo_quartz_surface_stroke_cg (void *abstract_surface,
if (path_for_unbounded) {
CGContextSaveGState (surface->cgContext);
- CGContextConcatCTM (surface->cgContext, strokeTransform);
CGContextBeginPath (surface->cgContext);
CGContextAddPath (surface->cgContext, path_for_unbounded);
CGPathRelease (path_for_unbounded);
+ CGContextConcatCTM (surface->cgContext, strokeTransform);
CGContextReplacePathWithStrokedPath (surface->cgContext);
CGContextAddRect (surface->cgContext, CGContextGetClipBoundingBox (surface->cgContext));
More information about the cairo-commit
mailing list