Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: bench/DashBench.cpp

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

Powered by Google App Engine
This is Rietveld 408576698