Index: src/core/SkResourceCache.cpp |
diff --git a/src/core/SkResourceCache.cpp b/src/core/SkResourceCache.cpp |
index 240d1977e53968d417de449d84ff42c8e34f405e..6d8e1662d964ecb33099c78865d6e2e49d08e92a 100644 |
--- a/src/core/SkResourceCache.cpp |
+++ b/src/core/SkResourceCache.cpp |
@@ -79,7 +79,9 @@ class SkOneShotDiscardablePixelRef : public SkPixelRef { |
public: |
// Ownership of the discardablememory is transfered to the pixelref |
- SkOneShotDiscardablePixelRef(const SkImageInfo&, SkDiscardableMemory*, size_t rowBytes); |
+ // The pixelref will ref() the colortable (if not NULL), and unref() in destructor |
+ SkOneShotDiscardablePixelRef(const SkImageInfo&, SkDiscardableMemory*, size_t rowBytes, |
+ SkColorTable*); |
~SkOneShotDiscardablePixelRef(); |
protected: |
@@ -93,22 +95,29 @@ private: |
SkDiscardableMemory* fDM; |
size_t fRB; |
bool fFirstTime; |
+ SkColorTable* fCTable; |
typedef SkPixelRef INHERITED; |
}; |
SkOneShotDiscardablePixelRef::SkOneShotDiscardablePixelRef(const SkImageInfo& info, |
SkDiscardableMemory* dm, |
- size_t rowBytes) |
+ size_t rowBytes, |
+ SkColorTable* ctable) |
: INHERITED(info) |
, fDM(dm) |
, fRB(rowBytes) |
+ , fCTable(ctable) |
{ |
SkASSERT(dm->data()); |
fFirstTime = true; |
+ SkSafeRef(ctable); |
} |
-SkOneShotDiscardablePixelRef::~SkOneShotDiscardablePixelRef() { delete fDM; } |
+SkOneShotDiscardablePixelRef::~SkOneShotDiscardablePixelRef() { |
+ delete fDM; |
+ SkSafeUnref(fCTable); |
+} |
bool SkOneShotDiscardablePixelRef::onNewLockPixels(LockRec* rec) { |
if (fFirstTime) { |
@@ -132,7 +141,7 @@ bool SkOneShotDiscardablePixelRef::onNewLockPixels(LockRec* rec) { |
SUCCESS: |
rec->fPixels = fDM->data(); |
- rec->fColorTable = nullptr; |
+ rec->fColorTable = fCTable; |
rec->fRowBytes = fRB; |
return true; |
} |
@@ -166,18 +175,22 @@ bool SkResourceCacheDiscardableAllocator::allocPixelRef(SkBitmap* bitmap, SkColo |
return false; |
} |
- SkDiscardableMemory* dm = fFactory(size); |
- if (nullptr == dm) { |
- return false; |
+ if (kIndex_8_SkColorType == bitmap->colorType()) { |
+ if (!ctable) { |
+ return false; |
+ } |
+ } else { |
+ ctable = nullptr; |
} |
- // can we relax this? |
- if (kN32_SkColorType != bitmap->colorType()) { |
+ SkDiscardableMemory* dm = fFactory(size); |
+ if (nullptr == dm) { |
return false; |
} |
SkImageInfo info = bitmap->info(); |
- bitmap->setPixelRef(new SkOneShotDiscardablePixelRef(info, dm, bitmap->rowBytes()))->unref(); |
+ bitmap->setPixelRef(new SkOneShotDiscardablePixelRef(info, dm, bitmap->rowBytes(), |
+ ctable))->unref(); |
bitmap->lockPixels(); |
return bitmap->readyToDraw(); |
} |