Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
sksg::Group Class Reference

#include <SkSGGroup.h>

Inheritance diagram for sksg::Group:
sksg::RenderNode sksg::Node SkRefCnt SkRefCntBase skottie::internal::TextAdapter::GlyphDecoratorNode

Public Member Functions

void addChild (sk_sp< RenderNode >)
 
void removeChild (const sk_sp< RenderNode > &)
 
size_t size () const
 
bool empty () const
 
void clear ()
 
- 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< GroupMake ()
 
static sk_sp< GroupMake (std::vector< sk_sp< RenderNode > > children)
 

Protected Member Functions

 Group ()
 
 Group (std::vector< sk_sp< RenderNode > >)
 
 ~Group () override
 
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::RenderNode
 RenderNode (uint32_t inval_traits=0)
 
- Protected Member Functions inherited from sksg::Node
 Node (uint32_t invalTraits)
 
 ~Node () override
 
const SkRectbounds () const
 
bool hasInval () const
 
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 node, grouping together multiple descendants.

Definition at line 29 of file SkSGGroup.h.

Constructor & Destructor Documentation

◆ Group() [1/2]

sksg::Group::Group ( )
protecteddefault

◆ Group() [2/2]

sksg::Group::Group ( std::vector< sk_sp< RenderNode > >  children)
explicitprotected

Definition at line 25 of file SkSGGroup.cpp.

26 : fChildren(std::move(children)) {
27 for (const auto& child : fChildren) {
28 this->observeInval(child);
29 }
30}
void observeInval(const sk_sp< Node > &)
Definition SkSGNode.cpp:61

◆ ~Group()

sksg::Group::~Group ( )
overrideprotected

Definition at line 32 of file SkSGGroup.cpp.

32 {
33 for (const auto& child : fChildren) {
34 this->unobserveInval(child);
35 }
36}
void unobserveInval(const sk_sp< Node > &)
Definition SkSGNode.cpp:84

Member Function Documentation

◆ addChild()

void sksg::Group::addChild ( sk_sp< RenderNode node)

Definition at line 45 of file SkSGGroup.cpp.

45 {
46 // should we allow duplicates?
47 for (const auto& child : fChildren) {
48 if (child == node) {
49 return;
50 }
51 }
52
53 this->observeInval(node);
54 fChildren.push_back(std::move(node));
55
56 this->invalidate();
57}
void invalidate(bool damage=true)
Definition SkSGNode.cpp:113

◆ clear()

void sksg::Group::clear ( )

Definition at line 38 of file SkSGGroup.cpp.

38 {
39 for (const auto& child : fChildren) {
40 this->unobserveInval(child);
41 }
42 fChildren.clear();
43}

◆ empty()

bool sksg::Group::empty ( ) const
inline

Definition at line 43 of file SkSGGroup.h.

43{ return fChildren.empty(); }

◆ Make() [1/2]

static sk_sp< Group > sksg::Group::Make ( )
inlinestatic

Definition at line 31 of file SkSGGroup.h.

31 {
32 return sk_sp<Group>(new Group(std::vector<sk_sp<RenderNode>>()));
33 }

◆ Make() [2/2]

static sk_sp< Group > sksg::Group::Make ( std::vector< sk_sp< RenderNode > >  children)
inlinestatic

Definition at line 35 of file SkSGGroup.h.

35 {
36 return sk_sp<Group>(new Group(std::move(children)));
37 }

◆ onNodeAt()

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

Implements sksg::RenderNode.

Definition at line 78 of file SkSGGroup.cpp.

78 {
79 for (auto it = fChildren.crbegin(); it != fChildren.crend(); ++it) {
80 if (const auto* node = (*it)->nodeAt(p)) {
81 return node;
82 }
83 }
84
85 return nullptr;
86}

◆ onRender()

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

Implements sksg::RenderNode.

Definition at line 68 of file SkSGGroup.cpp.

68 {
69 const auto local_ctx = ScopedRenderContext(canvas, ctx).setIsolation(this->bounds(),
70 canvas->getTotalMatrix(),
71 fRequiresIsolation);
72
73 for (const auto& child : fChildren) {
74 child->render(canvas, local_ctx);
75 }
76}
SkMatrix getTotalMatrix() const
const SkRect & bounds() const
Definition SkSGNode.h:55

◆ onRevalidate()

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

Implements sksg::Node.

Definition at line 88 of file SkSGGroup.cpp.

88 {
89 SkASSERT(this->hasInval());
90
92 fRequiresIsolation = false;
93
94 for (size_t i = 0; i < fChildren.size(); ++i) {
95 const auto child_bounds = fChildren[i]->revalidate(ic, ctm);
96
97 // If any of the child nodes overlap, group effects require layer isolation.
98 if (!fRequiresIsolation && i > 0 && child_bounds.intersects(bounds)) {
99#if 1
100 // Testing conservatively against the union of prev bounds is cheap and good enough.
101 fRequiresIsolation = true;
102#else
103 // Testing exhaustively doesn't seem to increase the layer elision rate in practice.
104 for (size_t j = 0; j < i; ++ j) {
105 if (child_bounds.intersects(fChildren[i]->bounds())) {
106 fRequiresIsolation = true;
107 break;
108 }
109 }
110#endif
111 }
112
113 bounds.join(child_bounds);
114 }
115
116 return bounds;
117}
#define SkASSERT(cond)
Definition SkAssert.h:116
bool hasInval() const
Definition SkSGNode.h:60
static constexpr SkRect MakeEmpty()
Definition SkRect.h:595
void join(const SkRect &r)
Definition SkRect.cpp:126

◆ removeChild()

void sksg::Group::removeChild ( const sk_sp< RenderNode > &  node)

Definition at line 59 of file SkSGGroup.cpp.

59 {
60 SkDEBUGCODE(const auto origSize = fChildren.size());
61 fChildren.erase(std::remove(fChildren.begin(), fChildren.end(), node), fChildren.end());
62 SkASSERT(fChildren.size() == origSize - 1);
63
64 this->unobserveInval(node);
65 this->invalidate();
66}
#define SkDEBUGCODE(...)
Definition SkDebug.h:23

◆ size()

size_t sksg::Group::size ( ) const
inline

Definition at line 42 of file SkSGGroup.h.

42{ return fChildren.size(); }

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