Flutter Engine
The Flutter Engine
Classes | Namespaces | Macros | Typedefs | Functions
blurrect.cpp File Reference
#include <cmath>
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkBlurTypes.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkImage.h"
#include "include/core/SkMaskFilter.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPathBuilder.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/private/base/SkTo.h"
#include "src/core/SkBlurMask.h"
#include "src/core/SkMask.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "tools/timer/TimeUtils.h"
#include <vector>

Go to the source code of this file.

Classes

class  BlurRectGM
 
class  skiagm::BlurRectCompareGM
 

Namespaces

namespace  skiagm
 

Macros

#define STROKE_WIDTH   SkIntToScalar(10)
 

Typedefs

typedef void(* Proc) (SkCanvas *, const SkRect &, const SkPaint &)
 
typedef void(* PaintProc) (SkPaint *, SkScalar width)
 

Functions

static void fill_rect (SkCanvas *canvas, const SkRect &r, const SkPaint &p)
 
static void draw_donut (SkCanvas *canvas, const SkRect &r, const SkPaint &p)
 
static void draw_donut_skewed (SkCanvas *canvas, const SkRect &r, const SkPaint &p)
 
static sk_sp< SkShadermake_radial ()
 
 DEF_SIMPLE_GM (blurrect_gallery, canvas, 1200, 1024)
 
 DEF_SIMPLE_GM (blur_matrix_rect, canvas, 650, 685)
 

Macro Definition Documentation

◆ STROKE_WIDTH

#define STROKE_WIDTH   SkIntToScalar(10)

Definition at line 40 of file blurrect.cpp.

Typedef Documentation

◆ PaintProc

typedef void(* PaintProc) (SkPaint *, SkScalar width)

Definition at line 107 of file blurrect.cpp.

◆ Proc

typedef void(* Proc) (SkCanvas *, const SkRect &, const SkPaint &)

Definition at line 42 of file blurrect.cpp.

Function Documentation

◆ DEF_SIMPLE_GM() [1/2]

DEF_SIMPLE_GM ( blur_matrix_rect  ,
canvas  ,
650  ,
685   
)

Definition at line 509 of file blurrect.cpp.

509 {
510 static constexpr auto kRect = SkRect::MakeWH(14, 60);
511 static constexpr float kSigmas[] = {0.5f, 1.2f, 2.3f, 3.9f, 7.4f};
512 static constexpr size_t kNumSigmas = std::size(kSigmas);
513
514 const SkPoint c = {kRect.centerX(), kRect.centerY()};
515
516 std::vector<SkMatrix> matrices;
517
518 matrices.push_back(SkMatrix::RotateDeg(4.f, c));
519
520 matrices.push_back(SkMatrix::RotateDeg(63.f, c));
521
522 matrices.push_back(SkMatrix::RotateDeg(30.f, c));
523 matrices.back().preScale(1.1f, .5f);
524
525 matrices.push_back(SkMatrix::RotateDeg(147.f, c));
526 matrices.back().preScale(3.f, .1f);
527
529 mirror.setAll(0, 1, 0,
530 1, 0, 0,
531 0, 0, 1);
532 matrices.push_back(SkMatrix::Concat(mirror, matrices.back()));
533
534 matrices.push_back(SkMatrix::RotateDeg(197.f, c));
535 matrices.back().preSkew(.3f, -.5f);
536
537 auto bounds = SkRect::MakeEmpty();
538 for (const auto& m : matrices) {
539 SkRect mapped;
540 m.mapRect(&mapped, kRect);
541 bounds.joinNonEmptyArg(mapped.makeSorted());
542 }
543 float blurPad = 2.f*kSigmas[kNumSigmas - 1];
544 bounds.outset(blurPad, blurPad);
545 canvas->translate(-bounds.left(), -bounds.top());
546 for (auto sigma : kSigmas) {
548 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma));
549 canvas->save();
550 for (const auto& m : matrices) {
551 canvas->save();
552 canvas->concat(m);
553 canvas->drawRect(kRect, paint);
554 canvas->restore();
555 canvas->translate(0, bounds.height());
556 }
557 canvas->restore();
558 canvas->translate(bounds.width(), 0);
559 }
560}
static unsigned mirror(SkFixed fx, int max)
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
static SkMatrix RotateDeg(SkScalar deg)
Definition: SkMatrix.h:104
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
Definition: SkMatrix.h:1775
const Paint & paint
Definition: color_source.cc:38
Optional< SkRect > bounds
Definition: SkRecords.h:189
constexpr std::array< std::array< float, 2 >, 2 > kRect
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
SkRect makeSorted() const
Definition: SkRect.h:1330
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ DEF_SIMPLE_GM() [2/2]

DEF_SIMPLE_GM ( blurrect_gallery  ,
canvas  ,
1200  ,
1024   
)

Definition at line 186 of file blurrect.cpp.

186 {
187 const int fGMWidth = 1200;
188 const int fPadding = 10;
189 const int fMargin = 100;
190
191 const int widths[] = {25, 5, 5, 100, 150, 25};
192 const int heights[] = {100, 100, 5, 25, 150, 25};
194 const float radii[] = {20, 5, 10};
195
196 canvas->translate(50,20);
197
198 int cur_x = 0;
199 int cur_y = 0;
200
201 int max_height = 0;
202
203 for (size_t i = 0 ; i < std::size(widths) ; i++) {
204 int width = widths[i];
205 int height = heights[i];
206 SkRect r;
208 SkAutoCanvasRestore autoRestore(canvas, true);
209
210 for (size_t j = 0 ; j < std::size(radii) ; j++) {
211 float radius = radii[j];
212 for (size_t k = 0 ; k < std::size(styles) ; k++) {
213 SkBlurStyle style = styles[k];
214
215 SkMaskBuilder mask;
217 &mask, r, style)) {
218 continue;
219 }
220
221 SkAutoMaskFreeImage amfi(mask.image());
222
223 SkBitmap bm;
224 bm.installMaskPixels(mask);
225
226 if (cur_x + bm.width() >= fGMWidth - fMargin) {
227 cur_x = 0;
228 cur_y += max_height + fPadding;
229 max_height = 0;
230 }
231
232 canvas->save();
233 canvas->translate((SkScalar)cur_x, (SkScalar)cur_y);
234 canvas->translate(-(bm.width() - r.width())/2, -(bm.height()-r.height())/2);
235 canvas->drawImage(bm.asImage(), 0.f, 0.f);
236 canvas->restore();
237
238 cur_x += bm.width() + fPadding;
239 if (bm.height() > max_height)
240 max_height = bm.height();
241 }
242 }
243 }
244}
SkBlurStyle
Definition: SkBlurTypes.h:11
@ kOuter_SkBlurStyle
nothing inside, fuzzy outside
Definition: SkBlurTypes.h:14
@ kInner_SkBlurStyle
fuzzy inside, nothing outside
Definition: SkBlurTypes.h:15
std::unique_ptr< uint8_t, SkFunctionObject< SkMaskBuilder::FreeImage > > SkAutoMaskFreeImage
Definition: SkMask.h:316
#define SkIntToScalar(x)
Definition: SkScalar.h:57
const SkScalar widths[]
Definition: StrokerTest.cpp:39
bool installMaskPixels(SkMaskBuilder &mask)
Definition: SkBitmap.cpp:349
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
int width() const
Definition: SkBitmap.h:149
int height() const
Definition: SkBitmap.h:158
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
float SkScalar
Definition: extension.cpp:12
int32_t height
int32_t width
uint8_t *& image()
Definition: SkMask.h:236
void setWH(float width, float height)
Definition: SkRect.h:944
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762

◆ draw_donut()

static void draw_donut ( SkCanvas canvas,
const SkRect r,
const SkPaint p 
)
static

Definition at line 48 of file blurrect.cpp.

48 {
51
52 rect = r;
53 rect.outset(STROKE_WIDTH/2, STROKE_WIDTH/2);
54 path.addRect(rect);
55 rect = r;
56 rect.inset(STROKE_WIDTH/2, STROKE_WIDTH/2);
57
58 path.addRect(rect);
59 path.setFillType(SkPathFillType::kEvenOdd);
60
61 canvas->drawPath(path.detach(), p);
62}
#define STROKE_WIDTH
Definition: blurrect.cpp:40
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
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

◆ draw_donut_skewed()

static void draw_donut_skewed ( SkCanvas canvas,
const SkRect r,
const SkPaint p 
)
static

Definition at line 64 of file blurrect.cpp.

64 {
67
68 rect = r;
69 rect.outset(STROKE_WIDTH/2, STROKE_WIDTH/2);
70 path.addRect(rect);
71 rect = r;
72 rect.inset(STROKE_WIDTH/2, STROKE_WIDTH/2);
73
74 rect.offset(7, -7);
75
76 path.addRect(rect);
77 path.setFillType(SkPathFillType::kEvenOdd);
78
79 canvas->drawPath(path.detach(), p);
80}

◆ fill_rect()

static void fill_rect ( SkCanvas canvas,
const SkRect r,
const SkPaint p 
)
static

Definition at line 44 of file blurrect.cpp.

44 {
45 canvas->drawRect(r, p);
46}
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673

◆ make_radial()

static sk_sp< SkShader > make_radial ( )
static

Definition at line 85 of file blurrect.cpp.

85 {
86 SkPoint pts[2] = {
87 { 0, 0 },
88 { SkIntToScalar(100), SkIntToScalar(100) }
89 };
92 const SkScalar pos[] = { SK_Scalar1/4, SK_Scalar1*3/4 };
94 scale.setScale(0.5f, 0.5f);
95 scale.postTranslate(25.f, 25.f);
96 SkPoint center0, center1;
97 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
98 SkScalarAve(pts[0].fY, pts[1].fY));
99 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
100 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
101 return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
102 center0, (pts[1].fX - pts[0].fX) / 2,
103 colors, pos, std::size(colors), tm,
104 0, &scale);
105}
SkPoint pos
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkScalarAve(a, b)
Definition: SkScalar.h:74
static SkScalar SkScalarInterp(SkScalar A, SkScalar B, SkScalar t)
Definition: SkScalar.h:131
SkTileMode
Definition: SkTileMode.h:13
static sk_sp< SkShader > MakeTwoPointConical(const SkPoint &start, SkScalar startRadius, const SkPoint &end, SkScalar endRadius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
PODArray< SkColor > colors
Definition: SkRecords.h:276
const Scalar scale
void set(float x, float y)
Definition: SkPoint_impl.h:200