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.
21 #define FLAGS00 Flags(0)
22 #define FLAGS01 Flags(kBig_Flag)
23 #define FLAGS10 Flags(kAA_Flag)
24 #define FLAGS11 Flags(kBig_Flag | kAA_Flag)
26 static const int points[] = {
27 10, 10, 15, 5, 20, 20,
28 30, 5, 25, 20, 15, 12,
29 21, 21, 30, 30, 12, 4,
30 32, 28, 20, 18, 12, 10
33 static const int kMaxPathSize = 10;
35 class HairlinePathBench : public Benchmark {
37 HairlinePathBench(Flags flags) : fFlags(flags) {
38 fPaint.setStyle(SkPaint::kStroke_Style);
39 fPaint.setStrokeWidth(SkIntToScalar(0));
42 virtual void appendName(SkString*) = 0;
43 virtual void makePath(SkPath*) = 0;
46 const char* onGetName() override {
47 fName.printf("path_hairline_%s_%s_",
48 fFlags & kBig_Flag ? "big" : "small",
49 fFlags & kAA_Flag ? "AA" : "noAA");
50 this->appendName(&fName);
54 void onDraw(int loops, SkCanvas* canvas) override {
55 SkPaint paint(fPaint);
56 this->setupPaint(&paint);
58 paint.setAntiAlias(fFlags & kAA_Flag ? true : false);
61 this->makePath(&path);
62 if (fFlags & kBig_Flag) {
63 const SkMatrix m = SkMatrix::MakeScale(SkIntToScalar(3), SkIntToScalar(3));
67 for (int i = 0; i < loops; i++) {
68 for (int j = 0; j < 100; ++j) {
69 canvas->drawPath(path, paint);
78 typedef Benchmark INHERITED;
81 class LinePathBench : public HairlinePathBench {
83 LinePathBench(Flags flags) : INHERITED(flags) {}
85 void appendName(SkString* name) override {
88 void makePath(SkPath* path) override {
90 int size = SK_ARRAY_COUNT(points);
92 for (int i = 0; i < kMaxPathSize; ++i) {
93 int xTrans = 10 + 40 * (i%(kMaxPathSize/2));
95 if (i > kMaxPathSize/2 - 1) {
98 int base1 = 2 * rand.nextULessThan(hSize);
99 int base2 = 2 * rand.nextULessThan(hSize);
100 int base3 = 2 * rand.nextULessThan(hSize);
101 path->moveTo(SkIntToScalar(points[base1] + xTrans),
102 SkIntToScalar(points[base1+1] + yTrans));
103 path->lineTo(SkIntToScalar(points[base2] + xTrans),
104 SkIntToScalar(points[base2+1] + yTrans));
105 path->lineTo(SkIntToScalar(points[base3] + xTrans),
106 SkIntToScalar(points[base3+1] + yTrans));
110 typedef HairlinePathBench INHERITED;
113 class QuadPathBench : public HairlinePathBench {
115 QuadPathBench(Flags flags) : INHERITED(flags) {}
117 void appendName(SkString* name) override {
118 name->append("quad");
120 void makePath(SkPath* path) override {
122 int size = SK_ARRAY_COUNT(points);
123 int hSize = size / 2;
124 for (int i = 0; i < kMaxPathSize; ++i) {
125 int xTrans = 10 + 40 * (i%(kMaxPathSize/2));
127 if (i > kMaxPathSize/2 - 1) {
130 int base1 = 2 * rand.nextULessThan(hSize);
131 int base2 = 2 * rand.nextULessThan(hSize);
132 int base3 = 2 * rand.nextULessThan(hSize);
133 path->moveTo(SkIntToScalar(points[base1] + xTrans),
134 SkIntToScalar(points[base1+1] + yTrans));
135 path->quadTo(SkIntToScalar(points[base2] + xTrans),
136 SkIntToScalar(points[base2+1] + yTrans),
137 SkIntToScalar(points[base3] + xTrans),
138 SkIntToScalar(points[base3+1] + yTrans));
142 typedef HairlinePathBench INHERITED;
145 class ConicPathBench : public HairlinePathBench {
147 ConicPathBench(Flags flags) : INHERITED(flags) {}
149 void appendName(SkString* name) override {
150 name->append("conic");
152 void makePath(SkPath* path) override {
155 int size = SK_ARRAY_COUNT(points);
156 int hSize = size / 2;
157 for (int i = 0; i < kMaxPathSize; ++i) {
158 int xTrans = 10 + 40 * (i%(kMaxPathSize/2));
160 if (i > kMaxPathSize/2 - 1) {
163 int base1 = 2 * rand.nextULessThan(hSize);
164 int base2 = 2 * rand.nextULessThan(hSize);
165 int base3 = 2 * rand.nextULessThan(hSize);
166 float weight = randWeight.nextRangeF(0.0f, 2.0f);
167 path->moveTo(SkIntToScalar(points[base1] + xTrans),
168 SkIntToScalar(points[base1+1] + yTrans));
169 path->conicTo(SkIntToScalar(points[base2] + xTrans),
170 SkIntToScalar(points[base2+1] + yTrans),
171 SkIntToScalar(points[base3] + xTrans),
172 SkIntToScalar(points[base3+1] + yTrans),
178 typedef HairlinePathBench INHERITED;
181 class CubicPathBench : public HairlinePathBench {
183 CubicPathBench(Flags flags) : INHERITED(flags) {}
185 void appendName(SkString* name) override {
186 name->append("cubic");
188 void makePath(SkPath* path) override {
190 int size = SK_ARRAY_COUNT(points);
191 int hSize = size / 2;
192 for (int i = 0; i < kMaxPathSize; ++i) {
193 int xTrans = 10 + 40 * (i%(kMaxPathSize/2));
195 if (i > kMaxPathSize/2 - 1) {
198 int base1 = 2 * rand.nextULessThan(hSize);
199 int base2 = 2 * rand.nextULessThan(hSize);
200 int base3 = 2 * rand.nextULessThan(hSize);
201 int base4 = 2 * rand.nextULessThan(hSize);
202 path->moveTo(SkIntToScalar(points[base1] + xTrans),
203 SkIntToScalar(points[base1+1] + yTrans));
204 path->cubicTo(SkIntToScalar(points[base2] + xTrans),
205 SkIntToScalar(points[base2+1] + yTrans),
206 SkIntToScalar(points[base3] + xTrans),
207 SkIntToScalar(points[base3+1] + yTrans),
208 SkIntToScalar(points[base4] + xTrans),
209 SkIntToScalar(points[base4+1] + yTrans));
213 typedef HairlinePathBench INHERITED;
216 // FLAG00 - no AA, small
217 // FLAG01 - no AA, small
221 DEF_BENCH( return new LinePathBench(FLAGS00); )
222 DEF_BENCH( return new LinePathBench(FLAGS01); )
223 DEF_BENCH( return new LinePathBench(FLAGS10); )
224 DEF_BENCH( return new LinePathBench(FLAGS11); )
226 DEF_BENCH( return new QuadPathBench(FLAGS00); )
227 DEF_BENCH( return new QuadPathBench(FLAGS01); )
228 DEF_BENCH( return new QuadPathBench(FLAGS10); )
229 DEF_BENCH( return new QuadPathBench(FLAGS11); )
231 // Don't have default path renderer for conics yet on GPU, so must use AA
232 // DEF_BENCH( return new ConicPathBench(FLAGS00); )
233 // DEF_BENCH( return new ConicPathBench(FLAGS01); )
234 DEF_BENCH( return new ConicPathBench(FLAGS10); )
235 DEF_BENCH( return new ConicPathBench(FLAGS11); )
237 DEF_BENCH( return new CubicPathBench(FLAGS00); )
238 DEF_BENCH( return new CubicPathBench(FLAGS01); )
239 DEF_BENCH( return new CubicPathBench(FLAGS10); )
240 DEF_BENCH( return new CubicPathBench(FLAGS11); )