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 "SkTRegistry.h" | 14 #include "SkTRegistry.h" |
14 | 15 |
15 #define DEF_BENCH(code) \ | 16 #define DEF_BENCH(code) \ |
16 static SkBenchmark* SK_MACRO_APPEND_LINE(F_)() { code; } \ | 17 static SkBenchmark* SK_MACRO_APPEND_LINE(F_)() { code; } \ |
17 static BenchRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_)); | 18 static BenchRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_)); |
18 | 19 |
19 /* | 20 /* |
20 * With the above macros, you can register benches as follows (at the bottom | 21 * With the above macros, you can register benches as follows (at the bottom |
21 * of your .cpp) | 22 * of your .cpp) |
22 * | 23 * |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 100 |
100 // The bench framework calls this to control the runtime of a bench. | 101 // The bench framework calls this to control the runtime of a bench. |
101 void setLoops(int loops) { | 102 void setLoops(int loops) { |
102 fLoops = loops; | 103 fLoops = loops; |
103 } | 104 } |
104 | 105 |
105 // Each bench should do its main work in a loop like this: | 106 // Each bench should do its main work in a loop like this: |
106 // for (int i = 0; i < this->getLoops(); i++) { <work here> } | 107 // for (int i = 0; i < this->getLoops(); i++) { <work here> } |
107 int getLoops() const { return fLoops; } | 108 int getLoops() const { return fLoops; } |
108 | 109 |
| 110 static void SetResourcePath(const char* resPath) { gResourcePath.set(resPath
); } |
| 111 |
| 112 static SkString& GetResourcePath() { return gResourcePath; } |
| 113 |
109 protected: | 114 protected: |
110 virtual void setupPaint(SkPaint* paint); | 115 virtual void setupPaint(SkPaint* paint); |
111 | 116 |
112 virtual const char* onGetName() = 0; | 117 virtual const char* onGetName() = 0; |
113 virtual void onPreDraw() {} | 118 virtual void onPreDraw() {} |
114 virtual void onDraw(SkCanvas*) = 0; | 119 virtual void onDraw(SkCanvas*) = 0; |
115 virtual void onPostDraw() {} | 120 virtual void onPostDraw() {} |
116 | 121 |
117 virtual SkIPoint onGetSize(); | 122 virtual SkIPoint onGetSize(); |
118 /// Defaults to true. | 123 /// Defaults to true. |
119 bool fIsRendering; | 124 bool fIsRendering; |
120 | 125 |
121 private: | 126 private: |
122 int fForceAlpha; | 127 int fForceAlpha; |
123 bool fForceAA; | 128 bool fForceAA; |
124 bool fForceFilter; | 129 bool fForceFilter; |
125 SkTriState::State fDither; | 130 SkTriState::State fDither; |
126 uint32_t fOrMask, fClearMask; | 131 uint32_t fOrMask, fClearMask; |
127 int fLoops; | 132 int fLoops; |
| 133 static SkString gResourcePath; |
128 | 134 |
129 typedef SkRefCnt INHERITED; | 135 typedef SkRefCnt INHERITED; |
130 }; | 136 }; |
131 | 137 |
132 typedef SkTRegistry<SkBenchmark*(*)()> BenchRegistry; | 138 typedef SkTRegistry<SkBenchmark*(*)()> BenchRegistry; |
133 | 139 |
134 #endif | 140 #endif |
OLD | NEW |