2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
20 #define FLAGS00 Flags(0)
21 #define FLAGS01 Flags(kBig_Flag)
22 #define FLAGS10 Flags(kAA_Flag)
23 #define FLAGS11 Flags(kBig_Flag | kAA_Flag)
25 static const int points[] = {
26 10, 10, 15, 5, 20, 20,
27 30, 5, 25, 20, 15, 12,
28 21, 21, 30, 30, 12, 4,
29 32, 28, 20, 18, 12, 10
32 static const int kMaxPathSize = 10;
34 class HairlinePathBench : public Benchmark {
36 HairlinePathBench(Flags flags) : fFlags(flags) {
37 fPaint.setStyle(SkPaint::kStroke_Style);
38 fPaint.setStrokeWidth(SkIntToScalar(0));
41 virtual void appendName(SkString*) = 0;
42 virtual void makePath(SkPath*) = 0;
45 const char* onGetName() override {
46 fName.printf("path_hairline_%s_%s_",
47 fFlags & kBig_Flag ? "big" : "small",
48 fFlags & kAA_Flag ? "AA" : "noAA");
49 this->appendName(&fName);
53 void onDraw(const int loops, SkCanvas* canvas) override {
54 SkPaint paint(fPaint);
55 this->setupPaint(&paint);
57 paint.setAntiAlias(fFlags & kAA_Flag ? true : false);
60 this->makePath(&path);
61 if (fFlags & kBig_Flag) {
63 m.setScale(SkIntToScalar(3), SkIntToScalar(3));
67 for (int i = 0; i < loops; i++) {
68 canvas->drawPath(path, paint);
76 typedef Benchmark INHERITED;
79 class LinePathBench : public HairlinePathBench {
81 LinePathBench(Flags flags) : INHERITED(flags) {}
83 void appendName(SkString* name) override {
86 void makePath(SkPath* path) override {
88 int size = SK_ARRAY_COUNT(points);
90 for (int i = 0; i < kMaxPathSize; ++i) {
91 int xTrans = 10 + 40 * (i%(kMaxPathSize/2));
93 if (i > kMaxPathSize/2 - 1) {
96 int base1 = 2 * rand.nextULessThan(hSize);
97 int base2 = 2 * rand.nextULessThan(hSize);
98 int base3 = 2 * rand.nextULessThan(hSize);
99 path->moveTo(SkIntToScalar(points[base1] + xTrans),
100 SkIntToScalar(points[base1+1] + yTrans));
101 path->lineTo(SkIntToScalar(points[base2] + xTrans),
102 SkIntToScalar(points[base2+1] + yTrans));
103 path->lineTo(SkIntToScalar(points[base3] + xTrans),
104 SkIntToScalar(points[base3+1] + yTrans));
108 typedef HairlinePathBench INHERITED;
111 class QuadPathBench : public HairlinePathBench {
113 QuadPathBench(Flags flags) : INHERITED(flags) {}
115 void appendName(SkString* name) override {
116 name->append("quad");
118 void makePath(SkPath* path) override {
120 int size = SK_ARRAY_COUNT(points);
121 int hSize = size / 2;
122 for (int i = 0; i < kMaxPathSize; ++i) {
123 int xTrans = 10 + 40 * (i%(kMaxPathSize/2));
125 if (i > kMaxPathSize/2 - 1) {
128 int base1 = 2 * rand.nextULessThan(hSize);
129 int base2 = 2 * rand.nextULessThan(hSize);
130 int base3 = 2 * rand.nextULessThan(hSize);
131 path->moveTo(SkIntToScalar(points[base1] + xTrans),
132 SkIntToScalar(points[base1+1] + yTrans));
133 path->quadTo(SkIntToScalar(points[base2] + xTrans),
134 SkIntToScalar(points[base2+1] + yTrans),
135 SkIntToScalar(points[base3] + xTrans),
136 SkIntToScalar(points[base3+1] + yTrans));
140 typedef HairlinePathBench INHERITED;
143 class ConicPathBench : public HairlinePathBench {
145 ConicPathBench(Flags flags) : INHERITED(flags) {}
147 void appendName(SkString* name) override {
148 name->append("conic");
150 void makePath(SkPath* path) override {
153 int size = SK_ARRAY_COUNT(points);
154 int hSize = size / 2;
155 for (int i = 0; i < kMaxPathSize; ++i) {
156 int xTrans = 10 + 40 * (i%(kMaxPathSize/2));
158 if (i > kMaxPathSize/2 - 1) {
161 int base1 = 2 * rand.nextULessThan(hSize);
162 int base2 = 2 * rand.nextULessThan(hSize);
163 int base3 = 2 * rand.nextULessThan(hSize);
164 float weight = randWeight.nextRangeF(0.0f, 2.0f);
165 path->moveTo(SkIntToScalar(points[base1] + xTrans),
166 SkIntToScalar(points[base1+1] + yTrans));
167 path->conicTo(SkIntToScalar(points[base2] + xTrans),
168 SkIntToScalar(points[base2+1] + yTrans),
169 SkIntToScalar(points[base3] + xTrans),
170 SkIntToScalar(points[base3+1] + yTrans),
176 typedef HairlinePathBench INHERITED;
179 class CubicPathBench : public HairlinePathBench {
181 CubicPathBench(Flags flags) : INHERITED(flags) {}
183 void appendName(SkString* name) override {
184 name->append("cubic");
186 void makePath(SkPath* path) override {
188 int size = SK_ARRAY_COUNT(points);
189 int hSize = size / 2;
190 for (int i = 0; i < kMaxPathSize; ++i) {
191 int xTrans = 10 + 40 * (i%(kMaxPathSize/2));
193 if (i > kMaxPathSize/2 - 1) {
196 int base1 = 2 * rand.nextULessThan(hSize);
197 int base2 = 2 * rand.nextULessThan(hSize);
198 int base3 = 2 * rand.nextULessThan(hSize);
199 int base4 = 2 * rand.nextULessThan(hSize);
200 path->moveTo(SkIntToScalar(points[base1] + xTrans),
201 SkIntToScalar(points[base1+1] + yTrans));
202 path->cubicTo(SkIntToScalar(points[base2] + xTrans),
203 SkIntToScalar(points[base2+1] + yTrans),
204 SkIntToScalar(points[base3] + xTrans),
205 SkIntToScalar(points[base3+1] + yTrans),
206 SkIntToScalar(points[base4] + xTrans),
207 SkIntToScalar(points[base4+1] + yTrans));
211 typedef HairlinePathBench INHERITED;
214 // FLAG00 - no AA, small
215 // FLAG01 - no AA, small
219 DEF_BENCH( return new LinePathBench(FLAGS00); )
220 DEF_BENCH( return new LinePathBench(FLAGS01); )
221 DEF_BENCH( return new LinePathBench(FLAGS10); )
222 DEF_BENCH( return new LinePathBench(FLAGS11); )
224 DEF_BENCH( return new QuadPathBench(FLAGS00); )
225 DEF_BENCH( return new QuadPathBench(FLAGS01); )
226 DEF_BENCH( return new QuadPathBench(FLAGS10); )
227 DEF_BENCH( return new QuadPathBench(FLAGS11); )
229 // Don't have default path renderer for conics yet on GPU, so must use AA
230 // DEF_BENCH( return new ConicPathBench(FLAGS00); )
231 // DEF_BENCH( return new ConicPathBench(FLAGS01); )
232 DEF_BENCH( return new ConicPathBench(FLAGS10); )
233 DEF_BENCH( return new ConicPathBench(FLAGS11); )
235 DEF_BENCH( return new CubicPathBench(FLAGS00); )
236 DEF_BENCH( return new CubicPathBench(FLAGS01); )
237 DEF_BENCH( return new CubicPathBench(FLAGS10); )
238 DEF_BENCH( return new CubicPathBench(FLAGS11); )