From 94c3b85f2495a0046f98c9216a078ae6653d2d1c Mon Sep 17 00:00:00 2001 From: U-NIRVANA-XP\ranma42 Date: Thu, 9 Jun 2011 08:45:05 +0200 Subject: [PATCH] win32-font: Implement font face destruction Based on the implementation of toy font face destruction. Fixes . See https://bugs.freedesktop.org/show_bug.cgi?id=38049 --- src/cairo-win32-font.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c index d0c29bb..818f8a7 100644 --- a/src/cairo-win32-font.c +++ b/src/cairo-win32-font.c @@ -149,6 +149,9 @@ static cairo_status_t _cairo_win32_scaled_font_init_glyph_path (cairo_win32_scaled_font_t *scaled_font, cairo_scaled_glyph_t *scaled_glyph); +static void +_cairo_win32_font_face_destroy (void *abstract_face); + #define NEARLY_ZERO(d) (fabs(d) < (1. / 65536.)) static HDC @@ -1920,11 +1923,6 @@ struct _cairo_win32_font_face { /* implement the platform-specific interface */ -static void -_cairo_win32_font_face_destroy (void *abstract_face) -{ -} - static cairo_bool_t _is_scale (const cairo_matrix_t *matrix, double scale) { @@ -1983,6 +1981,12 @@ static int _cairo_win32_font_face_keys_equal (const void *key_a, const void *key_b); +static cairo_bool_t +_enumerate_all (const void *unused) +{ + return TRUE; +} + static void _cairo_win32_font_face_hash_table_destroy (void) { @@ -1997,7 +2001,7 @@ _cairo_win32_font_face_hash_table_destroy (void) * relevant. */ while (1) { font_face= _cairo_hash_table_random_entry (cairo_win32_font_face_hash_table, - NULL); + _enumerate_all); if (font_face == NULL) break; _cairo_hash_table_remove (cairo_win32_font_face_hash_table, @@ -2359,3 +2363,31 @@ _cairo_win32_font_reset_static_data (void) { _cairo_win32_font_face_hash_table_destroy (); } + +static void +_cairo_win32_font_face_destroy (void *abstract_face) +{ + cairo_win32_font_face_t *font_face = abstract_face; + cairo_hash_table_t *hash_table; + + if (font_face == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->base.ref_count)) + return; + + hash_table = _cairo_win32_font_face_hash_table_lock (); + /* All created objects must have been mapped in the hash table. */ + assert (hash_table != NULL); + + if (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&font_face->base.ref_count)) { + /* somebody recreated the font whilst we waited for the lock */ + _cairo_win32_font_face_hash_table_unlock (); + return; + } + + /* CHECK ME: why should I care about the hash? Is 0 special in + * some way? */ + if (font_face->base.hash_entry.hash != 0) + _cairo_hash_table_remove (hash_table, &font_face->base.hash_entry); + + _cairo_win32_font_face_hash_table_unlock (); +} -- 1.7.5.1