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

#include <container_layer.h>

Inheritance diagram for flutter::ContainerLayer:
flutter::Layer flutter::BackdropFilterLayer flutter::CacheableContainerLayer flutter::TransformLayer flutter::ClipShapeLayer< SkPath > flutter::ClipShapeLayer< SkRRect > flutter::ClipShapeLayer< SkRect > flutter::ClipShapeLayer< T > flutter::ColorFilterLayer flutter::ImageFilterLayer flutter::OpacityLayer flutter::ShaderMaskLayer flutter::testing::MockCacheableContainerLayer

Public Member Functions

 ContainerLayer ()
 
void Diff (DiffContext *context, const Layer *old_layer) override
 
void PreservePaintRegion (DiffContext *context) override
 
virtual void Add (std::shared_ptr< Layer > layer)
 
void Preroll (PrerollContext *context) override
 
void Paint (PaintContext &context) const override
 
const std::vector< std::shared_ptr< Layer > > & layers () const
 
virtual void DiffChildren (DiffContext *context, const ContainerLayer *old_layer)
 
void PaintChildren (PaintContext &context) const override
 
const ContainerLayeras_container_layer () const override
 
const SkRectchild_paint_bounds () const
 
void set_child_paint_bounds (const SkRect &bounds)
 
int children_renderable_state_flags () const
 
void set_children_renderable_state_flags (int flags)
 
- Public Member Functions inherited from flutter::Layer
 Layer ()
 
virtual ~Layer ()
 
void AssignOldLayer (Layer *old_layer)
 
virtual bool IsReplacing (DiffContext *context, const Layer *old_layer) const
 
bool subtree_has_platform_view () const
 
void set_subtree_has_platform_view (bool value)
 
const SkRectpaint_bounds () const
 
void set_paint_bounds (const SkRect &paint_bounds)
 
bool is_empty () const
 
bool needs_painting (PaintContext &context) const
 
uint64_t original_layer_id () const
 
uint64_t unique_id () const
 
virtual RasterCacheKeyID caching_key_id () const
 
virtual const DisplayListLayeras_display_list_layer () const
 
virtual const TextureLayeras_texture_layer () const
 
virtual const PerformanceOverlayLayeras_performance_overlay_layer () const
 
virtual const testing::MockLayeras_mock_layer () const
 

Protected Member Functions

void PrerollChildren (PrerollContext *context, SkRect *child_paint_bounds)
 

Additional Inherited Members

- Static Public Attributes inherited from flutter::Layer
static constexpr int kSaveLayerRenderFlags
 
static constexpr int kRasterCacheRenderFlags
 

Detailed Description

Definition at line 14 of file container_layer.h.

Constructor & Destructor Documentation

◆ ContainerLayer()

flutter::ContainerLayer::ContainerLayer ( )

Definition at line 11 of file container_layer.cc.

11: child_paint_bounds_(SkRect::MakeEmpty()) {}
static constexpr SkRect MakeEmpty()
Definition SkRect.h:595

Member Function Documentation

◆ Add()

void flutter::ContainerLayer::Add ( std::shared_ptr< Layer layer)
virtual

Definition at line 106 of file container_layer.cc.

106 {
107 layers_.emplace_back(std::move(layer));
108}

◆ as_container_layer()

const ContainerLayer * flutter::ContainerLayer::as_container_layer ( ) const
inlineoverridevirtual

Reimplemented from flutter::Layer.

Definition at line 33 of file container_layer.h.

33{ return this; }

◆ child_paint_bounds()

const SkRect & flutter::ContainerLayer::child_paint_bounds ( ) const
inline

Definition at line 35 of file container_layer.h.

35{ return child_paint_bounds_; }

◆ children_renderable_state_flags()

int flutter::ContainerLayer::children_renderable_state_flags ( ) const
inline

Definition at line 40 of file container_layer.h.

40 {
41 return children_renderable_state_flags_;
42 }

◆ Diff()

void flutter::ContainerLayer::Diff ( DiffContext context,
const Layer old_layer 
)
overridevirtual

Reimplemented from flutter::Layer.

Reimplemented in flutter::ImageFilterLayer, flutter::OpacityLayer, flutter::ShaderMaskLayer, and flutter::TransformLayer.

Definition at line 13 of file container_layer.cc.

13 {
14 auto old_container = static_cast<const ContainerLayer*>(old_layer);
15 DiffContext::AutoSubtreeRestore subtree(context);
16 DiffChildren(context, old_container);
17 context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
18}
virtual void DiffChildren(DiffContext *context, const ContainerLayer *old_layer)

◆ DiffChildren()

void flutter::ContainerLayer::DiffChildren ( DiffContext context,
const ContainerLayer old_layer 
)
virtual

Definition at line 27 of file container_layer.cc.

28 {
29 if (context->IsSubtreeDirty()) {
30 for (auto& layer : layers_) {
31 layer->Diff(context, nullptr);
32 }
33 return;
34 }
35 FML_DCHECK(old_layer);
36
37 const auto& prev_layers = old_layer->layers_;
38
39 // first mismatched element
40 int new_children_top = 0;
41 int old_children_top = 0;
42
43 // last mismatched element
44 int new_children_bottom = layers_.size() - 1;
45 int old_children_bottom = prev_layers.size() - 1;
46
47 while ((old_children_top <= old_children_bottom) &&
48 (new_children_top <= new_children_bottom)) {
49 if (!layers_[new_children_top]->IsReplacing(
50 context, prev_layers[old_children_top].get())) {
51 break;
52 }
53 ++new_children_top;
54 ++old_children_top;
55 }
56
57 while ((old_children_top <= old_children_bottom) &&
58 (new_children_top <= new_children_bottom)) {
59 if (!layers_[new_children_bottom]->IsReplacing(
60 context, prev_layers[old_children_bottom].get())) {
61 break;
62 }
63 --new_children_bottom;
64 --old_children_bottom;
65 }
66
67 // old layers that don't match
68 for (int i = old_children_top; i <= old_children_bottom; ++i) {
69 auto layer = prev_layers[i];
70 context->AddDamage(context->GetOldLayerPaintRegion(layer.get()));
71 }
72
73 for (int i = 0; i < static_cast<int>(layers_.size()); ++i) {
74 if (i < new_children_top || i > new_children_bottom) {
75 int i_prev =
76 i < new_children_top ? i : prev_layers.size() - (layers_.size() - i);
77 auto layer = layers_[i];
78 auto prev_layer = prev_layers[i_prev];
79 auto paint_region = context->GetOldLayerPaintRegion(prev_layer.get());
80 if (layer == prev_layer && !paint_region.has_readback() &&
81 !paint_region.has_texture()) {
82 // for retained layers, stop processing the subtree and add existing
83 // region; We know current subtree is not dirty (every ancestor up to
84 // here matches) so the retained subtree will render identically to
85 // previous frame; We can only do this if there is no readback in the
86 // subtree. Layers that do readback must be able to register readback
87 // inside Diff
88 context->AddExistingPaintRegion(paint_region);
89
90 // While we don't need to diff retained layers, we still need to
91 // associate their paint region with current layer tree so that we can
92 // retrieve it in next frame diff
93 layer->PreservePaintRegion(context);
94 } else {
95 layer->Diff(context, prev_layer.get());
96 }
97 } else {
98 DiffContext::AutoSubtreeRestore subtree(context);
99 context->MarkSubtreeDirty();
100 auto layer = layers_[i];
101 layer->Diff(context, nullptr);
102 }
103 }
104}
virtual bool IsReplacing(DiffContext *context, const Layer *old_layer) const
Definition layer.h:152
#define FML_DCHECK(condition)
Definition logging.h:103
const myers::Point & get(const myers::Segment &)

◆ layers()

const std::vector< std::shared_ptr< Layer > > & flutter::ContainerLayer::layers ( ) const
inline

Definition at line 26 of file container_layer.h.

26{ return layers_; }

◆ Paint()

void flutter::ContainerLayer::Paint ( PaintContext context) const
overridevirtual

Implements flutter::Layer.

Reimplemented in flutter::ImageFilterLayer, flutter::OpacityLayer, flutter::ShaderMaskLayer, and flutter::TransformLayer.

Definition at line 116 of file container_layer.cc.

116 {
117 FML_DCHECK(needs_painting(context));
118
119 PaintChildren(context);
120}
void PaintChildren(PaintContext &context) const override
bool needs_painting(PaintContext &context) const
Definition layer.h:231

◆ PaintChildren()

void flutter::ContainerLayer::PaintChildren ( PaintContext context) const
overridevirtual

Reimplemented from flutter::Layer.

Definition at line 176 of file container_layer.cc.

176 {
177 // We can no longer call FML_DCHECK here on the needs_painting(context)
178 // condition as that test is only valid for the PaintContext that
179 // is initially handed to a layer's Paint() method. By the time the
180 // layer calls PaintChildren(), though, it may have modified the
181 // PaintContext so the test doesn't work in this "context".
182
183 // Apply any outstanding state that the children cannot individually
184 // and collectively handle.
185 auto restore = context.state_stack.applyState(
187
188 // Intentionally not tracing here as there should be no self-time
189 // and the trace event on this common function has a small overhead.
190 for (auto& layer : layers_) {
191 if (layer->needs_painting(context)) {
192 layer->Paint(context);
193 }
194 }
195}
int children_renderable_state_flags() const
const SkRect & child_paint_bounds() const

◆ Preroll()

void flutter::ContainerLayer::Preroll ( PrerollContext context)
overridevirtual

Implements flutter::Layer.

Reimplemented in flutter::ImageFilterLayer, flutter::OpacityLayer, flutter::ShaderMaskLayer, flutter::TransformLayer, and flutter::testing::MockCacheableContainerLayer.

Definition at line 110 of file container_layer.cc.

110 {
114}
void PrerollChildren(PrerollContext *context, SkRect *child_paint_bounds)
void set_paint_bounds(const SkRect &paint_bounds)
Definition layer.h:222

◆ PrerollChildren()

void flutter::ContainerLayer::PrerollChildren ( PrerollContext context,
SkRect child_paint_bounds 
)
protected

Definition at line 129 of file container_layer.cc.

130 {
131 // Platform views have no children, so context->has_platform_view should
132 // always be false.
133 FML_DCHECK(!context->has_platform_view);
134 FML_DCHECK(!context->has_texture_layer);
135
136 bool child_has_platform_view = false;
137 bool child_has_texture_layer = false;
138 bool all_renderable_state_flags = LayerStateStack::kCallerCanApplyAnything;
139
140 for (auto& layer : layers_) {
141 // Reset context->has_platform_view and context->has_texture_layer to false
142 // so that layers aren't treated as if they have a platform view or texture
143 // layer based on one being previously found in a sibling tree.
144 context->has_platform_view = false;
145 context->has_texture_layer = false;
146
147 // Initialize the renderable state flags to false to force the layer to
148 // opt-in to applying state attributes during its |Preroll|
149 context->renderable_state_flags = 0;
150
151 layer->Preroll(context);
152
153 all_renderable_state_flags &= context->renderable_state_flags;
154 if (safe_intersection_test(child_paint_bounds, layer->paint_bounds())) {
155 // This will allow inheritance by a linear sequence of non-overlapping
156 // children, but will fail with a grid or other arbitrary 2D layout.
157 // See https://github.com/flutter/flutter/issues/93899
158 all_renderable_state_flags = 0;
159 }
160 child_paint_bounds->join(layer->paint_bounds());
161
162 child_has_platform_view =
163 child_has_platform_view || context->has_platform_view;
164 child_has_texture_layer =
165 child_has_texture_layer || context->has_texture_layer;
166 }
167
168 context->has_platform_view = child_has_platform_view;
169 context->has_texture_layer = child_has_texture_layer;
170 context->renderable_state_flags = all_renderable_state_flags;
171 set_subtree_has_platform_view(child_has_platform_view);
172 set_children_renderable_state_flags(all_renderable_state_flags);
174}
void set_children_renderable_state_flags(int flags)
void set_child_paint_bounds(const SkRect &bounds)
static constexpr int kCallerCanApplyAnything
void set_subtree_has_platform_view(bool value)
Definition layer.h:201
static bool safe_intersection_test(const SkRect *rect1, const SkRect &rect2)
void join(const SkRect &r)
Definition SkRect.cpp:126

◆ PreservePaintRegion()

void flutter::ContainerLayer::PreservePaintRegion ( DiffContext context)
overridevirtual

Reimplemented from flutter::Layer.

Definition at line 20 of file container_layer.cc.

20 {
22 for (auto& layer : layers_) {
23 layer->PreservePaintRegion(context);
24 }
25}
virtual void PreservePaintRegion(DiffContext *context)
Definition layer.h:162

◆ set_child_paint_bounds()

void flutter::ContainerLayer::set_child_paint_bounds ( const SkRect bounds)
inline

Definition at line 36 of file container_layer.h.

36 {
37 child_paint_bounds_ = bounds;
38 }
Optional< SkRect > bounds
Definition SkRecords.h:189

◆ set_children_renderable_state_flags()

void flutter::ContainerLayer::set_children_renderable_state_flags ( int  flags)
inline

Definition at line 43 of file container_layer.h.

43 {
44 children_renderable_state_flags_ = flags;
45 }
FlutterSemanticsFlag flags

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