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