epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | */ |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 7 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "Benchmark.h" |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 9 | #include "SkBitmap.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkColorPriv.h" |
| 12 | #include "SkPaint.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 13 | #include "SkPath.h" |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 14 | #include "SkRandom.h" |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 15 | #include "SkShader.h" |
| 16 | #include "SkString.h" |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 17 | #include "SkTArray.h" |
| 18 | |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 19 | enum Flags { |
| 20 | kStroke_Flag = 1 << 0, |
| 21 | kBig_Flag = 1 << 1 |
| 22 | }; |
| 23 | |
| 24 | #define FLAGS00 Flags(0) |
| 25 | #define FLAGS01 Flags(kStroke_Flag) |
| 26 | #define FLAGS10 Flags(kBig_Flag) |
| 27 | #define FLAGS11 Flags(kStroke_Flag | kBig_Flag) |
| 28 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 29 | class PathBench : public Benchmark { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 30 | SkPaint fPaint; |
| 31 | SkString fName; |
| 32 | Flags fFlags; |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 33 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 34 | PathBench(Flags flags) : fFlags(flags) { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 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.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 43 | virtual int complexity() { return 0; } |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 44 | |
| 45 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 46 | const char* onGetName() override { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 47 | 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 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 54 | void onDraw(int loops, SkCanvas* canvas) override { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 55 | SkPaint paint(fPaint); |
| 56 | this->setupPaint(&paint); |
| 57 | |
| 58 | SkPath path; |
| 59 | this->makePath(&path); |
| 60 | if (fFlags & kBig_Flag) { |
robertphillips | 1d24b8d | 2015-03-26 19:57:08 -0700 | [diff] [blame] | 61 | const SkMatrix m = SkMatrix::MakeScale(SkIntToScalar(10), SkIntToScalar(10)); |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 62 | path.transform(m); |
| 63 | } |
| 64 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 65 | int count = loops; |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 66 | if (fFlags & kBig_Flag) { |
| 67 | count >>= 2; |
| 68 | } |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 69 | count >>= (3 * complexity()); |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 70 | |
| 71 | for (int i = 0; i < count; i++) { |
| 72 | canvas->drawPath(path, paint); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 77 | typedef Benchmark INHERITED; |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | class TrianglePathBench : public PathBench { |
| 81 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 82 | TrianglePathBench(Flags flags) : INHERITED(flags) {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 83 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 84 | void appendName(SkString* name) override { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 85 | name->append("triangle"); |
| 86 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 87 | void makePath(SkPath* path) override { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 88 | static const int gCoord[] = { |
| 89 | 10, 10, 15, 5, 20, 20 |
| 90 | }; |
| 91 | path->moveTo(SkIntToScalar(gCoord[0]), SkIntToScalar(gCoord[1])); |
| 92 | path->lineTo(SkIntToScalar(gCoord[2]), SkIntToScalar(gCoord[3])); |
| 93 | path->lineTo(SkIntToScalar(gCoord[4]), SkIntToScalar(gCoord[5])); |
| 94 | path->close(); |
| 95 | } |
| 96 | private: |
| 97 | typedef PathBench INHERITED; |
| 98 | }; |
| 99 | |
| 100 | class RectPathBench : public PathBench { |
| 101 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 102 | RectPathBench(Flags flags) : INHERITED(flags) {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 103 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 104 | void appendName(SkString* name) override { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 105 | name->append("rect"); |
| 106 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 107 | void makePath(SkPath* path) override { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 108 | SkRect r = { 10, 10, 20, 20 }; |
| 109 | path->addRect(r); |
| 110 | } |
| 111 | private: |
| 112 | typedef PathBench INHERITED; |
| 113 | }; |
| 114 | |
liyuqian | a27f669 | 2016-06-20 14:05:27 -0700 | [diff] [blame] | 115 | class RotatedRectBench : public PathBench { |
| 116 | public: |
| 117 | RotatedRectBench(Flags flags, bool aa, int degrees) : INHERITED(flags) { |
| 118 | fAA = aa; |
| 119 | fDegrees = degrees; |
| 120 | } |
| 121 | |
| 122 | void appendName(SkString* name) override { |
| 123 | SkString suffix; |
| 124 | suffix.printf("rotated_rect_%s_%d", fAA ? "aa" : "noaa", fDegrees); |
| 125 | name->append(suffix); |
| 126 | } |
| 127 | |
| 128 | void makePath(SkPath* path) override { |
| 129 | SkRect r = { 10, 10, 20, 20 }; |
| 130 | path->addRect(r); |
| 131 | SkMatrix rotateMatrix; |
| 132 | rotateMatrix.setRotate((SkScalar)fDegrees); |
| 133 | path->transform(rotateMatrix); |
| 134 | } |
| 135 | |
| 136 | virtual void setupPaint(SkPaint* paint) override { |
| 137 | PathBench::setupPaint(paint); |
| 138 | paint->setAntiAlias(fAA); |
| 139 | } |
| 140 | private: |
| 141 | typedef PathBench INHERITED; |
| 142 | int fDegrees; |
| 143 | bool fAA; |
| 144 | }; |
| 145 | |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 146 | class OvalPathBench : public PathBench { |
| 147 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 148 | OvalPathBench(Flags flags) : INHERITED(flags) {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 149 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 150 | void appendName(SkString* name) override { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 151 | name->append("oval"); |
| 152 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 153 | void makePath(SkPath* path) override { |
jvanverth@google.com | e2bfd8b | 2013-01-24 15:45:35 +0000 | [diff] [blame] | 154 | SkRect r = { 10, 10, 23, 20 }; |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 155 | path->addOval(r); |
| 156 | } |
| 157 | private: |
| 158 | typedef PathBench INHERITED; |
| 159 | }; |
| 160 | |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 161 | class CirclePathBench: public PathBench { |
| 162 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 163 | CirclePathBench(Flags flags) : INHERITED(flags) {} |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 164 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 165 | void appendName(SkString* name) override { |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 166 | name->append("circle"); |
| 167 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 168 | void makePath(SkPath* path) override { |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 169 | path->addCircle(SkIntToScalar(20), SkIntToScalar(20), |
| 170 | SkIntToScalar(10)); |
| 171 | } |
| 172 | private: |
| 173 | typedef PathBench INHERITED; |
| 174 | }; |
| 175 | |
Yuqian Li | 8eedbfc | 2017-01-11 13:55:49 +0000 | [diff] [blame] | 176 | class NonAACirclePathBench: public CirclePathBench { |
| 177 | public: |
| 178 | NonAACirclePathBench(Flags flags) : INHERITED(flags) {} |
| 179 | |
| 180 | void appendName(SkString* name) override { |
| 181 | name->append("nonaacircle"); |
| 182 | } |
| 183 | |
| 184 | void setupPaint(SkPaint* paint) override { |
| 185 | CirclePathBench::setupPaint(paint); |
| 186 | paint->setAntiAlias(false); |
| 187 | } |
| 188 | |
| 189 | private: |
| 190 | typedef CirclePathBench INHERITED; |
| 191 | }; |
| 192 | |
Yuqian Li | 131c1fb | 2016-12-12 16:24:47 -0500 | [diff] [blame] | 193 | // Test max speedup of Analytic AA for concave paths |
| 194 | class AAAConcavePathBench : public PathBench { |
| 195 | public: |
| 196 | AAAConcavePathBench(Flags flags) : INHERITED(flags) {} |
| 197 | |
| 198 | void appendName(SkString* name) override { |
| 199 | name->append("concave_aaa"); |
| 200 | } |
| 201 | |
| 202 | void makePath(SkPath* path) override { |
| 203 | path->moveTo(10, 10); |
| 204 | path->lineTo(15, 10); |
| 205 | path->lineTo(15, 5); |
| 206 | path->lineTo(40, 40); |
| 207 | path->close(); |
| 208 | } |
| 209 | |
| 210 | private: |
| 211 | typedef PathBench INHERITED; |
| 212 | }; |
| 213 | |
| 214 | // Test max speedup of Analytic AA for convex paths |
| 215 | class AAAConvexPathBench : public PathBench { |
| 216 | public: |
| 217 | AAAConvexPathBench(Flags flags) : INHERITED(flags) {} |
| 218 | |
| 219 | void appendName(SkString* name) override { |
| 220 | name->append("convex_aaa"); |
| 221 | } |
| 222 | |
| 223 | void makePath(SkPath* path) override { |
| 224 | path->moveTo(10, 10); |
| 225 | path->lineTo(15, 10); |
| 226 | path->lineTo(40, 50); |
| 227 | path->close(); |
| 228 | } |
| 229 | |
| 230 | private: |
| 231 | typedef PathBench INHERITED; |
| 232 | }; |
| 233 | |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 234 | class SawToothPathBench : public PathBench { |
| 235 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 236 | SawToothPathBench(Flags flags) : INHERITED(flags) {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 237 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 238 | void appendName(SkString* name) override { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 239 | name->append("sawtooth"); |
| 240 | } |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 241 | void makePath(SkPath* path) override { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 242 | SkScalar x = SkIntToScalar(20); |
| 243 | SkScalar y = SkIntToScalar(20); |
| 244 | const SkScalar x0 = x; |
| 245 | const SkScalar dx = SK_Scalar1 * 5; |
| 246 | const SkScalar dy = SK_Scalar1 * 10; |
| 247 | |
| 248 | path->moveTo(x, y); |
| 249 | for (int i = 0; i < 32; i++) { |
| 250 | x += dx; |
| 251 | path->lineTo(x, y - dy); |
| 252 | x += dx; |
| 253 | path->lineTo(x, y + dy); |
| 254 | } |
| 255 | path->lineTo(x, y + 2 * dy); |
| 256 | path->lineTo(x0, y + 2 * dy); |
| 257 | path->close(); |
| 258 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 259 | int complexity() override { return 1; } |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 260 | private: |
| 261 | typedef PathBench INHERITED; |
| 262 | }; |
| 263 | |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 264 | class LongCurvedPathBench : public PathBench { |
| 265 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 266 | LongCurvedPathBench(Flags flags) : INHERITED(flags) {} |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 267 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 268 | void appendName(SkString* name) override { |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 269 | name->append("long_curved"); |
| 270 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 271 | void makePath(SkPath* path) override { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 272 | SkRandom rand (12); |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 273 | int i; |
| 274 | for (i = 0; i < 100; i++) { |
| 275 | path->quadTo(SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)), |
| 276 | SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480)), |
| 277 | SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)), |
| 278 | SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480))); |
| 279 | } |
| 280 | path->close(); |
| 281 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 282 | int complexity() override { return 2; } |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 283 | private: |
| 284 | typedef PathBench INHERITED; |
| 285 | }; |
| 286 | |
senorblanco@chromium.org | e50f736 | 2012-01-12 19:10:35 +0000 | [diff] [blame] | 287 | class LongLinePathBench : public PathBench { |
| 288 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 289 | LongLinePathBench(Flags flags) : INHERITED(flags) {} |
senorblanco@chromium.org | e50f736 | 2012-01-12 19:10:35 +0000 | [diff] [blame] | 290 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 291 | void appendName(SkString* name) override { |
senorblanco@chromium.org | e50f736 | 2012-01-12 19:10:35 +0000 | [diff] [blame] | 292 | name->append("long_line"); |
| 293 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 294 | void makePath(SkPath* path) override { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 295 | SkRandom rand; |
senorblanco@chromium.org | e50f736 | 2012-01-12 19:10:35 +0000 | [diff] [blame] | 296 | path->moveTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); |
| 297 | for (size_t i = 1; i < 100; i++) { |
| 298 | path->lineTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); |
| 299 | } |
| 300 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 301 | int complexity() override { return 2; } |
senorblanco@chromium.org | e50f736 | 2012-01-12 19:10:35 +0000 | [diff] [blame] | 302 | private: |
| 303 | typedef PathBench INHERITED; |
| 304 | }; |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 305 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 306 | class RandomPathBench : public Benchmark { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 307 | public: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 308 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 309 | return backend == kNonRendering_Backend; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | protected: |
| 313 | void createData(int minVerbs, |
| 314 | int maxVerbs, |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 315 | bool allowMoves = true, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 316 | SkRect* bounds = nullptr) { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 317 | SkRect tempBounds; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 318 | if (nullptr == bounds) { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 319 | tempBounds.setXYWH(0, 0, SK_Scalar1, SK_Scalar1); |
| 320 | bounds = &tempBounds; |
| 321 | } |
bsalomon@google.com | 6d552ee | 2012-08-14 15:10:09 +0000 | [diff] [blame] | 322 | fVerbCnts.reset(kNumVerbCnts); |
| 323 | for (int i = 0; i < kNumVerbCnts; ++i) { |
| 324 | fVerbCnts[i] = fRandom.nextRangeU(minVerbs, maxVerbs + 1); |
| 325 | } |
| 326 | fVerbs.reset(kNumVerbs); |
| 327 | for (int i = 0; i < kNumVerbs; ++i) { |
| 328 | do { |
| 329 | fVerbs[i] = static_cast<SkPath::Verb>(fRandom.nextULessThan(SkPath::kDone_Verb)); |
| 330 | } while (!allowMoves && SkPath::kMove_Verb == fVerbs[i]); |
| 331 | } |
| 332 | fPoints.reset(kNumPoints); |
| 333 | for (int i = 0; i < kNumPoints; ++i) { |
| 334 | fPoints[i].set(fRandom.nextRangeScalar(bounds->fLeft, bounds->fRight), |
| 335 | fRandom.nextRangeScalar(bounds->fTop, bounds->fBottom)); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 336 | } |
| 337 | this->restartMakingPaths(); |
| 338 | } |
| 339 | |
| 340 | void restartMakingPaths() { |
| 341 | fCurrPath = 0; |
| 342 | fCurrVerb = 0; |
| 343 | fCurrPoint = 0; |
| 344 | } |
| 345 | |
| 346 | void makePath(SkPath* path) { |
bsalomon@google.com | 6d552ee | 2012-08-14 15:10:09 +0000 | [diff] [blame] | 347 | int vCount = fVerbCnts[(fCurrPath++) & (kNumVerbCnts - 1)]; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 348 | for (int v = 0; v < vCount; ++v) { |
bsalomon@google.com | 6d552ee | 2012-08-14 15:10:09 +0000 | [diff] [blame] | 349 | int verb = fVerbs[(fCurrVerb++) & (kNumVerbs - 1)]; |
| 350 | switch (verb) { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 351 | case SkPath::kMove_Verb: |
bsalomon@google.com | 6d552ee | 2012-08-14 15:10:09 +0000 | [diff] [blame] | 352 | path->moveTo(fPoints[(fCurrPoint++) & (kNumPoints - 1)]); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 353 | break; |
| 354 | case SkPath::kLine_Verb: |
bsalomon@google.com | 6d552ee | 2012-08-14 15:10:09 +0000 | [diff] [blame] | 355 | path->lineTo(fPoints[(fCurrPoint++) & (kNumPoints - 1)]); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 356 | break; |
| 357 | case SkPath::kQuad_Verb: |
bsalomon@google.com | 373ebc6 | 2012-09-26 13:08:56 +0000 | [diff] [blame] | 358 | path->quadTo(fPoints[(fCurrPoint + 0) & (kNumPoints - 1)], |
| 359 | fPoints[(fCurrPoint + 1) & (kNumPoints - 1)]); |
| 360 | fCurrPoint += 2; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 361 | break; |
reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 362 | case SkPath::kConic_Verb: |
| 363 | path->conicTo(fPoints[(fCurrPoint + 0) & (kNumPoints - 1)], |
| 364 | fPoints[(fCurrPoint + 1) & (kNumPoints - 1)], |
| 365 | SK_ScalarHalf); |
| 366 | fCurrPoint += 2; |
| 367 | break; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 368 | case SkPath::kCubic_Verb: |
bsalomon@google.com | 373ebc6 | 2012-09-26 13:08:56 +0000 | [diff] [blame] | 369 | path->cubicTo(fPoints[(fCurrPoint + 0) & (kNumPoints - 1)], |
| 370 | fPoints[(fCurrPoint + 1) & (kNumPoints - 1)], |
| 371 | fPoints[(fCurrPoint + 2) & (kNumPoints - 1)]); |
| 372 | fCurrPoint += 3; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 373 | break; |
| 374 | case SkPath::kClose_Verb: |
| 375 | path->close(); |
| 376 | break; |
| 377 | default: |
| 378 | SkDEBUGFAIL("Unexpected path verb"); |
| 379 | break; |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | void finishedMakingPaths() { |
bsalomon@google.com | 6d552ee | 2012-08-14 15:10:09 +0000 | [diff] [blame] | 385 | fVerbCnts.reset(0); |
| 386 | fVerbs.reset(0); |
| 387 | fPoints.reset(0); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | private: |
bsalomon@google.com | 6d552ee | 2012-08-14 15:10:09 +0000 | [diff] [blame] | 391 | enum { |
| 392 | // these should all be pow 2 |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 393 | kNumVerbCnts = 1 << 5, |
| 394 | kNumVerbs = 1 << 5, |
| 395 | kNumPoints = 1 << 5, |
bsalomon@google.com | 6d552ee | 2012-08-14 15:10:09 +0000 | [diff] [blame] | 396 | }; |
| 397 | SkAutoTArray<int> fVerbCnts; |
| 398 | SkAutoTArray<SkPath::Verb> fVerbs; |
| 399 | SkAutoTArray<SkPoint> fPoints; |
| 400 | int fCurrPath; |
| 401 | int fCurrVerb; |
| 402 | int fCurrPoint; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 403 | SkRandom fRandom; |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 404 | typedef Benchmark INHERITED; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 405 | }; |
| 406 | |
| 407 | class PathCreateBench : public RandomPathBench { |
| 408 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 409 | PathCreateBench() { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 413 | const char* onGetName() override { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 414 | return "path_create"; |
| 415 | } |
| 416 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 417 | void onDelayedSetup() override { |
bsalomon@google.com | 6d552ee | 2012-08-14 15:10:09 +0000 | [diff] [blame] | 418 | this->createData(10, 100); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 419 | } |
| 420 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 421 | void onDraw(int loops, SkCanvas*) override { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 422 | for (int i = 0; i < loops; ++i) { |
commit-bot@chromium.org | 8f88117 | 2014-01-06 20:19:14 +0000 | [diff] [blame] | 423 | if (i % 1000 == 0) { |
| 424 | fPath.reset(); // PathRef memory can grow without bound otherwise. |
| 425 | } |
| 426 | this->makePath(&fPath); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 427 | } |
| 428 | this->restartMakingPaths(); |
| 429 | } |
| 430 | |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 431 | private: |
commit-bot@chromium.org | 8f88117 | 2014-01-06 20:19:14 +0000 | [diff] [blame] | 432 | SkPath fPath; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 433 | |
| 434 | typedef RandomPathBench INHERITED; |
| 435 | }; |
| 436 | |
| 437 | class PathCopyBench : public RandomPathBench { |
| 438 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 439 | PathCopyBench() { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 443 | const char* onGetName() override { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 444 | return "path_copy"; |
| 445 | } |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 446 | void onDelayedSetup() override { |
bsalomon@google.com | 6d552ee | 2012-08-14 15:10:09 +0000 | [diff] [blame] | 447 | this->createData(10, 100); |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 448 | fPaths.reset(kPathCnt); |
| 449 | fCopies.reset(kPathCnt); |
| 450 | for (int i = 0; i < kPathCnt; ++i) { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 451 | this->makePath(&fPaths[i]); |
| 452 | } |
| 453 | this->finishedMakingPaths(); |
| 454 | } |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 455 | void onDraw(int loops, SkCanvas*) override { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 456 | for (int i = 0; i < loops; ++i) { |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 457 | int idx = i & (kPathCnt - 1); |
| 458 | fCopies[idx] = fPaths[idx]; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 459 | } |
| 460 | } |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 461 | |
| 462 | private: |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 463 | enum { |
| 464 | // must be a pow 2 |
| 465 | kPathCnt = 1 << 5, |
| 466 | }; |
| 467 | SkAutoTArray<SkPath> fPaths; |
| 468 | SkAutoTArray<SkPath> fCopies; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 469 | |
| 470 | typedef RandomPathBench INHERITED; |
| 471 | }; |
| 472 | |
| 473 | class PathTransformBench : public RandomPathBench { |
| 474 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 475 | PathTransformBench(bool inPlace) : fInPlace(inPlace) {} |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 476 | |
| 477 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 478 | const char* onGetName() override { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 479 | return fInPlace ? "path_transform_in_place" : "path_transform_copy"; |
| 480 | } |
| 481 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 482 | void onDelayedSetup() override { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 483 | fMatrix.setScale(5 * SK_Scalar1, 6 * SK_Scalar1); |
bsalomon@google.com | 6d552ee | 2012-08-14 15:10:09 +0000 | [diff] [blame] | 484 | this->createData(10, 100); |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 485 | fPaths.reset(kPathCnt); |
| 486 | for (int i = 0; i < kPathCnt; ++i) { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 487 | this->makePath(&fPaths[i]); |
| 488 | } |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 489 | this->finishedMakingPaths(); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 490 | if (!fInPlace) { |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 491 | fTransformed.reset(kPathCnt); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 495 | void onDraw(int loops, SkCanvas*) override { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 496 | if (fInPlace) { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 497 | for (int i = 0; i < loops; ++i) { |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 498 | fPaths[i & (kPathCnt - 1)].transform(fMatrix); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 499 | } |
| 500 | } else { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 501 | for (int i = 0; i < loops; ++i) { |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 502 | int idx = i & (kPathCnt - 1); |
| 503 | fPaths[idx].transform(fMatrix, &fTransformed[idx]); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 508 | private: |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 509 | enum { |
| 510 | // must be a pow 2 |
| 511 | kPathCnt = 1 << 5, |
| 512 | }; |
| 513 | SkAutoTArray<SkPath> fPaths; |
| 514 | SkAutoTArray<SkPath> fTransformed; |
| 515 | |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 516 | SkMatrix fMatrix; |
| 517 | bool fInPlace; |
| 518 | typedef RandomPathBench INHERITED; |
| 519 | }; |
| 520 | |
| 521 | class PathEqualityBench : public RandomPathBench { |
| 522 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 523 | PathEqualityBench() { } |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 524 | |
| 525 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 526 | const char* onGetName() override { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 527 | return "path_equality_50%"; |
| 528 | } |
| 529 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 530 | void onDelayedSetup() override { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 531 | fParity = 0; |
bsalomon@google.com | 6d552ee | 2012-08-14 15:10:09 +0000 | [diff] [blame] | 532 | this->createData(10, 100); |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 533 | fPaths.reset(kPathCnt); |
| 534 | fCopies.reset(kPathCnt); |
| 535 | for (int i = 0; i < kPathCnt; ++i) { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 536 | this->makePath(&fPaths[i]); |
| 537 | fCopies[i] = fPaths[i]; |
| 538 | } |
| 539 | this->finishedMakingPaths(); |
| 540 | } |
| 541 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 542 | void onDraw(int loops, SkCanvas*) override { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 543 | for (int i = 0; i < loops; ++i) { |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 544 | int idx = i & (kPathCnt - 1); |
| 545 | fParity ^= (fPaths[idx] == fCopies[idx & ~0x1]); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 549 | private: |
| 550 | bool fParity; // attempt to keep compiler from optimizing out the == |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 551 | enum { |
| 552 | // must be a pow 2 |
| 553 | kPathCnt = 1 << 5, |
| 554 | }; |
| 555 | SkAutoTArray<SkPath> fPaths; |
| 556 | SkAutoTArray<SkPath> fCopies; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 557 | typedef RandomPathBench INHERITED; |
| 558 | }; |
| 559 | |
| 560 | class SkBench_AddPathTest : public RandomPathBench { |
| 561 | public: |
| 562 | enum AddType { |
| 563 | kAdd_AddType, |
| 564 | kAddTrans_AddType, |
| 565 | kAddMatrix_AddType, |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 566 | kReverseAdd_AddType, |
| 567 | kReversePathTo_AddType, |
| 568 | }; |
| 569 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 570 | SkBench_AddPathTest(AddType type) : fType(type) { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 571 | fMatrix.setRotate(60 * SK_Scalar1); |
| 572 | } |
| 573 | |
| 574 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 575 | const char* onGetName() override { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 576 | switch (fType) { |
| 577 | case kAdd_AddType: |
| 578 | return "path_add_path"; |
| 579 | case kAddTrans_AddType: |
| 580 | return "path_add_path_trans"; |
| 581 | case kAddMatrix_AddType: |
| 582 | return "path_add_path_matrix"; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 583 | case kReverseAdd_AddType: |
| 584 | return "path_reverse_add_path"; |
| 585 | case kReversePathTo_AddType: |
| 586 | return "path_reverse_path_to"; |
| 587 | default: |
| 588 | SkDEBUGFAIL("Bad add type"); |
| 589 | return ""; |
| 590 | } |
| 591 | } |
| 592 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 593 | void onDelayedSetup() override { |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 594 | // reversePathTo assumes a single contour path. |
| 595 | bool allowMoves = kReversePathTo_AddType != fType; |
bsalomon@google.com | 6d552ee | 2012-08-14 15:10:09 +0000 | [diff] [blame] | 596 | this->createData(10, 100, allowMoves); |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 597 | fPaths0.reset(kPathCnt); |
| 598 | fPaths1.reset(kPathCnt); |
| 599 | for (int i = 0; i < kPathCnt; ++i) { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 600 | this->makePath(&fPaths0[i]); |
| 601 | this->makePath(&fPaths1[i]); |
| 602 | } |
| 603 | this->finishedMakingPaths(); |
| 604 | } |
| 605 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 606 | void onDraw(int loops, SkCanvas*) override { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 607 | switch (fType) { |
| 608 | case kAdd_AddType: |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 609 | for (int i = 0; i < loops; ++i) { |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 610 | int idx = i & (kPathCnt - 1); |
| 611 | SkPath result = fPaths0[idx]; |
| 612 | result.addPath(fPaths1[idx]); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 613 | } |
| 614 | break; |
| 615 | case kAddTrans_AddType: |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 616 | for (int i = 0; i < loops; ++i) { |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 617 | int idx = i & (kPathCnt - 1); |
| 618 | SkPath result = fPaths0[idx]; |
| 619 | result.addPath(fPaths1[idx], 2 * SK_Scalar1, 5 * SK_Scalar1); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 620 | } |
| 621 | break; |
| 622 | case kAddMatrix_AddType: |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 623 | for (int i = 0; i < loops; ++i) { |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 624 | int idx = i & (kPathCnt - 1); |
| 625 | SkPath result = fPaths0[idx]; |
| 626 | result.addPath(fPaths1[idx], fMatrix); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 627 | } |
| 628 | break; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 629 | case kReverseAdd_AddType: |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 630 | for (int i = 0; i < loops; ++i) { |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 631 | int idx = i & (kPathCnt - 1); |
| 632 | SkPath result = fPaths0[idx]; |
| 633 | result.reverseAddPath(fPaths1[idx]); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 634 | } |
| 635 | break; |
| 636 | case kReversePathTo_AddType: |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 637 | for (int i = 0; i < loops; ++i) { |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 638 | int idx = i & (kPathCnt - 1); |
| 639 | SkPath result = fPaths0[idx]; |
| 640 | result.reversePathTo(fPaths1[idx]); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 641 | } |
| 642 | break; |
| 643 | } |
| 644 | } |
| 645 | |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 646 | private: |
| 647 | AddType fType; // or reverseAddPath |
bsalomon@google.com | b5e4703 | 2012-08-14 17:49:46 +0000 | [diff] [blame] | 648 | enum { |
| 649 | // must be a pow 2 |
| 650 | kPathCnt = 1 << 5, |
| 651 | }; |
| 652 | SkAutoTArray<SkPath> fPaths0; |
| 653 | SkAutoTArray<SkPath> fPaths1; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 654 | SkMatrix fMatrix; |
| 655 | typedef RandomPathBench INHERITED; |
| 656 | }; |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 657 | |
robertphillips@google.com | 17bb458 | 2012-08-20 17:24:16 +0000 | [diff] [blame] | 658 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 659 | class CirclesBench : public Benchmark { |
robertphillips@google.com | 17bb458 | 2012-08-20 17:24:16 +0000 | [diff] [blame] | 660 | protected: |
| 661 | SkString fName; |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 662 | Flags fFlags; |
robertphillips@google.com | 17bb458 | 2012-08-20 17:24:16 +0000 | [diff] [blame] | 663 | |
robertphillips@google.com | 17bb458 | 2012-08-20 17:24:16 +0000 | [diff] [blame] | 664 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 665 | CirclesBench(Flags flags) : fFlags(flags) { |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 666 | fName.printf("circles_%s", fFlags & kStroke_Flag ? "stroke" : "fill"); |
robertphillips@google.com | 17bb458 | 2012-08-20 17:24:16 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 670 | const char* onGetName() override { |
robertphillips@google.com | 17bb458 | 2012-08-20 17:24:16 +0000 | [diff] [blame] | 671 | return fName.c_str(); |
| 672 | } |
| 673 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 674 | void onDraw(int loops, SkCanvas* canvas) override { |
robertphillips@google.com | 17bb458 | 2012-08-20 17:24:16 +0000 | [diff] [blame] | 675 | SkPaint paint; |
| 676 | |
| 677 | paint.setColor(SK_ColorBLACK); |
| 678 | paint.setAntiAlias(true); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 679 | if (fFlags & kStroke_Flag) { |
| 680 | paint.setStyle(SkPaint::kStroke_Style); |
| 681 | } |
robertphillips@google.com | 17bb458 | 2012-08-20 17:24:16 +0000 | [diff] [blame] | 682 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 683 | SkRandom rand; |
robertphillips@google.com | 17bb458 | 2012-08-20 17:24:16 +0000 | [diff] [blame] | 684 | |
| 685 | SkRect r; |
| 686 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 687 | for (int i = 0; i < loops; ++i) { |
robertphillips@google.com | 17bb458 | 2012-08-20 17:24:16 +0000 | [diff] [blame] | 688 | SkScalar radius = rand.nextUScalar1() * 3; |
| 689 | r.fLeft = rand.nextUScalar1() * 300; |
| 690 | r.fTop = rand.nextUScalar1() * 300; |
| 691 | r.fRight = r.fLeft + 2 * radius; |
| 692 | r.fBottom = r.fTop + 2 * radius; |
| 693 | |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 694 | if (fFlags & kStroke_Flag) { |
| 695 | paint.setStrokeWidth(rand.nextUScalar1() * 5.0f); |
| 696 | } |
| 697 | |
robertphillips@google.com | 17bb458 | 2012-08-20 17:24:16 +0000 | [diff] [blame] | 698 | SkPath temp; |
| 699 | |
| 700 | // mimic how Chrome does circles |
| 701 | temp.arcTo(r, 0, 0, false); |
| 702 | temp.addOval(r, SkPath::kCCW_Direction); |
| 703 | temp.arcTo(r, 360, 0, true); |
| 704 | temp.close(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 705 | |
robertphillips@google.com | 17bb458 | 2012-08-20 17:24:16 +0000 | [diff] [blame] | 706 | canvas->drawPath(temp, paint); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 711 | typedef Benchmark INHERITED; |
robertphillips@google.com | 17bb458 | 2012-08-20 17:24:16 +0000 | [diff] [blame] | 712 | }; |
| 713 | |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 714 | |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 715 | // Chrome creates its own round rects with each corner possibly being different. |
| 716 | // In its "zero radius" incarnation it creates degenerate round rects. |
skia.committer@gmail.com | 1e34ff7 | 2012-10-24 02:01:24 +0000 | [diff] [blame] | 717 | // Note: PathTest::test_arb_round_rect_is_convex and |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 718 | // test_arb_zero_rad_round_rect_is_rect perform almost exactly |
robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 719 | // the same test (but with no drawing) |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 720 | class ArbRoundRectBench : public Benchmark { |
robertphillips@google.com | f6fc3fc | 2012-10-17 15:23:21 +0000 | [diff] [blame] | 721 | protected: |
| 722 | SkString fName; |
| 723 | |
robertphillips@google.com | f6fc3fc | 2012-10-17 15:23:21 +0000 | [diff] [blame] | 724 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 725 | ArbRoundRectBench(bool zeroRad) : fZeroRad(zeroRad) { |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 726 | if (zeroRad) { |
| 727 | fName.printf("zeroradroundrect"); |
| 728 | } else { |
| 729 | fName.printf("arbroundrect"); |
| 730 | } |
robertphillips@google.com | f6fc3fc | 2012-10-17 15:23:21 +0000 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 734 | const char* onGetName() override { |
robertphillips@google.com | f6fc3fc | 2012-10-17 15:23:21 +0000 | [diff] [blame] | 735 | return fName.c_str(); |
| 736 | } |
| 737 | |
skia.committer@gmail.com | 989a95e | 2012-10-18 02:01:23 +0000 | [diff] [blame] | 738 | static void add_corner_arc(SkPath* path, const SkRect& rect, |
| 739 | SkScalar xIn, SkScalar yIn, |
robertphillips@google.com | f6fc3fc | 2012-10-17 15:23:21 +0000 | [diff] [blame] | 740 | int startAngle) |
| 741 | { |
| 742 | |
| 743 | SkScalar rx = SkMinScalar(rect.width(), xIn); |
| 744 | SkScalar ry = SkMinScalar(rect.height(), yIn); |
| 745 | |
| 746 | SkRect arcRect; |
| 747 | arcRect.set(-rx, -ry, rx, ry); |
| 748 | switch (startAngle) { |
| 749 | case 0: |
| 750 | arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom); |
| 751 | break; |
| 752 | case 90: |
| 753 | arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom); |
| 754 | break; |
| 755 | case 180: |
| 756 | arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop); |
| 757 | break; |
| 758 | case 270: |
| 759 | arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop); |
| 760 | break; |
| 761 | default: |
| 762 | break; |
| 763 | } |
| 764 | |
| 765 | path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false); |
| 766 | } |
| 767 | |
skia.committer@gmail.com | 989a95e | 2012-10-18 02:01:23 +0000 | [diff] [blame] | 768 | static void make_arb_round_rect(SkPath* path, const SkRect& r, |
robertphillips@google.com | f6fc3fc | 2012-10-17 15:23:21 +0000 | [diff] [blame] | 769 | SkScalar xCorner, SkScalar yCorner) { |
| 770 | // we are lazy here and use the same x & y for each corner |
| 771 | add_corner_arc(path, r, xCorner, yCorner, 270); |
| 772 | add_corner_arc(path, r, xCorner, yCorner, 0); |
| 773 | add_corner_arc(path, r, xCorner, yCorner, 90); |
| 774 | add_corner_arc(path, r, xCorner, yCorner, 180); |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 775 | path->close(); |
robertphillips@google.com | f6fc3fc | 2012-10-17 15:23:21 +0000 | [diff] [blame] | 776 | |
robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 777 | SkASSERT(path->isConvex()); |
robertphillips@google.com | f6fc3fc | 2012-10-17 15:23:21 +0000 | [diff] [blame] | 778 | } |
| 779 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 780 | void onDraw(int loops, SkCanvas* canvas) override { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 781 | SkRandom rand; |
robertphillips@google.com | f6fc3fc | 2012-10-17 15:23:21 +0000 | [diff] [blame] | 782 | SkRect r; |
| 783 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 784 | for (int i = 0; i < loops; ++i) { |
robertphillips@google.com | f6fc3fc | 2012-10-17 15:23:21 +0000 | [diff] [blame] | 785 | SkPaint paint; |
| 786 | paint.setColor(0xff000000 | rand.nextU()); |
| 787 | paint.setAntiAlias(true); |
| 788 | |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 789 | SkScalar size = rand.nextUScalar1() * 30; |
| 790 | if (size < SK_Scalar1) { |
robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 791 | continue; |
| 792 | } |
robertphillips@google.com | f6fc3fc | 2012-10-17 15:23:21 +0000 | [diff] [blame] | 793 | r.fLeft = rand.nextUScalar1() * 300; |
| 794 | r.fTop = rand.nextUScalar1() * 300; |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 795 | r.fRight = r.fLeft + 2 * size; |
| 796 | r.fBottom = r.fTop + 2 * size; |
robertphillips@google.com | f6fc3fc | 2012-10-17 15:23:21 +0000 | [diff] [blame] | 797 | |
| 798 | SkPath temp; |
| 799 | |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 800 | if (fZeroRad) { |
| 801 | make_arb_round_rect(&temp, r, 0, 0); |
| 802 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 803 | SkASSERT(temp.isRect(nullptr)); |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 804 | } else { |
| 805 | make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15); |
| 806 | } |
robertphillips@google.com | f6fc3fc | 2012-10-17 15:23:21 +0000 | [diff] [blame] | 807 | |
| 808 | canvas->drawPath(temp, paint); |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | private: |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 813 | bool fZeroRad; // should 0 radius rounds rects be tested? |
| 814 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 815 | typedef Benchmark INHERITED; |
robertphillips@google.com | f6fc3fc | 2012-10-17 15:23:21 +0000 | [diff] [blame] | 816 | }; |
| 817 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 818 | class ConservativelyContainsBench : public Benchmark { |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 819 | public: |
| 820 | enum Type { |
| 821 | kRect_Type, |
| 822 | kRoundRect_Type, |
| 823 | kOval_Type, |
| 824 | }; |
| 825 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 826 | ConservativelyContainsBench(Type type) { |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 827 | fParity = false; |
| 828 | fName = "conservatively_contains_"; |
| 829 | switch (type) { |
| 830 | case kRect_Type: |
| 831 | fName.append("rect"); |
| 832 | fPath.addRect(kBaseRect); |
| 833 | break; |
| 834 | case kRoundRect_Type: |
| 835 | fName.append("round_rect"); |
| 836 | fPath.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1]); |
| 837 | break; |
| 838 | case kOval_Type: |
| 839 | fName.append("oval"); |
| 840 | fPath.addOval(kBaseRect); |
| 841 | break; |
| 842 | } |
| 843 | } |
| 844 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 845 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 846 | return backend == kNonRendering_Backend; |
| 847 | } |
| 848 | |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 849 | private: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 850 | const char* onGetName() override { |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 851 | return fName.c_str(); |
| 852 | } |
| 853 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 854 | void onDraw(int loops, SkCanvas*) override { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 855 | for (int i = 0; i < loops; ++i) { |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 856 | const SkRect& rect = fQueryRects[i % kQueryRectCnt]; |
| 857 | fParity = fParity != fPath.conservativelyContainsRect(rect); |
| 858 | } |
| 859 | } |
| 860 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 861 | void onDelayedSetup() override { |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 862 | fQueryRects.setCount(kQueryRectCnt); |
| 863 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 864 | SkRandom rand; |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 865 | for (int i = 0; i < kQueryRectCnt; ++i) { |
| 866 | SkSize size; |
| 867 | SkPoint xy; |
| 868 | size.fWidth = rand.nextRangeScalar(kQueryMin.fWidth, kQueryMax.fWidth); |
| 869 | size.fHeight = rand.nextRangeScalar(kQueryMin.fHeight, kQueryMax.fHeight); |
| 870 | xy.fX = rand.nextRangeScalar(kBounds.fLeft, kBounds.fRight - size.fWidth); |
| 871 | xy.fY = rand.nextRangeScalar(kBounds.fTop, kBounds.fBottom - size.fHeight); |
| 872 | |
| 873 | fQueryRects[i] = SkRect::MakeXYWH(xy.fX, xy.fY, size.fWidth, size.fHeight); |
| 874 | } |
| 875 | } |
| 876 | |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 877 | enum { |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 878 | kQueryRectCnt = 400, |
| 879 | }; |
| 880 | static const SkRect kBounds; // bounds for all random query rects |
| 881 | static const SkSize kQueryMin; // minimum query rect size, should be <= kQueryMax |
| 882 | static const SkSize kQueryMax; // max query rect size, should < kBounds |
| 883 | static const SkRect kBaseRect; // rect that is used to construct the path |
| 884 | static const SkScalar kRRRadii[2]; // x and y radii for round rect |
| 885 | |
| 886 | SkString fName; |
| 887 | SkPath fPath; |
| 888 | bool fParity; |
| 889 | SkTDArray<SkRect> fQueryRects; |
| 890 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 891 | typedef Benchmark INHERITED; |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 892 | }; |
| 893 | |
mike@reedtribe.org | 8d55101 | 2013-04-14 02:40:50 +0000 | [diff] [blame] | 894 | /////////////////////////////////////////////////////////////////////////////// |
| 895 | |
| 896 | #include "SkGeometry.h" |
| 897 | |
reed | 5501103 | 2015-03-26 09:10:22 -0700 | [diff] [blame] | 898 | class ConicBench_Chop : public Benchmark { |
reed | b640203 | 2015-03-20 13:23:43 -0700 | [diff] [blame] | 899 | protected: |
| 900 | SkConic fRQ, fDst[2]; |
| 901 | SkString fName; |
mike@reedtribe.org | 8d55101 | 2013-04-14 02:40:50 +0000 | [diff] [blame] | 902 | public: |
reed | 5501103 | 2015-03-26 09:10:22 -0700 | [diff] [blame] | 903 | ConicBench_Chop() : fName("conic-chop") { |
mike@reedtribe.org | 8d55101 | 2013-04-14 02:40:50 +0000 | [diff] [blame] | 904 | fRQ.fPts[0].set(0, 0); |
| 905 | fRQ.fPts[1].set(100, 0); |
| 906 | fRQ.fPts[2].set(100, 100); |
| 907 | fRQ.fW = SkScalarCos(SK_ScalarPI/4); |
reed | b640203 | 2015-03-20 13:23:43 -0700 | [diff] [blame] | 908 | } |
| 909 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 910 | bool isSuitableFor(Backend backend) override { |
reed | b640203 | 2015-03-20 13:23:43 -0700 | [diff] [blame] | 911 | return backend == kNonRendering_Backend; |
mike@reedtribe.org | 8d55101 | 2013-04-14 02:40:50 +0000 | [diff] [blame] | 912 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 913 | |
mike@reedtribe.org | 8d55101 | 2013-04-14 02:40:50 +0000 | [diff] [blame] | 914 | private: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 915 | const char* onGetName() override { return fName.c_str(); } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 916 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 917 | void onDraw(int loops, SkCanvas*) override { |
reed | 5501103 | 2015-03-26 09:10:22 -0700 | [diff] [blame] | 918 | for (int i = 0; i < loops; ++i) { |
| 919 | fRQ.chop(fDst); |
mike@reedtribe.org | 8d55101 | 2013-04-14 02:40:50 +0000 | [diff] [blame] | 920 | } |
| 921 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 922 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 923 | typedef Benchmark INHERITED; |
mike@reedtribe.org | 8d55101 | 2013-04-14 02:40:50 +0000 | [diff] [blame] | 924 | }; |
reed | 5501103 | 2015-03-26 09:10:22 -0700 | [diff] [blame] | 925 | DEF_BENCH( return new ConicBench_Chop; ) |
reed | b640203 | 2015-03-20 13:23:43 -0700 | [diff] [blame] | 926 | |
reed | 5501103 | 2015-03-26 09:10:22 -0700 | [diff] [blame] | 927 | class ConicBench_EvalPos : public ConicBench_Chop { |
| 928 | const bool fUseV2; |
reed | b640203 | 2015-03-20 13:23:43 -0700 | [diff] [blame] | 929 | public: |
reed | 5501103 | 2015-03-26 09:10:22 -0700 | [diff] [blame] | 930 | ConicBench_EvalPos(bool useV2) : fUseV2(useV2) { |
reed | b640203 | 2015-03-20 13:23:43 -0700 | [diff] [blame] | 931 | fName.printf("conic-eval-pos%d", useV2); |
| 932 | } |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 933 | void onDraw(int loops, SkCanvas*) override { |
reed | b640203 | 2015-03-20 13:23:43 -0700 | [diff] [blame] | 934 | if (fUseV2) { |
| 935 | for (int i = 0; i < loops; ++i) { |
| 936 | for (int j = 0; j < 1000; ++j) { |
| 937 | fDst[0].fPts[0] = fRQ.evalAt(0.4f); |
| 938 | } |
| 939 | } |
| 940 | } else { |
| 941 | for (int i = 0; i < loops; ++i) { |
| 942 | for (int j = 0; j < 1000; ++j) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 943 | fRQ.evalAt(0.4f, &fDst[0].fPts[0], nullptr); |
reed | b640203 | 2015-03-20 13:23:43 -0700 | [diff] [blame] | 944 | } |
| 945 | } |
| 946 | } |
| 947 | } |
| 948 | }; |
| 949 | DEF_BENCH( return new ConicBench_EvalPos(false); ) |
| 950 | DEF_BENCH( return new ConicBench_EvalPos(true); ) |
| 951 | |
reed | 5501103 | 2015-03-26 09:10:22 -0700 | [diff] [blame] | 952 | class ConicBench_EvalTan : public ConicBench_Chop { |
| 953 | const bool fUseV2; |
reed | b640203 | 2015-03-20 13:23:43 -0700 | [diff] [blame] | 954 | public: |
reed | 5501103 | 2015-03-26 09:10:22 -0700 | [diff] [blame] | 955 | ConicBench_EvalTan(bool useV2) : fUseV2(useV2) { |
reed | b640203 | 2015-03-20 13:23:43 -0700 | [diff] [blame] | 956 | fName.printf("conic-eval-tan%d", useV2); |
| 957 | } |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 958 | void onDraw(int loops, SkCanvas*) override { |
reed | b640203 | 2015-03-20 13:23:43 -0700 | [diff] [blame] | 959 | if (fUseV2) { |
| 960 | for (int i = 0; i < loops; ++i) { |
| 961 | for (int j = 0; j < 1000; ++j) { |
| 962 | fDst[0].fPts[0] = fRQ.evalTangentAt(0.4f); |
| 963 | } |
| 964 | } |
| 965 | } else { |
| 966 | for (int i = 0; i < loops; ++i) { |
| 967 | for (int j = 0; j < 1000; ++j) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 968 | fRQ.evalAt(0.4f, nullptr, &fDst[0].fPts[0]); |
reed | b640203 | 2015-03-20 13:23:43 -0700 | [diff] [blame] | 969 | } |
| 970 | } |
| 971 | } |
| 972 | } |
| 973 | }; |
| 974 | DEF_BENCH( return new ConicBench_EvalTan(false); ) |
| 975 | DEF_BENCH( return new ConicBench_EvalTan(true); ) |
mike@reedtribe.org | 8d55101 | 2013-04-14 02:40:50 +0000 | [diff] [blame] | 976 | |
| 977 | /////////////////////////////////////////////////////////////////////////////// |
| 978 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 979 | static void rand_conic(SkConic* conic, SkRandom& rand) { |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 980 | for (int i = 0; i < 3; ++i) { |
| 981 | conic->fPts[i].set(rand.nextUScalar1() * 100, rand.nextUScalar1() * 100); |
| 982 | } |
| 983 | if (rand.nextUScalar1() > 0.5f) { |
| 984 | conic->fW = rand.nextUScalar1(); |
| 985 | } else { |
| 986 | conic->fW = 1 + rand.nextUScalar1() * 4; |
| 987 | } |
| 988 | } |
| 989 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 990 | class ConicBench : public Benchmark { |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 991 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 992 | ConicBench() { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 993 | SkRandom rand; |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 994 | for (int i = 0; i < CONICS; ++i) { |
| 995 | rand_conic(&fConics[i], rand); |
| 996 | } |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 997 | } |
| 998 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 999 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 1000 | return backend == kNonRendering_Backend; |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1001 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 1002 | |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1003 | protected: |
| 1004 | enum { |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1005 | CONICS = 100 |
| 1006 | }; |
| 1007 | SkConic fConics[CONICS]; |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 1008 | |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1009 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 1010 | typedef Benchmark INHERITED; |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1011 | }; |
| 1012 | |
| 1013 | class ConicBench_ComputeError : public ConicBench { |
| 1014 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1015 | ConicBench_ComputeError() {} |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 1016 | |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1017 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1018 | const char* onGetName() override { |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1019 | return "conic-compute-error"; |
| 1020 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 1021 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 1022 | void onDraw(int loops, SkCanvas*) override { |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1023 | SkVector err; |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 1024 | for (int i = 0; i < loops; ++i) { |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1025 | for (int j = 0; j < CONICS; ++j) { |
| 1026 | fConics[j].computeAsQuadError(&err); |
| 1027 | } |
| 1028 | } |
| 1029 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 1030 | |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1031 | private: |
| 1032 | typedef ConicBench INHERITED; |
| 1033 | }; |
| 1034 | |
| 1035 | class ConicBench_asQuadTol : public ConicBench { |
| 1036 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1037 | ConicBench_asQuadTol() {} |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 1038 | |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1039 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1040 | const char* onGetName() override { |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1041 | return "conic-asQuadTol"; |
| 1042 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 1043 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 1044 | void onDraw(int loops, SkCanvas*) override { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 1045 | for (int i = 0; i < loops; ++i) { |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1046 | for (int j = 0; j < CONICS; ++j) { |
| 1047 | fConics[j].asQuadTol(SK_ScalarHalf); |
| 1048 | } |
| 1049 | } |
| 1050 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 1051 | |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1052 | private: |
| 1053 | typedef ConicBench INHERITED; |
| 1054 | }; |
| 1055 | |
| 1056 | class ConicBench_quadPow2 : public ConicBench { |
| 1057 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1058 | ConicBench_quadPow2() {} |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1059 | |
| 1060 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1061 | const char* onGetName() override { |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1062 | return "conic-quadPow2"; |
| 1063 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 1064 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 1065 | void onDraw(int loops, SkCanvas*) override { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 1066 | for (int i = 0; i < loops; ++i) { |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1067 | for (int j = 0; j < CONICS; ++j) { |
| 1068 | fConics[j].computeQuadPOW2(SK_ScalarHalf); |
| 1069 | } |
| 1070 | } |
| 1071 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 1072 | |
mike@reedtribe.org | af5c506 | 2013-04-30 02:14:58 +0000 | [diff] [blame] | 1073 | private: |
| 1074 | typedef ConicBench INHERITED; |
| 1075 | }; |
| 1076 | |
| 1077 | /////////////////////////////////////////////////////////////////////////////// |
| 1078 | |
Mike Reed | 0d7dac8 | 2017-02-02 17:45:56 -0800 | [diff] [blame^] | 1079 | class TightBoundsBench : public Benchmark { |
| 1080 | SkPath fPath; |
| 1081 | SkString fName; |
| 1082 | bool (*fProc)(const SkPath&, SkRect*); |
| 1083 | |
| 1084 | public: |
| 1085 | TightBoundsBench(bool (*proc)(const SkPath&, SkRect*), const char suffix[]) : fProc(proc) { |
| 1086 | fName.printf("tight_bounds_%s", suffix); |
| 1087 | |
| 1088 | const int N = 100; |
| 1089 | SkRandom rand; |
| 1090 | for (int i = 0; i < N; ++i) { |
| 1091 | fPath.moveTo(rand.nextF()*100, rand.nextF()*100); |
| 1092 | fPath.lineTo(rand.nextF()*100, rand.nextF()*100); |
| 1093 | fPath.quadTo(rand.nextF()*100, rand.nextF()*100, rand.nextF()*100, rand.nextF()*100); |
| 1094 | fPath.conicTo(rand.nextF()*100, rand.nextF()*100, rand.nextF()*100, rand.nextF()*100, |
| 1095 | rand.nextF()*10); |
| 1096 | fPath.cubicTo(rand.nextF()*100, rand.nextF()*100, rand.nextF()*100, rand.nextF()*100, |
| 1097 | rand.nextF()*100, rand.nextF()*100); |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | protected: |
| 1102 | bool isSuitableFor(Backend backend) override { |
| 1103 | return backend == kNonRendering_Backend; |
| 1104 | } |
| 1105 | |
| 1106 | const char* onGetName() override { return fName.c_str(); } |
| 1107 | |
| 1108 | void onDraw(int loops, SkCanvas* canvas) override { |
| 1109 | SkRect bounds; |
| 1110 | for (int i = 0; i < loops*100; ++i) { |
| 1111 | fProc(fPath, &bounds); |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | private: |
| 1116 | typedef Benchmark INHERITED; |
| 1117 | }; |
| 1118 | |
| 1119 | |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1120 | const SkRect ConservativelyContainsBench::kBounds = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); |
| 1121 | const SkSize ConservativelyContainsBench::kQueryMin = SkSize::Make(SkIntToScalar(1), SkIntToScalar(1)); |
| 1122 | const SkSize ConservativelyContainsBench::kQueryMax = SkSize::Make(SkIntToScalar(40), SkIntToScalar(40)); |
| 1123 | const SkRect ConservativelyContainsBench::kBaseRect = SkRect::MakeXYWH(SkIntToScalar(25), SkIntToScalar(25), SkIntToScalar(50), SkIntToScalar(50)); |
| 1124 | const SkScalar ConservativelyContainsBench::kRRRadii[2] = {SkIntToScalar(5), SkIntToScalar(10)}; |
| 1125 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1126 | DEF_BENCH( return new TrianglePathBench(FLAGS00); ) |
| 1127 | DEF_BENCH( return new TrianglePathBench(FLAGS01); ) |
| 1128 | DEF_BENCH( return new TrianglePathBench(FLAGS10); ) |
| 1129 | DEF_BENCH( return new TrianglePathBench(FLAGS11); ) |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 1130 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1131 | DEF_BENCH( return new RectPathBench(FLAGS00); ) |
| 1132 | DEF_BENCH( return new RectPathBench(FLAGS01); ) |
| 1133 | DEF_BENCH( return new RectPathBench(FLAGS10); ) |
| 1134 | DEF_BENCH( return new RectPathBench(FLAGS11); ) |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 1135 | |
liyuqian | a27f669 | 2016-06-20 14:05:27 -0700 | [diff] [blame] | 1136 | DEF_BENCH( return new RotatedRectBench(FLAGS00, false, 45)); |
| 1137 | DEF_BENCH( return new RotatedRectBench(FLAGS10, false, 45)); |
| 1138 | DEF_BENCH( return new RotatedRectBench(FLAGS00, true, 45)); |
| 1139 | DEF_BENCH( return new RotatedRectBench(FLAGS10, true, 45)); |
| 1140 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1141 | DEF_BENCH( return new OvalPathBench(FLAGS00); ) |
| 1142 | DEF_BENCH( return new OvalPathBench(FLAGS01); ) |
| 1143 | DEF_BENCH( return new OvalPathBench(FLAGS10); ) |
| 1144 | DEF_BENCH( return new OvalPathBench(FLAGS11); ) |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 1145 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1146 | DEF_BENCH( return new CirclePathBench(FLAGS00); ) |
| 1147 | DEF_BENCH( return new CirclePathBench(FLAGS01); ) |
| 1148 | DEF_BENCH( return new CirclePathBench(FLAGS10); ) |
| 1149 | DEF_BENCH( return new CirclePathBench(FLAGS11); ) |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 1150 | |
Yuqian Li | 8eedbfc | 2017-01-11 13:55:49 +0000 | [diff] [blame] | 1151 | DEF_BENCH( return new NonAACirclePathBench(FLAGS00); ) |
| 1152 | DEF_BENCH( return new NonAACirclePathBench(FLAGS10); ) |
| 1153 | |
Yuqian Li | 131c1fb | 2016-12-12 16:24:47 -0500 | [diff] [blame] | 1154 | DEF_BENCH( return new AAAConcavePathBench(FLAGS00); ) |
| 1155 | DEF_BENCH( return new AAAConcavePathBench(FLAGS10); ) |
| 1156 | DEF_BENCH( return new AAAConvexPathBench(FLAGS00); ) |
| 1157 | DEF_BENCH( return new AAAConvexPathBench(FLAGS10); ) |
| 1158 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1159 | DEF_BENCH( return new SawToothPathBench(FLAGS00); ) |
| 1160 | DEF_BENCH( return new SawToothPathBench(FLAGS01); ) |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 1161 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1162 | DEF_BENCH( return new LongCurvedPathBench(FLAGS00); ) |
| 1163 | DEF_BENCH( return new LongCurvedPathBench(FLAGS01); ) |
| 1164 | DEF_BENCH( return new LongLinePathBench(FLAGS00); ) |
| 1165 | DEF_BENCH( return new LongLinePathBench(FLAGS01); ) |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 1166 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1167 | DEF_BENCH( return new PathCreateBench(); ) |
| 1168 | DEF_BENCH( return new PathCopyBench(); ) |
| 1169 | DEF_BENCH( return new PathTransformBench(true); ) |
| 1170 | DEF_BENCH( return new PathTransformBench(false); ) |
| 1171 | DEF_BENCH( return new PathEqualityBench(); ) |
senorblanco@chromium.org | e50f736 | 2012-01-12 19:10:35 +0000 | [diff] [blame] | 1172 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1173 | DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kAdd_AddType); ) |
| 1174 | DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kAddTrans_AddType); ) |
| 1175 | DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kAddMatrix_AddType); ) |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1176 | DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kReverseAdd_AddType); ) |
| 1177 | DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kReversePathTo_AddType); ) |
senorblanco@chromium.org | e50f736 | 2012-01-12 19:10:35 +0000 | [diff] [blame] | 1178 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1179 | DEF_BENCH( return new CirclesBench(FLAGS00); ) |
| 1180 | DEF_BENCH( return new CirclesBench(FLAGS01); ) |
| 1181 | DEF_BENCH( return new ArbRoundRectBench(false); ) |
| 1182 | DEF_BENCH( return new ArbRoundRectBench(true); ) |
| 1183 | DEF_BENCH( return new ConservativelyContainsBench(ConservativelyContainsBench::kRect_Type); ) |
| 1184 | DEF_BENCH( return new ConservativelyContainsBench(ConservativelyContainsBench::kRoundRect_Type); ) |
| 1185 | DEF_BENCH( return new ConservativelyContainsBench(ConservativelyContainsBench::kOval_Type); ) |
mike@reedtribe.org | 8d55101 | 2013-04-14 02:40:50 +0000 | [diff] [blame] | 1186 | |
Mike Reed | 0d7dac8 | 2017-02-02 17:45:56 -0800 | [diff] [blame^] | 1187 | #include "SkPathOps.h" |
| 1188 | #include "SkPathPriv.h" |
| 1189 | DEF_BENCH( return new TightBoundsBench(SkPathPriv::ComputeTightBounds, "priv"); ) |
| 1190 | DEF_BENCH( return new TightBoundsBench(TightBounds, "pathops"); ) |
reed | b640203 | 2015-03-20 13:23:43 -0700 | [diff] [blame] | 1191 | |
Mike Klein | 3f376a5 | 2014-07-16 20:23:43 -0400 | [diff] [blame] | 1192 | // These seem to be optimized away, which is troublesome for timing. |
| 1193 | /* |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1194 | DEF_BENCH( return new ConicBench_Chop5() ) |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 1195 | DEF_BENCH( return new ConicBench_ComputeError() ) |
| 1196 | DEF_BENCH( return new ConicBench_asQuadTol() ) |
| 1197 | DEF_BENCH( return new ConicBench_quadPow2() ) |
Mike Klein | 3f376a5 | 2014-07-16 20:23:43 -0400 | [diff] [blame] | 1198 | */ |