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 "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 void onDraw(int loops, SkCanvas* canvas) override { | 65 void onDraw(int loops, SkCanvas* canvas) override { |
66 SkPaint paint; | 66 SkPaint paint; |
67 this->setupPaint(&paint); | 67 this->setupPaint(&paint); |
68 paint.setStyle(SkPaint::kStroke_Style); | 68 paint.setStyle(SkPaint::kStroke_Style); |
69 paint.setStrokeWidth(SkIntToScalar(fWidth)); | 69 paint.setStrokeWidth(SkIntToScalar(fWidth)); |
70 paint.setAntiAlias(false); | 70 paint.setAntiAlias(false); |
71 | 71 |
72 SkPath path; | 72 SkPath path; |
73 this->makePath(&path); | 73 this->makePath(&path); |
74 | 74 |
75 paint.setPathEffect(SkDashPathEffect::Make(fIntervals.begin(), fInterval
s.count(), 0)); | 75 SkAutoTUnref<SkPathEffect> effect(SkDashPathEffect::Create(fIntervals.be
gin(), |
| 76 fIntervals.count(), 0)); |
| 77 paint.setPathEffect(effect); |
76 | 78 |
77 if (fDoClip) { | 79 if (fDoClip) { |
78 SkRect r = path.getBounds(); | 80 SkRect r = path.getBounds(); |
79 r.inset(-SkIntToScalar(20), -SkIntToScalar(20)); | 81 r.inset(-SkIntToScalar(20), -SkIntToScalar(20)); |
80 // now move it so we don't intersect | 82 // now move it so we don't intersect |
81 r.offset(0, r.height() * 3 / 2); | 83 r.offset(0, r.height() * 3 / 2); |
82 canvas->clipRect(r); | 84 canvas->clipRect(r); |
83 } | 85 } |
84 | 86 |
85 this->handlePath(canvas, path, paint, loops); | 87 this->handlePath(canvas, path, paint, loops); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 SkScalar y0 = SkIntToScalar(10); | 172 SkScalar y0 = SkIntToScalar(10); |
171 path->moveTo(x0, y0); | 173 path->moveTo(x0, y0); |
172 path->cubicTo(x0, y0 + 400 * SK_Scalar1, | 174 path->cubicTo(x0, y0 + 400 * SK_Scalar1, |
173 x0 + 600 * SK_Scalar1, y0 + 400 * SK_Scalar1, | 175 x0 + 600 * SK_Scalar1, y0 + 400 * SK_Scalar1, |
174 x0 + 600 * SK_Scalar1, y0); | 176 x0 + 600 * SK_Scalar1, y0); |
175 } | 177 } |
176 | 178 |
177 class MakeDashBench : public Benchmark { | 179 class MakeDashBench : public Benchmark { |
178 SkString fName; | 180 SkString fName; |
179 SkPath fPath; | 181 SkPath fPath; |
180 sk_sp<SkPathEffect> fPE; | 182 SkAutoTUnref<SkPathEffect> fPE; |
181 | 183 |
182 public: | 184 public: |
183 MakeDashBench(void (*proc)(SkPath*), const char name[]) { | 185 MakeDashBench(void (*proc)(SkPath*), const char name[]) { |
184 fName.printf("makedash_%s", name); | 186 fName.printf("makedash_%s", name); |
185 proc(&fPath); | 187 proc(&fPath); |
186 | 188 |
187 SkScalar vals[] = { SkIntToScalar(4), SkIntToScalar(4) }; | 189 SkScalar vals[] = { SkIntToScalar(4), SkIntToScalar(4) }; |
188 fPE = SkDashPathEffect::Make(vals, 2, 0); | 190 fPE.reset(SkDashPathEffect::Create(vals, 2, 0)); |
189 } | 191 } |
190 | 192 |
191 protected: | 193 protected: |
192 const char* onGetName() override { | 194 const char* onGetName() override { |
193 return fName.c_str(); | 195 return fName.c_str(); |
194 } | 196 } |
195 | 197 |
196 void onDraw(int loops, SkCanvas*) override { | 198 void onDraw(int loops, SkCanvas*) override { |
197 SkPath dst; | 199 SkPath dst; |
198 for (int i = 0; i < loops; ++i) { | 200 for (int i = 0; i < loops; ++i) { |
199 SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle); | 201 SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle); |
200 | 202 |
201 fPE->filterPath(&dst, fPath, &rec, nullptr); | 203 fPE->filterPath(&dst, fPath, &rec, nullptr); |
202 dst.rewind(); | 204 dst.rewind(); |
203 } | 205 } |
204 } | 206 } |
205 | 207 |
206 private: | 208 private: |
207 typedef Benchmark INHERITED; | 209 typedef Benchmark INHERITED; |
208 }; | 210 }; |
209 | 211 |
210 /* | 212 /* |
211 * We try to special case square dashes (intervals are equal to strokewidth). | 213 * We try to special case square dashes (intervals are equal to strokewidth). |
212 */ | 214 */ |
213 class DashLineBench : public Benchmark { | 215 class DashLineBench : public Benchmark { |
214 SkString fName; | 216 SkString fName; |
215 SkScalar fStrokeWidth; | 217 SkScalar fStrokeWidth; |
216 bool fIsRound; | 218 bool fIsRound; |
217 sk_sp<SkPathEffect> fPE; | 219 SkAutoTUnref<SkPathEffect> fPE; |
218 | 220 |
219 public: | 221 public: |
220 DashLineBench(SkScalar width, bool isRound) { | 222 DashLineBench(SkScalar width, bool isRound) { |
221 fName.printf("dashline_%g_%s", SkScalarToFloat(width), isRound ? "circle
" : "square"); | 223 fName.printf("dashline_%g_%s", SkScalarToFloat(width), isRound ? "circle
" : "square"); |
222 fStrokeWidth = width; | 224 fStrokeWidth = width; |
223 fIsRound = isRound; | 225 fIsRound = isRound; |
224 | 226 |
225 SkScalar vals[] = { SK_Scalar1, SK_Scalar1 }; | 227 SkScalar vals[] = { SK_Scalar1, SK_Scalar1 }; |
226 fPE = SkDashPathEffect::Make(vals, 2, 0); | 228 fPE.reset(SkDashPathEffect::Create(vals, 2, 0)); |
227 } | 229 } |
228 | 230 |
229 protected: | 231 protected: |
230 const char* onGetName() override { | 232 const char* onGetName() override { |
231 return fName.c_str(); | 233 return fName.c_str(); |
232 } | 234 } |
233 | 235 |
234 void onDraw(int loops, SkCanvas* canvas) override { | 236 void onDraw(int loops, SkCanvas* canvas) override { |
235 SkPaint paint; | 237 SkPaint paint; |
236 this->setupPaint(&paint); | 238 this->setupPaint(&paint); |
237 paint.setStrokeWidth(fStrokeWidth); | 239 paint.setStrokeWidth(fStrokeWidth); |
238 paint.setStrokeCap(fIsRound ? SkPaint::kRound_Cap : SkPaint::kSquare_Cap
); | 240 paint.setStrokeCap(fIsRound ? SkPaint::kRound_Cap : SkPaint::kSquare_Cap
); |
239 paint.setPathEffect(fPE); | 241 paint.setPathEffect(fPE); |
240 for (int i = 0; i < loops; ++i) { | 242 for (int i = 0; i < loops; ++i) { |
241 canvas->drawLine(10 * SK_Scalar1, 10 * SK_Scalar1, | 243 canvas->drawLine(10 * SK_Scalar1, 10 * SK_Scalar1, |
242 640 * SK_Scalar1, 10 * SK_Scalar1, paint); | 244 640 * SK_Scalar1, 10 * SK_Scalar1, paint); |
243 } | 245 } |
244 } | 246 } |
245 | 247 |
246 private: | 248 private: |
247 typedef Benchmark INHERITED; | 249 typedef Benchmark INHERITED; |
248 }; | 250 }; |
249 | 251 |
250 class DrawPointsDashingBench : public Benchmark { | 252 class DrawPointsDashingBench : public Benchmark { |
251 SkString fName; | 253 SkString fName; |
252 int fStrokeWidth; | 254 int fStrokeWidth; |
253 bool fDoAA; | 255 bool fDoAA; |
254 | 256 |
255 sk_sp<SkPathEffect> fPathEffect; | 257 SkAutoTUnref<SkPathEffect> fPathEffect; |
256 | 258 |
257 public: | 259 public: |
258 DrawPointsDashingBench(int dashLength, int strokeWidth, bool doAA) | 260 DrawPointsDashingBench(int dashLength, int strokeWidth, bool doAA) |
259 { | 261 { |
260 fName.printf("drawpointsdash_%d_%d%s", dashLength, strokeWidth, doAA ? "
_aa" : "_bw"); | 262 fName.printf("drawpointsdash_%d_%d%s", dashLength, strokeWidth, doAA ? "
_aa" : "_bw"); |
261 fStrokeWidth = strokeWidth; | 263 fStrokeWidth = strokeWidth; |
262 fDoAA = doAA; | 264 fDoAA = doAA; |
263 | 265 |
264 SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength)
}; | 266 SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength)
}; |
265 fPathEffect = SkDashPathEffect::Make(vals, 2, SK_Scalar1); | 267 fPathEffect.reset(SkDashPathEffect::Create(vals, 2, SK_Scalar1)); |
266 } | 268 } |
267 | 269 |
268 protected: | 270 protected: |
269 const char* onGetName() override { | 271 const char* onGetName() override { |
270 return fName.c_str(); | 272 return fName.c_str(); |
271 } | 273 } |
272 | 274 |
273 void onDraw(int loops, SkCanvas* canvas) override { | 275 void onDraw(int loops, SkCanvas* canvas) override { |
274 SkPaint p; | 276 SkPaint p; |
275 this->setupPaint(&p); | 277 this->setupPaint(&p); |
(...skipping 16 matching lines...) Expand all Loading... |
292 | 294 |
293 private: | 295 private: |
294 typedef Benchmark INHERITED; | 296 typedef Benchmark INHERITED; |
295 }; | 297 }; |
296 | 298 |
297 // Want to test how we handle dashing when 99% of the dash is clipped out | 299 // Want to test how we handle dashing when 99% of the dash is clipped out |
298 class GiantDashBench : public Benchmark { | 300 class GiantDashBench : public Benchmark { |
299 SkString fName; | 301 SkString fName; |
300 SkScalar fStrokeWidth; | 302 SkScalar fStrokeWidth; |
301 SkPoint fPts[2]; | 303 SkPoint fPts[2]; |
302 sk_sp<SkPathEffect> fPathEffect; | 304 SkAutoTUnref<SkPathEffect> fPathEffect; |
303 | 305 |
304 public: | 306 public: |
305 enum LineType { | 307 enum LineType { |
306 kHori_LineType, | 308 kHori_LineType, |
307 kVert_LineType, | 309 kVert_LineType, |
308 kDiag_LineType, | 310 kDiag_LineType, |
309 kLineTypeCount | 311 kLineTypeCount |
310 }; | 312 }; |
311 | 313 |
312 static const char* LineTypeName(LineType lt) { | 314 static const char* LineTypeName(LineType lt) { |
313 static const char* gNames[] = { "hori", "vert", "diag" }; | 315 static const char* gNames[] = { "hori", "vert", "diag" }; |
314 static_assert(kLineTypeCount == SK_ARRAY_COUNT(gNames), "names_wrong_siz
e"); | 316 static_assert(kLineTypeCount == SK_ARRAY_COUNT(gNames), "names_wrong_siz
e"); |
315 return gNames[lt]; | 317 return gNames[lt]; |
316 } | 318 } |
317 | 319 |
318 GiantDashBench(LineType lt, SkScalar width) { | 320 GiantDashBench(LineType lt, SkScalar width) { |
319 fName.printf("giantdashline_%s_%g", LineTypeName(lt), width); | 321 fName.printf("giantdashline_%s_%g", LineTypeName(lt), width); |
320 fStrokeWidth = width; | 322 fStrokeWidth = width; |
321 | 323 |
322 // deliberately pick intervals that won't be caught by asPoints(), so | 324 // deliberately pick intervals that won't be caught by asPoints(), so |
323 // we can test the filterPath code-path. | 325 // we can test the filterPath code-path. |
324 const SkScalar intervals[] = { 20, 10, 10, 10 }; | 326 const SkScalar intervals[] = { 20, 10, 10, 10 }; |
325 fPathEffect = SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals
), 0); | 327 fPathEffect.reset(SkDashPathEffect::Create(intervals, |
| 328 SK_ARRAY_COUNT(intervals), 0)
); |
326 | 329 |
327 SkScalar cx = 640 / 2; // center X | 330 SkScalar cx = 640 / 2; // center X |
328 SkScalar cy = 480 / 2; // center Y | 331 SkScalar cy = 480 / 2; // center Y |
329 SkMatrix matrix; | 332 SkMatrix matrix; |
330 | 333 |
331 switch (lt) { | 334 switch (lt) { |
332 case kHori_LineType: | 335 case kHori_LineType: |
333 matrix.setIdentity(); | 336 matrix.setIdentity(); |
334 break; | 337 break; |
335 case kVert_LineType: | 338 case kVert_LineType: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 typedef Benchmark INHERITED; | 374 typedef Benchmark INHERITED; |
372 }; | 375 }; |
373 | 376 |
374 // Want to test how we draw a dashed grid (like what is used in spreadsheets) of
many | 377 // Want to test how we draw a dashed grid (like what is used in spreadsheets) of
many |
375 // small dashed lines switching back and forth between horizontal and vertical | 378 // small dashed lines switching back and forth between horizontal and vertical |
376 class DashGridBench : public Benchmark { | 379 class DashGridBench : public Benchmark { |
377 SkString fName; | 380 SkString fName; |
378 int fStrokeWidth; | 381 int fStrokeWidth; |
379 bool fDoAA; | 382 bool fDoAA; |
380 | 383 |
381 sk_sp<SkPathEffect> fPathEffect; | 384 SkAutoTUnref<SkPathEffect> fPathEffect; |
382 | 385 |
383 public: | 386 public: |
384 DashGridBench(int dashLength, int strokeWidth, bool doAA) { | 387 DashGridBench(int dashLength, int strokeWidth, bool doAA) { |
385 fName.printf("dashgrid_%d_%d%s", dashLength, strokeWidth, doAA ? "_aa" :
"_bw"); | 388 fName.printf("dashgrid_%d_%d%s", dashLength, strokeWidth, doAA ? "_aa" :
"_bw"); |
386 fStrokeWidth = strokeWidth; | 389 fStrokeWidth = strokeWidth; |
387 fDoAA = doAA; | 390 fDoAA = doAA; |
388 | 391 |
389 SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength)
}; | 392 SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength)
}; |
390 fPathEffect = SkDashPathEffect::Make(vals, 2, SK_Scalar1); | 393 fPathEffect.reset(SkDashPathEffect::Create(vals, 2, SK_Scalar1)); |
391 } | 394 } |
392 | 395 |
393 protected: | 396 protected: |
394 const char* onGetName() override { | 397 const char* onGetName() override { |
395 return fName.c_str(); | 398 return fName.c_str(); |
396 } | 399 } |
397 | 400 |
398 void onDraw(int loops, SkCanvas* canvas) override { | 401 void onDraw(int loops, SkCanvas* canvas) override { |
399 SkPaint p; | 402 SkPaint p; |
400 this->setupPaint(&p); | 403 this->setupPaint(&p); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 // hori_2 is just too slow to enable at the moment | 481 // hori_2 is just too slow to enable at the moment |
479 DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 2); ) | 482 DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 2); ) |
480 DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 2); ) | 483 DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 2); ) |
481 DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 2); ) | 484 DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 2); ) |
482 | 485 |
483 DEF_BENCH( return new DashGridBench(1, 1, true); ) | 486 DEF_BENCH( return new DashGridBench(1, 1, true); ) |
484 DEF_BENCH( return new DashGridBench(1, 1, false); ) | 487 DEF_BENCH( return new DashGridBench(1, 1, false); ) |
485 DEF_BENCH( return new DashGridBench(3, 1, true); ) | 488 DEF_BENCH( return new DashGridBench(3, 1, true); ) |
486 DEF_BENCH( return new DashGridBench(3, 1, false); ) | 489 DEF_BENCH( return new DashGridBench(3, 1, false); ) |
487 #endif | 490 #endif |
OLD | NEW |