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

Unified Diff: src/core/SkResourceCache.cpp

Issue 1426753006: SkResourceCache::GetAllocator() index8 and other color types handling (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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 | « no previous file | tests/CachedDecodingPixelRefTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « no previous file | tests/CachedDecodingPixelRefTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698