Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 "bench/Benchmark.h" |
Robert Phillips | f028810 | 2020-07-06 13:45:34 -0400 | [diff] [blame] | 9 | #include "include/gpu/GrDirectContext.h" |
Chris Dalton | f6bf516 | 2020-05-13 19:18:46 -0600 | [diff] [blame] | 10 | #include "src/core/SkPathPriv.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 11 | #include "src/gpu/GrDirectContextPriv.h" |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 12 | #include "src/gpu/GrOpFlushState.h" |
Chris Dalton | 90ad0fe | 2020-11-09 14:13:39 -0700 | [diff] [blame] | 13 | #include "src/gpu/mock/GrMockOpTarget.h" |
Chris Dalton | b5391d9 | 2020-05-24 14:55:54 -0600 | [diff] [blame] | 14 | #include "src/gpu/tessellate/GrMiddleOutPolygonTriangulator.h" |
Chris Dalton | 078f875 | 2020-07-30 19:50:46 -0600 | [diff] [blame] | 15 | #include "src/gpu/tessellate/GrPathTessellateOp.h" |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 16 | #include "src/gpu/tessellate/GrStrokeIndirectOp.h" |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 17 | #include "src/gpu/tessellate/GrStrokeTessellateOp.h" |
Chris Dalton | f6bf516 | 2020-05-13 19:18:46 -0600 | [diff] [blame] | 18 | #include "src/gpu/tessellate/GrWangsFormula.h" |
Chris Dalton | f5132a0 | 2020-04-27 23:40:03 -0600 | [diff] [blame] | 19 | #include "tools/ToolUtils.h" |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 20 | #include <vector> |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 21 | |
| 22 | // This is the number of cubics in desk_chalkboard.skp. (There are no quadratics in the chalkboard.) |
| 23 | constexpr static int kNumCubicsInChalkboard = 47182; |
| 24 | |
Chris Dalton | 90ad0fe | 2020-11-09 14:13:39 -0700 | [diff] [blame] | 25 | static sk_sp<GrDirectContext> make_mock_context() { |
| 26 | GrMockOptions mockOptions; |
| 27 | mockOptions.fDrawInstancedSupport = true; |
| 28 | mockOptions.fMaxTessellationSegments = 64; |
| 29 | mockOptions.fMapBufferFlags = GrCaps::kCanMap_MapFlag; |
| 30 | mockOptions.fConfigOptions[(int)GrColorType::kAlpha_8].fRenderability = |
| 31 | GrMockOptions::ConfigOptions::Renderability::kMSAA; |
| 32 | mockOptions.fConfigOptions[(int)GrColorType::kAlpha_8].fTexturable = true; |
| 33 | mockOptions.fIntegerSupport = true; |
| 34 | |
| 35 | GrContextOptions ctxOptions; |
| 36 | ctxOptions.fGpuPathRenderers = GpuPathRenderers::kTessellation; |
Chris Dalton | 15f5184 | 2020-12-15 19:55:10 -0700 | [diff] [blame] | 37 | ctxOptions.fSuppressTessellationShaders = false; |
Chris Dalton | 90ad0fe | 2020-11-09 14:13:39 -0700 | [diff] [blame] | 38 | |
| 39 | return GrDirectContext::MakeMock(&mockOptions, ctxOptions); |
| 40 | } |
| 41 | |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 42 | static SkPath make_cubic_path() { |
| 43 | SkRandom rand; |
| 44 | SkPath path; |
| 45 | for (int i = 0; i < kNumCubicsInChalkboard/2; ++i) { |
Chris Dalton | 2f2d81c | 2020-05-13 17:57:37 -0600 | [diff] [blame] | 46 | float x = std::ldexp(rand.nextF(), (i % 18)) / 1e3f; |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 47 | path.cubicTo(111.625f*x, 308.188f*x, 764.62f*x, -435.688f*x, 742.63f*x, 85.187f*x); |
| 48 | path.cubicTo(764.62f*x, -435.688f*x, 111.625f*x, 308.188f*x, 0, 0); |
| 49 | } |
| 50 | return path; |
| 51 | } |
| 52 | |
Chris Dalton | 078f875 | 2020-07-30 19:50:46 -0600 | [diff] [blame] | 53 | // This serves as a base class for benchmarking individual methods on GrPathTessellateOp. |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 54 | class PathTessellateBenchmark : public Benchmark { |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 55 | public: |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 56 | PathTessellateBenchmark(const char* subName, const SkPath& p, const SkMatrix& m) |
| 57 | : fPath(p), fMatrix(m) { |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 58 | fName.printf("tessellate_%s", subName); |
| 59 | } |
| 60 | |
| 61 | const char* onGetName() override { return fName.c_str(); } |
| 62 | bool isSuitableFor(Backend backend) final { return backend == kNonRendering_Backend; } |
| 63 | |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 64 | protected: |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 65 | void onDelayedSetup() override { |
Chris Dalton | 90ad0fe | 2020-11-09 14:13:39 -0700 | [diff] [blame] | 66 | fTarget = std::make_unique<GrMockOpTarget>(make_mock_context()); |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 69 | void onDraw(int loops, SkCanvas*) final { |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 70 | if (!fTarget->mockContext()) { |
Chris Dalton | 1443c9d | 2020-05-27 09:43:34 -0600 | [diff] [blame] | 71 | SkDebugf("ERROR: could not create mock context."); |
| 72 | return; |
| 73 | } |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 74 | for (int i = 0; i < loops; ++i) { |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 75 | this->runBench(); |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 76 | fTarget->resetAllocator(); |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 80 | virtual void runBench() = 0; |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 81 | |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 82 | SkString fName; |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 83 | std::unique_ptr<GrMockOpTarget> fTarget; |
| 84 | const SkPath fPath; |
| 85 | const SkMatrix& fMatrix; |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 86 | }; |
| 87 | |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 88 | #define DEF_PATH_TESS_BENCH(NAME, PATH, MATRIX) \ |
| 89 | class PathTessellateBenchmark_##NAME : public PathTessellateBenchmark { \ |
Chris Dalton | b5391d9 | 2020-05-24 14:55:54 -0600 | [diff] [blame] | 90 | public: \ |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 91 | PathTessellateBenchmark_##NAME() : PathTessellateBenchmark(#NAME, (PATH), (MATRIX)) {} \ |
| 92 | void runBench() override; \ |
Chris Dalton | b5391d9 | 2020-05-24 14:55:54 -0600 | [diff] [blame] | 93 | }; \ |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 94 | DEF_BENCH( return new PathTessellateBenchmark_##NAME(); ); \ |
| 95 | void PathTessellateBenchmark_##NAME::runBench() |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 96 | |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 97 | DEF_PATH_TESS_BENCH(GrPathIndirectTessellator, make_cubic_path(), SkMatrix::I()) { |
| 98 | GrPathIndirectTessellator tess(fMatrix, fPath, GrPathIndirectTessellator::DrawInnerFan::kNo); |
| 99 | tess.prepare(fTarget.get(), fMatrix, fPath); |
Chris Dalton | b5391d9 | 2020-05-24 14:55:54 -0600 | [diff] [blame] | 100 | } |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 101 | |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 102 | DEF_PATH_TESS_BENCH(GrPathOuterCurveTessellator, make_cubic_path(), SkMatrix::I()) { |
| 103 | GrPathOuterCurveTessellator tess; |
| 104 | tess.prepare(fTarget.get(), fMatrix, fPath); |
Chris Dalton | b5391d9 | 2020-05-24 14:55:54 -0600 | [diff] [blame] | 105 | } |
Chris Dalton | 7f0b897 | 2020-04-23 15:52:24 -0600 | [diff] [blame] | 106 | |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 107 | DEF_PATH_TESS_BENCH(GrPathWedgeTessellator, make_cubic_path(), SkMatrix::I()) { |
| 108 | GrPathWedgeTessellator tess; |
| 109 | tess.prepare(fTarget.get(), fMatrix, fPath); |
Chris Dalton | b5391d9 | 2020-05-24 14:55:54 -0600 | [diff] [blame] | 110 | } |
Chris Dalton | f6bf516 | 2020-05-13 19:18:46 -0600 | [diff] [blame] | 111 | |
Chris Dalton | b5391d9 | 2020-05-24 14:55:54 -0600 | [diff] [blame] | 112 | static void benchmark_wangs_formula_cubic_log2(const SkMatrix& matrix, const SkPath& path) { |
| 113 | int sum = 0; |
| 114 | GrVectorXform xform(matrix); |
| 115 | for (auto [verb, pts, w] : SkPathPriv::Iterate(path)) { |
| 116 | if (verb == SkPathVerb::kCubic) { |
| 117 | sum += GrWangsFormula::cubic_log2(4, pts, xform); |
Chris Dalton | f6bf516 | 2020-05-13 19:18:46 -0600 | [diff] [blame] | 118 | } |
| 119 | } |
Chris Dalton | b5391d9 | 2020-05-24 14:55:54 -0600 | [diff] [blame] | 120 | // Don't let the compiler optimize away GrWangsFormula::cubic_log2. |
| 121 | if (sum <= 0) { |
| 122 | SK_ABORT("sum should be > 0."); |
| 123 | } |
| 124 | } |
Chris Dalton | f6bf516 | 2020-05-13 19:18:46 -0600 | [diff] [blame] | 125 | |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 126 | DEF_PATH_TESS_BENCH(wangs_formula_cubic_log2, make_cubic_path(), SkMatrix::I()) { |
| 127 | benchmark_wangs_formula_cubic_log2(fMatrix, fPath); |
Chris Dalton | b5391d9 | 2020-05-24 14:55:54 -0600 | [diff] [blame] | 128 | } |
| 129 | |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 130 | DEF_PATH_TESS_BENCH(wangs_formula_cubic_log2_scale, make_cubic_path(), |
| 131 | SkMatrix::Scale(1.1f, 0.9f)) { |
| 132 | benchmark_wangs_formula_cubic_log2(fMatrix, fPath); |
Chris Dalton | b5391d9 | 2020-05-24 14:55:54 -0600 | [diff] [blame] | 133 | } |
| 134 | |
Chris Dalton | e206764 | 2020-09-23 11:07:20 -0600 | [diff] [blame] | 135 | DEF_PATH_TESS_BENCH(wangs_formula_cubic_log2_affine, make_cubic_path(), |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 136 | SkMatrix::MakeAll(.9f,0.9f,0, 1.1f,1.1f,0, 0,0,1)) { |
| 137 | benchmark_wangs_formula_cubic_log2(fMatrix, fPath); |
Chris Dalton | b5391d9 | 2020-05-24 14:55:54 -0600 | [diff] [blame] | 138 | } |
| 139 | |
Chris Dalton | e206764 | 2020-09-23 11:07:20 -0600 | [diff] [blame] | 140 | DEF_PATH_TESS_BENCH(middle_out_triangulation, |
| 141 | ToolUtils::make_star(SkRect::MakeWH(500, 500), kNumCubicsInChalkboard), |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 142 | SkMatrix::I()) { |
Chris Dalton | b5391d9 | 2020-05-24 14:55:54 -0600 | [diff] [blame] | 143 | int baseVertex; |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 144 | auto vertexData = static_cast<SkPoint*>(fTarget->makeVertexSpace( |
Chris Dalton | b5391d9 | 2020-05-24 14:55:54 -0600 | [diff] [blame] | 145 | sizeof(SkPoint), kNumCubicsInChalkboard, nullptr, &baseVertex)); |
Chris Dalton | d717743 | 2021-01-15 13:12:50 -0700 | [diff] [blame] | 146 | GrMiddleOutPolygonTriangulator::WritePathInnerFan(vertexData, 3, fPath); |
Chris Dalton | b5391d9 | 2020-05-24 14:55:54 -0600 | [diff] [blame] | 147 | } |
Chris Dalton | e206764 | 2020-09-23 11:07:20 -0600 | [diff] [blame] | 148 | |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 149 | class GrStrokeTessellateOp::TestingOnly_Benchmark : public Benchmark { |
Chris Dalton | 2882e70 | 2020-11-02 12:43:06 -0700 | [diff] [blame] | 150 | public: |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 151 | TestingOnly_Benchmark(float matrixScale, const char* suffix) : fMatrixScale(matrixScale) { |
| 152 | fName.printf("tessellate_GrStrokeTessellateOp_prepare%s", suffix); |
Chris Dalton | 2882e70 | 2020-11-02 12:43:06 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | private: |
| 156 | const char* onGetName() override { return fName.c_str(); } |
Chris Dalton | e206764 | 2020-09-23 11:07:20 -0600 | [diff] [blame] | 157 | bool isSuitableFor(Backend backend) final { return backend == kNonRendering_Backend; } |
| 158 | |
| 159 | void onDelayedSetup() override { |
Chris Dalton | 90ad0fe | 2020-11-09 14:13:39 -0700 | [diff] [blame] | 160 | fTarget = std::make_unique<GrMockOpTarget>(make_mock_context()); |
Chris Dalton | e206764 | 2020-09-23 11:07:20 -0600 | [diff] [blame] | 161 | fPath.reset().moveTo(0, 0); |
| 162 | for (int i = 0; i < kNumCubicsInChalkboard/2; ++i) { |
Chris Dalton | 2882e70 | 2020-11-02 12:43:06 -0700 | [diff] [blame] | 163 | fPath.cubicTo(100, 0, 50, 100, 100, 100); |
| 164 | fPath.cubicTo(0, -100, 200, 100, 0, 0); |
Chris Dalton | e206764 | 2020-09-23 11:07:20 -0600 | [diff] [blame] | 165 | } |
| 166 | fStrokeRec.setStrokeStyle(8); |
| 167 | fStrokeRec.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kMiter_Join, 4); |
| 168 | } |
| 169 | |
| 170 | void onDraw(int loops, SkCanvas*) final { |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 171 | if (!fTarget->mockContext()) { |
Chris Dalton | e206764 | 2020-09-23 11:07:20 -0600 | [diff] [blame] | 172 | SkDebugf("ERROR: could not create mock context."); |
| 173 | return; |
| 174 | } |
| 175 | for (int i = 0; i < loops; ++i) { |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 176 | GrStrokeTessellateOp op(GrAAType::kMSAA, SkMatrix::Scale(fMatrixScale, fMatrixScale), |
| 177 | fStrokeRec, fPath, GrPaint()); |
| 178 | op.fTarget = fTarget.get(); |
| 179 | op.prepareBuffers(); |
Chris Dalton | e206764 | 2020-09-23 11:07:20 -0600 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
Chris Dalton | 2882e70 | 2020-11-02 12:43:06 -0700 | [diff] [blame] | 183 | const float fMatrixScale; |
| 184 | SkString fName; |
Chris Dalton | 90ad0fe | 2020-11-09 14:13:39 -0700 | [diff] [blame] | 185 | std::unique_ptr<GrMockOpTarget> fTarget; |
Chris Dalton | e206764 | 2020-09-23 11:07:20 -0600 | [diff] [blame] | 186 | SkPath fPath; |
| 187 | SkStrokeRec fStrokeRec = SkStrokeRec(SkStrokeRec::kFill_InitStyle); |
Chris Dalton | e206764 | 2020-09-23 11:07:20 -0600 | [diff] [blame] | 188 | }; |
| 189 | |
Chris Dalton | 0e54309 | 2020-11-03 14:09:16 -0700 | [diff] [blame] | 190 | DEF_BENCH( return new GrStrokeTessellateOp::TestingOnly_Benchmark(1, ""); ) |
| 191 | DEF_BENCH( return new GrStrokeTessellateOp::TestingOnly_Benchmark(5, "_one_chop"); ) |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 192 | |
| 193 | class GrStrokeIndirectOp::Benchmark : public ::Benchmark { |
Chris Dalton | ad48280 | 2020-12-28 09:02:47 -0700 | [diff] [blame] | 194 | protected: |
| 195 | Benchmark(const char* nameSuffix, SkPaint::Join join) : fJoin(join) { |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 196 | fName.printf("tessellate_GrStrokeIndirectOpBench%s", nameSuffix); |
| 197 | } |
| 198 | |
Chris Dalton | ad48280 | 2020-12-28 09:02:47 -0700 | [diff] [blame] | 199 | const SkPaint::Join fJoin; |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 200 | |
Chris Dalton | ad48280 | 2020-12-28 09:02:47 -0700 | [diff] [blame] | 201 | private: |
| 202 | const char* onGetName() final { return fName.c_str(); } |
| 203 | bool isSuitableFor(Backend backend) final { return backend == kNonRendering_Backend; } |
| 204 | void onDelayedSetup() final { |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 205 | fTarget = std::make_unique<GrMockOpTarget>(make_mock_context()); |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 206 | fStrokeRec.setStrokeStyle(8); |
| 207 | fStrokeRec.setStrokeParams(SkPaint::kButt_Cap, fJoin, 4); |
Chris Dalton | ad48280 | 2020-12-28 09:02:47 -0700 | [diff] [blame] | 208 | this->setupPaths(&fPaths); |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 209 | } |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 210 | void onDraw(int loops, SkCanvas*) final { |
| 211 | if (!fTarget->mockContext()) { |
| 212 | SkDebugf("ERROR: could not create mock context."); |
| 213 | return; |
| 214 | } |
| 215 | for (int i = 0; i < loops; ++i) { |
Chris Dalton | ad48280 | 2020-12-28 09:02:47 -0700 | [diff] [blame] | 216 | for (const SkPath& path : fPaths) { |
| 217 | GrStrokeIndirectOp op(GrAAType::kMSAA, SkMatrix::I(), path, fStrokeRec, GrPaint()); |
| 218 | op.prePrepareResolveLevels(fTarget->allocator()); |
| 219 | op.prepareBuffers(fTarget.get()); |
| 220 | } |
| 221 | fTarget->resetAllocator(); |
| 222 | } |
| 223 | } |
| 224 | virtual void setupPaths(SkTArray<SkPath>*) = 0; |
| 225 | |
| 226 | SkString fName; |
| 227 | std::unique_ptr<GrMockOpTarget> fTarget; |
| 228 | SkTArray<SkPath> fPaths; |
| 229 | SkStrokeRec fStrokeRec{SkStrokeRec::kHairline_InitStyle}; |
| 230 | }; |
| 231 | |
| 232 | class StrokeIndirectBenchmark : public GrStrokeIndirectOp::Benchmark { |
| 233 | public: |
| 234 | StrokeIndirectBenchmark(const char* nameSuffix, SkPaint::Join join, std::vector<SkPoint> pts) |
| 235 | : Benchmark(nameSuffix, join), fPts(std::move(pts)) {} |
| 236 | |
| 237 | private: |
| 238 | void setupPaths(SkTArray<SkPath>* paths) final { |
| 239 | SkPath& path = paths->push_back(); |
| 240 | if (fJoin == SkPaint::kRound_Join) { |
| 241 | path.reset().moveTo(fPts.back()); |
| 242 | for (size_t i = 0; i < kNumCubicsInChalkboard/fPts.size(); ++i) { |
| 243 | for (size_t j = 0; j < fPts.size(); ++j) { |
| 244 | path.lineTo(fPts[j]); |
| 245 | } |
| 246 | } |
| 247 | } else { |
| 248 | path.reset().moveTo(fPts[0]); |
| 249 | for (int i = 0; i < kNumCubicsInChalkboard/2; ++i) { |
| 250 | if (fPts.size() == 4) { |
| 251 | path.cubicTo(fPts[1], fPts[2], fPts[3]); |
| 252 | path.cubicTo(fPts[2], fPts[1], fPts[0]); |
| 253 | } else { |
| 254 | SkASSERT(fPts.size() == 3); |
| 255 | path.quadTo(fPts[1], fPts[2]); |
| 256 | path.quadTo(fPts[2], fPts[1]); |
| 257 | } |
| 258 | } |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
Chris Dalton | ad48280 | 2020-12-28 09:02:47 -0700 | [diff] [blame] | 262 | const std::vector<SkPoint> fPts; |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 263 | }; |
| 264 | |
Chris Dalton | ad48280 | 2020-12-28 09:02:47 -0700 | [diff] [blame] | 265 | DEF_BENCH( return new StrokeIndirectBenchmark( |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 266 | "_inflect1", SkPaint::kBevel_Join, {{0,0}, {100,0}, {0,100}, {100,100}}); ) |
| 267 | |
Chris Dalton | ad48280 | 2020-12-28 09:02:47 -0700 | [diff] [blame] | 268 | DEF_BENCH( return new StrokeIndirectBenchmark( |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 269 | "_inflect2", SkPaint::kBevel_Join, {{37,162}, {412,160}, {249,65}, {112,360}}); ) |
| 270 | |
Chris Dalton | ad48280 | 2020-12-28 09:02:47 -0700 | [diff] [blame] | 271 | DEF_BENCH( return new StrokeIndirectBenchmark( |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 272 | "_loop", SkPaint::kBevel_Join, {{0,0}, {100,0}, {0,100}, {0,0}}); ) |
| 273 | |
Chris Dalton | ad48280 | 2020-12-28 09:02:47 -0700 | [diff] [blame] | 274 | DEF_BENCH( return new StrokeIndirectBenchmark( |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 275 | "_nochop", SkPaint::kBevel_Join, {{0,0}, {50,0}, {100,50}, {100,100}}); ) |
| 276 | |
Chris Dalton | ad48280 | 2020-12-28 09:02:47 -0700 | [diff] [blame] | 277 | DEF_BENCH( return new StrokeIndirectBenchmark( |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 278 | "_quad", SkPaint::kBevel_Join, {{0,0}, {50,100}, {100,0}}); ) |
| 279 | |
Chris Dalton | ad48280 | 2020-12-28 09:02:47 -0700 | [diff] [blame] | 280 | DEF_BENCH( return new StrokeIndirectBenchmark( |
Chris Dalton | c2a1746 | 2020-12-09 16:46:22 -0700 | [diff] [blame] | 281 | "_roundjoin", SkPaint::kRound_Join, {{0,0}, {50,100}, {100,0}}); ) |
Chris Dalton | ad48280 | 2020-12-28 09:02:47 -0700 | [diff] [blame] | 282 | |
| 283 | class SingleVerbStrokeIndirectBenchmark : public GrStrokeIndirectOp::Benchmark { |
| 284 | public: |
| 285 | SingleVerbStrokeIndirectBenchmark(const char* nameSuffix, SkPathVerb verb) |
| 286 | : Benchmark(nameSuffix, SkPaint::kBevel_Join), fVerb(verb) {} |
| 287 | |
| 288 | private: |
| 289 | void setupPaths(SkTArray<SkPath>* paths) override { |
| 290 | SkRandom rand; |
| 291 | for (int i = 0; i < kNumCubicsInChalkboard; ++i) { |
| 292 | switch (fVerb) { |
| 293 | case SkPathVerb::kQuad: |
| 294 | paths->push_back().quadTo(rand.nextF(), rand.nextF(), rand.nextF(), |
| 295 | rand.nextF()); |
| 296 | break; |
| 297 | case SkPathVerb::kCubic: |
| 298 | switch (i % 3) { |
| 299 | case 0: |
| 300 | paths->push_back().cubicTo(100, 0, 0, 100, 100, 100); // 1 inflection. |
| 301 | break; |
| 302 | case 1: |
| 303 | paths->push_back().cubicTo(100, 0, 0, 100, 0, 0); // loop. |
| 304 | break; |
| 305 | case 2: |
| 306 | paths->push_back().cubicTo(50, 0, 100, 50, 100, 100); // no chop. |
| 307 | break; |
| 308 | } |
| 309 | break; |
| 310 | default: |
| 311 | SkUNREACHABLE; |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | const SkPathVerb fVerb; |
| 317 | }; |
| 318 | |
| 319 | DEF_BENCH( return new SingleVerbStrokeIndirectBenchmark("_singlequads", SkPathVerb::kQuad); ) |
| 320 | DEF_BENCH( return new SingleVerbStrokeIndirectBenchmark("_singlecubics", SkPathVerb::kCubic); ) |