5#include "flutter/flow/diff_context.h"
7#include "flutter/flow/layers/layer.h"
8#include "flutter/flow/raster_cache_util.h"
15 bool has_raster_cache,
16 bool impeller_enabled)
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) {}
25 state_stack_.push_back(state_);
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;
33 if (had_integral_transform) {
34 MakeTransformIntegral(state_.matrix_clip);
40 if (state_.has_filter_bounds_adjustment) {
41 filter_bounds_adjustment_stack_.pop_back();
43 state_ = state_stack_.back();
44 state_stack_.pop_back();
57void DiffContext::MakeTransformIntegral(
78 FML_DCHECK(state_.has_filter_bounds_adjustment ==
false);
79 state_.has_filter_bounds_adjustment =
true;
80 filter_bounds_adjustment_stack_.push_back(filter);
85 for (
auto i = filter_bounds_adjustment_stack_.rbegin();
86 i != filter_bounds_adjustment_stack_.rend(); ++
i) {
93 int horizontal_alignment,
94 int vertical_alignment)
const {
95 auto top =
rect.top();
98 auto bottom =
rect.bottom();
99 if (top % vertical_alignment != 0) {
100 top -= top % vertical_alignment;
102 if (left % horizontal_alignment != 0) {
103 left -=
left % horizontal_alignment;
105 if (right % horizontal_alignment != 0) {
106 right += horizontal_alignment -
right % horizontal_alignment;
108 if (bottom % vertical_alignment != 0) {
109 bottom += vertical_alignment - bottom % vertical_alignment;
117 int horizontal_clip_alignment,
118 int vertical_clip_alignment)
const {
120 buffer_damage.
join(damage_);
121 SkRect frame_damage(damage_);
123 for (
const auto& r : readbacks_) {
130 frame_damage.
join(readback_rect);
131 frame_damage.
join(paint_rect);
132 buffer_damage.
join(readback_rect);
133 buffer_damage.
join(paint_rect);
145 if (horizontal_clip_alignment > 1 || vertical_clip_alignment > 1) {
147 vertical_clip_alignment);
149 vertical_clip_alignment);
156 state_.matrix_clip.mapRect(&mapped_rect);
162 return !state_.matrix_clip.device_cull_rect().isEmpty();
166 return state_.matrix_clip.matrix_3x3();
170 return state_.matrix_clip.local_cull_rect();
175 if (previous_paint_region.
is_valid()) {
191 auto transformed_rect = ApplyFilterBoundsAdjustment(
MapRect(
rect));
192 if (transformed_rect.intersects(state_.matrix_clip.device_cull_rect())) {
193 if (state_.integral_transform) {
195 MakeTransformIntegral(temp_state);
197 transformed_rect = ApplyFilterBoundsAdjustment(transformed_rect);
199 rects_->push_back(transformed_rect);
210 for (
auto&
state : state_stack_) {
211 state.has_texture =
true;
213 state_.has_texture =
true;
221 rects_->insert(rects_->end(),
region.begin(),
region.end());
226 const SkIRect& readback_rect) {
229 readback.readback_rect = readback_rect;
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,
246 for (
const auto& r : damage) {
261 auto i = last_frame_paint_region_map_.find(layer->
unique_id());
262 if (
i != last_frame_paint_region_map_.end()) {
274 "NewPictures", new_pictures_,
"PicturesTooComplexToCompare",
275 pictures_too_complex_to_compare_,
"DeepComparePictures",
276 deep_compare_pictures_,
"SameInstancePictures",
277 same_instance_pictures_,
278 "DifferentInstanceButEqualPictures",
279 different_instance_but_equal_pictures_);
static void readback(const SkBitmap &src, int *result, int resultCount)
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
SkMatrix GetTransform3x3() const
void PushTransform(const SkMatrix &transform)
void AddLayerBounds(const SkRect &rect)
void SetLayerPaintRegion(const Layer *layer, const PaintRegion ®ion)
void MarkSubtreeDirty(const PaintRegion &previous_paint_region=PaintRegion())
void AddDamage(const PaintRegion &damage)
PaintRegion CurrentSubtreeRegion() const
void AddExistingPaintRegion(const PaintRegion ®ion)
void PushFilterBoundsAdjustment(const FilterBoundsAdjustment &filter)
PaintRegion GetOldLayerPaintRegion(const Layer *layer) const
SkRect MapRect(const SkRect &rect)
bool PushCullRect(const SkRect &clip)
Damage ComputeDamage(const SkIRect &additional_damage, int horizontal_clip_alignment=0, int vertical_clip_alignment=0) const
void MarkSubtreeHasTextureLayer()
bool IsSubtreeDirty() const
void AddReadbackRegion(const SkIRect &paint_rect, const SkIRect &readback_rect)
std::function< SkRect(SkRect)> FilterBoundsAdjustment
DiffContext(SkISize frame_size, PaintRegionMap &this_frame_paint_region_map, const PaintRegionMap &last_frame_paint_region_map, bool has_raster_cache, bool impeller_enabled)
SkRect GetCullRect() const
bool mapRect(DlRect *rect) const
bool using_4x4_matrix() const
SkMatrix matrix_3x3() const
void setTransform(const DlMatrix &matrix)
uint64_t unique_id() const
#define FML_DCHECK(condition)
static float min(float r, float g, float b)
ClipOpAndAA opAA SkRegion region
sk_sp< SkBlender > blender SkRect rect
std::map< uint64_t, PaintRegion > PaintRegionMap
static constexpr SkRect kGiantRect
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
bool intersect(const SkIRect &r)
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
static constexpr SkIRect MakeSize(const SkISize &size)
constexpr int32_t width() const
constexpr int32_t height() const
static SkRect Make(const SkISize &size)
static constexpr SkRect MakeEmpty()
bool intersects(const SkRect &r) const
void roundOut(SkIRect *dst) const
void join(const SkRect &r)
static bool ComputeIntegralTransCTM(const SkMatrix &in, SkMatrix *out)
Snap the translation components of the |in| matrix to integers and store the snapped matrix in |out|.
#define FML_TRACE_COUNTER(category_group, name, counter_id, arg1,...)