blob: e65d1fc3e860d86f44175b8b1d3fd34817456c87 [file] [log] [blame]
reed@google.com602a1d72013-07-23 19:13:54 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
reed@google.com602a1d72013-07-23 19:13:54 +00009#include "SkScaledImageCache.h"
10
tfarinaf168b862014-06-19 12:32:29 -070011class ImageCacheBench : public Benchmark {
reed@google.com602a1d72013-07-23 19:13:54 +000012 SkScaledImageCache fCache;
13 SkBitmap fBM;
14
15 enum {
reed@google.com602a1d72013-07-23 19:13:54 +000016 DIM = 1,
17 CACHE_COUNT = 500
18 };
19public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000020 ImageCacheBench() : fCache(CACHE_COUNT * 100) {
reed6c225732014-06-09 19:52:07 -070021 fBM.allocN32Pixels(DIM, DIM);
reed@google.com602a1d72013-07-23 19:13:54 +000022 }
23
24 void populateCache() {
25 SkScalar scale = 1;
26 for (int i = 0; i < CACHE_COUNT; ++i) {
27 SkBitmap tmp;
reed6c225732014-06-09 19:52:07 -070028 tmp.allocN32Pixels(1, 1);
reed@google.com602a1d72013-07-23 19:13:54 +000029 fCache.unlock(fCache.addAndLock(fBM, scale, scale, tmp));
30 scale += 1;
31 }
32 }
33
34protected:
35 virtual const char* onGetName() SK_OVERRIDE {
36 return "imagecache";
37 }
38
commit-bot@chromium.org33614712013-12-03 18:17:16 +000039 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
halcanary805ef152014-07-17 06:58:01 -070040 if (fCache.getTotalBytesUsed() == 0) {
reed@google.com602a1d72013-07-23 19:13:54 +000041 this->populateCache();
42 }
43
44 SkBitmap tmp;
45 // search for a miss (-1 scale)
commit-bot@chromium.org33614712013-12-03 18:17:16 +000046 for (int i = 0; i < loops; ++i) {
reed@google.com602a1d72013-07-23 19:13:54 +000047 (void)fCache.findAndLock(fBM, -1, -1, &tmp);
48 }
49 }
50
51private:
tfarinaf168b862014-06-19 12:32:29 -070052 typedef Benchmark INHERITED;
reed@google.com602a1d72013-07-23 19:13:54 +000053};
54
55///////////////////////////////////////////////////////////////////////////////
56
mtklein@google.com410e6e82013-09-13 19:52:27 +000057DEF_BENCH( return new ImageCacheBench(); )