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

Unified Diff: src/core/SkScaledImageCache.cpp

Issue 110383005: detect if the scaledimagecache returns a purged bitmap (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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/core/SkScaledImageCache.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkScaledImageCache.cpp
diff --git a/src/core/SkScaledImageCache.cpp b/src/core/SkScaledImageCache.cpp
index b3956f4a8dbd43d225dccd159eab687e572bd63e..7c8b66498e342f84e26a9d9236ef98bfc10eff49 100644
--- a/src/core/SkScaledImageCache.cpp
+++ b/src/core/SkScaledImageCache.cpp
@@ -239,9 +239,18 @@ void* SkOneShotDiscardablePixelRef::onLockPixels(SkColorTable** ctable) {
return fDM->data();
}
- SkASSERT(!fIsLocked);
- fIsLocked = fDM->lock();
- return fIsLocked ? fDM->data() : NULL;
+ // A previous call to onUnlock may have deleted our DM, so check for that
+ if (NULL == fDM) {
+ return NULL;
+ }
+
+ if (!fDM->lock()) {
+ // since it failed, we delete it now, to free-up the resource
+ delete fDM;
+ fDM = NULL;
+ return NULL;
+ }
+ return fDM->data();
}
void SkOneShotDiscardablePixelRef::onUnlockPixels() {
@@ -613,6 +622,8 @@ void SkScaledImageCache::addToHead(Rec* rec) {
this->validate();
}
+///////////////////////////////////////////////////////////////////////////////
+
#ifdef SK_DEBUG
void SkScaledImageCache::validate() const {
if (NULL == fHead) {
@@ -658,6 +669,21 @@ void SkScaledImageCache::validate() const {
}
#endif
+void SkScaledImageCache::dump() const {
+ this->validate();
+
+ const Rec* rec = fHead;
+ int locked = 0;
+ while (rec) {
+ locked += rec->fLockCount > 0;
+ rec = rec->fNext;
+ }
+
+ SkDebugf("SkScaledImageCache: count=%d bytes=%d locked=%d %s\n",
+ fCount, fBytesUsed, locked,
+ fDiscardableFactory ? "discardable" : "malloc");
+}
+
///////////////////////////////////////////////////////////////////////////////
#include "SkThread.h"
@@ -730,7 +756,9 @@ SkScaledImageCache::ID* SkScaledImageCache::AddAndLockMip(const SkBitmap& orig,
void SkScaledImageCache::Unlock(SkScaledImageCache::ID* id) {
SkAutoMutexAcquire am(gMutex);
- return get_cache()->unlock(id);
+ get_cache()->unlock(id);
+
+// get_cache()->dump();
}
size_t SkScaledImageCache::GetBytesUsed() {
@@ -753,6 +781,11 @@ SkBitmap::Allocator* SkScaledImageCache::GetAllocator() {
return get_cache()->allocator();
}
+void SkScaledImageCache::Dump() {
+ SkAutoMutexAcquire am(gMutex);
+ get_cache()->dump();
+}
+
///////////////////////////////////////////////////////////////////////////////
#include "SkGraphics.h"
« no previous file with comments | « src/core/SkScaledImageCache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698