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

Side by Side Diff: bench/BezierBench.cpp

Issue 558163005: thick stroke Beziers (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix bench Created 6 years, 2 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/beziers.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "Benchmark.h"
9 #include "SkCanvas.h"
10 #include "SkPaint.h"
11 #include "SkString.h"
12
13 struct BezierRec {
14 SkCanvas* fCanvas;
15 SkPaint fPaint;
16 SkPath fQuad;
17 SkPath fCubic;
18 };
19
20 typedef const char* (*DrawProc)(const BezierRec*, int);
21
22 static const char* draw_quad(const BezierRec* rec, int count) {
23 if (rec) {
24 SkCanvas* canvas = rec->fCanvas;
25 const SkPaint& paint = rec->fPaint;
26 const SkPath& path = rec->fQuad;
27 for (int i = 0; i < count; ++i) {
28 canvas->drawPath(path, paint);
29 }
30 }
31 return "quad";
32 }
33
34 static const char* draw_cubic(const BezierRec* rec, int count) {
35 if (rec) {
36 SkCanvas* canvas = rec->fCanvas;
37 const SkPaint& paint = rec->fPaint;
38 const SkPath& path = rec->fCubic;
39 for (int i = 0; i < count; ++i) {
40 canvas->drawPath(path, paint);
41 }
42 }
43 return "cubic";
44 }
45
46 class BezierBench : public Benchmark {
47 SkString fName;
48 SkPaint::Cap fCap;
49 SkPaint::Join fJoin;
50 BezierRec fRec;
51 DrawProc fProc;
52 SkScalar fWidth;
53 public:
54 BezierBench(SkPaint::Cap c, SkPaint::Join j, SkScalar w, DrawProc proc) {
55 static const char* gCapName[] = {
56 "butt", "round", "square"
57 };
58 static const char* gJoinName[] = {
59 "miter", "round", "bevel"
60 };
61
62 fCap = c;
63 fJoin = j;
64 fProc = proc;
65 fWidth = SkIntToScalar(w);
66 fName.printf("draw_stroke_bezier_%s_%s_%s_%g", proc(NULL, 0), gCapName[c ], gJoinName[j], w);
67
68 fRec.fQuad.moveTo(20, 20);
69 fRec.fQuad.quadTo(60, 20, 60, 60);
70 fRec.fQuad.quadTo(20, 60, 20, 100);
71 fRec.fCubic.moveTo(20, 20);
72 fRec.fCubic.cubicTo(40, 20, 60, 40, 60, 60);
73 fRec.fCubic.cubicTo(40, 60, 20, 80, 20, 100);
74 }
75
76 protected:
77 virtual const char* onGetName() {
78 return fName.c_str();
79 }
80
81 virtual void onDraw(const int loops, SkCanvas* canvas) {
82 fRec.fCanvas = canvas;
83 this->setupPaint(&fRec.fPaint);
84 fRec.fPaint.setStyle(SkPaint::kStroke_Style);
85 fRec.fPaint.setStrokeCap(fCap);
86 fRec.fPaint.setStrokeJoin(fJoin);
87 fRec.fPaint.setStrokeWidth(fWidth);
88 fProc(&fRec, loops);
89 }
90
91 private:
92 typedef Benchmark INHERITED;
93 };
94
95 DEF_BENCH( return new BezierBench(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2, d raw_quad); )
96 DEF_BENCH( return new BezierBench(SkPaint::kSquare_Cap, SkPaint::kBevel_Join, 10 , draw_quad); )
97 DEF_BENCH( return new BezierBench(SkPaint::kRound_Cap, SkPaint::kMiter_Join, 50, draw_quad); )
98
99 DEF_BENCH( return new BezierBench(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2, d raw_cubic); )
100 DEF_BENCH( return new BezierBench(SkPaint::kSquare_Cap, SkPaint::kBevel_Join, 10 , draw_cubic); )
101 DEF_BENCH( return new BezierBench(SkPaint::kRound_Cap, SkPaint::kMiter_Join, 50, draw_cubic); )
OLDNEW
« no previous file with comments | « no previous file | gm/beziers.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698