| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 OwnPtr<DecoderCacheEntry> newCacheEntry = DecoderCacheEntry::create(generato
r, decoder); | 99 OwnPtr<DecoderCacheEntry> newCacheEntry = DecoderCacheEntry::create(generato
r, decoder); |
| 100 | 100 |
| 101 MutexLocker lock(m_mutex); | 101 MutexLocker lock(m_mutex); |
| 102 ASSERT(!m_decoderCacheMap.contains(newCacheEntry->cacheKey())); | 102 ASSERT(!m_decoderCacheMap.contains(newCacheEntry->cacheKey())); |
| 103 insertCacheInternal(newCacheEntry.release(), &m_decoderCacheMap, &m_decoderC
acheKeyMap); | 103 insertCacheInternal(newCacheEntry.release(), &m_decoderCacheMap, &m_decoderC
acheKeyMap); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void ImageDecodingStore::removeDecoder(const ImageFrameGenerator* generator, con
st ImageDecoder* decoder) | 106 void ImageDecodingStore::removeDecoder(const ImageFrameGenerator* generator, con
st ImageDecoder* decoder) |
| 107 { | 107 { |
| 108 Vector<OwnPtr<CacheEntry> > cacheEntriesToDelete; | 108 Vector<OwnPtr<CacheEntry>> cacheEntriesToDelete; |
| 109 { | 109 { |
| 110 MutexLocker lock(m_mutex); | 110 MutexLocker lock(m_mutex); |
| 111 DecoderCacheMap::iterator iter = m_decoderCacheMap.find(DecoderCacheEntr
y::makeCacheKey(generator, decoder)); | 111 DecoderCacheMap::iterator iter = m_decoderCacheMap.find(DecoderCacheEntr
y::makeCacheKey(generator, decoder)); |
| 112 ASSERT_WITH_SECURITY_IMPLICATION(iter != m_decoderCacheMap.end()); | 112 ASSERT_WITH_SECURITY_IMPLICATION(iter != m_decoderCacheMap.end()); |
| 113 | 113 |
| 114 CacheEntry* cacheEntry = iter->value.get(); | 114 CacheEntry* cacheEntry = iter->value.get(); |
| 115 ASSERT(cacheEntry->useCount()); | 115 ASSERT(cacheEntry->useCount()); |
| 116 cacheEntry->decrementUseCount(); | 116 cacheEntry->decrementUseCount(); |
| 117 | 117 |
| 118 // Delete only one decoder cache entry. Ownership of the cache entry | 118 // Delete only one decoder cache entry. Ownership of the cache entry |
| 119 // is transfered to cacheEntriesToDelete such that object can be deleted | 119 // is transfered to cacheEntriesToDelete such that object can be deleted |
| 120 // outside of the lock. | 120 // outside of the lock. |
| 121 removeFromCacheInternal(cacheEntry, &cacheEntriesToDelete); | 121 removeFromCacheInternal(cacheEntry, &cacheEntriesToDelete); |
| 122 | 122 |
| 123 // Remove from LRU list. | 123 // Remove from LRU list. |
| 124 removeFromCacheListInternal(cacheEntriesToDelete); | 124 removeFromCacheListInternal(cacheEntriesToDelete); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 void ImageDecodingStore::removeCacheIndexedByGenerator(const ImageFrameGenerator
* generator) | 128 void ImageDecodingStore::removeCacheIndexedByGenerator(const ImageFrameGenerator
* generator) |
| 129 { | 129 { |
| 130 Vector<OwnPtr<CacheEntry> > cacheEntriesToDelete; | 130 Vector<OwnPtr<CacheEntry>> cacheEntriesToDelete; |
| 131 { | 131 { |
| 132 MutexLocker lock(m_mutex); | 132 MutexLocker lock(m_mutex); |
| 133 | 133 |
| 134 // Remove image cache objects and decoder cache objects associated | 134 // Remove image cache objects and decoder cache objects associated |
| 135 // with a ImageFrameGenerator. | 135 // with a ImageFrameGenerator. |
| 136 removeCacheIndexedByGeneratorInternal(&m_decoderCacheMap, &m_decoderCach
eKeyMap, generator, &cacheEntriesToDelete); | 136 removeCacheIndexedByGeneratorInternal(&m_decoderCacheMap, &m_decoderCach
eKeyMap, generator, &cacheEntriesToDelete); |
| 137 | 137 |
| 138 // Remove from LRU list as well. | 138 // Remove from LRU list as well. |
| 139 removeFromCacheListInternal(cacheEntriesToDelete); | 139 removeFromCacheListInternal(cacheEntriesToDelete); |
| 140 } | 140 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 int ImageDecodingStore::decoderCacheEntries() | 181 int ImageDecodingStore::decoderCacheEntries() |
| 182 { | 182 { |
| 183 MutexLocker lock(m_mutex); | 183 MutexLocker lock(m_mutex); |
| 184 return m_decoderCacheMap.size(); | 184 return m_decoderCacheMap.size(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void ImageDecodingStore::prune() | 187 void ImageDecodingStore::prune() |
| 188 { | 188 { |
| 189 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("blink.image_decoding"), "ImageDecodi
ngStore::prune"); | 189 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("blink.image_decoding"), "ImageDecodi
ngStore::prune"); |
| 190 | 190 |
| 191 Vector<OwnPtr<CacheEntry> > cacheEntriesToDelete; | 191 Vector<OwnPtr<CacheEntry>> cacheEntriesToDelete; |
| 192 { | 192 { |
| 193 MutexLocker lock(m_mutex); | 193 MutexLocker lock(m_mutex); |
| 194 | 194 |
| 195 // Head of the list is the least recently used entry. | 195 // Head of the list is the least recently used entry. |
| 196 const CacheEntry* cacheEntry = m_orderedCacheList.head(); | 196 const CacheEntry* cacheEntry = m_orderedCacheList.head(); |
| 197 | 197 |
| 198 // Walk the list of cache entries starting from the least recently used | 198 // Walk the list of cache entries starting from the least recently used |
| 199 // and then keep them for deletion later. | 199 // and then keep them for deletion later. |
| 200 while (cacheEntry) { | 200 while (cacheEntry) { |
| 201 const bool isPruneNeeded = m_heapMemoryUsageInBytes > m_heapLimitInB
ytes || !m_heapLimitInBytes; | 201 const bool isPruneNeeded = m_heapMemoryUsageInBytes > m_heapLimitInB
ytes || !m_heapLimitInBytes; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 226 typename U::KeyType key = cacheEntry->cacheKey(); | 226 typename U::KeyType key = cacheEntry->cacheKey(); |
| 227 typename V::AddResult result = identifierMap->add(cacheEntry->generator(), t
ypename V::MappedType()); | 227 typename V::AddResult result = identifierMap->add(cacheEntry->generator(), t
ypename V::MappedType()); |
| 228 result.storedValue->value.add(key); | 228 result.storedValue->value.add(key); |
| 229 cacheMap->add(key, cacheEntry); | 229 cacheMap->add(key, cacheEntry); |
| 230 | 230 |
| 231 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.image_decoding"), "ImageDeco
dingStoreHeapMemoryUsageBytes", m_heapMemoryUsageInBytes); | 231 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.image_decoding"), "ImageDeco
dingStoreHeapMemoryUsageBytes", m_heapMemoryUsageInBytes); |
| 232 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.image_decoding"), "ImageDeco
dingStoreNumOfDecoders", m_decoderCacheMap.size()); | 232 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.image_decoding"), "ImageDeco
dingStoreNumOfDecoders", m_decoderCacheMap.size()); |
| 233 } | 233 } |
| 234 | 234 |
| 235 template<class T, class U, class V> | 235 template<class T, class U, class V> |
| 236 void ImageDecodingStore::removeFromCacheInternal(const T* cacheEntry, U* cacheMa
p, V* identifierMap, Vector<OwnPtr<CacheEntry> >* deletionList) | 236 void ImageDecodingStore::removeFromCacheInternal(const T* cacheEntry, U* cacheMa
p, V* identifierMap, Vector<OwnPtr<CacheEntry>>* deletionList) |
| 237 { | 237 { |
| 238 const size_t cacheEntryBytes = cacheEntry->memoryUsageInBytes(); | 238 const size_t cacheEntryBytes = cacheEntry->memoryUsageInBytes(); |
| 239 ASSERT(m_heapMemoryUsageInBytes >= cacheEntryBytes); | 239 ASSERT(m_heapMemoryUsageInBytes >= cacheEntryBytes); |
| 240 m_heapMemoryUsageInBytes -= cacheEntryBytes; | 240 m_heapMemoryUsageInBytes -= cacheEntryBytes; |
| 241 | 241 |
| 242 // Remove entry from identifier map. | 242 // Remove entry from identifier map. |
| 243 typename V::iterator iter = identifierMap->find(cacheEntry->generator()); | 243 typename V::iterator iter = identifierMap->find(cacheEntry->generator()); |
| 244 ASSERT(iter != identifierMap->end()); | 244 ASSERT(iter != identifierMap->end()); |
| 245 iter->value.remove(cacheEntry->cacheKey()); | 245 iter->value.remove(cacheEntry->cacheKey()); |
| 246 if (!iter->value.size()) | 246 if (!iter->value.size()) |
| 247 identifierMap->remove(iter); | 247 identifierMap->remove(iter); |
| 248 | 248 |
| 249 // Remove entry from cache map. | 249 // Remove entry from cache map. |
| 250 deletionList->append(cacheMap->take(cacheEntry->cacheKey())); | 250 deletionList->append(cacheMap->take(cacheEntry->cacheKey())); |
| 251 | 251 |
| 252 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.image_decoding"), "ImageDeco
dingStoreHeapMemoryUsageBytes", m_heapMemoryUsageInBytes); | 252 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.image_decoding"), "ImageDeco
dingStoreHeapMemoryUsageBytes", m_heapMemoryUsageInBytes); |
| 253 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.image_decoding"), "ImageDeco
dingStoreNumOfDecoders", m_decoderCacheMap.size()); | 253 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.image_decoding"), "ImageDeco
dingStoreNumOfDecoders", m_decoderCacheMap.size()); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void ImageDecodingStore::removeFromCacheInternal(const CacheEntry* cacheEntry, V
ector<OwnPtr<CacheEntry> >* deletionList) | 256 void ImageDecodingStore::removeFromCacheInternal(const CacheEntry* cacheEntry, V
ector<OwnPtr<CacheEntry>>* deletionList) |
| 257 { | 257 { |
| 258 if (cacheEntry->type() == CacheEntry::TypeDecoder) { | 258 if (cacheEntry->type() == CacheEntry::TypeDecoder) { |
| 259 removeFromCacheInternal(static_cast<const DecoderCacheEntry*>(cacheEntry
), &m_decoderCacheMap, &m_decoderCacheKeyMap, deletionList); | 259 removeFromCacheInternal(static_cast<const DecoderCacheEntry*>(cacheEntry
), &m_decoderCacheMap, &m_decoderCacheKeyMap, deletionList); |
| 260 } else { | 260 } else { |
| 261 ASSERT(false); | 261 ASSERT(false); |
| 262 } | 262 } |
| 263 } | 263 } |
| 264 | 264 |
| 265 template<class U, class V> | 265 template<class U, class V> |
| 266 void ImageDecodingStore::removeCacheIndexedByGeneratorInternal(U* cacheMap, V* i
dentifierMap, const ImageFrameGenerator* generator, Vector<OwnPtr<CacheEntry> >*
deletionList) | 266 void ImageDecodingStore::removeCacheIndexedByGeneratorInternal(U* cacheMap, V* i
dentifierMap, const ImageFrameGenerator* generator, Vector<OwnPtr<CacheEntry>>*
deletionList) |
| 267 { | 267 { |
| 268 typename V::iterator iter = identifierMap->find(generator); | 268 typename V::iterator iter = identifierMap->find(generator); |
| 269 if (iter == identifierMap->end()) | 269 if (iter == identifierMap->end()) |
| 270 return; | 270 return; |
| 271 | 271 |
| 272 // Get all cache identifiers associated with generator. | 272 // Get all cache identifiers associated with generator. |
| 273 Vector<typename U::KeyType> cacheIdentifierList; | 273 Vector<typename U::KeyType> cacheIdentifierList; |
| 274 copyToVector(iter->value, cacheIdentifierList); | 274 copyToVector(iter->value, cacheIdentifierList); |
| 275 | 275 |
| 276 // For each cache identifier find the corresponding CacheEntry and remove it
. | 276 // For each cache identifier find the corresponding CacheEntry and remove it
. |
| 277 for (size_t i = 0; i < cacheIdentifierList.size(); ++i) { | 277 for (size_t i = 0; i < cacheIdentifierList.size(); ++i) { |
| 278 ASSERT(cacheMap->contains(cacheIdentifierList[i])); | 278 ASSERT(cacheMap->contains(cacheIdentifierList[i])); |
| 279 const typename U::MappedType::PtrType cacheEntry = cacheMap->get(cacheId
entifierList[i]); | 279 const typename U::MappedType::PtrType cacheEntry = cacheMap->get(cacheId
entifierList[i]); |
| 280 ASSERT(!cacheEntry->useCount()); | 280 ASSERT(!cacheEntry->useCount()); |
| 281 removeFromCacheInternal(cacheEntry, cacheMap, identifierMap, deletionLis
t); | 281 removeFromCacheInternal(cacheEntry, cacheMap, identifierMap, deletionLis
t); |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 | 284 |
| 285 void ImageDecodingStore::removeFromCacheListInternal(const Vector<OwnPtr<CacheEn
try> >& deletionList) | 285 void ImageDecodingStore::removeFromCacheListInternal(const Vector<OwnPtr<CacheEn
try>>& deletionList) |
| 286 { | 286 { |
| 287 for (size_t i = 0; i < deletionList.size(); ++i) | 287 for (size_t i = 0; i < deletionList.size(); ++i) |
| 288 m_orderedCacheList.remove(deletionList[i].get()); | 288 m_orderedCacheList.remove(deletionList[i].get()); |
| 289 } | 289 } |
| 290 | 290 |
| 291 } // namespace blink | 291 } // namespace blink |
| OLD | NEW |