Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(975)

Unified Diff: third_party/WebKit/Source/platform/fonts/FontCache.cpp

Issue 1962263002: Introduce FontCache content scaling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/fonts/FontCache.cpp
diff --git a/third_party/WebKit/Source/platform/fonts/FontCache.cpp b/third_party/WebKit/Source/platform/fonts/FontCache.cpp
index 29b184198ae71ce804bb47a3fdb79ec82ced6062..6bb2a9c93b1bced24d4d8d0031755c57eeb02f83 100644
--- a/third_party/WebKit/Source/platform/fonts/FontCache.cpp
+++ b/third_party/WebKit/Source/platform/fonts/FontCache.cpp
@@ -67,7 +67,8 @@ FontCache::FontCache()
}
#endif // !OS(WIN) && !OS(LINUX)
-typedef HashMap<FontCacheKey, OwnPtr<FontPlatformData>, FontCacheKeyHash, FontCacheKeyTraits> FontPlatformDataCache;
+typedef HashMap<unsigned, OwnPtr<FontPlatformData>> SizedFontPlatformDataSet;
+typedef HashMap<FontCacheKey, SizedFontPlatformDataSet, FontCacheKeyHash, FontCacheKeyTraits> FontPlatformDataCache;
typedef HashMap<FallbackListCompositeKey, OwnPtr<ShapeCache>, FallbackListCompositeKeyHash, FallbackListCompositeKeyTraits> FallbackListShaperCache;
static FontPlatformDataCache* gFontPlatformDataCache = nullptr;
@@ -96,17 +97,38 @@ FontPlatformData* FontCache::getFontPlatformData(const FontDescription& fontDesc
platformInit();
}
+ float size = fontDescription.effectiveFontSize();
FontCacheKey key = fontDescription.cacheKey(creationParams);
+
+ // Remove the font size from the cache key, and handle the font size separately in the inner
+ // HashMap. So that different size of FontPlatformData can share underlying SkTypeface.
+ key.clearFontSize();
+
FontPlatformData* result;
bool foundResult;
+
{
// addResult's scope must end before we recurse for alternate family names below,
// to avoid trigering its dtor hash-changed asserts.
- auto addResult = gFontPlatformDataCache->add(key, nullptr);
- if (addResult.isNewEntry)
- addResult.storedValue->value = createFontPlatformData(fontDescription, creationParams, fontDescription.effectiveFontSize());
+ SizedFontPlatformDataSet* sizedFonts = &gFontPlatformDataCache->add(key, SizedFontPlatformDataSet()).storedValue->value;
+ bool wasEmpty = sizedFonts->isEmpty();
+
+ // Take a different size instance of the same font before adding an entry to |sizedFont|.
+ FontPlatformData* anotherSize = wasEmpty ? nullptr : sizedFonts->begin()->value.get();
+
+ // Use -2 instead of 0 for the default size. We can not use 0 or -1 for HashMap key, since
+ // they are reserved for empty and deleted value.
+ unsigned roundedSize = size ? size * FontCacheKey::precisionMultiplier() : -2;
kouhei (in TOK) 2016/05/18 02:31:06 -2 should be defined as "static const unsigned" or
+ auto addResult = sizedFonts->add(roundedSize, nullptr);
+ OwnPtr<FontPlatformData>* found = &addResult.storedValue->value;
+ if (addResult.isNewEntry) {
+ if (wasEmpty)
+ *found = createFontPlatformData(fontDescription, creationParams, size);
+ else if (anotherSize)
+ *found = scaleFontPlatformData(*anotherSize, fontDescription, creationParams, size);
+ }
- result = addResult.storedValue->value.get();
+ result = found->get();
foundResult = result || !addResult.isNewEntry;
}
@@ -118,13 +140,25 @@ FontPlatformData* FontCache::getFontPlatformData(const FontDescription& fontDesc
FontFaceCreationParams createByAlternateFamily(alternateName);
result = getFontPlatformData(fontDescription, createByAlternateFamily, true);
}
- if (result)
- gFontPlatformDataCache->set(key, adoptPtr(new FontPlatformData(*result))); // Cache the result under the old name.
+ if (result) {
+ // Cache the result under the old name.
+ auto adding = &gFontPlatformDataCache->add(key, SizedFontPlatformDataSet()).storedValue->value;
+ adding->set(size, adoptPtr(new FontPlatformData(*result)));
+ }
}
return result;
}
+PassOwnPtr<FontPlatformData> FontCache::scaleFontPlatformData(const FontPlatformData& fontPlatformData, const FontDescription& fontDescription, const FontFaceCreationParams& creationParams, float fontSize)
+{
+#if OS(MACOSX)
+ return createFontPlatformData(fontDescription, creationParams, fontSize);
+#else
+ return adoptPtr(new FontPlatformData(fontPlatformData, fontSize));
+#endif
+}
+
ShapeCache* FontCache::getShapeCache(const FallbackListCompositeKey& key)
{
if (!gFallbackListShaperCache)
@@ -226,10 +260,16 @@ static inline void purgePlatformFontDataCache()
Vector<FontCacheKey> keysToRemove;
keysToRemove.reserveInitialCapacity(gFontPlatformDataCache->size());
- FontPlatformDataCache::iterator platformDataEnd = gFontPlatformDataCache->end();
- for (FontPlatformDataCache::iterator platformData = gFontPlatformDataCache->begin(); platformData != platformDataEnd; ++platformData) {
- if (platformData->value && !gFontDataCache->contains(platformData->value.get()))
- keysToRemove.append(platformData->key);
+ for (auto& sizedFonts : *gFontPlatformDataCache) {
+ Vector<float> sizesToRemove;
+ sizesToRemove.reserveInitialCapacity(sizedFonts.value.size());
+ for (const auto& platformData : sizedFonts.value) {
+ if (platformData.value && !gFontDataCache->contains(platformData.value.get()))
+ sizesToRemove.append(platformData.key);
+ }
+ sizedFonts.value.removeAll(sizesToRemove);
+ if (sizedFonts.value.isEmpty())
+ keysToRemove.append(sizedFonts.key);
}
gFontPlatformDataCache->removeAll(keysToRemove);
}
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/FontCache.h ('k') | third_party/WebKit/Source/platform/fonts/FontCacheKey.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698