bug 717178. Part 2.5: Make cairo_win32_font_face_create_for_logfontw_hfont take ownership of the HFONT. r=jrmuizel
authorRobert O'Callahan <robert@ocallahan.org>
Tue, 01 Jan 2013 17:53:32 +1300
changeset 126391 b1453ec5b550523e4bdfda6061d44168b13b466d
parent 126390 2cd447a60faa3077f391678f43b51ce3a9833d1c
child 126392 4bab6b6a32f3e69efaa428ec572366af37b47ae7
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs717178
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 717178. Part 2.5: Make cairo_win32_font_face_create_for_logfontw_hfont take ownership of the HFONT. r=jrmuizel
gfx/cairo/README
gfx/cairo/cairo/src/cairo-win32-font.c
--- a/gfx/cairo/README
+++ b/gfx/cairo/README
@@ -195,16 +195,18 @@ d2d-gradient-ensure-stops.patch: bug 792
 setlcdfilter_in_tree.patch: bug 790139; force cairo to use FT_Library_SetLcdFilter from our in tree library rather than picking it up from the system
 
 dwrite-font-match-robustness.patch: bug 717178, don't crash when _name_tables_match is passed a nil scaled-font
 
 handle-multi-path-clip.patch: bug 813124, handle multiple clip paths correctly
 
 win32-gdi-font-cache.patch: Bug 717178, cache GDI font faces to reduce usage of GDI resources
 
+win32-hfont-ownership.patch: Bug 717178, make cairo_win32_font_face_create_for_logfontw_hfont take ownership of the passed HFONT
+
 ==== pixman patches ====
 
 pixman-android-cpu-detect.patch: Add CPU detection support for Android, where we can't reliably access /proc/self/auxv.
 
 pixman-rename-and-endian.patch: include cairo-platform.h for renaming of external symbols and endian macros
 
 NOTE: we previously supported ARM assembler on MSVC, this has been removed because of the maintenance burden
 
--- a/gfx/cairo/cairo/src/cairo-win32-font.c
+++ b/gfx/cairo/cairo/src/cairo-win32-font.c
@@ -2037,31 +2037,35 @@ static int
 
 static void
 _cairo_win32_font_face_destroy (void *abstract_face)
 {
     cairo_hash_table_t *hash_table;
     cairo_win32_font_face_t *font_face = abstract_face;
 
     hash_table = _cairo_win32_font_face_hash_table_lock ();
-    if (unlikely (hash_table == NULL)) {
-        return;
+    if (hash_table) {
+        _cairo_hash_table_remove (hash_table, &font_face->base.hash_entry);
+        _cairo_win32_font_face_hash_table_unlock ();
     }
-    _cairo_hash_table_remove (hash_table, &font_face->base.hash_entry);
-    _cairo_win32_font_face_hash_table_unlock ();
+
+    if (font_face->hfont) {
+        DeleteObject (font_face->hfont);
+    }
 }
 
 /**
  * cairo_win32_font_face_create_for_logfontw_hfont:
  * @logfont: A #LOGFONTW structure specifying the font to use.
  *   If @font is %NULL then the lfHeight, lfWidth, lfOrientation and lfEscapement
  *   fields of this structure are ignored. Otherwise lfWidth, lfOrientation and
  *   lfEscapement must be zero.
  * @font: An #HFONT that can be used when the font matrix is a scale by
- *   -lfHeight and the CTM is identity.
+ *   -lfHeight and the CTM is identity. The cairo_font_face_t takes ownership
+ *   of 'font' and is responsible for destroying it.
  *
  * Creates a new font for the Win32 font backend based on a
  * #LOGFONT. This font can then be used with
  * cairo_set_font_face() or cairo_scaled_font_create().
  * The #cairo_scaled_font_t
  * returned from cairo_scaled_font_create() is also for the Win32 backend
  * and can be used with functions such as cairo_win32_scaled_font_select_font().
  *
@@ -2073,25 +2077,37 @@ cairo_win32_font_face_create_for_logfont
 {
     cairo_win32_font_face_t *font_face, key;
     cairo_hash_table_t *hash_table;
     cairo_status_t status;
 
     hash_table = _cairo_win32_font_face_hash_table_lock ();
     if (unlikely (hash_table == NULL)) {
         _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
+        if (font) {
+            /* We are supposed to take ownership of this font. Since we don't
+             * need to use it, delete it now.
+             */
+            DeleteObject (font);
+        }
 	return (cairo_font_face_t *)&_cairo_font_face_nil;
     }
 
     _cairo_win32_font_face_init_key (&key, logfont, font);
 
     /* Return existing unscaled font if it exists in the hash table. */
     font_face = _cairo_hash_table_lookup (hash_table,
 					 &key.base.hash_entry);
     if (font_face != NULL) {
+        if (font) {
+            /* We are supposed to take ownership of this font. Since we don't
+             * need to use it, delete it now.
+             */
+            DeleteObject (font);
+        }
 	cairo_font_face_reference (&font_face->base);
 	goto DONE;
     }
 
     /* Otherwise create it and insert into hash table. */
     font_face = malloc (sizeof (cairo_win32_font_face_t));
     if (!font_face) {
         _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
@@ -2110,16 +2126,23 @@ cairo_win32_font_face_create_for_logfont
 DONE:
     _cairo_win32_font_face_hash_table_unlock ();
 
     return &font_face->base;
 
 FAIL:
     _cairo_win32_font_face_hash_table_unlock ();
 
+    if (font) {
+        /* We are supposed to take ownership of this font. Since we don't
+         * need to use it, delete it now.
+         */
+        DeleteObject (font);
+    }
+
     return (cairo_font_face_t *)&_cairo_font_face_nil;
 }
 
 /**
  * cairo_win32_font_face_create_for_logfontw:
  * @logfont: A #LOGFONTW structure specifying the font to use.
  *   The lfHeight, lfWidth, lfOrientation and lfEscapement
  *   fields of this structure are ignored.