From d61c7df1c0f9c69b0022c58efd001855551af7dd Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Wed, 9 Jul 2008 13:20:53 -0700 Subject: [PATCH] [quartz] Take snapshot instead of using CGImageCreateCopy CGImageCreateCopy doesn't copy the data provider, so it's possible to free the data underneath an image without snapshotting it first. --- src/cairo-quartz-surface.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c index 84d870261..5bdabb7cf 100644 --- a/src/cairo-quartz-surface.c +++ b/src/cairo-quartz-surface.c @@ -695,6 +695,13 @@ CreateRepeatingGradientFunction (cairo_quartz_surface_t *surface, /* Obtain a CGImageRef from a #cairo_surface_t * */ +static void +DataProviderReleaseCallback (void *info, const void *data, size_t size) +{ + cairo_surface_t *surface = (cairo_surface_t *) info; + cairo_surface_destroy (surface); +} + static cairo_status_t _cairo_surface_to_cgimage (cairo_surface_t *target, cairo_surface_t *source, @@ -737,17 +744,22 @@ _cairo_surface_to_cgimage (cairo_surface_t *target, if (isurf->width == 0 || isurf->height == 0) { *image_out = NULL; } else { - image = _cairo_quartz_create_cgimage (isurf->format, - isurf->width, - isurf->height, - isurf->stride, - isurf->data, - TRUE, - NULL, NULL, NULL); + cairo_image_surface_t *isurf_snap = NULL; + isurf_snap = _cairo_surface_snapshot (isurf); + if (isurf_snap == NULL) + return CAIRO_STATUS_NO_MEMORY; - /* Create a copy to ensure that the CGImageRef doesn't depend on the image surface's backing store */ - *image_out = CGImageCreateCopy (image); - CGImageRelease (image); + image = _cairo_quartz_create_cgimage (isurf_snap->format, + isurf_snap->width, + isurf_snap->height, + isurf_snap->stride, + isurf_snap->data, + TRUE, + NULL, + DataProviderReleaseCallback, + isurf_snap); + + *image_out = image; } if ((cairo_surface_t*) isurf != source)