Flutter Engine
 
Loading...
Searching...
No Matches
flutter::ContainerLayer Class Reference

#include <container_layer.h>

Inheritance diagram for flutter::ContainerLayer:
flutter::Layer flutter::BackdropFilterLayer flutter::CacheableContainerLayer flutter::TransformLayer flutter::ClipShapeLayer< DlPath > flutter::ClipShapeLayer< DlRoundRect > flutter::ClipShapeLayer< DlRoundSuperellipse > flutter::ClipShapeLayer< DlRect > 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 DlRectchild_paint_bounds () const
 
void set_child_paint_bounds (const DlRect &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 DlRectpaint_bounds () const
 
void set_paint_bounds (const DlRect &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, DlRect *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{}

Member Function Documentation

◆ Add()

◆ 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 DlRect & flutter::ContainerLayer::child_paint_bounds ( ) const
inline

◆ 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 }

Referenced by PaintChildren().

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

References flutter::DiffContext::CurrentSubtreeRegion(), DiffChildren(), and flutter::DiffContext::SetLayerPaintRegion().

Referenced by flutter::testing::DiffContextTest::DiffLayerTree(), and flutter::testing::TEST_F().

◆ 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:139
#define FML_DCHECK(condition)
Definition logging.h:122

References flutter::DiffContext::AddDamage(), flutter::DiffContext::AddExistingPaintRegion(), FML_DCHECK, flutter::DiffContext::GetOldLayerPaintRegion(), i, flutter::Layer::IsReplacing(), flutter::DiffContext::IsSubtreeDirty(), and flutter::DiffContext::MarkSubtreeDirty().

Referenced by flutter::BackdropFilterLayer::Diff(), flutter::ClipShapeLayer< T >::Diff(), flutter::ColorFilterLayer::Diff(), Diff(), flutter::ImageFilterLayer::Diff(), flutter::OpacityLayer::Diff(), flutter::ShaderMaskLayer::Diff(), and flutter::TransformLayer::Diff().

◆ 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_; }

Referenced by flutter::RasterCacheKeyID::LayerChildrenIds(), and flutter::TEST_F().

◆ 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:218

References FML_DCHECK, flutter::Layer::needs_painting(), and PaintChildren().

◆ PaintChildren()

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

Reimplemented from flutter::Layer.

Definition at line 169 of file container_layer.cc.

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

References flutter::LayerStateStack::applyState(), child_paint_bounds(), children_renderable_state_flags(), and flutter::PaintContext::state_stack.

Referenced by flutter::BackdropFilterLayer::Paint(), flutter::ClipShapeLayer< T >::Paint(), flutter::ColorFilterLayer::Paint(), Paint(), flutter::ImageFilterLayer::Paint(), flutter::OpacityLayer::Paint(), flutter::ShaderMaskLayer::Paint(), and flutter::TransformLayer::Paint().

◆ Preroll()

◆ PrerollChildren()

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

Definition at line 122 of file container_layer.cc.

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

References child_paint_bounds(), FML_DCHECK, flutter::PrerollContext::has_platform_view, flutter::PrerollContext::has_texture_layer, impeller::TRect< T >::IntersectsWithRect(), flutter::LayerStateStack::kCallerCanApplyAnything, flutter::PrerollContext::renderable_state_flags, set_child_paint_bounds(), set_children_renderable_state_flags(), flutter::Layer::set_subtree_has_platform_view(), and impeller::TRect< T >::Union().

Referenced by flutter::BackdropFilterLayer::Preroll(), flutter::ClipShapeLayer< T >::Preroll(), Preroll(), flutter::ImageFilterLayer::Preroll(), and flutter::TransformLayer::Preroll().

◆ 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:149

References flutter::Layer::PreservePaintRegion().

◆ set_child_paint_bounds()

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

Definition at line 36 of file container_layer.h.

36 {
37 child_paint_bounds_ = bounds;
38 }

Referenced by PrerollChildren().

◆ 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 }

Referenced by PrerollChildren().


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