csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | */ |
| 7 | |
| 8 | #include "Benchmark.h" |
| 9 | |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 10 | #include "GrPathUtils.h" |
| 11 | #include "SkGeometry.h" |
| 12 | |
| 13 | class CubicKLMBench : public Benchmark { |
| 14 | public: |
| 15 | CubicKLMBench(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, |
| 16 | SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3) { |
| 17 | fPoints[0].set(x0, y0); |
| 18 | fPoints[1].set(x1, y1); |
| 19 | fPoints[2].set(x2, y2); |
| 20 | fPoints[3].set(x3, y3); |
| 21 | |
| 22 | fName = "cubic_klm_"; |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 23 | switch (SkClassifyCubic(fPoints)) { |
Chris Dalton | 4343654 | 2017-04-13 14:26:00 -0600 | [diff] [blame] | 24 | case SkCubicType::kSerpentine: |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 25 | fName.append("serp"); |
| 26 | break; |
Chris Dalton | 4343654 | 2017-04-13 14:26:00 -0600 | [diff] [blame] | 27 | case SkCubicType::kLoop: |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 28 | fName.append("loop"); |
| 29 | break; |
| 30 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 31 | SK_ABORT("Unexpected cubic type"); |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 32 | break; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | bool isSuitableFor(Backend backend) override { |
| 37 | return backend == kNonRendering_Backend; |
| 38 | } |
| 39 | |
| 40 | const char* onGetName() override { |
| 41 | return fName.c_str(); |
| 42 | } |
| 43 | |
| 44 | void onDraw(int loops, SkCanvas*) override { |
| 45 | SkPoint dst[10]; |
| 46 | SkMatrix klm; |
| 47 | int loopIdx; |
| 48 | for (int i = 0; i < loops * 50000; ++i) { |
| 49 | GrPathUtils::chopCubicAtLoopIntersection(fPoints, dst, &klm, &loopIdx); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | private: |
| 54 | SkPoint fPoints[4]; |
| 55 | SkString fName; |
| 56 | |
| 57 | typedef Benchmark INHERITED; |
| 58 | }; |
| 59 | |
| 60 | DEF_BENCH( return new CubicKLMBench(285.625f, 499.687f, 411.625f, 808.188f, |
| 61 | 1064.62f, 135.688f, 1042.63f, 585.187f); ) |
| 62 | DEF_BENCH( return new CubicKLMBench(635.625f, 614.687f, 171.625f, 236.188f, |
| 63 | 1064.62f, 135.688f, 516.625f, 570.187f); ) |