Index: src/lazy/SkDiscardablePixelRef.cpp |
diff --git a/src/lazy/SkDiscardablePixelRef.cpp b/src/lazy/SkDiscardablePixelRef.cpp |
index e614db37e98589678919002432f1d9feb687f6d5..e9e2d8a3ee257f1a59e22c86049a23ac3ff326d5 100644 |
--- a/src/lazy/SkDiscardablePixelRef.cpp |
+++ b/src/lazy/SkDiscardablePixelRef.cpp |
@@ -10,17 +10,15 @@ |
SkDiscardablePixelRef::SkDiscardablePixelRef(SkImageGenerator* generator, |
const SkImageInfo& info, |
- size_t size, |
size_t rowBytes, |
SkDiscardableMemory::Factory* fact) |
- : fGenerator(generator) |
+ : INHERITED(info) |
+ , fGenerator(generator) |
, fDMFactory(fact) |
- , fInfo(info) |
- , fSize(size) |
, fRowBytes(rowBytes) |
- , fDiscardableMemory(NULL) { |
+ , fDiscardableMemory(NULL) |
+{ |
SkASSERT(fGenerator != NULL); |
- SkASSERT(fSize > 0); |
SkASSERT(fRowBytes > 0); |
// The SkImageGenerator contract requires fGenerator to always |
// decode the same image on each call to getPixels(). |
@@ -34,28 +32,39 @@ SkDiscardablePixelRef::~SkDiscardablePixelRef() { |
SkDELETE(fGenerator); |
} |
-void* SkDiscardablePixelRef::onLockPixels(SkColorTable**) { |
+bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) { |
if (fDiscardableMemory != NULL) { |
if (fDiscardableMemory->lock()) { |
- return fDiscardableMemory->data(); |
+ rec->fPixels = fDiscardableMemory->data(); |
+ rec->fColorTable = NULL; |
+ rec->fRowBytes = fRowBytes; |
+ return true; |
} |
SkDELETE(fDiscardableMemory); |
fDiscardableMemory = NULL; |
} |
+ |
+ const size_t size = this->info().getSafeSize(fRowBytes); |
if (fDMFactory != NULL) { |
- fDiscardableMemory = fDMFactory->create(fSize); |
+ fDiscardableMemory = fDMFactory->create(size); |
} else { |
- fDiscardableMemory = SkDiscardableMemory::Create(fSize); |
+ fDiscardableMemory = SkDiscardableMemory::Create(size); |
} |
if (NULL == fDiscardableMemory) { |
- return NULL; // Memory allocation failed. |
+ return false; // Memory allocation failed. |
} |
+ |
void* pixels = fDiscardableMemory->data(); |
- if (!fGenerator->getPixels(fInfo, pixels, fRowBytes)) { |
- return NULL; // TODO(halcanary) Find out correct thing to do. |
+ if (!fGenerator->getPixels(this->info(), pixels, fRowBytes)) { |
+ return false; // TODO(halcanary) Find out correct thing to do. |
} |
- return pixels; |
+ |
+ rec->fPixels = pixels; |
+ rec->fColorTable = NULL; |
+ rec->fRowBytes = fRowBytes; |
+ return true; |
} |
+ |
void SkDiscardablePixelRef::onUnlockPixels() { |
if (fDiscardableMemory != NULL) { |
fDiscardableMemory->unlock(); |
@@ -76,7 +85,6 @@ bool SkDiscardablePixelRef::Install(SkImageGenerator* generator, |
} |
SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef, |
(generator, info, |
- dst->getSize(), |
dst->rowBytes(), |
factory))); |
dst->setPixelRef(ref); |