aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/ClipStrategyBench.cpp
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2017-11-16 09:33:36 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-24 17:12:42 +0000
commitcda4e94b0d47ddcc3bdeb1a5295f57e35c0be42e (patch)
tree3a89b67d9e09509643b016098ef17d7f8229e9df /bench/ClipStrategyBench.cpp
parente5ae84bea7ea2724c9d0ca4825eae1303440a9ac (diff)
Add a bench for comparing complex clip strategies
Clip consisting of a union of |n| circles. Comparing mask (2x saveLayer + srcIn) vs. clipPath approaches. MBP numbers: ! -> high variance, ? -> moderate variance micros bench 233.05 ! clip_strategy_mask_100 gl 207.61 ! clip_strategy_mask_10 gl 210.41 ? clip_strategy_mask_5 gl 219.10 ? clip_strategy_mask_1 gl 115.56 ? clip_strategy_path_100 gl 113.29 ! clip_strategy_path_10 gl 102.36 ? clip_strategy_path_5 gl 6.37 ? clip_strategy_path_1 gl 361.06 ! clip_strategy_mask_100 8888 328.97 ! clip_strategy_mask_10 8888 316.72 ! clip_strategy_mask_5 8888 325.84 ! clip_strategy_mask_1 8888 368.54 ! clip_strategy_path_100 8888 306.99 ! clip_strategy_path_10 8888 298.71 ! clip_strategy_path_5 8888 191.00 ! clip_strategy_path_1 8888 TBR= Change-Id: I945c12e2e35b9847af06342473e56272e2041e21 Reviewed-on: https://skia-review.googlesource.com/72521 Commit-Queue: Florin Malita <fmalita@chromium.org> Reviewed-by: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'bench/ClipStrategyBench.cpp')
-rw-r--r--bench/ClipStrategyBench.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/bench/ClipStrategyBench.cpp b/bench/ClipStrategyBench.cpp
new file mode 100644
index 0000000000..c65cf4b97d
--- /dev/null
+++ b/bench/ClipStrategyBench.cpp
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Benchmark.h"
+#include "SkCanvas.h"
+#include "SkPath.h"
+#include "SkPathOps.h"
+
+class ClipStrategyBench : public Benchmark {
+public:
+ enum class Mode {
+ kClipPath,
+ kMask,
+ };
+
+ ClipStrategyBench(Mode mode, size_t count)
+ : fMode(mode)
+ , fCount(count)
+ , fName("clip_strategy_"){
+
+ if (fMode == Mode::kClipPath) {
+ fName.append("path_");
+ this->forEachClipCircle([&](float x, float y, float r) {
+ fClipPath.addCircle(x, y, r);
+ });
+ } else {
+ fName.append("mask_");
+ }
+ fName.appendf("%zu", count);
+ }
+
+ ~ClipStrategyBench() override = default;
+
+protected:
+ const char* onGetName() override {
+ return fName.c_str();
+ }
+
+ void onDraw(int loops, SkCanvas* canvas) override {
+ SkPaint p, srcIn;
+ p.setAntiAlias(true);
+ srcIn.setBlendMode(SkBlendMode::kSrcIn);
+
+ for (int i = 0; i < loops; ++i) {
+ SkAutoCanvasRestore acr(canvas, false);
+
+ if (fMode == Mode::kClipPath) {
+ canvas->save();
+ canvas->clipPath(fClipPath, true);
+ } else {
+ canvas->saveLayer(nullptr, nullptr);
+ this->forEachClipCircle([&](float x, float y, float r) {
+ canvas->drawCircle(x, y, r, p);
+ });
+ canvas->saveLayer(nullptr, &srcIn);
+ }
+ canvas->drawColor(SK_ColorGREEN);
+ }
+ }
+
+private:
+ template <typename Func>
+ void forEachClipCircle(Func&& func) {
+ auto q = static_cast<float>(this->getSize().x()) / (fCount + 1);
+ for (size_t i = 1; i <= fCount; ++i) {
+ auto x = q * i;
+ func(x, x, q / 2);
+ }
+ }
+
+ Mode fMode;
+ size_t fCount;
+ SkString fName;
+ SkPath fClipPath;
+
+ typedef Benchmark INHERITED;
+};
+
+DEF_BENCH( return new ClipStrategyBench(ClipStrategyBench::Mode::kClipPath, 1 );)
+DEF_BENCH( return new ClipStrategyBench(ClipStrategyBench::Mode::kClipPath, 5 );)
+DEF_BENCH( return new ClipStrategyBench(ClipStrategyBench::Mode::kClipPath, 10 );)
+DEF_BENCH( return new ClipStrategyBench(ClipStrategyBench::Mode::kClipPath, 100);)
+
+DEF_BENCH( return new ClipStrategyBench(ClipStrategyBench::Mode::kMask, 1 );)
+DEF_BENCH( return new ClipStrategyBench(ClipStrategyBench::Mode::kMask, 5 );)
+DEF_BENCH( return new ClipStrategyBench(ClipStrategyBench::Mode::kMask, 10 );)
+DEF_BENCH( return new ClipStrategyBench(ClipStrategyBench::Mode::kMask, 100);)