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 12 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
afbb37a
Testing Preroll/Paint
JTKryptic Jun 16, 2022
5103d9d
Pushed opacity to platform view stack / Background Filter Proto 1
JTKryptic Jun 17, 2022
825fbc8
Create Backdrop Filter Mutator
JTKryptic Jun 23, 2022
4b5c705
Merge branch 'diff' into backdrop_filter_testing
JTKryptic Jun 23, 2022
24c077f
Removed Logs
JTKryptic Jun 23, 2022
e1a817d
Tests for PushFilter
JTKryptic Jun 27, 2022
d06155c
Backdrop Filter Mutator
JTKryptic Jun 27, 2022
452a0b7
Merge branch 'diff' into backdrop_filter_testing
JTKryptic Jun 27, 2022
6b74e7d
Formatting
JTKryptic Jun 27, 2022
455b87f
Merge branch 'backdrop_filter_testing'
JTKryptic Jun 27, 2022
bc1d19b
Format files
JTKryptic Jun 28, 2022
4c0f2a5
Merge branch 'main' into backdrop_filter_testing
JTKryptic Jun 28, 2022
55d328c
Delete backdrop_filter_diff
JTKryptic Jun 28, 2022
d080e8e
Code cleanup
JTKryptic Jun 29, 2022
93accab
Updating to DlImageFilter and code cleanup
JTKryptic Jun 29, 2022
a9cd101
Formatting
JTKryptic Jun 29, 2022
abc3a0e
bug fix
JTKryptic Jun 29, 2022
86a5913
Fix
JTKryptic Jul 7, 2022
3897724
Merge branch 'main' into backdrop_filter_testing
JTKryptic Jul 19, 2022
d60a016
Enum style guide fix
JTKryptic Jul 13, 2022
484957d
Cleanup
JTKryptic Jul 21, 2022
929be62
Cleanup and Tests
JTKryptic Jul 22, 2022
b280266
format
JTKryptic Jul 22, 2022
153df5d
format
JTKryptic Jul 22, 2022
70049ad
Memory leak failure fix
JTKryptic Jul 25, 2022
3a98c7d
format
JTKryptic Jul 25, 2022
1e6c271
Merge upstream_main into backdrop_filter_testing
JTKryptic Jul 25, 2022
5e94dee
Remove platform view flag
JTKryptic Jul 26, 2022
af66748
format
JTKryptic Jul 26, 2022
89cfd8b
nit
JTKryptic Jul 27, 2022
042c22e
Merge branch 'upstream_main' into backdrop_filter_testing
JTKryptic Jul 28, 2022
f9dd08b
test fix
JTKryptic Jul 28, 2022
9d00f75
format
JTKryptic Jul 28, 2022
f30e262
backdrop filter unit tests
JTKryptic Aug 2, 2022
8b3277f
shell cleaning
JTKryptic Aug 2, 2022
15fa54f
Merge branch 'upstream_main' into backdrop_filter_testing
JTKryptic Aug 2, 2022
5891b2e
formatting
JTKryptic Aug 2, 2022
7c05b74
Update ios_external_view_embedder.h
JTKryptic Aug 2, 2022
ca719f3
Update ios_external_view_embedder.mm
JTKryptic Aug 2, 2022
8d24f64
format
JTKryptic Aug 2, 2022
58b3ce3
PR comment changes
JTKryptic Aug 3, 2022
7b558e2
Update embedded_views.h
JTKryptic Aug 3, 2022
b92b17a
Merge branch 'upstream_main' into backdrop_filter_testing
JTKryptic Aug 3, 2022
0739448
Merge branch 'main' into backdrop_filter_testing
JTKryptic Aug 10, 2022
1d0bb6d
Update embedded_views.h
JTKryptic Aug 10, 2022
b2a2625
Update shell_test_external_view_embedder.cc
JTKryptic Aug 10, 2022
aef123c
Update shell_test_external_view_embedder.cc
JTKryptic Aug 10, 2022
85e0b4c
Update shell_test_external_view_embedder.cc
JTKryptic Aug 10, 2022
235a853
Update shell_test_external_view_embedder.h
JTKryptic Aug 10, 2022
e9d7cb1
test fix
JTKryptic Aug 10, 2022
a33caa4
fixes
JTKryptic Aug 10, 2022
3be1bf3
test fix
JTKryptic Aug 10, 2022
357ec82
test fix 3
JTKryptic Aug 10, 2022
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
95 changes: 95 additions & 0 deletions backdrop_filter_diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
diff --git a/flow/embedded_views.h b/flow/embedded_views.h
index 7a5a34f330..76b002befd 100644
--- a/flow/embedded_views.h
+++ b/flow/embedded_views.h
@@ -345,6 +345,8 @@ class ExternalViewEmbedder {
// 'EndFrame', otherwise returns false.
bool GetUsedThisFrame() const { return used_this_frame_; }

+ void PushMutator() {}
+
private:
bool used_this_frame_ = false;

diff --git a/flow/layers/backdrop_filter_layer.cc b/flow/layers/backdrop_filter_layer.cc
index 8e8ef2628a..b059e427c3 100644
--- a/flow/layers/backdrop_filter_layer.cc
+++ b/flow/layers/backdrop_filter_layer.cc
@@ -43,6 +43,10 @@ void BackdropFilterLayer::Preroll(PrerollContext* context,
Layer::AutoPrerollSaveLayerState save =
Layer::AutoPrerollSaveLayerState::Create(context, true, bool(filter_));
SkRect child_paint_bounds = SkRect::MakeEmpty();
+ auto visited_platform_views = context->view_embedder->GetVisitedPlatformViews();
+ for (id in visited_platform_views) {
+ context->view_embedder->ApplyMutator(id, alpha);
+ }
PrerollChildren(context, matrix, &child_paint_bounds);
child_paint_bounds.join(context->cull_rect);
set_paint_bounds(child_paint_bounds);
diff --git a/flow/layers/platform_view_layer.cc b/flow/layers/platform_view_layer.cc
index 285db390cc..63b7827cf9 100644
--- a/flow/layers/platform_view_layer.cc
+++ b/flow/layers/platform_view_layer.cc
@@ -28,6 +28,7 @@ void PlatformViewLayer::Preroll(PrerollContext* context,
context->mutators_stack);
context->view_embedder->PrerollCompositeEmbeddedView(view_id_,
std::move(params));
+ context->view_embedder->PushVisitedPlatformView(view_id_);
}

void PlatformViewLayer::Paint(PaintContext& context) const {
diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
index e5325aee85..a6992cca3f 100644
--- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
+++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
@@ -319,6 +319,11 @@ void FlutterPlatformViewsController::EndFrame(
}
}

+void FlutterPlatformViewsController::PushMutator(flutter::Mutator mutator, int64_t platform_view_id) {
+ EmbeddedViewParams params = current_composition_params_[platform_view_id];
+ params.mutatorsStack().PushOpacity(20);
+}
+
void FlutterPlatformViewsController::PrerollCompositeEmbeddedView(
int view_id,
std::unique_ptr<EmbeddedViewParams> params) {
diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h
index fde21d23e2..522b847ef4 100644
--- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h
+++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h
@@ -184,6 +184,8 @@ class FlutterPlatformViewsController {
// responder. Returns -1 if no such platform view is found.
long FindFirstResponderPlatformViewId();

+ void PushMutator(flutter::Mutator mutator, int64_t platform_view_id);
+
private:
static const size_t kMaxLayerAllocations = 2;

diff --git a/shell/platform/darwin/ios/ios_external_view_embedder.h b/shell/platform/darwin/ios/ios_external_view_embedder.h
index 6c023d1b79..da160dd023 100644
--- a/shell/platform/darwin/ios/ios_external_view_embedder.h
+++ b/shell/platform/darwin/ios/ios_external_view_embedder.h
@@ -64,6 +64,8 @@ class IOSExternalViewEmbedder : public ExternalViewEmbedder {
// |ExternalViewEmbedder|
bool SupportsDynamicThreadMerging() override;

+ void PushMutator() override;
+
FML_DISALLOW_COPY_AND_ASSIGN(IOSExternalViewEmbedder);
};

diff --git a/shell/platform/darwin/ios/ios_external_view_embedder.mm b/shell/platform/darwin/ios/ios_external_view_embedder.mm
index 1323fa4c2f..edd4a3adcd 100644
--- a/shell/platform/darwin/ios/ios_external_view_embedder.mm
+++ b/shell/platform/darwin/ios/ios_external_view_embedder.mm
@@ -92,4 +92,8 @@ bool IOSExternalViewEmbedder::SupportsDynamicThreadMerging() {
return true;
}

+void PushMutator(int alpha, int view_id) {
+ platform_views_controller_->PushMutator(alpha, view_id);
+}
+
} // namespace flutter
5 changes: 5 additions & 0 deletions flow/embedded_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ void MutatorsStack::PushOpacity(const int& alpha) {
vector_.push_back(element);
};

void MutatorsStack::PushBackdropFilter(const sk_sp<SkImageFilter>& filter) {
std::shared_ptr<Mutator> element = std::make_shared<Mutator>(filter);
vector_.push_back(element);
};

void MutatorsStack::Pop() {
vector_.pop_back();
};
Expand Down
36 changes: 35 additions & 1 deletion flow/embedded_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@
namespace flutter {

// TODO(chinmaygarde): Make these enum names match the style guide.
enum MutatorType { clip_rect, clip_rrect, clip_path, transform, opacity };
enum MutatorType {
clip_rect,
clip_rrect,
clip_path,
transform,
opacity,
backdrop_filter
};

// Stores mutation information like clipping or transform.
//
Expand Down Expand Up @@ -49,6 +56,9 @@ class Mutator {
case opacity:
alpha_ = other.alpha_;
break;
case backdrop_filter:
filter_ = other.filter_;
break;
default:
break;
}
Expand All @@ -61,12 +71,15 @@ class Mutator {
explicit Mutator(const SkMatrix& matrix)
: type_(transform), matrix_(matrix) {}
explicit Mutator(const int& alpha) : type_(opacity), alpha_(alpha) {}
explicit Mutator(const sk_sp<SkImageFilter>& filter)
: type_(backdrop_filter), filter_(filter) {}

const MutatorType& GetType() const { return type_; }
const SkRect& GetRect() const { return rect_; }
const SkRRect& GetRRect() const { return rrect_; }
const SkPath& GetPath() const { return *path_; }
const SkMatrix& GetMatrix() const { return matrix_; }
const sk_sp<SkImageFilter>& GetFilter() const { return filter_; }
const int& GetAlpha() const { return alpha_; }
float GetAlphaFloat() const { return (alpha_ / 255.0); }

Expand All @@ -85,6 +98,8 @@ class Mutator {
return matrix_ == other.matrix_;
case opacity:
return alpha_ == other.alpha_;
case backdrop_filter:
return filter_ == other.filter_;
}

return false;
Expand All @@ -111,6 +126,7 @@ class Mutator {
SkMatrix matrix_;
SkPath* path_;
int alpha_;
sk_sp<SkImageFilter> filter_;
};

}; // Mutator
Expand All @@ -133,6 +149,7 @@ class MutatorsStack {
void PushClipPath(const SkPath& path);
void PushTransform(const SkMatrix& matrix);
void PushOpacity(const int& alpha);
void PushBackdropFilter(const sk_sp<SkImageFilter>& filter);

// Removes the `Mutator` on the top of the stack
// and destroys it.
Expand Down Expand Up @@ -224,6 +241,10 @@ class EmbeddedViewParams {
// Clippings are ignored.
const SkRect& finalBoundingRect() const { return final_bounding_rect_; }

void PushFilter(sk_sp<SkImageFilter> filter) {
mutators_stack_.PushBackdropFilter(filter);
}

bool operator==(const EmbeddedViewParams& other) const {
return size_points_ == other.size_points_ &&
mutators_stack_ == other.mutators_stack_ &&
Expand Down Expand Up @@ -345,9 +366,22 @@ class ExternalViewEmbedder {
// 'EndFrame', otherwise returns false.
bool GetUsedThisFrame() const { return used_this_frame_; }

std::vector<int64_t> GetVisitedPlatformViews() {
return visited_platform_views_;
}

void PushVisitedPlatformView(int64_t view_id) {
visited_platform_views_.push_back(view_id);
}

virtual void FilterPlatformViews(int64_t view_id,
sk_sp<SkImageFilter> filter) {}

private:
bool used_this_frame_ = false;

std::vector<int64_t> visited_platform_views_;

FML_DISALLOW_COPY_AND_ASSIGN(ExternalViewEmbedder);

}; // ExternalViewEmbedder
Expand Down
6 changes: 6 additions & 0 deletions flow/layers/backdrop_filter_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ void BackdropFilterLayer::Preroll(PrerollContext* context,
Layer::AutoPrerollSaveLayerState save =
Layer::AutoPrerollSaveLayerState::Create(context, true, bool(filter_));
SkRect child_paint_bounds = SkRect::MakeEmpty();
auto visited_platform_views =
context->view_embedder->GetVisitedPlatformViews();
for (int64_t id : visited_platform_views) {
context->view_embedder->FilterPlatformViews(id, filter_);
}

PrerollChildren(context, matrix, &child_paint_bounds);
child_paint_bounds.join(context->cull_rect);
set_paint_bounds(child_paint_bounds);
Expand Down
1 change: 1 addition & 0 deletions flow/layers/platform_view_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void PlatformViewLayer::Preroll(PrerollContext* context,
context->mutators_stack);
context->view_embedder->PrerollCompositeEmbeddedView(view_id_,
std::move(params));
context->view_embedder->PushVisitedPlatformView(view_id_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Platform view is pushed but nothing ever clears that list, so it will have the same issue as the filters, it slows down rendering until app is unresponsive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we are fixing it here: #34596

}

void PlatformViewLayer::Paint(PaintContext& context) const {
Expand Down
11 changes: 11 additions & 0 deletions flow/mutators_stack_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ TEST(MutatorsStack, PushClipRect) {
ASSERT_TRUE(iter->get()->GetRect() == rect);
}

TEST(MutatorsStack, PushBackdropFilter) {
MutatorsStack stack;
sk_sp<SkImageFilter> filter;
filter->filterBounds(SkIRect::MakeWH(10, 10), SkMatrix::I(),
SkImageFilter::kForward_MapDirection);
stack.PushBackdropFilter(filter);
auto iter = stack.Bottom();
ASSERT_TRUE(iter->get()->GetType() == MutatorType::backdrop_filter);
ASSERT_TRUE(iter->get()->GetFilter() == filter);
}

TEST(MutatorsStack, PushClipRRect) {
MutatorsStack stack;
auto rrect = SkRRect::MakeEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,13 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
}
}

void FlutterPlatformViewsController::FilterPlatformViews(int64_t platform_view_id,
sk_sp<SkImageFilter> filter) {
EmbeddedViewParams params = current_composition_params_[platform_view_id];
params.PushFilter(filter);
current_composition_params_[platform_view_id] = params;
}

void FlutterPlatformViewsController::PrerollCompositeEmbeddedView(
int view_id,
std::unique_ptr<EmbeddedViewParams> params) {
Expand Down Expand Up @@ -422,6 +429,8 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
case opacity:
embedded_view.alpha = (*iter)->GetAlphaFloat() * embedded_view.alpha;
break;
case backdrop_filter:
break;
}
++iter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ class FlutterPlatformViewsController {
// responder. Returns -1 if no such platform view is found.
long FindFirstResponderPlatformViewId();

void FilterPlatformViews(int64_t platform_view_id, sk_sp<SkImageFilter> filter);

private:
static const size_t kMaxLayerAllocations = 2;

Expand Down
3 changes: 3 additions & 0 deletions shell/platform/darwin/ios/ios_external_view_embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class IOSExternalViewEmbedder : public ExternalViewEmbedder {
// |ExternalViewEmbedder|
bool SupportsDynamicThreadMerging() override;

void FilterPlatformViews(int64_t view_id,
sk_sp<SkImageFilter> filter) override;

FML_DISALLOW_COPY_AND_ASSIGN(IOSExternalViewEmbedder);
};

Expand Down
4 changes: 4 additions & 0 deletions shell/platform/darwin/ios/ios_external_view_embedder.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@
return true;
}

void IOSExternalViewEmbedder::FilterPlatformViews(int64_t view_id, sk_sp<SkImageFilter> filter) {
platform_views_controller_->FilterPlatformViews(view_id, filter);
}

} // namespace flutter
2 changes: 2 additions & 0 deletions shell/platform/embedder/embedder_layers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ void EmbedderLayers::PushPlatformViewLayer(
.get());
}
} break;
case MutatorType::backdrop_filter: {
} break;
}
}

Expand Down