Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
56df9b7
Add DiffContext
knopp Oct 13, 2020
92b478f
Add basic unit tests
knopp Oct 13, 2020
d39a23e
Add DiffContextTest.DieIfOldLayerWasNeverDiffed
knopp Oct 13, 2020
60964fc
Use FML_DCHECK instead of assert
knopp Oct 13, 2020
54bffae
Add missing space
knopp Oct 13, 2020
99e886c
Compare pictures in PictureLayer::CanDiff
knopp Oct 14, 2020
74f6357
Fail early if requesting paint region from layer that doesn’t have one
knopp Oct 14, 2020
e1341e3
Rename AddPaintRegion to AddExistingPaintRegion
knopp Oct 14, 2020
24be2f6
Fix BackdropFilterLayer paint region
knopp Oct 14, 2020
71da136
Use filterBounds instead of computeFastBounds
knopp Oct 15, 2020
c1fa535
Use MockLayer in diff unit test
knopp Oct 26, 2020
c4099d9
Clip damage to frame bounds
knopp Oct 31, 2020
8528d85
Add tests for TransformLayer and BackdropFilterLayer
knopp Oct 30, 2020
bd81ddd
Add ImageFilterLayer test
knopp Oct 30, 2020
b26987f
tweak comment
knopp Nov 1, 2020
68107c0
FilterBounds is in local coordinates
knopp Nov 9, 2020
89a545b
Reformat
knopp Nov 10, 2020
020d212
Add entries to licenses_flutter
knopp Nov 10, 2020
5dd72d0
Remove map methods, no longer used
knopp Nov 11, 2020
11af6af
Replace SkRect::MakeXYWH with SkRect::MakeLTRB
knopp Nov 11, 2020
ee505ca
Move diff tests to respective layer unit tests
knopp Nov 23, 2020
dd6bc8b
Skia factories rename
knopp Dec 10, 2020
7a29cc0
Move PaintRegion to separate file
knopp Dec 10, 2020
57552a9
GetBounds -> ComputeBounds
knopp Dec 10, 2020
4fb5d82
GetDamage -> ComputeDamage
knopp Dec 10, 2020
b70a3b4
Fix coments
knopp Dec 10, 2020
b696f8c
Consistency
knopp Dec 10, 2020
b9c16b5
AddPaintRegion -> AddLayerBounds
knopp Dec 10, 2020
d4b2497
Cleanup
knopp Dec 10, 2020
c525795
Use different layer instances
knopp Dec 10, 2020
756a3e5
Diff proper subtrees
knopp Dec 10, 2020
9d3453e
LayerTree -> MockLayerTree
knopp Dec 10, 2020
edae457
Put FLUTTER_ENABLE_DIFF_CONTEXT in separate config
knopp Dec 11, 2020
67ab7ce
surface_damage -> frame_damage
knopp Dec 14, 2020
33064ad
Rename variables
knopp Dec 14, 2020
48e3450
Get old paint region of correct layer
knopp Dec 14, 2020
aaf0b75
Missing paint region of retained layer is a valid state
knopp Dec 14, 2020
b1d2593
Move FLUTTER_ENABLE_DIFF_CONTEXT to //flutter:config
knopp Dec 14, 2020
22f35ff
Remove DieIfOldLayerTreeWasNeverDiffed test
knopp Jan 13, 2021
86a5e4d
Fix include and blur constructor
knopp Feb 14, 2021
b69e1c4
Comment fixes
knopp Feb 14, 2021
23b7318
Rename CanDiff to IsReplacing
knopp Feb 14, 2021
72d0b75
Apply filter in screen space
knopp Feb 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ config("config") {
if (is_fuchsia && flutter_enable_legacy_fuchsia_embedder) {
defines = [ "LEGACY_FUCHSIA_EMBEDDER" ]
}

if (is_debug) {
defines = [ "FLUTTER_ENABLE_DIFF_CONTEXT" ]
}
}

config("export_dynamic_symbols") {
Expand Down
4 changes: 4 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ FILE: ../../../flutter/common/task_runners.cc
FILE: ../../../flutter/common/task_runners.h
FILE: ../../../flutter/flow/compositor_context.cc
FILE: ../../../flutter/flow/compositor_context.h
FILE: ../../../flutter/flow/diff_context.cc
FILE: ../../../flutter/flow/diff_context.h
FILE: ../../../flutter/flow/embedded_view_params_unittests.cc
FILE: ../../../flutter/flow/embedded_views.cc
FILE: ../../../flutter/flow/embedded_views.h
Expand Down Expand Up @@ -101,6 +103,8 @@ FILE: ../../../flutter/flow/matrix_decomposition.cc
FILE: ../../../flutter/flow/matrix_decomposition.h
FILE: ../../../flutter/flow/matrix_decomposition_unittests.cc
FILE: ../../../flutter/flow/mutators_stack_unittests.cc
FILE: ../../../flutter/flow/paint_region.cc
FILE: ../../../flutter/flow/paint_region.h
FILE: ../../../flutter/flow/paint_utils.cc
FILE: ../../../flutter/flow/paint_utils.h
FILE: ../../../flutter/flow/raster_cache.cc
Expand Down
4 changes: 2 additions & 2 deletions common/graphics/persistent_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
#include "flutter/fml/unique_fd.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"

namespace flutter {

namespace testing {
class ShellTest;
}

namespace flutter {

/// A cache of SkData that gets stored to disk.
///
/// This is mainly used for Shaders but is also written to by Dart. It is
Expand Down
6 changes: 6 additions & 0 deletions flow/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ source_set("flow") {
sources = [
"compositor_context.cc",
"compositor_context.h",
"diff_context.cc",
"diff_context.h",
"embedded_views.cc",
"embedded_views.h",
"instrumentation.cc",
Expand Down Expand Up @@ -50,6 +52,8 @@ source_set("flow") {
"layers/transform_layer.h",
"matrix_decomposition.cc",
"matrix_decomposition.h",
"paint_region.cc",
"paint_region.h",
"paint_utils.cc",
"paint_utils.h",
"raster_cache.cc",
Expand Down Expand Up @@ -103,6 +107,8 @@ if (enable_unittests) {
testonly = true

sources = [
"testing/diff_context_test.cc",
"testing/diff_context_test.h",
"testing/gl_context_switch_test.cc",
"testing/gl_context_switch_test.h",
"testing/layer_test.h",
Expand Down
161 changes: 161 additions & 0 deletions flow/diff_context.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#include "flutter/flow/diff_context.h"
#include "flutter/flow/layers/layer.h"

namespace flutter {

#ifdef FLUTTER_ENABLE_DIFF_CONTEXT

DiffContext::DiffContext(SkISize frame_size,
double frame_device_pixel_ratio,
PaintRegionMap& this_frame_paint_region_map,
const PaintRegionMap& last_frame_paint_region_map)
: rects_(std::make_shared<std::vector<SkRect>>()),
frame_size_(frame_size),
frame_device_pixel_ratio_(frame_device_pixel_ratio),
this_frame_paint_region_map_(this_frame_paint_region_map),
last_frame_paint_region_map_(last_frame_paint_region_map) {}

void DiffContext::BeginSubtree() {
state_stack_.push_back(state_);
state_.rect_index_ = rects_->size();
}

void DiffContext::EndSubtree() {
FML_DCHECK(!state_stack_.empty());
state_ = std::move(state_stack_.back());
state_stack_.pop_back();
}

DiffContext::State::State()
: dirty(false), cull_rect(kGiantRect), rect_index_(0) {}

void DiffContext::PushTransform(const SkMatrix& transform) {
state_.transform.preConcat(transform);
SkMatrix inverse_transform;
// Perspective projections don't produce rectangles that are useful for
// culling for some reason.
if (!transform.hasPerspective() && transform.invert(&inverse_transform)) {
inverse_transform.mapRect(&state_.cull_rect);
} else {
state_.cull_rect = kGiantRect;
}
}

Damage DiffContext::ComputeDamage(
const SkIRect& accumulated_buffer_damage) const {
SkRect buffer_damage = SkRect::Make(accumulated_buffer_damage);
buffer_damage.join(damage_);
SkRect frame_damage(damage_);

for (const auto& r : readbacks_) {
SkRect rect = SkRect::Make(r.rect);
if (rect.intersects(frame_damage)) {
frame_damage.join(rect);
}
if (rect.intersects(buffer_damage)) {
buffer_damage.join(rect);
}
}

Damage res;
buffer_damage.roundOut(&res.buffer_damage);
frame_damage.roundOut(&res.frame_damage);

SkIRect frame_clip = SkIRect::MakeSize(frame_size_);
res.buffer_damage.intersect(frame_clip);
res.frame_damage.intersect(frame_clip);
return res;
}

bool DiffContext::PushCullRect(const SkRect& clip) {
return state_.cull_rect.intersect(clip);
}

void DiffContext::MarkSubtreeDirty(const PaintRegion& previous_paint_region) {
FML_DCHECK(!IsSubtreeDirty());
if (previous_paint_region.is_valid()) {
AddDamage(previous_paint_region);
}
state_.dirty = true;
}

void DiffContext::AddLayerBounds(const SkRect& rect) {
SkRect r(rect);
if (r.intersect(state_.cull_rect)) {
state_.transform.mapRect(&r);
if (!r.isEmpty()) {
rects_->push_back(r);
if (IsSubtreeDirty()) {
AddDamage(r);
}
}
}
}

void DiffContext::AddExistingPaintRegion(const PaintRegion& region) {
// Adding paint region for retained layer implies that current subtree is not
// dirty, so we know, for example, that the inherited transforms must match
FML_DCHECK(!IsSubtreeDirty());
if (region.is_valid()) {
rects_->insert(rects_->end(), region.begin(), region.end());
}
}

void DiffContext::AddReadbackRegion(const SkIRect& rect) {
Readback readback;
readback.rect = rect;
readback.position = rects_->size();
// Push empty rect as a placeholder for position in current subtree
rects_->push_back(SkRect::MakeEmpty());
readbacks_.push_back(std::move(readback));
}

PaintRegion DiffContext::CurrentSubtreeRegion() const {
bool has_readback = std::any_of(
readbacks_.begin(), readbacks_.end(),
[&](const Readback& r) { return r.position >= state_.rect_index_; });
return PaintRegion(rects_, state_.rect_index_, rects_->size(), has_readback);
}

void DiffContext::AddDamage(const PaintRegion& damage) {
FML_DCHECK(damage.is_valid());
for (const auto& r : damage) {
damage_.join(r);
}
}

void DiffContext::AddDamage(const SkRect& rect) {
damage_.join(rect);
}

void DiffContext::SetLayerPaintRegion(const Layer* layer,
const PaintRegion& region) {
this_frame_paint_region_map_[layer->unique_id()] = region;
}

PaintRegion DiffContext::GetOldLayerPaintRegion(const Layer* layer) const {
auto i = last_frame_paint_region_map_.find(layer->unique_id());
if (i != last_frame_paint_region_map_.end()) {
return i->second;
} else {
// This is valid when Layer::PreservePaintRegion is called for retained
// layer with zero sized parent clip (these layers are not diffed)
return PaintRegion();
}
}

void DiffContext::Statistics::LogStatistics() {
#if !FLUTTER_RELEASE
FML_TRACE_COUNTER("flutter", "DiffContext", reinterpret_cast<int64_t>(this),
"NewPictures", new_pictures_, "PicturesTooComplexToCompare",
pictures_too_complex_to_compare_, "DeepComparePictures",
deep_compare_pictures_, "SameInstancePictures",
same_instance_pictures_,
"DifferentInstanceButEqualPictures",
different_instance_but_equal_pictures_);
#endif // !FLUTTER_RELEASE
}

#endif // FLUTTER_ENABLE_DIFF_CONTEXT

} // namespace flutter
Loading