OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
9 #include "SkScaledImageCache.h" | 9 #include "SkScaledImageCache.h" |
10 | 10 |
11 class ImageCacheBench : public SkBenchmark { | 11 class ImageCacheBench : public SkBenchmark { |
12 SkScaledImageCache fCache; | 12 SkScaledImageCache fCache; |
13 SkBitmap fBM; | 13 SkBitmap fBM; |
14 | 14 |
15 enum { | 15 enum { |
16 N = SkBENCHLOOP(1000), | |
17 DIM = 1, | 16 DIM = 1, |
18 CACHE_COUNT = 500 | 17 CACHE_COUNT = 500 |
19 }; | 18 }; |
20 public: | 19 public: |
21 ImageCacheBench(void* param) : INHERITED(param) , fCache(CACHE_COUNT * 100)
{ | 20 ImageCacheBench(void* param) : INHERITED(param) , fCache(CACHE_COUNT * 100)
{ |
22 fBM.setConfig(SkBitmap::kARGB_8888_Config, DIM, DIM); | 21 fBM.setConfig(SkBitmap::kARGB_8888_Config, DIM, DIM); |
23 fBM.allocPixels(); | 22 fBM.allocPixels(); |
24 } | 23 } |
25 | 24 |
26 void populateCache() { | 25 void populateCache() { |
(...skipping 12 matching lines...) Expand all Loading... |
39 return "imagecache"; | 38 return "imagecache"; |
40 } | 39 } |
41 | 40 |
42 virtual void onDraw(SkCanvas*) SK_OVERRIDE { | 41 virtual void onDraw(SkCanvas*) SK_OVERRIDE { |
43 if (fCache.getBytesUsed() == 0) { | 42 if (fCache.getBytesUsed() == 0) { |
44 this->populateCache(); | 43 this->populateCache(); |
45 } | 44 } |
46 | 45 |
47 SkBitmap tmp; | 46 SkBitmap tmp; |
48 // search for a miss (-1 scale) | 47 // search for a miss (-1 scale) |
49 for (int i = 0; i < N; ++i) { | 48 for (int i = 0; i < this->getLoops(); ++i) { |
50 (void)fCache.findAndLock(fBM, -1, -1, &tmp); | 49 (void)fCache.findAndLock(fBM, -1, -1, &tmp); |
51 } | 50 } |
52 } | 51 } |
53 | 52 |
54 private: | 53 private: |
55 typedef SkBenchmark INHERITED; | 54 typedef SkBenchmark INHERITED; |
56 }; | 55 }; |
57 | 56 |
58 /////////////////////////////////////////////////////////////////////////////// | 57 /////////////////////////////////////////////////////////////////////////////// |
59 | 58 |
60 DEF_BENCH( return new ImageCacheBench(p); ) | 59 DEF_BENCH( return new ImageCacheBench(p); ) |
OLD | NEW |