From cda4e94b0d47ddcc3bdeb1a5295f57e35c0be42e Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Thu, 16 Nov 2017 09:33:36 -0500 Subject: 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 Reviewed-by: Florin Malita --- bench/ClipStrategyBench.cpp | 91 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 bench/ClipStrategyBench.cpp (limited to 'bench/ClipStrategyBench.cpp') 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 + void forEachClipCircle(Func&& func) { + auto q = static_cast(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);) -- cgit v1.2.3