aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/lazy
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-10-21 19:45:38 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-10-21 19:45:38 +0000
commite986b221ee4c6678180367a6c34ca781ed8b3152 (patch)
tree157e017439e0ffad69efa674bcba68e22e18430e /src/lazy
parent2590a91b643347ce39cc40bdb599537fcf433645 (diff)
Revert "cache SkImage::Info calculation in lazypixelref"
This reverts commit a2537480710aa10b9ab9f8aec98538b79539f47e. git-svn-id: http://skia.googlecode.com/svn/trunk@11894 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/lazy')
-rw-r--r--src/lazy/SkLazyPixelRef.cpp31
-rw-r--r--src/lazy/SkLazyPixelRef.h4
2 files changed, 10 insertions, 25 deletions
diff --git a/src/lazy/SkLazyPixelRef.cpp b/src/lazy/SkLazyPixelRef.cpp
index ad60892ad1..22d4b112f1 100644
--- a/src/lazy/SkLazyPixelRef.cpp
+++ b/src/lazy/SkLazyPixelRef.cpp
@@ -37,10 +37,6 @@ SkLazyPixelRef::SkLazyPixelRef(SkData* data, SkBitmapFactory::DecodeProc proc, S
}
SkASSERT(cache != NULL);
cache->ref();
-
- // mark as uninitialized -- all fields are -1
- memset(&fLazilyCachedInfo, 0xFF, sizeof(fLazilyCachedInfo));
-
// Since this pixel ref bases its data on encoded data, it should never change.
this->setImmutable();
}
@@ -67,18 +63,6 @@ static size_t ComputeMinRowBytesAndSize(const SkImage::Info& info, size_t* rowBy
return safeSize.is32() ? safeSize.get32() : 0;
}
-const SkImage::Info* SkLazyPixelRef::getCachedInfo() {
- if (fLazilyCachedInfo.fWidth < 0) {
- SkImage::Info info;
- fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, NULL);
- if (fErrorInDecoding) {
- return NULL;
- }
- fLazilyCachedInfo = info;
- }
- return &fLazilyCachedInfo;
-}
-
void* SkLazyPixelRef::onLockPixels(SkColorTable**) {
if (fErrorInDecoding) {
return NULL;
@@ -107,15 +91,20 @@ void* SkLazyPixelRef::onLockPixels(SkColorTable**) {
sk_atomic_inc(&gCacheMisses);
#endif
}
-
+ SkImage::Info info;
SkASSERT(fData != NULL && fData->size() > 0);
if (NULL == target.fAddr) {
- const SkImage::Info* info = this->getCachedInfo();
- if (NULL == info) {
+ // Determine the size of the image in order to determine how much memory to allocate.
+ // FIXME: As an optimization, only do this part once.
+ fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, NULL);
+ if (fErrorInDecoding) {
+ // We can only reach here if fCacheId was already set to UNINITIALIZED_ID, or if
+ // pinCache returned NULL, in which case it was reset to UNINITIALIZED_ID.
SkASSERT(SkImageCache::UNINITIALIZED_ID == fCacheId);
return NULL;
}
- size_t bytes = ComputeMinRowBytesAndSize(*info, &target.fRowBytes);
+
+ size_t bytes = ComputeMinRowBytesAndSize(info, &target.fRowBytes);
target.fAddr = fImageCache->allocAndPinCache(bytes, &fCacheId);
if (NULL == target.fAddr) {
// Space could not be allocated.
@@ -132,7 +121,7 @@ void* SkLazyPixelRef::onLockPixels(SkColorTable**) {
}
SkASSERT(target.fAddr != NULL);
SkASSERT(SkImageCache::UNINITIALIZED_ID != fCacheId);
- fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), NULL, &target);
+ fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, &target);
if (fErrorInDecoding) {
fImageCache->throwAwayCache(fCacheId);
fCacheId = SkImageCache::UNINITIALIZED_ID;
diff --git a/src/lazy/SkLazyPixelRef.h b/src/lazy/SkLazyPixelRef.h
index 8f7a751e95..c51675dd5f 100644
--- a/src/lazy/SkLazyPixelRef.h
+++ b/src/lazy/SkLazyPixelRef.h
@@ -71,16 +71,12 @@ private:
SkImageCache* fImageCache;
intptr_t fCacheId;
size_t fRowBytes;
- SkImage::Info fLazilyCachedInfo;
#if LAZY_CACHE_STATS
static int32_t gCacheHits;
static int32_t gCacheMisses;
#endif
- // lazily initialized our cached info. Returns NULL on failure.
- const SkImage::Info* getCachedInfo();
-
typedef SkPixelRef INHERITED;
};