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 |
(...skipping 11 matching lines...) Expand all Loading... | |
22 * of your .cpp) | 22 * of your .cpp) |
23 * | 23 * |
24 * DEF_BENCH(return new MyBenchmark(...)) | 24 * DEF_BENCH(return new MyBenchmark(...)) |
25 * DEF_BENCH(return new MyBenchmark(...)) | 25 * DEF_BENCH(return new MyBenchmark(...)) |
26 * DEF_BENCH(return new MyBenchmark(...)) | 26 * DEF_BENCH(return new MyBenchmark(...)) |
27 */ | 27 */ |
28 | 28 |
29 | 29 |
30 class SkCanvas; | 30 class SkCanvas; |
31 class SkPaint; | 31 class SkPaint; |
32 #if SK_SUPPORT_GPU | |
33 class GrContext; | |
34 #endif | |
32 | 35 |
33 class SkTriState { | 36 class SkTriState { |
34 public: | 37 public: |
35 enum State { | 38 enum State { |
36 kDefault, | 39 kDefault, |
37 kTrue, | 40 kTrue, |
38 kFalse | 41 kFalse |
39 }; | 42 }; |
40 static const char* Name[]; | 43 static const char* Name[]; |
41 }; | 44 }; |
42 | 45 |
43 class SkBenchmark : public SkRefCnt { | 46 class SkBenchmark : public SkRefCnt { |
44 public: | 47 public: |
45 SK_DECLARE_INST_COUNT(SkBenchmark) | 48 SK_DECLARE_INST_COUNT(SkBenchmark) |
46 | 49 |
47 SkBenchmark(); | 50 SkBenchmark(); |
48 | 51 |
49 const char* getName(); | 52 const char* getName(); |
50 SkIPoint getSize(); | 53 SkIPoint getSize(); |
51 | 54 |
55 enum Backend { | |
56 kNonRendering_Backend, | |
57 kRaster_Backend, | |
58 kGPU_Backend, | |
59 kPDF_Backend, | |
60 }; | |
61 | |
62 // Call to determine whether the benchmark is intended for | |
63 // the rendering mode. | |
64 virtual bool isSuitableFor(Backend) { | |
65 return true; | |
66 } | |
67 | |
52 // Call before draw, allows the benchmark to do setup work outside of the | 68 // Call before draw, allows the benchmark to do setup work outside of the |
53 // timer. When a benchmark is repeatedly drawn, this should be called once | 69 // timer. When a benchmark is repeatedly drawn, this should be called once |
54 // before the initial draw. | 70 // before the initial draw. |
55 void preDraw(); | 71 void preDraw(); |
56 | 72 |
57 void draw(SkCanvas*); | 73 void draw(SkCanvas*); |
58 | 74 |
59 // Call after draw, allows the benchmark to do cleanup work outside of the | 75 // Call after draw, allows the benchmark to do cleanup work outside of the |
60 // timer. When a benchmark is repeatedly drawn, this is only called once | 76 // timer. When a benchmark is repeatedly drawn, this is only called once |
61 // after the last draw. | 77 // after the last draw. |
62 void postDraw(); | 78 void postDraw(); |
63 | 79 |
64 void setForceAlpha(int alpha) { | 80 void setForceAlpha(int alpha) { |
65 fForceAlpha = alpha; | 81 fForceAlpha = alpha; |
66 } | 82 } |
67 | 83 |
68 void setForceAA(bool aa) { | 84 void setForceAA(bool aa) { |
69 fForceAA = aa; | 85 fForceAA = aa; |
70 } | 86 } |
71 | 87 |
72 void setForceFilter(bool filter) { | 88 void setForceFilter(bool filter) { |
73 fForceFilter = filter; | 89 fForceFilter = filter; |
74 } | 90 } |
75 | 91 |
76 void setDither(SkTriState::State state) { | 92 void setDither(SkTriState::State state) { |
77 fDither = state; | 93 fDither = state; |
78 } | 94 } |
79 | 95 |
80 /** If true; the benchmark does rendering; if false, the benchmark | |
81 doesn't, and so need not be re-run in every different rendering | |
82 mode. */ | |
83 bool isRendering() { | |
84 return fIsRendering; | |
85 } | |
86 | |
87 /** Assign masks for paint-flags. These will be applied when setupPaint() | 96 /** Assign masks for paint-flags. These will be applied when setupPaint() |
88 * is called. | 97 * is called. |
89 * | 98 * |
90 * Performs the following on the paint: | 99 * Performs the following on the paint: |
91 * uint32_t flags = paint.getFlags(); | 100 * uint32_t flags = paint.getFlags(); |
92 * flags &= ~clearMask; | 101 * flags &= ~clearMask; |
93 * flags |= orMask; | 102 * flags |= orMask; |
94 * paint.setFlags(flags); | 103 * paint.setFlags(flags); |
95 */ | 104 */ |
96 void setPaintMasks(uint32_t orMask, uint32_t clearMask) { | 105 void setPaintMasks(uint32_t orMask, uint32_t clearMask) { |
97 fOrMask = orMask; | 106 fOrMask = orMask; |
98 fClearMask = clearMask; | 107 fClearMask = clearMask; |
99 } | 108 } |
100 | 109 |
101 // The bench framework calls this to control the runtime of a bench. | 110 // The bench framework calls this to control the runtime of a bench. |
102 void setLoops(int loops) { | 111 void setLoops(int loops) { |
103 fLoops = loops; | 112 fLoops = loops; |
104 } | 113 } |
105 | 114 |
106 // Each bench should do its main work in a loop like this: | 115 // Each bench should do its main work in a loop like this: |
107 // for (int i = 0; i < this->getLoops(); i++) { <work here> } | 116 // for (int i = 0; i < this->getLoops(); i++) { <work here> } |
108 int getLoops() const { return fLoops; } | 117 int getLoops() const { return fLoops; } |
109 | 118 |
110 static void SetResourcePath(const char* resPath) { gResourcePath.set(resPath ); } | 119 static void SetResourcePath(const char* resPath) { gResourcePath.set(resPath ); } |
111 | 120 |
112 static SkString& GetResourcePath() { return gResourcePath; } | 121 static SkString& GetResourcePath() { return gResourcePath; } |
113 | 122 |
123 #if SK_SUPPORT_GPU | |
124 virtual void setContext(GrContext* context) { fContext = context; }; | |
mtklein
2013/11/19 12:59:01
Would something like GrContext* GM::GetGr(SkCanvas
Kimmo Kinnunen
2013/11/19 14:12:49
Done.
| |
125 #endif | |
126 | |
114 protected: | 127 protected: |
115 virtual void setupPaint(SkPaint* paint); | 128 virtual void setupPaint(SkPaint* paint); |
116 | 129 |
130 | |
117 virtual const char* onGetName() = 0; | 131 virtual const char* onGetName() = 0; |
118 virtual void onPreDraw() {} | 132 virtual void onPreDraw() {} |
119 virtual void onDraw(SkCanvas*) = 0; | 133 virtual void onDraw(SkCanvas*) = 0; |
120 virtual void onPostDraw() {} | 134 virtual void onPostDraw() {} |
121 | 135 |
122 virtual SkIPoint onGetSize(); | 136 virtual SkIPoint onGetSize(); |
123 /// Defaults to true. | 137 #if SK_SUPPORT_GPU |
124 bool fIsRendering; | 138 GrContext* fContext; |
139 #endif | |
125 | 140 |
126 private: | 141 private: |
127 int fForceAlpha; | 142 int fForceAlpha; |
128 bool fForceAA; | 143 bool fForceAA; |
129 bool fForceFilter; | 144 bool fForceFilter; |
130 SkTriState::State fDither; | 145 SkTriState::State fDither; |
131 uint32_t fOrMask, fClearMask; | 146 uint32_t fOrMask, fClearMask; |
132 int fLoops; | 147 int fLoops; |
133 static SkString gResourcePath; | 148 static SkString gResourcePath; |
134 | 149 |
135 typedef SkRefCnt INHERITED; | 150 typedef SkRefCnt INHERITED; |
136 }; | 151 }; |
137 | 152 |
138 typedef SkTRegistry<SkBenchmark*(*)()> BenchRegistry; | 153 typedef SkTRegistry<SkBenchmark*(*)()> BenchRegistry; |
139 | 154 |
140 #endif | 155 #endif |
OLD | NEW |