3361471a35
I'm not quite sure why I wrote such a convoluted API with setLoops()/getLoops(). This replaces it with a loops argument passed to onDraw(). This CL is largely mechanical translation from the old API to the new one. MathBench used this->getLoops() outside onDraw(), which seems incorrect. I fixed it. BUG= R=djsollen@google.com Author: mtklein@google.com Review URL: https://codereview.chromium.org/99893003 git-svn-id: http://skia.googlecode.com/svn/trunk@12466 2bbb7eff-a529-9590-31e7-b0007b416f81
60 lines
1.4 KiB
C++
60 lines
1.4 KiB
C++
/*
|
|
* Copyright 2013 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "SkBenchmark.h"
|
|
#include "SkScaledImageCache.h"
|
|
|
|
class ImageCacheBench : public SkBenchmark {
|
|
SkScaledImageCache fCache;
|
|
SkBitmap fBM;
|
|
|
|
enum {
|
|
DIM = 1,
|
|
CACHE_COUNT = 500
|
|
};
|
|
public:
|
|
ImageCacheBench() : fCache(CACHE_COUNT * 100) {
|
|
fBM.setConfig(SkBitmap::kARGB_8888_Config, DIM, DIM);
|
|
fBM.allocPixels();
|
|
}
|
|
|
|
void populateCache() {
|
|
SkScalar scale = 1;
|
|
for (int i = 0; i < CACHE_COUNT; ++i) {
|
|
SkBitmap tmp;
|
|
tmp.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
|
|
tmp.allocPixels();
|
|
fCache.unlock(fCache.addAndLock(fBM, scale, scale, tmp));
|
|
scale += 1;
|
|
}
|
|
}
|
|
|
|
protected:
|
|
virtual const char* onGetName() SK_OVERRIDE {
|
|
return "imagecache";
|
|
}
|
|
|
|
virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
|
|
if (fCache.getBytesUsed() == 0) {
|
|
this->populateCache();
|
|
}
|
|
|
|
SkBitmap tmp;
|
|
// search for a miss (-1 scale)
|
|
for (int i = 0; i < loops; ++i) {
|
|
(void)fCache.findAndLock(fBM, -1, -1, &tmp);
|
|
}
|
|
}
|
|
|
|
private:
|
|
typedef SkBenchmark INHERITED;
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
DEF_BENCH( return new ImageCacheBench(); )
|