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

#include <SkSGRenderEffect.h>

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

Public Types

enum class  Cropping { kNone , kContent }
 

Public Member Functions

 ~ImageFilterEffect () 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< RenderNodeMake (sk_sp< RenderNode > child, sk_sp< ImageFilter > filter)
 

Protected Member Functions

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

Attaches an ImageFilter (chain) to the render DAG.

Definition at line 136 of file SkSGRenderEffect.h.

Member Enumeration Documentation

◆ Cropping

Enumerator
kNone 
kContent 

Definition at line 142 of file SkSGRenderEffect.h.

142 {
143 kNone, // Doesn't use a crop rect.
144 kContent, // Uses the content bounding box as a crop rect.
145 };
@ kNone
Definition: layer.h:53

Constructor & Destructor Documentation

◆ ~ImageFilterEffect()

sksg::ImageFilterEffect::~ImageFilterEffect ( )
override

Definition at line 109 of file SkSGRenderEffect.cpp.

109 {
110 this->unobserveInval(fImageFilter);
111}
void unobserveInval(const sk_sp< Node > &)
Definition: SkSGNode.cpp:84

Member Function Documentation

◆ Make()

sk_sp< RenderNode > sksg::ImageFilterEffect::Make ( sk_sp< RenderNode child,
sk_sp< ImageFilter filter 
)
static

Definition at line 97 of file SkSGRenderEffect.cpp.

97 {
98 return filter ? sk_sp<RenderNode>(new ImageFilterEffect(std::move(child), std::move(filter)))
99 : child;
100}
friend class ImageFilterEffect

◆ onNodeAt()

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

Reimplemented from sksg::EffectNode.

Definition at line 135 of file SkSGRenderEffect.cpp.

135 {
136 // TODO: map p through the filter DAG and dispatch to descendants?
137 // For now, image filters occlude hit-testing.
138 SkASSERT(this->bounds().contains(p.x(), p.y()));
139 return this;
140}
#define SkASSERT(cond)
Definition: SkAssert.h:116
const SkRect & bounds() const
Definition: SkSGNode.h:55
constexpr bool contains(std::string_view str, std::string_view needle)
Definition: SkStringView.h:41
constexpr float x() const
Definition: SkPoint_impl.h:181

◆ onRender()

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

Reimplemented from sksg::EffectNode.

Definition at line 142 of file SkSGRenderEffect.cpp.

142 {
143 // Note: we're using the source content bounds for saveLayer, not our local/filtered bounds.
144 const auto filter_ctx =
145 ScopedRenderContext(canvas, ctx).setFilterIsolation(this->getChild()->bounds(),
146 canvas->getTotalMatrix(),
147 fImageFilter->getFilter());
148 this->INHERITED::onRender(canvas, filter_ctx);
149}
SkMatrix getTotalMatrix() const
Definition: SkCanvas.cpp:1629
const sk_sp< RenderNode > & getChild() const
void onRender(SkCanvas *, const RenderContext *) const override

◆ onRevalidate()

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

Reimplemented from sksg::EffectNode.

Definition at line 113 of file SkSGRenderEffect.cpp.

113 {
114 const auto content_bounds = this->INHERITED::onRevalidate(ic, ctm);
115
116 if (fCropping == Cropping::kContent) {
117 fImageFilter->setCropRect(content_bounds);
118 } else {
119 fImageFilter->setCropRect(std::nullopt);
120 }
121
122 // FIXME: image filter effects should replace the descendents' damage!
123 fImageFilter->revalidate(ic, ctm);
124
125 const auto& filter = fImageFilter->getFilter();
126
127 // Would be nice for this this to stick, but canComputeFastBounds()
128 // appears to be conservative (false negatives).
129 // SkASSERT(!filter || filter->canComputeFastBounds());
130
131 return filter ? filter->computeFastBounds(content_bounds)
132 : content_bounds;
133}
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override

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