| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkLruImageCache.h" | 8 #include "SkLruImageCache.h" |
| 9 | 9 |
| 10 static intptr_t NextGenerationID() { | 10 static intptr_t NextGenerationID() { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 if (pixels->getID() == ID) { | 161 if (pixels->getID() == ID) { |
| 162 return pixels; | 162 return pixels; |
| 163 } | 163 } |
| 164 pixels = iter.next(); | 164 pixels = iter.next(); |
| 165 } | 165 } |
| 166 return NULL; | 166 return NULL; |
| 167 } | 167 } |
| 168 | 168 |
| 169 void SkLruImageCache::purgeIfNeeded() { | 169 void SkLruImageCache::purgeIfNeeded() { |
| 170 // Mutex is already locked. | 170 // Mutex is already locked. |
| 171 this->purgeTilAtOrBelow(fRamBudget); | 171 if (fRamBudget > 0) { |
| 172 this->purgeTilAtOrBelow(fRamBudget); |
| 173 } |
| 172 } | 174 } |
| 173 | 175 |
| 174 void SkLruImageCache::purgeTilAtOrBelow(size_t limit) { | 176 void SkLruImageCache::purgeTilAtOrBelow(size_t limit) { |
| 175 // Mutex is already locked. | 177 // Mutex is already locked. |
| 176 if (fRamUsed > limit) { | 178 if (fRamUsed > limit) { |
| 177 Iter iter; | 179 Iter iter; |
| 178 // Start from the tail, least recently used. | 180 // Start from the tail, least recently used. |
| 179 CachedPixels* pixels = iter.init(fLRU, Iter::kTail_IterStart); | 181 CachedPixels* pixels = iter.init(fLRU, Iter::kTail_IterStart); |
| 180 while (pixels != NULL && fRamUsed > limit) { | 182 while (pixels != NULL && fRamUsed > limit) { |
| 181 CachedPixels* prev = iter.prev(); | 183 CachedPixels* prev = iter.prev(); |
| 182 if (!pixels->isLocked()) { | 184 if (!pixels->isLocked()) { |
| 183 this->removePixels(pixels); | 185 this->removePixels(pixels); |
| 184 } | 186 } |
| 185 pixels = prev; | 187 pixels = prev; |
| 186 } | 188 } |
| 187 } | 189 } |
| 188 } | 190 } |
| OLD | NEW |