[cairo] [PATCH 2/5] surface: Make map_to_image return cairo_image_surface_t*

Andrea Canciani ranma42 at gmail.com
Thu May 17 13:28:07 PDT 2012


This makes it easier to check that the funciton is returning the
correct type of surfaces.
---
 src/cairo-directfb-surface.c            |   13 +++++++------
 src/cairo-gl-surface.c                  |   16 ++++++++--------
 src/cairo-image-surface-inline.h        |    6 ++++++
 src/cairo-image-surface-private.h       |    2 +-
 src/cairo-image-surface.c               |    4 ++--
 src/cairo-os2-surface.c                 |    2 +-
 src/cairo-quartz-image-surface.c        |    2 +-
 src/cairo-quartz-surface.c              |    2 +-
 src/cairo-surface-backend-private.h     |    2 +-
 src/cairo-surface-observer.c            |    2 +-
 src/cairo-surface-subsurface.c          |    2 +-
 src/cairo-surface.c                     |    2 +-
 src/cairo-xcb-surface.c                 |   18 +++++++++++-------
 src/cairo-xlib-surface.c                |    4 ++--
 src/cairo-xlib-xcb-surface.c            |    2 +-
 src/skia/cairo-skia-surface.cpp         |    3 ++-
 src/win32/cairo-win32-display-surface.c |    8 ++++----
 17 files changed, 51 insertions(+), 39 deletions(-)

diff --git a/src/cairo-directfb-surface.c b/src/cairo-directfb-surface.c
index fd187bd..494ec07 100644
--- a/src/cairo-directfb-surface.c
+++ b/src/cairo-directfb-surface.c
@@ -40,7 +40,7 @@
 #include "cairo-compositor-private.h"
 #include "cairo-default-context-private.h"
 #include "cairo-error-private.h"
-#include "cairo-image-surface-private.h"
+#include "cairo-image-surface-inline.h"
 #include "cairo-pattern-private.h"
 #include "cairo-surface-backend-private.h"
 #include "cairo-surface-fallback-private.h"
@@ -171,7 +171,7 @@ _cairo_dfb_surface_finish (void *abstract_surface)
     return _cairo_image_surface_finish (abstract_surface);
 }
 
-static cairo_surface_t *
+static cairo_image_surface_t *
 _cairo_dfb_surface_map_to_image (void *abstract_surface,
 				 const cairo_rectangle_int_t *extents)
 {
@@ -184,7 +184,7 @@ _cairo_dfb_surface_map_to_image (void *abstract_surface,
 	int pitch;
 
 	if (buffer->Lock (buffer, DSLF_READ | DSLF_WRITE, &data, &pitch))
-	    return _cairo_surface_create_in_error(_cairo_error (CAIRO_STATUS_NO_MEMORY));
+	    return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
 	image = pixman_image_create_bits (surface->image.pixman_format,
 					  surface->image.width,
@@ -192,19 +192,20 @@ _cairo_dfb_surface_map_to_image (void *abstract_surface,
 					  data, pitch);
 	if (image == NULL) {
 	    buffer->Unlock (buffer);
-	    return _cairo_surface_create_in_error(_cairo_error (CAIRO_STATUS_NO_MEMORY));
+	    return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 	}
 	_cairo_image_surface_init (&surface->image, image, surface->image.pixman_format);
     }
 
-    return _cairo_image_surface_map_to_image (&surface->image, extents);
+    return _cairo_surface_map_to_image (&surface->image.base, extents);
 }
 
 static cairo_int_status_t
 _cairo_dfb_surface_unmap_image (void *abstract_surface,
 				cairo_image_surface_t *image)
 {
-    return CAIRO_INT_STATUS_SUCCESS;
+    cairo_dfb_surface_t *surface = abstract_surface;
+    return _cairo_surface_unmap_image (&surface->image.base, image);
 }
 
 static cairo_status_t
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index f480260..56a9025 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -46,7 +46,7 @@
 #include "cairo-compositor-private.h"
 #include "cairo-default-context-private.h"
 #include "cairo-error-private.h"
-#include "cairo-image-surface-private.h"
+#include "cairo-image-surface-inline.h"
 #include "cairo-surface-backend-private.h"
 
 static const cairo_surface_backend_t _cairo_gl_surface_backend;
@@ -973,7 +973,7 @@ _cairo_gl_surface_finish (void *abstract_surface)
     return _cairo_gl_context_release (ctx, status);
 }
 
-static cairo_surface_t *
+static cairo_image_surface_t *
 _cairo_gl_surface_map_to_image (void      *abstract_surface,
 				const cairo_rectangle_int_t   *extents)
 {
@@ -1038,15 +1038,15 @@ _cairo_gl_surface_map_to_image (void      *abstract_surface,
 							extents->height,
 							-1);
     if (unlikely (image->base.status))
-	return &image->base;
+	return image;
 
     if (surface->base.serial == 0)
-	return &image->base;
+	return image;
 
     status = _cairo_gl_context_acquire (surface->base.device, &ctx);
     if (unlikely (status)) {
 	cairo_surface_destroy (&image->base);
-	return _cairo_surface_create_in_error (status);
+	return _cairo_image_surface_create_in_error (status);
     }
 
     cairo_surface_set_device_offset (&image->base, -extents->x, -extents->y);
@@ -1080,7 +1080,7 @@ _cairo_gl_surface_map_to_image (void      *abstract_surface,
     status = _cairo_gl_context_release (ctx, status);
     if (unlikely (status)) {
 	cairo_surface_destroy (&image->base);
-	return _cairo_surface_create_in_error (status);
+	return _cairo_image_surface_create_in_error (status);
     }
 
     /* We must invert the image manualy if we lack GL_MESA_pack_invert */
@@ -1093,7 +1093,7 @@ _cairo_gl_surface_map_to_image (void      *abstract_surface,
 	    row = malloc (image->stride);
 	    if (unlikely (row == NULL)) {
 		cairo_surface_destroy (&image->base);
-		return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
+		return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 	    }
 	}
 
@@ -1109,7 +1109,7 @@ _cairo_gl_surface_map_to_image (void      *abstract_surface,
 	    free(row);
     }
 
-    return &image->base;
+    return image;
 }
 
 static cairo_surface_t *
diff --git a/src/cairo-image-surface-inline.h b/src/cairo-image-surface-inline.h
index 95cbb99..d529bde 100644
--- a/src/cairo-image-surface-inline.h
+++ b/src/cairo-image-surface-inline.h
@@ -42,6 +42,12 @@
 
 CAIRO_BEGIN_DECLS
 
+static inline cairo_image_surface_t *
+_cairo_image_surface_create_in_error (cairo_status_t status)
+{
+    return (cairo_image_surface_t *) _cairo_surface_create_in_error (status);
+}
+
 static inline void
 _cairo_image_surface_set_parent (cairo_image_surface_t *image,
 				 cairo_surface_t *parent)
diff --git a/src/cairo-image-surface-private.h b/src/cairo-image-surface-private.h
index 6f5f05b..8f7364c 100644
--- a/src/cairo-image-surface-private.h
+++ b/src/cairo-image-surface-private.h
@@ -151,7 +151,7 @@ _cairo_image_surface_init (cairo_image_surface_t *surface,
 			   pixman_image_t	*pixman_image,
 			   pixman_format_code_t	 pixman_format);
 
-cairo_private cairo_surface_t *
+cairo_private cairo_image_surface_t *
 _cairo_image_surface_map_to_image (void *abstract_other,
 				   const cairo_rectangle_int_t *extents);
 
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 00369b6..33f6160 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -794,7 +794,7 @@ _cairo_image_surface_snapshot (void *abstract_surface)
     return &clone->base;
 }
 
-cairo_surface_t *
+cairo_image_surface_t *
 _cairo_image_surface_map_to_image (void *abstract_other,
 				   const cairo_rectangle_int_t *extents)
 {
@@ -814,7 +814,7 @@ _cairo_image_surface_map_to_image (void *abstract_other,
 							other->stride);
 
     cairo_surface_set_device_offset (surface, -extents->x, -extents->y);
-    return surface;
+    return (cairo_image_surface_t *) surface;
 }
 
 cairo_int_status_t
diff --git a/src/cairo-os2-surface.c b/src/cairo-os2-surface.c
index 19646fb..edef42e 100644
--- a/src/cairo-os2-surface.c
+++ b/src/cairo-os2-surface.c
@@ -585,7 +585,7 @@ _cairo_os2_surface_release_source_image (void                  *abstract_surface
     DosReleaseMutexSem (surface->hmtx_use_private_fields);
 }
 
-static cairo_surface_t *
+static cairo_image_surface_t *
 _cairo_os2_surface_map_to_image (void *abstract_surface,
 				 const cairo_rectangle_int_t *extents)
 {
diff --git a/src/cairo-quartz-image-surface.c b/src/cairo-quartz-image-surface.c
index 763ce96..da10a98 100644
--- a/src/cairo-quartz-image-surface.c
+++ b/src/cairo-quartz-image-surface.c
@@ -107,7 +107,7 @@ _cairo_quartz_image_surface_acquire_source_image (void *asurface,
     return CAIRO_STATUS_SUCCESS;
 }
 
-static cairo_surface_t *
+static cairo_image_surface_t *
 _cairo_quartz_image_surface_map_to_image (void *asurface,
 					  const cairo_rectangle_int_t *extents)
 {
diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index d216261..3010988 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -1553,7 +1553,7 @@ _cairo_quartz_surface_release_source_image (void *abstract_surface,
 }
 
 
-static cairo_surface_t *
+static cairo_image_surface_t *
 _cairo_quartz_surface_map_to_image (void *abstract_surface,
 				    const cairo_rectangle_int_t *extents)
 {
diff --git a/src/cairo-surface-backend-private.h b/src/cairo-surface-backend-private.h
index fbaa912..c275ce6 100644
--- a/src/cairo-surface-backend-private.h
+++ b/src/cairo-surface-backend-private.h
@@ -63,7 +63,7 @@ struct _cairo_surface_backend {
 				 int			 width,
 				 int			 height);
 
-    cairo_surface_t *
+    cairo_image_surface_t *
     (*map_to_image)		(void			*surface,
 				 const cairo_rectangle_int_t  *extents);
     cairo_int_status_t
diff --git a/src/cairo-surface-observer.c b/src/cairo-surface-observer.c
index 9247bc4..1922398 100644
--- a/src/cairo-surface-observer.c
+++ b/src/cairo-surface-observer.c
@@ -474,7 +474,7 @@ _cairo_surface_observer_create_similar_image (void *other,
     return NULL;
 }
 
-static cairo_surface_t *
+static cairo_image_surface_t *
 _cairo_surface_observer_map_to_image (void *abstract_surface,
 				      const cairo_rectangle_int_t *extents)
 {
diff --git a/src/cairo-surface-subsurface.c b/src/cairo-surface-subsurface.c
index dfea05c..020b961 100644
--- a/src/cairo-surface-subsurface.c
+++ b/src/cairo-surface-subsurface.c
@@ -84,7 +84,7 @@ _cairo_surface_subsurface_create_similar_image (void *other,
 							   width, height);
 }
 
-static cairo_surface_t *
+static cairo_image_surface_t *
 _cairo_surface_subsurface_map_to_image (void *abstract_surface,
 					const cairo_rectangle_int_t *extents)
 {
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 99cbfbe..e28e115 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -638,7 +638,7 @@ _cairo_surface_map_to_image (cairo_surface_t  *surface,
 
     /* TODO: require map_to_image != NULL */
     if (surface->backend->map_to_image)
-	image = (cairo_image_surface_t *) surface->backend->map_to_image (surface, extents);
+	image = surface->backend->map_to_image (surface, extents);
 
     if (image == NULL)
 	image = _cairo_image_surface_clone_subimage (surface, extents);
diff --git a/src/cairo-xcb-surface.c b/src/cairo-xcb-surface.c
index c6a1d29..489e17e 100644
--- a/src/cairo-xcb-surface.c
+++ b/src/cairo-xcb-surface.c
@@ -45,8 +45,8 @@
 
 #include "cairo-composite-rectangles-private.h"
 #include "cairo-default-context-private.h"
+#include "cairo-image-surface-inline.h"
 #include "cairo-list-inline.h"
-#include "cairo-image-surface-private.h"
 #include "cairo-surface-backend-private.h"
 
 #if CAIRO_HAS_XLIB_XCB_FUNCTIONS
@@ -755,12 +755,13 @@ _cairo_xcb_surface_flush (void *abstract_surface)
     return status;
 }
 
-static cairo_surface_t *
+static cairo_image_surface_t *
 _cairo_xcb_surface_map_to_image (void *abstract_surface,
 				 const cairo_rectangle_int_t *extents)
 {
     cairo_xcb_surface_t *surface = abstract_surface;
     cairo_surface_t *image;
+    cairo_status_t status;
 
     if (surface->fallback)
 	return surface->fallback->base.backend->map_to_image (&surface->fallback->base, extents);
@@ -768,8 +769,11 @@ _cairo_xcb_surface_map_to_image (void *abstract_surface,
     image = _get_image (surface, TRUE,
 			extents->x, extents->y,
 			extents->width, extents->height);
-    if (unlikely (image->status))
-	return image;
+    status = cairo_surface_status (image);
+    if (unlikely (status)) {
+	cairo_surface_destroy(image);
+	return _cairo_image_surface_create_in_error (status);
+    }
 
     /* Do we have a deferred clear and this image surface does NOT cover the
      * whole xcb surface? Have to apply the clear in that case, else
@@ -778,16 +782,16 @@ _cairo_xcb_surface_map_to_image (void *abstract_surface,
     if (surface->deferred_clear &&
 	! (extents->width == surface->width &&
 	   extents->height == surface->height)) {
-	cairo_status_t status = _cairo_xcb_surface_clear (surface);
+	status = _cairo_xcb_surface_clear (surface);
 	if (unlikely (status)) {
 	    cairo_surface_destroy(image);
-	    return _cairo_surface_create_in_error (status);
+	    return _cairo_image_surface_create_in_error (status);
 	}
     }
     surface->deferred_clear = FALSE;
 
     cairo_surface_set_device_offset (image, -extents->x, -extents->y);
-    return image;
+    return (cairo_image_surface_t *) image;
 }
 
 static cairo_int_status_t
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index ae2153b..9dadca6 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -1278,7 +1278,7 @@ _cairo_xlib_surface_release_source_image (void                   *abstract_surfa
     cairo_surface_destroy (&image->base);
 }
 
-static cairo_surface_t *
+static cairo_image_surface_t *
 _cairo_xlib_surface_map_to_image (void                    *abstract_surface,
 				  const cairo_rectangle_int_t   *extents)
 {
@@ -1287,7 +1287,7 @@ _cairo_xlib_surface_map_to_image (void                    *abstract_surface,
     image = _get_image_surface (abstract_surface, extents);
     cairo_surface_set_device_offset (image, -extents->x, -extents->y);
 
-    return image;
+    return (cairo_image_surface_t *) image;
 }
 
 static cairo_int_status_t
diff --git a/src/cairo-xlib-xcb-surface.c b/src/cairo-xlib-xcb-surface.c
index caa9bd3..1df5de8 100644
--- a/src/cairo-xlib-xcb-surface.c
+++ b/src/cairo-xlib-xcb-surface.c
@@ -116,7 +116,7 @@ _cairo_xlib_xcb_surface_create_similar_image (void			*abstract_other,
     return cairo_surface_create_similar_image (&surface->xcb->base, format, width, height);
 }
 
-static cairo_surface_t *
+static cairo_image_surface_t *
 _cairo_xlib_xcb_surface_map_to_image (void *abstract_surface,
 				      const cairo_rectangle_int_t *extents)
 {
diff --git a/src/skia/cairo-skia-surface.cpp b/src/skia/cairo-skia-surface.cpp
index 71bebb0..cc76cfb 100644
--- a/src/skia/cairo-skia-surface.cpp
+++ b/src/skia/cairo-skia-surface.cpp
@@ -90,7 +90,7 @@ _cairo_skia_surface_finish (void *asurface)
     return CAIRO_STATUS_SUCCESS;
 }
 
-static cairo_surface_t *
+static cairo_image_surface_t *
 _cairo_skia_surface_map_to_image (void *asurface,
 				  const cairo_rectangle_int_t *extents)
 {
@@ -98,6 +98,7 @@ _cairo_skia_surface_map_to_image (void *asurface,
 
     surface->bitmap->lockPixels ();
 
+    /* XXX: Broken! */
     if (extents->width < surface->image.width ||
 	extents->height < surface->image.height)
     {
diff --git a/src/win32/cairo-win32-display-surface.c b/src/win32/cairo-win32-display-surface.c
index 7efa7d8..0d4c5f9 100644
--- a/src/win32/cairo-win32-display-surface.c
+++ b/src/win32/cairo-win32-display-surface.c
@@ -427,7 +427,7 @@ _cairo_win32_display_surface_finish (void *abstract_surface)
     return CAIRO_STATUS_SUCCESS;
 }
 
-static cairo_surface_t *
+static cairo_image_surface_t *
 _cairo_win32_display_surface_map_to_image (void                    *abstract_surface,
 					   const cairo_rectangle_int_t   *extents)
 {
@@ -464,13 +464,13 @@ _cairo_win32_display_surface_map_to_image (void                    *abstract_sur
     surface = to_win32_display_surface (surface->fallback);
 done:
     GdiFlush();
-    return _cairo_image_surface_map_to_image (surface->image, extents);
+    return _cairo_surface_map_to_image (&surface->image->base, extents);
 
 err:
     cairo_surface_destroy (surface->fallback);
     surface->fallback = NULL;
 
-    return _cairo_surface_create_in_error (status);
+    return _cairo_image_surface_create_in_error (status);
 }
 
 static cairo_int_status_t
@@ -499,7 +499,7 @@ _cairo_win32_display_surface_unmap_image (void                    *abstract_surf
 	    _cairo_damage_add_rectangle (surface->fallback->damage, &r);
     }
 
-    return CAIRO_INT_STATUS_SUCCESS;
+    return _cairo_surface_unmap_image (&surface->image->base, image);
 }
 
 static cairo_status_t
-- 
1.7.7.5 (Apple Git-26)



More information about the cairo mailing list