Flutter Engine
The Flutter Engine
ClipStrategyBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 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"
10#include "include/core/SkPath.h"
11
13public:
14 enum class Mode {
15 kClipPath,
16 kMask,
17 };
18
20 : fMode(mode)
21 , fCount(count)
22 , fName("clip_strategy_"){
23
24 if (fMode == Mode::kClipPath) {
25 fName.append("path_");
26 this->forEachClipCircle([&](float x, float y, float r) {
27 fClipPath.addCircle(x, y, r);
28 });
29 } else {
30 fName.append("mask_");
31 }
32 fName.appendf("%zu", count);
33 }
34
35 ~ClipStrategyBench() override = default;
36
37protected:
38 const char* onGetName() override {
39 return fName.c_str();
40 }
41
42 void onDraw(int loops, SkCanvas* canvas) override {
43 SkPaint p, srcIn;
44 p.setAntiAlias(true);
46
47 for (int i = 0; i < loops; ++i) {
48 SkAutoCanvasRestore acr(canvas, false);
49
50 if (fMode == Mode::kClipPath) {
51 canvas->save();
52 canvas->clipPath(fClipPath, true);
53 } else {
54 canvas->saveLayer(nullptr, nullptr);
55 this->forEachClipCircle([&](float x, float y, float r) {
56 canvas->drawCircle(x, y, r, p);
57 });
58 canvas->saveLayer(nullptr, &srcIn);
59 }
60 canvas->drawColor(SK_ColorGREEN);
61 }
62 }
63
64private:
65 template <typename Func>
66 void forEachClipCircle(Func&& func) {
67 auto q = static_cast<float>(this->getSize().width()) / (fCount + 1);
68 for (size_t i = 1; i <= fCount; ++i) {
69 auto x = q * i;
70 func(x, x, q / 2);
71 }
72 }
73
74 Mode fMode;
75 size_t fCount;
76 SkString fName;
77 SkPath fClipPath;
78
79 using INHERITED = Benchmark;
80};
81
86
#define DEF_BENCH(code)
Definition: Benchmark.h:20
int count
Definition: FontMgrTest.cpp:50
@ kSrcIn
r = s * da
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
SkISize getSize()
Definition: Benchmark.cpp:26
ClipStrategyBench(Mode mode, size_t count)
~ClipStrategyBench() override=default
void onDraw(int loops, SkCanvas *canvas) override
const char * onGetName() override
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1456
int save()
Definition: SkCanvas.cpp:447
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
void setBlendMode(SkBlendMode mode)
Definition: SkPaint.cpp:151
Definition: SkPath.h:59
SkPath & addCircle(SkScalar x, SkScalar y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:1213
void append(const char text[])
Definition: SkString.h:203
const char * c_str() const
Definition: SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
double y
double x
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
constexpr int32_t width() const
Definition: SkSize.h:36