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 fW, fH; | 15 const int fW, fH; |
| 16 SkSourceGammaTreatment fTreatment; |
16 | 17 |
17 public: | 18 public: |
18 MipMapBench(int w, int h) : fW(w), fH(h) { | 19 MipMapBench(int w, int h, SkSourceGammaTreatment treatment) |
19 fName.printf("mipmap_build_%dx%d", w, h); | 20 : fW(w), fH(h), fTreatment(treatment) |
| 21 { |
| 22 fName.printf("mipmap_build_%dx%d_%d_gamma", w, h, static_cast<int>(treat
ment)); |
20 } | 23 } |
21 | 24 |
22 protected: | 25 protected: |
23 bool isSuitableFor(Backend backend) override { | 26 bool isSuitableFor(Backend backend) override { |
24 return kNonRendering_Backend == backend; | 27 return kNonRendering_Backend == backend; |
25 } | 28 } |
26 | 29 |
27 const char* onGetName() override { return fName.c_str(); } | 30 const char* onGetName() override { return fName.c_str(); } |
28 | 31 |
29 void onDelayedSetup() override { | 32 void onDelayedSetup() override { |
30 fBitmap.allocN32Pixels(fW, fH, true); | 33 SkImageInfo info = SkImageInfo::MakeS32(fW, fH, kPremul_SkAlphaType); |
| 34 fBitmap.allocPixels(info); |
31 fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized me
mory | 35 fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized me
mory |
32 } | 36 } |
33 | 37 |
34 void onDraw(int loops, SkCanvas*) override { | 38 void onDraw(int loops, SkCanvas*) override { |
35 for (int i = 0; i < loops * 4; i++) { | 39 for (int i = 0; i < loops * 4; i++) { |
36 SkMipMap::Build(fBitmap, nullptr)->unref(); | 40 SkMipMap::Build(fBitmap, fTreatment, nullptr)->unref(); |
37 } | 41 } |
38 } | 42 } |
39 | 43 |
40 private: | 44 private: |
41 typedef Benchmark INHERITED; | 45 typedef Benchmark INHERITED; |
42 }; | 46 }; |
43 | 47 |
44 // Build variants that exercise the width and heights being even or odd at each
level, as the | 48 // Build variants that exercise the width and heights being even or odd at each
level, as the |
45 // impl specializes on each of these. | 49 // impl specializes on each of these. |
46 // | 50 // |
47 DEF_BENCH( return new MipMapBench(511, 511); ) | 51 DEF_BENCH( return new MipMapBench(511, 511, SkSourceGammaTreatment::kIgnore); ) |
48 DEF_BENCH( return new MipMapBench(512, 511); ) | 52 DEF_BENCH( return new MipMapBench(512, 511, SkSourceGammaTreatment::kIgnore); ) |
49 DEF_BENCH( return new MipMapBench(511, 512); ) | 53 DEF_BENCH( return new MipMapBench(511, 512, SkSourceGammaTreatment::kIgnore); ) |
50 DEF_BENCH( return new MipMapBench(512, 512); ) | 54 DEF_BENCH( return new MipMapBench(512, 512, SkSourceGammaTreatment::kIgnore); ) |
| 55 DEF_BENCH( return new MipMapBench(512, 512, SkSourceGammaTreatment::kRespect); ) |
OLD | NEW |