Skip to content

Commit

Permalink
quartz: Unify DO_SOLID and DO_PATTERN
Browse files Browse the repository at this point in the history
Both DO_SOLID and DO_PATTERN setup the underlying CGContext to directly
use the chosen color/pattern when filling and stroking, thus require no
additional drawing operations and can share the same drawing code.
  • Loading branch information
Andrea Canciani committed Oct 12, 2010
1 parent c22e75e commit 51a6ae9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
4 changes: 1 addition & 3 deletions src/cairo-quartz-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ typedef float cairo_quartz_float_t;
#endif

typedef enum {
DO_SOLID,
DO_DIRECT,
DO_SHADING,
DO_PATTERN,
DO_IMAGE,
DO_TILED_IMAGE
} cairo_quartz_action_t;
Expand Down Expand Up @@ -82,7 +81,6 @@ typedef struct cairo_quartz_surface {
CGRect sourceImageRect;

CGShadingRef sourceShading;
CGPatternRef sourcePattern;
} cairo_quartz_surface_t;

typedef struct cairo_quartz_image_surface {
Expand Down
22 changes: 9 additions & 13 deletions src/cairo-quartz-surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ _cairo_quartz_setup_source (cairo_quartz_surface_t *surface,
{
cairo_status_t status;

assert (!(surface->sourceImage || surface->sourceShading || surface->sourcePattern));
assert (!(surface->sourceImage || surface->sourceShading));

/* Save before we change the pattern, colorspace, etc. so that
* we can restore and make sure that quartz releases our
Expand Down Expand Up @@ -1452,7 +1452,7 @@ _cairo_quartz_setup_source (cairo_quartz_surface_t *surface,
solid->color.blue,
solid->color.alpha);

surface->action = DO_SOLID;
surface->action = DO_DIRECT;
return CAIRO_STATUS_SUCCESS;
}

Expand Down Expand Up @@ -1561,8 +1561,9 @@ _cairo_quartz_setup_source (cairo_quartz_surface_t *surface,
*/
CGContextSetPatternPhase (surface->cgContext, CGSizeMake (0, 0));

surface->sourcePattern = pattern;
surface->action = DO_PATTERN;
CGPatternRelease (pattern);

surface->action = DO_DIRECT;
return CAIRO_STATUS_SUCCESS;
}

Expand All @@ -1587,11 +1588,6 @@ _cairo_quartz_teardown_source (cairo_quartz_surface_t *surface,
CGShadingRelease (surface->sourceShading);
surface->sourceShading = NULL;
}

if (surface->sourcePattern) {
CGPatternRelease (surface->sourcePattern);
surface->sourcePattern = NULL;
}
}

static cairo_int_status_t
Expand Down Expand Up @@ -1999,7 +1995,7 @@ _cairo_quartz_surface_paint_cg (cairo_quartz_surface_t *surface,
if (unlikely (rv))
return rv;

if (surface->action == DO_SOLID || surface->action == DO_PATTERN) {
if (surface->action == DO_DIRECT) {
CGContextFillRect (surface->cgContext, CGRectMake (surface->extents.x,
surface->extents.y,
surface->extents.width,
Expand Down Expand Up @@ -2082,7 +2078,7 @@ _cairo_quartz_surface_fill_cg (cairo_quartz_surface_t *surface,
if (!_cairo_operator_bounded_by_mask (op) && CGContextCopyPathPtr)
path_for_unbounded = CGContextCopyPathPtr (surface->cgContext);

if (surface->action == DO_SOLID || surface->action == DO_PATTERN) {
if (surface->action == DO_DIRECT) {
if (fill_rule == CAIRO_FILL_RULE_WINDING)
CGContextFillPath (surface->cgContext);
else
Expand Down Expand Up @@ -2236,7 +2232,7 @@ _cairo_quartz_surface_stroke_cg (cairo_quartz_surface_t *surface,
_cairo_quartz_cairo_matrix_to_quartz (ctm, &strokeTransform);
CGContextConcatCTM (surface->cgContext, strokeTransform);

if (surface->action == DO_SOLID || surface->action == DO_PATTERN) {
if (surface->action == DO_DIRECT) {
CGContextStrokePath (surface->cgContext);
} else if (surface->action == DO_IMAGE || surface->action == DO_TILED_IMAGE) {
CGContextReplacePathWithStrokedPath (surface->cgContext);
Expand Down Expand Up @@ -2364,7 +2360,7 @@ _cairo_quartz_surface_show_glyphs_cg (cairo_quartz_surface_t *surface,
if (unlikely (rv))
return rv;

if (surface->action == DO_SOLID || surface->action == DO_PATTERN) {
if (surface->action == DO_DIRECT) {
CGContextSetTextDrawingMode (surface->cgContext, kCGTextFill);
} else if (surface->action == DO_IMAGE || surface->action == DO_TILED_IMAGE || surface->action == DO_SHADING) {
CGContextSetTextDrawingMode (surface->cgContext, kCGTextClip);
Expand Down

0 comments on commit 51a6ae9

Please sign in to comment.