From 455b4de1fc6be05f985b43c2f8f83eeed2b2a191 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 27 Apr 2012 11:41:41 +0100 Subject: [PATCH] image: Allow a snapshot to steal the original memory upon finish Signed-off-by: Chris Wilson --- src/cairo-image-surface.c | 18 ++++++++++++++++++ src/cairo-surface-private.h | 1 + src/cairo-surface.c | 3 +++ 3 files changed, 22 insertions(+) diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c index 8bbea0020..56914b06b 100644 --- a/src/cairo-image-surface.c +++ b/src/cairo-image-surface.c @@ -753,6 +753,24 @@ _cairo_image_surface_snapshot (void *abstract_surface) cairo_image_surface_t *image = abstract_surface; cairo_image_surface_t *clone; + /* If we own the image, we can simply steal the memory for the snapshot */ + if (image->owns_data && image->base._finishing) { + clone = (cairo_image_surface_t *) + _cairo_image_surface_create_for_pixman_image (image->pixman_image, + image->pixman_format); + if (unlikely (clone->base.status)) + return &clone->base; + + image->pixman_image = NULL; + image->owns_data = FALSE; + + clone->transparency = image->transparency; + clone->color = image->color; + + clone->owns_data = FALSE; + return &clone->base; + } + clone = (cairo_image_surface_t *) _cairo_image_surface_create_with_pixman_format (NULL, image->pixman_format, diff --git a/src/cairo-surface-private.h b/src/cairo-surface-private.h index c4d5de2dc..d23fc0530 100644 --- a/src/cairo-surface-private.h +++ b/src/cairo-surface-private.h @@ -65,6 +65,7 @@ struct _cairo_surface { unsigned int serial; cairo_damage_t *damage; + unsigned _finishing : 1; unsigned finished : 1; unsigned is_clear : 1; unsigned has_font_options : 1; diff --git a/src/cairo-surface.c b/src/cairo-surface.c index 457b3f00a..58db7be75 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -108,6 +108,7 @@ const cairo_surface_t name = { \ 0, /* unique id */ \ 0, /* serial */ \ NULL, /* damage */ \ + FALSE, /* _finishing */ \ FALSE, /* finished */ \ TRUE, /* is_clear */ \ FALSE, /* has_font_options */ \ @@ -905,6 +906,8 @@ _cairo_surface_finish (cairo_surface_t *surface) cairo_surface_flush (surface); /* update the snapshots *before* we declare the surface as finished */ + surface->_finishing = TRUE; + _cairo_surface_detach_snapshots (surface); if (surface->snapshot_of != NULL) _cairo_surface_detach_snapshot (surface);