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 #include "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkCommandLineFlags.h" | 10 #include "SkCommandLineFlags.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 return fName.c_str(); | 39 return fName.c_str(); |
40 } | 40 } |
41 | 41 |
42 bool isVisual() override { return true; } | 42 bool isVisual() override { return true; } |
43 | 43 |
44 protected: | 44 protected: |
45 virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) { | 45 virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) { |
46 c->drawRect(r, p); | 46 c->drawRect(r, p); |
47 } | 47 } |
48 | 48 |
49 virtual const char* onGetName() { return computeName("rects"); } | 49 const char* onGetName() override { return computeName("rects"); } |
50 | 50 |
51 virtual void onPreDraw() { | 51 void onPreDraw() override { |
52 SkRandom rand; | 52 SkRandom rand; |
53 const SkScalar offset = SK_Scalar1/3; | 53 const SkScalar offset = SK_Scalar1/3; |
54 for (int i = 0; i < N; i++) { | 54 for (int i = 0; i < N; i++) { |
55 int x = rand.nextU() % W; | 55 int x = rand.nextU() % W; |
56 int y = rand.nextU() % H; | 56 int y = rand.nextU() % H; |
57 int w = rand.nextU() % W; | 57 int w = rand.nextU() % W; |
58 int h = rand.nextU() % H; | 58 int h = rand.nextU() % H; |
59 w >>= fShift; | 59 w >>= fShift; |
60 h >>= fShift; | 60 h >>= fShift; |
61 x -= w/2; | 61 x -= w/2; |
62 y -= h/2; | 62 y -= h/2; |
63 fRects[i].set(SkIntToScalar(x), SkIntToScalar(y), | 63 fRects[i].set(SkIntToScalar(x), SkIntToScalar(y), |
64 SkIntToScalar(x+w), SkIntToScalar(y+h)); | 64 SkIntToScalar(x+w), SkIntToScalar(y+h)); |
65 fRects[i].offset(offset, offset); | 65 fRects[i].offset(offset, offset); |
66 fColors[i] = rand.nextU() | 0xFF808080; | 66 fColors[i] = rand.nextU() | 0xFF808080; |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 virtual void onDraw(const int loops, SkCanvas* canvas) { | 70 void onDraw(const int loops, SkCanvas* canvas) override { |
71 SkPaint paint; | 71 SkPaint paint; |
72 if (fStroke > 0) { | 72 if (fStroke > 0) { |
73 paint.setStyle(SkPaint::kStroke_Style); | 73 paint.setStyle(SkPaint::kStroke_Style); |
74 paint.setStrokeWidth(SkIntToScalar(fStroke)); | 74 paint.setStrokeWidth(SkIntToScalar(fStroke)); |
75 } | 75 } |
76 for (int i = 0; i < loops; i++) { | 76 for (int i = 0; i < loops; i++) { |
77 paint.setColor(fColors[i % N]); | 77 paint.setColor(fColors[i % N]); |
78 this->setupPaint(&paint); | 78 this->setupPaint(&paint); |
79 this->drawThisRect(canvas, fRects[i % N], paint); | 79 this->drawThisRect(canvas, fRects[i % N], paint); |
80 } | 80 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 SkString fName; | 135 SkString fName; |
136 | 136 |
137 typedef RectBench INHERITED; | 137 typedef RectBench INHERITED; |
138 }; | 138 }; |
139 | 139 |
140 | 140 |
141 class OvalBench : public RectBench { | 141 class OvalBench : public RectBench { |
142 public: | 142 public: |
143 OvalBench(int shift, int stroke = 0) : RectBench(shift, stroke) {} | 143 OvalBench(int shift, int stroke = 0) : RectBench(shift, stroke) {} |
144 protected: | 144 protected: |
145 virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) { | 145 void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) override { |
146 c->drawOval(r, p); | 146 c->drawOval(r, p); |
147 } | 147 } |
148 virtual const char* onGetName() { return computeName("ovals"); } | 148 const char* onGetName() override { return computeName("ovals"); } |
149 }; | 149 }; |
150 | 150 |
151 class RRectBench : public RectBench { | 151 class RRectBench : public RectBench { |
152 public: | 152 public: |
153 RRectBench(int shift, int stroke = 0) : RectBench(shift, stroke) {} | 153 RRectBench(int shift, int stroke = 0) : RectBench(shift, stroke) {} |
154 protected: | 154 protected: |
155 virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) { | 155 void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) override { |
156 c->drawRoundRect(r, r.width() / 4, r.height() / 4, p); | 156 c->drawRoundRect(r, r.width() / 4, r.height() / 4, p); |
157 } | 157 } |
158 virtual const char* onGetName() { return computeName("rrects"); } | 158 const char* onGetName() override { return computeName("rrects"); } |
159 }; | 159 }; |
160 | 160 |
161 class PointsBench : public RectBench { | 161 class PointsBench : public RectBench { |
162 public: | 162 public: |
163 SkCanvas::PointMode fMode; | 163 SkCanvas::PointMode fMode; |
164 const char* fName; | 164 const char* fName; |
165 | 165 |
166 PointsBench(SkCanvas::PointMode mode, const char* name) | 166 PointsBench(SkCanvas::PointMode mode, const char* name) |
167 : RectBench(2) | 167 : RectBench(2) |
168 , fMode(mode) { | 168 , fMode(mode) { |
169 fName = name; | 169 fName = name; |
170 } | 170 } |
171 | 171 |
172 protected: | 172 protected: |
173 virtual void onDraw(const int loops, SkCanvas* canvas) { | 173 void onDraw(const int loops, SkCanvas* canvas) override { |
174 SkScalar gSizes[] = { | 174 SkScalar gSizes[] = { |
175 SkIntToScalar(7), 0 | 175 SkIntToScalar(7), 0 |
176 }; | 176 }; |
177 size_t sizes = SK_ARRAY_COUNT(gSizes); | 177 size_t sizes = SK_ARRAY_COUNT(gSizes); |
178 | 178 |
179 if (FLAGS_strokeWidth >= 0) { | 179 if (FLAGS_strokeWidth >= 0) { |
180 gSizes[0] = (SkScalar)FLAGS_strokeWidth; | 180 gSizes[0] = (SkScalar)FLAGS_strokeWidth; |
181 sizes = 1; | 181 sizes = 1; |
182 } | 182 } |
183 | 183 |
184 SkPaint paint; | 184 SkPaint paint; |
185 paint.setStrokeCap(SkPaint::kRound_Cap); | 185 paint.setStrokeCap(SkPaint::kRound_Cap); |
186 | 186 |
187 for (int loop = 0; loop < loops; loop++) { | 187 for (int loop = 0; loop < loops; loop++) { |
188 for (size_t i = 0; i < sizes; i++) { | 188 for (size_t i = 0; i < sizes; i++) { |
189 paint.setStrokeWidth(gSizes[i]); | 189 paint.setStrokeWidth(gSizes[i]); |
190 this->setupPaint(&paint); | 190 this->setupPaint(&paint); |
191 canvas->drawPoints(fMode, N * 2, SkTCast<SkPoint*>(fRects), pain
t); | 191 canvas->drawPoints(fMode, N * 2, SkTCast<SkPoint*>(fRects), pain
t); |
192 paint.setColor(fColors[i % N]); | 192 paint.setColor(fColors[i % N]); |
193 } | 193 } |
194 } | 194 } |
195 } | 195 } |
196 virtual const char* onGetName() { return fName; } | 196 const char* onGetName() override { return fName; } |
197 }; | 197 }; |
198 | 198 |
199 /******************************************************************************* | 199 /******************************************************************************* |
200 * to bench BlitMask [Opaque, Black, color, shader] | 200 * to bench BlitMask [Opaque, Black, color, shader] |
201 *******************************************************************************
/ | 201 *******************************************************************************
/ |
202 | 202 |
203 class BlitMaskBench : public RectBench { | 203 class BlitMaskBench : public RectBench { |
204 public: | 204 public: |
205 enum kMaskType { | 205 enum kMaskType { |
206 kMaskOpaque = 0, | 206 kMaskOpaque = 0, |
207 kMaskBlack, | 207 kMaskBlack, |
208 kMaskColor, | 208 kMaskColor, |
209 KMaskShader | 209 KMaskShader |
210 }; | 210 }; |
211 SkCanvas::PointMode fMode; | 211 SkCanvas::PointMode fMode; |
212 const char* fName; | 212 const char* fName; |
213 | 213 |
214 BlitMaskBench(SkCanvas::PointMode mode, | 214 BlitMaskBench(SkCanvas::PointMode mode, |
215 BlitMaskBench::kMaskType type, const char* name) : | 215 BlitMaskBench::kMaskType type, const char* name) : |
216 RectBench(2), fMode(mode), _type(type) { | 216 RectBench(2), fMode(mode), _type(type) { |
217 fName = name; | 217 fName = name; |
218 } | 218 } |
219 | 219 |
220 protected: | 220 protected: |
221 virtual void onDraw(const int loops, SkCanvas* canvas) { | 221 void onDraw(const int loops, SkCanvas* canvas) override { |
222 SkScalar gSizes[] = { | 222 SkScalar gSizes[] = { |
223 SkIntToScalar(13), SkIntToScalar(24) | 223 SkIntToScalar(13), SkIntToScalar(24) |
224 }; | 224 }; |
225 size_t sizes = SK_ARRAY_COUNT(gSizes); | 225 size_t sizes = SK_ARRAY_COUNT(gSizes); |
226 | 226 |
227 if (FLAGS_strokeWidth >= 0) { | 227 if (FLAGS_strokeWidth >= 0) { |
228 gSizes[0] = (SkScalar)FLAGS_strokeWidth; | 228 gSizes[0] = (SkScalar)FLAGS_strokeWidth; |
229 sizes = 1; | 229 sizes = 1; |
230 } | 230 } |
231 SkRandom rand; | 231 SkRandom rand; |
(...skipping 30 matching lines...) Expand all Loading... |
262 break; | 262 break; |
263 } | 263 } |
264 paint.setStrokeWidth(gSizes[i]); | 264 paint.setStrokeWidth(gSizes[i]); |
265 this->setupPaint(&paint); | 265 this->setupPaint(&paint); |
266 paint.setColor(color); | 266 paint.setColor(color); |
267 paint.setAlpha(alpha); | 267 paint.setAlpha(alpha); |
268 canvas->drawPoints(fMode, N * 2, SkTCast<SkPoint*>(fRects), pain
t); | 268 canvas->drawPoints(fMode, N * 2, SkTCast<SkPoint*>(fRects), pain
t); |
269 } | 269 } |
270 } | 270 } |
271 } | 271 } |
272 virtual const char* onGetName() { return fName; } | 272 const char* onGetName() override { return fName; } |
273 private: | 273 private: |
274 typedef RectBench INHERITED; | 274 typedef RectBench INHERITED; |
275 kMaskType _type; | 275 kMaskType _type; |
276 }; | 276 }; |
277 | 277 |
278 DEF_BENCH(return new RectBench(1);) | 278 DEF_BENCH(return new RectBench(1);) |
279 DEF_BENCH(return new RectBench(1, 4);) | 279 DEF_BENCH(return new RectBench(1, 4);) |
280 DEF_BENCH(return new RectBench(3);) | 280 DEF_BENCH(return new RectBench(3);) |
281 DEF_BENCH(return new RectBench(3, 4);) | 281 DEF_BENCH(return new RectBench(3, 4);) |
282 DEF_BENCH(return new OvalBench(1);) | 282 DEF_BENCH(return new OvalBench(1);) |
(...skipping 19 matching lines...) Expand all Loading... |
302 "maskopaque");) | 302 "maskopaque");) |
303 DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, | 303 DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, |
304 BlitMaskBench::kMaskBlack, | 304 BlitMaskBench::kMaskBlack, |
305 "maskblack");) | 305 "maskblack");) |
306 DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, | 306 DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, |
307 BlitMaskBench::kMaskColor, | 307 BlitMaskBench::kMaskColor, |
308 "maskcolor");) | 308 "maskcolor");) |
309 DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, | 309 DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, |
310 BlitMaskBench::KMaskShader, | 310 BlitMaskBench::KMaskShader, |
311 "maskshader");) | 311 "maskshader");) |
OLD | NEW |