OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkMipMap.h" | 10 #include "SkMipMap.h" |
11 | 11 |
12 class MipMapBench: public Benchmark { | 12 class MipMapBench: public Benchmark { |
13 SkBitmap fBitmap; | 13 SkBitmap fBitmap; |
14 SkString fName; | 14 SkString fName; |
15 const int fN; | 15 const int fW, fH; |
16 | 16 |
17 public: | 17 public: |
18 MipMapBench(int N) : fN(N) { | 18 MipMapBench(int w, int h) : fW(w), fH(h) { |
19 fName.printf("mipmap_build_%d", N); | 19 fName.printf("mipmap_build_%dx%d", w, h); |
20 } | 20 } |
21 | 21 |
22 protected: | 22 protected: |
23 bool isSuitableFor(Backend backend) override { | 23 bool isSuitableFor(Backend backend) override { |
24 return kNonRendering_Backend == backend; | 24 return kNonRendering_Backend == backend; |
25 } | 25 } |
26 | 26 |
27 const char* onGetName() override { return fName.c_str(); } | 27 const char* onGetName() override { return fName.c_str(); } |
28 | 28 |
29 void onDelayedSetup() override { | 29 void onDelayedSetup() override { |
30 fBitmap.allocN32Pixels(fN, fN, true); | 30 fBitmap.allocN32Pixels(fW, fH, true); |
31 fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized me
mory | 31 fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized me
mory |
32 } | 32 } |
33 | 33 |
34 void onDraw(int loops, SkCanvas*) override { | 34 void onDraw(int loops, SkCanvas*) override { |
35 for (int i = 0; i < loops * 4; i++) { | 35 for (int i = 0; i < loops * 4; i++) { |
36 SkMipMap::Build(fBitmap, nullptr)->unref(); | 36 SkMipMap::Build(fBitmap, nullptr)->unref(); |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 private: | 40 private: |
41 typedef Benchmark INHERITED; | 41 typedef Benchmark INHERITED; |
42 }; | 42 }; |
43 | 43 |
44 DEF_BENCH( return new MipMapBench(511); ) | 44 // Build variants that exercise the width and heights being even or odd at each
level, as the |
45 DEF_BENCH( return new MipMapBench(512); ) | 45 // impl specializes on each of these. |
| 46 // |
| 47 DEF_BENCH( return new MipMapBench(511, 511); ) |
| 48 DEF_BENCH( return new MipMapBench(512, 511); ) |
| 49 DEF_BENCH( return new MipMapBench(511, 512); ) |
| 50 DEF_BENCH( return new MipMapBench(512, 512); ) |
OLD | NEW |