2013-07-23 19:13:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2013-07-23 19:13:54 +00:00
|
|
|
#include "SkScaledImageCache.h"
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class ImageCacheBench : public Benchmark {
|
2013-07-23 19:13:54 +00:00
|
|
|
SkScaledImageCache fCache;
|
|
|
|
SkBitmap fBM;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
DIM = 1,
|
|
|
|
CACHE_COUNT = 500
|
|
|
|
};
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
ImageCacheBench() : fCache(CACHE_COUNT * 100) {
|
2014-06-10 02:52:07 +00:00
|
|
|
fBM.allocN32Pixels(DIM, DIM);
|
2013-07-23 19:13:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void populateCache() {
|
|
|
|
SkScalar scale = 1;
|
|
|
|
for (int i = 0; i < CACHE_COUNT; ++i) {
|
|
|
|
SkBitmap tmp;
|
2014-06-10 02:52:07 +00:00
|
|
|
tmp.allocN32Pixels(1, 1);
|
2013-07-23 19:13:54 +00:00
|
|
|
fCache.unlock(fCache.addAndLock(fBM, scale, scale, tmp));
|
|
|
|
scale += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() SK_OVERRIDE {
|
|
|
|
return "imagecache";
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
|
2014-07-17 13:58:01 +00:00
|
|
|
if (fCache.getTotalBytesUsed() == 0) {
|
2013-07-23 19:13:54 +00:00
|
|
|
this->populateCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap tmp;
|
|
|
|
// search for a miss (-1 scale)
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2013-07-23 19:13:54 +00:00
|
|
|
(void)fCache.findAndLock(fBM, -1, -1, &tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-07-23 19:13:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new ImageCacheBench(); )
|