blob: ea295fd094d65c6d92afa1efc528d64303478505 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/*
* 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(SkCanvas*) SK_OVERRIDE {
if (fCache.getBytesUsed() == 0) {
this->populateCache();
}
SkBitmap tmp;
// search for a miss (-1 scale)
for (int i = 0; i < this->getLoops(); ++i) {
(void)fCache.findAndLock(fBM, -1, -1, &tmp);
}
}
private:
typedef SkBenchmark INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
DEF_BENCH( return new ImageCacheBench(); )
|