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

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

Issue 1931393002: Introduce typeface cache in blink::FontCache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wip: others Created 4 years, 8 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/FontDataCache.cpp
diff --git a/third_party/WebKit/Source/platform/fonts/FontDataCache.cpp b/third_party/WebKit/Source/platform/fonts/FontDataCache.cpp
index 4bf5a2c28fc4bb51710f122a8309305dc81fc557..b14faa588e32f503001b3e2c2713b89813816d5d 100644
--- a/third_party/WebKit/Source/platform/fonts/FontDataCache.cpp
+++ b/third_party/WebKit/Source/platform/fonts/FontDataCache.cpp
@@ -44,7 +44,7 @@ const unsigned cMaxInactiveFontData = 225;
const unsigned cTargetInactiveFontData = 200;
#endif
-PassRefPtr<SimpleFontData> FontDataCache::get(const FontPlatformData* platformData, ShouldRetain shouldRetain)
+PassRefPtr<SimpleFontData> FontDataCache::get(const FontPlatformData* platformData, float fontSize, ShouldRetain shouldRetain)
{
if (!platformData)
return nullptr;
@@ -57,29 +57,26 @@ PassRefPtr<SimpleFontData> FontDataCache::get(const FontPlatformData* platformDa
return nullptr;
}
- Cache::iterator result = m_cache.find(*platformData);
- if (result == m_cache.end()) {
- std::pair<RefPtr<SimpleFontData>, unsigned> newValue(SimpleFontData::create(*platformData), shouldRetain == Retain ? 1 : 0);
- m_cache.set(*platformData, newValue);
- if (shouldRetain == DoNotRetain)
- m_inactiveFontData.add(newValue.first);
- return newValue.first.release();
- }
+ InnerCache* innerCache = &m_cache.add(*platformData, InnerCache()).storedValue->value;
+ InnerCache::AddResult addResult = innerCache->add(fontSize, std::make_pair(nullptr, 0));
+ auto* value = &addResult.storedValue->value;
- if (!result.get()->value.second) {
- ASSERT(m_inactiveFontData.contains(result.get()->value.first));
- m_inactiveFontData.remove(result.get()->value.first);
+ if (addResult.isNewEntry) {
+ value->first = SimpleFontData::create(*platformData, fontSize, nullptr, false);
+ } else if (!value->second) {
+ ASSERT(m_inactiveFontData.contains(value->first));
+ m_inactiveFontData.remove(value->first);
}
if (shouldRetain == Retain) {
- result.get()->value.second++;
- } else if (!result.get()->value.second) {
+ value->second++;
+ } else if (!value->second) {
// If shouldRetain is DoNotRetain and count is 0, we want to remove the fontData from
// m_inactiveFontData (above) and re-add here to update LRU position.
- m_inactiveFontData.add(result.get()->value.first);
+ m_inactiveFontData.add(value->first);
}
- return result.get()->value.first;
+ return value->first;
}
bool FontDataCache::contains(const FontPlatformData* fontPlatformData) const
@@ -91,23 +88,28 @@ void FontDataCache::release(const SimpleFontData* fontData)
{
ASSERT(!fontData->isCustomFont());
- Cache::iterator it = m_cache.find(fontData->platformData());
- ASSERT(it != m_cache.end());
- if (it == m_cache.end())
+ Cache::iterator outer = m_cache.find(fontData->platformData());
+ ASSERT(outer != m_cache.end());
+ if (outer == m_cache.end())
+ return;
+
+ InnerCache::iterator inner = outer->value.find(fontData->size());
+ if (inner == outer->value.end())
return;
- ASSERT(it->value.second);
- if (!--it->value.second)
- m_inactiveFontData.add(it->value.first);
+ ASSERT(inner->value.second);
+ if (!--inner->value.second)
+ m_inactiveFontData.add(inner->value.first);
}
void FontDataCache::markAllVerticalData()
{
- Cache::iterator end = m_cache.end();
- for (Cache::iterator fontData = m_cache.begin(); fontData != end; ++fontData) {
- OpenTypeVerticalData* verticalData = const_cast<OpenTypeVerticalData*>(fontData->value.first->verticalData());
- if (verticalData)
- verticalData->setInFontCache(true);
+ for (auto& inner : m_cache) {
+ for (auto& fontData : inner.value) {
+ OpenTypeVerticalData* verticalData = const_cast<OpenTypeVerticalData*>(fontData.value.first->verticalData());
+ if (verticalData)
+ verticalData->setInFontCache(true);
+ }
}
}
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/FontDataCache.h ('k') | third_party/WebKit/Source/platform/fonts/FontPlatformData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698