[cairo] [PATCH 5/5] surface: Use the internal map/unmap

Andrea Canciani ranma42 at gmail.com
Sun Jan 15 05:59:08 PST 2012


In many places Cairo maps/unmaps surfaces to perform operations on the
raw image, but it doesn't case about the format being invalid. All of
these are appropriate users of _cairo_surface_map_to_image().
---
 src/cairo-fallback-compositor.c |  122 +++++++++++++++++----------------------
 src/cairo-gl-operand.c          |    4 +-
 src/cairo-surface-observer.c    |    6 +-
 src/cairo-surface.c             |    2 -
 src/cairo-xlib-source.c         |    8 +-
 src/cairoint.h                  |    2 -
 6 files changed, 63 insertions(+), 81 deletions(-)

diff --git a/src/cairo-fallback-compositor.c b/src/cairo-fallback-compositor.c
index 767fc6b..e1fd131 100644
--- a/src/cairo-fallback-compositor.c
+++ b/src/cairo-fallback-compositor.c
@@ -51,18 +51,16 @@ _cairo_fallback_compositor_paint (const cairo_compositor_t	*_compositor,
 				  cairo_composite_rectangles_t	*extents)
 {
     cairo_surface_t *image;
-    cairo_int_status_t status;
-
-    image = cairo_surface_map_to_image (extents->surface, &extents->unbounded);
-    status = _cairo_surface_offset_paint (image,
-					  extents->unbounded.x,
-					  extents->unbounded.y,
-					  extents->op,
-					  &extents->source_pattern.base,
-					  extents->clip);
-    cairo_surface_unmap_image (extents->surface, image);
-
-    return status;
+
+    image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded);
+    _cairo_surface_offset_paint (image,
+				 extents->unbounded.x,
+				 extents->unbounded.y,
+				 extents->op,
+				 &extents->source_pattern.base,
+				 extents->clip);
+
+    return _cairo_surface_unmap_image (extents->surface, image);
 }
 
 static cairo_int_status_t
@@ -70,19 +68,16 @@ _cairo_fallback_compositor_mask (const cairo_compositor_t	*_compositor,
 				 cairo_composite_rectangles_t	*extents)
 {
     cairo_surface_t *image;
-    cairo_int_status_t status;
-
-    image = cairo_surface_map_to_image (extents->surface, &extents->unbounded);
-    status = _cairo_surface_offset_mask (image,
-					 extents->unbounded.x,
-					 extents->unbounded.y,
-					 extents->op,
-					 &extents->source_pattern.base,
-					 &extents->mask_pattern.base,
-					 extents->clip);
-    cairo_surface_unmap_image (extents->surface, image);
-
-    return status;
+
+    image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded);
+    _cairo_surface_offset_mask (image,
+				extents->unbounded.x,
+				extents->unbounded.y,
+				extents->op,
+				&extents->source_pattern.base,
+				&extents->mask_pattern.base,
+				extents->clip);
+    return _cairo_surface_unmap_image (extents->surface, image);
 }
 
 static cairo_int_status_t
@@ -96,22 +91,19 @@ _cairo_fallback_compositor_stroke (const cairo_compositor_t	*_compositor,
 				   cairo_antialias_t		 antialias)
 {
     cairo_surface_t *image;
-    cairo_int_status_t status;
-
-    image = cairo_surface_map_to_image (extents->surface, &extents->unbounded);
-    status = _cairo_surface_offset_stroke (image,
-					   extents->unbounded.x,
-					   extents->unbounded.y,
-					   extents->op,
-					   &extents->source_pattern.base,
-					   path, style,
-					   ctm, ctm_inverse,
-					   tolerance,
-					   antialias,
-					   extents->clip);
-    cairo_surface_unmap_image (extents->surface, image);
-
-    return status;
+
+    image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded);
+    _cairo_surface_offset_stroke (image,
+				  extents->unbounded.x,
+				  extents->unbounded.y,
+				  extents->op,
+				  &extents->source_pattern.base,
+				  path, style,
+				  ctm, ctm_inverse,
+				  tolerance,
+				  antialias,
+				  extents->clip);
+    return _cairo_surface_unmap_image (extents->surface, image);
 }
 
 static cairo_int_status_t
@@ -123,20 +115,17 @@ _cairo_fallback_compositor_fill (const cairo_compositor_t	*_compositor,
 				 cairo_antialias_t		 antialias)
 {
     cairo_surface_t *image;
-    cairo_int_status_t status;
-
-    image = cairo_surface_map_to_image (extents->surface, &extents->unbounded);
-    status = _cairo_surface_offset_fill (image,
-					 extents->unbounded.x,
-					 extents->unbounded.y,
-					 extents->op,
-					 &extents->source_pattern.base,
-					 path,
-					 fill_rule, tolerance, antialias,
-					 extents->clip);
-    cairo_surface_unmap_image (extents->surface, image);
-
-    return status;
+
+    image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded);
+    _cairo_surface_offset_fill (image,
+				extents->unbounded.x,
+				extents->unbounded.y,
+				extents->op,
+				&extents->source_pattern.base,
+				path,
+				fill_rule, tolerance, antialias,
+				extents->clip);
+    return _cairo_surface_unmap_image (extents->surface, image);
 }
 
 static cairo_int_status_t
@@ -148,19 +137,16 @@ _cairo_fallback_compositor_glyphs (const cairo_compositor_t	*_compositor,
 				   cairo_bool_t			 overlap)
 {
     cairo_surface_t *image;
-    cairo_int_status_t status;
-
-    image = cairo_surface_map_to_image (extents->surface, &extents->unbounded);
-    status = _cairo_surface_offset_glyphs (image,
-					   extents->unbounded.x,
-					   extents->unbounded.y,
-					   extents->op,
-					   &extents->source_pattern.base,
-					   scaled_font, glyphs, num_glyphs,
-					   extents->clip);
-    cairo_surface_unmap_image (extents->surface, image);
-
-    return status;
+
+    image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded);
+    _cairo_surface_offset_glyphs (image,
+				  extents->unbounded.x,
+				  extents->unbounded.y,
+				  extents->op,
+				  &extents->source_pattern.base,
+				  scaled_font, glyphs, num_glyphs,
+				  extents->clip);
+    return _cairo_surface_unmap_image (extents->surface, image);
 }
 
 const cairo_compositor_t _cairo_fallback_compositor = {
diff --git a/src/cairo-gl-operand.c b/src/cairo-gl-operand.c
index bc5e541..4b7e9cc 100644
--- a/src/cairo-gl-operand.c
+++ b/src/cairo-gl-operand.c
@@ -244,10 +244,10 @@ _cairo_gl_pattern_texture_setup (cairo_gl_operand_t *operand,
 					  CAIRO_CONTENT_COLOR_ALPHA,
 					  extents->width, extents->height);
 
-    image = cairo_surface_map_to_image (&surface->base, NULL);
+    image = _cairo_surface_map_to_image (&surface->base, NULL);
     status = _cairo_surface_offset_paint (image, extents->x, extents->y,
 					  CAIRO_OPERATOR_SOURCE, _src, NULL);
-    cairo_surface_unmap_image (&surface->base, image);
+    status = _cairo_surface_unmap_image (&surface->base, image);
     status = _cairo_gl_context_release (ctx, status);
     if (unlikely (status)) {
 	cairo_surface_destroy (&surface->base);
diff --git a/src/cairo-surface-observer.c b/src/cairo-surface-observer.c
index dd25125..21dd121 100644
--- a/src/cairo-surface-observer.c
+++ b/src/cairo-surface-observer.c
@@ -656,9 +656,9 @@ sync (cairo_surface_t *target, int x, int y)
     extents.width  = 1;
     extents.height = 1;
 
-    cairo_surface_unmap_image (target,
-			       cairo_surface_map_to_image (target,
-							   &extents));
+    _cairo_surface_unmap_image (target,
+				_cairo_surface_map_to_image (target,
+							     &extents));
 }
 
 static void
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index d22728c..f523c75 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -842,7 +842,6 @@ cairo_surface_map_to_image (cairo_surface_t  *surface,
 
     return image;
 }
-slim_hidden_def (cairo_surface_map_to_image);
 
 /**
  * cairo_surface_unmap_image:
@@ -897,7 +896,6 @@ error:
     cairo_surface_finish (image);
     cairo_surface_destroy (image);
 }
-slim_hidden_def (cairo_surface_unmap_image);
 
 cairo_surface_t *
 _cairo_surface_create_similar_solid (cairo_surface_t	 *other,
diff --git a/src/cairo-xlib-source.c b/src/cairo-xlib-source.c
index a098cf2..98f1bfc 100644
--- a/src/cairo-xlib-source.c
+++ b/src/cairo-xlib-source.c
@@ -279,11 +279,11 @@ render_pattern (cairo_xlib_surface_t *dst,
 	return None;
     }
 
-    image = cairo_surface_map_to_image (&src->base, NULL);
+    image = _cairo_surface_map_to_image (&src->base, NULL);
     status = _cairo_surface_offset_paint (image, extents->x, extents->y,
 					  CAIRO_OPERATOR_SOURCE, pattern,
 					  NULL);
-    cairo_surface_unmap_image (&src->base, image);
+    status = _cairo_surface_unmap_image (&src->base, image);
     if (unlikely (status)) {
 	cairo_surface_destroy (&src->base);
 	return _cairo_surface_create_in_error (status);
@@ -946,12 +946,12 @@ surface_source (cairo_xlib_surface_t *dst,
     cairo_matrix_init_translate (&local_pattern.base.matrix,
 				 upload.x, upload.y);
 
-    image = cairo_surface_map_to_image (&src->base, NULL);
+    image = _cairo_surface_map_to_image (&src->base, NULL);
     status = _cairo_surface_paint (image,
 				   CAIRO_OPERATOR_SOURCE,
 				   &local_pattern.base,
 				   NULL);
-    cairo_surface_unmap_image (&src->base, image);
+    status = _cairo_surface_unmap_image (&src->base, image);
     _cairo_pattern_fini (&local_pattern.base);
 
     if (unlikely (status)) {
diff --git a/src/cairoint.h b/src/cairoint.h
index 15a26cd..33b7482 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1897,7 +1897,6 @@ slim_hidden_proto (cairo_surface_get_font_options);
 slim_hidden_proto (cairo_surface_get_mime_data);
 slim_hidden_proto (cairo_surface_get_type);
 slim_hidden_proto (cairo_surface_has_show_text_glyphs);
-slim_hidden_proto (cairo_surface_map_to_image);
 slim_hidden_proto (cairo_surface_mark_dirty);
 slim_hidden_proto (cairo_surface_mark_dirty_rectangle);
 slim_hidden_proto_no_warn (cairo_surface_reference);
@@ -1906,7 +1905,6 @@ slim_hidden_proto (cairo_surface_set_fallback_resolution);
 slim_hidden_proto (cairo_surface_set_mime_data);
 slim_hidden_proto (cairo_surface_show_page);
 slim_hidden_proto (cairo_surface_status);
-slim_hidden_proto (cairo_surface_unmap_image);
 slim_hidden_proto (cairo_text_cluster_allocate);
 slim_hidden_proto (cairo_text_cluster_free);
 slim_hidden_proto (cairo_toy_font_face_create);
-- 
1.7.5.4



More information about the cairo mailing list