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