| 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 namespace { \ | 17 namespace { \ |
| 18 class SK_MACRO_APPEND_LINE(F_CLASS) : public SkBenchmarkFactory { \ | 18 static SkBenchmark* SK_MACRO_APPEND_LINE(factory)(void*) { code; } \ |
| 19 virtual SkBenchmark* operator()() const SK_OVERRIDE { code; } \ | 19 BenchRegistry SK_MACRO_APPEND_LINE(g_R_)(SK_MACRO_APPEND_LINE(factory)); \ |
| 20 } SK_MACRO_APPEND_LINE(g_F_); \ | |
| 21 BenchRegistry SK_MACRO_APPEND_LINE(g_R_)(&SK_MACRO_APPEND_LINE(g_F_)); \ | |
| 22 } | 20 } |
| 23 | 21 |
| 24 /* | 22 /* |
| 25 * With the above macros, you can register benches as follows (at the bottom | 23 * With the above macros, you can register benches as follows (at the bottom |
| 26 * of your .cpp) | 24 * of your .cpp) |
| 27 * | 25 * |
| 28 * DEF_BENCH(return new MyBenchmark(...)) | 26 * DEF_BENCH(return new MyBenchmark(...)) |
| 29 * DEF_BENCH(return new MyBenchmark(...)) | 27 * DEF_BENCH(return new MyBenchmark(...)) |
| 30 * DEF_BENCH(return new MyBenchmark(...)) | 28 * DEF_BENCH(return new MyBenchmark(...)) |
| 31 */ | 29 */ |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 int fForceAlpha; | 127 int fForceAlpha; |
| 130 bool fForceAA; | 128 bool fForceAA; |
| 131 bool fForceFilter; | 129 bool fForceFilter; |
| 132 SkTriState::State fDither; | 130 SkTriState::State fDither; |
| 133 uint32_t fOrMask, fClearMask; | 131 uint32_t fOrMask, fClearMask; |
| 134 static SkString gResourcePath; | 132 static SkString gResourcePath; |
| 135 | 133 |
| 136 typedef SkRefCnt INHERITED; | 134 typedef SkRefCnt INHERITED; |
| 137 }; | 135 }; |
| 138 | 136 |
| 139 class SkBenchmarkFactory : public SkRefCnt { | 137 typedef SkTRegistry<SkBenchmark*(*)(void*)> BenchRegistry; |
| 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; | |
| 147 | 138 |
| 148 #endif | 139 #endif |
| OLD | NEW |