Flutter Engine
The Flutter Engine
BlurRectBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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"
14#include "src/base/SkRandom.h"
15#include "src/core/SkBlurMask.h"
16
17#define SMALL SkIntToScalar(2)
18#define REAL 1.5f
19static const SkScalar kMedium = SkIntToScalar(5);
20#define BIG SkIntToScalar(10)
21static const SkScalar kMedBig = SkIntToScalar(20);
22#define REALBIG 30.5f
23
24class BlurRectBench: public Benchmark {
25 int fLoopCount;
26 SkScalar fRadius;
27 SkString fName;
28
29public:
31 fRadius = rad;
32
33 if (fRadius > SkIntToScalar(25)) {
34 fLoopCount = 100;
35 } else if (fRadius > SkIntToScalar(5)) {
36 fLoopCount = 1000;
37 } else {
38 fLoopCount = 10000;
39 }
40 }
41
42protected:
43 const char* onGetName() override {
44 return fName.c_str();
45 }
46
47 SkScalar radius() const {
48 return fRadius;
49 }
50
51 void setName(const SkString& name) {
52 fName = name;
53 }
54
55 void onDraw(int loops, SkCanvas*) override {
57 this->setupPaint(&paint);
58
59 paint.setAntiAlias(true);
60
61 SkScalar pad = fRadius*3/2 + SK_Scalar1;
62 SkRect r = SkRect::MakeWH(2 * pad + SK_Scalar1, 2 * pad + SK_Scalar1);
63
65
66 for (int i = 0; i < loops; i++) {
67 this->makeBlurryRect(r);
68 }
69 }
70
71 virtual void makeBlurryRect(const SkRect&) = 0;
72 virtual void preBenchSetup(const SkRect&) {}
73private:
74 using INHERITED = Benchmark;
75};
76
77
79 public:
82
83 if (SkScalarFraction(rad) != 0) {
84 name.printf("blurrect_direct_%.2f", rad);
85 } else {
86 name.printf("blurrect_direct_%d", SkScalarRoundToInt(rad));
87 }
88
89 this->setName(name);
90 }
91protected:
92 void makeBlurryRect(const SkRect& r) override {
93 SkMaskBuilder mask;
95 &mask, r, kNormal_SkBlurStyle)) {
96 return;
97 }
99 }
100private:
101 using INHERITED = BlurRectBench;
102};
103
105
106public:
108
111 }
112
113protected:
114 void preBenchSetup(const SkRect& r) override {
116
121
122 memset(fSrcMask.image(), 0xff, fSrcMask.computeTotalImageSize());
123 }
124
126private:
127 using INHERITED = BlurRectBench;
128};
129
131public:
134
135 if (SkScalarFraction(rad) != 0) {
136 name.printf("blurrect_boxfilter_%.2f", rad);
137 } else {
138 name.printf("blurrect_boxfilter_%d", SkScalarRoundToInt(rad));
139 }
140
141 this->setName(name);
142 }
143
144protected:
145
146 void makeBlurryRect(const SkRect&) override {
147 SkMaskBuilder mask;
150 return;
151 }
153 }
154private:
155 using INHERITED = BlurRectSeparableBench;
156};
157
159public:
162
163 if (SkScalarFraction(rad) != 0) {
164 name.printf("blurrect_gaussian_%.2f", rad);
165 } else {
166 name.printf("blurrect_gaussian_%d", SkScalarRoundToInt(rad));
167 }
168
169 this->setName(name);
170 }
171
172protected:
173
174 void makeBlurryRect(const SkRect&) override {
175 SkMaskBuilder mask;
177 &mask, fSrcMask, kNormal_SkBlurStyle)) {
178 return;
179 }
181 }
182private:
183 using INHERITED = BlurRectSeparableBench;
184};
185
198
201
204
205#if 0
206// disable Gaussian benchmarks; the algorithm works well enough
207// and serves as a baseline for ground truth, but it's too slow
208// to use in production for non-trivial radii, so no real point
209// in having the bots benchmark it all the time.
210
231#endif
#define DEF_BENCH(code)
Definition: Benchmark.h:20
#define SMALL
static const SkScalar kMedium
#define BIG
#define REAL
static const SkScalar kMedBig
#define REALBIG
const char * fName
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:37
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static SkScalar SkScalarFraction(SkScalar x)
Definition: SkScalar.h:67
virtual void setupPaint(SkPaint *paint)
Definition: Benchmark.cpp:55
void setName(const SkString &name)
SkScalar radius() const
const char * onGetName() override
virtual void makeBlurryRect(const SkRect &)=0
BlurRectBench(SkScalar rad)
void onDraw(int loops, SkCanvas *) override
virtual void preBenchSetup(const SkRect &)
void makeBlurryRect(const SkRect &) override
BlurRectBoxFilterBench(SkScalar rad)
BlurRectDirectBench(SkScalar rad)
void makeBlurryRect(const SkRect &r) override
BlurRectGaussianBench(SkScalar rad)
void makeBlurryRect(const SkRect &) override
void preBenchSetup(const SkRect &r) override
BlurRectSeparableBench(SkScalar rad)
~BlurRectSeparableBench() override
static bool BlurRect(SkScalar sigma, SkMaskBuilder *dst, const SkRect &src, SkBlurStyle, SkIPoint *margin=nullptr, SkMaskBuilder::CreateMode createMode=SkMaskBuilder::kComputeBoundsAndRenderImage_CreateMode)
Definition: SkBlurMask.cpp:407
static SkScalar SK_SPI ConvertRadiusToSigma(SkScalar radius)
Definition: SkBlurMask.cpp:39
static bool BlurGroundTruth(SkScalar sigma, SkMaskBuilder *dst, const SkMask &src, SkBlurStyle, SkIPoint *margin=nullptr)
Definition: SkBlurMask.cpp:517
static bool BoxBlur(SkMaskBuilder *dst, const SkMask &src, SkScalar sigma, SkBlurStyle style, SkIPoint *margin=nullptr)
Definition: SkBlurMask.cpp:116
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
constexpr int32_t width() const
Definition: SkRect.h:158
static void FreeImage(void *image)
Definition: SkMask.cpp:57
Format & format()
Definition: SkMask.h:239
uint32_t & rowBytes()
Definition: SkMask.h:238
static uint8_t * AllocImage(size_t bytes, AllocType=kUninit_Alloc)
Definition: SkMask.cpp:45
SkIRect & bounds()
Definition: SkMask.h:237
uint8_t *& image()
Definition: SkMask.h:236
@ kA8_Format
8bits per pixel mask (e.g. antialiasing)
Definition: SkMask.h:28
const SkIRect fBounds
Definition: SkMask.h:42
size_t computeTotalImageSize() const
Definition: SkMask.cpp:34
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609