aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/lazy
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-03-04 19:56:21 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-03-04 19:56:21 +0000
commitcc690201d2538a7ec2dbec7040064c8d3c42c613 (patch)
tree6d6e3522202b6f993498bb2254ad1d669ef14aae /src/lazy
parent46348e21732e64e1a4dcfb5d859e6edafba471ff (diff)
Add a way to monitor cache hits and misses for deferred decoding.
Adds a new flag to bench_pictures in order to do this. Also fix a warning. Review URL: https://codereview.chromium.org/12393046 git-svn-id: http://skia.googlecode.com/svn/trunk@7965 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/lazy')
-rw-r--r--src/lazy/SkLazyPixelRef.cpp68
-rw-r--r--src/lazy/SkLazyPixelRef.h17
2 files changed, 60 insertions, 25 deletions
diff --git a/src/lazy/SkLazyPixelRef.cpp b/src/lazy/SkLazyPixelRef.cpp
index c262884561..a20b3c028d 100644
--- a/src/lazy/SkLazyPixelRef.cpp
+++ b/src/lazy/SkLazyPixelRef.cpp
@@ -12,6 +12,13 @@
#include "SkImageCache.h"
#include "SkImagePriv.h"
+#if LAZY_CACHE_STATS
+#include "SkThread.h"
+
+int32_t SkLazyPixelRef::gCacheHits;
+int32_t SkLazyPixelRef::gCacheMisses;
+#endif
+
SkLazyPixelRef::SkLazyPixelRef(SkData* data, SkBitmapFactory::DecodeProc proc, SkImageCache* cache)
// Pass NULL for the Mutex so that the default (ring buffer) will be used.
: INHERITED(NULL)
@@ -61,33 +68,44 @@ void* SkLazyPixelRef::onLockPixels(SkColorTable**) {
}
SkBitmapFactory::Target target;
// Check to see if the pixels still exist in the cache.
- target.fAddr = SkImageCache::UNINITIALIZED_ID == fCacheId ?
- NULL : fImageCache->pinCache(fCacheId);
- if (NULL == target.fAddr) {
- SkImage::Info info;
- SkASSERT(fData != NULL && fData->size() > 0);
- // FIXME: As an optimization, only do this part once.
- fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, NULL);
- if (fErrorInDecoding) {
- fCacheId = SkImageCache::UNINITIALIZED_ID;
- return NULL;
+ if (SkImageCache::UNINITIALIZED_ID == fCacheId) {
+ target.fAddr = NULL;
+ } else {
+ target.fAddr = fImageCache->pinCache(fCacheId);
+ if (NULL != target.fAddr) {
+#if LAZY_CACHE_STATS
+ sk_atomic_inc(&gCacheHits);
+#endif
+ return target.fAddr;
}
- // Allocate the memory.
- size_t bytes = ComputeMinRowBytesAndSize(info, &target.fRowBytes);
+#if LAZY_CACHE_STATS
+ sk_atomic_inc(&gCacheMisses);
+#endif
+ }
+ SkASSERT(NULL == target.fAddr);
+ SkImage::Info info;
+ SkASSERT(fData != NULL && fData->size() > 0);
+ // FIXME: As an optimization, only do this part once.
+ fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, NULL);
+ if (fErrorInDecoding) {
+ fCacheId = SkImageCache::UNINITIALIZED_ID;
+ return NULL;
+ }
+ // Allocate the memory.
+ size_t bytes = ComputeMinRowBytesAndSize(info, &target.fRowBytes);
- target.fAddr = fImageCache->allocAndPinCache(bytes, &fCacheId);
- if (NULL == target.fAddr) {
- // Space could not be allocated.
- fCacheId = SkImageCache::UNINITIALIZED_ID;
- return NULL;
- }
- SkASSERT(SkImageCache::UNINITIALIZED_ID != fCacheId);
- fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, &target);
- if (fErrorInDecoding) {
- fImageCache->throwAwayCache(fCacheId);
- fCacheId = SkImageCache::UNINITIALIZED_ID;
- return NULL;
- }
+ target.fAddr = fImageCache->allocAndPinCache(bytes, &fCacheId);
+ if (NULL == target.fAddr) {
+ // Space could not be allocated.
+ fCacheId = SkImageCache::UNINITIALIZED_ID;
+ return NULL;
+ }
+ SkASSERT(SkImageCache::UNINITIALIZED_ID != fCacheId);
+ fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, &target);
+ if (fErrorInDecoding) {
+ fImageCache->throwAwayCache(fCacheId);
+ fCacheId = SkImageCache::UNINITIALIZED_ID;
+ return NULL;
}
return target.fAddr;
}
diff --git a/src/lazy/SkLazyPixelRef.h b/src/lazy/SkLazyPixelRef.h
index e5a20bd91a..af85f90552 100644
--- a/src/lazy/SkLazyPixelRef.h
+++ b/src/lazy/SkLazyPixelRef.h
@@ -17,6 +17,12 @@ class SkColorTable;
class SkData;
class SkImageCache;
+#ifdef SK_DEBUG
+ #define LAZY_CACHE_STATS 1
+#elif !defined(LAZY_CACHE_STATS)
+ #define LAZY_CACHE_STATS 0
+#endif
+
/**
* PixelRef which defers decoding until SkBitmap::lockPixels() is called.
*/
@@ -38,6 +44,12 @@ public:
intptr_t getCacheId() const { return fCacheId; }
#endif
+#if LAZY_CACHE_STATS
+ static int32_t GetCacheHits() { return gCacheHits; }
+ static int32_t GetCacheMisses() { return gCacheMisses; }
+ static void ResetCacheStats() { gCacheHits = gCacheMisses = 0; }
+#endif
+
// No need to flatten this object. When flattening an SkBitmap, SkOrderedWriteBuffer will check
// the encoded data and write that instead.
// Future implementations of SkFlattenableWriteBuffer will need to special case for
@@ -57,6 +69,11 @@ private:
SkImageCache* fImageCache;
intptr_t fCacheId;
+#if LAZY_CACHE_STATS
+ static int32_t gCacheHits;
+ static int32_t gCacheMisses;
+#endif
+
typedef SkPixelRef INHERITED;
};