Flutter Engine
The Flutter Engine
Functions
blurs.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBlurTypes.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkFont.h"
#include "include/core/SkMaskFilter.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPathBuilder.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkImageFilters.h"
#include "src/core/SkBlurMask.h"
#include "tools/DecodeUtils.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"

Go to the source code of this file.

Functions

 DEF_SIMPLE_GM_BG (blurs, canvas, 700, 500, 0xFFDDDDDD)
 
 DEF_SIMPLE_GM (blur2rects, canvas, 700, 500)
 
 DEF_SIMPLE_GM (blur2rectsnonninepatch, canvas, 700, 500)
 
 DEF_SIMPLE_GM (BlurDrawImage, canvas, 256, 256)
 
 DEF_SIMPLE_GM (BlurBigSigma, canvas, 1024, 1024)
 
 DEF_SIMPLE_GM (BlurSmallSigma, canvas, 512, 256)
 
 DEF_SIMPLE_GM (TiledBlurBigSigma, canvas, 1024, 768)
 

Function Documentation

◆ DEF_SIMPLE_GM() [1/6]

DEF_SIMPLE_GM ( blur2rects  ,
canvas  ,
700  ,
500   
)

Definition at line 87 of file blurs.cpp.

87 {
89
91
92 SkRect outer = SkRect::MakeXYWH(10.125f, 10.125f, 100.125f, 100);
93 SkRect inner = SkRect::MakeXYWH(20.25f, 20.125f, 80, 80);
96 .detach();
97
98 canvas->drawPath(path, paint);
99 // important to translate by a factional amount to exercise a different "phase"
100 // of the same path w.r.t. the pixel grid
101 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 14 + 0.25f;
102 canvas->translate(dx, 0);
103 canvas->drawPath(path, paint);
104}
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
#define SkScalarRoundToScalar(x)
Definition: SkScalar.h:32
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
SkPathBuilder & addRect(const SkRect &, SkPathDirection, unsigned startIndex)
Definition: SkPath.h:59
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ DEF_SIMPLE_GM() [2/6]

DEF_SIMPLE_GM ( blur2rectsnonninepatch  ,
canvas  ,
700  ,
500   
)

Definition at line 106 of file blurs.cpp.

106 {
109
110 SkRect outer = SkRect::MakeXYWH(10, 110, 100, 100);
111 SkRect inner = SkRect::MakeXYWH(50, 150, 10, 10);
114 .detach();
115 canvas->drawPath(path, paint);
116
117 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 40 + 0.25f;
118 canvas->translate(dx, 0);
119 canvas->drawPath(path, paint);
120
121 // Translate to outside of clip bounds.
122 canvas->translate(-dx, 0);
123 canvas->translate(-30, -150);
124 canvas->drawPath(path, paint);
125}

◆ DEF_SIMPLE_GM() [3/6]

DEF_SIMPLE_GM ( BlurBigSigma  ,
canvas  ,
1024  ,
1024   
)

Definition at line 137 of file blurs.cpp.

137 {
138 SkPaint layerPaint, p;
139
140 p.setImageFilter(SkImageFilters::Blur(500, 500, nullptr));
141
142 canvas->drawRect(SkRect::MakeWH(700, 800), p);
143}
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ DEF_SIMPLE_GM() [4/6]

DEF_SIMPLE_GM ( BlurDrawImage  ,
canvas  ,
256  ,
256   
)

Definition at line 127 of file blurs.cpp.

127 {
130 canvas->clear(0xFF88FF88);
131 if (auto image = ToolUtils::GetResourceAsImage("images/mandrill_512_q075.jpg")) {
132 canvas->scale(0.25, 0.25);
133 canvas->drawImage(image, 256, 256, SkSamplingOptions(), &paint);
134 }
135}
sk_sp< const SkImage > image
Definition: SkRecords.h:269
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
SkSamplingOptions(SkFilterMode::kLinear))

◆ DEF_SIMPLE_GM() [5/6]

DEF_SIMPLE_GM ( BlurSmallSigma  ,
canvas  ,
512  ,
256   
)

Definition at line 145 of file blurs.cpp.

145 {
146 {
147 // Normal sigma on x-axis, a small but non-zero sigma on y-axis that should
148 // be treated as identity.
150 paint.setImageFilter(SkImageFilters::Blur(16.f, 1e-5f, nullptr));
151 canvas->drawRect(SkRect::MakeLTRB(64, 64, 192, 192), paint);
152 }
153
154 {
155 // Small sigma on both axes, should be treated as identity and no red should show
157 paint.setColor(SK_ColorRED);
158 SkRect rect = SkRect::MakeLTRB(320, 64, 448, 192);
159 canvas->drawRect(rect, paint);
160 paint.setColor(SK_ColorBLACK);
161 paint.setImageFilter(SkImageFilters::Blur(1e-5f, 1e-5f, nullptr));
162 canvas->drawRect(rect, paint);
163 }
164}
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646

◆ DEF_SIMPLE_GM() [6/6]

DEF_SIMPLE_GM ( TiledBlurBigSigma  ,
canvas  ,
1024  ,
768   
)

Definition at line 168 of file blurs.cpp.

168 {
169 static constexpr int kTileWidth = 342;
170 static constexpr int kTileHeight = 256;
171
172 SkM44 origCTM = canvas->getLocalToDevice();
173
174 for (int y = 0; y < 3; ++y) {
175 for (int x = 0; x < 3; ++x) {
176 // Define tiled grid in the canvas pixel space
177 canvas->save();
178 canvas->resetMatrix();
179
180 canvas->clipIRect(SkIRect::MakeXYWH(x*kTileWidth, y*kTileHeight,
182 canvas->setMatrix(origCTM);
183
187 std::move(flood), nullptr);
188 auto blur = SkImageFilters::Blur(206.f, 206.f, std::move(blend));
189
190 SkPaint p;
191 p.setImageFilter(std::move(blur));
192
193 canvas->clipRect({0, 0, 1970, 1223});
194 canvas->saveLayer(nullptr, &p);
195 SkPaint fill;
197 canvas->drawCircle(600, 150, 350, fill);
198 canvas->restore();
199 canvas->restore();
200 }
201 }
202}
@ kSrcOver
r = s + (1-sa)*d
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
static sk_sp< SkColorFilter > Blend(const SkColor4f &c, sk_sp< SkColorSpace >, SkBlendMode mode)
static sk_sp< SkImageFilter > ColorFilter(sk_sp< SkColorFilter > cf, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Blend(SkBlendMode mode, sk_sp< SkImageFilter > background, sk_sp< SkImageFilter > foreground=nullptr, const CropRect &cropRect={})
Definition: SkM44.h:150
void setColor(SkColor color)
Definition: SkPaint.cpp:119
static constexpr SkScalar kTileHeight
static constexpr SkScalar kTileWidth
static SkColor blend(SkColor dst, SkColor src, void(*mode)(float, float, float, float *, float *, float *))
Definition: hsl.cpp:142
double y
double x
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104

◆ DEF_SIMPLE_GM_BG()

DEF_SIMPLE_GM_BG ( blurs  ,
canvas  ,
700  ,
500  ,
0xFFDDDDDD   
)

Definition at line 29 of file blurs.cpp.

29 {
30 SkBlurStyle NONE = SkBlurStyle(-999);
31 const struct {
33 int fCx, fCy;
34 } gRecs[] = {
35 { NONE, 0, 0 },
36 { kInner_SkBlurStyle, -1, 0 },
37 { kNormal_SkBlurStyle, 0, 1 },
38 { kSolid_SkBlurStyle, 0, -1 },
39 { kOuter_SkBlurStyle, 1, 0 },
40 };
41
43 paint.setAntiAlias(true);
44 paint.setColor(SK_ColorBLUE);
45
46 canvas->translate(SkIntToScalar(-40), SkIntToScalar(0));
47
48 for (size_t i = 0; i < std::size(gRecs); i++) {
49 if (gRecs[i].fStyle != NONE) {
50 paint.setMaskFilter(SkMaskFilter::MakeBlur(gRecs[i].fStyle,
52 } else {
53 paint.setMaskFilter(nullptr);
54 }
55 canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100),
56 SkIntToScalar(200 + gRecs[i].fCy*100),
57 SkIntToScalar(50),
58 paint);
59 }
60 // draw text
61 {
67 paint.setColor(SK_ColorBLACK);
68 canvas->drawString("Hamburgefons Style", x, y, font, paint);
69 canvas->drawString("Hamburgefons Style",
70 x, y + SkIntToScalar(50), font, paint);
71 paint.setMaskFilter(nullptr);
72 paint.setColor(SK_ColorWHITE);
73 x -= SkIntToScalar(2);
74 y -= SkIntToScalar(2);
75 canvas->drawString("Hamburgefons Style", x, y, font, paint);
76 }
77}
SkStrokeRec::Style fStyle
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
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static SkScalar SK_SPI ConvertRadiusToSigma(SkScalar radius)
Definition: SkBlurMask.cpp:39
Definition: SkFont.h:35
sk_sp< SkTypeface > DefaultPortableTypeface()
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 keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.