Title: [180561] trunk/Source/WebCore
Revision
180561
Author
akl...@apple.com
Date
2015-02-24 08:46:18 -0800 (Tue, 24 Feb 2015)

Log Message

[Cocoa] Break internal reference cycle in WebCore::Font.
<https://webkit.org/b/141941>
<rdar://problem/19650570>

Reviewed by Antti Koivisto.

The Cocoa implementation of Font::platformCreateScaledFont() tried to be smart and use the FontCache.
This didn't work out well when scaling a 0pt Font, since scaling 0pt by any factor will return 0pt.

We'd have a 0pt font, scale it by 0.7 to get a small-caps variant, and then cache that small-caps
variant (really "this") in Font::m_derivedData->smallCaps.

Fix this by having Cocoa Font scaling do exactly what other platforms do: create a new Font every time.
This stops us from accumulating tons of abandoned Font objects over time.

* platform/graphics/Font.cpp:
(WebCore::Font::verticalRightOrientationFont):
(WebCore::Font::uprightOrientationFont):
(WebCore::Font::smallCapsFont):
(WebCore::Font::emphasisMarkFont):
(WebCore::Font::brokenIdeographFont):
(WebCore::Font::nonSyntheticItalicFont): Add assertions to guard against reference cycles inside a Font.

* platform/graphics/cocoa/FontCocoa.mm:
(WebCore::Font::platformCreateScaledFont): Always create a new Font when scaling an existing Font to a different size.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (180560 => 180561)


--- trunk/Source/WebCore/ChangeLog	2015-02-24 15:32:32 UTC (rev 180560)
+++ trunk/Source/WebCore/ChangeLog	2015-02-24 16:46:18 UTC (rev 180561)
@@ -1,3 +1,31 @@
+2015-02-24  Andreas Kling  <akl...@apple.com>
+
+        [Cocoa] Break internal reference cycle in WebCore::Font.
+        <https://webkit.org/b/141941>
+        <rdar://problem/19650570>
+
+        Reviewed by Antti Koivisto.
+
+        The Cocoa implementation of Font::platformCreateScaledFont() tried to be smart and use the FontCache.
+        This didn't work out well when scaling a 0pt Font, since scaling 0pt by any factor will return 0pt.
+
+        We'd have a 0pt font, scale it by 0.7 to get a small-caps variant, and then cache that small-caps
+        variant (really "this") in Font::m_derivedData->smallCaps.
+
+        Fix this by having Cocoa Font scaling do exactly what other platforms do: create a new Font every time.
+        This stops us from accumulating tons of abandoned Font objects over time.
+
+        * platform/graphics/Font.cpp:
+        (WebCore::Font::verticalRightOrientationFont):
+        (WebCore::Font::uprightOrientationFont):
+        (WebCore::Font::smallCapsFont):
+        (WebCore::Font::emphasisMarkFont):
+        (WebCore::Font::brokenIdeographFont):
+        (WebCore::Font::nonSyntheticItalicFont): Add assertions to guard against reference cycles inside a Font.
+
+        * platform/graphics/cocoa/FontCocoa.mm:
+        (WebCore::Font::platformCreateScaledFont): Always create a new Font when scaling an existing Font to a different size.
+
 2015-02-24  Xabier Rodriguez Calvar <calva...@igalia.com> and Youenn Fablet  <youenn.fab...@crf.canon.fr>
 
         [Streams API] Reading ReadableStream ready and closed attributes should not always create a new promise

Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (180560 => 180561)


--- trunk/Source/WebCore/platform/graphics/Font.cpp	2015-02-24 15:32:32 UTC (rev 180560)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp	2015-02-24 16:46:18 UTC (rev 180561)
@@ -287,6 +287,7 @@
         verticalRightPlatformData.setOrientation(Horizontal);
         m_derivedFontData->verticalRightOrientation = create(verticalRightPlatformData, isCustomFont(), false, true);
     }
+    ASSERT(m_derivedFontData->verticalRightOrientation != this);
     return m_derivedFontData->verticalRightOrientation;
 }
 
@@ -296,6 +297,7 @@
         m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
     if (!m_derivedFontData->uprightOrientation)
         m_derivedFontData->uprightOrientation = create(m_platformData, isCustomFont(), false, true);
+    ASSERT(m_derivedFontData->uprightOrientation != this);
     return m_derivedFontData->uprightOrientation;
 }
 
@@ -305,7 +307,7 @@
         m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
     if (!m_derivedFontData->smallCaps)
         m_derivedFontData->smallCaps = createScaledFont(fontDescription, smallCapsFontSizeMultiplier);
-
+    ASSERT(m_derivedFontData->smallCaps != this);
     return m_derivedFontData->smallCaps;
 }
 
@@ -315,7 +317,7 @@
         m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
     if (!m_derivedFontData->emphasisMark)
         m_derivedFontData->emphasisMark = createScaledFont(fontDescription, emphasisMarkFontSizeMultiplier);
-
+    ASSERT(m_derivedFontData->emphasisMark != this);
     return m_derivedFontData->emphasisMark;
 }
 
@@ -327,6 +329,7 @@
         m_derivedFontData->brokenIdeograph = create(m_platformData, isCustomFont(), false);
         m_derivedFontData->brokenIdeograph->m_isBrokenIdeographFallback = true;
     }
+    ASSERT(m_derivedFontData->brokenIdeograph != this);
     return m_derivedFontData->brokenIdeograph;
 }
 
@@ -341,6 +344,7 @@
 #endif
         m_derivedFontData->nonSyntheticItalic = create(nonSyntheticItalicFontPlatformData, isCustomFont());
     }
+    ASSERT(m_derivedFontData->nonSyntheticItalic != this);
     return m_derivedFontData->nonSyntheticItalic;
 }
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm (180560 => 180561)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm	2015-02-24 15:32:32 UTC (rev 180560)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm	2015-02-24 16:46:18 UTC (rev 180561)
@@ -339,7 +339,7 @@
         scaledFontData.m_syntheticBold = (fontTraits & NSBoldFontMask) && !(scaledFontTraits & NSBoldFontMask);
         scaledFontData.m_syntheticOblique = (fontTraits & NSItalicFontMask) && !(scaledFontTraits & NSItalicFontMask);
 
-        return FontCache::singleton().fontForPlatformData(scaledFontData);
+        return Font::create(scaledFontData);
     }
     END_BLOCK_OBJC_EXCEPTIONS;
 
@@ -360,7 +360,7 @@
         scaledFontData.m_syntheticBold = (fontTraits & kCTFontBoldTrait) && !(scaledFontTraits & kCTFontTraitBold);
         scaledFontData.m_syntheticOblique = (fontTraits & kCTFontItalicTrait) && !(scaledFontTraits & kCTFontTraitItalic);
 
-        return FontCache::singleton().fontForPlatformData(scaledFontData);
+        return Font::create(scaledFontData);
     }
 
     return nullptr;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to