Skip to content

Commit

Permalink
image: add _cairo_image_reset_static_data
Browse files Browse the repository at this point in the history
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 <chris@chris-wilson.co.uk>
  • Loading branch information
Andrea Canciani committed Sep 9, 2010
1 parent ca775cb commit 8fda4ab
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/cairo-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 34 additions & 8 deletions src/cairo-image-surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/cairoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8fda4ab

Please sign in to comment.