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 | |
| 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 | |
| 29 | class PathBench : public SkBenchmark { |
| 30 | SkPaint fPaint; |
| 31 | SkString fName; |
| 32 | Flags fFlags; |
tomhudson@google.com | ca529d3 | 2011-10-28 15:34:49 +0000 | [diff] [blame] | 33 | enum { N = SkBENCHLOOP(1000) }; |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 34 | public: |
| 35 | PathBench(void* param, Flags flags) : INHERITED(param), fFlags(flags) { |
| 36 | fPaint.setStyle(flags & kStroke_Flag ? SkPaint::kStroke_Style : |
| 37 | SkPaint::kFill_Style); |
| 38 | fPaint.setStrokeWidth(SkIntToScalar(5)); |
| 39 | fPaint.setStrokeJoin(SkPaint::kBevel_Join); |
| 40 | } |
| 41 | |
| 42 | virtual void appendName(SkString*) = 0; |
| 43 | virtual void makePath(SkPath*) = 0; |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 44 | virtual int complexity() { return 0; } |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 45 | |
| 46 | protected: |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 47 | virtual const char* onGetName() SK_OVERRIDE { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 48 | fName.printf("path_%s_%s_", |
| 49 | fFlags & kStroke_Flag ? "stroke" : "fill", |
| 50 | fFlags & kBig_Flag ? "big" : "small"); |
| 51 | this->appendName(&fName); |
| 52 | return fName.c_str(); |
| 53 | } |
| 54 | |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 55 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 56 | SkPaint paint(fPaint); |
| 57 | this->setupPaint(&paint); |
| 58 | |
| 59 | SkPath path; |
| 60 | this->makePath(&path); |
| 61 | if (fFlags & kBig_Flag) { |
| 62 | SkMatrix m; |
| 63 | m.setScale(SkIntToScalar(10), SkIntToScalar(10)); |
| 64 | path.transform(m); |
| 65 | } |
| 66 | |
| 67 | int count = N; |
| 68 | if (fFlags & kBig_Flag) { |
| 69 | count >>= 2; |
| 70 | } |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 71 | count >>= (3 * complexity()); |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 72 | |
| 73 | for (int i = 0; i < count; i++) { |
| 74 | canvas->drawPath(path, paint); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | private: |
| 79 | typedef SkBenchmark INHERITED; |
| 80 | }; |
| 81 | |
| 82 | class TrianglePathBench : public PathBench { |
| 83 | public: |
| 84 | TrianglePathBench(void* param, Flags flags) : INHERITED(param, flags) {} |
| 85 | |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 86 | virtual void appendName(SkString* name) SK_OVERRIDE { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 87 | name->append("triangle"); |
| 88 | } |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 89 | virtual void makePath(SkPath* path) SK_OVERRIDE { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 90 | static const int gCoord[] = { |
| 91 | 10, 10, 15, 5, 20, 20 |
| 92 | }; |
| 93 | path->moveTo(SkIntToScalar(gCoord[0]), SkIntToScalar(gCoord[1])); |
| 94 | path->lineTo(SkIntToScalar(gCoord[2]), SkIntToScalar(gCoord[3])); |
| 95 | path->lineTo(SkIntToScalar(gCoord[4]), SkIntToScalar(gCoord[5])); |
| 96 | path->close(); |
| 97 | } |
| 98 | private: |
| 99 | typedef PathBench INHERITED; |
| 100 | }; |
| 101 | |
| 102 | class RectPathBench : public PathBench { |
| 103 | public: |
| 104 | RectPathBench(void* param, Flags flags) : INHERITED(param, flags) {} |
| 105 | |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 106 | virtual void appendName(SkString* name) SK_OVERRIDE { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 107 | name->append("rect"); |
| 108 | } |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 109 | virtual void makePath(SkPath* path) SK_OVERRIDE { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 110 | SkRect r = { 10, 10, 20, 20 }; |
| 111 | path->addRect(r); |
| 112 | } |
| 113 | private: |
| 114 | typedef PathBench INHERITED; |
| 115 | }; |
| 116 | |
| 117 | class OvalPathBench : public PathBench { |
| 118 | public: |
| 119 | OvalPathBench(void* param, Flags flags) : INHERITED(param, flags) {} |
| 120 | |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 121 | virtual void appendName(SkString* name) SK_OVERRIDE { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 122 | name->append("oval"); |
| 123 | } |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 124 | virtual void makePath(SkPath* path) SK_OVERRIDE { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 125 | SkRect r = { 10, 10, 20, 20 }; |
| 126 | path->addOval(r); |
| 127 | } |
| 128 | private: |
| 129 | typedef PathBench INHERITED; |
| 130 | }; |
| 131 | |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 132 | class CirclePathBench: public PathBench { |
| 133 | public: |
| 134 | CirclePathBench(void* param, Flags flags) : INHERITED(param, flags) {} |
| 135 | |
| 136 | virtual void appendName(SkString* name) SK_OVERRIDE { |
| 137 | name->append("circle"); |
| 138 | } |
| 139 | virtual void makePath(SkPath* path) SK_OVERRIDE { |
| 140 | path->addCircle(SkIntToScalar(20), SkIntToScalar(20), |
| 141 | SkIntToScalar(10)); |
| 142 | } |
| 143 | private: |
| 144 | typedef PathBench INHERITED; |
| 145 | }; |
| 146 | |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 147 | class SawToothPathBench : public PathBench { |
| 148 | public: |
| 149 | SawToothPathBench(void* param, Flags flags) : INHERITED(param, flags) {} |
| 150 | |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 151 | virtual void appendName(SkString* name) SK_OVERRIDE { |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 152 | name->append("sawtooth"); |
| 153 | } |
| 154 | virtual void makePath(SkPath* path) { |
| 155 | SkScalar x = SkIntToScalar(20); |
| 156 | SkScalar y = SkIntToScalar(20); |
| 157 | const SkScalar x0 = x; |
| 158 | const SkScalar dx = SK_Scalar1 * 5; |
| 159 | const SkScalar dy = SK_Scalar1 * 10; |
| 160 | |
| 161 | path->moveTo(x, y); |
| 162 | for (int i = 0; i < 32; i++) { |
| 163 | x += dx; |
| 164 | path->lineTo(x, y - dy); |
| 165 | x += dx; |
| 166 | path->lineTo(x, y + dy); |
| 167 | } |
| 168 | path->lineTo(x, y + 2 * dy); |
| 169 | path->lineTo(x0, y + 2 * dy); |
| 170 | path->close(); |
| 171 | } |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 172 | virtual int complexity() SK_OVERRIDE { return 1; } |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 173 | private: |
| 174 | typedef PathBench INHERITED; |
| 175 | }; |
| 176 | |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 177 | class LongCurvedPathBench : public PathBench { |
| 178 | public: |
| 179 | LongCurvedPathBench(void * param, Flags flags) |
| 180 | : INHERITED(param, flags) { |
| 181 | } |
| 182 | |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 183 | virtual void appendName(SkString* name) SK_OVERRIDE { |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 184 | name->append("long_curved"); |
| 185 | } |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 186 | virtual void makePath(SkPath* path) SK_OVERRIDE { |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 187 | SkRandom rand (12); |
| 188 | int i; |
| 189 | for (i = 0; i < 100; i++) { |
| 190 | path->quadTo(SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)), |
| 191 | SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480)), |
| 192 | SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)), |
| 193 | SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480))); |
| 194 | } |
| 195 | path->close(); |
| 196 | } |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 197 | virtual int complexity() SK_OVERRIDE { return 2; } |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 198 | private: |
| 199 | typedef PathBench INHERITED; |
| 200 | }; |
| 201 | |
senorblanco@chromium.org | e50f736 | 2012-01-12 19:10:35 +0000 | [diff] [blame] | 202 | class LongLinePathBench : public PathBench { |
| 203 | public: |
| 204 | LongLinePathBench(void * param, Flags flags) |
| 205 | : INHERITED(param, flags) { |
| 206 | } |
| 207 | |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 208 | virtual void appendName(SkString* name) SK_OVERRIDE { |
senorblanco@chromium.org | e50f736 | 2012-01-12 19:10:35 +0000 | [diff] [blame] | 209 | name->append("long_line"); |
| 210 | } |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 211 | virtual void makePath(SkPath* path) SK_OVERRIDE { |
senorblanco@chromium.org | e50f736 | 2012-01-12 19:10:35 +0000 | [diff] [blame] | 212 | SkRandom rand; |
| 213 | path->moveTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); |
| 214 | for (size_t i = 1; i < 100; i++) { |
| 215 | path->lineTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); |
| 216 | } |
| 217 | } |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 218 | virtual int complexity() SK_OVERRIDE { return 2; } |
senorblanco@chromium.org | e50f736 | 2012-01-12 19:10:35 +0000 | [diff] [blame] | 219 | private: |
| 220 | typedef PathBench INHERITED; |
| 221 | }; |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 222 | |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame^] | 223 | class RandomPathBench : public SkBenchmark { |
| 224 | public: |
| 225 | RandomPathBench(void* param) : INHERITED(param) { |
| 226 | } |
| 227 | |
| 228 | protected: |
| 229 | void createData(int minVerbs, |
| 230 | int maxVerbs, |
| 231 | int pathCnt, |
| 232 | bool allowMoves = true, |
| 233 | SkRect* bounds = NULL) { |
| 234 | SkRect tempBounds; |
| 235 | if (NULL == bounds) { |
| 236 | tempBounds.setXYWH(0, 0, SK_Scalar1, SK_Scalar1); |
| 237 | bounds = &tempBounds; |
| 238 | } |
| 239 | fVerbCnts.setReserve(pathCnt); |
| 240 | for (int i = 0; i < pathCnt; ++i) { |
| 241 | int vCount = fRandom.nextRangeU(minVerbs, maxVerbs + 1); |
| 242 | *fVerbCnts.append() = vCount; |
| 243 | for (int v = 0; v < vCount; ++v) { |
| 244 | int verb = fRandom.nextULessThan(SkPath::kDone_Verb); |
| 245 | if (SkPath::kMove_Verb == verb && !allowMoves) { |
| 246 | --v; |
| 247 | continue; |
| 248 | } |
| 249 | *fVerbs.append() = static_cast<SkPath::Verb>(verb); |
| 250 | static const int gPointCnt[] = { |
| 251 | 1, // kMove |
| 252 | 1, // kLine |
| 253 | 2, // kQuad |
| 254 | 3, // kCubic |
| 255 | 0, // kClose |
| 256 | }; |
| 257 | int pCnt = gPointCnt[verb]; |
| 258 | for (int p = 0; p < pCnt; ++p) { |
| 259 | fPoints.append()->set(fRandom.nextRangeScalar(bounds->fLeft, bounds->fRight), |
| 260 | fRandom.nextRangeScalar(bounds->fTop, bounds->fBottom)); |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | this->restartMakingPaths(); |
| 265 | } |
| 266 | |
| 267 | void restartMakingPaths() { |
| 268 | fCurrPath = 0; |
| 269 | fCurrVerb = 0; |
| 270 | fCurrPoint = 0; |
| 271 | } |
| 272 | |
| 273 | void makePath(SkPath* path) { |
| 274 | int vCount = fVerbCnts[fCurrPath++]; |
| 275 | for (int v = 0; v < vCount; ++v) { |
| 276 | switch (fVerbs[fCurrVerb++]) { |
| 277 | case SkPath::kMove_Verb: |
| 278 | path->moveTo(fPoints[fCurrPoint]); |
| 279 | ++fCurrPoint; |
| 280 | break; |
| 281 | case SkPath::kLine_Verb: |
| 282 | path->lineTo(fPoints[fCurrPoint]); |
| 283 | ++fCurrPoint; |
| 284 | break; |
| 285 | case SkPath::kQuad_Verb: |
| 286 | path->quadTo(fPoints[fCurrPoint], fPoints[fCurrPoint + 1]); |
| 287 | fCurrPoint += 2; |
| 288 | break; |
| 289 | case SkPath::kCubic_Verb: |
| 290 | path->cubicTo(fPoints[fCurrPoint], |
| 291 | fPoints[fCurrPoint + 1], |
| 292 | fPoints[fCurrPoint + 2]); |
| 293 | fCurrPoint += 3; |
| 294 | break; |
| 295 | case SkPath::kClose_Verb: |
| 296 | path->close(); |
| 297 | break; |
| 298 | default: |
| 299 | SkDEBUGFAIL("Unexpected path verb"); |
| 300 | break; |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | void finishedMakingPaths() { |
| 306 | fVerbCnts.reset(); |
| 307 | fVerbs.reset(); |
| 308 | fPoints.reset(); |
| 309 | } |
| 310 | |
| 311 | private: |
| 312 | SkTDArray<int> fVerbCnts; |
| 313 | SkTDArray<SkPath::Verb> fVerbs; |
| 314 | SkTDArray<SkPoint> fPoints; |
| 315 | int fCurrPath; |
| 316 | int fCurrVerb; |
| 317 | int fCurrPoint; |
| 318 | SkRandom fRandom; |
| 319 | typedef SkBenchmark INHERITED; |
| 320 | }; |
| 321 | |
| 322 | class PathCreateBench : public RandomPathBench { |
| 323 | public: |
| 324 | PathCreateBench(void* param) : INHERITED(param) { |
| 325 | } |
| 326 | |
| 327 | protected: |
| 328 | enum { N = SkBENCHLOOP(5000) }; |
| 329 | |
| 330 | virtual const char* onGetName() SK_OVERRIDE { |
| 331 | return "path_create"; |
| 332 | } |
| 333 | |
| 334 | virtual void onPreDraw() SK_OVERRIDE { |
| 335 | this->createData(10, 100, N); |
| 336 | SkASSERT(0 == fPaths.count()); |
| 337 | fPaths.resize_back(N); |
| 338 | } |
| 339 | |
| 340 | virtual void onDraw(SkCanvas*) SK_OVERRIDE { |
| 341 | for (int i = 0; i < N; ++i) { |
| 342 | this->makePath(&fPaths[i]); |
| 343 | } |
| 344 | this->restartMakingPaths(); |
| 345 | } |
| 346 | |
| 347 | virtual void onPostDraw() SK_OVERRIDE { |
| 348 | this->finishedMakingPaths(); |
| 349 | fPaths.reset(); |
| 350 | } |
| 351 | |
| 352 | private: |
| 353 | SkTArray<SkPath> fPaths; |
| 354 | |
| 355 | typedef RandomPathBench INHERITED; |
| 356 | }; |
| 357 | |
| 358 | class PathCopyBench : public RandomPathBench { |
| 359 | public: |
| 360 | PathCopyBench(void* param) : INHERITED(param) { |
| 361 | } |
| 362 | |
| 363 | protected: |
| 364 | enum { N = SkBENCHLOOP(50000) }; |
| 365 | |
| 366 | virtual const char* onGetName() SK_OVERRIDE { |
| 367 | return "path_copy"; |
| 368 | } |
| 369 | virtual void onPreDraw() SK_OVERRIDE { |
| 370 | this->createData(10, 100, N); |
| 371 | SkASSERT(0 == fPaths.count()); |
| 372 | fPaths.resize_back(N); |
| 373 | fCopies.resize_back(N); |
| 374 | for (int i = 0; i < N; ++i) { |
| 375 | this->makePath(&fPaths[i]); |
| 376 | } |
| 377 | this->finishedMakingPaths(); |
| 378 | } |
| 379 | virtual void onDraw(SkCanvas*) SK_OVERRIDE { |
| 380 | for (int i = 0; i < N; ++i) { |
| 381 | fCopies[i] = fPaths[i]; |
| 382 | } |
| 383 | } |
| 384 | virtual void onPostDraw() SK_OVERRIDE { |
| 385 | fPaths.reset(); |
| 386 | fCopies.reset(); |
| 387 | } |
| 388 | |
| 389 | private: |
| 390 | SkTArray<SkPath> fPaths; |
| 391 | SkTArray<SkPath> fCopies; |
| 392 | |
| 393 | typedef RandomPathBench INHERITED; |
| 394 | }; |
| 395 | |
| 396 | class PathTransformBench : public RandomPathBench { |
| 397 | public: |
| 398 | PathTransformBench(bool inPlace, void* param) |
| 399 | : INHERITED(param) |
| 400 | , fInPlace(inPlace) { |
| 401 | } |
| 402 | |
| 403 | protected: |
| 404 | enum { N = SkBENCHLOOP(30000) }; |
| 405 | |
| 406 | virtual const char* onGetName() SK_OVERRIDE { |
| 407 | return fInPlace ? "path_transform_in_place" : "path_transform_copy"; |
| 408 | } |
| 409 | |
| 410 | virtual void onPreDraw() SK_OVERRIDE { |
| 411 | fMatrix.setScale(5 * SK_Scalar1, 6 * SK_Scalar1); |
| 412 | this->createData(10, 100, N); |
| 413 | SkASSERT(0 == fPaths.count()); |
| 414 | SkASSERT(0 == fTransformed.count()); |
| 415 | fPaths.resize_back(N); |
| 416 | for (int i = 0; i < N; ++i) { |
| 417 | this->makePath(&fPaths[i]); |
| 418 | } |
| 419 | if (!fInPlace) { |
| 420 | fTransformed.resize_back(N); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | virtual void onDraw(SkCanvas*) SK_OVERRIDE { |
| 425 | if (fInPlace) { |
| 426 | for (int i = 0; i < N; ++i) { |
| 427 | fPaths[i].transform(fMatrix); |
| 428 | } |
| 429 | } else { |
| 430 | for (int i = 0; i < N; ++i) { |
| 431 | fPaths[i].transform(fMatrix, &fTransformed[i]); |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | virtual void onPostDraw() SK_OVERRIDE { |
| 437 | fPaths.reset(); |
| 438 | fTransformed.reset(); |
| 439 | } |
| 440 | |
| 441 | private: |
| 442 | SkTArray<SkPath> fPaths; |
| 443 | SkTArray<SkPath> fTransformed; |
| 444 | SkMatrix fMatrix; |
| 445 | bool fInPlace; |
| 446 | typedef RandomPathBench INHERITED; |
| 447 | }; |
| 448 | |
| 449 | class PathEqualityBench : public RandomPathBench { |
| 450 | public: |
| 451 | PathEqualityBench(void* param) |
| 452 | : INHERITED(param) { |
| 453 | } |
| 454 | |
| 455 | protected: |
| 456 | enum { N = SkBENCHLOOP(40000) }; |
| 457 | |
| 458 | virtual const char* onGetName() SK_OVERRIDE { |
| 459 | return "path_equality_50%"; |
| 460 | } |
| 461 | |
| 462 | virtual void onPreDraw() SK_OVERRIDE { |
| 463 | fParity = 0; |
| 464 | this->createData(10, 100, N); |
| 465 | SkASSERT(0 == fPaths.count()); |
| 466 | SkASSERT(0 == fCopies.count()); |
| 467 | fPaths.resize_back(N); |
| 468 | fCopies.resize_back(N); |
| 469 | for (int i = 0; i < N; ++i) { |
| 470 | this->makePath(&fPaths[i]); |
| 471 | fCopies[i] = fPaths[i]; |
| 472 | } |
| 473 | this->finishedMakingPaths(); |
| 474 | } |
| 475 | |
| 476 | virtual void onDraw(SkCanvas*) SK_OVERRIDE { |
| 477 | for (int i = 0; i < N; ++i) { |
| 478 | fParity ^= (fPaths[i] == fCopies[i & ~0x1]); |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | virtual void onPostDraw() SK_OVERRIDE { |
| 483 | fPaths.reset(); |
| 484 | } |
| 485 | |
| 486 | private: |
| 487 | bool fParity; // attempt to keep compiler from optimizing out the == |
| 488 | SkTArray<SkPath> fPaths; |
| 489 | SkTArray<SkPath> fCopies; |
| 490 | typedef RandomPathBench INHERITED; |
| 491 | }; |
| 492 | |
| 493 | class SkBench_AddPathTest : public RandomPathBench { |
| 494 | public: |
| 495 | enum AddType { |
| 496 | kAdd_AddType, |
| 497 | kAddTrans_AddType, |
| 498 | kAddMatrix_AddType, |
| 499 | kPathTo_AddType, |
| 500 | kReverseAdd_AddType, |
| 501 | kReversePathTo_AddType, |
| 502 | }; |
| 503 | |
| 504 | SkBench_AddPathTest(AddType type, void* param) |
| 505 | : INHERITED(param) |
| 506 | , fType(type) { |
| 507 | fMatrix.setRotate(60 * SK_Scalar1); |
| 508 | } |
| 509 | |
| 510 | protected: |
| 511 | enum { N = SkBENCHLOOP(15000) }; |
| 512 | |
| 513 | virtual const char* onGetName() SK_OVERRIDE { |
| 514 | switch (fType) { |
| 515 | case kAdd_AddType: |
| 516 | return "path_add_path"; |
| 517 | case kAddTrans_AddType: |
| 518 | return "path_add_path_trans"; |
| 519 | case kAddMatrix_AddType: |
| 520 | return "path_add_path_matrix"; |
| 521 | case kPathTo_AddType: |
| 522 | return "path_path_to"; |
| 523 | case kReverseAdd_AddType: |
| 524 | return "path_reverse_add_path"; |
| 525 | case kReversePathTo_AddType: |
| 526 | return "path_reverse_path_to"; |
| 527 | default: |
| 528 | SkDEBUGFAIL("Bad add type"); |
| 529 | return ""; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | virtual void onPreDraw() SK_OVERRIDE { |
| 534 | // pathTo and reversePathTo assume a single contour path. |
| 535 | bool allowMoves = kPathTo_AddType != fType && |
| 536 | kReversePathTo_AddType != fType; |
| 537 | this->createData(10, 100, 2 * N, allowMoves); |
| 538 | SkASSERT(0 == fPaths0.count()); |
| 539 | SkASSERT(0 == fPaths1.count()); |
| 540 | fPaths0.resize_back(N); |
| 541 | fPaths1.resize_back(N); |
| 542 | for (int i = 0; i < N; ++i) { |
| 543 | this->makePath(&fPaths0[i]); |
| 544 | this->makePath(&fPaths1[i]); |
| 545 | } |
| 546 | this->finishedMakingPaths(); |
| 547 | } |
| 548 | |
| 549 | virtual void onDraw(SkCanvas*) SK_OVERRIDE { |
| 550 | switch (fType) { |
| 551 | case kAdd_AddType: |
| 552 | for (int i = 0; i < N; ++i) { |
| 553 | SkPath result = fPaths0[i]; |
| 554 | result.addPath(fPaths1[i]); |
| 555 | } |
| 556 | break; |
| 557 | case kAddTrans_AddType: |
| 558 | for (int i = 0; i < N; ++i) { |
| 559 | SkPath result = fPaths0[i]; |
| 560 | result.addPath(fPaths1[i], 2 * SK_Scalar1, 5 * SK_Scalar1); |
| 561 | } |
| 562 | break; |
| 563 | case kAddMatrix_AddType: |
| 564 | for (int i = 0; i < N; ++i) { |
| 565 | SkPath result = fPaths0[i]; |
| 566 | result.addPath(fPaths1[i], fMatrix); |
| 567 | } |
| 568 | break; |
| 569 | case kPathTo_AddType: |
| 570 | for (int i = 0; i < N; ++i) { |
| 571 | SkPath result = fPaths0[i]; |
| 572 | result.pathTo(fPaths1[i]); |
| 573 | } |
| 574 | break; |
| 575 | case kReverseAdd_AddType: |
| 576 | for (int i = 0; i < N; ++i) { |
| 577 | SkPath result = fPaths0[i]; |
| 578 | result.reverseAddPath(fPaths1[i]); |
| 579 | } |
| 580 | break; |
| 581 | case kReversePathTo_AddType: |
| 582 | for (int i = 0; i < N; ++i) { |
| 583 | SkPath result = fPaths0[i]; |
| 584 | result.reversePathTo(fPaths1[i]); |
| 585 | } |
| 586 | break; |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | virtual void onPostDraw() SK_OVERRIDE { |
| 591 | fPaths0.reset(); |
| 592 | fPaths1.reset(); |
| 593 | } |
| 594 | |
| 595 | private: |
| 596 | AddType fType; // or reverseAddPath |
| 597 | SkTArray<SkPath> fPaths0; |
| 598 | SkTArray<SkPath> fPaths1; |
| 599 | SkMatrix fMatrix; |
| 600 | typedef RandomPathBench INHERITED; |
| 601 | }; |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 602 | |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 603 | static SkBenchmark* FactT00(void* p) { return new TrianglePathBench(p, FLAGS00); } |
| 604 | static SkBenchmark* FactT01(void* p) { return new TrianglePathBench(p, FLAGS01); } |
| 605 | static SkBenchmark* FactT10(void* p) { return new TrianglePathBench(p, FLAGS10); } |
| 606 | static SkBenchmark* FactT11(void* p) { return new TrianglePathBench(p, FLAGS11); } |
| 607 | |
| 608 | static SkBenchmark* FactR00(void* p) { return new RectPathBench(p, FLAGS00); } |
| 609 | static SkBenchmark* FactR01(void* p) { return new RectPathBench(p, FLAGS01); } |
| 610 | static SkBenchmark* FactR10(void* p) { return new RectPathBench(p, FLAGS10); } |
| 611 | static SkBenchmark* FactR11(void* p) { return new RectPathBench(p, FLAGS11); } |
| 612 | |
| 613 | static SkBenchmark* FactO00(void* p) { return new OvalPathBench(p, FLAGS00); } |
| 614 | static SkBenchmark* FactO01(void* p) { return new OvalPathBench(p, FLAGS01); } |
| 615 | static SkBenchmark* FactO10(void* p) { return new OvalPathBench(p, FLAGS10); } |
| 616 | static SkBenchmark* FactO11(void* p) { return new OvalPathBench(p, FLAGS11); } |
| 617 | |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 618 | static SkBenchmark* FactC00(void* p) { return new CirclePathBench(p, FLAGS00); } |
| 619 | static SkBenchmark* FactC01(void* p) { return new CirclePathBench(p, FLAGS01); } |
| 620 | static SkBenchmark* FactC10(void* p) { return new CirclePathBench(p, FLAGS10); } |
| 621 | static SkBenchmark* FactC11(void* p) { return new CirclePathBench(p, FLAGS11); } |
| 622 | |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 623 | static SkBenchmark* FactS00(void* p) { return new SawToothPathBench(p, FLAGS00); } |
| 624 | static SkBenchmark* FactS01(void* p) { return new SawToothPathBench(p, FLAGS01); } |
| 625 | |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 626 | static SkBenchmark* FactLC00(void* p) { |
| 627 | return new LongCurvedPathBench(p, FLAGS00); |
| 628 | } |
| 629 | static SkBenchmark* FactLC01(void* p) { |
| 630 | return new LongCurvedPathBench(p, FLAGS01); |
| 631 | } |
| 632 | |
senorblanco@chromium.org | e50f736 | 2012-01-12 19:10:35 +0000 | [diff] [blame] | 633 | static SkBenchmark* FactLL00(void* p) { |
| 634 | return new LongLinePathBench(p, FLAGS00); |
| 635 | } |
| 636 | |
| 637 | static SkBenchmark* FactLL01(void* p) { |
| 638 | return new LongLinePathBench(p, FLAGS01); |
| 639 | } |
| 640 | |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 641 | static BenchRegistry gRegT00(FactT00); |
| 642 | static BenchRegistry gRegT01(FactT01); |
| 643 | static BenchRegistry gRegT10(FactT10); |
| 644 | static BenchRegistry gRegT11(FactT11); |
| 645 | |
| 646 | static BenchRegistry gRegR00(FactR00); |
| 647 | static BenchRegistry gRegR01(FactR01); |
| 648 | static BenchRegistry gRegR10(FactR10); |
| 649 | static BenchRegistry gRegR11(FactR11); |
| 650 | |
| 651 | static BenchRegistry gRegO00(FactO00); |
| 652 | static BenchRegistry gRegO01(FactO01); |
| 653 | static BenchRegistry gRegO10(FactO10); |
| 654 | static BenchRegistry gRegO11(FactO11); |
| 655 | |
bsalomon@google.com | 1647a19 | 2012-04-11 15:34:46 +0000 | [diff] [blame] | 656 | static BenchRegistry gRegC00(FactC00); |
| 657 | static BenchRegistry gRegC01(FactC01); |
| 658 | static BenchRegistry gRegC10(FactC10); |
| 659 | static BenchRegistry gRegC11(FactC11); |
| 660 | |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 661 | static BenchRegistry gRegS00(FactS00); |
| 662 | static BenchRegistry gRegS01(FactS01); |
| 663 | |
tomhudson@google.com | 6e8d335 | 2011-06-22 17:16:35 +0000 | [diff] [blame] | 664 | static BenchRegistry gRegLC00(FactLC00); |
| 665 | static BenchRegistry gRegLC01(FactLC01); |
| 666 | |
senorblanco@chromium.org | e50f736 | 2012-01-12 19:10:35 +0000 | [diff] [blame] | 667 | static BenchRegistry gRegLL00(FactLL00); |
| 668 | static BenchRegistry gRegLL01(FactLL01); |
| 669 | |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame^] | 670 | static SkBenchmark* FactCreate(void* p) { return new PathCreateBench(p); } |
| 671 | static BenchRegistry gRegCreate(FactCreate); |
| 672 | |
| 673 | static SkBenchmark* FactCopy(void* p) { return new PathCopyBench(p); } |
| 674 | static BenchRegistry gRegCopy(FactCopy); |
| 675 | |
| 676 | static SkBenchmark* FactPathTransformInPlace(void* p) { return new PathTransformBench(true, p); } |
| 677 | static BenchRegistry gRegPathTransformInPlace(FactPathTransformInPlace); |
| 678 | |
| 679 | static SkBenchmark* FactPathTransformCopy(void* p) { return new PathTransformBench(false, p); } |
| 680 | static BenchRegistry gRegPathTransformCopy(FactPathTransformCopy); |
| 681 | |
| 682 | static SkBenchmark* FactEquality(void* p) { return new PathEqualityBench(p); } |
| 683 | static BenchRegistry gRegEquality(FactEquality); |
| 684 | |
| 685 | static SkBenchmark* FactAdd(void* p) { return new SkBench_AddPathTest(SkBench_AddPathTest::kAdd_AddType, p); } |
| 686 | static SkBenchmark* FactAddTrans(void* p) { return new SkBench_AddPathTest(SkBench_AddPathTest::kAddTrans_AddType, p); } |
| 687 | static SkBenchmark* FactAddMatrix(void* p) { return new SkBench_AddPathTest(SkBench_AddPathTest::kAddMatrix_AddType, p); } |
| 688 | static SkBenchmark* FactPathTo(void* p) { return new SkBench_AddPathTest(SkBench_AddPathTest::kPathTo_AddType, p); } |
| 689 | static SkBenchmark* FactReverseAdd(void* p) { return new SkBench_AddPathTest(SkBench_AddPathTest::kReverseAdd_AddType, p); } |
| 690 | static SkBenchmark* FactReverseTo(void* p) { return new SkBench_AddPathTest(SkBench_AddPathTest::kReversePathTo_AddType, p); } |
| 691 | |
| 692 | static BenchRegistry gRegAdd(FactAdd); |
| 693 | static BenchRegistry gRegAddTrans(FactAddTrans); |
| 694 | static BenchRegistry gRegAddMatrix(FactAddMatrix); |
| 695 | static BenchRegistry gRegPathTo(FactPathTo); |
| 696 | static BenchRegistry gRegReverseAdd(FactReverseAdd); |
| 697 | static BenchRegistry gRegReverseTo(FactReverseTo); |