| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 #if !OS(ANDROID) | 39 #if !OS(ANDROID) |
| 40 const unsigned cMaxInactiveFontData = 250; | 40 const unsigned cMaxInactiveFontData = 250; |
| 41 const unsigned cTargetInactiveFontData = 200; | 41 const unsigned cTargetInactiveFontData = 200; |
| 42 #else | 42 #else |
| 43 const unsigned cMaxInactiveFontData = 225; | 43 const unsigned cMaxInactiveFontData = 225; |
| 44 const unsigned cTargetInactiveFontData = 200; | 44 const unsigned cTargetInactiveFontData = 200; |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 PassRefPtr<SimpleFontData> FontDataCache::get(const FontPlatformData* platformDa
ta, ShouldRetain shouldRetain) | 47 PassRefPtr<SimpleFontData> FontDataCache::get(const FontPlatformData* platformDa
ta, float fontSize, ShouldRetain shouldRetain) |
| 48 { | 48 { |
| 49 if (!platformData) | 49 if (!platformData) |
| 50 return nullptr; | 50 return nullptr; |
| 51 | 51 |
| 52 // TODO: crbug.com/446376 - This should not happen, but we currently | 52 // TODO: crbug.com/446376 - This should not happen, but we currently |
| 53 // do not have a reproduction for the crash that an empty typeface() | 53 // do not have a reproduction for the crash that an empty typeface() |
| 54 // causes downstream from here. | 54 // causes downstream from here. |
| 55 if (!platformData->typeface()) { | 55 if (!platformData->typeface()) { |
| 56 DLOG(ERROR) << "Empty typeface() in FontPlatformData when accessing Font
DataCache."; | 56 DLOG(ERROR) << "Empty typeface() in FontPlatformData when accessing Font
DataCache."; |
| 57 return nullptr; | 57 return nullptr; |
| 58 } | 58 } |
| 59 | 59 |
| 60 Cache::iterator result = m_cache.find(*platformData); | 60 InnerCache* innerCache = &m_cache.add(*platformData, InnerCache()).storedVal
ue->value; |
| 61 if (result == m_cache.end()) { | 61 InnerCache::AddResult addResult = innerCache->add(fontSize, std::make_pair(n
ullptr, 0)); |
| 62 std::pair<RefPtr<SimpleFontData>, unsigned> newValue(SimpleFontData::cre
ate(*platformData), shouldRetain == Retain ? 1 : 0); | 62 auto* value = &addResult.storedValue->value; |
| 63 m_cache.set(*platformData, newValue); | |
| 64 if (shouldRetain == DoNotRetain) | |
| 65 m_inactiveFontData.add(newValue.first); | |
| 66 return newValue.first.release(); | |
| 67 } | |
| 68 | 63 |
| 69 if (!result.get()->value.second) { | 64 if (addResult.isNewEntry) { |
| 70 ASSERT(m_inactiveFontData.contains(result.get()->value.first)); | 65 value->first = SimpleFontData::create(*platformData, fontSize, nullptr,
false); |
| 71 m_inactiveFontData.remove(result.get()->value.first); | 66 } else if (!value->second) { |
| 67 ASSERT(m_inactiveFontData.contains(value->first)); |
| 68 m_inactiveFontData.remove(value->first); |
| 72 } | 69 } |
| 73 | 70 |
| 74 if (shouldRetain == Retain) { | 71 if (shouldRetain == Retain) { |
| 75 result.get()->value.second++; | 72 value->second++; |
| 76 } else if (!result.get()->value.second) { | 73 } else if (!value->second) { |
| 77 // If shouldRetain is DoNotRetain and count is 0, we want to remove the
fontData from | 74 // If shouldRetain is DoNotRetain and count is 0, we want to remove the
fontData from |
| 78 // m_inactiveFontData (above) and re-add here to update LRU position. | 75 // m_inactiveFontData (above) and re-add here to update LRU position. |
| 79 m_inactiveFontData.add(result.get()->value.first); | 76 m_inactiveFontData.add(value->first); |
| 80 } | 77 } |
| 81 | 78 |
| 82 return result.get()->value.first; | 79 return value->first; |
| 83 } | 80 } |
| 84 | 81 |
| 85 bool FontDataCache::contains(const FontPlatformData* fontPlatformData) const | 82 bool FontDataCache::contains(const FontPlatformData* fontPlatformData) const |
| 86 { | 83 { |
| 87 return m_cache.contains(*fontPlatformData); | 84 return m_cache.contains(*fontPlatformData); |
| 88 } | 85 } |
| 89 | 86 |
| 90 void FontDataCache::release(const SimpleFontData* fontData) | 87 void FontDataCache::release(const SimpleFontData* fontData) |
| 91 { | 88 { |
| 92 ASSERT(!fontData->isCustomFont()); | 89 ASSERT(!fontData->isCustomFont()); |
| 93 | 90 |
| 94 Cache::iterator it = m_cache.find(fontData->platformData()); | 91 Cache::iterator outer = m_cache.find(fontData->platformData()); |
| 95 ASSERT(it != m_cache.end()); | 92 ASSERT(outer != m_cache.end()); |
| 96 if (it == m_cache.end()) | 93 if (outer == m_cache.end()) |
| 97 return; | 94 return; |
| 98 | 95 |
| 99 ASSERT(it->value.second); | 96 InnerCache::iterator inner = outer->value.find(fontData->size()); |
| 100 if (!--it->value.second) | 97 if (inner == outer->value.end()) |
| 101 m_inactiveFontData.add(it->value.first); | 98 return; |
| 99 |
| 100 ASSERT(inner->value.second); |
| 101 if (!--inner->value.second) |
| 102 m_inactiveFontData.add(inner->value.first); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void FontDataCache::markAllVerticalData() | 105 void FontDataCache::markAllVerticalData() |
| 105 { | 106 { |
| 106 Cache::iterator end = m_cache.end(); | 107 for (auto& inner : m_cache) { |
| 107 for (Cache::iterator fontData = m_cache.begin(); fontData != end; ++fontData
) { | 108 for (auto& fontData : inner.value) { |
| 108 OpenTypeVerticalData* verticalData = const_cast<OpenTypeVerticalData*>(f
ontData->value.first->verticalData()); | 109 OpenTypeVerticalData* verticalData = const_cast<OpenTypeVerticalData
*>(fontData.value.first->verticalData()); |
| 109 if (verticalData) | 110 if (verticalData) |
| 110 verticalData->setInFontCache(true); | 111 verticalData->setInFontCache(true); |
| 112 } |
| 111 } | 113 } |
| 112 } | 114 } |
| 113 | 115 |
| 114 bool FontDataCache::purge(PurgeSeverity PurgeSeverity) | 116 bool FontDataCache::purge(PurgeSeverity PurgeSeverity) |
| 115 { | 117 { |
| 116 if (PurgeSeverity == ForcePurge) | 118 if (PurgeSeverity == ForcePurge) |
| 117 return purgeLeastRecentlyUsed(INT_MAX); | 119 return purgeLeastRecentlyUsed(INT_MAX); |
| 118 | 120 |
| 119 if (m_inactiveFontData.size() > cMaxInactiveFontData) | 121 if (m_inactiveFontData.size() > cMaxInactiveFontData) |
| 120 return purgeLeastRecentlyUsed(m_inactiveFontData.size() - cTargetInactiv
eFontData); | 122 return purgeLeastRecentlyUsed(m_inactiveFontData.size() - cTargetInactiv
eFontData); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 151 bool didWork = fontDataToDelete.size(); | 153 bool didWork = fontDataToDelete.size(); |
| 152 | 154 |
| 153 fontDataToDelete.clear(); | 155 fontDataToDelete.clear(); |
| 154 | 156 |
| 155 isPurging = false; | 157 isPurging = false; |
| 156 | 158 |
| 157 return didWork; | 159 return didWork; |
| 158 } | 160 } |
| 159 | 161 |
| 160 } // namespace blink | 162 } // namespace blink |
| OLD | NEW |