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

Unified Diff: src/lazy/SkLruImageCache.cpp

Issue 12433020: Improvements/additions to SkImageCache/SkLazyPixelRef. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Respond to comments. Created 7 years, 9 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
« no previous file with comments | « src/lazy/SkLazyPixelRef.cpp ('k') | src/lazy/SkPurgeableImageCache.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/lazy/SkLruImageCache.cpp
diff --git a/src/lazy/SkLruImageCache.cpp b/src/lazy/SkLruImageCache.cpp
index 54f26fb5dcbf8263e143b12ce9efe846b5f1da38..26f7ef54838bd8c61fd47178fe7a30eba895e371 100644
--- a/src/lazy/SkLruImageCache.cpp
+++ b/src/lazy/SkLruImageCache.cpp
@@ -74,16 +74,24 @@ SkLruImageCache::~SkLruImageCache() {
}
#ifdef SK_DEBUG
-SkImageCache::CacheStatus SkLruImageCache::getCacheStatus(intptr_t ID) const {
+SkImageCache::MemoryStatus SkLruImageCache::getMemoryStatus(intptr_t ID) const {
+ if (SkImageCache::UNINITIALIZED_ID == ID) {
+ return SkImageCache::kFreed_MemoryStatus;
+ }
SkAutoMutexAcquire ac(&fMutex);
CachedPixels* pixels = this->findByID(ID);
if (NULL == pixels) {
- return SkImageCache::kThrownAway_CacheStatus;
+ return SkImageCache::kFreed_MemoryStatus;
}
if (pixels->isLocked()) {
- return SkImageCache::kPinned_CacheStatus;
+ return SkImageCache::kPinned_MemoryStatus;
}
- return SkImageCache::kUnpinned_CacheStatus;
+ return SkImageCache::kUnpinned_MemoryStatus;
+}
+
+void SkLruImageCache::purgeAllUnpinnedCaches() {
+ SkAutoMutexAcquire ac(&fMutex);
+ this->purgeTilAtOrBelow(0);
}
#endif
@@ -108,7 +116,7 @@ void* SkLruImageCache::allocAndPinCache(size_t bytes, intptr_t* ID) {
return pixels->getData();
}
-void* SkLruImageCache::pinCache(intptr_t ID) {
+void* SkLruImageCache::pinCache(intptr_t ID, SkImageCache::DataStatus* status) {
SkASSERT(ID != SkImageCache::UNINITIALIZED_ID);
SkAutoMutexAcquire ac(&fMutex);
CachedPixels* pixels = this->findByID(ID);
@@ -119,6 +127,9 @@ void* SkLruImageCache::pinCache(intptr_t ID) {
fLRU.remove(pixels);
fLRU.addToHead(pixels);
}
+ SkASSERT(status != NULL);
+ // This cache will never return pinned memory whose data has been overwritten.
+ *status = SkImageCache::kRetained_DataStatus;
pixels->lock();
return pixels->getData();
}
@@ -133,6 +144,7 @@ void SkLruImageCache::releaseCache(intptr_t ID) {
}
void SkLruImageCache::throwAwayCache(intptr_t ID) {
+ SkASSERT(ID != SkImageCache::UNINITIALIZED_ID);
SkAutoMutexAcquire ac(&fMutex);
CachedPixels* pixels = this->findByID(ID);
if (pixels != NULL) {
@@ -155,9 +167,6 @@ void SkLruImageCache::removePixels(CachedPixels* pixels) {
CachedPixels* SkLruImageCache::findByID(intptr_t ID) const {
// Mutex is already locked.
- if (SkImageCache::UNINITIALIZED_ID == ID) {
- return NULL;
- }
Iter iter;
// Start from the head, most recently used.
CachedPixels* pixels = iter.init(fLRU, Iter::kHead_IterStart);
« no previous file with comments | « src/lazy/SkLazyPixelRef.cpp ('k') | src/lazy/SkPurgeableImageCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698