blob: 057a2b028c3666ecc8bf6d1f2021f33162fc346d [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@google.comd34658a2011-04-11 13:12:51 +00008#include "SkBenchmark.h"
9#include "SkBitmap.h"
10#include "SkCanvas.h"
11#include "SkColorPriv.h"
12#include "SkPaint.h"
tomhudson@google.com6e8d3352011-06-22 17:16:35 +000013#include "SkRandom.h"
reed@google.comd34658a2011-04-11 13:12:51 +000014#include "SkShader.h"
15#include "SkString.h"
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +000016#include "SkTArray.h"
17
reed@google.comd34658a2011-04-11 13:12:51 +000018enum Flags {
19 kStroke_Flag = 1 << 0,
20 kBig_Flag = 1 << 1
21};
22
23#define FLAGS00 Flags(0)
24#define FLAGS01 Flags(kStroke_Flag)
25#define FLAGS10 Flags(kBig_Flag)
26#define FLAGS11 Flags(kStroke_Flag | kBig_Flag)
27
28class PathBench : public SkBenchmark {
29 SkPaint fPaint;
30 SkString fName;
31 Flags fFlags;
tomhudson@google.comca529d32011-10-28 15:34:49 +000032 enum { N = SkBENCHLOOP(1000) };
reed@google.comd34658a2011-04-11 13:12:51 +000033public:
34 PathBench(void* param, Flags flags) : INHERITED(param), fFlags(flags) {
35 fPaint.setStyle(flags & kStroke_Flag ? SkPaint::kStroke_Style :
36 SkPaint::kFill_Style);
37 fPaint.setStrokeWidth(SkIntToScalar(5));
38 fPaint.setStrokeJoin(SkPaint::kBevel_Join);
39 }
40
41 virtual void appendName(SkString*) = 0;
42 virtual void makePath(SkPath*) = 0;
tomhudson@google.com6e8d3352011-06-22 17:16:35 +000043 virtual int complexity() { return 0; }
reed@google.comd34658a2011-04-11 13:12:51 +000044
45protected:
bsalomon@google.com1647a192012-04-11 15:34:46 +000046 virtual const char* onGetName() SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +000047 fName.printf("path_%s_%s_",
48 fFlags & kStroke_Flag ? "stroke" : "fill",
49 fFlags & kBig_Flag ? "big" : "small");
50 this->appendName(&fName);
51 return fName.c_str();
52 }
53
bsalomon@google.com1647a192012-04-11 15:34:46 +000054 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +000055 SkPaint paint(fPaint);
56 this->setupPaint(&paint);
57
58 SkPath path;
59 this->makePath(&path);
60 if (fFlags & kBig_Flag) {
61 SkMatrix m;
62 m.setScale(SkIntToScalar(10), SkIntToScalar(10));
63 path.transform(m);
64 }
65
66 int count = N;
67 if (fFlags & kBig_Flag) {
68 count >>= 2;
69 }
tomhudson@google.com6e8d3352011-06-22 17:16:35 +000070 count >>= (3 * complexity());
reed@google.comd34658a2011-04-11 13:12:51 +000071
72 for (int i = 0; i < count; i++) {
73 canvas->drawPath(path, paint);
74 }
75 }
76
77private:
78 typedef SkBenchmark INHERITED;
79};
80
81class TrianglePathBench : public PathBench {
82public:
83 TrianglePathBench(void* param, Flags flags) : INHERITED(param, flags) {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +000084
bsalomon@google.com1647a192012-04-11 15:34:46 +000085 virtual void appendName(SkString* name) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +000086 name->append("triangle");
87 }
bsalomon@google.com1647a192012-04-11 15:34:46 +000088 virtual void makePath(SkPath* path) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +000089 static const int gCoord[] = {
90 10, 10, 15, 5, 20, 20
91 };
92 path->moveTo(SkIntToScalar(gCoord[0]), SkIntToScalar(gCoord[1]));
93 path->lineTo(SkIntToScalar(gCoord[2]), SkIntToScalar(gCoord[3]));
94 path->lineTo(SkIntToScalar(gCoord[4]), SkIntToScalar(gCoord[5]));
95 path->close();
96 }
97private:
98 typedef PathBench INHERITED;
99};
100
101class RectPathBench : public PathBench {
102public:
103 RectPathBench(void* param, Flags flags) : INHERITED(param, flags) {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000104
bsalomon@google.com1647a192012-04-11 15:34:46 +0000105 virtual void appendName(SkString* name) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +0000106 name->append("rect");
107 }
bsalomon@google.com1647a192012-04-11 15:34:46 +0000108 virtual void makePath(SkPath* path) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +0000109 SkRect r = { 10, 10, 20, 20 };
110 path->addRect(r);
111 }
112private:
113 typedef PathBench INHERITED;
114};
115
116class OvalPathBench : public PathBench {
117public:
118 OvalPathBench(void* param, Flags flags) : INHERITED(param, flags) {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000119
bsalomon@google.com1647a192012-04-11 15:34:46 +0000120 virtual void appendName(SkString* name) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +0000121 name->append("oval");
122 }
bsalomon@google.com1647a192012-04-11 15:34:46 +0000123 virtual void makePath(SkPath* path) SK_OVERRIDE {
jvanverth@google.come2bfd8b2013-01-24 15:45:35 +0000124 SkRect r = { 10, 10, 23, 20 };
reed@google.comd34658a2011-04-11 13:12:51 +0000125 path->addOval(r);
126 }
127private:
128 typedef PathBench INHERITED;
129};
130
bsalomon@google.com1647a192012-04-11 15:34:46 +0000131class CirclePathBench: public PathBench {
132public:
133 CirclePathBench(void* param, Flags flags) : INHERITED(param, flags) {}
134
135 virtual void appendName(SkString* name) SK_OVERRIDE {
136 name->append("circle");
137 }
138 virtual void makePath(SkPath* path) SK_OVERRIDE {
139 path->addCircle(SkIntToScalar(20), SkIntToScalar(20),
140 SkIntToScalar(10));
141 }
142private:
143 typedef PathBench INHERITED;
144};
145
reed@google.comd34658a2011-04-11 13:12:51 +0000146class SawToothPathBench : public PathBench {
147public:
148 SawToothPathBench(void* param, Flags flags) : INHERITED(param, flags) {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000149
bsalomon@google.com1647a192012-04-11 15:34:46 +0000150 virtual void appendName(SkString* name) SK_OVERRIDE {
reed@google.comd34658a2011-04-11 13:12:51 +0000151 name->append("sawtooth");
152 }
153 virtual void makePath(SkPath* path) {
154 SkScalar x = SkIntToScalar(20);
155 SkScalar y = SkIntToScalar(20);
156 const SkScalar x0 = x;
157 const SkScalar dx = SK_Scalar1 * 5;
158 const SkScalar dy = SK_Scalar1 * 10;
159
160 path->moveTo(x, y);
161 for (int i = 0; i < 32; i++) {
162 x += dx;
163 path->lineTo(x, y - dy);
164 x += dx;
165 path->lineTo(x, y + dy);
166 }
167 path->lineTo(x, y + 2 * dy);
168 path->lineTo(x0, y + 2 * dy);
169 path->close();
170 }
bsalomon@google.com1647a192012-04-11 15:34:46 +0000171 virtual int complexity() SK_OVERRIDE { return 1; }
reed@google.comd34658a2011-04-11 13:12:51 +0000172private:
173 typedef PathBench INHERITED;
174};
175
tomhudson@google.com6e8d3352011-06-22 17:16:35 +0000176class LongCurvedPathBench : public PathBench {
177public:
178 LongCurvedPathBench(void * param, Flags flags)
179 : INHERITED(param, flags) {
180 }
181
bsalomon@google.com1647a192012-04-11 15:34:46 +0000182 virtual void appendName(SkString* name) SK_OVERRIDE {
tomhudson@google.com6e8d3352011-06-22 17:16:35 +0000183 name->append("long_curved");
184 }
bsalomon@google.com1647a192012-04-11 15:34:46 +0000185 virtual void makePath(SkPath* path) SK_OVERRIDE {
tomhudson@google.com6e8d3352011-06-22 17:16:35 +0000186 SkRandom rand (12);
187 int i;
188 for (i = 0; i < 100; i++) {
189 path->quadTo(SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)),
190 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480)),
191 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)),
192 SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480)));
193 }
194 path->close();
195 }
bsalomon@google.com1647a192012-04-11 15:34:46 +0000196 virtual int complexity() SK_OVERRIDE { return 2; }
tomhudson@google.com6e8d3352011-06-22 17:16:35 +0000197private:
198 typedef PathBench INHERITED;
199};
200
senorblanco@chromium.orge50f7362012-01-12 19:10:35 +0000201class LongLinePathBench : public PathBench {
202public:
203 LongLinePathBench(void * param, Flags flags)
204 : INHERITED(param, flags) {
205 }
206
bsalomon@google.com1647a192012-04-11 15:34:46 +0000207 virtual void appendName(SkString* name) SK_OVERRIDE {
senorblanco@chromium.orge50f7362012-01-12 19:10:35 +0000208 name->append("long_line");
209 }
bsalomon@google.com1647a192012-04-11 15:34:46 +0000210 virtual void makePath(SkPath* path) SK_OVERRIDE {
senorblanco@chromium.orge50f7362012-01-12 19:10:35 +0000211 SkRandom rand;
212 path->moveTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
213 for (size_t i = 1; i < 100; i++) {
214 path->lineTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
215 }
216 }
bsalomon@google.com1647a192012-04-11 15:34:46 +0000217 virtual int complexity() SK_OVERRIDE { return 2; }
senorblanco@chromium.orge50f7362012-01-12 19:10:35 +0000218private:
219 typedef PathBench INHERITED;
220};
tomhudson@google.com6e8d3352011-06-22 17:16:35 +0000221
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000222class RandomPathBench : public SkBenchmark {
223public:
224 RandomPathBench(void* param) : INHERITED(param) {
robertphillips@google.com83187a22012-09-13 16:39:08 +0000225 fIsRendering = false;
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000226 }
227
228protected:
229 void createData(int minVerbs,
230 int maxVerbs,
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000231 bool allowMoves = true,
232 SkRect* bounds = NULL) {
233 SkRect tempBounds;
234 if (NULL == bounds) {
235 tempBounds.setXYWH(0, 0, SK_Scalar1, SK_Scalar1);
236 bounds = &tempBounds;
237 }
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000238 fVerbCnts.reset(kNumVerbCnts);
239 for (int i = 0; i < kNumVerbCnts; ++i) {
240 fVerbCnts[i] = fRandom.nextRangeU(minVerbs, maxVerbs + 1);
241 }
242 fVerbs.reset(kNumVerbs);
243 for (int i = 0; i < kNumVerbs; ++i) {
244 do {
245 fVerbs[i] = static_cast<SkPath::Verb>(fRandom.nextULessThan(SkPath::kDone_Verb));
246 } while (!allowMoves && SkPath::kMove_Verb == fVerbs[i]);
247 }
248 fPoints.reset(kNumPoints);
249 for (int i = 0; i < kNumPoints; ++i) {
250 fPoints[i].set(fRandom.nextRangeScalar(bounds->fLeft, bounds->fRight),
251 fRandom.nextRangeScalar(bounds->fTop, bounds->fBottom));
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000252 }
253 this->restartMakingPaths();
254 }
255
256 void restartMakingPaths() {
257 fCurrPath = 0;
258 fCurrVerb = 0;
259 fCurrPoint = 0;
260 }
261
262 void makePath(SkPath* path) {
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000263 int vCount = fVerbCnts[(fCurrPath++) & (kNumVerbCnts - 1)];
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000264 for (int v = 0; v < vCount; ++v) {
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000265 int verb = fVerbs[(fCurrVerb++) & (kNumVerbs - 1)];
266 switch (verb) {
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000267 case SkPath::kMove_Verb:
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000268 path->moveTo(fPoints[(fCurrPoint++) & (kNumPoints - 1)]);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000269 break;
270 case SkPath::kLine_Verb:
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000271 path->lineTo(fPoints[(fCurrPoint++) & (kNumPoints - 1)]);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000272 break;
273 case SkPath::kQuad_Verb:
bsalomon@google.com373ebc62012-09-26 13:08:56 +0000274 path->quadTo(fPoints[(fCurrPoint + 0) & (kNumPoints - 1)],
275 fPoints[(fCurrPoint + 1) & (kNumPoints - 1)]);
276 fCurrPoint += 2;
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000277 break;
reed@google.com277c3f82013-05-31 15:17:50 +0000278 case SkPath::kConic_Verb:
279 path->conicTo(fPoints[(fCurrPoint + 0) & (kNumPoints - 1)],
280 fPoints[(fCurrPoint + 1) & (kNumPoints - 1)],
281 SK_ScalarHalf);
282 fCurrPoint += 2;
283 break;
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000284 case SkPath::kCubic_Verb:
bsalomon@google.com373ebc62012-09-26 13:08:56 +0000285 path->cubicTo(fPoints[(fCurrPoint + 0) & (kNumPoints - 1)],
286 fPoints[(fCurrPoint + 1) & (kNumPoints - 1)],
287 fPoints[(fCurrPoint + 2) & (kNumPoints - 1)]);
288 fCurrPoint += 3;
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000289 break;
290 case SkPath::kClose_Verb:
291 path->close();
292 break;
293 default:
294 SkDEBUGFAIL("Unexpected path verb");
295 break;
296 }
297 }
298 }
299
300 void finishedMakingPaths() {
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000301 fVerbCnts.reset(0);
302 fVerbs.reset(0);
303 fPoints.reset(0);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000304 }
305
306private:
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000307 enum {
308 // these should all be pow 2
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000309 kNumVerbCnts = 1 << 5,
310 kNumVerbs = 1 << 5,
311 kNumPoints = 1 << 5,
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000312 };
313 SkAutoTArray<int> fVerbCnts;
314 SkAutoTArray<SkPath::Verb> fVerbs;
315 SkAutoTArray<SkPoint> fPoints;
316 int fCurrPath;
317 int fCurrVerb;
318 int fCurrPoint;
319 SkRandom fRandom;
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000320 typedef SkBenchmark INHERITED;
321};
322
323class PathCreateBench : public RandomPathBench {
324public:
325 PathCreateBench(void* param) : INHERITED(param) {
326 }
327
328protected:
329 enum { N = SkBENCHLOOP(5000) };
330
331 virtual const char* onGetName() SK_OVERRIDE {
332 return "path_create";
333 }
334
335 virtual void onPreDraw() SK_OVERRIDE {
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000336 this->createData(10, 100);
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000337 fPaths.reset(kPathCnt);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000338 }
339
340 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
341 for (int i = 0; i < N; ++i) {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000342 this->makePath(&fPaths[i & (kPathCnt - 1)]);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000343 }
344 this->restartMakingPaths();
345 }
346
347 virtual void onPostDraw() SK_OVERRIDE {
348 this->finishedMakingPaths();
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000349 fPaths.reset(0);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000350 }
351
352private:
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000353 enum {
354 // must be a pow 2
355 kPathCnt = 1 << 5,
356 };
357 SkAutoTArray<SkPath> fPaths;
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000358
359 typedef RandomPathBench INHERITED;
360};
361
362class PathCopyBench : public RandomPathBench {
363public:
364 PathCopyBench(void* param) : INHERITED(param) {
365 }
366
367protected:
bsalomon@google.com62e41902012-08-13 16:59:21 +0000368 enum { N = SkBENCHLOOP(30000) };
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000369
370 virtual const char* onGetName() SK_OVERRIDE {
371 return "path_copy";
372 }
373 virtual void onPreDraw() SK_OVERRIDE {
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000374 this->createData(10, 100);
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000375 fPaths.reset(kPathCnt);
376 fCopies.reset(kPathCnt);
377 for (int i = 0; i < kPathCnt; ++i) {
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000378 this->makePath(&fPaths[i]);
379 }
380 this->finishedMakingPaths();
381 }
382 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
383 for (int i = 0; i < N; ++i) {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000384 int idx = i & (kPathCnt - 1);
385 fCopies[idx] = fPaths[idx];
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000386 }
387 }
388 virtual void onPostDraw() SK_OVERRIDE {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000389 fPaths.reset(0);
390 fCopies.reset(0);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000391 }
392
393private:
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000394 enum {
395 // must be a pow 2
396 kPathCnt = 1 << 5,
397 };
398 SkAutoTArray<SkPath> fPaths;
399 SkAutoTArray<SkPath> fCopies;
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000400
401 typedef RandomPathBench INHERITED;
402};
403
404class PathTransformBench : public RandomPathBench {
405public:
406 PathTransformBench(bool inPlace, void* param)
407 : INHERITED(param)
408 , fInPlace(inPlace) {
409 }
410
411protected:
412 enum { N = SkBENCHLOOP(30000) };
413
414 virtual const char* onGetName() SK_OVERRIDE {
415 return fInPlace ? "path_transform_in_place" : "path_transform_copy";
416 }
417
418 virtual void onPreDraw() SK_OVERRIDE {
419 fMatrix.setScale(5 * SK_Scalar1, 6 * SK_Scalar1);
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000420 this->createData(10, 100);
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000421 fPaths.reset(kPathCnt);
422 for (int i = 0; i < kPathCnt; ++i) {
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000423 this->makePath(&fPaths[i]);
424 }
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000425 this->finishedMakingPaths();
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000426 if (!fInPlace) {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000427 fTransformed.reset(kPathCnt);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000428 }
429 }
430
431 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
432 if (fInPlace) {
433 for (int i = 0; i < N; ++i) {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000434 fPaths[i & (kPathCnt - 1)].transform(fMatrix);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000435 }
436 } else {
437 for (int i = 0; i < N; ++i) {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000438 int idx = i & (kPathCnt - 1);
439 fPaths[idx].transform(fMatrix, &fTransformed[idx]);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000440 }
441 }
442 }
443
444 virtual void onPostDraw() SK_OVERRIDE {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000445 fPaths.reset(0);
446 fTransformed.reset(0);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000447 }
448
449private:
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000450 enum {
451 // must be a pow 2
452 kPathCnt = 1 << 5,
453 };
454 SkAutoTArray<SkPath> fPaths;
455 SkAutoTArray<SkPath> fTransformed;
456
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000457 SkMatrix fMatrix;
458 bool fInPlace;
459 typedef RandomPathBench INHERITED;
460};
461
462class PathEqualityBench : public RandomPathBench {
463public:
464 PathEqualityBench(void* param)
465 : INHERITED(param) {
466 }
467
468protected:
469 enum { N = SkBENCHLOOP(40000) };
470
471 virtual const char* onGetName() SK_OVERRIDE {
472 return "path_equality_50%";
473 }
474
475 virtual void onPreDraw() SK_OVERRIDE {
476 fParity = 0;
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000477 this->createData(10, 100);
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000478 fPaths.reset(kPathCnt);
479 fCopies.reset(kPathCnt);
480 for (int i = 0; i < kPathCnt; ++i) {
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000481 this->makePath(&fPaths[i]);
482 fCopies[i] = fPaths[i];
483 }
484 this->finishedMakingPaths();
485 }
486
487 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
488 for (int i = 0; i < N; ++i) {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000489 int idx = i & (kPathCnt - 1);
490 fParity ^= (fPaths[idx] == fCopies[idx & ~0x1]);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000491 }
492 }
493
494 virtual void onPostDraw() SK_OVERRIDE {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000495 fPaths.reset(0);
496 fCopies.reset(0);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000497 }
498
499private:
500 bool fParity; // attempt to keep compiler from optimizing out the ==
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000501 enum {
502 // must be a pow 2
503 kPathCnt = 1 << 5,
504 };
505 SkAutoTArray<SkPath> fPaths;
506 SkAutoTArray<SkPath> fCopies;
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000507 typedef RandomPathBench INHERITED;
508};
509
510class SkBench_AddPathTest : public RandomPathBench {
511public:
512 enum AddType {
513 kAdd_AddType,
514 kAddTrans_AddType,
515 kAddMatrix_AddType,
516 kPathTo_AddType,
517 kReverseAdd_AddType,
518 kReversePathTo_AddType,
519 };
520
521 SkBench_AddPathTest(AddType type, void* param)
522 : INHERITED(param)
523 , fType(type) {
524 fMatrix.setRotate(60 * SK_Scalar1);
525 }
526
527protected:
528 enum { N = SkBENCHLOOP(15000) };
529
530 virtual const char* onGetName() SK_OVERRIDE {
531 switch (fType) {
532 case kAdd_AddType:
533 return "path_add_path";
534 case kAddTrans_AddType:
535 return "path_add_path_trans";
536 case kAddMatrix_AddType:
537 return "path_add_path_matrix";
538 case kPathTo_AddType:
539 return "path_path_to";
540 case kReverseAdd_AddType:
541 return "path_reverse_add_path";
542 case kReversePathTo_AddType:
543 return "path_reverse_path_to";
544 default:
545 SkDEBUGFAIL("Bad add type");
546 return "";
547 }
548 }
549
550 virtual void onPreDraw() SK_OVERRIDE {
551 // pathTo and reversePathTo assume a single contour path.
552 bool allowMoves = kPathTo_AddType != fType &&
553 kReversePathTo_AddType != fType;
bsalomon@google.com6d552ee2012-08-14 15:10:09 +0000554 this->createData(10, 100, allowMoves);
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000555 fPaths0.reset(kPathCnt);
556 fPaths1.reset(kPathCnt);
557 for (int i = 0; i < kPathCnt; ++i) {
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000558 this->makePath(&fPaths0[i]);
559 this->makePath(&fPaths1[i]);
560 }
561 this->finishedMakingPaths();
562 }
563
564 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
565 switch (fType) {
566 case kAdd_AddType:
567 for (int i = 0; i < N; ++i) {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000568 int idx = i & (kPathCnt - 1);
569 SkPath result = fPaths0[idx];
570 result.addPath(fPaths1[idx]);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000571 }
572 break;
573 case kAddTrans_AddType:
574 for (int i = 0; i < N; ++i) {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000575 int idx = i & (kPathCnt - 1);
576 SkPath result = fPaths0[idx];
577 result.addPath(fPaths1[idx], 2 * SK_Scalar1, 5 * SK_Scalar1);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000578 }
579 break;
580 case kAddMatrix_AddType:
581 for (int i = 0; i < N; ++i) {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000582 int idx = i & (kPathCnt - 1);
583 SkPath result = fPaths0[idx];
584 result.addPath(fPaths1[idx], fMatrix);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000585 }
586 break;
587 case kPathTo_AddType:
588 for (int i = 0; i < N; ++i) {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000589 int idx = i & (kPathCnt - 1);
590 SkPath result = fPaths0[idx];
591 result.pathTo(fPaths1[idx]);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000592 }
593 break;
594 case kReverseAdd_AddType:
595 for (int i = 0; i < N; ++i) {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000596 int idx = i & (kPathCnt - 1);
597 SkPath result = fPaths0[idx];
598 result.reverseAddPath(fPaths1[idx]);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000599 }
600 break;
601 case kReversePathTo_AddType:
602 for (int i = 0; i < N; ++i) {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000603 int idx = i & (kPathCnt - 1);
604 SkPath result = fPaths0[idx];
605 result.reversePathTo(fPaths1[idx]);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000606 }
607 break;
608 }
609 }
610
611 virtual void onPostDraw() SK_OVERRIDE {
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000612 fPaths0.reset(0);
613 fPaths1.reset(0);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000614 }
615
616private:
617 AddType fType; // or reverseAddPath
bsalomon@google.comb5e47032012-08-14 17:49:46 +0000618 enum {
619 // must be a pow 2
620 kPathCnt = 1 << 5,
621 };
622 SkAutoTArray<SkPath> fPaths0;
623 SkAutoTArray<SkPath> fPaths1;
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000624 SkMatrix fMatrix;
625 typedef RandomPathBench INHERITED;
626};
tomhudson@google.com6e8d3352011-06-22 17:16:35 +0000627
robertphillips@google.com17bb4582012-08-20 17:24:16 +0000628
629class CirclesBench : public SkBenchmark {
630protected:
631 SkString fName;
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000632 Flags fFlags;
robertphillips@google.com17bb4582012-08-20 17:24:16 +0000633
634 enum {
635 N = SkBENCHLOOP(100)
636 };
637public:
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000638 CirclesBench(void* param, Flags flags) : INHERITED(param), fFlags(flags) {
639 fName.printf("circles_%s", fFlags & kStroke_Flag ? "stroke" : "fill");
robertphillips@google.com17bb4582012-08-20 17:24:16 +0000640 }
641
642protected:
643 virtual const char* onGetName() SK_OVERRIDE {
644 return fName.c_str();
645 }
646
647 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
648 SkPaint paint;
649
650 paint.setColor(SK_ColorBLACK);
651 paint.setAntiAlias(true);
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000652 if (fFlags & kStroke_Flag) {
653 paint.setStyle(SkPaint::kStroke_Style);
654 }
robertphillips@google.com17bb4582012-08-20 17:24:16 +0000655
656 SkRandom rand;
657
658 SkRect r;
659
660 for (int i = 0; i < 5000; ++i) {
661 SkScalar radius = rand.nextUScalar1() * 3;
662 r.fLeft = rand.nextUScalar1() * 300;
663 r.fTop = rand.nextUScalar1() * 300;
664 r.fRight = r.fLeft + 2 * radius;
665 r.fBottom = r.fTop + 2 * radius;
666
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000667 if (fFlags & kStroke_Flag) {
668 paint.setStrokeWidth(rand.nextUScalar1() * 5.0f);
669 }
670
robertphillips@google.com17bb4582012-08-20 17:24:16 +0000671 SkPath temp;
672
673 // mimic how Chrome does circles
674 temp.arcTo(r, 0, 0, false);
675 temp.addOval(r, SkPath::kCCW_Direction);
676 temp.arcTo(r, 360, 0, true);
677 temp.close();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000678
robertphillips@google.com17bb4582012-08-20 17:24:16 +0000679 canvas->drawPath(temp, paint);
680 }
681 }
682
683private:
684 typedef SkBenchmark INHERITED;
685};
686
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000687
robertphillips@google.com158618e2012-10-23 16:56:56 +0000688// Chrome creates its own round rects with each corner possibly being different.
689// In its "zero radius" incarnation it creates degenerate round rects.
skia.committer@gmail.com1e34ff72012-10-24 02:01:24 +0000690// Note: PathTest::test_arb_round_rect_is_convex and
robertphillips@google.com158618e2012-10-23 16:56:56 +0000691// test_arb_zero_rad_round_rect_is_rect perform almost exactly
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000692// the same test (but with no drawing)
robertphillips@google.comf6fc3fc2012-10-17 15:23:21 +0000693class ArbRoundRectBench : public SkBenchmark {
694protected:
695 SkString fName;
696
697 enum {
698 N = SkBENCHLOOP(100)
699 };
700public:
robertphillips@google.com158618e2012-10-23 16:56:56 +0000701 ArbRoundRectBench(void* param, bool zeroRad) : INHERITED(param), fZeroRad(zeroRad) {
702 if (zeroRad) {
703 fName.printf("zeroradroundrect");
704 } else {
705 fName.printf("arbroundrect");
706 }
robertphillips@google.comf6fc3fc2012-10-17 15:23:21 +0000707 }
708
709protected:
710 virtual const char* onGetName() SK_OVERRIDE {
711 return fName.c_str();
712 }
713
skia.committer@gmail.com989a95e2012-10-18 02:01:23 +0000714 static void add_corner_arc(SkPath* path, const SkRect& rect,
715 SkScalar xIn, SkScalar yIn,
robertphillips@google.comf6fc3fc2012-10-17 15:23:21 +0000716 int startAngle)
717 {
718
719 SkScalar rx = SkMinScalar(rect.width(), xIn);
720 SkScalar ry = SkMinScalar(rect.height(), yIn);
721
722 SkRect arcRect;
723 arcRect.set(-rx, -ry, rx, ry);
724 switch (startAngle) {
725 case 0:
726 arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom);
727 break;
728 case 90:
729 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom);
730 break;
731 case 180:
732 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop);
733 break;
734 case 270:
735 arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop);
736 break;
737 default:
738 break;
739 }
740
741 path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false);
742 }
743
skia.committer@gmail.com989a95e2012-10-18 02:01:23 +0000744 static void make_arb_round_rect(SkPath* path, const SkRect& r,
robertphillips@google.comf6fc3fc2012-10-17 15:23:21 +0000745 SkScalar xCorner, SkScalar yCorner) {
746 // we are lazy here and use the same x & y for each corner
747 add_corner_arc(path, r, xCorner, yCorner, 270);
748 add_corner_arc(path, r, xCorner, yCorner, 0);
749 add_corner_arc(path, r, xCorner, yCorner, 90);
750 add_corner_arc(path, r, xCorner, yCorner, 180);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000751 path->close();
robertphillips@google.comf6fc3fc2012-10-17 15:23:21 +0000752
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000753 SkASSERT(path->isConvex());
robertphillips@google.comf6fc3fc2012-10-17 15:23:21 +0000754 }
755
756 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
757 SkRandom rand;
758 SkRect r;
759
760 for (int i = 0; i < 5000; ++i) {
761 SkPaint paint;
762 paint.setColor(0xff000000 | rand.nextU());
763 paint.setAntiAlias(true);
764
robertphillips@google.com158618e2012-10-23 16:56:56 +0000765 SkScalar size = rand.nextUScalar1() * 30;
766 if (size < SK_Scalar1) {
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000767 continue;
768 }
robertphillips@google.comf6fc3fc2012-10-17 15:23:21 +0000769 r.fLeft = rand.nextUScalar1() * 300;
770 r.fTop = rand.nextUScalar1() * 300;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000771 r.fRight = r.fLeft + 2 * size;
772 r.fBottom = r.fTop + 2 * size;
robertphillips@google.comf6fc3fc2012-10-17 15:23:21 +0000773
774 SkPath temp;
775
robertphillips@google.com158618e2012-10-23 16:56:56 +0000776 if (fZeroRad) {
777 make_arb_round_rect(&temp, r, 0, 0);
778
779 SkASSERT(temp.isRect(NULL));
780 } else {
781 make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15);
782 }
robertphillips@google.comf6fc3fc2012-10-17 15:23:21 +0000783
784 canvas->drawPath(temp, paint);
785 }
786 }
787
788private:
robertphillips@google.com158618e2012-10-23 16:56:56 +0000789 bool fZeroRad; // should 0 radius rounds rects be tested?
790
robertphillips@google.comf6fc3fc2012-10-17 15:23:21 +0000791 typedef SkBenchmark INHERITED;
792};
793
bsalomon@google.com9bee33a2012-11-13 21:51:38 +0000794class ConservativelyContainsBench : public SkBenchmark {
795public:
796 enum Type {
797 kRect_Type,
798 kRoundRect_Type,
799 kOval_Type,
800 };
801
802 ConservativelyContainsBench(void* param, Type type) : INHERITED(param) {
803 fIsRendering = false;
804 fParity = false;
805 fName = "conservatively_contains_";
806 switch (type) {
807 case kRect_Type:
808 fName.append("rect");
809 fPath.addRect(kBaseRect);
810 break;
811 case kRoundRect_Type:
812 fName.append("round_rect");
813 fPath.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1]);
814 break;
815 case kOval_Type:
816 fName.append("oval");
817 fPath.addOval(kBaseRect);
818 break;
819 }
820 }
821
822private:
823 virtual const char* onGetName() SK_OVERRIDE {
824 return fName.c_str();
825 }
826
sugoi@google.com77472f02013-03-05 18:50:01 +0000827 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +0000828 for (int i = 0; i < N; ++i) {
829 const SkRect& rect = fQueryRects[i % kQueryRectCnt];
830 fParity = fParity != fPath.conservativelyContainsRect(rect);
831 }
832 }
833
834 virtual void onPreDraw() SK_OVERRIDE {
835 fQueryRects.setCount(kQueryRectCnt);
836
837 SkRandom rand;
838 for (int i = 0; i < kQueryRectCnt; ++i) {
839 SkSize size;
840 SkPoint xy;
841 size.fWidth = rand.nextRangeScalar(kQueryMin.fWidth, kQueryMax.fWidth);
842 size.fHeight = rand.nextRangeScalar(kQueryMin.fHeight, kQueryMax.fHeight);
843 xy.fX = rand.nextRangeScalar(kBounds.fLeft, kBounds.fRight - size.fWidth);
844 xy.fY = rand.nextRangeScalar(kBounds.fTop, kBounds.fBottom - size.fHeight);
845
846 fQueryRects[i] = SkRect::MakeXYWH(xy.fX, xy.fY, size.fWidth, size.fHeight);
847 }
848 }
849
850 virtual void onPostDraw() SK_OVERRIDE {
851 fQueryRects.setCount(0);
852 }
853
854 enum {
855 N = SkBENCHLOOP(100000),
856 kQueryRectCnt = 400,
857 };
858 static const SkRect kBounds; // bounds for all random query rects
859 static const SkSize kQueryMin; // minimum query rect size, should be <= kQueryMax
860 static const SkSize kQueryMax; // max query rect size, should < kBounds
861 static const SkRect kBaseRect; // rect that is used to construct the path
862 static const SkScalar kRRRadii[2]; // x and y radii for round rect
863
864 SkString fName;
865 SkPath fPath;
866 bool fParity;
867 SkTDArray<SkRect> fQueryRects;
868
869 typedef SkBenchmark INHERITED;
870};
871
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000872///////////////////////////////////////////////////////////////////////////////
873
874#include "SkGeometry.h"
875
mike@reedtribe.org28552e12013-04-26 00:58:29 +0000876class ConicBench_Chop5 : public SkBenchmark {
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000877 enum {
878 N = 100000
879 };
mike@reedtribe.org28552e12013-04-26 00:58:29 +0000880 SkConic fRQ;
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000881public:
mike@reedtribe.org28552e12013-04-26 00:58:29 +0000882 ConicBench_Chop5(void* param) : INHERITED(param) {
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000883 fRQ.fPts[0].set(0, 0);
884 fRQ.fPts[1].set(100, 0);
885 fRQ.fPts[2].set(100, 100);
886 fRQ.fW = SkScalarCos(SK_ScalarPI/4);
887 }
skia.committer@gmail.comab38e562013-04-14 07:01:08 +0000888
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000889private:
890 virtual const char* onGetName() SK_OVERRIDE {
891 return "ratquad-chop-0.5";
892 }
skia.committer@gmail.comab38e562013-04-14 07:01:08 +0000893
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000894 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
mike@reedtribe.org28552e12013-04-26 00:58:29 +0000895 SkConic dst[2];
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000896 for (int i = 0; i < N; ++i) {
897 fRQ.chopAt(0.5f, dst);
898 }
899 }
skia.committer@gmail.comab38e562013-04-14 07:01:08 +0000900
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000901 typedef SkBenchmark INHERITED;
902};
903
mike@reedtribe.org28552e12013-04-26 00:58:29 +0000904class ConicBench_ChopHalf : public SkBenchmark {
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000905 enum {
906 N = 100000
907 };
mike@reedtribe.org28552e12013-04-26 00:58:29 +0000908 SkConic fRQ;
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000909public:
mike@reedtribe.org28552e12013-04-26 00:58:29 +0000910 ConicBench_ChopHalf(void* param) : INHERITED(param) {
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000911 fRQ.fPts[0].set(0, 0);
912 fRQ.fPts[1].set(100, 0);
913 fRQ.fPts[2].set(100, 100);
914 fRQ.fW = SkScalarCos(SK_ScalarPI/4);
915 }
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000916
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000917private:
918 virtual const char* onGetName() SK_OVERRIDE {
919 return "ratquad-chop-half";
920 }
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000921
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000922 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
mike@reedtribe.org28552e12013-04-26 00:58:29 +0000923 SkConic dst[2];
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000924 for (int i = 0; i < N; ++i) {
925 fRQ.chop(dst);
926 }
927 }
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000928
mike@reedtribe.org8d551012013-04-14 02:40:50 +0000929 typedef SkBenchmark INHERITED;
930};
931
932///////////////////////////////////////////////////////////////////////////////
933
mike@reedtribe.orgaf5c5062013-04-30 02:14:58 +0000934static void rand_conic(SkConic* conic, SkRandom& rand) {
935 for (int i = 0; i < 3; ++i) {
936 conic->fPts[i].set(rand.nextUScalar1() * 100, rand.nextUScalar1() * 100);
937 }
938 if (rand.nextUScalar1() > 0.5f) {
939 conic->fW = rand.nextUScalar1();
940 } else {
941 conic->fW = 1 + rand.nextUScalar1() * 4;
942 }
943}
944
945class ConicBench : public SkBenchmark {
946public:
947 ConicBench(void* param) : INHERITED(param) {
948 SkRandom rand;
949 for (int i = 0; i < CONICS; ++i) {
950 rand_conic(&fConics[i], rand);
951 }
952 fIsRendering = false;
953 }
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000954
mike@reedtribe.orgaf5c5062013-04-30 02:14:58 +0000955protected:
956 enum {
957 N = 20000,
958 CONICS = 100
959 };
960 SkConic fConics[CONICS];
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000961
mike@reedtribe.orgaf5c5062013-04-30 02:14:58 +0000962private:
963 typedef SkBenchmark INHERITED;
964};
965
966class ConicBench_ComputeError : public ConicBench {
967public:
968 ConicBench_ComputeError(void* param) : INHERITED(param) {}
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000969
mike@reedtribe.orgaf5c5062013-04-30 02:14:58 +0000970protected:
971 virtual const char* onGetName() SK_OVERRIDE {
972 return "conic-compute-error";
973 }
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000974
mike@reedtribe.orgaf5c5062013-04-30 02:14:58 +0000975 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
976 SkVector err;
977 for (int i = 0; i < N; ++i) {
978 for (int j = 0; j < CONICS; ++j) {
979 fConics[j].computeAsQuadError(&err);
980 }
981 }
982 }
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000983
mike@reedtribe.orgaf5c5062013-04-30 02:14:58 +0000984private:
985 typedef ConicBench INHERITED;
986};
987
988class ConicBench_asQuadTol : public ConicBench {
989public:
990 ConicBench_asQuadTol(void* param) : INHERITED(param) {}
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000991
mike@reedtribe.orgaf5c5062013-04-30 02:14:58 +0000992protected:
993 virtual const char* onGetName() SK_OVERRIDE {
994 return "conic-asQuadTol";
995 }
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000996
mike@reedtribe.orgaf5c5062013-04-30 02:14:58 +0000997 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
998 for (int i = 0; i < N; ++i) {
999 for (int j = 0; j < CONICS; ++j) {
1000 fConics[j].asQuadTol(SK_ScalarHalf);
1001 }
1002 }
1003 }
skia.committer@gmail.com81521132013-04-30 07:01:03 +00001004
mike@reedtribe.orgaf5c5062013-04-30 02:14:58 +00001005private:
1006 typedef ConicBench INHERITED;
1007};
1008
1009class ConicBench_quadPow2 : public ConicBench {
1010public:
1011 ConicBench_quadPow2(void* param) : INHERITED(param) {}
1012
1013protected:
1014 virtual const char* onGetName() SK_OVERRIDE {
1015 return "conic-quadPow2";
1016 }
skia.committer@gmail.com81521132013-04-30 07:01:03 +00001017
mike@reedtribe.orgaf5c5062013-04-30 02:14:58 +00001018 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
1019 for (int i = 0; i < N; ++i) {
1020 for (int j = 0; j < CONICS; ++j) {
1021 fConics[j].computeQuadPOW2(SK_ScalarHalf);
1022 }
1023 }
1024 }
skia.committer@gmail.com81521132013-04-30 07:01:03 +00001025
mike@reedtribe.orgaf5c5062013-04-30 02:14:58 +00001026private:
1027 typedef ConicBench INHERITED;
1028};
1029
1030///////////////////////////////////////////////////////////////////////////////
1031
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001032const SkRect ConservativelyContainsBench::kBounds = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
1033const SkSize ConservativelyContainsBench::kQueryMin = SkSize::Make(SkIntToScalar(1), SkIntToScalar(1));
1034const SkSize ConservativelyContainsBench::kQueryMax = SkSize::Make(SkIntToScalar(40), SkIntToScalar(40));
1035const SkRect ConservativelyContainsBench::kBaseRect = SkRect::MakeXYWH(SkIntToScalar(25), SkIntToScalar(25), SkIntToScalar(50), SkIntToScalar(50));
1036const SkScalar ConservativelyContainsBench::kRRRadii[2] = {SkIntToScalar(5), SkIntToScalar(10)};
1037
mike@reedtribe.org0cf7b822013-02-04 05:05:36 +00001038DEF_BENCH( return new TrianglePathBench(p, FLAGS00); )
1039DEF_BENCH( return new TrianglePathBench(p, FLAGS01); )
1040DEF_BENCH( return new TrianglePathBench(p, FLAGS10); )
1041DEF_BENCH( return new TrianglePathBench(p, FLAGS11); )
reed@google.comd34658a2011-04-11 13:12:51 +00001042
mike@reedtribe.org0cf7b822013-02-04 05:05:36 +00001043DEF_BENCH( return new RectPathBench(p, FLAGS00); )
1044DEF_BENCH( return new RectPathBench(p, FLAGS01); )
1045DEF_BENCH( return new RectPathBench(p, FLAGS10); )
1046DEF_BENCH( return new RectPathBench(p, FLAGS11); )
reed@google.comd34658a2011-04-11 13:12:51 +00001047
mike@reedtribe.org0cf7b822013-02-04 05:05:36 +00001048DEF_BENCH( return new OvalPathBench(p, FLAGS00); )
1049DEF_BENCH( return new OvalPathBench(p, FLAGS01); )
1050DEF_BENCH( return new OvalPathBench(p, FLAGS10); )
1051DEF_BENCH( return new OvalPathBench(p, FLAGS11); )
reed@google.comd34658a2011-04-11 13:12:51 +00001052
mike@reedtribe.org0cf7b822013-02-04 05:05:36 +00001053DEF_BENCH( return new CirclePathBench(p, FLAGS00); )
1054DEF_BENCH( return new CirclePathBench(p, FLAGS01); )
1055DEF_BENCH( return new CirclePathBench(p, FLAGS10); )
1056DEF_BENCH( return new CirclePathBench(p, FLAGS11); )
bsalomon@google.com1647a192012-04-11 15:34:46 +00001057
mike@reedtribe.org0cf7b822013-02-04 05:05:36 +00001058DEF_BENCH( return new SawToothPathBench(p, FLAGS00); )
1059DEF_BENCH( return new SawToothPathBench(p, FLAGS01); )
reed@google.comd34658a2011-04-11 13:12:51 +00001060
mike@reedtribe.org0cf7b822013-02-04 05:05:36 +00001061DEF_BENCH( return new LongCurvedPathBench(p, FLAGS00); )
1062DEF_BENCH( return new LongCurvedPathBench(p, FLAGS01); )
1063DEF_BENCH( return new LongLinePathBench(p, FLAGS00); )
1064DEF_BENCH( return new LongLinePathBench(p, FLAGS01); )
tomhudson@google.com6e8d3352011-06-22 17:16:35 +00001065
mike@reedtribe.org0cf7b822013-02-04 05:05:36 +00001066DEF_BENCH( return new PathCreateBench(p); )
1067DEF_BENCH( return new PathCopyBench(p); )
1068DEF_BENCH( return new PathTransformBench(true, p); )
1069DEF_BENCH( return new PathTransformBench(false, p); )
1070DEF_BENCH( return new PathEqualityBench(p); )
senorblanco@chromium.orge50f7362012-01-12 19:10:35 +00001071
mike@reedtribe.org0cf7b822013-02-04 05:05:36 +00001072DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kAdd_AddType, p); )
1073DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kAddTrans_AddType, p); )
1074DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kAddMatrix_AddType, p); )
1075DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kPathTo_AddType, p); )
1076DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kReverseAdd_AddType, p); )
1077DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kReversePathTo_AddType, p); )
senorblanco@chromium.orge50f7362012-01-12 19:10:35 +00001078
mike@reedtribe.org0cf7b822013-02-04 05:05:36 +00001079DEF_BENCH( return new CirclesBench(p, FLAGS00); )
1080DEF_BENCH( return new CirclesBench(p, FLAGS01); )
1081DEF_BENCH( return new ArbRoundRectBench(p, false); )
1082DEF_BENCH( return new ArbRoundRectBench(p, true); )
1083DEF_BENCH( return new ConservativelyContainsBench(p, ConservativelyContainsBench::kRect_Type); )
1084DEF_BENCH( return new ConservativelyContainsBench(p, ConservativelyContainsBench::kRoundRect_Type); )
1085DEF_BENCH( return new ConservativelyContainsBench(p, ConservativelyContainsBench::kOval_Type); )
mike@reedtribe.org8d551012013-04-14 02:40:50 +00001086
mike@reedtribe.org28552e12013-04-26 00:58:29 +00001087DEF_BENCH( return new ConicBench_Chop5(p) )
1088DEF_BENCH( return new ConicBench_ChopHalf(p) )
mike@reedtribe.orgaf5c5062013-04-30 02:14:58 +00001089DEF_BENCH( return new ConicBench_ComputeError(p) )
1090DEF_BENCH( return new ConicBench_asQuadTol(p) )
1091DEF_BENCH( return new ConicBench_quadPow2(p) )