Flutter Engine
The Flutter Engine
Functions
backdrop.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkImageFilters.h"
#include "src/core/SkCanvasPriv.h"
#include "src/core/SkMatrixPriv.h"
#include <initializer_list>

Go to the source code of this file.

Functions

static sk_sp< SkShadermake_shader (SkScalar cx, SkScalar cy, SkScalar rad)
 
static void do_draw (SkCanvas *canvas, bool useClip, bool useHintRect, SkScalar scaleFactor)
 
 DEF_SIMPLE_GM (backdrop_hintrect_clipping, canvas, 512, 1024)
 
 DEF_SIMPLE_GM (backdrop_scalefactor, canvas, 768, 1024)
 

Function Documentation

◆ DEF_SIMPLE_GM() [1/2]

DEF_SIMPLE_GM ( backdrop_hintrect_clipping  ,
canvas  ,
512  ,
1024   
)

Definition at line 88 of file backdrop.cpp.

88 {
89 for (bool useHintRect : {false, true}) {
90 for (bool useClip : {false, true}) {
91 canvas->save();
92 do_draw(canvas, useClip, useHintRect, 1.0f);
93
95 do_draw(rec.beginRecording(256, 256), useClip, useHintRect, 1.0f);
96 canvas->translate(256, 0);
97 canvas->drawPicture(rec.finishRecordingAsPicture());
98 canvas->restore();
99
100 canvas->translate(0, 256);
101 }
102 }
103}
static void do_draw(SkCanvas *canvas, bool useClip, bool useHintRect, SkScalar scaleFactor)
Definition: backdrop.cpp:41
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()

◆ DEF_SIMPLE_GM() [2/2]

DEF_SIMPLE_GM ( backdrop_scalefactor  ,
canvas  ,
768  ,
1024   
)

Definition at line 113 of file backdrop.cpp.

113 {
114 for (bool useHintRect : {false, true}) {
115 for (bool useClip : {false, true}) {
116 canvas->save();
117 do_draw(canvas, useClip, useHintRect, 1.0f);
118 canvas->translate(256, 0);
119 do_draw(canvas, useClip, useHintRect, 0.25f);
120 canvas->translate(256, 0);
121 do_draw(canvas, useClip, useHintRect, 0.1f);
122 canvas->restore();
123
124 canvas->translate(0, 256);
125 }
126 }
127}

◆ do_draw()

static void do_draw ( SkCanvas canvas,
bool  useClip,
bool  useHintRect,
SkScalar  scaleFactor 
)
static

Definition at line 41 of file backdrop.cpp.

41 {
42 SkAutoCanvasRestore acr(canvas, true);
43 canvas->clipRect({0, 0, 256, 256});
44
45 const SkScalar cx = 128, cy = 128, rad = 100;
46 SkPaint p;
47 p.setShader(make_shader(cx, cy, rad));
48 p.setAntiAlias(true);
49 canvas->drawCircle(cx, cy, rad, p);
50
51 // now setup a saveLayer that will pull in the backdrop and blur it
52 //
53 const SkRect r = {cx-50, cy-50, cx+50, cy+50};
54 const SkRect* drawrptr = useHintRect ? &r : nullptr;
55 const SkScalar sigma = 10;
56 if (useClip) {
57 canvas->clipRect(r);
58 }
59 // Using kClamp because kDecal, the default, produces transparency near the edge of the canvas's
60 // device.
61 SkRect blurCrop;
63 &blurCrop,
64 SkRect::MakeWH(canvas->imageInfo().width(),
65 canvas->imageInfo().height())));
66 auto blur = SkImageFilters::Blur(sigma, sigma, SkTileMode::kClamp, nullptr, blurCrop);
67 auto rec = SkCanvasPriv::ScaledBackdropLayer(drawrptr, nullptr, blur.get(), scaleFactor, 0);
68 canvas->saveLayer(rec);
69 // draw something inside, just to demonstrate that we don't blur the new contents,
70 // just the backdrop.
71 p.setColor(SK_ColorYELLOW);
72 p.setShader(nullptr);
73 canvas->drawCircle(cx, cy, 30, p);
74 canvas->restore();
75}
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
static sk_sp< SkShader > make_shader(SkScalar cx, SkScalar cy, SkScalar rad)
Definition: backdrop.cpp:28
static SkCanvas::SaveLayerRec ScaledBackdropLayer(const SkRect *bounds, const SkPaint *paint, const SkImageFilter *backdrop, SkScalar backdropScale, SkCanvas::SaveLayerFlags saveLayerFlags, SkCanvas::FilterSpan filters={})
Definition: SkCanvasPriv.h:75
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
SkMatrix getLocalToDeviceAs3x3() const
Definition: SkCanvas.h:2222
SkImageInfo imageInfo() const
Definition: SkCanvas.cpp:1206
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static bool InverseMapRect(const SkMatrix &mx, SkRect *dst, const SkRect &src)
Definition: SkMatrixPriv.h:54
float SkScalar
Definition: extension.cpp:12
int width() const
Definition: SkImageInfo.h:365
int height() const
Definition: SkImageInfo.h:371
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ make_shader()

static sk_sp< SkShader > make_shader ( SkScalar  cx,
SkScalar  cy,
SkScalar  rad 
)
static

Definition at line 28 of file backdrop.cpp.

28 {
29 const SkColor colors[] = {
32 };
33 constexpr int count = std::size(colors);
34 SkScalar pos[count] = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6 };
35 for (int i = 0; i < count; ++i) {
36 pos[i] *= 1.0f/6;
37 }
39}
int count
Definition: FontMgrTest.cpp:50
SkPoint pos
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
static sk_sp< SkShader > MakeSweep(SkScalar cx, SkScalar cy, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, SkScalar startAngle, SkScalar endAngle, uint32_t flags, const SkMatrix *localMatrix)
PODArray< SkColor > colors
Definition: SkRecords.h:276
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