[cairo] [PATCH 1/2] Fix const cairo_pattern_t * in the quartz backend.

Jeff Muizelaar jeff at infidigm.net
Mon Nov 10 17:05:23 PST 2008


794460186459981cd43ca38f3eba07e3f6bf8908 broke the quartz backend.
Fix it by adding const to the appropriate parameters in the function
declarations and copying the pattern when needed.
---
 src/cairo-quartz-surface.c |   44 +++++++++++++++++++++++++++-----------------
 1 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 2addd8b..6fa368b 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -631,7 +631,7 @@ static void
 ComputeGradientValue (void *info, const float *in, float *out)
 {
     double fdist = *in;
-    cairo_gradient_pattern_t *grad = (cairo_gradient_pattern_t*) info;
+    const cairo_gradient_pattern_t *grad = (cairo_gradient_pattern_t*) info;
     unsigned int i;
 
     /* Put fdist back in the 0.0..1.0 range if we're doing
@@ -688,7 +688,9 @@ CreateGradientFunction (cairo_gradient_pattern_t *gpat)
 	0, ComputeGradientValue, (CGFunctionReleaseInfoCallback) cairo_pattern_destroy
     };
 
-    return CGFunctionCreate (_cairo_pattern_create_copy (&gpat->base),
+    cairo_pattern_reference (&gpat->base);
+
+    return CGFunctionCreate (gpat,
 			     1,
 			     input_value_range,
 			     4,
@@ -766,7 +768,9 @@ CreateRepeatingGradientFunction (cairo_quartz_surface_t *surface,
     input_value_range[0] = 0.0 - 1.0 * rep_start;
     input_value_range[1] = 1.0 + 1.0 * rep_end;
 
-    return CGFunctionCreate (_cairo_pattern_create_copy (&gpat->base),
+    cairo_pattern_reference (&gpat->base);
+
+    return CGFunctionCreate (gpat,
 			     1,
 			     input_value_range,
 			     4,
@@ -904,7 +908,7 @@ SurfacePatternReleaseInfoFunc (void *ainfo)
 
 static cairo_int_status_t
 _cairo_quartz_cairo_repeating_surface_pattern_to_quartz (cairo_quartz_surface_t *dest,
-							 cairo_pattern_t *apattern,
+							 const cairo_pattern_t *apattern,
 							 CGPatternRef *cgpat)
 {
     cairo_surface_pattern_t *spattern;
@@ -1174,7 +1178,7 @@ _cairo_quartz_setup_radial_source (cairo_quartz_surface_t *surface,
 
 static cairo_quartz_action_t
 _cairo_quartz_setup_source (cairo_quartz_surface_t *surface,
-			    cairo_pattern_t *source)
+			    const cairo_pattern_t *source)
 {
     assert (!(surface->sourceImage || surface->sourceShading || surface->sourcePattern));
 
@@ -1320,7 +1324,7 @@ _cairo_quartz_setup_source (cairo_quartz_surface_t *surface,
 
 static void
 _cairo_quartz_teardown_source (cairo_quartz_surface_t *surface,
-				cairo_pattern_t *source)
+			       const cairo_pattern_t *source)
 {
     CGContextSetInterpolationQuality (surface->cgContext, surface->oldInterpolationQuality);
 
@@ -1667,7 +1671,7 @@ _cairo_quartz_surface_get_extents (void *abstract_surface,
 static cairo_int_status_t
 _cairo_quartz_surface_paint (void *abstract_surface,
 			     cairo_operator_t op,
-			     cairo_pattern_t *source,
+			     const cairo_pattern_t *source,
 			     cairo_rectangle_int_t *extents)
 {
     cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
@@ -1719,7 +1723,7 @@ _cairo_quartz_surface_paint (void *abstract_surface,
 static cairo_int_status_t
 _cairo_quartz_surface_fill (void *abstract_surface,
 			     cairo_operator_t op,
-			     cairo_pattern_t *source,
+			     const cairo_pattern_t *source,
 			     cairo_path_fixed_t *path,
 			     cairo_fill_rule_t fill_rule,
 			     double tolerance,
@@ -1825,7 +1829,7 @@ _cairo_quartz_surface_fill (void *abstract_surface,
 static cairo_int_status_t
 _cairo_quartz_surface_stroke (void *abstract_surface,
 			      cairo_operator_t op,
-			      cairo_pattern_t *source,
+			      const cairo_pattern_t *source,
 			      cairo_path_fixed_t *path,
 			      cairo_stroke_style_t *style,
 			      cairo_matrix_t *ctm,
@@ -1972,7 +1976,7 @@ _cairo_quartz_surface_stroke (void *abstract_surface,
 static cairo_int_status_t
 _cairo_quartz_surface_show_glyphs (void *abstract_surface,
 				   cairo_operator_t op,
-				   cairo_pattern_t *source,
+				   const cairo_pattern_t *source,
 				   cairo_glyph_t *glyphs,
 				   int num_glyphs,
 				   cairo_scaled_font_t *scaled_font,
@@ -2182,8 +2186,8 @@ BAIL:
 static cairo_int_status_t
 _cairo_quartz_surface_mask_with_surface (cairo_quartz_surface_t *surface,
                                          cairo_operator_t op,
-                                         cairo_pattern_t *source,
-                                         cairo_surface_pattern_t *mask)
+                                         const cairo_pattern_t *source,
+                                         const cairo_surface_pattern_t *mask)
 {
     cairo_rectangle_int_t extents;
     CGRect rect;
@@ -2247,8 +2251,8 @@ _cairo_quartz_surface_mask_with_surface (cairo_quartz_surface_t *surface,
 static cairo_int_status_t
 _cairo_quartz_surface_mask_with_generic (cairo_quartz_surface_t *surface,
 					 cairo_operator_t op,
-					 cairo_pattern_t *source,
-					 cairo_pattern_t *mask)
+					 const cairo_pattern_t *source,
+					 const cairo_pattern_t *mask)
 {
     int width = surface->extents.width - surface->extents.x;
     int height = surface->extents.height - surface->extents.y;
@@ -2257,6 +2261,7 @@ _cairo_quartz_surface_mask_with_generic (cairo_quartz_surface_t *surface,
     cairo_t *gradient_surf_cr = NULL;
 
     cairo_surface_pattern_t surface_pattern;
+    cairo_pattern_t *mask_copy = NULL;
     cairo_int_status_t status;
 
     /* Render the gradient to a surface */
@@ -2264,11 +2269,16 @@ _cairo_quartz_surface_mask_with_generic (cairo_quartz_surface_t *surface,
 						 width,
 						 height);
     gradient_surf_cr = cairo_create(gradient_surf);
-    cairo_set_source (gradient_surf_cr, mask);
+
+    /* make a copy of the pattern because it is const */
+    _cairo_pattern_create_copy (&mask_copy, mask);
+
+    cairo_set_source (gradient_surf_cr, mask_copy);
     cairo_set_operator (gradient_surf_cr, CAIRO_OPERATOR_SOURCE);
     cairo_paint (gradient_surf_cr);
     status = cairo_status (gradient_surf_cr);
     cairo_destroy (gradient_surf_cr);
+    cairo_pattern_destroy (mask_copy);
 
     if (status)
 	goto BAIL;
@@ -2289,8 +2299,8 @@ _cairo_quartz_surface_mask_with_generic (cairo_quartz_surface_t *surface,
 static cairo_int_status_t
 _cairo_quartz_surface_mask (void *abstract_surface,
 			    cairo_operator_t op,
-			    cairo_pattern_t *source,
-			    cairo_pattern_t *mask,
+			    const cairo_pattern_t *source,
+			    const cairo_pattern_t *mask,
 			    cairo_rectangle_int_t *extents)
 {
     cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;



More information about the cairo mailing list