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

#include <diff_context.h>

Classes

class  AutoSubtreeRestore
 
class  Statistics
 

Public Types

using FilterBoundsAdjustment = std::function< DlRect(DlRect)>
 

Public Member Functions

 DiffContext (DlISize frame_size, PaintRegionMap &this_frame_paint_region_map, const PaintRegionMap &last_frame_paint_region_map, bool has_raster_cache, bool impeller_enabled)
 
void BeginSubtree ()
 
void EndSubtree ()
 
void PushTransform (const DlMatrix &transform)
 
bool PushCullRect (const DlRect &clip)
 
void PushFilterBoundsAdjustment (const FilterBoundsAdjustment &filter)
 
void WillPaintWithIntegralTransform ()
 
const DlMatrixGetMatrix () const
 
DlRect GetCullRect () const
 
void MarkSubtreeDirty (const PaintRegion &previous_paint_region=PaintRegion())
 
void MarkSubtreeDirty (const DlRect &previous_paint_region)
 
bool IsSubtreeDirty () const
 
void MarkSubtreeHasTextureLayer ()
 
void AddLayerBounds (const DlRect &rect)
 
void AddExistingPaintRegion (const PaintRegion &region)
 
void AddReadbackRegion (const DlIRect &paint_rect, const DlIRect &readback_rect)
 
PaintRegion CurrentSubtreeRegion () const
 
Damage ComputeDamage (const DlIRect &additional_damage, int horizontal_clip_alignment=0, int vertical_clip_alignment=0) const
 
void AddDamage (const PaintRegion &damage)
 
void SetLayerPaintRegion (const Layer *layer, const PaintRegion &region)
 
PaintRegion GetOldLayerPaintRegion (const Layer *layer) const
 
bool has_raster_cache () const
 
bool impeller_enabled () const
 
Statisticsstatistics ()
 
DlRect MapRect (const DlRect &rect)
 

Detailed Description

Definition at line 41 of file diff_context.h.

Member Typedef Documentation

◆ FilterBoundsAdjustment

Definition at line 78 of file diff_context.h.

Constructor & Destructor Documentation

◆ DiffContext()

flutter::DiffContext::DiffContext ( DlISize  frame_size,
PaintRegionMap this_frame_paint_region_map,
const PaintRegionMap last_frame_paint_region_map,
bool  has_raster_cache,
bool  impeller_enabled 
)
explicit

Definition at line 12 of file diff_context.cc.

17 : rects_(std::make_shared<std::vector<DlRect>>()),
18 frame_size_(frame_size),
19 this_frame_paint_region_map_(this_frame_paint_region_map),
20 last_frame_paint_region_map_(last_frame_paint_region_map),
21 has_raster_cache_(has_raster_cache),
22 impeller_enabled_(impeller_enabled) {}
bool impeller_enabled() const
bool has_raster_cache() const

Member Function Documentation

◆ AddDamage()

void flutter::DiffContext::AddDamage ( const PaintRegion damage)

Definition at line 230 of file diff_context.cc.

230 {
231 FML_DCHECK(damage.is_valid());
232 for (const auto& r : damage) {
233 damage_ = damage_.Union(r);
234 }
235}
#define FML_DCHECK(condition)
Definition logging.h:122
constexpr TRect Union(const TRect &o) const
Definition rect.h:513

References FML_DCHECK, flutter::PaintRegion::is_valid(), and impeller::TRect< T >::Union().

Referenced by AddLayerBounds(), flutter::ContainerLayer::DiffChildren(), MarkSubtreeDirty(), and MarkSubtreeDirty().

◆ AddExistingPaintRegion()

void flutter::DiffContext::AddExistingPaintRegion ( const PaintRegion region)

Definition at line 202 of file diff_context.cc.

202 {
203 // Adding paint region for retained layer implies that current subtree is not
204 // dirty, so we know, for example, that the inherited transforms must match
206 if (region.is_valid()) {
207 rects_->insert(rects_->end(), region.begin(), region.end());
208 }
209}
bool IsSubtreeDirty() const

References flutter::PaintRegion::begin(), flutter::PaintRegion::end(), FML_DCHECK, flutter::PaintRegion::is_valid(), and IsSubtreeDirty().

Referenced by flutter::ContainerLayer::DiffChildren().

◆ AddLayerBounds()

void flutter::DiffContext::AddLayerBounds ( const DlRect rect)

Definition at line 172 of file diff_context.cc.

172 {
173 // During painting we cull based on non-overriden transform and then
174 // override the transform right before paint. Do the same thing here to get
175 // identical paint rect.
176 auto transformed_rect = ApplyFilterBoundsAdjustment(MapRect(rect));
177 if (transformed_rect.IntersectsWithRect(
178 state_.matrix_clip.GetDeviceCullCoverage())) {
179 if (state_.integral_transform) {
180 DisplayListMatrixClipState temp_state = state_.matrix_clip;
181 MakeTransformIntegral(temp_state);
182 temp_state.mapRect(rect, &transformed_rect);
183 transformed_rect = ApplyFilterBoundsAdjustment(transformed_rect);
184 }
185 rects_->push_back(transformed_rect);
186 if (IsSubtreeDirty()) {
187 AddDamage(transformed_rect);
188 }
189 }
190}
DlRect MapRect(const DlRect &rect)
void AddDamage(const PaintRegion &damage)

References AddDamage(), IsSubtreeDirty(), MapRect(), and flutter::DisplayListMatrixClipState::mapRect().

Referenced by flutter::BackdropFilterLayer::Diff(), flutter::DisplayListLayer::Diff(), flutter::PerformanceOverlayLayer::Diff(), flutter::TextureLayer::Diff(), and flutter::testing::MockLayer::Diff().

◆ AddReadbackRegion()

void flutter::DiffContext::AddReadbackRegion ( const DlIRect paint_rect,
const DlIRect readback_rect 
)

Definition at line 211 of file diff_context.cc.

212 {
213 Readback readback;
214 readback.paint_rect = paint_rect;
215 readback.readback_rect = readback_rect;
216 readback.position = rects_->size();
217 // Push empty rect as a placeholder for position in current subtree
218 rects_->push_back(DlRect());
219 readbacks_.push_back(readback);
220}
impeller::Rect DlRect

Referenced by flutter::BackdropFilterLayer::Diff().

◆ BeginSubtree()

void flutter::DiffContext::BeginSubtree ( )

Definition at line 24 of file diff_context.cc.

24 {
25 state_stack_.push_back(state_);
26
27 bool had_integral_transform = state_.integral_transform;
28 state_.rect_index = rects_->size();
29 state_.has_filter_bounds_adjustment = false;
30 state_.has_texture = false;
31 state_.integral_transform = false;
32
33 if (had_integral_transform) {
34 MakeTransformIntegral(state_.matrix_clip);
35 }
36}

Referenced by flutter::DiffContext::AutoSubtreeRestore::AutoSubtreeRestore().

◆ ComputeDamage()

Damage flutter::DiffContext::ComputeDamage ( const DlIRect additional_damage,
int  horizontal_clip_alignment = 0,
int  vertical_clip_alignment = 0 
) const

Definition at line 104 of file diff_context.cc.

106 {
107 DlRect buffer_damage = DlRect::Make(accumulated_buffer_damage).Union(damage_);
108 DlRect frame_damage(damage_);
109
110 for (const auto& r : readbacks_) {
111 DlRect paint_rect = DlRect::Make(r.paint_rect);
112 DlRect readback_rect = DlRect::Make(r.readback_rect);
113 // Changes either in readback or paint rect require repainting both readback
114 // and paint rect.
115 if (paint_rect.IntersectsWithRect(frame_damage) ||
116 readback_rect.IntersectsWithRect(frame_damage)) {
117 frame_damage = frame_damage.Union(readback_rect).Union(paint_rect);
118 buffer_damage = buffer_damage.Union(readback_rect).Union(paint_rect);
119 }
120 }
121
122 DlIRect frame_clip = DlIRect::MakeSize(frame_size_);
123
124 Damage res;
125 res.buffer_damage =
126 DlIRect::RoundOut(buffer_damage).IntersectionOrEmpty(frame_clip);
127 res.frame_damage =
128 DlIRect::RoundOut(frame_damage).IntersectionOrEmpty(frame_clip);
129
130 if (horizontal_clip_alignment > 1 || vertical_clip_alignment > 1) {
131 AlignRect(res.buffer_damage, horizontal_clip_alignment,
132 vertical_clip_alignment);
133 AlignRect(res.frame_damage, horizontal_clip_alignment,
134 vertical_clip_alignment);
135 }
136 return res;
137}
impeller::IRect32 DlIRect
static constexpr std::enable_if_t< std::is_floating_point_v< FT >, TRect > Make(const TRect< U > &rect)
Definition rect.h:157
RoundOut(const TRect< U > &r)
Definition rect.h:679
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:150

References flutter::Damage::buffer_damage, flutter::Damage::frame_damage, impeller::TRect< T >::IntersectionOrEmpty(), impeller::TRect< T >::IntersectsWithRect(), impeller::TRect< Scalar >::Make(), impeller::TRect< T >::MakeSize(), impeller::TRect< T >::RoundOut(), and impeller::TRect< T >::Union().

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

◆ CurrentSubtreeRegion()

PaintRegion flutter::DiffContext::CurrentSubtreeRegion ( ) const

Definition at line 222 of file diff_context.cc.

222 {
223 bool has_readback = std::any_of(
224 readbacks_.begin(), readbacks_.end(),
225 [&](const Readback& r) { return r.position >= state_.rect_index; });
226 return PaintRegion(rects_, state_.rect_index, rects_->size(), has_readback,
227 state_.has_texture);
228}

Referenced by flutter::BackdropFilterLayer::Diff(), flutter::ClipShapeLayer< T >::Diff(), flutter::ColorFilterLayer::Diff(), flutter::ContainerLayer::Diff(), flutter::DisplayListLayer::Diff(), flutter::ImageFilterLayer::Diff(), flutter::OpacityLayer::Diff(), flutter::PerformanceOverlayLayer::Diff(), flutter::ShaderMaskLayer::Diff(), flutter::TextureLayer::Diff(), flutter::TransformLayer::Diff(), and flutter::testing::MockLayer::Diff().

◆ EndSubtree()

void flutter::DiffContext::EndSubtree ( )

Definition at line 38 of file diff_context.cc.

38 {
39 FML_DCHECK(!state_stack_.empty());
40 if (state_.has_filter_bounds_adjustment) {
41 filter_bounds_adjustment_stack_.pop_back();
42 }
43 state_ = state_stack_.back();
44 state_stack_.pop_back();
45}

References FML_DCHECK.

Referenced by flutter::DiffContext::AutoSubtreeRestore::~AutoSubtreeRestore().

◆ GetCullRect()

DlRect flutter::DiffContext::GetCullRect ( ) const

Definition at line 154 of file diff_context.cc.

154 {
155 return state_.matrix_clip.GetLocalCullCoverage();
156}

Referenced by flutter::BackdropFilterLayer::Diff().

◆ GetMatrix()

const DlMatrix & flutter::DiffContext::GetMatrix ( ) const

Definition at line 150 of file diff_context.cc.

150 {
151 return state_.matrix_clip.matrix();
152}

Referenced by flutter::BackdropFilterLayer::Diff(), and flutter::ImageFilterLayer::Diff().

◆ GetOldLayerPaintRegion()

PaintRegion flutter::DiffContext::GetOldLayerPaintRegion ( const Layer layer) const

Definition at line 246 of file diff_context.cc.

246 {
247 auto i = last_frame_paint_region_map_.find(layer->unique_id());
248 if (i != last_frame_paint_region_map_.end()) {
249 return i->second;
250 } else {
251 // This is valid when Layer::PreservePaintRegion is called for retained
252 // layer with zero sized parent clip (these layers are not diffed)
253 return PaintRegion();
254 }
255}

References i, and flutter::Layer::unique_id().

Referenced by flutter::BackdropFilterLayer::Diff(), flutter::ClipShapeLayer< T >::Diff(), flutter::ColorFilterLayer::Diff(), flutter::ImageFilterLayer::Diff(), flutter::OpacityLayer::Diff(), flutter::PerformanceOverlayLayer::Diff(), flutter::ShaderMaskLayer::Diff(), flutter::TextureLayer::Diff(), flutter::TransformLayer::Diff(), flutter::ContainerLayer::DiffChildren(), and flutter::Layer::PreservePaintRegion().

◆ has_raster_cache()

bool flutter::DiffContext::has_raster_cache ( ) const
inline

◆ impeller_enabled()

bool flutter::DiffContext::impeller_enabled ( ) const
inline

Definition at line 165 of file diff_context.h.

165{ return impeller_enabled_; }

◆ IsSubtreeDirty()

◆ MapRect()

DlRect flutter::DiffContext::MapRect ( const DlRect rect)

Definition at line 139 of file diff_context.cc.

139 {
140 DlRect mapped_rect(rect);
141 state_.matrix_clip.mapRect(&mapped_rect);
142 return mapped_rect;
143}

Referenced by AddLayerBounds(), and flutter::BackdropFilterLayer::Diff().

◆ MarkSubtreeDirty() [1/2]

void flutter::DiffContext::MarkSubtreeDirty ( const DlRect previous_paint_region)

Definition at line 166 of file diff_context.cc.

166 {
168 AddDamage(previous_paint_region);
169 state_.dirty = true;
170}

References AddDamage(), FML_DCHECK, and IsSubtreeDirty().

◆ MarkSubtreeDirty() [2/2]

◆ MarkSubtreeHasTextureLayer()

void flutter::DiffContext::MarkSubtreeHasTextureLayer ( )

Definition at line 192 of file diff_context.cc.

192 {
193 // Set the has_texture flag on current state and all parent states. That
194 // way we'll know that we can't skip diff for retained layers because
195 // they contain a TextureLayer.
196 for (auto& state : state_stack_) {
197 state.has_texture = true;
198 }
199 state_.has_texture = true;
200}

Referenced by flutter::TextureLayer::Diff().

◆ PushCullRect()

bool flutter::DiffContext::PushCullRect ( const DlRect clip)

Definition at line 145 of file diff_context.cc.

145 {
146 state_.matrix_clip.clipRect(clip, DlClipOp::kIntersect, false);
147 return !state_.matrix_clip.is_cull_rect_empty();
148}

References flutter::kIntersect.

Referenced by flutter::FrameDamage::ComputeClipRect(), flutter::ClipShapeLayer< T >::Diff(), and flutter::testing::DiffContextTest::DiffLayerTree().

◆ PushFilterBoundsAdjustment()

void flutter::DiffContext::PushFilterBoundsAdjustment ( const FilterBoundsAdjustment filter)

Definition at line 64 of file diff_context.cc.

65 {
66 FML_DCHECK(state_.has_filter_bounds_adjustment == false);
67 state_.has_filter_bounds_adjustment = true;
68 filter_bounds_adjustment_stack_.push_back(filter);
69}

References FML_DCHECK.

Referenced by flutter::ImageFilterLayer::Diff().

◆ PushTransform()

void flutter::DiffContext::PushTransform ( const DlMatrix transform)

Definition at line 49 of file diff_context.cc.

49 {
50 state_.matrix_clip.transform(transform);
51}

References transform.

Referenced by flutter::DisplayListLayer::Diff(), flutter::ImageFilterLayer::Diff(), flutter::OpacityLayer::Diff(), and flutter::TransformLayer::Diff().

◆ SetLayerPaintRegion()

◆ statistics()

Statistics & flutter::DiffContext::statistics ( )
inline

Definition at line 199 of file diff_context.h.

199{ return statistics_; }

Referenced by flutter::DisplayListLayer::IsReplacing().

◆ WillPaintWithIntegralTransform()

void flutter::DiffContext::WillPaintWithIntegralTransform ( )
inline

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