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

Side by Side Diff: bench/PathIterBench.cpp

Issue 1126993003: experimental path-builder Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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 | gyp/core.gypi » ('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"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkPaint.h" 12 #include "SkPaint.h"
13 #include "SkPath.h" 13 #include "SkPath.h"
14 #include "SkRandom.h" 14 #include "SkRandom.h"
15 #include "SkShader.h" 15 #include "SkShader.h"
16 #include "SkString.h" 16 #include "SkString.h"
17 #include "SkPathIter.h"
17 18
18 static int rand_pts(SkRandom& rand, SkPoint pts[4]) { 19 static int rand_pts(SkRandom& rand, SkPoint pts[4]) {
19 int n = rand.nextU() & 3; 20 int n = rand.nextU() & 3;
20 n += 1; 21 n += 1;
21 22
22 for (int i = 0; i < n; ++i) { 23 for (int i = 0; i < n; ++i) {
23 pts[i].fX = rand.nextSScalar1(); 24 pts[i].fX = rand.nextSScalar1();
24 pts[i].fY = rand.nextSScalar1(); 25 pts[i].fY = rand.nextSScalar1();
25 } 26 }
26 return n; 27 return n;
27 } 28 }
28 29
30 enum IterType {
31 kRaw,
32 kConsume,
33 kNew
34 };
35
29 class PathIterBench : public Benchmark { 36 class PathIterBench : public Benchmark {
30 SkString fName; 37 SkString fName;
31 SkPath fPath; 38 SkPath fPath;
32 bool fRaw; 39 IterType fRaw;
33 40
34 public: 41 public:
35 PathIterBench(bool raw) { 42 PathIterBench(IterType raw) {
36 fName.printf("pathiter_%s", raw ? "raw" : "consume"); 43 fName.printf("pathiter_%s", raw == 0 ? "raw" : (raw == 1 ? "consume" : " new"));
37 fRaw = raw; 44 fRaw = raw;
38 45
39 SkRandom rand; 46 SkRandom rand;
40 for (int i = 0; i < 1000; ++i) { 47 for (int i = 0; i < 1000; ++i) {
41 SkPoint pts[4]; 48 SkPoint pts[4];
42 int n = rand_pts(rand, pts); 49 int n = rand_pts(rand, pts);
43 switch (n) { 50 switch (n) {
44 case 1: 51 case 1:
45 fPath.moveTo(pts[0]); 52 fPath.moveTo(pts[0]);
46 break; 53 break;
47 case 2: 54 case 2:
48 fPath.lineTo(pts[1]); 55 fPath.lineTo(pts[1]);
49 break; 56 break;
50 case 3: 57 case 3:
51 fPath.quadTo(pts[1], pts[2]); 58 fPath.quadTo(pts[1], pts[2]);
52 break; 59 break;
53 case 4: 60 case 4:
54 fPath.cubicTo(pts[1], pts[2], pts[3]); 61 fPath.cubicTo(pts[1], pts[2], pts[3]);
55 break; 62 break;
56 } 63 }
57 } 64 }
58 } 65 }
59 66
60 bool isSuitableFor(Backend backend) override { 67 bool isSuitableFor(Backend backend) override {
61 return backend == kNonRendering_Backend; 68 return backend == kNonRendering_Backend;
62 } 69 }
63 70
71 virtual void handlePts(const SkPoint pts[]) {}
72
64 protected: 73 protected:
65 const char* onGetName() override { 74 const char* onGetName() override {
66 return fName.c_str(); 75 return fName.c_str();
67 } 76 }
68 77
69 void onDraw(const int loops, SkCanvas*) override { 78 void onDraw(const int loops, SkCanvas*) override {
70 if (fRaw) { 79 for (int j = 0; j < 1000; ++j) {
71 for (int i = 0; i < loops; ++i) { 80 switch (fRaw) {
72 SkPath::RawIter iter(fPath); 81 case kRaw:
73 SkPath::Verb verb; 82 for (int i = 0; i < loops; ++i) {
74 SkPoint pts[4]; 83 SkPath::RawIter iter(fPath);
84 SkPath::Verb verb;
85 SkPoint pts[4];
75 86
76 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { } 87 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
77 } 88 this->handlePts(pts);
78 } else { 89 }
79 for (int i = 0; i < loops; ++i) { 90 }
80 SkPath::Iter iter(fPath, false); 91 break;
81 SkPath::Verb verb; 92 case kConsume:
82 SkPoint pts[4]; 93 for (int i = 0; i < loops; ++i) {
94 SkPath::Iter iter(fPath, false);
95 SkPath::Verb verb;
96 SkPoint pts[4];
83 97
84 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { } 98 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
85 } 99 this->handlePts(pts);
100 }
101 }
102 break;
103 case kNew: {
104 for (int i = 0; i < loops; ++i) {
105 SkPathIter iter(fPath);
106 while (iter.next()) {
107 this->handlePts(iter.currPts());
108 }
109 }
110 } break;
111 }
86 } 112 }
87 } 113 }
88 114
89 private: 115 private:
90 typedef Benchmark INHERITED; 116 typedef Benchmark INHERITED;
91 }; 117 };
92 118
93 /////////////////////////////////////////////////////////////////////////////// 119 DEF_BENCH( return new PathIterBench(kRaw); )
94 120 DEF_BENCH( return new PathIterBench(kConsume); )
95 DEF_BENCH( return new PathIterBench(false); ) 121 DEF_BENCH( return new PathIterBench(kNew); )
96 DEF_BENCH( return new PathIterBench(true); )
OLDNEW
« no previous file with comments | « no previous file | gyp/core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698