OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #ifndef Benchmark_DEFINED | 8 #ifndef Benchmark_DEFINED |
9 #define Benchmark_DEFINED | 9 #define Benchmark_DEFINED |
10 | 10 |
11 #include "SkPoint.h" | 11 #include "SkPoint.h" |
12 #include "SkRefCnt.h" | 12 #include "SkRefCnt.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_BENCH3(code, N) \ |
17 namespace { \ | 17 static BenchRegistry gBench##N([](void*) -> Benchmark* { code; }); |
18 static Benchmark* SK_MACRO_APPEND_LINE(factory)(void*) { code; } \ | 18 #define DEF_BENCH2(code, N) DEF_BENCH3(code, N) |
19 BenchRegistry SK_MACRO_APPEND_LINE(g_R_)(SK_MACRO_APPEND_LINE(factory)); \ | 19 #define DEF_BENCH(code) DEF_BENCH2(code, __COUNTER__) |
20 } | |
21 | 20 |
22 /* | 21 /* |
23 * With the above macros, you can register benches as follows (at the bottom | 22 * With the above macros, you can register benches as follows (at the bottom |
24 * of your .cpp) | 23 * of your .cpp) |
25 * | 24 * |
26 * DEF_BENCH(return new MyBenchmark(...)) | 25 * DEF_BENCH(return new MyBenchmark(...)) |
27 * DEF_BENCH(return new MyBenchmark(...)) | 26 * DEF_BENCH(return new MyBenchmark(...)) |
28 * DEF_BENCH(return new MyBenchmark(...)) | 27 * DEF_BENCH(return new MyBenchmark(...)) |
29 */ | 28 */ |
30 | 29 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 int fForceAlpha; | 118 int fForceAlpha; |
120 SkTriState::State fDither; | 119 SkTriState::State fDither; |
121 uint32_t fOrMask, fClearMask; | 120 uint32_t fOrMask, fClearMask; |
122 | 121 |
123 typedef SkRefCnt INHERITED; | 122 typedef SkRefCnt INHERITED; |
124 }; | 123 }; |
125 | 124 |
126 typedef SkTRegistry<Benchmark*(*)(void*)> BenchRegistry; | 125 typedef SkTRegistry<Benchmark*(*)(void*)> BenchRegistry; |
127 | 126 |
128 #endif | 127 #endif |
OLD | NEW |