diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/third_party/skia/bench/PathOpsBench.cpp | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/third_party/skia/bench/PathOpsBench.cpp')
-rw-r--r-- | chromium/third_party/skia/bench/PathOpsBench.cpp | 130 |
1 files changed, 127 insertions, 3 deletions
diff --git a/chromium/third_party/skia/bench/PathOpsBench.cpp b/chromium/third_party/skia/bench/PathOpsBench.cpp index c7df558bce1..9d86c2b8981 100644 --- a/chromium/third_party/skia/bench/PathOpsBench.cpp +++ b/chromium/third_party/skia/bench/PathOpsBench.cpp @@ -78,8 +78,6 @@ protected: private: typedef Benchmark INHERITED; }; - - DEF_BENCH( return new PathOpsBench("sect", kIntersect_SkPathOp); ) DEF_BENCH( return new PathOpsBench("join", kUnion_SkPathOp); ) @@ -94,5 +92,131 @@ static SkPath makerects() { } return path; } - DEF_BENCH( return new PathOpsSimplifyBench("rects", makerects()); ) + +#include "include/core/SkPathBuilder.h" + +template <size_t N> struct ArrayPath { + SkPoint fPts[N]; + uint8_t fVbs[N]; + int fPIndex = 0, fVIndex = 0; + + void moveTo(float x, float y) { + fVbs[fVIndex++] = (uint8_t)SkPathVerb::kMove; + fPts[fPIndex++] = {x, y}; + } + void lineTo(float x, float y) { + fVbs[fVIndex++] = (uint8_t)SkPathVerb::kLine; + fPts[fPIndex++] = {x, y}; + } + void quadTo(float x, float y, float x1, float y1) { + fVbs[fVIndex++] = (uint8_t)SkPathVerb::kQuad; + fPts[fPIndex++] = {x, y}; + fPts[fPIndex++] = {x1, y1}; + } + void cubicTo(float x, float y, float x1, float y1, float x2, float y2) { + fVbs[fVIndex++] = (uint8_t)SkPathVerb::kCubic; + fPts[fPIndex++] = {x, y}; + fPts[fPIndex++] = {x1, y1}; + fPts[fPIndex++] = {x2, y2}; + } + void incReserve(int) {} +}; + +template <typename T> void run_builder(T& b, bool useReserve, int N) { + if (useReserve) { + b.incReserve(N * 12); + } + + float x = 0, y = 0; + b.moveTo(x, y); + for (int i = 1; i < N; ++i) { + b.lineTo(x, y); + b.quadTo(x, y, x, y); + b.cubicTo(x, y, x, y, x, y); + } +} + +enum class MakeType { + kPath, + kSnapshot, + kDetach, + kArray, +}; + +class PathBuilderBench : public Benchmark { + SkString fName; + MakeType fMakeType; + bool fUseReserve; + + enum { N = 100 }; + ArrayPath<N*12> fArrays; + +public: + PathBuilderBench(MakeType mt, bool reserve) : fMakeType(mt), fUseReserve(reserve) { + const char* typenames[] = { "path", "snapshot", "detach", "arrays" }; + + fName.printf("makepath_%s_%s", typenames[(int)mt], reserve ? "reserve" : "noreserve"); + } + + bool isSuitableFor(Backend backend) override { + return backend == kNonRendering_Backend; + } + +protected: + const char* onGetName() override { + return fName.c_str(); + } + + void onDelayedSetup() override { + run_builder(fArrays, false, N); + } + + SkPath build() { + switch (fMakeType) { + case MakeType::kSnapshot: + case MakeType::kDetach: { + SkPathBuilder b; + run_builder(b, fUseReserve, N); + return MakeType::kSnapshot == fMakeType ? b.snapshot() : b.detach(); + } + case MakeType::kPath: { + SkPath p; + run_builder(p, fUseReserve, N); + return p; + } + case MakeType::kArray: { + // ArrayPath<N*12> arrays; + // run_builder(arrays, false, N); + return SkPathBuilder::Make(fArrays.fPts, fArrays.fPIndex, + fArrays.fVbs, fArrays.fVIndex, + nullptr, 0, SkPathFillType::kWinding); + } + } + return SkPath(); + } + + void onDraw(int loops, SkCanvas* canvas) override { + for (int i = 0; i < loops; i++) { + for (int j = 0; j < 100; ++j) { + SkPath result = this->build(); + // force bounds calc as part of the test + if (!result.getBounds().isFinite()) { + SkDebugf("should never get here!\n"); + return; + } + } + } + } + +private: + typedef Benchmark INHERITED; +}; +DEF_BENCH( return new PathBuilderBench(MakeType::kPath, false); ) +DEF_BENCH( return new PathBuilderBench(MakeType::kSnapshot, false); ) +DEF_BENCH( return new PathBuilderBench(MakeType::kDetach, false); ) +DEF_BENCH( return new PathBuilderBench(MakeType::kPath, true); ) +DEF_BENCH( return new PathBuilderBench(MakeType::kSnapshot, true); ) +DEF_BENCH( return new PathBuilderBench(MakeType::kDetach, true); ) + +DEF_BENCH( return new PathBuilderBench(MakeType::kArray, true); ) |