OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #include "SkBenchmark.h" | 7 #include "SkBenchmark.h" |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkPaint.h" | 9 #include "SkPaint.h" |
10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 "erode", | 29 "erode", |
30 "dilate" | 30 "dilate" |
31 }; | 31 }; |
32 | 32 |
33 class MorphologyBench : public SkBenchmark { | 33 class MorphologyBench : public SkBenchmark { |
34 SkScalar fRadius; | 34 SkScalar fRadius; |
35 MorphologyType fStyle; | 35 MorphologyType fStyle; |
36 SkString fName; | 36 SkString fName; |
37 | 37 |
38 public: | 38 public: |
39 MorphologyBench(void* param, SkScalar rad, MorphologyType style) | 39 MorphologyBench(SkScalar rad, MorphologyType style) |
40 : INHERITED(param) { | 40 { |
41 fRadius = rad; | 41 fRadius = rad; |
42 fStyle = style; | 42 fStyle = style; |
43 const char* name = rad > 0 ? gStyleName[style] : "none"; | 43 const char* name = rad > 0 ? gStyleName[style] : "none"; |
44 if (SkScalarFraction(rad) != 0) { | 44 if (SkScalarFraction(rad) != 0) { |
45 fName.printf("morph_%.2f_%s", SkScalarToFloat(rad), name); | 45 fName.printf("morph_%.2f_%s", SkScalarToFloat(rad), name); |
46 } else { | 46 } else { |
47 fName.printf("morph_%d_%s", SkScalarRound(rad), name); | 47 fName.printf("morph_%d_%s", SkScalarRound(rad), name); |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
(...skipping 29 matching lines...) Expand all Loading... |
80 paint.setImageFilter(mf)->unref(); | 80 paint.setImageFilter(mf)->unref(); |
81 } | 81 } |
82 canvas->drawOval(r, paint); | 82 canvas->drawOval(r, paint); |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 private: | 86 private: |
87 typedef SkBenchmark INHERITED; | 87 typedef SkBenchmark INHERITED; |
88 }; | 88 }; |
89 | 89 |
90 static SkBenchmark* Fact00(void* p) { return new MorphologyBench(p, SMALL, kErod
e_MT); } | |
91 static SkBenchmark* Fact01(void* p) { return new MorphologyBench(p, SMALL, kDila
te_MT); } | |
92 | |
93 static SkBenchmark* Fact10(void* p) { return new MorphologyBench(p, BIG, kErode_
MT); } | |
94 static SkBenchmark* Fact11(void* p) { return new MorphologyBench(p, BIG, kDilate
_MT); } | |
95 | |
96 static SkBenchmark* Fact20(void* p) { return new MorphologyBench(p, REAL, kErode
_MT); } | |
97 static SkBenchmark* Fact21(void* p) { return new MorphologyBench(p, REAL, kDilat
e_MT); } | |
98 | |
99 static SkBenchmark* FactNone(void* p) { return new MorphologyBench(p, 0, kErode_
MT); } | |
100 | |
101 // Fixed point can be 100x slower than float on these tests, causing | 90 // Fixed point can be 100x slower than float on these tests, causing |
102 // bench to timeout. | 91 // bench to timeout. |
103 #ifndef SK_SCALAR_IS_FIXED | 92 #ifndef SK_SCALAR_IS_FIXED |
| 93 DEF_BENCH( return new MorphologyBench(SMALL, kErode_MT); ) |
| 94 DEF_BENCH( return new MorphologyBench(SMALL, kDilate_MT); ) |
104 | 95 |
105 static BenchRegistry gReg00(Fact00); | 96 DEF_BENCH( return new MorphologyBench(BIG, kErode_MT); ) |
106 static BenchRegistry gReg01(Fact01); | 97 DEF_BENCH( return new MorphologyBench(BIG, kDilate_MT); ) |
107 | 98 |
108 static BenchRegistry gReg10(Fact10); | 99 DEF_BENCH( return new MorphologyBench(REAL, kErode_MT); ) |
109 static BenchRegistry gReg11(Fact11); | 100 DEF_BENCH( return new MorphologyBench(REAL, kDilate_MT); ) |
110 | 101 |
111 static BenchRegistry gReg20(Fact20); | 102 DEF_BENCH( return new MorphologyBench(0, kErode_MT); ) |
112 static BenchRegistry gReg21(Fact21); | |
113 | |
114 static BenchRegistry gRegNone(FactNone); | |
115 | |
116 #endif | 103 #endif |
OLD | NEW |