OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #ifndef SkBenchmark_DEFINED | 8 #ifndef SkBenchmark_DEFINED |
9 #define SkBenchmark_DEFINED | 9 #define SkBenchmark_DEFINED |
10 | 10 |
11 #include "SkRefCnt.h" | 11 #include "SkRefCnt.h" |
12 #include "SkPoint.h" | 12 #include "SkPoint.h" |
13 #include "SkString.h" | 13 #include "SkString.h" |
14 #include "SkTRegistry.h" | 14 #include "SkTRegistry.h" |
15 | 15 |
16 #define DEF_BENCH(code) \ | 16 #define DEF_BENCH(code) \ |
17 static SkBenchmark* SK_MACRO_APPEND_LINE(F_)() { code; } \ | 17 namespace { \ |
18 static BenchRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_)); | 18 class SK_MACRO_APPEND_LINE(F_CLASS) : public SkBenchmarkFactory { \ |
| 19 virtual SkBenchmark* operator()() const SK_OVERRIDE { code; } \ |
| 20 } SK_MACRO_APPEND_LINE(g_F_); \ |
| 21 BenchRegistry SK_MACRO_APPEND_LINE(g_R_)(&SK_MACRO_APPEND_LINE(g_F_)); \ |
| 22 } |
19 | 23 |
20 /* | 24 /* |
21 * With the above macros, you can register benches as follows (at the bottom | 25 * With the above macros, you can register benches as follows (at the bottom |
22 * of your .cpp) | 26 * of your .cpp) |
23 * | 27 * |
24 * DEF_BENCH(return new MyBenchmark(...)) | 28 * DEF_BENCH(return new MyBenchmark(...)) |
25 * DEF_BENCH(return new MyBenchmark(...)) | 29 * DEF_BENCH(return new MyBenchmark(...)) |
26 * DEF_BENCH(return new MyBenchmark(...)) | 30 * DEF_BENCH(return new MyBenchmark(...)) |
27 */ | 31 */ |
28 | 32 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 int fForceAlpha; | 129 int fForceAlpha; |
126 bool fForceAA; | 130 bool fForceAA; |
127 bool fForceFilter; | 131 bool fForceFilter; |
128 SkTriState::State fDither; | 132 SkTriState::State fDither; |
129 uint32_t fOrMask, fClearMask; | 133 uint32_t fOrMask, fClearMask; |
130 static SkString gResourcePath; | 134 static SkString gResourcePath; |
131 | 135 |
132 typedef SkRefCnt INHERITED; | 136 typedef SkRefCnt INHERITED; |
133 }; | 137 }; |
134 | 138 |
135 typedef SkTRegistry<SkBenchmark*(*)()> BenchRegistry; | 139 class SkBenchmarkFactory : public SkRefCnt { |
| 140 public: |
| 141 // Creates a new SkBenchmark that is owned by the caller on each call. |
| 142 virtual SkBenchmark* operator()() const = 0; |
| 143 virtual ~SkBenchmarkFactory() {} |
| 144 }; |
| 145 |
| 146 typedef SkTRegistry<SkBenchmarkFactory*> BenchRegistry; |
136 | 147 |
137 #endif | 148 #endif |
OLD | NEW |