Flutter Engine
The Flutter Engine
BlurBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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#include "bench/Benchmark.h"
14#include "src/base/SkRandom.h"
15#include "src/core/SkBlurMask.h"
16
17#define MINI 0.01f
18#define SMALL SkIntToScalar(2)
19#define REAL 0.5f
20#define BIG SkIntToScalar(10)
21#define REALBIG 100.5f
22// The value that produces a sigma of just over 2.
23#define CUTOVER 2.6f
24
25static const char* gStyleName[] = {
26 "normal",
27 "solid",
28 "outer",
29 "inner"
30};
31
32class BlurBench : public Benchmark {
33 SkScalar fRadius;
34 SkBlurStyle fStyle;
35 SkString fName;
36
37public:
39 fRadius = rad;
40 fStyle = bs;
41 const char* name = rad > 0 ? gStyleName[bs] : "none";
42 const char* quality = "high_quality";
43 if (SkScalarFraction(rad) != 0) {
44 fName.printf("blur_%.2f_%s_%s", rad, name, quality);
45 } else {
46 fName.printf("blur_%d_%s_%s", SkScalarRoundToInt(rad), name, quality);
47 }
48 }
49
50protected:
51 const char* onGetName() override {
52 return fName.c_str();
53 }
54
55 void onDraw(int loops, SkCanvas* canvas) override {
57 this->setupPaint(&paint);
58
59 paint.setAntiAlias(true);
60
61 SkRandom rand;
62 for (int i = 0; i < loops; i++) {
63 SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
64 rand.nextUScalar1() * 400);
65 r.offset(fRadius, fRadius);
66
67 if (fRadius > 0) {
70 }
71 canvas->drawOval(r, paint);
72 }
73 }
74
75private:
76 using INHERITED = Benchmark;
77};
78
83
88
93
98
103
SkStrokeRec::Style fStyle
#define DEF_BENCH(code)
Definition: Benchmark.h:20
#define SMALL
Definition: BlurBench.cpp:18
#define MINI
Definition: BlurBench.cpp:17
#define BIG
Definition: BlurBench.cpp:20
#define REAL
Definition: BlurBench.cpp:19
static const char * gStyleName[]
Definition: BlurBench.cpp:25
#define REALBIG
Definition: BlurBench.cpp:21
const char * fName
SkBlurStyle
Definition: SkBlurTypes.h:11
@ kOuter_SkBlurStyle
nothing inside, fuzzy outside
Definition: SkBlurTypes.h:14
@ kSolid_SkBlurStyle
solid inside, fuzzy outside
Definition: SkBlurTypes.h:13
@ kInner_SkBlurStyle
fuzzy inside, nothing outside
Definition: SkBlurTypes.h:15
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:37
static SkScalar SkScalarFraction(SkScalar x)
Definition: SkScalar.h:67
virtual void setupPaint(SkPaint *paint)
Definition: Benchmark.cpp:55
BlurBench(SkScalar rad, SkBlurStyle bs)
Definition: BlurBench.cpp:38
void onDraw(int loops, SkCanvas *canvas) override
Definition: BlurBench.cpp:55
const char * onGetName() override
Definition: BlurBench.cpp:51
static SkScalar SK_SPI ConvertRadiusToSigma(SkScalar radius)
Definition: SkBlurMask.cpp:39
void drawOval(const SkRect &oval, const SkPaint &paint)
Definition: SkCanvas.cpp:1698
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
SkScalar nextUScalar1()
Definition: SkRandom.h:101
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
void offset(float dx, float dy)
Definition: SkRect.h:1016
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609