Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
sksg::RenderNode::ScopedRenderContext Class Referencefinal

#include <SkSGRenderNode.h>

Public Member Functions

 ScopedRenderContext (SkCanvas *, const RenderContext *)
 
 ~ScopedRenderContext ()
 
 ScopedRenderContext (ScopedRenderContext &&that)
 
ScopedRenderContextoperator= (ScopedRenderContext &&that)
 
 operator const RenderContext * () const
 
const RenderContextoperator-> () const
 
ScopedRenderContext && modulateOpacity (float opacity)
 
ScopedRenderContext && modulateColorFilter (sk_sp< SkColorFilter >)
 
ScopedRenderContext && modulateShader (sk_sp< SkShader >, const SkMatrix &shader_ctm)
 
ScopedRenderContext && modulateMaskShader (sk_sp< SkShader >, const SkMatrix &ms_ctm)
 
ScopedRenderContext && modulateBlender (sk_sp< SkBlender >)
 
ScopedRenderContext && setIsolation (const SkRect &bounds, const SkMatrix &ctm, bool do_isolate)
 
ScopedRenderContext && setFilterIsolation (const SkRect &bounds, const SkMatrix &ctm, sk_sp< SkImageFilter >)
 

Detailed Description

Definition at line 75 of file SkSGRenderNode.h.

Constructor & Destructor Documentation

◆ ScopedRenderContext() [1/2]

sksg::RenderNode::ScopedRenderContext::ScopedRenderContext ( SkCanvas canvas,
const RenderContext ctx 
)

Definition at line 122 of file SkSGRenderNode.cpp.

123 : fCanvas(canvas)
124 , fCtx(ctx ? *ctx : RenderContext())
125 , fRestoreCount(canvas->getSaveCount()) {}
int getSaveCount() const
Definition: SkCanvas.cpp:431

◆ ~ScopedRenderContext()

sksg::RenderNode::ScopedRenderContext::~ScopedRenderContext ( )

Definition at line 127 of file SkSGRenderNode.cpp.

127 {
128 if (fRestoreCount >= 0) {
129 if (fMaskShader) {
130 SkPaint mask_paint;
132 mask_paint.setShader(std::move(fMaskShader));
133 fCanvas->drawPaint(mask_paint);
134 }
135 fCanvas->restoreToCount(fRestoreCount);
136 }
137}
@ kDstIn
r = d * sa
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
void restoreToCount(int saveCount)
Definition: SkCanvas.cpp:478
void setShader(sk_sp< SkShader > shader)
void setBlendMode(SkBlendMode mode)
Definition: SkPaint.cpp:151

◆ ScopedRenderContext() [2/2]

sksg::RenderNode::ScopedRenderContext::ScopedRenderContext ( ScopedRenderContext &&  that)
inline

Definition at line 80 of file SkSGRenderNode.h.

80{ *this = std::move(that); }

Member Function Documentation

◆ modulateBlender()

RenderNode::ScopedRenderContext && sksg::RenderNode::ScopedRenderContext::modulateBlender ( sk_sp< SkBlender blender)

Definition at line 188 of file SkSGRenderNode.cpp.

188 {
189 fCtx.fBlender = std::move(blender);
190 return std::move(*this);
191}

◆ modulateColorFilter()

RenderNode::ScopedRenderContext && sksg::RenderNode::ScopedRenderContext::modulateColorFilter ( sk_sp< SkColorFilter cf)

Definition at line 147 of file SkSGRenderNode.cpp.

147 {
148 fCtx.fColorFilter = SkColorFilters::Compose(std::move(fCtx.fColorFilter), std::move(cf));
149 return std::move(*this);
150}
static sk_sp< SkColorFilter > Compose(const sk_sp< SkColorFilter > &outer, sk_sp< SkColorFilter > inner)
Definition: SkColorFilter.h:92
sk_sp< SkColorFilter > fColorFilter

◆ modulateMaskShader()

RenderNode::ScopedRenderContext && sksg::RenderNode::ScopedRenderContext::modulateMaskShader ( sk_sp< SkShader ms,
const SkMatrix ms_ctm 
)

Definition at line 164 of file SkSGRenderNode.cpp.

164 {
165 if (fCtx.fMaskShader) {
166 // As we compose mask filters, use the relative transform T for the inner mask:
167 //
168 // maskCTM x T = ctm
169 //
170 // => T = Inv(maskCTM) x ctm
171 //
172 SkMatrix invMaskCTM;
173 if (ms && fCtx.fMaskCTM.invert(&invMaskCTM)) {
174 const auto relative_transform = SkMatrix::Concat(invMaskCTM, ctm);
176 std::move(fCtx.fMaskShader),
177 ms->makeWithLocalMatrix(relative_transform));
178 }
179 } else {
180 fCtx.fMaskShader = std::move(ms);
181 fCtx.fMaskCTM = ctm;
182 }
183
184 return std::move(*this);
185}
@ kSrcIn
r = s * da
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
Definition: SkMatrix.h:1775
bool invert(SkMatrix *inverse) const
Definition: SkMatrix.h:1206
sk_sp< SkShader > makeWithLocalMatrix(const SkMatrix &) const
Definition: SkShader.cpp:26
SK_API sk_sp< SkShader > Blend(SkBlendMode mode, sk_sp< SkShader > dst, sk_sp< SkShader > src)

◆ modulateOpacity()

RenderNode::ScopedRenderContext && sksg::RenderNode::ScopedRenderContext::modulateOpacity ( float  opacity)

Definition at line 140 of file SkSGRenderNode.cpp.

140 {
141 SkASSERT(opacity >= 0 && opacity <= 1);
142 fCtx.fOpacity *= opacity;
143 return std::move(*this);
144}
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ modulateShader()

RenderNode::ScopedRenderContext && sksg::RenderNode::ScopedRenderContext::modulateShader ( sk_sp< SkShader sh,
const SkMatrix shader_ctm 
)

Definition at line 153 of file SkSGRenderNode.cpp.

153 {
154 // Topmost shader takes precedence.
155 if (!fCtx.fShader) {
156 fCtx.fShader = std::move(sh);
157 fCtx.fShaderCTM = shader_ctm;
158 }
159
160 return std::move(*this);
161}
sh
Definition: run_sh.py:10

◆ operator const RenderContext *()

sksg::RenderNode::ScopedRenderContext::operator const RenderContext * ( ) const
inline

Definition at line 94 of file SkSGRenderNode.h.

94{ return &fCtx; }

◆ operator->()

const RenderContext * sksg::RenderNode::ScopedRenderContext::operator-> ( ) const
inline

Definition at line 95 of file SkSGRenderNode.h.

95{ return &fCtx; }

◆ operator=()

ScopedRenderContext & sksg::RenderNode::ScopedRenderContext::operator= ( ScopedRenderContext &&  that)
inline

Definition at line 82 of file SkSGRenderNode.h.

82 {
83 fCanvas = that.fCanvas;
84 fCtx = std::move(that.fCtx);
85 fMaskShader = std::move(that.fMaskShader);
86 fRestoreCount = that.fRestoreCount;
87
88 // scope ownership is being transferred
89 that.fRestoreCount = -1;
90
91 return *this;
92 }

◆ setFilterIsolation()

RenderNode::ScopedRenderContext && sksg::RenderNode::ScopedRenderContext::setFilterIsolation ( const SkRect bounds,
const SkMatrix ctm,
sk_sp< SkImageFilter filter 
)

Definition at line 217 of file SkSGRenderNode.cpp.

218 {
219 if (filter) {
220 SkPaint layer_paint;
221 fCtx.modulatePaint(ctm, &layer_paint);
222 // shaders and image filters are not composable, so we convert the shader to an
223 // image filter and blend them together
224 if (layer_paint.getShader()) {
225 filter = SkImageFilters::Blend(SkBlendMode::kSrcIn, std::move(filter),
226 SkImageFilters::Shader(layer_paint.refShader()));
227 }
228 SkASSERT(!layer_paint.getImageFilter());
229 layer_paint.setImageFilter(std::move(filter));
230 fCanvas->saveLayer(bounds, &layer_paint);
231 fCtx = RenderContext();
232 }
233
234 return std::move(*this);
235}
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
static sk_sp< SkImageFilter > Blend(SkBlendMode mode, sk_sp< SkImageFilter > background, sk_sp< SkImageFilter > foreground=nullptr, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Shader(sk_sp< SkShader > shader, const CropRect &cropRect={})
sk_sp< SkShader > refShader() const
void setImageFilter(sk_sp< SkImageFilter > imageFilter)
SkImageFilter * getImageFilter() const
Definition: SkPaint.h:564
SkShader * getShader() const
Definition: SkPaint.h:397
const SkRect & bounds() const
Definition: SkSGNode.h:55
void modulatePaint(const SkMatrix &ctm, SkPaint *, bool is_layer_paint=false) const

◆ setIsolation()

RenderNode::ScopedRenderContext && sksg::RenderNode::ScopedRenderContext::setIsolation ( const SkRect bounds,
const SkMatrix ctm,
bool  do_isolate 
)

Definition at line 194 of file SkSGRenderNode.cpp.

195 {
196 if (isolation && fCtx.requiresIsolation()) {
197 SkPaint layer_paint;
198 fCtx.modulatePaint(ctm, &layer_paint, /*is_layer_paint = */true);
199 fCanvas->saveLayer(bounds, &layer_paint);
200
201 // Fetch the mask shader for restore.
202 if (fCtx.fMaskShader) {
203 fMaskShader = LocalShader(fCtx.fMaskShader, fCtx.fMaskCTM, ctm);
204 }
205
206 // Reset only the props applied via isolation layers.
207 fCtx.fColorFilter = nullptr;
208 fCtx.fMaskShader = nullptr;
209 fCtx.fBlender = nullptr;
210 fCtx.fOpacity = 1;
211 }
212
213 return std::move(*this);
214}
static sk_sp< SkShader > LocalShader(const sk_sp< SkShader > &shader, const SkMatrix &base, const SkMatrix &ctm)

The documentation for this class was generated from the following files: