From 680fb9e8f10d24b5fe35c90338de37c57392f1aa Mon Sep 17 00:00:00 2001 From: reed Date: Tue, 26 Aug 2014 09:08:04 -0700 Subject: retool image cache to be generic cache, allowing the client to subclass "Rec", so they can provide a custom Key and arbitrary Value. Follow-on CLs - rename ScaledimageCache to something like GeneralCache - explore if we can use call-backs or some mechanism to completely hide "lock/unlock", by forcing all clients to support "copying" their value out of the cache as the result of a Find. R=mtklein@google.com, senorblanco@google.com, bsalomon@google.com, qiankun.miao@intel.com, senorblanco@chromium.org Author: reed@google.com Review URL: https://codereview.chromium.org/507483002 --- bench/ImageCacheBench.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'bench/ImageCacheBench.cpp') diff --git a/bench/ImageCacheBench.cpp b/bench/ImageCacheBench.cpp index 07f332baa2..f4d88da042 100644 --- a/bench/ImageCacheBench.cpp +++ b/bench/ImageCacheBench.cpp @@ -19,6 +19,15 @@ public: this->init(sizeof(fPtr) + sizeof(fValue)); } }; +struct TestRec : public SkScaledImageCache::Rec { + TestKey fKey; + intptr_t fValue; + + TestRec(const TestKey& key, intptr_t value) : fKey(key), fValue(value) {} + + virtual const Key& getKey() const SK_OVERRIDE { return fKey; } + virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + sizeof(fValue); } +}; } class ImageCacheBench : public Benchmark { @@ -36,10 +45,7 @@ public: void populateCache() { for (int i = 0; i < CACHE_COUNT; ++i) { - TestKey key(i); - SkBitmap tmp; - tmp.allocN32Pixels(1, 1); - fCache.unlock(fCache.addAndLock(key, tmp)); + fCache.unlock(fCache.addAndLock(SkNEW_ARGS(TestRec, (TestKey(i), i)))); } } @@ -54,10 +60,9 @@ protected: } TestKey key(-1); - SkBitmap tmp; - // search for a miss (-1 scale) + // search for a miss (-1) for (int i = 0; i < loops; ++i) { - SkDEBUGCODE(SkScaledImageCache::ID* id =) fCache.findAndLock(key, &tmp); + SkDEBUGCODE(SkScaledImageCache::ID id =) fCache.findAndLock(key); SkASSERT(NULL == id); } } -- cgit v1.2.3