[cairo-commit] 14 commits - src/cairo-quartz-surface.c

Andrea Canciani ranma42 at kemper.freedesktop.org
Thu Oct 7 11:59:09 PDT 2010


 src/cairo-quartz-surface.c |  630 +++++++++++++++++++++------------------------
 1 file changed, 298 insertions(+), 332 deletions(-)

New commits:
commit 5500d072e0e3d66d762a147caa803d036766b629
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Tue Jul 27 21:22:02 2010 +0200

    quartz: Handle failures in _cairo_quartz_setup_fallback_source
    
    If the fallback surface creation or painting fail, the fallback
    surface needs to be destroyed.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index daae871..1d7ef04 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -1333,6 +1333,7 @@ static cairo_quartz_action_t
 _cairo_quartz_setup_fallback_source (cairo_quartz_surface_t *surface,
 				     const cairo_pattern_t *source)
 {
+    cairo_pattern_union_t pattern;
     CGRect clipBox = CGContextGetClipBoundingBox (surface->cgContext);
     double x0, y0, w, h;
 
@@ -1355,42 +1356,23 @@ _cairo_quartz_setup_fallback_source (cairo_quartz_surface_t *surface,
     fallback = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) w, (int) h);
     cairo_surface_set_device_offset (fallback, -x0, -y0);
 
-#if 0
-    {
-	cairo_t *fallback_cr;
-	cairo_pattern_t *source_copy;
-
-	/* Paint the source onto our temporary */
-	fallback_cr = cairo_create (fallback);
-	cairo_set_operator (fallback_cr, CAIRO_OPERATOR_SOURCE);
-
-	/* Use a copy of the pattern because it is const and could be allocated
-	 * on the stack */
-	status = _cairo_pattern_create_copy (&source_copy, source);
-	cairo_set_source (fallback_cr, source_copy);
-	cairo_pattern_destroy (source_copy);
-
-	cairo_paint (fallback_cr);
-	cairo_destroy (fallback_cr);
-    }
-#else
-    {
-	cairo_pattern_union_t pattern;
-
-	_cairo_pattern_init_static_copy (&pattern.base, source);
-	_cairo_pattern_transform (&pattern.base,
-				  &fallback->device_transform_inverse);
-	status = _cairo_surface_paint (fallback,
-				       CAIRO_OPERATOR_SOURCE,
-				       &pattern.base, NULL);
+    _cairo_pattern_init_static_copy (&pattern.base, source);
+    _cairo_pattern_transform (&pattern.base, &fallback->device_transform_inverse);
+    status = _cairo_surface_paint (fallback, CAIRO_OPERATOR_SOURCE, &pattern.base, NULL);
+    if (unlikely (status)) {
+	cairo_surface_destroy (fallback);
+	return DO_UNSUPPORTED;
     }
-#endif
 
     status = _cairo_surface_to_cgimage (fallback, &img);
-    if (unlikely (status))
+    if (unlikely (status)) {
+	cairo_surface_destroy (fallback);
 	return DO_UNSUPPORTED;
-    if (unlikely (img == NULL))
+    }
+    if (unlikely (img == NULL)) {
+	cairo_surface_destroy (fallback);
 	return DO_NOTHING;
+    }
 
     surface->sourceImageRect = CGRectMake (0.0, 0.0, w, h);
     surface->sourceImage = img;
commit 17bb0f8b1fc6d209ad53b7b995bc013c85a4e058
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Wed Jul 28 10:26:50 2010 +0200

    quartz: Improve _cg function types

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 3919846..daae871 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -2072,12 +2072,11 @@ _cairo_quartz_surface_get_extents (void *abstract_surface,
 }
 
 static cairo_int_status_t
-_cairo_quartz_surface_paint_cg (void *abstract_surface,
+_cairo_quartz_surface_paint_cg (cairo_quartz_surface_t *surface,
 				cairo_operator_t op,
 				const cairo_pattern_t *source,
 				cairo_clip_t *clip)
 {
-    cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
     cairo_int_status_t rv = CAIRO_STATUS_SUCCESS;
     cairo_quartz_action_t action;
 
@@ -2149,7 +2148,7 @@ _cairo_quartz_surface_paint (void *abstract_surface,
     cairo_int_status_t rv;
     cairo_image_surface_t *image;
 
-    rv = _cairo_quartz_surface_paint_cg (abstract_surface,
+    rv = _cairo_quartz_surface_paint_cg (surface,
 					 op,
 					 source,
 					 clip);
@@ -2167,7 +2166,7 @@ _cairo_quartz_surface_paint (void *abstract_surface,
 }
 
 static cairo_int_status_t
-_cairo_quartz_surface_fill_cg (void *abstract_surface,
+_cairo_quartz_surface_fill_cg (cairo_quartz_surface_t *surface,
 			       cairo_operator_t op,
 			       const cairo_pattern_t *source,
 			       cairo_path_fixed_t *path,
@@ -2176,7 +2175,6 @@ _cairo_quartz_surface_fill_cg (void *abstract_surface,
 			       cairo_antialias_t antialias,
 			       cairo_clip_t *clip)
 {
-    cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
     cairo_int_status_t rv = CAIRO_STATUS_SUCCESS;
     cairo_quartz_action_t action;
     CGPathRef path_for_unbounded = NULL;
@@ -2274,7 +2272,7 @@ _cairo_quartz_surface_fill (void *abstract_surface,
     cairo_int_status_t rv;
     cairo_image_surface_t *image;
 
-    rv = _cairo_quartz_surface_fill_cg (abstract_surface,
+    rv = _cairo_quartz_surface_fill_cg (surface,
 					op,
 					source,
 					path,
@@ -2298,7 +2296,7 @@ _cairo_quartz_surface_fill (void *abstract_surface,
 }
 
 static cairo_int_status_t
-_cairo_quartz_surface_stroke_cg (void *abstract_surface,
+_cairo_quartz_surface_stroke_cg (cairo_quartz_surface_t *surface,
 				 cairo_operator_t op,
 				 const cairo_pattern_t *source,
 				 cairo_path_fixed_t *path,
@@ -2309,7 +2307,6 @@ _cairo_quartz_surface_stroke_cg (void *abstract_surface,
 				 cairo_antialias_t antialias,
 				 cairo_clip_t *clip)
 {
-    cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
     cairo_int_status_t rv = CAIRO_STATUS_SUCCESS;
     cairo_quartz_action_t action;
     CGAffineTransform origCTM, strokeTransform;
@@ -2446,7 +2443,7 @@ _cairo_quartz_surface_stroke (void *abstract_surface,
     cairo_int_status_t rv;
     cairo_image_surface_t *image;
 
-    rv = _cairo_quartz_surface_stroke_cg (abstract_surface, op, source,
+    rv = _cairo_quartz_surface_stroke_cg (surface, op, source,
 					  path, style, ctm, ctm_inverse,
 					  tolerance, antialias,
 					  clip);
@@ -2468,7 +2465,7 @@ _cairo_quartz_surface_stroke (void *abstract_surface,
 
 #if CAIRO_HAS_QUARTZ_FONT
 static cairo_int_status_t
-_cairo_quartz_surface_show_glyphs_cg (void *abstract_surface,
+_cairo_quartz_surface_show_glyphs_cg (cairo_quartz_surface_t *surface,
 				      cairo_operator_t op,
 				      const cairo_pattern_t *source,
 				      cairo_glyph_t *glyphs,
@@ -2485,7 +2482,6 @@ _cairo_quartz_surface_show_glyphs_cg (void *abstract_surface,
     CGSize *cg_advances = &cg_advances_static[0];
 
     cairo_rectangle_int_t glyph_extents;
-    cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
     cairo_int_status_t rv = CAIRO_STATUS_SUCCESS;
     cairo_quartz_action_t action;
     cairo_quartz_float_t xprev, yprev;
@@ -2671,7 +2667,7 @@ _cairo_quartz_surface_show_glyphs (void *abstract_surface,
     cairo_image_surface_t *image;
 
 #if CAIRO_HAS_QUARTZ_FONT
-    rv = _cairo_quartz_surface_show_glyphs_cg (abstract_surface, op, source,
+    rv = _cairo_quartz_surface_show_glyphs_cg (surface, op, source,
 					       glyphs, num_glyphs,
 					       scaled_font, clip, remaining_glyphs);
 
@@ -2791,13 +2787,12 @@ _cairo_quartz_surface_mask_with_generic (cairo_quartz_surface_t *surface,
 }
 
 static cairo_int_status_t
-_cairo_quartz_surface_mask_cg (void *abstract_surface,
+_cairo_quartz_surface_mask_cg (cairo_quartz_surface_t *surface,
 			       cairo_operator_t op,
 			       const cairo_pattern_t *source,
 			       const cairo_pattern_t *mask,
 			       cairo_clip_t *clip)
 {
-    cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
     cairo_int_status_t rv = CAIRO_STATUS_SUCCESS;
 
     ND ((stderr, "%p _cairo_quartz_surface_mask op %d source->type %d mask->type %d\n", surface, op, source->type, mask->type));
@@ -2850,7 +2845,7 @@ _cairo_quartz_surface_mask (void *abstract_surface,
     cairo_int_status_t rv;
     cairo_image_surface_t *image;
 
-    rv = _cairo_quartz_surface_mask_cg (abstract_surface,
+    rv = _cairo_quartz_surface_mask_cg (surface,
 					op,
 					source,
 					mask,
commit 3b4f7c36626d2d08295ebc1ec2548060c1728b67
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Thu Oct 7 18:59:22 2010 +0200

    quartz: Improve handling of surface creation failure
    
    Don't paint on a surface whose status is not SUCCESS.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 35a9ac3..3919846 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -2772,6 +2772,9 @@ _cairo_quartz_surface_mask_with_generic (cairo_quartz_surface_t *surface,
     gradient_surf = cairo_quartz_surface_create (CAIRO_FORMAT_A8,
 						 width,
 						 height);
+    status = gradient_surf->status;
+    if (unlikely (status))
+	goto BAIL;
 
     status = _cairo_quartz_surface_paint (gradient_surf, CAIRO_OPERATOR_SOURCE, mask, NULL);
     if (unlikely (status))
commit b13a8035c1c164c6fe6382467a53ceb463d2d3ff
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Tue Jul 27 19:05:25 2010 +0200

    quartz: Remove useless code
    
    The condition is always true (since surface creation returns non-NULL
    even upon failure).

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index e89e91d..35a9ac3 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -2764,7 +2764,7 @@ _cairo_quartz_surface_mask_with_generic (cairo_quartz_surface_t *surface,
     int width = surface->extents.width;
     int height = surface->extents.height;
 
-    cairo_surface_t *gradient_surf = NULL;
+    cairo_surface_t *gradient_surf;
     cairo_surface_pattern_t surface_pattern;
     cairo_int_status_t status;
 
@@ -2781,9 +2781,8 @@ _cairo_quartz_surface_mask_with_generic (cairo_quartz_surface_t *surface,
     status = _cairo_quartz_surface_mask_with_surface (surface, op, source, &surface_pattern, clip);
     _cairo_pattern_fini (&surface_pattern.base);
 
-  BAIL:
-    if (gradient_surf)
-	cairo_surface_destroy (gradient_surf);
+ BAIL:
+    cairo_surface_destroy (gradient_surf);
 
     return status;
 }
commit f156f89db071cc09e35e30de0c9ac7b5824f6849
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Tue Jul 27 18:55:38 2010 +0200

    quartz: Simplify cairo_quartz_surface_create_for_cg_context
    
    Only retaining the context when the surface cration is successful
    avoids needless retaining and simplifies the code.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index a243066..e89e91d 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -3029,15 +3029,10 @@ cairo_quartz_surface_create_for_cg_context (CGContextRef cgContext,
 {
     cairo_quartz_surface_t *surf;
 
-    CGContextRetain (cgContext);
-
     surf = _cairo_quartz_surface_create_internal (cgContext, CAIRO_CONTENT_COLOR_ALPHA,
 						  width, height);
-    if (surf->base.status) {
-	CGContextRelease (cgContext);
-	// create_internal will have set an error
-	return &surf->base;
-    }
+    if (likely (!surf->base.status))
+	CGContextRetain (cgContext);
 
     return &surf->base;
 }
commit c5fc8fa62fa92a80a5d8ee84cfe610ec4497fef6
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Tue Jul 27 18:48:00 2010 +0200

    quartz: Use NOTHING_TO_DO instead of SUCCESS where appropriate
    
    Returning CAIRO_INT_STATUS_NOTHING_TO_DO removes some code that
    specifically handles it to convert to CAIRO_STATUS_SUCCESS. This
    is already performed out of the backend, in the upper layers, so
    it is not needed here.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 23f9924..a243066 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -2084,7 +2084,7 @@ _cairo_quartz_surface_paint_cg (void *abstract_surface,
     ND ((stderr, "%p _cairo_quartz_surface_paint op %d source->type %d\n", surface, op, source->type));
 
     if (IS_EMPTY (surface))
-	return CAIRO_STATUS_SUCCESS;
+	return CAIRO_INT_STATUS_NOTHING_TO_DO;
 
     rv = _cairo_surface_clipper_set_clip (&surface->clipper, clip);
     if (unlikely (rv))
@@ -2092,7 +2092,7 @@ _cairo_quartz_surface_paint_cg (void *abstract_surface,
 
     rv = _cairo_quartz_surface_set_cairo_operator (surface, op);
     if (unlikely (rv))
-	return rv == CAIRO_INT_STATUS_NOTHING_TO_DO ? CAIRO_STATUS_SUCCESS : rv;
+	return rv;
 
     action = _cairo_quartz_setup_source (surface, source, NULL);
 
@@ -2184,7 +2184,7 @@ _cairo_quartz_surface_fill_cg (void *abstract_surface,
     ND ((stderr, "%p _cairo_quartz_surface_fill op %d source->type %d\n", surface, op, source->type));
 
     if (IS_EMPTY (surface))
-	return CAIRO_STATUS_SUCCESS;
+	return CAIRO_INT_STATUS_NOTHING_TO_DO;
 
     rv = _cairo_surface_clipper_set_clip (&surface->clipper, clip);
     if (unlikely (rv))
@@ -2192,7 +2192,7 @@ _cairo_quartz_surface_fill_cg (void *abstract_surface,
 
     rv = _cairo_quartz_surface_set_cairo_operator (surface, op);
     if (unlikely (rv))
-	return rv == CAIRO_INT_STATUS_NOTHING_TO_DO ? CAIRO_STATUS_SUCCESS : rv;
+	return rv;
 
     CGContextSaveGState (surface->cgContext);
 
@@ -2318,7 +2318,7 @@ _cairo_quartz_surface_stroke_cg (void *abstract_surface,
     ND ((stderr, "%p _cairo_quartz_surface_stroke op %d source->type %d\n", surface, op, source->type));
 
     if (IS_EMPTY (surface))
-	return CAIRO_STATUS_SUCCESS;
+	return CAIRO_INT_STATUS_NOTHING_TO_DO;
 
     rv = _cairo_surface_clipper_set_clip (&surface->clipper, clip);
     if (unlikely (rv))
@@ -2326,7 +2326,7 @@ _cairo_quartz_surface_stroke_cg (void *abstract_surface,
 
     rv = _cairo_quartz_surface_set_cairo_operator (surface, op);
     if (unlikely (rv))
-	return rv == CAIRO_INT_STATUS_NOTHING_TO_DO ? CAIRO_STATUS_SUCCESS : rv;
+	return rv;
 
     // Turning antialiasing off used to cause misrendering with
     // single-pixel lines (e.g. 20,10.5 -> 21,10.5 end up being rendered as 2 pixels).
@@ -2496,10 +2496,10 @@ _cairo_quartz_surface_show_glyphs_cg (void *abstract_surface,
     cairo_bool_t didForceFontSmoothing = FALSE;
 
     if (IS_EMPTY (surface))
-	return CAIRO_STATUS_SUCCESS;
+	return CAIRO_INT_STATUS_NOTHING_TO_DO;
 
     if (num_glyphs <= 0)
-	return CAIRO_STATUS_SUCCESS;
+	return CAIRO_INT_STATUS_NOTHING_TO_DO;
 
     if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_QUARTZ)
 	return CAIRO_INT_STATUS_UNSUPPORTED;
@@ -2510,7 +2510,7 @@ _cairo_quartz_surface_show_glyphs_cg (void *abstract_surface,
 
     rv = _cairo_quartz_surface_set_cairo_operator (surface, op);
     if (unlikely (rv))
-	return rv == CAIRO_INT_STATUS_NOTHING_TO_DO ? CAIRO_STATUS_SUCCESS : rv;
+	return rv;
 
     CGContextSaveGState (surface->cgContext);
 
@@ -2801,7 +2801,7 @@ _cairo_quartz_surface_mask_cg (void *abstract_surface,
     ND ((stderr, "%p _cairo_quartz_surface_mask op %d source->type %d mask->type %d\n", surface, op, source->type, mask->type));
 
     if (IS_EMPTY (surface))
-	return CAIRO_STATUS_SUCCESS;
+	return CAIRO_INT_STATUS_NOTHING_TO_DO;
 
     rv = _cairo_surface_clipper_set_clip (&surface->clipper, clip);
     if (unlikely (rv))
commit eae5fafc89d35f76d1eb49f3a0dcee509e735b5e
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Thu Jul 29 16:05:51 2010 +0200

    quartz: Beautify code
    
    Remove redundant parentheses and reference/dereferences.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index d447e4e..23f9924 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -284,13 +284,11 @@ cairo_bool_t
 _cairo_quartz_verify_surface_size (int width, int height)
 {
     /* hmmm, allow width, height == 0 ? */
-    if (width < 0 || height < 0) {
+    if (width < 0 || height < 0)
 	return FALSE;
-    }
 
-    if (width > CG_MAX_WIDTH || height > CG_MAX_HEIGHT) {
+    if (width > CG_MAX_WIDTH || height > CG_MAX_HEIGHT)
 	return FALSE;
-    }
 
     return TRUE;
 }
@@ -772,15 +770,13 @@ ComputeGradientValue (void *info,
 	fdist = fdist - floor (fdist);
     } else if (grad->base.extend == CAIRO_EXTEND_REFLECT) {
 	fdist = fmod (fabs (fdist), 2.0);
-	if (fdist > 1.0) {
+	if (fdist > 1.0)
 	    fdist = 2.0 - fdist;
-	}
     }
 
-    for (i = 0; i < grad->n_stops; i++) {
+    for (i = 0; i < grad->n_stops; i++)
 	if (grad->stops[i].offset > fdist)
 	    break;
-    }
 
     if (i == 0 || i == grad->n_stops) {
 	if (i == grad->n_stops)
@@ -883,12 +879,11 @@ UpdateLinearParametersToIncludePoint (double *min_t, double *max_t, CGPoint *sta
     double denominator = dx*dx + dy*dy;
     double t = numerator/denominator;
 
-    if (*min_t > t) {
+    if (*min_t > t)
         *min_t = t;
-    }
-    if (*max_t < t) {
+
+    if (*max_t < t)
         *max_t = t;
-    }
 }
 
 static CGFunctionRef
@@ -994,9 +989,8 @@ UpdateRadialParameterToIncludePoint (double *max_t, CGPoint *center,
     double denominator = dx*dx + dy*dy - dr*dr;
     double t = numerator/denominator;
 
-    if (*max_t < t) {
+    if (*max_t < t)
         *max_t = t;
-    }
 }
 
 /* This must only be called when one of the circles properly contains the other */
@@ -2001,9 +1995,8 @@ _cairo_quartz_surface_clone_similar (void *abstract_surface,
     *clone_out = NULL;
 
     // verify width and height of surface
-    if (!_cairo_quartz_verify_surface_size (width, height)) {
+    if (!_cairo_quartz_verify_surface_size (width, height))
 	return CAIRO_INT_STATUS_UNSUPPORTED;
-    }
 
     if (width == 0 || height == 0) {
 	*clone_out = &_cairo_quartz_surface_create_internal (NULL, CAIRO_CONTENT_COLOR_ALPHA,
@@ -2032,9 +2025,8 @@ _cairo_quartz_surface_clone_similar (void *abstract_surface,
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
     new_format = CAIRO_FORMAT_ARGB32;  /* assumed */
-    if (_cairo_surface_is_image (src)) {
+    if (_cairo_surface_is_image (src))
 	new_format = ((cairo_image_surface_t *) src)->format;
-    }
 
     new_surface = (cairo_quartz_surface_t *)
 	cairo_quartz_surface_create (new_format, width, height);
@@ -2654,14 +2646,11 @@ BAIL:
 	_cairo_quartz_fixup_unbounded_operation (surface, &ub, scaled_font->options.antialias);
     }
 
-
-    if (cg_advances != &cg_advances_static[0]) {
+    if (cg_advances != cg_advances_static)
 	free (cg_advances);
-    }
 
-    if (cg_glyphs != &glyphs_static[0]) {
+    if (cg_glyphs != glyphs_static)
 	free (cg_glyphs);
-    }
 
     return rv;
 }
commit f93603fda094c149deeb77afa11cc12f4d1d5c19
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Tue Jul 27 17:24:08 2010 +0200

    quartz: Whitespace cleanup

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 197d502..d447e4e 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -341,8 +341,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);
 
-    CGContextAddCurveToPoint (closure,
-			      x0, y0, x1, y1, x2, y2);
+    CGContextAddCurveToPoint (closure, x0, y0, x1, y1, x2, y2);
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -1088,16 +1087,16 @@ CreateRepeatingRadialGradientFunction (cairo_quartz_surface_t *surface,
     }
 
     if (_cairo_pattern_create_copy (&pat, &gpat->base))
-  /* quartz doesn't deal very well with malloc failing, so there's
-   * not much point in us trying either */
-  return NULL;
+	/* quartz doesn't deal very well with malloc failing, so there's
+	 * not much point in us trying either */
+	return NULL;
 
     return CGFunctionCreate (pat,
-           1,
-           input_value_range,
-           4,
-           gradient_output_value_ranges,
-           &gradient_callbacks);
+			     1,
+			     input_value_range,
+			     4,
+			     gradient_output_value_ranges,
+			     &gradient_callbacks);
 }
 
 /* Obtain a CGImageRef from a #cairo_surface_t * */
@@ -1957,9 +1956,9 @@ _cairo_quartz_surface_release_dest_image (void *abstract_surface,
 
 static cairo_surface_t *
 _cairo_quartz_surface_create_similar (void *abstract_surface,
-				       cairo_content_t content,
-				       int width,
-				       int height)
+				      cairo_content_t content,
+				      int width,
+				      int height)
 {
     /*cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;*/
 
@@ -2790,9 +2789,7 @@ _cairo_quartz_surface_mask_with_generic (cairo_quartz_surface_t *surface,
 	goto BAIL;
 
     _cairo_pattern_init_for_surface (&surface_pattern, gradient_surf);
-
     status = _cairo_quartz_surface_mask_with_surface (surface, op, source, &surface_pattern, clip);
-
     _cairo_pattern_fini (&surface_pattern.base);
 
   BAIL:
@@ -2960,9 +2957,9 @@ static const struct _cairo_surface_backend cairo_quartz_surface_backend = {
 
 cairo_quartz_surface_t *
 _cairo_quartz_surface_create_internal (CGContextRef cgContext,
-					cairo_content_t content,
-					unsigned int width,
-					unsigned int height)
+				       cairo_content_t content,
+				       unsigned int width,
+				       unsigned int height)
 {
     cairo_quartz_surface_t *surface;
 
commit 6ff5cbd8a9c7d8e9d226c0eedc5c278c4afe7700
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Tue Jul 27 16:51:30 2010 +0200

    quartz: Mark failures as unlikely

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 98182ba..197d502 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -150,7 +150,7 @@ _cairo_surface_is_quartz (const cairo_surface_t *surface);
 /* Load all extra symbols */
 static void quartz_ensure_symbols (void)
 {
-    if (_cairo_quartz_symbol_lookup_done)
+    if (likely (_cairo_quartz_symbol_lookup_done))
 	return;
 
     CGContextClipToMaskPtr = dlsym (RTLD_DEFAULT, "CGContextClipToMask");
@@ -221,7 +221,7 @@ _cairo_quartz_create_cgimage (cairo_format_t format,
 						 height * stride,
 						 releaseCallback);
 
-    if (!dataProvider) {
+    if (unlikely (!dataProvider)) {
 	// manually release
 	if (releaseCallback)
 	    releaseCallback (releaseInfo, data, height * stride);
@@ -260,15 +260,14 @@ FINISH:
 }
 
 static inline cairo_bool_t
-_cairo_quartz_is_cgcontext_bitmap_context (CGContextRef cgc) {
-    if (cgc == NULL)
+_cairo_quartz_is_cgcontext_bitmap_context (CGContextRef cgc)
+{
+    if (unlikely (cgc == NULL))
 	return FALSE;
 
-    if (CGContextGetTypePtr) {
+    if (likely (CGContextGetTypePtr)) {
 	/* 4 is the type value of a bitmap context */
-	if (CGContextGetTypePtr (cgc) == 4)
-	    return TRUE;
-	return FALSE;
+	return CGContextGetTypePtr (cgc) == 4;
     }
 
     /* This will cause a (harmless) warning to be printed if called on a non-bitmap context */
@@ -1145,13 +1144,13 @@ _cairo_surface_to_cgimage (cairo_surface_t *source,
     }
 
     source_img = malloc (sizeof (quartz_source_image_t));
-    if (source_img == NULL)
+    if (unlikely (source_img == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     source_img->surface = source;
 
     status = _cairo_surface_acquire_source_image (source_img->surface, &source_img->image_out, &source_img->image_extra);
-    if (status) {
+    if (unlikely (status)) {
 	free (source_img);
 	return status;
     }
@@ -1173,7 +1172,7 @@ _cairo_surface_to_cgimage (cairo_surface_t *source,
 						   source_img);
 
 	/* TODO: differentiate memory error and unsupported surface type */
-	if (*image_out == NULL)
+	if (unlikely (*image_out == NULL))
 	    status = CAIRO_INT_STATUS_UNSUPPORTED;
     }
 
@@ -1262,13 +1261,13 @@ _cairo_quartz_cairo_repeating_surface_pattern_to_quartz (cairo_quartz_surface_t
     assert (is_bounded);
 
     status = _cairo_surface_to_cgimage (pat_surf, &image);
-    if (status)
+    if (unlikely (status))
 	return status;
-    if (image == NULL)
+    if (unlikely (image == NULL))
 	return CAIRO_INT_STATUS_NOTHING_TO_DO;
 
     info = malloc (sizeof (SurfacePatternDrawInfo));
-    if (!info)
+    if (unlikely (!info))
 	return CAIRO_STATUS_NO_MEMORY;
 
     /* XXX -- if we're printing, we may need to call CGImageCreateCopy to make sure
@@ -1395,9 +1394,9 @@ _cairo_quartz_setup_fallback_source (cairo_quartz_surface_t *surface,
 #endif
 
     status = _cairo_surface_to_cgimage (fallback, &img);
-    if (status)
+    if (unlikely (status))
 	return DO_UNSUPPORTED;
-    if (img == NULL)
+    if (unlikely (img == NULL))
 	return DO_NOTHING;
 
     surface->sourceImageRect = CGRectMake (0.0, 0.0, w, h);
@@ -1599,9 +1598,9 @@ _cairo_quartz_setup_source (cairo_quartz_surface_t *surface,
 	cairo_bool_t is_bounded;
 
 	status = _cairo_surface_to_cgimage (pat_surf, &img);
-	if (status)
+	if (unlikely (status))
 	    return DO_UNSUPPORTED;
-	if (img == NULL)
+	if (unlikely (img == NULL))
 	    return DO_NOTHING;
 
 	CGContextSetRGBFillColor (surface->cgContext, 0, 0, 0, 1);
@@ -1663,9 +1662,9 @@ _cairo_quartz_setup_source (cairo_quartz_surface_t *surface,
 	cairo_int_status_t status;
 
 	status = _cairo_quartz_cairo_repeating_surface_pattern_to_quartz (surface, source, &pattern);
-	if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
+	if (unlikely (status == CAIRO_INT_STATUS_NOTHING_TO_DO))
 	    return DO_NOTHING;
-	if (status)
+	if (unlikely (status))
 	    return DO_UNSUPPORTED;
 
 	// Save before we change the pattern, colorspace, etc. so that
@@ -1886,7 +1885,7 @@ _cairo_quartz_surface_acquire_source_image (void *abstract_surface,
     //ND ((stderr, "%p _cairo_quartz_surface_acquire_source_image\n", surface));
 
     status = _cairo_quartz_get_image (surface, image_out);
-    if (status)
+    if (unlikely (status))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     *image_extra = NULL;
@@ -1933,7 +1932,7 @@ _cairo_quartz_surface_acquire_dest_image (void *abstract_surface,
     ND ((stderr, "%p _cairo_quartz_surface_acquire_dest_image\n", surface));
 
     status = _cairo_quartz_get_image (surface, image_out);
-    if (status)
+    if (unlikely (status))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     *image_rect = surface->extents;
@@ -2030,7 +2029,7 @@ _cairo_quartz_surface_clone_similar (void *abstract_surface,
     }
 
     status = _cairo_surface_to_cgimage (src, &quartz_image);
-    if (status)
+    if (unlikely (status))
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
     new_format = CAIRO_FORMAT_ARGB32;  /* assumed */
@@ -2168,7 +2167,7 @@ _cairo_quartz_surface_paint (void *abstract_surface,
 	return rv;
 
     rv = _cairo_quartz_get_image (surface, &image);
-    if (rv == CAIRO_STATUS_SUCCESS) {
+    if (likely (rv == CAIRO_STATUS_SUCCESS)) {
 	rv = _cairo_surface_paint (&image->base, op, source, clip);
 	cairo_surface_destroy (&image->base);
     }
@@ -2297,7 +2296,7 @@ _cairo_quartz_surface_fill (void *abstract_surface,
 	return rv;
 
     rv = _cairo_quartz_get_image (surface, &image);
-    if (rv == CAIRO_STATUS_SUCCESS) {
+    if (likely (rv == CAIRO_STATUS_SUCCESS)) {
 	rv = _cairo_surface_fill (&image->base, op, source,
 				  path, fill_rule, tolerance, antialias,
 				  clip);
@@ -2360,7 +2359,7 @@ _cairo_quartz_surface_stroke_cg (void *abstract_surface,
 	    max_dashes *= 2;
 	if (max_dashes > STATIC_DASH)
 	    fdash = _cairo_malloc_ab (max_dashes, sizeof (cairo_quartz_float_t));
-	if (fdash == NULL)
+	if (unlikely (fdash == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	for (k = 0; k < max_dashes; k++)
@@ -2465,7 +2464,7 @@ _cairo_quartz_surface_stroke (void *abstract_surface,
 	return rv;
 
     rv = _cairo_quartz_get_image (surface, &image);
-    if (rv == CAIRO_STATUS_SUCCESS) {
+    if (likely (rv == CAIRO_STATUS_SUCCESS)) {
 	rv = _cairo_surface_stroke (&image->base, op, source,
 				    path, style, ctm, ctm_inverse,
 				    tolerance, antialias,
@@ -2574,13 +2573,13 @@ _cairo_quartz_surface_show_glyphs_cg (void *abstract_surface,
 
     if (num_glyphs > STATIC_BUF_SIZE) {
 	cg_glyphs = (CGGlyph*) _cairo_malloc_ab (num_glyphs, sizeof (CGGlyph));
-	if (cg_glyphs == NULL) {
+	if (unlikely (cg_glyphs == NULL)) {
 	    rv = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto BAIL;
 	}
 
 	cg_advances = (CGSize*) _cairo_malloc_ab (num_glyphs, sizeof (CGSize));
-	if (cg_advances == NULL) {
+	if (unlikely (cg_advances == NULL)) {
 	    rv = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto BAIL;
 	}
@@ -2694,7 +2693,7 @@ _cairo_quartz_surface_show_glyphs (void *abstract_surface,
 #endif
 
     rv = _cairo_quartz_get_image (surface, &image);
-    if (rv == CAIRO_STATUS_SUCCESS) {
+    if (likely (rv == CAIRO_STATUS_SUCCESS)) {
 	rv = _cairo_surface_show_text_glyphs (&image->base, op, source,
 					      NULL, 0,
 					      glyphs, num_glyphs,
@@ -2720,9 +2719,9 @@ _cairo_quartz_surface_mask_with_surface (cairo_quartz_surface_t *surface,
     CGAffineTransform ctm, mask_matrix;
 
     status = _cairo_surface_to_cgimage (pat_surf, &img);
-    if (status)
+    if (unlikely (status))
 	return status;
-    if (img == NULL) {
+    if (unlikely (img == NULL)) {
 	if (!_cairo_operator_bounded_by_mask (op))
 	    CGContextClearRect (surface->cgContext, CGContextGetClipBoundingBox (surface->cgContext));
 	return CAIRO_STATUS_SUCCESS;
@@ -2787,7 +2786,7 @@ _cairo_quartz_surface_mask_with_generic (cairo_quartz_surface_t *surface,
 						 height);
 
     status = _cairo_quartz_surface_paint (gradient_surf, CAIRO_OPERATOR_SOURCE, mask, NULL);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     _cairo_pattern_init_for_surface (&surface_pattern, gradient_surf);
@@ -2873,7 +2872,7 @@ _cairo_quartz_surface_mask (void *abstract_surface,
 	return rv;
 
     rv = _cairo_quartz_get_image (surface, &image);
-    if (rv == CAIRO_STATUS_SUCCESS) {
+    if (likely (rv == CAIRO_STATUS_SUCCESS)) {
 	rv = _cairo_surface_mask (&image->base, op, source, mask, clip);
 	cairo_surface_destroy (&image->base);
     }
@@ -2971,7 +2970,7 @@ _cairo_quartz_surface_create_internal (CGContextRef cgContext,
 
     /* Init the base surface */
     surface = malloc (sizeof (cairo_quartz_surface_t));
-    if (surface == NULL)
+    if (unlikely (surface == NULL))
 	return (cairo_quartz_surface_t*) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     memset (surface, 0, sizeof (cairo_quartz_surface_t));
@@ -3127,7 +3126,7 @@ cairo_quartz_surface_create (cairo_format_t format,
     stride = (stride + 15) & ~15;
 
     imageData = _cairo_malloc_ab (height, stride);
-    if (!imageData) {
+    if (unlikely (!imageData)) {
 	CGColorSpaceRelease (cgColorspace);
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
     }
commit 2f4a47c6bfd10594ec31830d45bc218ebe4eafb0
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Tue Jul 27 15:59:31 2010 +0200

    quartz: Fix function call coding style
    
    Cairo coding style specifies a single space between the function
    name and the parentheses.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 441d591..98182ba 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -148,18 +148,18 @@ static cairo_bool_t
 _cairo_surface_is_quartz (const cairo_surface_t *surface);
 
 /* Load all extra symbols */
-static void quartz_ensure_symbols(void)
+static void quartz_ensure_symbols (void)
 {
     if (_cairo_quartz_symbol_lookup_done)
 	return;
 
-    CGContextClipToMaskPtr = dlsym(RTLD_DEFAULT, "CGContextClipToMask");
-    CGContextDrawTiledImagePtr = dlsym(RTLD_DEFAULT, "CGContextDrawTiledImage");
-    CGContextGetTypePtr = dlsym(RTLD_DEFAULT, "CGContextGetType");
-    CGContextSetShouldAntialiasFontsPtr = dlsym(RTLD_DEFAULT, "CGContextSetShouldAntialiasFonts");
-    CGContextCopyPathPtr = dlsym(RTLD_DEFAULT, "CGContextCopyPath");
-    CGContextGetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing");
-    CGContextSetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing");
+    CGContextClipToMaskPtr = dlsym (RTLD_DEFAULT, "CGContextClipToMask");
+    CGContextDrawTiledImagePtr = dlsym (RTLD_DEFAULT, "CGContextDrawTiledImage");
+    CGContextGetTypePtr = dlsym (RTLD_DEFAULT, "CGContextGetType");
+    CGContextSetShouldAntialiasFontsPtr = dlsym (RTLD_DEFAULT, "CGContextSetShouldAntialiasFonts");
+    CGContextCopyPathPtr = dlsym (RTLD_DEFAULT, "CGContextCopyPath");
+    CGContextGetAllowsFontSmoothingPtr = dlsym (RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing");
+    CGContextSetAllowsFontSmoothingPtr = dlsym (RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing");
 
     _cairo_quartz_symbol_lookup_done = TRUE;
 }
@@ -184,7 +184,7 @@ _cairo_quartz_create_cgimage (cairo_format_t format,
     switch (format) {
 	case CAIRO_FORMAT_ARGB32:
 	    if (colorSpace == NULL)
-		colorSpace = CGColorSpaceCreateDeviceRGB();
+		colorSpace = CGColorSpaceCreateDeviceRGB ();
 	    bitinfo |= kCGImageAlphaPremultipliedFirst;
 	    bitsPerComponent = 8;
 	    bitsPerPixel = 32;
@@ -192,7 +192,7 @@ _cairo_quartz_create_cgimage (cairo_format_t format,
 
 	case CAIRO_FORMAT_RGB24:
 	    if (colorSpace == NULL)
-		colorSpace = CGColorSpaceCreateDeviceRGB();
+		colorSpace = CGColorSpaceCreateDeviceRGB ();
 	    bitinfo |= kCGImageAlphaNoneSkipFirst;
 	    bitsPerComponent = 8;
 	    bitsPerPixel = 32;
@@ -266,13 +266,13 @@ _cairo_quartz_is_cgcontext_bitmap_context (CGContextRef cgc) {
 
     if (CGContextGetTypePtr) {
 	/* 4 is the type value of a bitmap context */
-	if (CGContextGetTypePtr(cgc) == 4)
+	if (CGContextGetTypePtr (cgc) == 4)
 	    return TRUE;
 	return FALSE;
     }
 
     /* This will cause a (harmless) warning to be printed if called on a non-bitmap context */
-    return CGBitmapContextGetBitsPerPixel(cgc) != 0;
+    return CGBitmapContextGetBitsPerPixel (cgc) != 0;
 }
 
 /* CoreGraphics limitation with flipped CTM surfaces: height must be less than signed 16-bit max */
@@ -282,7 +282,7 @@ _cairo_quartz_is_cgcontext_bitmap_context (CGContextRef cgc) {
 
 /* is the desired size of the surface within bounds? */
 cairo_bool_t
-_cairo_quartz_verify_surface_size(int width, int height)
+_cairo_quartz_verify_surface_size (int width, int height)
 {
     /* hmmm, allow width, height == 0 ? */
     if (width < 0 || height < 0) {
@@ -305,7 +305,7 @@ 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)));
+    //ND ((stderr, "moveto: %f %f\n", _cairo_fixed_to_double (point->x), _cairo_fixed_to_double (point->y)));
     double x = _cairo_fixed_to_double (point->x);
     double y = _cairo_fixed_to_double (point->y);
 
@@ -317,7 +317,7 @@ static cairo_status_t
 _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)));
+    //ND ((stderr, "lineto: %f %f\n",  _cairo_fixed_to_double (point->x), _cairo_fixed_to_double (point->y)));
     double x = _cairo_fixed_to_double (point->x);
     double y = _cairo_fixed_to_double (point->y);
 
@@ -331,10 +331,10 @@ _cairo_path_to_quartz_context_curve_to (void *closure,
 					const cairo_point_t *p1,
 					const cairo_point_t *p2)
 {
-    //ND( (stderr, "curveto: %f,%f %f,%f %f,%f\n",
-    //		   _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)));
+    //ND ((stderr, "curveto: %f,%f %f,%f %f,%f\n",
+    //		   _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)));
     double x0 = _cairo_fixed_to_double (p0->x);
     double y0 = _cairo_fixed_to_double (p0->y);
     double x1 = _cairo_fixed_to_double (p1->x);
@@ -350,7 +350,7 @@ _cairo_path_to_quartz_context_curve_to (void *closure,
 static cairo_status_t
 _cairo_path_to_quartz_context_close_path (void *closure)
 {
-    //ND((stderr, "closepath\n"));
+    //ND ((stderr, "closepath\n"));
     CGContextClosePath (closure);
     return CAIRO_STATUS_SUCCESS;
 }
@@ -431,7 +431,7 @@ _cairo_quartz_cairo_operator_to_quartz_composite (cairo_operator_t op)
 static cairo_int_status_t
 _cairo_quartz_surface_set_cairo_operator (cairo_quartz_surface_t *surface, cairo_operator_t op)
 {
-    ND((stderr, "%p _cairo_quartz_surface_set_cairo_operator %d\n", surface, op));
+    ND ((stderr, "%p _cairo_quartz_surface_set_cairo_operator %d\n", surface, op));
 
     if (surface->base.content == CAIRO_CONTENT_ALPHA) {
 	/* For some weird reason, some compositing operators are
@@ -716,8 +716,11 @@ _cairo_quartz_fixup_unbounded_operation (cairo_quartz_surface_t *surface,
 	CGAffineTransform ctm = CGContextGetCTM (cgc);
 	CGContextSaveGState (cgc);
 	CGContextConcatCTM (cgc, op->u.mask.maskTransform);
-	CGContextClipToMask (cgc, CGRectMake (0.0f, 0.0f,
-					      CGImageGetWidth(op->u.mask.mask), CGImageGetHeight(op->u.mask.mask)),
+	CGContextClipToMask (cgc,
+			     CGRectMake (0.0,
+					 0.0,
+					 CGImageGetWidth (op->u.mask.mask),
+					 CGImageGetHeight (op->u.mask.mask)),
 			     op->u.mask.mask);
 	CGContextSetCTM (cgc, ctm);
 	CGContextClearRect (cgc, clipBoxRound);
@@ -768,9 +771,9 @@ ComputeGradientValue (void *info,
      * REPEAT/REFLECT
      */
     if (grad->base.extend == CAIRO_EXTEND_REPEAT) {
-	fdist = fdist - floor(fdist);
+	fdist = fdist - floor (fdist);
     } else if (grad->base.extend == CAIRO_EXTEND_REFLECT) {
-	fdist = fmod(fabs(fdist), 2.0);
+	fdist = fmod (fabs (fdist), 2.0);
 	if (fdist > 1.0) {
 	    fdist = 2.0 - fdist;
 	}
@@ -856,9 +859,9 @@ CreateGradientFunction (const cairo_gradient_pattern_t *gpat)
 }
 
 static void
-UpdateLinearParametersToIncludePoint(double *min_t, double *max_t, CGPoint *start,
-                                     double dx, double dy,
-                                     double x, double y)
+UpdateLinearParametersToIncludePoint (double *min_t, double *max_t, CGPoint *start,
+				      double dx, double dy,
+				      double x, double y)
 {
     /* Compute a parameter t such that a line perpendicular to the (dx,dy)
        vector, passing through (start->x + dx*t, start->y + dy*t), also
@@ -916,14 +919,14 @@ CreateRepeatingLinearGradientFunction (cairo_quartz_surface_t *surface,
                                           &bounds_x2, &bounds_y2,
                                           NULL);
 
-    UpdateLinearParametersToIncludePoint(&t_min, &t_max, start, dx, dy,
-                                         bounds_x1, bounds_y1);
-    UpdateLinearParametersToIncludePoint(&t_min, &t_max, start, dx, dy,
-                                         bounds_x2, bounds_y1);
-    UpdateLinearParametersToIncludePoint(&t_min, &t_max, start, dx, dy,
-                                         bounds_x2, bounds_y2);
-    UpdateLinearParametersToIncludePoint(&t_min, &t_max, start, dx, dy,
-                                         bounds_x1, bounds_y2);
+    UpdateLinearParametersToIncludePoint (&t_min, &t_max, start, dx, dy,
+					  bounds_x1, bounds_y1);
+    UpdateLinearParametersToIncludePoint (&t_min, &t_max, start, dx, dy,
+					  bounds_x2, bounds_y1);
+    UpdateLinearParametersToIncludePoint (&t_min, &t_max, start, dx, dy,
+					  bounds_x2, bounds_y2);
+    UpdateLinearParametersToIncludePoint (&t_min, &t_max, start, dx, dy,
+					  bounds_x1, bounds_y2);
 
     /* Move t_min and t_max to the nearest usable integer to try to avoid
        subtle variations due to numerical instability, especially accidentally
@@ -954,9 +957,9 @@ CreateRepeatingLinearGradientFunction (cairo_quartz_surface_t *surface,
 }
 
 static void
-UpdateRadialParameterToIncludePoint(double *max_t, CGPoint *center,
-                                    double dr, double dx, double dy,
-                                    double x, double y)
+UpdateRadialParameterToIncludePoint (double *max_t, CGPoint *center,
+				     double dr, double dx, double dy,
+				     double x, double y)
 {
     /* Compute a parameter t such that a circle centered at
        (center->x + dx*t, center->y + dy*t) with radius dr*t contains the
@@ -1056,14 +1059,14 @@ CreateRepeatingRadialGradientFunction (cairo_quartz_surface_t *surface,
     *inner_radius = 0.;
 
     t_temp = 0.;
-    UpdateRadialParameterToIncludePoint(&t_temp, inner, dr, dx, dy,
-                                        bounds_x1, bounds_y1);
-    UpdateRadialParameterToIncludePoint(&t_temp, inner, dr, dx, dy,
-                                        bounds_x2, bounds_y1);
-    UpdateRadialParameterToIncludePoint(&t_temp, inner, dr, dx, dy,
-                                        bounds_x2, bounds_y2);
-    UpdateRadialParameterToIncludePoint(&t_temp, inner, dr, dx, dy,
-                                        bounds_x1, bounds_y2);
+    UpdateRadialParameterToIncludePoint (&t_temp, inner, dr, dx, dy,
+					 bounds_x1, bounds_y1);
+    UpdateRadialParameterToIncludePoint (&t_temp, inner, dr, dx, dy,
+					 bounds_x2, bounds_y1);
+    UpdateRadialParameterToIncludePoint (&t_temp, inner, dr, dx, dy,
+					 bounds_x2, bounds_y2);
+    UpdateRadialParameterToIncludePoint (&t_temp, inner, dr, dx, dy,
+					 bounds_x1, bounds_y2);
     /* UpdateRadialParameterToIncludePoint assumes t=0 means radius 0.
        But for the parameter values we use with Quartz, t_min means radius 0.
        Since the circles are alway expanding and contain the earlier circles,
@@ -1129,7 +1132,7 @@ _cairo_surface_to_cgimage (cairo_surface_t *source,
 
     if (_cairo_surface_is_quartz (source)) {
 	cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) source;
-	if (IS_EMPTY(surface)) {
+	if (IS_EMPTY (surface)) {
 	    *image_out = NULL;
 	    return CAIRO_STATUS_SUCCESS;
 	}
@@ -1264,7 +1267,7 @@ _cairo_quartz_cairo_repeating_surface_pattern_to_quartz (cairo_quartz_surface_t
     if (image == NULL)
 	return CAIRO_INT_STATUS_NOTHING_TO_DO;
 
-    info = malloc(sizeof(SurfacePatternDrawInfo));
+    info = malloc (sizeof (SurfacePatternDrawInfo));
     if (!info)
 	return CAIRO_STATUS_NO_MEMORY;
 
@@ -1296,7 +1299,7 @@ _cairo_quartz_cairo_repeating_surface_pattern_to_quartz (cairo_quartz_surface_t
     rh = pbounds.size.height;
 
     m = spattern->base.matrix;
-    cairo_matrix_invert(&m);
+    cairo_matrix_invert (&m);
     _cairo_quartz_cairo_matrix_to_quartz (&m, &stransform);
 
     /* The pattern matrix is relative to the bottom left, again; the
@@ -1304,13 +1307,13 @@ _cairo_quartz_cairo_repeating_surface_pattern_to_quartz (cairo_quartz_surface_t
      * So we take the pattern matrix and the original context matrix,
      * which gives us the correct base translation/y flip.
      */
-    ptransform = CGAffineTransformConcat(stransform, dest->cgContextBaseCTM);
+    ptransform = CGAffineTransformConcat (stransform, dest->cgContextBaseCTM);
 
 #ifdef QUARTZ_DEBUG
-    ND((stderr, "  pbounds: %f %f %f %f\n", pbounds.origin.x, pbounds.origin.y, pbounds.size.width, pbounds.size.height));
-    ND((stderr, "  pattern xform: t: %f %f xx: %f xy: %f yx: %f yy: %f\n", ptransform.tx, ptransform.ty, ptransform.a, ptransform.b, ptransform.c, ptransform.d));
-    CGAffineTransform xform = CGContextGetCTM(dest->cgContext);
-    ND((stderr, "  context xform: t: %f %f xx: %f xy: %f yx: %f yy: %f\n", xform.tx, xform.ty, xform.a, xform.b, xform.c, xform.d));
+    ND ((stderr, "  pbounds: %f %f %f %f\n", pbounds.origin.x, pbounds.origin.y, pbounds.size.width, pbounds.size.height));
+    ND ((stderr, "  pattern xform: t: %f %f xx: %f xy: %f yx: %f yy: %f\n", ptransform.tx, ptransform.ty, ptransform.a, ptransform.b, ptransform.c, ptransform.d));
+    CGAffineTransform xform = CGContextGetCTM (dest->cgContext);
+    ND ((stderr, "  context xform: t: %f %f xx: %f xy: %f yx: %f yy: %f\n", xform.tx, xform.ty, xform.a, xform.b, xform.c, xform.d));
 #endif
 
     *cgpat = CGPatternCreate (info,
@@ -1350,10 +1353,10 @@ _cairo_quartz_setup_fallback_source (cairo_quartz_surface_t *surface,
 	clipBox.size.height == 0.0f)
 	return DO_NOTHING;
 
-    x0 = floor(clipBox.origin.x);
-    y0 = floor(clipBox.origin.y);
-    w = ceil(clipBox.origin.x + clipBox.size.width) - x0;
-    h = ceil(clipBox.origin.y + clipBox.size.height) - y0;
+    x0 = floor (clipBox.origin.x);
+    y0 = floor (clipBox.origin.y);
+    w = ceil (clipBox.origin.x + clipBox.size.width) - x0;
+    h = ceil (clipBox.origin.y + clipBox.size.height) - y0;
 
     /* Create a temporary the size of the clip surface, and position
      * it so that the device origin coincides with the original surface */
@@ -1446,7 +1449,7 @@ _cairo_quartz_setup_linear_source (cairo_quartz_surface_t *surface,
     cairo_matrix_invert (&mat);
     _cairo_quartz_cairo_matrix_to_quartz (&mat, &surface->sourceTransform);
 
-    rgb = CGColorSpaceCreateDeviceRGB();
+    rgb = CGColorSpaceCreateDeviceRGB ();
 
     start = CGPointMake (_cairo_fixed_to_double (lpat->p1.x),
 			 _cairo_fixed_to_double (lpat->p1.y));
@@ -1469,8 +1472,8 @@ _cairo_quartz_setup_linear_source (cairo_quartz_surface_t *surface,
 						   gradFunc,
 						   extend, extend);
 
-    CGColorSpaceRelease(rgb);
-    CGFunctionRelease(gradFunc);
+    CGColorSpaceRelease (rgb);
+    CGFunctionRelease (gradFunc);
 
     return DO_SHADING;
 }
@@ -1513,7 +1516,7 @@ _cairo_quartz_setup_radial_source (cairo_quartz_surface_t *surface,
     cairo_matrix_invert (&mat);
     _cairo_quartz_cairo_matrix_to_quartz (&mat, &surface->sourceTransform);
 
-    rgb = CGColorSpaceCreateDeviceRGB();
+    rgb = CGColorSpaceCreateDeviceRGB ();
 
     start = CGPointMake (c1x, c1y);
     end = CGPointMake (c2x, c2y);
@@ -1538,8 +1541,8 @@ _cairo_quartz_setup_radial_source (cairo_quartz_surface_t *surface,
 						    gradFunc,
 						    extend, extend);
 
-    CGColorSpaceRelease(rgb);
-    CGFunctionRelease(gradFunc);
+    CGColorSpaceRelease (rgb);
+    CGFunctionRelease (gradFunc);
 
     return DO_SHADING;
 }
@@ -1605,7 +1608,7 @@ _cairo_quartz_setup_source (cairo_quartz_surface_t *surface,
 
 	surface->sourceImage = img;
 
-	cairo_matrix_invert(&m);
+	cairo_matrix_invert (&m);
 	_cairo_quartz_cairo_matrix_to_quartz (&m, &surface->sourceTransform);
 
 	is_bounded = _cairo_surface_get_extents (pat_surf, &extents);
@@ -1638,8 +1641,8 @@ _cairo_quartz_setup_source (cairo_quartz_surface_t *surface,
 	    /* We're good to use DrawTiledImage, but ensure that
 	     * the math works out */
 
-	    srcRect.size.width = round(srcRect.size.width);
-	    srcRect.size.height = round(srcRect.size.height);
+	    srcRect.size.width = round (srcRect.size.width);
+	    srcRect.size.height = round (srcRect.size.height);
 
 	    xform = CGAffineTransformInvert (xform);
 
@@ -1668,9 +1671,9 @@ _cairo_quartz_setup_source (cairo_quartz_surface_t *surface,
 	// Save before we change the pattern, colorspace, etc. so that
 	// we can restore and make sure that quartz releases our
 	// pattern (which may be stack allocated)
-	CGContextSaveGState(surface->cgContext);
+	CGContextSaveGState (surface->cgContext);
 
-	patternSpace = CGColorSpaceCreatePattern(NULL);
+	patternSpace = CGColorSpaceCreatePattern (NULL);
 	CGContextSetFillColorSpace (surface->cgContext, patternSpace);
 	CGContextSetFillPattern (surface->cgContext, pattern, &patternAlpha);
 	CGContextSetStrokeColorSpace (surface->cgContext, patternSpace);
@@ -1681,7 +1684,7 @@ _cairo_quartz_setup_source (cairo_quartz_surface_t *surface,
 	 * why); force it to 0,0 as we've already baked in the correct
 	 * pattern translation into the pattern matrix
 	 */
-	CGContextSetPatternPhase (surface->cgContext, CGSizeMake(0,0));
+	CGContextSetPatternPhase (surface->cgContext, CGSizeMake (0, 0));
 
 	surface->sourcePattern = pattern;
 
@@ -1698,22 +1701,22 @@ _cairo_quartz_teardown_source (cairo_quartz_surface_t *surface,
     CGContextSetInterpolationQuality (surface->cgContext, surface->oldInterpolationQuality);
 
     if (surface->sourceImage) {
-	CGImageRelease(surface->sourceImage);
+	CGImageRelease (surface->sourceImage);
 	surface->sourceImage = NULL;
 
-	cairo_surface_destroy(surface->sourceImageSurface);
+	cairo_surface_destroy (surface->sourceImageSurface);
 	surface->sourceImageSurface = NULL;
     }
 
     if (surface->sourceShading) {
-	CGShadingRelease(surface->sourceShading);
+	CGShadingRelease (surface->sourceShading);
 	surface->sourceShading = NULL;
     }
 
     if (surface->sourcePattern) {
-	CGPatternRelease(surface->sourcePattern);
+	CGPatternRelease (surface->sourcePattern);
 	// To tear down the pattern and colorspace
-	CGContextRestoreGState(surface->cgContext);
+	CGContextRestoreGState (surface->cgContext);
 
 	surface->sourcePattern = NULL;
     }
@@ -1731,7 +1734,7 @@ _cairo_quartz_draw_image (cairo_quartz_surface_t *surface, cairo_operator_t op,
 
     if (action == DO_IMAGE) {
 	CGContextDrawImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
-	if (!_cairo_operator_bounded_by_source(op)) {
+	if (!_cairo_operator_bounded_by_source (op)) {
 	    CGContextBeginPath (surface->cgContext);
 	    CGContextAddRect (surface->cgContext, surface->sourceImageRect);
 	    CGContextAddRect (surface->cgContext, CGContextGetClipBoundingBox (surface->cgContext));
@@ -1755,24 +1758,24 @@ _cairo_quartz_get_image (cairo_quartz_surface_t *surface,
     unsigned char *imageData;
     cairo_image_surface_t *isurf;
 
-    if (IS_EMPTY(surface)) {
+    if (IS_EMPTY (surface)) {
 	*image_out = (cairo_image_surface_t*) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0);
 	return CAIRO_STATUS_SUCCESS;
     }
 
     if (surface->imageSurfaceEquiv) {
-	*image_out = (cairo_image_surface_t*) cairo_surface_reference(surface->imageSurfaceEquiv);
+	*image_out = (cairo_image_surface_t*) cairo_surface_reference (surface->imageSurfaceEquiv);
 	return CAIRO_STATUS_SUCCESS;
     }
 
-    if (_cairo_quartz_is_cgcontext_bitmap_context(surface->cgContext)) {
+    if (_cairo_quartz_is_cgcontext_bitmap_context (surface->cgContext)) {
 	unsigned int stride;
 	unsigned int bitinfo;
 	unsigned int bpc, bpp;
 	CGColorSpaceRef colorspace;
 	unsigned int color_comps;
 
-	imageData = (unsigned char *) CGBitmapContextGetData(surface->cgContext);
+	imageData = (unsigned char *) CGBitmapContextGetData (surface->cgContext);
 
 #ifdef USE_10_3_WORKAROUNDS
 	bitinfo = CGBitmapContextGetAlphaInfo (surface->cgContext);
@@ -1785,7 +1788,7 @@ _cairo_quartz_get_image (cairo_quartz_surface_t *surface,
 
 	// let's hope they don't add YUV under us
 	colorspace = CGBitmapContextGetColorSpace (surface->cgContext);
-	color_comps = CGColorSpaceGetNumberOfComponents(colorspace);
+	color_comps = CGColorSpaceGetNumberOfComponents (colorspace);
 
 	// XXX TODO: We can handle all of these by converting to
 	// pixman masks, including non-native-endian masks
@@ -1846,9 +1849,9 @@ _cairo_quartz_surface_finish (void *abstract_surface)
 {
     cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
 
-    ND((stderr, "_cairo_quartz_surface_finish[%p] cgc: %p\n", surface, surface->cgContext));
+    ND ((stderr, "_cairo_quartz_surface_finish[%p] cgc: %p\n", surface, surface->cgContext));
 
-    if (IS_EMPTY(surface))
+    if (IS_EMPTY (surface))
 	return CAIRO_STATUS_SUCCESS;
 
     /* Restore our saved gstate that we use to reset clipping */
@@ -1880,7 +1883,7 @@ _cairo_quartz_surface_acquire_source_image (void *abstract_surface,
     cairo_int_status_t status;
     cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
 
-    //ND((stderr, "%p _cairo_quartz_surface_acquire_source_image\n", surface));
+    //ND ((stderr, "%p _cairo_quartz_surface_acquire_source_image\n", surface));
 
     status = _cairo_quartz_get_image (surface, image_out);
     if (status)
@@ -1927,7 +1930,7 @@ _cairo_quartz_surface_acquire_dest_image (void *abstract_surface,
     cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
     cairo_int_status_t status;
 
-    ND((stderr, "%p _cairo_quartz_surface_acquire_dest_image\n", surface));
+    ND ((stderr, "%p _cairo_quartz_surface_acquire_dest_image\n", surface));
 
     status = _cairo_quartz_get_image (surface, image_out);
     if (status)
@@ -1948,7 +1951,7 @@ _cairo_quartz_surface_release_dest_image (void *abstract_surface,
 {
     //cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
 
-    //ND((stderr, "%p _cairo_quartz_surface_release_dest_image\n", surface));
+    //ND ((stderr, "%p _cairo_quartz_surface_release_dest_image\n", surface));
 
     cairo_surface_destroy (&image->base);
 }
@@ -1973,7 +1976,7 @@ _cairo_quartz_surface_create_similar (void *abstract_surface,
 	return NULL;
 
     // verify width and height of surface
-    if (!_cairo_quartz_verify_surface_size(width, height)) {
+    if (!_cairo_quartz_verify_surface_size (width, height)) {
 	return _cairo_surface_create_in_error (_cairo_error
 					       (CAIRO_STATUS_INVALID_SIZE));
     }
@@ -2000,7 +2003,7 @@ _cairo_quartz_surface_clone_similar (void *abstract_surface,
     *clone_out = NULL;
 
     // verify width and height of surface
-    if (!_cairo_quartz_verify_surface_size(width, height)) {
+    if (!_cairo_quartz_verify_surface_size (width, height)) {
 	return CAIRO_INT_STATUS_UNSUPPORTED;
     }
 
@@ -2053,7 +2056,7 @@ _cairo_quartz_surface_clone_similar (void *abstract_surface,
 
     CGContextTranslateCTM (new_surface->cgContext, -src_x, -src_y);
     CGContextDrawImage (new_surface->cgContext,
-			CGRectMake (0, 0, CGImageGetWidth(quartz_image), CGImageGetHeight(quartz_image)),
+			CGRectMake (0, 0, CGImageGetWidth (quartz_image), CGImageGetHeight (quartz_image)),
 			quartz_image);
 
     CGContextRestoreGState (new_surface->cgContext);
@@ -2088,9 +2091,9 @@ _cairo_quartz_surface_paint_cg (void *abstract_surface,
     cairo_int_status_t rv = CAIRO_STATUS_SUCCESS;
     cairo_quartz_action_t action;
 
-    ND((stderr, "%p _cairo_quartz_surface_paint op %d source->type %d\n", surface, op, source->type));
+    ND ((stderr, "%p _cairo_quartz_surface_paint op %d source->type %d\n", surface, op, source->type));
 
-    if (IS_EMPTY(surface))
+    if (IS_EMPTY (surface))
 	return CAIRO_STATUS_SUCCESS;
 
     rv = _cairo_surface_clipper_set_clip (&surface->clipper, clip);
@@ -2104,10 +2107,10 @@ _cairo_quartz_surface_paint_cg (void *abstract_surface,
     action = _cairo_quartz_setup_source (surface, source, NULL);
 
     if (action == DO_SOLID || action == DO_PATTERN) {
-	CGContextFillRect (surface->cgContext, CGRectMake(surface->extents.x,
-							  surface->extents.y,
-							  surface->extents.width,
-							  surface->extents.height));
+	CGContextFillRect (surface->cgContext, CGRectMake (surface->extents.x,
+							   surface->extents.y,
+							   surface->extents.width,
+							   surface->extents.height));
     } else if (action == DO_SHADING) {
 	CGContextSaveGState (surface->cgContext);
 	CGContextConcatCTM (surface->cgContext, surface->sourceTransform);
@@ -2123,7 +2126,7 @@ _cairo_quartz_surface_paint_cg (void *abstract_surface,
 
     _cairo_quartz_teardown_source (surface, source);
 
-    ND((stderr, "-- paint\n"));
+    ND ((stderr, "-- paint\n"));
     return rv;
 }
 
@@ -2188,9 +2191,9 @@ _cairo_quartz_surface_fill_cg (void *abstract_surface,
     cairo_quartz_action_t action;
     CGPathRef path_for_unbounded = NULL;
 
-    ND((stderr, "%p _cairo_quartz_surface_fill op %d source->type %d\n", surface, op, source->type));
+    ND ((stderr, "%p _cairo_quartz_surface_fill op %d source->type %d\n", surface, op, source->type));
 
-    if (IS_EMPTY(surface))
+    if (IS_EMPTY (surface))
 	return CAIRO_STATUS_SUCCESS;
 
     rv = _cairo_surface_clipper_set_clip (&surface->clipper, clip);
@@ -2219,7 +2222,7 @@ _cairo_quartz_surface_fill_cg (void *abstract_surface,
 
     _cairo_quartz_cairo_path_to_quartz_context (path, surface->cgContext);
 
-    if (!_cairo_operator_bounded_by_mask(op) && CGContextCopyPathPtr)
+    if (!_cairo_operator_bounded_by_mask (op) && CGContextCopyPathPtr)
 	path_for_unbounded = CGContextCopyPathPtr (surface->cgContext);
 
     if (action == DO_SOLID || action == DO_PATTERN) {
@@ -2263,7 +2266,7 @@ _cairo_quartz_surface_fill_cg (void *abstract_surface,
 	CGPathRelease (path_for_unbounded);
     }
 
-    ND((stderr, "-- fill\n"));
+    ND ((stderr, "-- fill\n"));
     return rv;
 }
 
@@ -2322,9 +2325,9 @@ _cairo_quartz_surface_stroke_cg (void *abstract_surface,
     CGAffineTransform origCTM, strokeTransform;
     CGPathRef path_for_unbounded = NULL;
 
-    ND((stderr, "%p _cairo_quartz_surface_stroke op %d source->type %d\n", surface, op, source->type));
+    ND ((stderr, "%p _cairo_quartz_surface_stroke op %d source->type %d\n", surface, op, source->type));
 
-    if (IS_EMPTY(surface))
+    if (IS_EMPTY (surface))
 	return CAIRO_STATUS_SUCCESS;
 
     rv = _cairo_surface_clipper_set_clip (&surface->clipper, clip);
@@ -2433,7 +2436,7 @@ _cairo_quartz_surface_stroke_cg (void *abstract_surface,
 	CGPathRelease (ub.u.stroke_fill.cgPath);
     }
 
-    ND((stderr, "-- stroke\n"));
+    ND ((stderr, "-- stroke\n"));
     return rv;
 }
 
@@ -2502,7 +2505,7 @@ _cairo_quartz_surface_show_glyphs_cg (void *abstract_surface,
     cairo_bool_t isClipping = FALSE;
     cairo_bool_t didForceFontSmoothing = FALSE;
 
-    if (IS_EMPTY(surface))
+    if (IS_EMPTY (surface))
 	return CAIRO_STATUS_SUCCESS;
 
     if (num_glyphs <= 0)
@@ -2570,13 +2573,13 @@ _cairo_quartz_surface_show_glyphs_cg (void *abstract_surface,
     }
 
     if (num_glyphs > STATIC_BUF_SIZE) {
-	cg_glyphs = (CGGlyph*) _cairo_malloc_ab (num_glyphs, sizeof(CGGlyph));
+	cg_glyphs = (CGGlyph*) _cairo_malloc_ab (num_glyphs, sizeof (CGGlyph));
 	if (cg_glyphs == NULL) {
 	    rv = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto BAIL;
 	}
 
-	cg_advances = (CGSize*) _cairo_malloc_ab (num_glyphs, sizeof(CGSize));
+	cg_advances = (CGSize*) _cairo_malloc_ab (num_glyphs, sizeof (CGSize));
 	if (cg_advances == NULL) {
 	    rv = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto BAIL;
@@ -2603,7 +2606,7 @@ _cairo_quartz_surface_show_glyphs_cg (void *abstract_surface,
 	cairo_quartz_float_t xf = glyphs[i].x;
 	cairo_quartz_float_t yf = glyphs[i].y;
 	cg_glyphs[i] = glyphs[i].index;
-	cg_advances[i - 1] = CGSizeApplyAffineTransform(CGSizeMake (xf - xprev, yf - yprev), invTextTransform);
+	cg_advances[i - 1] = CGSizeApplyAffineTransform (CGSizeMake (xf - xprev, yf - yprev), invTextTransform);
 	xprev = xf;
 	yprev = yf;
     }
@@ -2734,7 +2737,7 @@ _cairo_quartz_surface_mask_with_surface (cairo_quartz_surface_t *surface,
     ctm = CGContextGetCTM (surface->cgContext);
 
     _cairo_quartz_cairo_matrix_to_quartz (&mask->base.matrix, &mask_matrix);
-    mask_matrix = CGAffineTransformInvert(mask_matrix);
+    mask_matrix = CGAffineTransformInvert (mask_matrix);
     mask_matrix = CGAffineTransformTranslate (mask_matrix, 0.0, CGImageGetHeight (img));
     mask_matrix = CGAffineTransformScale (mask_matrix, 1.0, -1.0);
 
@@ -2810,9 +2813,9 @@ _cairo_quartz_surface_mask_cg (void *abstract_surface,
     cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
     cairo_int_status_t rv = CAIRO_STATUS_SUCCESS;
 
-    ND((stderr, "%p _cairo_quartz_surface_mask op %d source->type %d mask->type %d\n", surface, op, source->type, mask->type));
+    ND ((stderr, "%p _cairo_quartz_surface_mask op %d source->type %d mask->type %d\n", surface, op, source->type, mask->type));
 
-    if (IS_EMPTY(surface))
+    if (IS_EMPTY (surface))
 	return CAIRO_STATUS_SUCCESS;
 
     rv = _cairo_surface_clipper_set_clip (&surface->clipper, clip);
@@ -2888,9 +2891,9 @@ _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);
 
-    ND((stderr, "%p _cairo_quartz_surface_intersect_clip_path path: %p\n", surface, path));
+    ND ((stderr, "%p _cairo_quartz_surface_intersect_clip_path path: %p\n", surface, path));
 
-    if (IS_EMPTY(surface))
+    if (IS_EMPTY (surface))
 	return CAIRO_STATUS_SUCCESS;
 
     if (path == NULL) {
@@ -2914,7 +2917,7 @@ _cairo_quartz_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clip
 	    CGContextEOClip (surface->cgContext);
     }
 
-    ND((stderr, "-- intersect_clip_path\n"));
+    ND ((stderr, "-- intersect_clip_path\n"));
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -2964,14 +2967,14 @@ _cairo_quartz_surface_create_internal (CGContextRef cgContext,
 {
     cairo_quartz_surface_t *surface;
 
-    quartz_ensure_symbols();
+    quartz_ensure_symbols ();
 
     /* Init the base surface */
-    surface = malloc(sizeof(cairo_quartz_surface_t));
+    surface = malloc (sizeof (cairo_quartz_surface_t));
     if (surface == NULL)
 	return (cairo_quartz_surface_t*) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
-    memset(surface, 0, sizeof(cairo_quartz_surface_t));
+    memset (surface, 0, sizeof (cairo_quartz_surface_t));
 
     _cairo_surface_init (&surface->base,
 			 &cairo_quartz_surface_backend,
@@ -2986,7 +2989,7 @@ _cairo_quartz_surface_create_internal (CGContextRef cgContext,
     surface->extents.width = width;
     surface->extents.height = height;
 
-    if (IS_EMPTY(surface)) {
+    if (IS_EMPTY (surface)) {
 	surface->cgContext = NULL;
 	surface->cgContextBaseCTM = CGAffineTransformIdentity;
 	surface->imageData = NULL;
@@ -3083,7 +3086,7 @@ cairo_quartz_surface_create (cairo_format_t format,
     int bitsPerComponent;
 
     // verify width and height of surface
-    if (!_cairo_quartz_verify_surface_size(width, height))
+    if (!_cairo_quartz_verify_surface_size (width, height))
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
 
     if (width == 0 || height == 0) {
@@ -3094,7 +3097,7 @@ cairo_quartz_surface_create (cairo_format_t format,
     if (format == CAIRO_FORMAT_ARGB32 ||
 	format == CAIRO_FORMAT_RGB24)
     {
-	cgColorspace = CGColorSpaceCreateDeviceRGB();
+	cgColorspace = CGColorSpaceCreateDeviceRGB ();
 	bitinfo = kCGBitmapByteOrder32Host;
 	if (format == CAIRO_FORMAT_ARGB32)
 	    bitinfo |= kCGImageAlphaPremultipliedFirst;
@@ -3198,11 +3201,11 @@ _cairo_surface_is_quartz (const cairo_surface_t *surface)
 
 #include <Movies.h>
 
-void ExportCGImageToPNGFile(CGImageRef inImageRef, char* dest)
+void ExportCGImageToPNGFile (CGImageRef inImageRef, char* dest)
 {
     Handle  dataRef = NULL;
     OSType  dataRefType;
-    CFStringRef inPath = CFStringCreateWithCString(NULL, dest, kCFStringEncodingASCII);
+    CFStringRef inPath = CFStringCreateWithCString (NULL, dest, kCFStringEncodingASCII);
 
     GraphicsExportComponent grex = 0;
     unsigned long sizeWritten;
@@ -3210,35 +3213,35 @@ void ExportCGImageToPNGFile(CGImageRef inImageRef, char* dest)
     ComponentResult result;
 
     // create the data reference
-    result = QTNewDataReferenceFromFullPathCFString(inPath, kQTNativeDefaultPathStyle,
-						    0, &dataRef, &dataRefType);
+    result = QTNewDataReferenceFromFullPathCFString (inPath, kQTNativeDefaultPathStyle,
+						     0, &dataRef, &dataRefType);
 
     if (NULL != dataRef && noErr == result) {
 	// get the PNG exporter
-	result = OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypePNG,
-				       &grex);
+	result = OpenADefaultComponent (GraphicsExporterComponentType, kQTFileTypePNG,
+					&grex);
 
 	if (grex) {
 	    // tell the exporter where to find its source image
-	    result = GraphicsExportSetInputCGImage(grex, inImageRef);
+	    result = GraphicsExportSetInputCGImage (grex, inImageRef);
 
 	    if (noErr == result) {
 		// tell the exporter where to save the exporter image
-		result = GraphicsExportSetOutputDataReference(grex, dataRef,
-							      dataRefType);
+		result = GraphicsExportSetOutputDataReference (grex, dataRef,
+							       dataRefType);
 
 		if (noErr == result) {
 		    // write the PNG file
-		    result = GraphicsExportDoExport(grex, &sizeWritten);
+		    result = GraphicsExportDoExport (grex, &sizeWritten);
 		}
 	    }
 
 	    // remember to close the component
-	    CloseComponent(grex);
+	    CloseComponent (grex);
 	}
 
 	// remember to dispose of the data reference handle
-	DisposeHandle(dataRef);
+	DisposeHandle (dataRef);
     }
 }
 
@@ -3255,7 +3258,7 @@ quartz_image_to_png (CGImageRef imgref, char *dest)
 	dest = sptr;
     }
 
-    ExportCGImageToPNGFile(imgref, dest);
+    ExportCGImageToPNGFile (imgref, dest);
 }
 
 void
@@ -3282,9 +3285,9 @@ quartz_surface_to_png (cairo_quartz_surface_t *nq, char *dest)
 	return;
     }
 
-    ExportCGImageToPNGFile(imgref, dest);
+    ExportCGImageToPNGFile (imgref, dest);
 
-    CGImageRelease(imgref);
+    CGImageRelease (imgref);
 }
 
 #endif /* QUARTZ_DEBUG */
commit 692f20a8592ed2730b63c084224d996225912b53
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Tue Jul 27 16:06:27 2010 +0200

    quartz: Don't typecast surfaces
    
    Casting to (cairo_surface_t *) is considered bad practice. The
    correct way to get a reference to the generic surface information
    is &(surface->base)

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 21f4aa6..441d591 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -1910,10 +1910,10 @@ _cairo_quartz_surface_snapshot (void *abstract_surface)
 
 static void
 _cairo_quartz_surface_release_source_image (void *abstract_surface,
-					     cairo_image_surface_t *image,
-					     void *image_extra)
+					    cairo_image_surface_t *image,
+					    void *image_extra)
 {
-    cairo_surface_destroy ((cairo_surface_t *) image);
+    cairo_surface_destroy (&image->base);
 }
 
 
@@ -1950,7 +1950,7 @@ _cairo_quartz_surface_release_dest_image (void *abstract_surface,
 
     //ND((stderr, "%p _cairo_quartz_surface_release_dest_image\n", surface));
 
-    cairo_surface_destroy ((cairo_surface_t *) image);
+    cairo_surface_destroy (&image->base);
 }
 
 static cairo_surface_t *
@@ -2005,9 +2005,8 @@ _cairo_quartz_surface_clone_similar (void *abstract_surface,
     }
 
     if (width == 0 || height == 0) {
-	*clone_out = (cairo_surface_t*)
-	    _cairo_quartz_surface_create_internal (NULL, CAIRO_CONTENT_COLOR_ALPHA,
-						   width, height);
+	*clone_out = &_cairo_quartz_surface_create_internal (NULL, CAIRO_CONTENT_COLOR_ALPHA,
+							     width, height)->base;
 	*clone_offset_x = 0;
 	*clone_offset_y = 0;
 	return CAIRO_STATUS_SUCCESS;
@@ -2016,10 +2015,11 @@ _cairo_quartz_surface_clone_similar (void *abstract_surface,
     if (_cairo_surface_is_quartz (src)) {
 	cairo_quartz_surface_t *qsurf = (cairo_quartz_surface_t *) src;
 
-	if (IS_EMPTY(qsurf)) {
-	    *clone_out = (cairo_surface_t*)
-		_cairo_quartz_surface_create_internal (NULL, CAIRO_CONTENT_COLOR_ALPHA,
-						       qsurf->extents.width, qsurf->extents.height);
+	if (IS_EMPTY (qsurf)) {
+	    *clone_out = &_cairo_quartz_surface_create_internal (NULL,
+								 CAIRO_CONTENT_COLOR_ALPHA,
+								 qsurf->extents.width,
+								 qsurf->extents.height)->base;
 	    *clone_offset_x = 0;
 	    *clone_offset_y = 0;
 	    return CAIRO_STATUS_SUCCESS;
@@ -2063,7 +2063,7 @@ _cairo_quartz_surface_clone_similar (void *abstract_surface,
 FINISH:
     *clone_offset_x = src_x;
     *clone_offset_y = src_y;
-    *clone_out = (cairo_surface_t*) new_surface;
+    *clone_out = &new_surface->base;
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -3048,10 +3048,10 @@ cairo_quartz_surface_create_for_cg_context (CGContextRef cgContext,
     if (surf->base.status) {
 	CGContextRelease (cgContext);
 	// create_internal will have set an error
-	return (cairo_surface_t*) surf;
+	return &surf->base;
     }
 
-    return (cairo_surface_t *) surf;
+    return &surf->base;
 }
 
 /**
@@ -3087,8 +3087,8 @@ cairo_quartz_surface_create (cairo_format_t format,
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
 
     if (width == 0 || height == 0) {
-	return (cairo_surface_t*) _cairo_quartz_surface_create_internal (NULL, _cairo_content_from_format (format),
-									 width, height);
+	return &_cairo_quartz_surface_create_internal (NULL, _cairo_content_from_format (format),
+						       width, height)->base;
     }
 
     if (format == CAIRO_FORMAT_ARGB32 ||
@@ -3156,13 +3156,13 @@ cairo_quartz_surface_create (cairo_format_t format,
 	CGContextRelease (cgc);
 	free (imageData);
 	// create_internal will have set an error
-	return (cairo_surface_t*) surf;
+	return &surf->base;
     }
 
     surf->imageData = imageData;
     surf->imageSurfaceEquiv = cairo_image_surface_create_for_data (imageData, format, width, height, stride);
 
-    return (cairo_surface_t *) surf;
+    return &surf->base;
 }
 
 /**
commit b922477e4e31198739098dff1bc1ed49f81e4745
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Tue Jul 27 14:44:17 2010 +0200

    quartz: Check for valid patterns
    
    The pattern handling code ensures that 0 stops patterns are reduced
    to clear solid patterns before being passed down to the backend.
    An assertion is used to make sure that the assumption actually holds,
    removing the duplication of the reduce-to-solid-clear logic.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index d0c3391..21f4aa6 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -1250,8 +1250,7 @@ _cairo_quartz_cairo_repeating_surface_pattern_to_quartz (cairo_quartz_surface_t
     cairo_matrix_t m;
 
     /* SURFACE is the only type we'll handle here */
-    if (apattern->type != CAIRO_PATTERN_TYPE_SURFACE)
-	return CAIRO_INT_STATUS_UNSUPPORTED;
+    assert (apattern->type == CAIRO_PATTERN_TYPE_SURFACE);
 
     spattern = (cairo_surface_pattern_t *) apattern;
     pat_surf = spattern->surface;
@@ -1431,11 +1430,7 @@ _cairo_quartz_setup_linear_source (cairo_quartz_surface_t *surface,
     CGColorSpaceRef rgb;
     bool extend = abspat->extend == CAIRO_EXTEND_PAD;
 
-    if (lpat->base.n_stops == 0) {
-	CGContextSetRGBStrokeColor (surface->cgContext, 0., 0., 0., 0.);
-	CGContextSetRGBFillColor (surface->cgContext, 0., 0., 0., 0.);
-	return DO_SOLID;
-    }
+    assert (lpat->base.n_stops > 0);
 
     if (lpat->p1.x == lpat->p2.x &&
         lpat->p1.y == lpat->p2.y) {
@@ -1501,11 +1496,7 @@ _cairo_quartz_setup_radial_source (cairo_quartz_surface_t *surface,
     double dy = c1y - c2y;
     double centerDistance = sqrt (dx*dx + dy*dy);
 
-    if (rpat->base.n_stops == 0) {
-	CGContextSetRGBStrokeColor (surface->cgContext, 0., 0., 0., 0.);
-	CGContextSetRGBFillColor (surface->cgContext, 0., 0., 0., 0.);
-	return DO_SOLID;
-    }
+    assert (rpat->base.n_stops > 0);
 
     if (r2 <= centerDistance + r1 + 1e-6 && /* circle 2 doesn't contain circle 1 */
         r1 <= centerDistance + r2 + 1e-6) { /* circle 1 doesn't contain circle 2 */
commit c9aa393a4db15eeb1ea29aaf5bca4b2570a0cfab
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Tue Jul 27 14:43:15 2010 +0200

    quartz: Assert upon invalid enum values
    
    Invalid enum values were being ignored (and replaced by a default
    value). This behavior is not desirable on development builds,
    because an explicit failure is much easier to track.
    Assertions allow release builds to keep on with the old behaviour,
    while development builds fail as soon as the invalid operaiton is
    performed.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index a89e0c2..d0c3391 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -538,44 +538,58 @@ static inline CGLineCap
 _cairo_quartz_cairo_line_cap_to_quartz (cairo_line_cap_t ccap)
 {
     switch (ccap) {
-	case CAIRO_LINE_CAP_BUTT: return kCGLineCapButt; break;
-	case CAIRO_LINE_CAP_ROUND: return kCGLineCapRound; break;
-	case CAIRO_LINE_CAP_SQUARE: return kCGLineCapSquare; break;
-    }
+    default:
+	ASSERT_NOT_REACHED;
+
+    case CAIRO_LINE_CAP_BUTT:
+	return kCGLineCapButt;
+
+    case CAIRO_LINE_CAP_ROUND:
+	return kCGLineCapRound;
 
-    return kCGLineCapButt;
+    case CAIRO_LINE_CAP_SQUARE:
+	return kCGLineCapSquare;
+    }
 }
 
 static inline CGLineJoin
 _cairo_quartz_cairo_line_join_to_quartz (cairo_line_join_t cjoin)
 {
     switch (cjoin) {
-	case CAIRO_LINE_JOIN_MITER: return kCGLineJoinMiter; break;
-	case CAIRO_LINE_JOIN_ROUND: return kCGLineJoinRound; break;
-	case CAIRO_LINE_JOIN_BEVEL: return kCGLineJoinBevel; break;
-    }
+    default:
+	ASSERT_NOT_REACHED;
 
-    return kCGLineJoinMiter;
+    case CAIRO_LINE_JOIN_MITER:
+	return kCGLineJoinMiter;
+
+    case CAIRO_LINE_JOIN_ROUND:
+	return kCGLineJoinRound;
+
+    case CAIRO_LINE_JOIN_BEVEL:
+	return kCGLineJoinBevel;
+    }
 }
 
 static inline CGInterpolationQuality
 _cairo_quartz_filter_to_quartz (cairo_filter_t filter)
 {
     switch (filter) {
-	case CAIRO_FILTER_NEAREST:
-	    return kCGInterpolationNone;
+    case CAIRO_FILTER_NEAREST:
+	return kCGInterpolationNone;
 
-	case CAIRO_FILTER_FAST:
-	    return kCGInterpolationLow;
+    case CAIRO_FILTER_FAST:
+	return kCGInterpolationLow;
 
-	case CAIRO_FILTER_BEST:
-	case CAIRO_FILTER_GOOD:
-	case CAIRO_FILTER_BILINEAR:
-	case CAIRO_FILTER_GAUSSIAN:
-	    return kCGInterpolationDefault;
-    }
+    case CAIRO_FILTER_BEST:
+    case CAIRO_FILTER_GOOD:
+    case CAIRO_FILTER_BILINEAR:
+    case CAIRO_FILTER_GAUSSIAN:
+	return kCGInterpolationDefault;
 
-    return kCGInterpolationDefault;
+    default:
+	ASSERT_NOT_REACHED;
+	return kCGInterpolationDefault;
+    }
 }
 
 static inline void
commit 9c22f97ebdcc9303d1a1530e7909d6b0d74d30e4
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Tue Jul 27 14:38:28 2010 +0200

    quartz: Remove unused argument from _cairo_surface_to_cgimage

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 113674f..a89e0c2 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -1101,8 +1101,7 @@ DataProviderReleaseCallback (void *info, const void *data, size_t size)
 }
 
 static cairo_status_t
-_cairo_surface_to_cgimage (cairo_surface_t *target,
-			   cairo_surface_t *source,
+_cairo_surface_to_cgimage (cairo_surface_t *source,
 			   CGImageRef *image_out)
 {
     cairo_status_t status;
@@ -1246,7 +1245,7 @@ _cairo_quartz_cairo_repeating_surface_pattern_to_quartz (cairo_quartz_surface_t
     is_bounded = _cairo_surface_get_extents (pat_surf, &extents);
     assert (is_bounded);
 
-    status = _cairo_surface_to_cgimage ((cairo_surface_t*) dest, pat_surf, &image);
+    status = _cairo_surface_to_cgimage (pat_surf, &image);
     if (status)
 	return status;
     if (image == NULL)
@@ -1379,7 +1378,7 @@ _cairo_quartz_setup_fallback_source (cairo_quartz_surface_t *surface,
     }
 #endif
 
-    status = _cairo_surface_to_cgimage (&surface->base, fallback, &img);
+    status = _cairo_surface_to_cgimage (fallback, &img);
     if (status)
 	return DO_UNSUPPORTED;
     if (img == NULL)
@@ -1591,7 +1590,7 @@ _cairo_quartz_setup_source (cairo_quartz_surface_t *surface,
 	cairo_fixed_t fw, fh;
 	cairo_bool_t is_bounded;
 
-	status = _cairo_surface_to_cgimage ((cairo_surface_t *) surface, pat_surf, &img);
+	status = _cairo_surface_to_cgimage (pat_surf, &img);
 	if (status)
 	    return DO_UNSUPPORTED;
 	if (img == NULL)
@@ -2022,7 +2021,7 @@ _cairo_quartz_surface_clone_similar (void *abstract_surface,
 	}
     }
 
-    status = _cairo_surface_to_cgimage ((cairo_surface_t*) abstract_surface, src, &quartz_image);
+    status = _cairo_surface_to_cgimage (src, &quartz_image);
     if (status)
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
@@ -2712,7 +2711,7 @@ _cairo_quartz_surface_mask_with_surface (cairo_quartz_surface_t *surface,
     cairo_status_t status = CAIRO_STATUS_SUCCESS;
     CGAffineTransform ctm, mask_matrix;
 
-    status = _cairo_surface_to_cgimage ((cairo_surface_t *) surface, pat_surf, &img);
+    status = _cairo_surface_to_cgimage (pat_surf, &img);
     if (status)
 	return status;
     if (img == NULL) {


More information about the cairo-commit mailing list