Changeset 88260 in webkit


Ignore:
Timestamp:
Jun 7, 2011 1:46:28 PM (13 years ago)
Author:
msaboff@apple.com
Message:

2011-06-06 Michael Saboff <msaboff@apple.com>

Reviewed by Geoffrey Garen.

Fonts returned by FontCache::getFontDataForCharacters() are never released
https://bugs.webkit.org/show_bug.cgi?id=61875

This change allows fonts allocated as system fallback fonts to be
released. Previously, the reference counts for these fonts grew
without bound. This is implemented as an auto release class that wraps
accesses to the cache for system fallback fonts. All such accesses are
via the method FontCache::getFontDataForCharacters. The new class is
called FontCachePurgePreventer. When such an object exists, it protects
these fonts from deletion.

See more comments for this defect in Source/WebCore/ChangeLog.

  • WebKitGraphics.cpp: (CenterTruncateStringToWidth): (RightTruncateStringToWidth): Wrapped code accessing fallback fonts with local FontCachePurgePreventer in these methods.

2011-06-06 Michael Saboff <msaboff@apple.com>

Reviewed by Geoffrey Garen.

Fonts returned by FontCache::getFontDataForCharacters() are never released
https://bugs.webkit.org/show_bug.cgi?id=61875

This change allows fonts allocated as system fallback fonts to be
released. Previously, the reference counts for these fonts grew
without bound. This is implemented as an auto release class that wraps
accesses to the cache for system fallback fonts. All such accesses are
via the method FontCache::getFontDataForCharacters. The new class is
called FontCachePurgePreventer. When such an object exists, it protects
these fonts from deletion.

See more comments for this defect in Source/WebCore/ChangeLog.

  • Misc/WebKitNSStringExtras.mm: (-[NSString _web_drawAtPoint:font:textColor:allowingFontSmoothing:]): (-[NSString _web_widthWithFont:]): Wrapped code accessing fallback fonts with local FontCachePurgePreventer in these methods.
  • Misc/WebStringTruncator.mm: (+[WebStringTruncator centerTruncateString:toWidth:]): (+[WebStringTruncator centerTruncateString:toWidth:withFont:]): (+[WebStringTruncator rightTruncateString:toWidth:withFont:]): (+[WebStringTruncator widthOfString:font:]): Wrapped code accessing fallback fonts with local FontCachePurgePreventer in these methods.

2011-06-07 Michael Saboff <msaboff@apple.com>

Reviewed by Geoffrey Garen.

Fonts returned by FontCache::getFontDataForCharacters() are never released
https://bugs.webkit.org/show_bug.cgi?id=61875

This change allows fonts allocated as system fallback fonts to be
released. Previously, the reference counts for these fonts grew
without bound. This is implemented as an auto release class that wraps
accesses to the cache for system fallback fonts. All such accesses are
via the method FontCache::getFontDataForCharacters. The new class is
called FontCachePurgePreventer. When such an object exists, it protects
these fonts from deletion.

Most accesses to the font cache still use the reference counting
implemented by FontCache::getCacheFontData() and
FontCache::releaseFontData() and that operation is not affected by
this change.

Added local scoped instance of FontCachePurgePreventer to wrap code
that directly or indirectly accesses fonts via getFontDataForCharacters.
Did a few other miscellaneous bug fixes and changes to allow system
fallback fonts to be pruned from the GlyphPageTree. Changed the
calls to getFontData in the platform specific versions of
Fontcache::getFontDataForCharacters to not increment the reference
count. Moved the purge font check
outside of FontCache::getCachedFontData() into a separate method,
purgeInactiveFontDataIfNeeded() since almost all calls to
getCachedFontData() now happen when purging is not allowed.
purgeInactiveFontDataIfNeeded is invoked in enablePurging() when
m_purgePreventCount is 0.

No new test as the functionality has not changed. Improved font life
cycle management.

  • WebCore.exp.in: Added FontCache::purgeInactiveFontDataIfNeeded().
  • html/canvas/CanvasRenderingContext2D.cpp: (WebCore::CanvasRenderingContext2D::measureText): (WebCore::CanvasRenderingContext2D::drawTextInternal): Wrapped code accessing fallback fonts with local FontCachePurgePreventer in these methods.
  • page/FrameView.cpp: (WebCore::FrameView::layout): (WebCore::FrameView::paintContents): Wrapped code accessing fallback fonts with local FontCachePurgePreventer in these methods.
  • platform/graphics/FontCache.cpp: (WebCore::FontCache::FontCache): (WebCore::FontCache::getCachedFontData): Moved purge check to new method since it likely can't happen here. (WebCore::FontCache::releaseFontData): (WebCore::FontCache::purgeInactiveFontDataIfNeeded): (WebCore::FontCache::purgeInactiveFontData): Made purging conditional on m_purgePreventCount. Now some fonts in the cache are reference counted while other can be purged outside of code wrapped by in scope FontCachePurgePreventer objects.
  • platform/graphics/FontCache.h: (WebCore::FontCache::disablePurging): (WebCore::FontCache::enablePurging): (WebCore::FontCachePurgePreventer::FontCachePurgePreventer): (WebCore::FontCachePurgePreventer::~FontCachePurgePreventer): Added new simple purge prevention wrapper class and methods that it calls in FontCache actually prevent purging. The simple methods inlined to reduce overhead.
  • platform/graphics/FontFastPath.cpp: (WebCore::Font::glyphDataForCharacter): Update level in glyph page tree for system fallback fonts so pruning works.
  • platform/graphics/GlyphPage.h: (WebCore::GlyphPage::clearForFontData): New method used for pruning
  • platform/graphics/GlyphPageTreeNode.cpp: (WebCore::GlyphPageTreeNode::pruneFontData): Now we prune system fallback fonts.
  • platform/graphics/chromium/FontCacheChromiumWin.cpp: (WebCore::FontCache::getFontDataForCharacters):
  • platform/graphics/freetype/FontCacheFreeType.cpp: (WebCore::FontCache::getFontDataForCharacters):
  • platform/graphics/haiku/FontCacheHaiku.cpp: (WebCore::FontCache::getFontDataForCharacters):
  • platform/graphics/mac/FontCacheMac.mm: (WebCore::FontCache::getFontDataForCharacters):
  • platform/graphics/qt/FontCacheQt.cpp: (WebCore::FontCache::getFontDataForCharacters):
  • platform/graphics/win/FontCacheWin.cpp: (WebCore::FontCache::getFontDataForCharacters):
  • platform/graphics/wince/FontCacheWinCE.cpp:
  • platform/graphics/wx/FontCacheWx.cpp: (WebCore::FontCache::getFontDataForCharacters): Changed the calls to getFontData() to not increment the reference count. The caller of this getFontDataForCharacters() (currently only Font::glyphDataForCharacter() in fontFastPath.cpp) and it's callers don't attempt to release the returned fonts so we use the purge protection described above.
  • rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::selectionRect): (WebCore::InlineTextBox::offsetForPosition): (WebCore::InlineTextBox::positionForOffset): Wrapped code accessing fallback fonts with local FontCachePurgePreventer in these methods.
  • rendering/RenderImage.cpp: (WebCore::RenderImage::setImageSizeForAltText): Wrapped code accessing fallback fonts with local FontCachePurgePreventer in this method.
  • rendering/RenderListBox.cpp: (WebCore::RenderListBox::updateFromElement): (WebCore::RenderListBox::paintItemForeground): Wrapped code accessing fallback fonts with local FontCachePurgePreventer in these methods
  • rendering/svg/SVGInlineTextBox.cpp: (WebCore::SVGInlineTextBox::selectionRectForTextFragment): Wrapped code accessing fallback fonts with local FontCachePurgePreventer in this method.
Location:
trunk/Source
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r88259 r88260  
     12011-06-07  Michael Saboff  <msaboff@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Fonts returned by FontCache::getFontDataForCharacters() are never released
     6        https://bugs.webkit.org/show_bug.cgi?id=61875
     7
     8        This change allows fonts allocated as system fallback fonts to be
     9        released.  Previously, the reference counts for these fonts grew
     10        without bound.  This is implemented as an auto release class that wraps
     11        accesses to the cache for system fallback fonts. All such accesses are
     12        via the method FontCache::getFontDataForCharacters. The new class is
     13        called FontCachePurgePreventer. When such an object exists, it protects
     14        these fonts from deletion.
     15
     16        Most accesses to the font cache still use the reference counting
     17        implemented by FontCache::getCacheFontData() and
     18        FontCache::releaseFontData() and that operation is not affected by
     19        this change.
     20
     21        Added local scoped instance of FontCachePurgePreventer to wrap code
     22        that directly or indirectly accesses fonts via getFontDataForCharacters.
     23        Did a few other miscellaneous bug fixes and changes to allow system
     24        fallback fonts to be pruned from the GlyphPageTree. Changed the
     25        calls to getFontData in the platform specific versions of
     26        Fontcache::getFontDataForCharacters to not increment the reference
     27        count.  Moved the purge font check
     28        outside of FontCache::getCachedFontData() into a separate method,
     29        purgeInactiveFontDataIfNeeded() since almost all calls to
     30        getCachedFontData() now happen when purging is not allowed.
     31        purgeInactiveFontDataIfNeeded is invoked in enablePurging() when
     32        m_purgePreventCount is 0.
     33
     34        No new test as the functionality has not changed. Improved font life
     35        cycle management.
     36
     37        * WebCore.exp.in: Added FontCache::purgeInactiveFontDataIfNeeded().
     38        * html/canvas/CanvasRenderingContext2D.cpp:
     39        (WebCore::CanvasRenderingContext2D::measureText):
     40        (WebCore::CanvasRenderingContext2D::drawTextInternal):
     41        Wrapped code accessing fallback fonts with local
     42        FontCachePurgePreventer in these methods.
     43
     44        * page/FrameView.cpp:
     45        (WebCore::FrameView::layout):
     46        (WebCore::FrameView::paintContents):
     47        Wrapped code accessing fallback fonts with local
     48        FontCachePurgePreventer in these methods.
     49
     50        * platform/graphics/FontCache.cpp:
     51        (WebCore::FontCache::FontCache):
     52        (WebCore::FontCache::getCachedFontData):
     53        Moved purge check to new method since it likely can't happen here.
     54        (WebCore::FontCache::releaseFontData):
     55        (WebCore::FontCache::purgeInactiveFontDataIfNeeded):
     56        (WebCore::FontCache::purgeInactiveFontData):
     57        Made purging conditional on m_purgePreventCount.  Now some fonts
     58        in the cache are reference counted while other can be purged
     59        outside of code wrapped by in scope FontCachePurgePreventer objects.
     60
     61        * platform/graphics/FontCache.h:
     62        (WebCore::FontCache::disablePurging):
     63        (WebCore::FontCache::enablePurging):
     64        (WebCore::FontCachePurgePreventer::FontCachePurgePreventer):
     65        (WebCore::FontCachePurgePreventer::~FontCachePurgePreventer):
     66        Added new simple purge prevention wrapper class and methods
     67        that it calls in FontCache actually prevent purging.  The
     68        simple methods inlined to reduce overhead.
     69
     70        * platform/graphics/FontFastPath.cpp:
     71        (WebCore::Font::glyphDataForCharacter): Update level in
     72        glyph page tree for system fallback fonts so pruning works.
     73
     74        * platform/graphics/GlyphPage.h:
     75        (WebCore::GlyphPage::clearForFontData): New method used for pruning
     76        * platform/graphics/GlyphPageTreeNode.cpp:
     77        (WebCore::GlyphPageTreeNode::pruneFontData):
     78        Now we prune system fallback fonts.
     79
     80        * platform/graphics/chromium/FontCacheChromiumWin.cpp:
     81        (WebCore::FontCache::getFontDataForCharacters):
     82        * platform/graphics/freetype/FontCacheFreeType.cpp:
     83        (WebCore::FontCache::getFontDataForCharacters):
     84        * platform/graphics/haiku/FontCacheHaiku.cpp:
     85        (WebCore::FontCache::getFontDataForCharacters):
     86        * platform/graphics/mac/FontCacheMac.mm:
     87        (WebCore::FontCache::getFontDataForCharacters):
     88        * platform/graphics/qt/FontCacheQt.cpp:
     89        (WebCore::FontCache::getFontDataForCharacters):
     90        * platform/graphics/win/FontCacheWin.cpp:
     91        (WebCore::FontCache::getFontDataForCharacters):
     92        * platform/graphics/wince/FontCacheWinCE.cpp:
     93        * platform/graphics/wx/FontCacheWx.cpp:
     94        (WebCore::FontCache::getFontDataForCharacters):
     95        Changed the calls to getFontData() to not increment the reference
     96        count. The caller of this getFontDataForCharacters() (currently only
     97        Font::glyphDataForCharacter() in fontFastPath.cpp) and it's callers
     98        don't attempt to release the returned fonts so we use the purge
     99        protection described above.
     100
     101        * rendering/InlineTextBox.cpp:
     102        (WebCore::InlineTextBox::selectionRect):
     103        (WebCore::InlineTextBox::offsetForPosition):
     104        (WebCore::InlineTextBox::positionForOffset):
     105        Wrapped code accessing fallback fonts with local
     106        FontCachePurgePreventer in these methods.
     107
     108        * rendering/RenderImage.cpp:
     109        (WebCore::RenderImage::setImageSizeForAltText):
     110        Wrapped code accessing fallback fonts with local
     111        FontCachePurgePreventer in this method.
     112
     113        * rendering/RenderListBox.cpp:
     114        (WebCore::RenderListBox::updateFromElement):
     115        (WebCore::RenderListBox::paintItemForeground):
     116        Wrapped code accessing fallback fonts with local
     117        FontCachePurgePreventer in these methods
     118
     119        * rendering/svg/SVGInlineTextBox.cpp:
     120        (WebCore::SVGInlineTextBox::selectionRectForTextFragment):
     121        Wrapped code accessing fallback fonts with local
     122        FontCachePurgePreventer in this method.
     123
    11242011-06-07  Tim Horton  <timothy_horton@apple.com>
    2125
  • trunk/Source/WebCore/WebCore.exp.in

    r88178 r88260  
    924924__ZN7WebCore9FontCache21inactiveFontDataCountEv
    925925__ZN7WebCore9FontCache21purgeInactiveFontDataEi
     926__ZN7WebCore9FontCache29purgeInactiveFontDataIfNeededEv
    926927__ZN7WebCore9FrameTree11appendChildEN3WTF10PassRefPtrINS_5FrameEEE
    927928__ZN7WebCore9FrameTree7setNameERKN3WTF12AtomicStringE
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r87473 r88260  
    4444#include "ExceptionCode.h"
    4545#include "FloatConversion.h"
     46#include "FontCache.h"
    4647#include "GraphicsContext.h"
    4748#include "HTMLCanvasElement.h"
     
    18751876PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text)
    18761877{
     1878    FontCachePurgePreventer fontCachePurgePreventer;
     1879
    18771880    RefPtr<TextMetrics> metrics = TextMetrics::create();
    18781881
     
    19011904    if (!isfinite(x) | !isfinite(y))
    19021905        return;
     1906
     1907    FontCachePurgePreventer fontCachePurgePreventer;
    19031908
    19041909    const Font& font = accessFont();
  • trunk/Source/WebCore/page/FrameView.cpp

    r88250 r88260  
    3838#include "FloatRect.h"
    3939#include "FocusController.h"
     40#include "FontCache.h"
    4041#include "Frame.h"
    4142#include "FrameActionScheduler.h"
     
    897898    }
    898899
     900    FontCachePurgePreventer fontCachePurgePreventer;
     901
    899902    m_nestedLayoutCount++;
    900903
     
    24452448    if (needsLayout())
    24462449        return;
     2450
     2451    FontCachePurgePreventer fontCachePurgePreventer;
    24472452
    24482453#if USE(ACCELERATED_COMPOSITING)
  • trunk/Source/WebCore/platform/graphics/FontCache.cpp

    r83664 r88260  
    3535#include "FontPlatformData.h"
    3636#include "FontSelector.h"
     37#include "GlyphPageTreeNode.h"
    3738#include <wtf/HashMap.h>
    3839#include <wtf/ListHashSet.h>
     
    5152
    5253FontCache::FontCache()
     54    : m_purgePreventCount(0)
    5355{
    5456}
     
    250252static FontDataCache* gFontDataCache = 0;
    251253
    252 const int cMaxInactiveFontData = 120; // Pretty Low Threshold
    253 const int cTargetInactiveFontData = 100;
     254const int cMaxInactiveFontData = 50; // Pretty Low Threshold
     255const int cTargetInactiveFontData = 30;
    254256static ListHashSet<const SimpleFontData*>* gInactiveFontData = 0;
    255257
    256 SimpleFontData* FontCache::getCachedFontData(const FontDescription& fontDescription, const AtomicString& family, bool checkingAlternateName)
     258SimpleFontData* FontCache::getCachedFontData(const FontDescription& fontDescription, const AtomicString& family, bool checkingAlternateName, ShouldRetain shouldRetain)
    257259{
    258260    FontPlatformData* platformData = getCachedFontPlatformData(fontDescription, family, checkingAlternateName);
     
    260262        return 0;
    261263
    262     return getCachedFontData(platformData);
    263 }
    264 
    265 SimpleFontData* FontCache::getCachedFontData(const FontPlatformData* platformData)
     264    return getCachedFontData(platformData, shouldRetain);
     265}
     266
     267SimpleFontData* FontCache::getCachedFontData(const FontPlatformData* platformData, ShouldRetain shouldRetain)
    266268{
    267269    if (!platformData)
    268270        return 0;
     271
     272#if !ASSERT_DISABLED
     273    if (shouldRetain == DoNotRetain)
     274        ASSERT(m_purgePreventCount);
     275#endif
    269276
    270277    if (!gFontDataCache) {
     
    272279        gInactiveFontData = new ListHashSet<const SimpleFontData*>;
    273280    }
    274    
     281
    275282    FontDataCache::iterator result = gFontDataCache->find(*platformData);
    276283    if (result == gFontDataCache->end()) {
    277         pair<SimpleFontData*, unsigned> newValue(new SimpleFontData(*platformData), 1);
     284        pair<SimpleFontData*, unsigned> newValue(new SimpleFontData(*platformData), shouldRetain == Retain ? 1 : 0);
    278285        gFontDataCache->set(*platformData, newValue);
     286        if (shouldRetain == DoNotRetain)
     287            gInactiveFontData->add(newValue.first);
    279288        return newValue.first;
    280289    }
    281     if (!result.get()->second.second++) {
     290
     291    if (!result.get()->second.second) {
    282292        ASSERT(gInactiveFontData->contains(result.get()->second.first));
    283293        gInactiveFontData->remove(result.get()->second.first);
    284294    }
    285295
     296    if (shouldRetain == Retain)
     297        result.get()->second.second++;
     298    else if (!result.get()->second.second) {
     299        // If shouldRetain is DoNotRetain and count is 0, we want to remove the fontData from
     300        // gInactiveFontData (above) and re-add here to update LRU position.
     301        gInactiveFontData->add(result.get()->second.first);
     302    }
     303
    286304    return result.get()->second.first;
    287305}
     
    295313    ASSERT(it != gFontDataCache->end());
    296314
    297     if (!--it->second.second) {
     315    ASSERT(it->second.second);
     316    if (!--it->second.second)
    298317        gInactiveFontData->add(fontData);
    299         if (gInactiveFontData->size() > cMaxInactiveFontData)
    300             purgeInactiveFontData(gInactiveFontData->size() - cTargetInactiveFontData);
    301     }
     318}
     319
     320void FontCache::purgeInactiveFontDataIfNeeded()
     321{
     322    if (gInactiveFontData && !m_purgePreventCount && gInactiveFontData->size() > cMaxInactiveFontData)
     323        purgeInactiveFontData(gInactiveFontData->size() - cTargetInactiveFontData);
    302324}
    303325
    304326void FontCache::purgeInactiveFontData(int count)
    305327{
    306     if (!gInactiveFontData)
     328    if (!gInactiveFontData || m_purgePreventCount)
    307329        return;
    308330
  • trunk/Source/WebCore/platform/graphics/FontCache.h

    r76248 r88260  
    5252
    5353class FontCache {
     54    friend class FontCachePurgePreventer;
     55
     56    enum ShouldRetain { Retain, DoNotRetain };
     57
    5458    WTF_MAKE_NONCOPYABLE(FontCache); WTF_MAKE_FAST_ALLOCATED;
    5559public:
     
    5862    const FontData* getFontData(const Font&, int& familyIndex, FontSelector*);
    5963    void releaseFontData(const SimpleFontData*);
    60    
     64
    6165    // This method is implemented by the platform.
    62     // FIXME: Font data returned by this method never go inactive because callers don't track and release them.
    6366    const SimpleFontData* getFontDataForCharacters(const Font&, const UChar* characters, int length);
    64    
     67
    6568    // Also implemented by the platform.
    6669    void platformInit();
     
    8184    void getTraitsInFamily(const AtomicString&, Vector<unsigned>&);
    8285
    83     SimpleFontData* getCachedFontData(const FontDescription& fontDescription, const AtomicString& family, bool checkingAlternateName = false);
     86    SimpleFontData* getCachedFontData(const FontDescription&, const AtomicString&, bool checkingAlternateName = false, ShouldRetain = Retain);
    8487    SimpleFontData* getLastResortFallbackFont(const FontDescription&);
    8588
     
    98101    ~FontCache();
    99102
     103    void disablePurging() { m_purgePreventCount++; }
     104    void enablePurging()
     105    {
     106        ASSERT(m_purgePreventCount);
     107        if (!--m_purgePreventCount)
     108            purgeInactiveFontDataIfNeeded();
     109    }
     110
     111    void purgeInactiveFontDataIfNeeded();
     112
    100113    // FIXME: This method should eventually be removed.
    101114    FontPlatformData* getCachedFontPlatformData(const FontDescription&, const AtomicString& family, bool checkingAlternateName = false);
     
    105118    FontPlatformData* createFontPlatformData(const FontDescription&, const AtomicString& family);
    106119
    107     SimpleFontData* getCachedFontData(const FontPlatformData*);
     120    SimpleFontData* getCachedFontData(const FontPlatformData*, ShouldRetain = Retain);
     121
     122    // Don't purge if this count is > 0;
     123    int m_purgePreventCount;
    108124
    109125    friend class SimpleFontData; // For getCachedFontData(const FontPlatformData*)
     
    114130FontCache* fontCache();
    115131
     132class FontCachePurgePreventer {
     133public:
     134    FontCachePurgePreventer() { fontCache()->disablePurging(); }
     135    ~FontCachePurgePreventer() { fontCache()->enablePurging(); }
     136};
     137
    116138}
    117139
  • trunk/Source/WebCore/platform/graphics/FontFastPath.cpp

    r87215 r88260  
    3838using namespace WTF;
    3939using namespace Unicode;
     40using namespace std;
    4041
    4142namespace WebCore {
     
    211212            // So we just always set the glyph to be same as the character, and let GDI solve it.
    212213            page->setGlyphDataForCharacter(c, c, characterFontData);
     214            characterFontData->setMaxGlyphPageTreeLevel(max(characterFontData->maxGlyphPageTreeLevel(), node->level()));
    213215            return page->glyphDataForCharacter(c);
    214216#else
    215217            page->setGlyphDataForCharacter(c, data.glyph, data.fontData);
     218            data.fontData->setMaxGlyphPageTreeLevel(max(data.fontData->maxGlyphPageTreeLevel(), node->level()));
    216219#endif
    217220        }
     
    226229        // See comment about WINCE GDI handling near setGlyphDataForCharacter above.
    227230        page->setGlyphDataForCharacter(c, c, data.fontData);
     231        data.fontData->setMaxGlyphPageTreeLevel(max(data.fontData->maxGlyphPageTreeLevel(), node->level()));
    228232        return page->glyphDataForCharacter(c);
    229233#else
    230234        page->setGlyphDataForCharacter(c, data.glyph, data.fontData);
     235        data.fontData->setMaxGlyphPageTreeLevel(max(data.fontData->maxGlyphPageTreeLevel(), node->level()));
    231236#endif
    232237    }
  • trunk/Source/WebCore/platform/graphics/GlyphPage.h

    r84490 r88260  
    122122        memset(m_glyphFontData, 0, sizeof(m_glyphFontData));
    123123    }
    124    
     124
     125    void clearForFontData(const SimpleFontData* fontData)
     126    {
     127        for (size_t i = 0; i < size; ++i) {
     128            if (m_glyphFontData[i] == fontData) {
     129                m_glyphs[i] = 0;
     130                m_glyphFontData[i] = 0;
     131            }
     132        }
     133    }
     134
    125135    GlyphPageTreeNode* owner() const { return m_owner; }
    126136
  • trunk/Source/WebCore/platform/graphics/GlyphPageTreeNode.cpp

    r84264 r88260  
    375375        return;
    376376
     377    // Prune fall back child (if any) of this font.
     378    if (m_systemFallbackChild && m_systemFallbackChild->m_page)
     379        m_systemFallbackChild->m_page->clearForFontData(fontData);
     380
    377381    // Prune any branch that contains this FontData.
    378382    HashMap<const FontData*, GlyphPageTreeNode*>::iterator child = m_children.find(fontData);
    379     if (child == m_children.end()) {
    380         // If there is no level-1 node for fontData, then there is no deeper node for it in this tree.
    381         if (!level)
    382             return;
    383     } else {
     383    if (child != m_children.end()) {
    384384        GlyphPageTreeNode* node = child->second;
    385385        m_children.remove(fontData);
  • trunk/Source/WebCore/platform/graphics/chromium/FontCacheChromiumWin.cpp

    r79174 r88260  
    507507    // So, we have to use '<=" rather than '<' to see if we found a font
    508508    // covering the character.
    509     if (i <= numFonts) 
    510        return getCachedFontData(data);
     509    if (i <= numFonts)
     510        return getCachedFontData(data, DoNotRetain);
    511511
    512512    return 0;
  • trunk/Source/WebCore/platform/graphics/chromium/FontCacheLinux.cpp

    r80654 r88260  
    6565
    6666    AtomicString atomicFamily(family);
    67     return getCachedFontData(getCachedFontPlatformData(font.fontDescription(), atomicFamily, false));
     67    return getCachedFontData(getCachedFontPlatformData(font.fontDescription(), atomicFamily, DoNotRetain));
    6868}
    6969
  • trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp

    r78614 r88260  
    9090    if (fallbackPattern) {
    9191        FontPlatformData alternateFontData(fallbackPattern.get(), font.fontDescription());
    92         return getCachedFontData(&alternateFontData);
     92        return getCachedFontData(&alternateFontData, DoNotRetain);
    9393    }
    9494
     
    9898        return 0;
    9999    FontPlatformData alternateFontData(resultPattern.get(), font.fontDescription());
    100     return getCachedFontData(&alternateFontData);
     100    return getCachedFontData(&alternateFontData, DoNotRetain);
    101101}
    102102
  • trunk/Source/WebCore/platform/graphics/haiku/FontCacheHaiku.cpp

    r57517 r88260  
    5050{
    5151    FontPlatformData data(font.fontDescription(), font.family().family());
    52     return getCachedFontData(&data);
     52    return getCachedFontData(&data, DoNotRetain);
    5353}
    5454
  • trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm

    r87462 r88260  
    153153        !font.isPlatformFont() && (traits & NSFontItalicTrait) && !(substituteFontTraits & NSFontItalicTrait),
    154154        platformData.m_orientation);
    155     return getCachedFontData(&alternateFont);
     155
     156    return getCachedFontData(&alternateFont, DoNotRetain);
    156157}
    157158
  • trunk/Source/WebCore/platform/graphics/qt/FontCacheQt.cpp

    r85853 r88260  
    8181        return 0;
    8282    FontPlatformData alternateFont(computedFont);
    83     return getCachedFontData(&alternateFont);
     83    return getCachedFontData(&alternateFont, DoNotRetain);
    8484#else
    8585    Q_UNUSED(font);
  • trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp

    r84996 r88260  
    286286            FontPlatformData* result = getCachedFontPlatformData(font.fontDescription(), familyName);
    287287            if (result)
    288                 fontData = getCachedFontData(result);
     288                fontData = getCachedFontData(result, false);
    289289        }
    290290
  • trunk/Source/WebCore/platform/graphics/wince/FontCacheWinCE.cpp

    r67788 r88260  
    309309        FontPlatformData* result = getCachedFontPlatformData(fontDescription, familyName);
    310310        if (result && result->hash() != origFont.hash()) {
    311             if (SimpleFontData* fontData = getCachedFontData(result))
     311            if (SimpleFontData* fontData = getCachedFontData(result, false))
    312312                return fontData;
    313313        }
  • trunk/Source/WebCore/platform/graphics/wx/FontCacheWx.cpp

    r59780 r88260  
    4343{
    4444    SimpleFontData* fontData = 0;
    45     fontData = getCachedFontData(font.fontDescription(), font.family().family());
     45    fontData = getCachedFontData(font.fontDescription(), font.family().family(), false, false);
    4646    if (!fontData->containsCharacters(characters, length))
    4747        fontData = getSimilarFontPlatformData(font);
    4848    if (!fontData->containsCharacters(characters, length))
    4949        fontData = getLastResortFallbackFont(font.fontDescription());
    50    
     50
    5151    ASSERT(fontData);
    5252    return fontData;
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r88188 r88260  
    3030#include "Editor.h"
    3131#include "EllipsisBox.h"
     32#include "FontCache.h"
    3233#include "Frame.h"
    3334#include "GraphicsContext.h"
     
    180181    if (sPos > ePos)
    181182        return IntRect();
     183
     184    FontCachePurgePreventer fontCachePurgePreventer;
    182185
    183186    RenderText* textObj = textRenderer();
     
    12331236        return leftOffset;
    12341237
     1238    FontCachePurgePreventer fontCachePurgePreventer;
     1239
    12351240    RenderText* text = toRenderText(renderer());
    12361241    RenderStyle* style = text->style(m_firstLine);
     
    12491254    if (isLineBreak())
    12501255        return logicalLeft();
     1256
     1257    FontCachePurgePreventer fontCachePurgePreventer;
    12511258
    12521259    RenderText* text = toRenderText(renderer());
  • trunk/Source/WebCore/rendering/RenderImage.cpp

    r88250 r88260  
    2828#include "RenderImage.h"
    2929
     30#include "FontCache.h"
    3031#include "Frame.h"
    3132#include "FrameSelection.h"
     
    103104    // we have an alt and the user meant it (its not a text we invented)
    104105    if (!m_altText.isEmpty()) {
     106        FontCachePurgePreventer fontCachePurgePreventer;
     107
    105108        const Font& font = style()->font();
    106109        IntSize textSize(min(font.width(RenderBlock::constructTextRun(this, font, m_altText, style())), maxAltTextWidth), min(font.fontMetrics().height(), maxAltTextHeight));
  • trunk/Source/WebCore/rendering/RenderListBox.cpp

    r88193 r88260  
    3838#include "EventQueue.h"
    3939#include "FocusController.h"
     40#include "FontCache.h"
    4041#include "Frame.h"
    4142#include "FrameSelection.h"
     
    99100void RenderListBox::updateFromElement()
    100101{
     102    FontCachePurgePreventer fontCachePurgePreventer;
     103
    101104    if (m_optionsChanged) {
    102105        const Vector<Element*>& listItems = toSelectElement(static_cast<Element*>(node()))->listItems();
     
    359362void RenderListBox::paintItemForeground(PaintInfo& paintInfo, const IntPoint& paintOffset, int listIndex)
    360363{
     364    FontCachePurgePreventer fontCachePurgePreventer;
     365
    361366    SelectElement* select = toSelectElement(static_cast<Element*>(node()));
    362367    const Vector<Element*>& listItems = select->listItems();
  • trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp

    r88188 r88260  
    2525#if ENABLE(SVG)
    2626#include "FloatConversion.h"
     27#include "FontCache.h"
    2728#include "GraphicsContext.h"
    2829#include "InlineFlowBox.h"
     
    9192    ASSERT(style);
    9293
     94    FontCachePurgePreventer fontCachePurgePreventer;
     95
    9396    RenderSVGInlineText* textRenderer = toRenderSVGInlineText(this->textRenderer());
    9497    ASSERT(textRenderer);
  • trunk/Source/WebKit/mac/ChangeLog

    r88178 r88260  
     12011-06-06  Michael Saboff  <msaboff@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Fonts returned by FontCache::getFontDataForCharacters() are never released
     6        https://bugs.webkit.org/show_bug.cgi?id=61875
     7
     8        This change allows fonts allocated as system fallback fonts to be
     9        released.  Previously, the reference counts for these fonts grew
     10        without bound.  This is implemented as an auto release class that wraps
     11        accesses to the cache for system fallback fonts. All such accesses are
     12        via the method FontCache::getFontDataForCharacters. The new class is
     13        called FontCachePurgePreventer. When such an object exists, it protects
     14        these fonts from deletion.
     15
     16        See more comments for this defect in Source/WebCore/ChangeLog.
     17
     18        * Misc/WebKitNSStringExtras.mm:
     19        (-[NSString _web_drawAtPoint:font:textColor:allowingFontSmoothing:]):
     20        (-[NSString _web_widthWithFont:]):
     21        Wrapped code accessing fallback fonts with local
     22        FontCachePurgePreventer in these methods.
     23
     24        * Misc/WebStringTruncator.mm:
     25        (+[WebStringTruncator centerTruncateString:toWidth:]):
     26        (+[WebStringTruncator centerTruncateString:toWidth:withFont:]):
     27        (+[WebStringTruncator rightTruncateString:toWidth:withFont:]):
     28        (+[WebStringTruncator widthOfString:font:]):
     29        Wrapped code accessing fallback fonts with local
     30        FontCachePurgePreventer in these methods.
     31
    1322011-06-06  Peter Kasting  <pkasting@google.com>
    233
  • trunk/Source/WebKit/mac/Misc/WebKitNSStringExtras.mm

    r85036 r88260  
    3030
    3131#import <WebCore/Font.h>
     32#import <WebCore/FontCache.h>
    3233#import <WebCore/GraphicsContext.h>
    3334#import <WebCore/TextRun.h>
     
    8990        if (!flipped)
    9091            CGContextScaleCTM(cgContext, 1, -1);
     92
     93        FontCachePurgePreventer fontCachePurgePreventer;
    9194
    9295        Font webCoreFont(FontPlatformData(font, [font pointSize]), ![nsContext isDrawingToScreen], fontSmoothingIsAllowed ? AutoSmoothing : Antialiased);
     
    135138
    136139    if (canUseFastRenderer(buffer.data(), length)) {
     140        FontCachePurgePreventer fontCachePurgePreventer;
     141
    137142        Font webCoreFont(FontPlatformData(font, [font pointSize]), ![[NSGraphicsContext currentContext] isDrawingToScreen]);
    138143        TextRun run(buffer.data(), length);
  • trunk/Source/WebKit/mac/Misc/WebStringTruncator.mm

    r72141 r88260  
    3131#import "WebSystemInterface.h"
    3232#import <WebCore/Font.h>
     33#import <WebCore/FontCache.h>
    3334#import <WebCore/FontPlatformData.h>
    3435#import <WebCore/PlatformString.h>
     
    7374+ (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth
    7475{
     76    FontCachePurgePreventer fontCachePurgePreventer;
    7577    return StringTruncator::centerTruncate(string, maxWidth, fontFromNSFont(defaultMenuFont()));
    7678}
     
    7880+ (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth withFont:(NSFont *)font
    7981{
     82    FontCachePurgePreventer fontCachePurgePreventer;
    8083    return StringTruncator::centerTruncate(string, maxWidth, fontFromNSFont(font));
    8184}
     
    8386+ (NSString *)rightTruncateString:(NSString *)string toWidth:(float)maxWidth withFont:(NSFont *)font
    8487{
     88    FontCachePurgePreventer fontCachePurgePreventer;
    8589    return StringTruncator::rightTruncate(string, maxWidth, fontFromNSFont(font));
    8690}
     
    8892+ (float)widthOfString:(NSString *)string font:(NSFont *)font
    8993{
     94    FontCachePurgePreventer fontCachePurgePreventer;
    9095    return StringTruncator::width(string, fontFromNSFont(font));
    9196}
  • trunk/Source/WebKit/win/ChangeLog

    r88159 r88260  
     12011-06-06  Michael Saboff  <msaboff@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Fonts returned by FontCache::getFontDataForCharacters() are never released
     6        https://bugs.webkit.org/show_bug.cgi?id=61875
     7
     8        This change allows fonts allocated as system fallback fonts to be
     9        released.  Previously, the reference counts for these fonts grew
     10        without bound.  This is implemented as an auto release class that wraps
     11        accesses to the cache for system fallback fonts. All such accesses are
     12        via the method FontCache::getFontDataForCharacters. The new class is
     13        called FontCachePurgePreventer. When such an object exists, it protects
     14        these fonts from deletion.
     15
     16        See more comments for this defect in Source/WebCore/ChangeLog.
     17
     18        * WebKitGraphics.cpp:
     19        (CenterTruncateStringToWidth):
     20        (RightTruncateStringToWidth):
     21        Wrapped code accessing fallback fonts with local
     22        FontCachePurgePreventer in these methods.
     23
    1242011-06-04  Dominic Cooney  <dominicc@chromium.org>
    225
  • trunk/Source/WebKit/win/WebKitGraphics.cpp

    r82294 r88260  
    3333
    3434#include <WebCore/Font.h>
     35#include <WebCore/FontCache.h>
    3536#include <WebCore/FontDescription.h>
    3637#include <WebCore/FontSelector.h>
     
    148149    ASSERT(buffer);
    149150
     151    FontCachePurgePreventer fontCachePurgePreventer;
     152
    150153    String result = StringTruncator::centerTruncate(String(text, length), width, makeFont(description));
    151154    memcpy(buffer, result.characters(), result.length() * sizeof(UChar));
     
    157160{
    158161    ASSERT(buffer);
     162
     163    FontCachePurgePreventer fontCachePurgePreventer;
    159164
    160165    String result = StringTruncator::rightTruncate(String(text, length), width, makeFont(description));
Note: See TracChangeset for help on using the changeset viewer.