Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 10 of file diff_context.cc.

15 : clip_tracker_(DisplayListMatrixClipTracker(kGiantRect, SkMatrix::I())),
16 rects_(std::make_shared<std::vector<SkRect>>()),
17 frame_size_(frame_size),
18 this_frame_paint_region_map_(this_frame_paint_region_map),
19 last_frame_paint_region_map_(last_frame_paint_region_map),
20 has_raster_cache_(has_raster_cache),
21 impeller_enabled_(impeller_enabled) {}
static const SkMatrix & I()
bool impeller_enabled() const
bool has_raster_cache() const
static constexpr SkRect kGiantRect
Definition layer.h:49

Member Function Documentation

◆ AddDamage()

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

Definition at line 246 of file diff_context.cc.

246 {
247 FML_DCHECK(damage.is_valid());
248 for (const auto& r : damage) {
249 damage_.join(r);
250 }
251}
#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 218 of file diff_context.cc.

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

◆ AddLayerBounds()

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

Definition at line 189 of file diff_context.cc.

189 {
190 // During painting we cull based on non-overriden transform and then
191 // override the transform right before paint. Do the same thing here to get
192 // identical paint rect.
193 auto transformed_rect = ApplyFilterBoundsAdjustment(MapRect(rect));
194 if (transformed_rect.intersects(clip_tracker_.device_cull_rect())) {
195 if (state_.integral_transform) {
196 clip_tracker_.save();
197 MakeCurrentTransformIntegral();
198 transformed_rect = ApplyFilterBoundsAdjustment(MapRect(rect));
199 clip_tracker_.restore();
200 }
201 rects_->push_back(transformed_rect);
202 if (IsSubtreeDirty()) {
203 AddDamage(transformed_rect);
204 }
205 }
206}
void AddDamage(const PaintRegion &damage)
SkRect MapRect(const SkRect &rect)

◆ AddReadbackRegion()

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

Definition at line 227 of file diff_context.cc.

228 {
229 Readback readback;
230 readback.paint_rect = paint_rect;
231 readback.readback_rect = readback_rect;
232 readback.position = rects_->size();
233 // Push empty rect as a placeholder for position in current subtree
234 rects_->push_back(SkRect::MakeEmpty());
235 readbacks_.push_back(readback);
236}
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 23 of file diff_context.cc.

23 {
24 state_stack_.push_back(state_);
25
26 bool had_integral_transform = state_.integral_transform;
27 state_.rect_index = rects_->size();
28 state_.has_filter_bounds_adjustment = false;
29 state_.has_texture = false;
30 state_.integral_transform = false;
31
32 state_.clip_tracker_save_count = clip_tracker_.getSaveCount();
33 clip_tracker_.save();
34
35 if (had_integral_transform) {
36 MakeCurrentTransformIntegral();
37 }
38}

◆ ComputeDamage()

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

Definition at line 118 of file diff_context.cc.

120 {
121 SkRect buffer_damage = SkRect::Make(accumulated_buffer_damage);
122 buffer_damage.join(damage_);
123 SkRect frame_damage(damage_);
124
125 for (const auto& r : readbacks_) {
126 SkRect paint_rect = SkRect::Make(r.paint_rect);
127 SkRect readback_rect = SkRect::Make(r.readback_rect);
128 // Changes either in readback or paint rect require repainting both readback
129 // and paint rect.
130 if (paint_rect.intersects(frame_damage) ||
131 readback_rect.intersects(frame_damage)) {
132 frame_damage.join(readback_rect);
133 frame_damage.join(paint_rect);
134 buffer_damage.join(readback_rect);
135 buffer_damage.join(paint_rect);
136 }
137 }
138
139 Damage res;
140 buffer_damage.roundOut(&res.buffer_damage);
141 frame_damage.roundOut(&res.frame_damage);
142
143 SkIRect frame_clip = SkIRect::MakeSize(frame_size_);
144 res.buffer_damage.intersect(frame_clip);
145 res.frame_damage.intersect(frame_clip);
146
147 if (horizontal_clip_alignment > 1 || vertical_clip_alignment > 1) {
148 AlignRect(res.buffer_damage, horizontal_clip_alignment,
149 vertical_clip_alignment);
150 AlignRect(res.frame_damage, horizontal_clip_alignment,
151 vertical_clip_alignment);
152 }
153 return res;
154}
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 238 of file diff_context.cc.

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

◆ EndSubtree()

void flutter::DiffContext::EndSubtree ( )

Definition at line 40 of file diff_context.cc.

40 {
41 FML_DCHECK(!state_stack_.empty());
42 if (state_.has_filter_bounds_adjustment) {
43 filter_bounds_adjustment_stack_.pop_back();
44 }
45 clip_tracker_.restoreToCount(state_.clip_tracker_save_count);
46 state_ = state_stack_.back();
47 state_stack_.pop_back();
48}

◆ GetCullRect()

SkRect flutter::DiffContext::GetCullRect ( ) const

Definition at line 171 of file diff_context.cc.

171 {
172 return clip_tracker_.local_cull_rect();
173}

◆ GetOldLayerPaintRegion()

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

Definition at line 262 of file diff_context.cc.

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

◆ GetTransform3x3()

SkMatrix flutter::DiffContext::GetTransform3x3 ( ) const

Definition at line 167 of file diff_context.cc.

167 {
168 return clip_tracker_.matrix_3x3();
169}

◆ 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 156 of file diff_context.cc.

156 {
157 SkRect mapped_rect(rect);
158 clip_tracker_.mapRect(&mapped_rect);
159 return mapped_rect;
160}

◆ MarkSubtreeDirty() [1/2]

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

Definition at line 175 of file diff_context.cc.

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

◆ MarkSubtreeDirty() [2/2]

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

Definition at line 183 of file diff_context.cc.

183 {
185 AddDamage(previous_paint_region);
186 state_.dirty = true;
187}

◆ MarkSubtreeHasTextureLayer()

void flutter::DiffContext::MarkSubtreeHasTextureLayer ( )

Definition at line 208 of file diff_context.cc.

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

◆ PushCullRect()

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

Definition at line 162 of file diff_context.cc.

162 {
163 clip_tracker_.clipRect(clip, DlCanvas::ClipOp::kIntersect, false);
164 return !clip_tracker_.device_cull_rect().isEmpty();
165}
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition SkPath.cpp:3824
void clipRect(const DlRect &rect, ClipOp op, bool is_aa)
bool isEmpty() const
Definition SkRect.h:693

◆ PushFilterBoundsAdjustment()

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

Definition at line 78 of file diff_context.cc.

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

◆ PushTransform() [1/2]

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

Definition at line 56 of file diff_context.cc.

56 {
57 clip_tracker_.transform(transform);
58}
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 52 of file diff_context.cc.

52 {
53 clip_tracker_.transform(transform);
54}

◆ SetLayerPaintRegion()

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

Definition at line 257 of file diff_context.cc.

258 {
259 this_frame_paint_region_map_[layer->unique_id()] = region;
260}

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