diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkBitmapProcState.cpp | 47 | ||||
-rw-r--r-- | src/core/SkPixelRef.cpp | 8 | ||||
-rw-r--r-- | src/lazy/SkDiscardablePixelRef.cpp | 11 | ||||
-rw-r--r-- | src/lazy/SkDiscardablePixelRef.h | 1 |
4 files changed, 19 insertions, 48 deletions
diff --git a/src/core/SkBitmapProcState.cpp b/src/core/SkBitmapProcState.cpp index 81c14a2ffd..335924fc35 100644 --- a/src/core/SkBitmapProcState.cpp +++ b/src/core/SkBitmapProcState.cpp @@ -241,43 +241,12 @@ void SkBitmapProcState::processMediumRequest() { } } -static bool get_locked_pixels(const SkBitmap& src, int pow2, SkBitmap* dst) { - SkPixelRef* pr = src.pixelRef(); - if (pr && pr->decodeInto(pow2, dst)) { - return true; - } - - /* - * If decodeInto() fails, it is possibe that we have an old subclass that - * does not, or cannot, implement that. In that case we fall back to the - * older protocol of having the pixelRef handle the caching for us. - */ - *dst = src; - dst->lockPixels(); - return SkToBool(dst->getPixels()); -} - bool SkBitmapProcState::lockBaseBitmap() { - SkPixelRef* pr = fOrigBitmap.pixelRef(); - - if (pr->isLocked() || !pr->implementsDecodeInto()) { - // fast-case, no need to look in our cache - fScaledBitmap = fOrigBitmap; - fScaledBitmap.lockPixels(); - if (NULL == fScaledBitmap.getPixels()) { - return false; - } - } else { - if (!SkBitmapCache::Find(fOrigBitmap, 1, 1, &fScaledBitmap)) { - if (!get_locked_pixels(fOrigBitmap, 0, &fScaledBitmap)) { - return false; - } - - // TODO: if fScaled comes back at a different width/height than fOrig, - // we need to update the matrix we are using to sample from this guy. - - SkBitmapCache::Add(fOrigBitmap, 1, 1, fScaledBitmap); - } + // TODO(reed): use bitmap cache here? + fScaledBitmap = fOrigBitmap; + fScaledBitmap.lockPixels(); + if (NULL == fScaledBitmap.getPixels()) { + return false; } fBitmap = &fScaledBitmap; return true; @@ -387,7 +356,7 @@ bool SkBitmapProcState::chooseProcs(const SkMatrix& inv, const SkPaint& paint) { fShaderProc16 = NULL; fSampleProc32 = NULL; fSampleProc16 = NULL; - + // recompute the triviality of the matrix here because we may have // changed it! @@ -561,10 +530,10 @@ bool SkBitmapProcState::chooseScanlineProcs(bool trivialMatrix, bool clampClamp, fShaderProc32 = this->chooseShaderProc32(); } } - + // see if our platform has any accelerated overrides this->platformProcs(); - + return true; } diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp index f56298165c..c73c2f4b7d 100644 --- a/src/core/SkPixelRef.cpp +++ b/src/core/SkPixelRef.cpp @@ -197,14 +197,6 @@ bool SkPixelRef::onLockPixelsAreWritable() const { return true; } -bool SkPixelRef::onImplementsDecodeInto() { - return false; -} - -bool SkPixelRef::onDecodeInto(int pow2, SkBitmap* bitmap) { - return false; -} - uint32_t SkPixelRef::getGenerationID() const { if (0 == fGenerationID) { fGenerationID = SkNextPixelRefGenerationID(); diff --git a/src/lazy/SkDiscardablePixelRef.cpp b/src/lazy/SkDiscardablePixelRef.cpp index 50988587a7..b6dec1b3a1 100644 --- a/src/lazy/SkDiscardablePixelRef.cpp +++ b/src/lazy/SkDiscardablePixelRef.cpp @@ -18,6 +18,7 @@ SkDiscardablePixelRef::SkDiscardablePixelRef(const SkImageInfo& info, , fDMFactory(fact) , fRowBytes(rowBytes) , fDiscardableMemory(NULL) + , fDiscardableMemoryIsLocked(false) { SkASSERT(fGenerator != NULL); SkASSERT(fRowBytes > 0); @@ -28,8 +29,9 @@ SkDiscardablePixelRef::SkDiscardablePixelRef(const SkImageInfo& info, } SkDiscardablePixelRef::~SkDiscardablePixelRef() { - if (this->isLocked()) { + if (fDiscardableMemoryIsLocked) { fDiscardableMemory->unlock(); + fDiscardableMemoryIsLocked = false; } SkDELETE(fDiscardableMemory); SkSafeUnref(fDMFactory); @@ -39,6 +41,7 @@ SkDiscardablePixelRef::~SkDiscardablePixelRef() { bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) { if (fDiscardableMemory != NULL) { if (fDiscardableMemory->lock()) { + fDiscardableMemoryIsLocked = true; rec->fPixels = fDiscardableMemory->data(); rec->fColorTable = fCTable.get(); rec->fRowBytes = fRowBytes; @@ -46,16 +49,20 @@ bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) { } SkDELETE(fDiscardableMemory); fDiscardableMemory = NULL; + fDiscardableMemoryIsLocked = false; } const size_t size = this->info().getSafeSize(fRowBytes); if (fDMFactory != NULL) { fDiscardableMemory = fDMFactory->create(size); + fDiscardableMemoryIsLocked = true; } else { fDiscardableMemory = SkDiscardableMemory::Create(size); + fDiscardableMemoryIsLocked = true; } if (NULL == fDiscardableMemory) { + fDiscardableMemoryIsLocked = false; return false; // Memory allocation failed. } @@ -72,6 +79,7 @@ bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) { break; default: fDiscardableMemory->unlock(); + fDiscardableMemoryIsLocked = false; SkDELETE(fDiscardableMemory); fDiscardableMemory = NULL; return false; @@ -96,6 +104,7 @@ bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) { void SkDiscardablePixelRef::onUnlockPixels() { fDiscardableMemory->unlock(); + fDiscardableMemoryIsLocked = false; } bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst, diff --git a/src/lazy/SkDiscardablePixelRef.h b/src/lazy/SkDiscardablePixelRef.h index 448f0ab24b..38ff2c4703 100644 --- a/src/lazy/SkDiscardablePixelRef.h +++ b/src/lazy/SkDiscardablePixelRef.h @@ -41,6 +41,7 @@ private: // PixelRef, since the SkBitmap doesn't expect them to change. SkDiscardableMemory* fDiscardableMemory; + bool fDiscardableMemoryIsLocked; SkAutoTUnref<SkColorTable> fCTable; /* Takes ownership of SkImageGenerator. */ |