diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2012-10-17 16:21:14 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2012-10-17 16:21:14 +0200 |
commit | 8995b83bcbfbb68245f779b64e5517627c6cc6ea (patch) | |
tree | 17985605dab9263cc2444bd4d45f189e142cca7c /Source/WebCore/platform/graphics/FontCache.cpp | |
parent | b9c9652036d5e9f1e29c574f40bc73a35c81ace6 (diff) |
Imported WebKit commit cf4f8fc6f19b0629f51860cb2d4b25e139d07e00 (http://svn.webkit.org/repository/webkit/trunk@131592)
New snapshot that includes the build fixes for Mac OS X 10.6 and earlier as well
as the previously cherry-picked changes
Diffstat (limited to 'Source/WebCore/platform/graphics/FontCache.cpp')
-rw-r--r-- | Source/WebCore/platform/graphics/FontCache.cpp | 79 |
1 files changed, 38 insertions, 41 deletions
diff --git a/Source/WebCore/platform/graphics/FontCache.cpp b/Source/WebCore/platform/graphics/FontCache.cpp index 9cab2fa0e..3fea6c235 100644 --- a/Source/WebCore/platform/graphics/FontCache.cpp +++ b/Source/WebCore/platform/graphics/FontCache.cpp @@ -34,7 +34,6 @@ #include "FontFallbackList.h" #include "FontPlatformData.h" #include "FontSelector.h" -#include "GlyphPageTreeNode.h" #include "OpenTypeVerticalData.h" #include "WebKitFontFamilyNames.h" #include <wtf/HashMap.h> @@ -211,7 +210,7 @@ FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& fo gFontPlatformDataCache->set(key, result); foundResult = result; } else { - result = it->second; + result = it->value; foundResult = true; } @@ -229,7 +228,7 @@ FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& fo } #if ENABLE(OPENTYPE_VERTICAL) -typedef HashMap<FontCache::FontFileKey, OwnPtr<OpenTypeVerticalData> > FontVerticalDataCache; +typedef HashMap<FontCache::FontFileKey, OwnPtr<OpenTypeVerticalData>, WTF::IntHash<FontCache::FontFileKey>, WTF::UnsignedWithZeroKeyHashTraits<FontCache::FontFileKey> > FontVerticalDataCache; FontVerticalDataCache& fontVerticalDataCacheInstance() { @@ -242,7 +241,7 @@ OpenTypeVerticalData* FontCache::getVerticalData(const FontFileKey& key, const F FontVerticalDataCache& fontVerticalDataCache = fontVerticalDataCacheInstance(); FontVerticalDataCache::iterator result = fontVerticalDataCache.find(key); if (result != fontVerticalDataCache.end()) - return result.get()->second.get(); + return result.get()->value.get(); OpenTypeVerticalData* verticalData = new OpenTypeVerticalData(platformData); if (!verticalData->isOpenType()) { @@ -286,7 +285,7 @@ struct FontDataCacheKeyTraits : WTF::GenericHashTraits<FontPlatformData> { } }; -typedef HashMap<FontPlatformData, pair<SimpleFontData*, unsigned>, FontDataCacheKeyHash, FontDataCacheKeyTraits> FontDataCache; +typedef HashMap<FontPlatformData, pair<RefPtr<SimpleFontData>, unsigned>, FontDataCacheKeyHash, FontDataCacheKeyTraits> FontDataCache; static FontDataCache* gFontDataCache = 0; @@ -297,9 +296,9 @@ const int cTargetInactiveFontData = 200; const int cMaxInactiveFontData = 50; // Pretty Low Threshold const int cTargetInactiveFontData = 30; #endif -static ListHashSet<const SimpleFontData*>* gInactiveFontData = 0; +static ListHashSet<RefPtr<SimpleFontData> >* gInactiveFontData = 0; -SimpleFontData* FontCache::getCachedFontData(const FontDescription& fontDescription, const AtomicString& family, bool checkingAlternateName, ShouldRetain shouldRetain) +PassRefPtr<SimpleFontData> FontCache::getCachedFontData(const FontDescription& fontDescription, const AtomicString& family, bool checkingAlternateName, ShouldRetain shouldRetain) { FontPlatformData* platformData = getCachedFontPlatformData(fontDescription, family, checkingAlternateName); if (!platformData) @@ -308,7 +307,7 @@ SimpleFontData* FontCache::getCachedFontData(const FontDescription& fontDescript return getCachedFontData(platformData, shouldRetain); } -SimpleFontData* FontCache::getCachedFontData(const FontPlatformData* platformData, ShouldRetain shouldRetain) +PassRefPtr<SimpleFontData> FontCache::getCachedFontData(const FontPlatformData* platformData, ShouldRetain shouldRetain) { if (!platformData) return 0; @@ -320,37 +319,37 @@ SimpleFontData* FontCache::getCachedFontData(const FontPlatformData* platformDat if (!gFontDataCache) { gFontDataCache = new FontDataCache; - gInactiveFontData = new ListHashSet<const SimpleFontData*>; + gInactiveFontData = new ListHashSet<RefPtr<SimpleFontData> >; } FontDataCache::iterator result = gFontDataCache->find(*platformData); if (result == gFontDataCache->end()) { - pair<SimpleFontData*, unsigned> newValue(new SimpleFontData(*platformData), shouldRetain == Retain ? 1 : 0); + pair<RefPtr<SimpleFontData>, unsigned> newValue(SimpleFontData::create(*platformData), shouldRetain == Retain ? 1 : 0); gFontDataCache->set(*platformData, newValue); if (shouldRetain == DoNotRetain) gInactiveFontData->add(newValue.first); - return newValue.first; + return newValue.first.release(); } - if (!result.get()->second.second) { - ASSERT(gInactiveFontData->contains(result.get()->second.first)); - gInactiveFontData->remove(result.get()->second.first); + if (!result.get()->value.second) { + ASSERT(gInactiveFontData->contains(result.get()->value.first)); + gInactiveFontData->remove(result.get()->value.first); } if (shouldRetain == Retain) - result.get()->second.second++; - else if (!result.get()->second.second) { + result.get()->value.second++; + else if (!result.get()->value.second) { // If shouldRetain is DoNotRetain and count is 0, we want to remove the fontData from // gInactiveFontData (above) and re-add here to update LRU position. - gInactiveFontData->add(result.get()->second.first); + gInactiveFontData->add(result.get()->value.first); } - return result.get()->second.first; + return result.get()->value.first; } SimpleFontData* FontCache::getNonRetainedLastResortFallbackFont(const FontDescription& fontDescription) { - return getLastResortFallbackFont(fontDescription, DoNotRetain); + return getLastResortFallbackFont(fontDescription, DoNotRetain).leakRef(); } void FontCache::releaseFontData(const SimpleFontData* fontData) @@ -361,9 +360,9 @@ void FontCache::releaseFontData(const SimpleFontData* fontData) FontDataCache::iterator it = gFontDataCache->find(fontData->platformData()); ASSERT(it != gFontDataCache->end()); - ASSERT(it->second.second); - if (!--it->second.second) - gInactiveFontData->add(fontData); + ASSERT(it->value.second); + if (!--it->value.second) + gInactiveFontData->add(it->value.first); } void FontCache::purgeInactiveFontDataIfNeeded() @@ -383,11 +382,11 @@ void FontCache::purgeInactiveFontData(int count) isPurging = true; - Vector<const SimpleFontData*, 20> fontDataToDelete; - ListHashSet<const SimpleFontData*>::iterator end = gInactiveFontData->end(); - ListHashSet<const SimpleFontData*>::iterator it = gInactiveFontData->begin(); + Vector<RefPtr<SimpleFontData>, 20> fontDataToDelete; + ListHashSet<RefPtr<SimpleFontData> >::iterator end = gInactiveFontData->end(); + ListHashSet<RefPtr<SimpleFontData> >::iterator it = gInactiveFontData->begin(); for (int i = 0; i < count && it != end; ++it, ++i) { - const SimpleFontData* fontData = *it.get(); + RefPtr<SimpleFontData>& fontData = *it.get(); gFontDataCache->remove(fontData->platformData()); // We should not delete SimpleFontData here because deletion can modify gInactiveFontData. See http://trac.webkit.org/changeset/44011 fontDataToDelete.append(fontData); @@ -401,17 +400,15 @@ void FontCache::purgeInactiveFontData(int count) gInactiveFontData->remove(gInactiveFontData->begin()); } - size_t fontDataToDeleteCount = fontDataToDelete.size(); - for (size_t i = 0; i < fontDataToDeleteCount; ++i) - delete fontDataToDelete[i]; + fontDataToDelete.clear(); if (gFontPlatformDataCache) { Vector<FontPlatformDataCacheKey> keysToRemove; keysToRemove.reserveInitialCapacity(gFontPlatformDataCache->size()); FontPlatformDataCache::iterator platformDataEnd = gFontPlatformDataCache->end(); for (FontPlatformDataCache::iterator platformData = gFontPlatformDataCache->begin(); platformData != platformDataEnd; ++platformData) { - if (platformData->second && !gFontDataCache->contains(*platformData->second)) - keysToRemove.append(platformData->first); + if (platformData->value && !gFontDataCache->contains(*platformData->value)) + keysToRemove.append(platformData->key); } size_t keysToRemoveCount = keysToRemove.size(); @@ -425,20 +422,20 @@ void FontCache::purgeInactiveFontData(int count) // Mark & sweep unused verticalData FontVerticalDataCache::iterator verticalDataEnd = fontVerticalDataCache.end(); for (FontVerticalDataCache::iterator verticalData = fontVerticalDataCache.begin(); verticalData != verticalDataEnd; ++verticalData) { - if (verticalData->second) - verticalData->second->m_inFontCache = false; + if (verticalData->value) + verticalData->value->m_inFontCache = false; } FontDataCache::iterator fontDataEnd = gFontDataCache->end(); for (FontDataCache::iterator fontData = gFontDataCache->begin(); fontData != fontDataEnd; ++fontData) { - OpenTypeVerticalData* verticalData = const_cast<OpenTypeVerticalData*>(fontData->second.first->verticalData()); + OpenTypeVerticalData* verticalData = const_cast<OpenTypeVerticalData*>(fontData->value.first->verticalData()); if (verticalData) verticalData->m_inFontCache = true; } Vector<FontFileKey> keysToRemove; keysToRemove.reserveInitialCapacity(fontVerticalDataCache.size()); for (FontVerticalDataCache::iterator verticalData = fontVerticalDataCache.begin(); verticalData != verticalDataEnd; ++verticalData) { - if (!verticalData->second || !verticalData->second->m_inFontCache) - keysToRemove.append(verticalData->first); + if (!verticalData->value || !verticalData->value->m_inFontCache) + keysToRemove.append(verticalData->key); } for (size_t i = 0, count = keysToRemove.size(); i < count; ++i) fontVerticalDataCache.take(keysToRemove[i]); @@ -462,9 +459,9 @@ size_t FontCache::inactiveFontDataCount() return 0; } -const FontData* FontCache::getFontData(const Font& font, int& familyIndex, FontSelector* fontSelector) +PassRefPtr<FontData> FontCache::getFontData(const Font& font, int& familyIndex, FontSelector* fontSelector) { - FontData* result = 0; + RefPtr<FontData> result; int startIndex = familyIndex; const FontFamily* startFamily = &font.fontDescription().family(); @@ -498,14 +495,14 @@ const FontData* FontCache::getFontData(const Font& font, int& familyIndex, FontS if (fontSelector) { // Try the user's preferred standard font. - if (FontData* data = fontSelector->getFontData(font.fontDescription(), standardFamily)) - return data; + if (RefPtr<FontData> data = fontSelector->getFontData(font.fontDescription(), standardFamily)) + return data.release(); } // Still no result. Hand back our last resort fallback font. result = getLastResortFallbackFont(font.fontDescription()); } - return result; + return result.release(); } static HashSet<FontSelector*>* gClients; |