Changeset 180561 in webkit


Ignore:
Timestamp:
Feb 24, 2015, 8:46:18 AM (10 years ago)
Author:
akling@apple.com
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.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r180559 r180561  
     12015-02-24  Andreas Kling  <akling@apple.com>
     2
     3        [Cocoa] Break internal reference cycle in WebCore::Font.
     4        <https://webkit.org/b/141941>
     5        <rdar://problem/19650570>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        The Cocoa implementation of Font::platformCreateScaledFont() tried to be smart and use the FontCache.
     10        This didn't work out well when scaling a 0pt Font, since scaling 0pt by any factor will return 0pt.
     11
     12        We'd have a 0pt font, scale it by 0.7 to get a small-caps variant, and then cache that small-caps
     13        variant (really "this") in Font::m_derivedData->smallCaps.
     14
     15        Fix this by having Cocoa Font scaling do exactly what other platforms do: create a new Font every time.
     16        This stops us from accumulating tons of abandoned Font objects over time.
     17
     18        * platform/graphics/Font.cpp:
     19        (WebCore::Font::verticalRightOrientationFont):
     20        (WebCore::Font::uprightOrientationFont):
     21        (WebCore::Font::smallCapsFont):
     22        (WebCore::Font::emphasisMarkFont):
     23        (WebCore::Font::brokenIdeographFont):
     24        (WebCore::Font::nonSyntheticItalicFont): Add assertions to guard against reference cycles inside a Font.
     25
     26        * platform/graphics/cocoa/FontCocoa.mm:
     27        (WebCore::Font::platformCreateScaledFont): Always create a new Font when scaling an existing Font to a different size.
     28
    1292015-02-24  Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet  <youenn.fablet@crf.canon.fr>
    230
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r180281 r180561  
    288288        m_derivedFontData->verticalRightOrientation = create(verticalRightPlatformData, isCustomFont(), false, true);
    289289    }
     290    ASSERT(m_derivedFontData->verticalRightOrientation != this);
    290291    return m_derivedFontData->verticalRightOrientation;
    291292}
     
    297298    if (!m_derivedFontData->uprightOrientation)
    298299        m_derivedFontData->uprightOrientation = create(m_platformData, isCustomFont(), false, true);
     300    ASSERT(m_derivedFontData->uprightOrientation != this);
    299301    return m_derivedFontData->uprightOrientation;
    300302}
     
    306308    if (!m_derivedFontData->smallCaps)
    307309        m_derivedFontData->smallCaps = createScaledFont(fontDescription, smallCapsFontSizeMultiplier);
    308 
     310    ASSERT(m_derivedFontData->smallCaps != this);
    309311    return m_derivedFontData->smallCaps;
    310312}
     
    316318    if (!m_derivedFontData->emphasisMark)
    317319        m_derivedFontData->emphasisMark = createScaledFont(fontDescription, emphasisMarkFontSizeMultiplier);
    318 
     320    ASSERT(m_derivedFontData->emphasisMark != this);
    319321    return m_derivedFontData->emphasisMark;
    320322}
     
    328330        m_derivedFontData->brokenIdeograph->m_isBrokenIdeographFallback = true;
    329331    }
     332    ASSERT(m_derivedFontData->brokenIdeograph != this);
    330333    return m_derivedFontData->brokenIdeograph;
    331334}
     
    342345        m_derivedFontData->nonSyntheticItalic = create(nonSyntheticItalicFontPlatformData, isCustomFont());
    343346    }
     347    ASSERT(m_derivedFontData->nonSyntheticItalic != this);
    344348    return m_derivedFontData->nonSyntheticItalic;
    345349}
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm

    r180281 r180561  
    340340        scaledFontData.m_syntheticOblique = (fontTraits & NSItalicFontMask) && !(scaledFontTraits & NSItalicFontMask);
    341341
    342         return FontCache::singleton().fontForPlatformData(scaledFontData);
     342        return Font::create(scaledFontData);
    343343    }
    344344    END_BLOCK_OBJC_EXCEPTIONS;
     
    361361        scaledFontData.m_syntheticOblique = (fontTraits & kCTFontItalicTrait) && !(scaledFontTraits & kCTFontTraitItalic);
    362362
    363         return FontCache::singleton().fontForPlatformData(scaledFontData);
     363        return Font::create(scaledFontData);
    364364    }
    365365
Note: See TracChangeset for help on using the changeset viewer.