Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
sksg::MaskEffect Class Referencefinal

#include <SkSGMaskEffect.h>

Inheritance diagram for sksg::MaskEffect:
sksg::EffectNode sksg::RenderNode sksg::Node SkRefCnt SkRefCntBase

Public Types

enum class  Mode : uint32_t { kAlphaNormal , kAlphaInvert , kLumaNormal , kLumaInvert }
 

Public Member Functions

 ~MaskEffect () override
 
- Public Member Functions inherited from sksg::RenderNode
void render (SkCanvas *, const RenderContext *=nullptr) const
 
const RenderNodenodeAt (const SkPoint &point) const
 
bool isVisible () const
 
void setVisible (bool)
 
- Public Member Functions inherited from sksg::Node
const SkRectrevalidate (InvalidationController *, const SkMatrix &)
 
void invalidate (bool damage=true)
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< MaskEffectMake (sk_sp< RenderNode > child, sk_sp< RenderNode > mask, Mode mode=Mode::kAlphaNormal)
 

Protected Member Functions

 MaskEffect (sk_sp< RenderNode >, sk_sp< RenderNode > mask, Mode)
 
void onRender (SkCanvas *, const RenderContext *) const override
 
const RenderNodeonNodeAt (const SkPoint &) const override
 
SkRect onRevalidate (InvalidationController *, const SkMatrix &) override
 
- Protected Member Functions inherited from sksg::EffectNode
 EffectNode (sk_sp< RenderNode >, uint32_t inval_traits=0)
 
 ~EffectNode () override
 
void onRender (SkCanvas *, const RenderContext *) const override
 
const RenderNodeonNodeAt (const SkPoint &) const override
 
SkRect onRevalidate (InvalidationController *, const SkMatrix &) override
 
const sk_sp< RenderNode > & getChild () const
 
- Protected Member Functions inherited from sksg::RenderNode
 RenderNode (uint32_t inval_traits=0)
 
virtual void onRender (SkCanvas *, const RenderContext *) const =0
 
virtual const RenderNodeonNodeAt (const SkPoint &p) const =0
 
- Protected Member Functions inherited from sksg::Node
 Node (uint32_t invalTraits)
 
 ~Node () override
 
const SkRectbounds () const
 
bool hasInval () const
 
virtual SkRect onRevalidate (InvalidationController *, const SkMatrix &ctm)=0
 
void observeInval (const sk_sp< Node > &)
 
void unobserveInval (const sk_sp< Node > &)
 

Additional Inherited Members

- Protected Types inherited from sksg::Node
enum  InvalTraits { kBubbleDamage_Trait = 1 << 0 , kOverrideDamage_Trait = 1 << 1 }
 

Detailed Description

Concrete Effect node, applying a mask to its descendants.

Definition at line 30 of file SkSGMaskEffect.h.

Member Enumeration Documentation

◆ Mode

enum class sksg::MaskEffect::Mode : uint32_t
strong
Enumerator
kAlphaNormal 
kAlphaInvert 
kLumaNormal 
kLumaInvert 

Definition at line 32 of file SkSGMaskEffect.h.

32 : uint32_t {
33 kAlphaNormal,
34 kAlphaInvert,
35 kLumaNormal,
36 kLumaInvert,
37 };

Constructor & Destructor Documentation

◆ ~MaskEffect()

sksg::MaskEffect::~MaskEffect ( )
override

Definition at line 39 of file SkSGMaskEffect.cpp.

39 {
40 this->unobserveInval(fMaskNode);
41}
void unobserveInval(const sk_sp< Node > &)
Definition: SkSGNode.cpp:84

◆ MaskEffect()

sksg::MaskEffect::MaskEffect ( sk_sp< RenderNode child,
sk_sp< RenderNode mask,
Mode  mode 
)
protected

Definition at line 32 of file SkSGMaskEffect.cpp.

33 : INHERITED(std::move(child))
34 , fMaskNode(std::move(mask))
35 , fMaskMode(mode) {
36 this->observeInval(fMaskNode);
37}
void observeInval(const sk_sp< Node > &)
Definition: SkSGNode.cpp:61
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 mode
Definition: switches.h:228

Member Function Documentation

◆ Make()

static sk_sp< MaskEffect > sksg::MaskEffect::Make ( sk_sp< RenderNode child,
sk_sp< RenderNode mask,
Mode  mode = Mode::kAlphaNormal 
)
inlinestatic

Definition at line 39 of file SkSGMaskEffect.h.

40 {
41 return (child && mask)
42 ? sk_sp<MaskEffect>(new MaskEffect(std::move(child), std::move(mask), mode))
43 : nullptr;
44 }
MaskEffect(sk_sp< RenderNode >, sk_sp< RenderNode > mask, Mode)

◆ onNodeAt()

const RenderNode * sksg::MaskEffect::onNodeAt ( const SkPoint p) const
overrideprotectedvirtual

Reimplemented from sksg::EffectNode.

Definition at line 85 of file SkSGMaskEffect.cpp.

85 {
86 const auto mask_hit = (SkToBool(fMaskNode->nodeAt(p)) == !is_inverted(fMaskMode));
87
88 if (!mask_hit) {
89 return nullptr;
90 }
91
92 return this->INHERITED::onNodeAt(p);
93}
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
const RenderNode * onNodeAt(const SkPoint &) const override
static bool is_inverted(sksg::MaskEffect::Mode mode)

◆ onRender()

void sksg::MaskEffect::onRender ( SkCanvas canvas,
const RenderContext ctx 
) const
overrideprotectedvirtual

Reimplemented from sksg::EffectNode.

Definition at line 43 of file SkSGMaskEffect.cpp.

43 {
44 SkAutoCanvasRestore acr(canvas, false);
45
46 // The mask mode covers two independent bits.
47 //
48 // - mask source controls how the mask coverage is generated:
49 // * alpha => coverage = mask_alpha
50 // * luma => coverage = luma(mask_rgb)
51 //
52 // - mask type controls how the mask coverage is interpreted:
53 // * normal => coverage' = coverage
54 // * inverted => coverage' = 1 - coverage
55
56 {
57 // Outer layer: mask coverage stored in the alpha channel.
58 SkPaint mask_layer_paint;
59 if (ctx) {
60 // Apply all optional context overrides upfront.
61 ctx->modulatePaint(canvas->getTotalMatrix(), &mask_layer_paint);
62 }
63
64 RenderContext mask_render_context;
65 if (is_luma(fMaskMode)) {
66 mask_render_context.fColorFilter = SkLumaColorFilter::Make();
67 }
68
69 // TODO: could be an A8 layer?
70 canvas->saveLayer(this->bounds(), &mask_layer_paint);
71 fMaskNode->render(canvas, &mask_render_context);
72
73 {
74 // Inner layer: masked content.
75 SkPaint content_layer_paint;
76 content_layer_paint.setBlendMode(is_inverted(fMaskMode) ? SkBlendMode::kSrcOut
78 canvas->saveLayer(this->bounds(), &content_layer_paint);
79
80 this->INHERITED::onRender(canvas, nullptr);
81 }
82 }
83}
@ kSrcOut
r = s * (1-da)
@ kSrcIn
r = s * da
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
SkMatrix getTotalMatrix() const
Definition: SkCanvas.cpp:1629
void setBlendMode(SkBlendMode mode)
Definition: SkPaint.cpp:151
void onRender(SkCanvas *, const RenderContext *) const override
const SkRect & bounds() const
Definition: SkSGNode.h:55
static bool is_luma(sksg::MaskEffect::Mode mode)
static sk_sp< SkColorFilter > Make()

◆ onRevalidate()

SkRect sksg::MaskEffect::onRevalidate ( InvalidationController ic,
const SkMatrix ctm 
)
overrideprotectedvirtual

Reimplemented from sksg::EffectNode.

Definition at line 95 of file SkSGMaskEffect.cpp.

95 {
96 SkASSERT(this->hasInval());
97
98 const auto maskBounds = fMaskNode->revalidate(ic, ctm);
99 auto childBounds = this->INHERITED::onRevalidate(ic, ctm);
100
101 return (is_inverted(fMaskMode) || childBounds.intersect(maskBounds))
102 ? childBounds
104}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
bool hasInval() const
Definition: SkSGNode.h:60
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595

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