From 8fda4ab1cc7f60196b232d194c33e592ecdec9b5 Mon Sep 17 00:00:00 2001 From: Andrea Canciani Date: Thu, 26 Aug 2010 11:15:46 +0200 Subject: [PATCH] image: add _cairo_image_reset_static_data Image has static caches which needs to be reset to make cairo_debug_reset_static_data behave as expected. Silences a bunch of leak reports by check-valgrind. Reviewed-by: Chris Wilson --- src/cairo-debug.c | 2 ++ src/cairo-image-surface.c | 42 +++++++++++++++++++++++++++++++-------- src/cairoint.h | 3 +++ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/cairo-debug.c b/src/cairo-debug.c index 712ce9394..c95675318 100644 --- a/src/cairo-debug.c +++ b/src/cairo-debug.c @@ -77,6 +77,8 @@ cairo_debug_reset_static_data (void) _cairo_clip_reset_static_data (); + _cairo_image_reset_static_data (); + #if CAIRO_HAS_DRM_SURFACE _cairo_drm_device_reset_static_data (); #endif diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c index f88ccb88d..4d65ee6d2 100644 --- a/src/cairo-image-surface.c +++ b/src/cairo-image-surface.c @@ -876,10 +876,13 @@ _nearest_sample (cairo_filter_t filter, double *tx, double *ty) } #if HAS_ATOMIC_OPS +static pixman_image_t *__pixman_transparent_image; +static pixman_image_t *__pixman_black_image; +static pixman_image_t *__pixman_white_image; + static pixman_image_t * _pixman_transparent_image (void) { - static pixman_image_t *__pixman_transparent_image; pixman_image_t *image; image = __pixman_transparent_image; @@ -910,7 +913,6 @@ _pixman_transparent_image (void) static pixman_image_t * _pixman_black_image (void) { - static pixman_image_t *__pixman_black_image; pixman_image_t *image; image = __pixman_black_image; @@ -941,7 +943,6 @@ _pixman_black_image (void) static pixman_image_t * _pixman_white_image (void) { - static pixman_image_t *__pixman_white_image; pixman_image_t *image; image = __pixman_white_image; @@ -995,14 +996,39 @@ hars_petruska_f54_1_random (void) #undef rol } +static struct { + cairo_color_t color; + pixman_image_t *image; +} cache[16]; +static int n_cached; + +void +_cairo_image_reset_static_data () +{ + while (n_cached) + pixman_image_unref (cache[--n_cached].image); + +#if HAS_ATOMIC_OPS + if (__pixman_transparent_image) { + pixman_image_unref (__pixman_transparent_image); + __pixman_transparent_image = NULL; + } + + if (__pixman_black_image) { + pixman_image_unref (__pixman_black_image); + __pixman_black_image = NULL; + } + + if (__pixman_white_image) { + pixman_image_unref (__pixman_white_image); + __pixman_white_image = NULL; + } +#endif +} + static pixman_image_t * _pixman_image_for_solid (const cairo_solid_pattern_t *pattern) { - static struct { - cairo_color_t color; - pixman_image_t *image; - } cache[16]; - static int n_cached; pixman_color_t color; pixman_image_t *image; int i; diff --git a/src/cairoint.h b/src/cairoint.h index fe2f7fcc4..500b2d930 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -1906,6 +1906,9 @@ cairo_private cairo_bool_t _pixman_format_to_masks (pixman_format_code_t pixman_format, cairo_format_masks_t *masks); +cairo_private void +_cairo_image_reset_static_data (void); + cairo_private cairo_surface_t * _cairo_image_surface_create_with_pixman_format (unsigned char *data, pixman_format_code_t pixman_format,