aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/SkBitmapCache.cpp4
-rw-r--r--src/core/SkResourceCache.cpp59
-rw-r--r--src/core/SkResourceCache.h4
3 files changed, 45 insertions, 22 deletions
diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp
index c954a3099e..6d4f4b4cc7 100644
--- a/src/core/SkBitmapCache.cpp
+++ b/src/core/SkBitmapCache.cpp
@@ -71,8 +71,8 @@ static bool find_and_return(const BitmapKey& key, SkBitmap* result) {
if (result->getPixels()) {
return true;
}
- // todo: we should explicitly purge rec from the cache at this point, since
- // it is effectively purged already (has no memory behind it)
+
+ SkResourceCache::Remove(rec);
result->reset();
// fall-through to false
}
diff --git a/src/core/SkResourceCache.cpp b/src/core/SkResourceCache.cpp
index 73f788cd17..6400e8a71e 100644
--- a/src/core/SkResourceCache.cpp
+++ b/src/core/SkResourceCache.cpp
@@ -286,6 +286,23 @@ void SkResourceCache::unlock(SkResourceCache::ID id) {
}
}
+void SkResourceCache::remove(Rec* rec) {
+ SkASSERT(0 == rec->fLockCount);
+
+ size_t used = rec->bytesUsed();
+ SkASSERT(used <= fTotalBytesUsed);
+
+ this->detach(rec);
+#ifdef USE_HASH
+ fHash->remove(rec->getKey());
+#endif
+
+ SkDELETE(rec);
+
+ fTotalBytesUsed -= used;
+ fCount -= 1;
+}
+
void SkResourceCache::purgeAsNeeded() {
size_t byteLimit;
int countLimit;
@@ -298,34 +315,18 @@ void SkResourceCache::purgeAsNeeded() {
byteLimit = fTotalByteLimit;
}
- size_t bytesUsed = fTotalBytesUsed;
- int countUsed = fCount;
-
Rec* rec = fTail;
while (rec) {
- if (bytesUsed < byteLimit && countUsed < countLimit) {
+ if (fTotalBytesUsed < byteLimit && fCount < countLimit) {
break;
}
Rec* prev = rec->fPrev;
if (0 == rec->fLockCount) {
- size_t used = rec->bytesUsed();
- SkASSERT(used <= bytesUsed);
- this->detach(rec);
-#ifdef USE_HASH
- fHash->remove(rec->getKey());
-#endif
-
- SkDELETE(rec);
-
- bytesUsed -= used;
- countUsed -= 1;
+ this->remove(rec);
}
rec = prev;
}
-
- fTotalBytesUsed = bytesUsed;
- fCount = countUsed;
}
size_t SkResourceCache::setTotalByteLimit(size_t newLimit) {
@@ -506,6 +507,28 @@ void SkResourceCache::Unlock(SkResourceCache::ID id) {
// get_cache()->dump();
}
+void SkResourceCache::Remove(SkResourceCache::ID id) {
+ SkAutoMutexAcquire am(gMutex);
+ SkASSERT(id);
+
+#ifdef SK_DEBUG
+ {
+ bool found = false;
+ Rec* rec = get_cache()->fHead;
+ while (rec != NULL) {
+ if (rec == id) {
+ found = true;
+ break;
+ }
+ rec = rec->fNext;
+ }
+ SkASSERT(found);
+ }
+#endif
+ const Rec* rec = id;
+ get_cache()->remove(const_cast<Rec*>(rec));
+}
+
size_t SkResourceCache::GetTotalBytesUsed() {
SkAutoMutexAcquire am(gMutex);
return get_cache()->getTotalBytesUsed();
diff --git a/src/core/SkResourceCache.h b/src/core/SkResourceCache.h
index f2fd8fc047..93f2ca49e6 100644
--- a/src/core/SkResourceCache.h
+++ b/src/core/SkResourceCache.h
@@ -76,7 +76,6 @@ public:
Rec* fNext;
Rec* fPrev;
int32_t fLockCount;
- int32_t fPad;
friend class SkResourceCache;
};
@@ -98,6 +97,7 @@ public:
static const Rec* AddAndLock(Rec*);
static void Add(Rec*);
static void Unlock(ID);
+ static void Remove(ID);
static size_t GetTotalBytesUsed();
static size_t GetTotalByteLimit();
@@ -140,6 +140,7 @@ public:
const Rec* findAndLock(const Key& key);
const Rec* addAndLock(Rec*);
void add(Rec*);
+ void remove(Rec*);
/**
* Given a non-null ID ptr returned by either findAndLock or addAndLock,
@@ -189,7 +190,6 @@ private:
size_t fSingleAllocationByteLimit;
int fCount;
- void purgeRec(Rec*);
void purgeAsNeeded();
// linklist management