| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Cache::iterator result = m_cache.find(platformData); |
| 61 if (result == m_cache.end()) { | 61 if (result == m_cache.end()) { |
| 62 std::pair<RefPtr<SimpleFontData>, unsigned> newValue(SimpleFontData::cre
ate(*platformData), shouldRetain == Retain ? 1 : 0); | 62 std::pair<RefPtr<SimpleFontData>, unsigned> newValue(SimpleFontData::cre
ate(*platformData), shouldRetain == Retain ? 1 : 0); |
| 63 m_cache.set(*platformData, newValue); | 63 // The new SimpleFontData takes a copy of the incoming FontPlatformData
object. The incoming key may be |
| 64 // temporary. So, for cache storage, take the address of the newly creat
ed FontPlatformData that is copied an |
| 65 // owned by SimpleFontData. |
| 66 m_cache.set(&newValue.first->platformData(), newValue); |
| 64 if (shouldRetain == DoNotRetain) | 67 if (shouldRetain == DoNotRetain) |
| 65 m_inactiveFontData.add(newValue.first); | 68 m_inactiveFontData.add(newValue.first); |
| 66 return newValue.first.release(); | 69 return newValue.first.release(); |
| 67 } | 70 } |
| 68 | 71 |
| 69 if (!result.get()->value.second) { | 72 if (!result.get()->value.second) { |
| 70 ASSERT(m_inactiveFontData.contains(result.get()->value.first)); | 73 ASSERT(m_inactiveFontData.contains(result.get()->value.first)); |
| 71 m_inactiveFontData.remove(result.get()->value.first); | 74 m_inactiveFontData.remove(result.get()->value.first); |
| 72 } | 75 } |
| 73 | 76 |
| 74 if (shouldRetain == Retain) { | 77 if (shouldRetain == Retain) { |
| 75 result.get()->value.second++; | 78 result.get()->value.second++; |
| 76 } else if (!result.get()->value.second) { | 79 } else if (!result.get()->value.second) { |
| 77 // If shouldRetain is DoNotRetain and count is 0, we want to remove the
fontData from | 80 // 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. | 81 // m_inactiveFontData (above) and re-add here to update LRU position. |
| 79 m_inactiveFontData.add(result.get()->value.first); | 82 m_inactiveFontData.add(result.get()->value.first); |
| 80 } | 83 } |
| 81 | 84 |
| 82 return result.get()->value.first; | 85 return result.get()->value.first; |
| 83 } | 86 } |
| 84 | 87 |
| 85 bool FontDataCache::contains(const FontPlatformData* fontPlatformData) const | 88 bool FontDataCache::contains(const FontPlatformData* fontPlatformData) const |
| 86 { | 89 { |
| 87 return m_cache.contains(*fontPlatformData); | 90 return m_cache.contains(fontPlatformData); |
| 88 } | 91 } |
| 89 | 92 |
| 90 void FontDataCache::release(const SimpleFontData* fontData) | 93 void FontDataCache::release(const SimpleFontData* fontData) |
| 91 { | 94 { |
| 92 ASSERT(!fontData->isCustomFont()); | 95 ASSERT(!fontData->isCustomFont()); |
| 93 | 96 |
| 94 Cache::iterator it = m_cache.find(fontData->platformData()); | 97 Cache::iterator it = m_cache.find(&(fontData->platformData())); |
| 95 ASSERT(it != m_cache.end()); | 98 ASSERT(it != m_cache.end()); |
| 96 if (it == m_cache.end()) | 99 if (it == m_cache.end()) |
| 97 return; | 100 return; |
| 98 | 101 |
| 99 ASSERT(it->value.second); | 102 ASSERT(it->value.second); |
| 100 if (!--it->value.second) | 103 if (!--it->value.second) |
| 101 m_inactiveFontData.add(it->value.first); | 104 m_inactiveFontData.add(it->value.first); |
| 102 } | 105 } |
| 103 | 106 |
| 104 void FontDataCache::markAllVerticalData() | 107 void FontDataCache::markAllVerticalData() |
| (...skipping 23 matching lines...) Expand all Loading... |
| 128 if (isPurging) | 131 if (isPurging) |
| 129 return false; | 132 return false; |
| 130 | 133 |
| 131 isPurging = true; | 134 isPurging = true; |
| 132 | 135 |
| 133 Vector<RefPtr<SimpleFontData>, 20> fontDataToDelete; | 136 Vector<RefPtr<SimpleFontData>, 20> fontDataToDelete; |
| 134 ListHashSet<RefPtr<SimpleFontData>>::iterator end = m_inactiveFontData.end()
; | 137 ListHashSet<RefPtr<SimpleFontData>>::iterator end = m_inactiveFontData.end()
; |
| 135 ListHashSet<RefPtr<SimpleFontData>>::iterator it = m_inactiveFontData.begin(
); | 138 ListHashSet<RefPtr<SimpleFontData>>::iterator it = m_inactiveFontData.begin(
); |
| 136 for (int i = 0; i < count && it != end; ++it, ++i) { | 139 for (int i = 0; i < count && it != end; ++it, ++i) { |
| 137 RefPtr<SimpleFontData>& fontData = *it.get(); | 140 RefPtr<SimpleFontData>& fontData = *it.get(); |
| 138 m_cache.remove(fontData->platformData()); | 141 m_cache.remove(&(fontData->platformData())); |
| 139 // We should not delete SimpleFontData here because deletion can modify
m_inactiveFontData. See http://trac.webkit.org/changeset/44011 | 142 // We should not delete SimpleFontData here because deletion can modify
m_inactiveFontData. See http://trac.webkit.org/changeset/44011 |
| 140 fontDataToDelete.append(fontData); | 143 fontDataToDelete.append(fontData); |
| 141 } | 144 } |
| 142 | 145 |
| 143 if (it == end) { | 146 if (it == end) { |
| 144 // Removed everything | 147 // Removed everything |
| 145 m_inactiveFontData.clear(); | 148 m_inactiveFontData.clear(); |
| 146 } else { | 149 } else { |
| 147 for (int i = 0; i < count; ++i) | 150 for (int i = 0; i < count; ++i) |
| 148 m_inactiveFontData.remove(m_inactiveFontData.begin()); | 151 m_inactiveFontData.remove(m_inactiveFontData.begin()); |
| 149 } | 152 } |
| 150 | 153 |
| 151 bool didWork = fontDataToDelete.size(); | 154 bool didWork = fontDataToDelete.size(); |
| 152 | 155 |
| 153 fontDataToDelete.clear(); | 156 fontDataToDelete.clear(); |
| 154 | 157 |
| 155 isPurging = false; | 158 isPurging = false; |
| 156 | 159 |
| 157 return didWork; | 160 return didWork; |
| 158 } | 161 } |
| 159 | 162 |
| 160 } // namespace blink | 163 } // namespace blink |
| OLD | NEW |