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