Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Protected Types | Protected Member Functions | Friends | List of all members
sksg::Node Class Referenceabstract

#include <SkSGNode.h>

Inheritance diagram for sksg::Node:
SkRefCnt SkRefCntBase sksg::GeometryNode sksg::ImageFilter sksg::PaintNode sksg::RenderNode sksg::Shader sksg::Transform sksg::GeometryEffect sksg::Merge sksg::Path sksg::Plane sksg::RRect sksg::Rect sksg::Text sksg::BlurImageFilter sksg::DropShadowImageFilter sksg::ExternalImageFilter sksg::Color sksg::ShaderPaint sksg::CustomRenderNode sksg::Draw sksg::EffectNode sksg::Group sksg::Image sksg::Gradient sksg::Matrix< SkMatrix > sksg::Matrix< SkM44 > sksg::Matrix< T >

Classes

class  ScopedFlag
 

Public Member Functions

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
 

Protected Types

enum  InvalTraits { kBubbleDamage_Trait = 1 << 0 , kOverrideDamage_Trait = 1 << 1 }
 

Protected Member Functions

 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 > &)
 

Friends

class NodePriv
 
class RenderNode
 

Detailed Description

Base class for all scene graph nodes.

Handles ingress edge management for the DAG (i.e. node -> "parent" node mapping), and invalidation.

Note: egress edges are only implemented/supported in container subclasses (e.g. Group, Effect, Draw).

Definition at line 33 of file SkSGNode.h.

Member Enumeration Documentation

◆ InvalTraits

enum sksg::Node::InvalTraits
protected
Enumerator
kBubbleDamage_Trait 
kOverrideDamage_Trait 

Definition at line 43 of file SkSGNode.h.

43 {
44 // Nodes with this trait never generate direct damage -- instead,
45 // the damage bubbles up to ancestors.
46 kBubbleDamage_Trait = 1 << 0,
47
48 // Nodes with this trait obscure the descendants' damage and always override it.
49 kOverrideDamage_Trait = 1 << 1,
50 };
@ kOverrideDamage_Trait
Definition: SkSGNode.h:49
@ kBubbleDamage_Trait
Definition: SkSGNode.h:46

Constructor & Destructor Documentation

◆ Node()

Node::Node ( uint32_t  invalTraits)
explicitprotected

Definition at line 45 of file SkSGNode.cpp.

46 : fInvalObserver(nullptr)
47 , fBounds(SkRectPriv::MakeLargeS32())
48 , fInvalTraits(invalTraits)
49 , fFlags(kInvalidated_Flag)
50 , fNodeFlags(0) {}
static SkRect MakeLargeS32()
Definition: SkRectPriv.h:33
Node * fInvalObserver
Definition: SkSGNode.h:84

◆ ~Node()

Node::~Node ( )
overrideprotected

Definition at line 52 of file SkSGNode.cpp.

52 {
53 if (fFlags & kObserverArray_Flag) {
56 } else {
58 }
59}
#define SkASSERT(cond)
Definition: SkAssert.h:116
std::vector< Node * > * fInvalObserverArray
Definition: SkSGNode.h:85

Member Function Documentation

◆ bounds()

const SkRect & sksg::Node::bounds ( ) const
inlineprotected

Definition at line 55 of file SkSGNode.h.

55 {
56 SkASSERT(!this->hasInval());
57 return fBounds;
58 }
bool hasInval() const
Definition: SkSGNode.h:60

◆ hasInval()

bool sksg::Node::hasInval ( ) const
inlineprotected

Definition at line 60 of file SkSGNode.h.

60{ return fFlags & kInvalidated_Flag; }

◆ invalidate()

void Node::invalidate ( bool  damage = true)

Definition at line 113 of file SkSGNode.cpp.

113 {
115
116 if (this->hasInval() && (!damageBubbling || (fFlags & kDamage_Flag))) {
117 // All done.
118 return;
119 }
120
121 if (damageBubbling && !(fInvalTraits & kBubbleDamage_Trait)) {
122 // Found a damage observer.
123 fFlags |= kDamage_Flag;
124 damageBubbling = false;
125 }
126
127 fFlags |= kInvalidated_Flag;
128
129 forEachInvalObserver([&](Node* observer) {
130 observer->invalidate(damageBubbling);
131 });
132}
#define TRAVERSAL_GUARD
Definition: SkSGNode.cpp:40
Definition: dart.idl:29

◆ observeInval()

void Node::observeInval ( const sk_sp< Node > &  node)
protected

Definition at line 61 of file SkSGNode.cpp.

61 {
62 SkASSERT(node);
63 if (!(node->fFlags & kObserverArray_Flag)) {
64 if (!node->fInvalObserver) {
65 node->fInvalObserver = this;
66 return;
67 }
68
69 auto observers = new std::vector<Node*>();
70 observers->reserve(2);
71 observers->push_back(node->fInvalObserver);
72
73 node->fInvalObserverArray = observers;
74 node->fFlags |= kObserverArray_Flag;
75 }
76
77 // No duplicate observers.
78 SkASSERT(std::find(node->fInvalObserverArray->begin(),
79 node->fInvalObserverArray->end(), this) == node->fInvalObserverArray->end());
80
81 node->fInvalObserverArray->push_back(this);
82}
int find(T *array, int N, T item)

◆ onRevalidate()

virtual SkRect sksg::Node::onRevalidate ( InvalidationController ,
const SkMatrix ctm 
)
protectedpure virtual

◆ revalidate()

const SkRect & Node::revalidate ( InvalidationController ic,
const SkMatrix ctm 
)

Definition at line 134 of file SkSGNode.cpp.

134 {
135 TRAVERSAL_GUARD fBounds;
136
137 if (!this->hasInval()) {
138 return fBounds;
139 }
140
141 const auto generate_damage =
142 ic && ((fFlags & kDamage_Flag) || (fInvalTraits & kOverrideDamage_Trait));
143 if (!generate_damage) {
144 // Trivial transitive revalidation.
145 fBounds = this->onRevalidate(ic, ctm);
146 } else {
147 // Revalidate and emit damage for old-bounds, new-bounds.
148 const auto prev_bounds = fBounds;
149
150 auto* ic_override = (fInvalTraits & kOverrideDamage_Trait) ? nullptr : ic;
151 fBounds = this->onRevalidate(ic_override, ctm);
152
153 ic->inval(prev_bounds, ctm);
154 if (fBounds != prev_bounds) {
155 ic->inval(fBounds, ctm);
156 }
157 }
158
159 fFlags &= ~(kInvalidated_Flag | kDamage_Flag);
160
161 return fBounds;
162}
const SkRect fBounds
virtual SkRect onRevalidate(InvalidationController *, const SkMatrix &ctm)=0

◆ unobserveInval()

void Node::unobserveInval ( const sk_sp< Node > &  node)
protected

Definition at line 84 of file SkSGNode.cpp.

84 {
85 SkASSERT(node);
86 if (!(node->fFlags & kObserverArray_Flag)) {
87 SkASSERT(node->fInvalObserver == this);
88 node->fInvalObserver = nullptr;
89 return;
90 }
91
92 SkDEBUGCODE(const auto origSize = node->fInvalObserverArray->size());
93 node->fInvalObserverArray->erase(std::remove(node->fInvalObserverArray->begin(),
94 node->fInvalObserverArray->end(), this),
95 node->fInvalObserverArray->end());
96 SkASSERT(node->fInvalObserverArray->size() == origSize - 1);
97}
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
def remove(*paths)

Friends And Related Function Documentation

◆ NodePriv

friend class NodePriv
friend

Definition at line 93 of file SkSGNode.h.

◆ RenderNode

friend class RenderNode
friend

Definition at line 94 of file SkSGNode.h.

Member Data Documentation

◆ fInvalObserver

Node* sksg::Node::fInvalObserver

Definition at line 84 of file SkSGNode.h.

◆ fInvalObserverArray

std::vector<Node*>* sksg::Node::fInvalObserverArray

Definition at line 85 of file SkSGNode.h.


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