Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
modules
sksg
src
SkSGGroup.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2017 Google Inc.
3
*
4
* Use of this source code is governed by a BSD-style license that can be
5
* found in the LICENSE file.
6
*/
7
8
#include "
modules/sksg/include/SkSGGroup.h
"
9
10
#include "
include/core/SkCanvas.h
"
11
#include "
include/private/base/SkAssert.h
"
12
#include "
include/private/base/SkDebug.h
"
13
#include "
modules/sksg/include/SkSGNode.h
"
14
15
#include <algorithm>
16
17
class
SkMatrix
;
18
struct
SkPoint
;
19
20
namespace
sksg
{
21
class
InvalidationController;
22
23
Group::Group
() =
default
;
24
25
Group::Group
(std::vector<
sk_sp<RenderNode>
> children)
26
: fChildren(
std
::move(children)) {
27
for
(
const
auto
& child : fChildren) {
28
this->
observeInval
(child);
29
}
30
}
31
32
Group::~Group
() {
33
for
(
const
auto
& child : fChildren) {
34
this->
unobserveInval
(child);
35
}
36
}
37
38
void
Group::clear
() {
39
for
(
const
auto
& child : fChildren) {
40
this->
unobserveInval
(child);
41
}
42
fChildren.clear();
43
}
44
45
void
Group::addChild
(
sk_sp<RenderNode>
node) {
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
}
58
59
void
Group::removeChild
(
const
sk_sp<RenderNode>
& node) {
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
}
67
68
void
Group::onRender
(
SkCanvas
* canvas,
const
RenderContext
* ctx)
const
{
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
}
77
78
const
RenderNode
*
Group::onNodeAt
(
const
SkPoint
& p)
const
{
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
}
87
88
SkRect
Group::onRevalidate
(
InvalidationController
* ic,
const
SkMatrix
& ctm) {
89
SkASSERT
(this->
hasInval
());
90
91
SkRect
bounds
=
SkRect::MakeEmpty
();
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
}
118
119
}
// namespace sksg
SkAssert.h
SkASSERT
#define SkASSERT(cond)
Definition
SkAssert.h:116
SkCanvas.h
SkDebug.h
SkDEBUGCODE
#define SkDEBUGCODE(...)
Definition
SkDebug.h:23
SkSGGroup.h
SkSGNode.h
SkCanvas
Definition
SkCanvas.h:106
SkCanvas::getTotalMatrix
SkMatrix getTotalMatrix() const
Definition
SkCanvas.cpp:1953
SkMatrix
Definition
SkMatrix.h:54
sk_sp
Definition
SkRefCnt.h:220
sksg::Group::onRevalidate
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
Definition
SkSGGroup.cpp:88
sksg::Group::removeChild
void removeChild(const sk_sp< RenderNode > &)
Definition
SkSGGroup.cpp:59
sksg::Group::onRender
void onRender(SkCanvas *, const RenderContext *) const override
Definition
SkSGGroup.cpp:68
sksg::Group::Group
Group()
sksg::Group::~Group
~Group() override
Definition
SkSGGroup.cpp:32
sksg::Group::addChild
void addChild(sk_sp< RenderNode >)
Definition
SkSGGroup.cpp:45
sksg::Group::onNodeAt
const RenderNode * onNodeAt(const SkPoint &) const override
Definition
SkSGGroup.cpp:78
sksg::Group::clear
void clear()
Definition
SkSGGroup.cpp:38
sksg::InvalidationController
Definition
SkSGInvalidationController.h:24
sksg::Node::observeInval
void observeInval(const sk_sp< Node > &)
Definition
SkSGNode.cpp:61
sksg::Node::unobserveInval
void unobserveInval(const sk_sp< Node > &)
Definition
SkSGNode.cpp:84
sksg::Node::bounds
const SkRect & bounds() const
Definition
SkSGNode.h:55
sksg::Node::hasInval
bool hasInval() const
Definition
SkSGNode.h:60
sksg::Node::invalidate
void invalidate(bool damage=true)
Definition
SkSGNode.cpp:113
sksg::RenderNode::ScopedRenderContext
Definition
SkSGRenderNode.h:75
sksg::RenderNode::ScopedRenderContext::setIsolation
ScopedRenderContext && setIsolation(const SkRect &bounds, const SkMatrix &ctm, bool do_isolate)
Definition
SkSGRenderNode.cpp:193
sksg::RenderNode
Definition
SkSGRenderNode.h:34
sksg
Definition
Skottie.h:32
std
Definition
ref_ptr.h:256
SkPoint
Definition
SkPoint_impl.h:163
SkRect
Definition
extension.cpp:13
SkRect::MakeEmpty
static constexpr SkRect MakeEmpty()
Definition
SkRect.h:595
SkRect::join
void join(const SkRect &r)
Definition
SkRect.cpp:126
sksg::RenderNode::RenderContext
Definition
SkSGRenderNode.h:60
Generated on Fri Apr 26 2024 06:16:23 for Flutter Engine by
1.9.8