Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | List of all members
flutter::DiffContext Class Reference

#include <diff_context.h>

Classes

class  AutoSubtreeRestore
 
class  Statistics
 

Public Types

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

Public Member Functions

 DiffContext (SkISize 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 SkMatrix &transform)
 
void PushTransform (const SkM44 &transform)
 
bool PushCullRect (const SkRect &clip)
 
void PushFilterBoundsAdjustment (const FilterBoundsAdjustment &filter)
 
void WillPaintWithIntegralTransform ()
 
SkMatrix GetTransform3x3 () const
 
SkRect GetCullRect () const
 
void MarkSubtreeDirty (const PaintRegion &previous_paint_region=PaintRegion())
 
void MarkSubtreeDirty (const SkRect &previous_paint_region)
 
bool IsSubtreeDirty () const
 
void MarkSubtreeHasTextureLayer ()
 
void AddLayerBounds (const SkRect &rect)
 
void AddExistingPaintRegion (const PaintRegion &region)
 
void AddReadbackRegion (const SkIRect &paint_rect, const SkIRect &readback_rect)
 
PaintRegion CurrentSubtreeRegion () const
 
Damage ComputeDamage (const SkIRect &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 ()
 
SkRect MapRect (const SkRect &rect)
 

Detailed Description

Definition at line 44 of file diff_context.h.

Member Typedef Documentation

◆ FilterBoundsAdjustment

Definition at line 82 of file diff_context.h.

Constructor & Destructor Documentation

◆ DiffContext()

flutter::DiffContext::DiffContext ( SkISize  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<SkRect>>()),
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
Definition: diff_context.h:169
bool has_raster_cache() const
Definition: diff_context.h:167

Member Function Documentation

◆ AddDamage()

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

Definition at line 244 of file diff_context.cc.

244 {
245 FML_DCHECK(damage.is_valid());
246 for (const auto& r : damage) {
247 damage_.join(r);
248 }
249}
#define FML_DCHECK(condition)
Definition: logging.h:103
void join(const SkRect &r)
Definition: SkRect.cpp:126

◆ AddExistingPaintRegion()

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

Definition at line 216 of file diff_context.cc.

216 {
217 // Adding paint region for retained layer implies that current subtree is not
218 // dirty, so we know, for example, that the inherited transforms must match
220 if (region.is_valid()) {
221 rects_->insert(rects_->end(), region.begin(), region.end());
222 }
223}
bool IsSubtreeDirty() const
Definition: diff_context.h:108
ClipOpAndAA opAA SkRegion region
Definition: SkRecords.h:238

◆ AddLayerBounds()

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

Definition at line 187 of file diff_context.cc.

187 {
188 // During painting we cull based on non-overriden transform and then
189 // override the transform right before paint. Do the same thing here to get
190 // identical paint rect.
191 auto transformed_rect = ApplyFilterBoundsAdjustment(MapRect(rect));
192 if (transformed_rect.intersects(state_.matrix_clip.device_cull_rect())) {
193 if (state_.integral_transform) {
194 DisplayListMatrixClipState temp_state = state_.matrix_clip;
195 MakeTransformIntegral(temp_state);
196 temp_state.mapRect(rect, &transformed_rect);
197 transformed_rect = ApplyFilterBoundsAdjustment(transformed_rect);
198 }
199 rects_->push_back(transformed_rect);
200 if (IsSubtreeDirty()) {
201 AddDamage(transformed_rect);
202 }
203 }
204}
void AddDamage(const PaintRegion &damage)
SkRect MapRect(const SkRect &rect)
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350

◆ AddReadbackRegion()

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

Definition at line 225 of file diff_context.cc.

226 {
227 Readback readback;
228 readback.paint_rect = paint_rect;
229 readback.readback_rect = readback_rect;
230 readback.position = rects_->size();
231 // Push empty rect as a placeholder for position in current subtree
232 rects_->push_back(SkRect::MakeEmpty());
233 readbacks_.push_back(readback);
234}
static void readback(const SkBitmap &src, int *result, int resultCount)
Definition: BlurTest.cpp:264
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595

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

◆ ComputeDamage()

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

Definition at line 116 of file diff_context.cc.

118 {
119 SkRect buffer_damage = SkRect::Make(accumulated_buffer_damage);
120 buffer_damage.join(damage_);
121 SkRect frame_damage(damage_);
122
123 for (const auto& r : readbacks_) {
124 SkRect paint_rect = SkRect::Make(r.paint_rect);
125 SkRect readback_rect = SkRect::Make(r.readback_rect);
126 // Changes either in readback or paint rect require repainting both readback
127 // and paint rect.
128 if (paint_rect.intersects(frame_damage) ||
129 readback_rect.intersects(frame_damage)) {
130 frame_damage.join(readback_rect);
131 frame_damage.join(paint_rect);
132 buffer_damage.join(readback_rect);
133 buffer_damage.join(paint_rect);
134 }
135 }
136
137 Damage res;
138 buffer_damage.roundOut(&res.buffer_damage);
139 frame_damage.roundOut(&res.frame_damage);
140
141 SkIRect frame_clip = SkIRect::MakeSize(frame_size_);
142 res.buffer_damage.intersect(frame_clip);
143 res.frame_damage.intersect(frame_clip);
144
145 if (horizontal_clip_alignment > 1 || vertical_clip_alignment > 1) {
146 AlignRect(res.buffer_damage, horizontal_clip_alignment,
147 vertical_clip_alignment);
148 AlignRect(res.frame_damage, horizontal_clip_alignment,
149 vertical_clip_alignment);
150 }
151 return res;
152}
Definition: SkRect.h:32
static constexpr SkIRect MakeSize(const SkISize &size)
Definition: SkRect.h:66
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
bool intersects(const SkRect &r) const
Definition: SkRect.h:1121
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241

◆ CurrentSubtreeRegion()

PaintRegion flutter::DiffContext::CurrentSubtreeRegion ( ) const

Definition at line 236 of file diff_context.cc.

236 {
237 bool has_readback = std::any_of(
238 readbacks_.begin(), readbacks_.end(),
239 [&](const Readback& r) { return r.position >= state_.rect_index; });
240 return PaintRegion(rects_, state_.rect_index, rects_->size(), has_readback,
241 state_.has_texture);
242}

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

◆ GetCullRect()

SkRect flutter::DiffContext::GetCullRect ( ) const

Definition at line 169 of file diff_context.cc.

169 {
170 return state_.matrix_clip.local_cull_rect();
171}

◆ GetOldLayerPaintRegion()

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

Definition at line 260 of file diff_context.cc.

260 {
261 auto i = last_frame_paint_region_map_.find(layer->unique_id());
262 if (i != last_frame_paint_region_map_.end()) {
263 return i->second;
264 } else {
265 // This is valid when Layer::PreservePaintRegion is called for retained
266 // layer with zero sized parent clip (these layers are not diffed)
267 return PaintRegion();
268 }
269}

◆ GetTransform3x3()

SkMatrix flutter::DiffContext::GetTransform3x3 ( ) const

Definition at line 165 of file diff_context.cc.

165 {
166 return state_.matrix_clip.matrix_3x3();
167}

◆ has_raster_cache()

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

Definition at line 167 of file diff_context.h.

167{ return has_raster_cache_; }

◆ impeller_enabled()

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

Definition at line 169 of file diff_context.h.

169{ return impeller_enabled_; }

◆ IsSubtreeDirty()

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

Definition at line 108 of file diff_context.h.

108{ return state_.dirty; }

◆ MapRect()

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

Definition at line 154 of file diff_context.cc.

154 {
155 SkRect mapped_rect(rect);
156 state_.matrix_clip.mapRect(&mapped_rect);
157 return mapped_rect;
158}

◆ MarkSubtreeDirty() [1/2]

void flutter::DiffContext::MarkSubtreeDirty ( const PaintRegion previous_paint_region = PaintRegion())

Definition at line 173 of file diff_context.cc.

173 {
175 if (previous_paint_region.is_valid()) {
176 AddDamage(previous_paint_region);
177 }
178 state_.dirty = true;
179}

◆ MarkSubtreeDirty() [2/2]

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

Definition at line 181 of file diff_context.cc.

181 {
183 AddDamage(previous_paint_region);
184 state_.dirty = true;
185}

◆ MarkSubtreeHasTextureLayer()

void flutter::DiffContext::MarkSubtreeHasTextureLayer ( )

Definition at line 206 of file diff_context.cc.

206 {
207 // Set the has_texture flag on current state and all parent states. That
208 // way we'll know that we can't skip diff for retained layers because
209 // they contain a TextureLayer.
210 for (auto& state : state_stack_) {
211 state.has_texture = true;
212 }
213 state_.has_texture = true;
214}
AtkStateType state

◆ PushCullRect()

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

Definition at line 160 of file diff_context.cc.

160 {
161 state_.matrix_clip.clipRect(clip, DlCanvas::ClipOp::kIntersect, false);
162 return !state_.matrix_clip.device_cull_rect().isEmpty();
163}
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892

◆ PushFilterBoundsAdjustment()

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

Definition at line 76 of file diff_context.cc.

77 {
78 FML_DCHECK(state_.has_filter_bounds_adjustment == false);
79 state_.has_filter_bounds_adjustment = true;
80 filter_bounds_adjustment_stack_.push_back(filter);
81}

◆ PushTransform() [1/2]

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

Definition at line 53 of file diff_context.cc.

53 {
54 state_.matrix_clip.transform(transform);
55}
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47

◆ PushTransform() [2/2]

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

Definition at line 49 of file diff_context.cc.

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

◆ SetLayerPaintRegion()

void flutter::DiffContext::SetLayerPaintRegion ( const Layer layer,
const PaintRegion region 
)

Definition at line 255 of file diff_context.cc.

256 {
257 this_frame_paint_region_map_[layer->unique_id()] = region;
258}

◆ statistics()

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

Definition at line 203 of file diff_context.h.

203{ return statistics_; }

◆ WillPaintWithIntegralTransform()

void flutter::DiffContext::WillPaintWithIntegralTransform ( )
inline

Definition at line 89 of file diff_context.h.

89{ state_.integral_transform = true; }

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