diff options
author | reed <reed@google.com> | 2014-08-26 09:08:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-26 09:08:04 -0700 |
commit | 680fb9e8f10d24b5fe35c90338de37c57392f1aa (patch) | |
tree | f973f7d37ccd4deb5a23eb57c8b0a0b7e514ad3f /bench | |
parent | 97b49478cfbcdb9cac6de2ab0d44f975311ef631 (diff) |
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
Diffstat (limited to 'bench')
-rw-r--r-- | bench/ImageCacheBench.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
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); } } |