hstern | 0446a3c | 2016-08-08 12:28:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | // for std::max |
| 9 | #include <algorithm> |
| 10 | |
| 11 | #include "Benchmark.h" |
| 12 | #include "SkCurveMeasure.h" |
| 13 | #include "SkPath.h" |
| 14 | #include "SkPathMeasure.h" |
| 15 | #include "SkString.h" |
| 16 | |
| 17 | #define NORMALIZE_LOOPS |
| 18 | |
| 19 | class MeasureBench : public Benchmark { |
| 20 | protected: |
| 21 | SkString fName; |
| 22 | |
| 23 | SkPath fPath; |
| 24 | |
| 25 | bool fUsePathMeasure; |
| 26 | float fSize; |
| 27 | size_t fPieces; |
| 28 | |
| 29 | SkPoint fPts[3]; |
| 30 | |
| 31 | public: |
| 32 | MeasureBench(bool usePathMeasure, float size, size_t pieces) |
| 33 | : fUsePathMeasure(usePathMeasure), |
| 34 | fSize(size), |
| 35 | fPieces(pieces) { |
| 36 | fName.printf("measure_%s_%.1f_" SK_SIZE_T_SPECIFIER, |
| 37 | fUsePathMeasure ? "pathMeasure" : "curveMeasure", fSize, |
| 38 | fPieces); |
| 39 | |
| 40 | auto p1 = SkPoint::Make(0, 0); |
| 41 | auto p2 = SkPoint::Make(30*fSize, 0); |
| 42 | auto p3 = SkPoint::Make(15*fSize, 15*fSize); |
| 43 | |
| 44 | fPts[0] = p1; |
| 45 | fPts[1] = p2; |
| 46 | fPts[2] = p3; |
| 47 | |
| 48 | this->setPath(); |
| 49 | } |
| 50 | |
| 51 | protected: |
| 52 | const char* onGetName() override { return fName.c_str(); } |
| 53 | |
| 54 | void setPath() { |
| 55 | fPath.moveTo(fPts[0]); |
| 56 | fPath.quadTo(fPts[1], fPts[2]); |
| 57 | } |
| 58 | |
| 59 | int numLoops() { |
| 60 | #ifdef NORMALIZE_LOOPS |
| 61 | // arbitrary heuristic |
| 62 | return std::max(2, 10000 / ((int)fSize*(int)fPieces)); |
| 63 | #else |
| 64 | return 1000; |
| 65 | #endif // NORMALIZE_LOOPS |
| 66 | } |
| 67 | |
| 68 | //// measurement code |
| 69 | |
| 70 | void do_pathMeasure(SkCanvas* canvas) { |
| 71 | SkPathMeasure meas(fPath, false); |
| 72 | |
| 73 | SkScalar totalLength = meas.getLength(); |
| 74 | SkScalar pieceLength = totalLength / fPieces; |
| 75 | |
| 76 | SkPoint point; |
| 77 | for (size_t i = 0; i <= fPieces; i++) { |
| 78 | if (meas.getPosTan(i * pieceLength, &point, nullptr)) { |
| 79 | }; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | void do_curveMeasure(SkCanvas* canvas) { |
| 84 | SkCurveMeasure meas(fPts, kQuad_SegType); |
| 85 | |
| 86 | SkScalar totalLength = meas.getLength(); |
| 87 | SkScalar pieceLength = totalLength / fPieces; |
| 88 | |
| 89 | SkPoint point; |
| 90 | for (size_t i = 0; i <= fPieces; i++) { |
hstern | 80ac591 | 2016-08-10 07:45:31 -0700 | [diff] [blame] | 91 | meas.getPosTanTime(i*pieceLength, &point, nullptr, nullptr); |
hstern | 0446a3c | 2016-08-08 12:28:13 -0700 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
| 95 | void onDraw(int loops, SkCanvas* canvas) override { |
| 96 | int inner_loops = numLoops(); |
| 97 | for (int i = 0; i < loops; i++) { |
| 98 | for (int j = 0; j < inner_loops; j++) { |
| 99 | if (fUsePathMeasure) { |
| 100 | do_pathMeasure(canvas); |
| 101 | } |
| 102 | else { |
| 103 | do_curveMeasure(canvas); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | private: |
| 110 | typedef Benchmark INHERITED; |
| 111 | }; |
| 112 | |
| 113 | /////////////////////////////////////////////////////////////////////////////// |
| 114 | |
| 115 | DEF_BENCH(return new MeasureBench(true, 1, 2);) |
| 116 | DEF_BENCH(return new MeasureBench(true, 2, 2);) |
| 117 | DEF_BENCH(return new MeasureBench(true, 10, 2);) |
| 118 | DEF_BENCH(return new MeasureBench(true, 100, 2);) |
| 119 | DEF_BENCH(return new MeasureBench(true, 1000, 2);) |
| 120 | |
| 121 | DEF_BENCH(return new MeasureBench(true, 1, 1);) |
| 122 | DEF_BENCH(return new MeasureBench(true, 1, 2);) |
| 123 | DEF_BENCH(return new MeasureBench(true, 1, 3);) |
| 124 | DEF_BENCH(return new MeasureBench(true, 1, 4);) |
| 125 | DEF_BENCH(return new MeasureBench(true, 1, 5);) |
| 126 | DEF_BENCH(return new MeasureBench(true, 2, 1);) |
| 127 | DEF_BENCH(return new MeasureBench(true, 2, 2);) |
| 128 | DEF_BENCH(return new MeasureBench(true, 2, 3);) |
| 129 | DEF_BENCH(return new MeasureBench(true, 2, 4);) |
| 130 | DEF_BENCH(return new MeasureBench(true, 2, 5);) |
| 131 | DEF_BENCH(return new MeasureBench(true, 10, 10);) |
| 132 | DEF_BENCH(return new MeasureBench(true, 10, 20);) |
| 133 | DEF_BENCH(return new MeasureBench(true, 10, 30);) |
| 134 | DEF_BENCH(return new MeasureBench(true, 10, 40);) |
| 135 | DEF_BENCH(return new MeasureBench(true, 10, 50);) |
| 136 | DEF_BENCH(return new MeasureBench(true, 100, 100);) |
| 137 | DEF_BENCH(return new MeasureBench(true, 100, 200);) |
| 138 | DEF_BENCH(return new MeasureBench(true, 100, 300);) |
| 139 | DEF_BENCH(return new MeasureBench(true, 100, 400);) |
| 140 | DEF_BENCH(return new MeasureBench(true, 100, 500);) |
| 141 | DEF_BENCH(return new MeasureBench(true, 1000, 1000);) |
| 142 | DEF_BENCH(return new MeasureBench(true, 1000, 2000);) |
| 143 | DEF_BENCH(return new MeasureBench(true, 1000, 3000);) |
| 144 | DEF_BENCH(return new MeasureBench(true, 1000, 4000);) |
| 145 | DEF_BENCH(return new MeasureBench(true, 1000, 5000);) |
| 146 | |
| 147 | DEF_BENCH(return new MeasureBench(false, 1, 2);) |
| 148 | DEF_BENCH(return new MeasureBench(false, 2, 2);) |
| 149 | DEF_BENCH(return new MeasureBench(false, 10, 2);) |
| 150 | DEF_BENCH(return new MeasureBench(false, 100, 2);) |
| 151 | DEF_BENCH(return new MeasureBench(false, 1000, 2);) |
| 152 | |
| 153 | DEF_BENCH(return new MeasureBench(false, 1, 1);) |
| 154 | DEF_BENCH(return new MeasureBench(false, 1, 2);) |
| 155 | DEF_BENCH(return new MeasureBench(false, 1, 3);) |
| 156 | DEF_BENCH(return new MeasureBench(false, 1, 4);) |
| 157 | DEF_BENCH(return new MeasureBench(false, 1, 5);) |
| 158 | DEF_BENCH(return new MeasureBench(false, 2, 1);) |
| 159 | DEF_BENCH(return new MeasureBench(false, 2, 2);) |
| 160 | DEF_BENCH(return new MeasureBench(false, 2, 3);) |
| 161 | DEF_BENCH(return new MeasureBench(false, 2, 4);) |
| 162 | DEF_BENCH(return new MeasureBench(false, 2, 5);) |
| 163 | DEF_BENCH(return new MeasureBench(false, 10, 10);) |
| 164 | DEF_BENCH(return new MeasureBench(false, 10, 20);) |
| 165 | DEF_BENCH(return new MeasureBench(false, 10, 30);) |
| 166 | DEF_BENCH(return new MeasureBench(false, 10, 40);) |
| 167 | DEF_BENCH(return new MeasureBench(false, 10, 50);) |
| 168 | DEF_BENCH(return new MeasureBench(false, 100, 100);) |
| 169 | DEF_BENCH(return new MeasureBench(false, 100, 200);) |
| 170 | DEF_BENCH(return new MeasureBench(false, 100, 300);) |
| 171 | DEF_BENCH(return new MeasureBench(false, 100, 400);) |
| 172 | DEF_BENCH(return new MeasureBench(false, 100, 500);) |
| 173 | DEF_BENCH(return new MeasureBench(false, 1000, 1000);) |
| 174 | DEF_BENCH(return new MeasureBench(false, 1000, 2000);) |
| 175 | DEF_BENCH(return new MeasureBench(false, 1000, 3000);) |
| 176 | DEF_BENCH(return new MeasureBench(false, 1000, 4000);) |
| 177 | DEF_BENCH(return new MeasureBench(false, 1000, 5000);) |