Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 8fcf413

Browse files
author
Chris Yang
authored
Revert "PlatformView partial blur" (#37085)
1 parent abc3aab commit 8fcf413

14 files changed

+344
-669
lines changed

flow/embedded_views.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,8 @@ void MutatorsStack::PushOpacity(const int& alpha) {
100100
};
101101

102102
void MutatorsStack::PushBackdropFilter(
103-
const std::shared_ptr<const DlImageFilter>& filter,
104-
const SkRect& filter_rect) {
105-
std::shared_ptr<Mutator> element =
106-
std::make_shared<Mutator>(filter, filter_rect);
103+
const std::shared_ptr<const DlImageFilter>& filter) {
104+
std::shared_ptr<Mutator> element = std::make_shared<Mutator>(filter);
107105
vector_.push_back(element);
108106
};
109107

flow/embedded_views.h

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,6 @@ enum MutatorType {
3232
kBackdropFilter
3333
};
3434

35-
// Represents an image filter mutation.
36-
//
37-
// Should be used for image_filter_layer and backdrop_filter_layer.
38-
// TODO(cyanglaz): Refactor this into a ImageFilterMutator class.
39-
// https://github.com/flutter/flutter/issues/108470
40-
class ImageFilterMutation {
41-
public:
42-
ImageFilterMutation(std::shared_ptr<const DlImageFilter> filter,
43-
const SkRect& filter_rect)
44-
: filter_(filter), filter_rect_(filter_rect) {}
45-
46-
const DlImageFilter& GetFilter() const { return *filter_; }
47-
const SkRect& GetFilterRect() const { return filter_rect_; }
48-
49-
bool operator==(const ImageFilterMutation& other) const {
50-
return *filter_ == *other.filter_ && filter_rect_ == other.filter_rect_;
51-
}
52-
53-
bool operator!=(const ImageFilterMutation& other) const {
54-
return !operator==(other);
55-
}
56-
57-
private:
58-
std::shared_ptr<const DlImageFilter> filter_;
59-
const SkRect filter_rect_;
60-
};
61-
6235
// Stores mutation information like clipping or kTransform.
6336
//
6437
// The `type` indicates the type of the mutation: kClipRect, kTransform and etc.
@@ -86,7 +59,7 @@ class Mutator {
8659
alpha_ = other.alpha_;
8760
break;
8861
case kBackdropFilter:
89-
filter_mutation_ = other.filter_mutation_;
62+
filter_ = other.filter_;
9063
break;
9164
default:
9265
break;
@@ -100,20 +73,15 @@ class Mutator {
10073
explicit Mutator(const SkMatrix& matrix)
10174
: type_(kTransform), matrix_(matrix) {}
10275
explicit Mutator(const int& alpha) : type_(kOpacity), alpha_(alpha) {}
103-
explicit Mutator(std::shared_ptr<const DlImageFilter> filter,
104-
const SkRect& filter_rect)
105-
: type_(kBackdropFilter),
106-
filter_mutation_(
107-
std::make_shared<ImageFilterMutation>(filter, filter_rect)) {}
76+
explicit Mutator(std::shared_ptr<const DlImageFilter> filter)
77+
: type_(kBackdropFilter), filter_(filter) {}
10878

10979
const MutatorType& GetType() const { return type_; }
11080
const SkRect& GetRect() const { return rect_; }
11181
const SkRRect& GetRRect() const { return rrect_; }
11282
const SkPath& GetPath() const { return *path_; }
11383
const SkMatrix& GetMatrix() const { return matrix_; }
114-
const ImageFilterMutation& GetFilterMutation() const {
115-
return *filter_mutation_;
116-
}
84+
const DlImageFilter& GetFilter() const { return *filter_; }
11785
const int& GetAlpha() const { return alpha_; }
11886
float GetAlphaFloat() const { return (alpha_ / 255.0); }
11987

@@ -133,7 +101,7 @@ class Mutator {
133101
case kOpacity:
134102
return alpha_ == other.alpha_;
135103
case kBackdropFilter:
136-
return *filter_mutation_ == *other.filter_mutation_;
104+
return *filter_ == *other.filter_;
137105
}
138106

139107
return false;
@@ -164,7 +132,8 @@ class Mutator {
164132
int alpha_;
165133
};
166134

167-
std::shared_ptr<ImageFilterMutation> filter_mutation_;
135+
std::shared_ptr<const DlImageFilter> filter_;
136+
168137
}; // Mutator
169138

170139
// A stack of mutators that can be applied to an embedded platform view.
@@ -185,8 +154,7 @@ class MutatorsStack {
185154
void PushClipPath(const SkPath& path);
186155
void PushTransform(const SkMatrix& matrix);
187156
void PushOpacity(const int& alpha);
188-
void PushBackdropFilter(const std::shared_ptr<const DlImageFilter>& filter,
189-
const SkRect& filter_rect);
157+
void PushBackdropFilter(const std::shared_ptr<const DlImageFilter>& filter);
190158

191159
// Removes the `Mutator` on the top of the stack
192160
// and destroys it.
@@ -284,9 +252,8 @@ class EmbeddedViewParams {
284252
const SkRect& finalBoundingRect() const { return final_bounding_rect_; }
285253

286254
// Pushes the stored DlImageFilter object to the mutators stack.
287-
void PushImageFilter(std::shared_ptr<const DlImageFilter> filter,
288-
const SkRect& filter_rect) {
289-
mutators_stack_.PushBackdropFilter(filter, filter_rect);
255+
void PushImageFilter(std::shared_ptr<const DlImageFilter> filter) {
256+
mutators_stack_.PushBackdropFilter(filter);
290257
}
291258

292259
// Whether the embedder should construct DisplayList objects to hold the
@@ -490,8 +457,7 @@ class ExternalViewEmbedder {
490457
// See also: |PushVisitedPlatformView| for pushing platform view ids to the
491458
// visited platform views list.
492459
virtual void PushFilterToVisitedPlatformViews(
493-
std::shared_ptr<const DlImageFilter> filter,
494-
const SkRect& filter_rect) {}
460+
std::shared_ptr<const DlImageFilter> filter) {}
495461

496462
private:
497463
bool used_this_frame_ = false;

flow/layers/backdrop_filter_layer.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ void BackdropFilterLayer::Preroll(PrerollContext* context) {
4343
Layer::AutoPrerollSaveLayerState save =
4444
Layer::AutoPrerollSaveLayerState::Create(context, true, bool(filter_));
4545
if (context->view_embedder != nullptr) {
46-
context->view_embedder->PushFilterToVisitedPlatformViews(
47-
filter_, context->cull_rect);
46+
context->view_embedder->PushFilterToVisitedPlatformViews(filter_);
4847
}
4948
SkRect child_paint_bounds = SkRect::MakeEmpty();
5049
PrerollChildren(context, &child_paint_bounds);

flow/mutators_stack_unittests.cc

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,14 @@ TEST(MutatorsStack, PushBackdropFilter) {
9494
const int num_of_mutators = 10;
9595
for (int i = 0; i < num_of_mutators; i++) {
9696
auto filter = std::make_shared<DlBlurImageFilter>(i, 5, DlTileMode::kClamp);
97-
stack.PushBackdropFilter(filter, SkRect::MakeXYWH(i, i, i, i));
97+
stack.PushBackdropFilter(filter);
9898
}
9999

100100
auto iter = stack.Begin();
101101
int i = 0;
102102
while (iter != stack.End()) {
103103
ASSERT_EQ(iter->get()->GetType(), MutatorType::kBackdropFilter);
104-
ASSERT_EQ(iter->get()->GetFilterMutation().GetFilter().asBlur()->sigma_x(),
105-
i);
106-
ASSERT_EQ(iter->get()->GetFilterMutation().GetFilterRect().x(), i);
107-
ASSERT_EQ(iter->get()->GetFilterMutation().GetFilterRect().x(), i);
108-
ASSERT_EQ(iter->get()->GetFilterMutation().GetFilterRect().width(), i);
109-
ASSERT_EQ(iter->get()->GetFilterMutation().GetFilterRect().height(), i);
104+
ASSERT_EQ(iter->get()->GetFilter().asBlur()->sigma_x(), i);
110105
++iter;
111106
++i;
112107
}
@@ -169,7 +164,7 @@ TEST(MutatorsStack, Equality) {
169164
int alpha = 240;
170165
stack.PushOpacity(alpha);
171166
auto filter = std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
172-
stack.PushBackdropFilter(filter, SkRect::MakeEmpty());
167+
stack.PushBackdropFilter(filter);
173168

174169
MutatorsStack stack_other;
175170
SkMatrix matrix_other = SkMatrix::Scale(1, 1);
@@ -184,7 +179,7 @@ TEST(MutatorsStack, Equality) {
184179
stack_other.PushOpacity(other_alpha);
185180
auto other_filter =
186181
std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
187-
stack_other.PushBackdropFilter(other_filter, SkRect::MakeEmpty());
182+
stack_other.PushBackdropFilter(other_filter);
188183

189184
ASSERT_TRUE(stack == stack_other);
190185
}
@@ -216,9 +211,9 @@ TEST(Mutator, Initialization) {
216211
ASSERT_TRUE(mutator5.GetType() == MutatorType::kOpacity);
217212

218213
auto filter = std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
219-
Mutator mutator6 = Mutator(filter, SkRect::MakeEmpty());
214+
Mutator mutator6 = Mutator(filter);
220215
ASSERT_TRUE(mutator6.GetType() == MutatorType::kBackdropFilter);
221-
ASSERT_TRUE(mutator6.GetFilterMutation().GetFilter() == *filter);
216+
ASSERT_TRUE(mutator6.GetFilter() == *filter);
222217
}
223218

224219
TEST(Mutator, CopyConstructor) {
@@ -249,7 +244,7 @@ TEST(Mutator, CopyConstructor) {
249244
ASSERT_TRUE(mutator5 == copy5);
250245

251246
auto filter = std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
252-
Mutator mutator6 = Mutator(filter, SkRect::MakeEmpty());
247+
Mutator mutator6 = Mutator(filter);
253248
Mutator copy6 = Mutator(mutator6);
254249
ASSERT_TRUE(mutator6 == copy6);
255250
}
@@ -281,10 +276,9 @@ TEST(Mutator, Equality) {
281276
Mutator other_mutator5 = Mutator(alpha);
282277
ASSERT_TRUE(mutator5 == other_mutator5);
283278

284-
auto filter1 = std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
285-
auto filter2 = std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
286-
Mutator mutator6 = Mutator(filter1, SkRect::MakeEmpty());
287-
Mutator other_mutator6 = Mutator(filter2, SkRect::MakeEmpty());
279+
auto filter = std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
280+
Mutator mutator6 = Mutator(filter);
281+
Mutator other_mutator6 = Mutator(filter);
288282
ASSERT_TRUE(mutator6 == other_mutator6);
289283
}
290284

@@ -305,8 +299,8 @@ TEST(Mutator, UnEquality) {
305299
auto filter = std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
306300
auto filter2 =
307301
std::make_shared<DlBlurImageFilter>(10, 10, DlTileMode::kClamp);
308-
Mutator mutator3 = Mutator(filter, SkRect::MakeEmpty());
309-
Mutator other_mutator3 = Mutator(filter2, SkRect::MakeEmpty());
302+
Mutator mutator3 = Mutator(filter);
303+
Mutator other_mutator3 = Mutator(filter2);
310304
ASSERT_TRUE(mutator3 != other_mutator3);
311305
}
312306

shell/common/shell_test_external_view_embedder.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,10 @@ void ShellTestExternalViewEmbedder::PushVisitedPlatformView(int64_t view_id) {
8989

9090
// |ExternalViewEmbedder|
9191
void ShellTestExternalViewEmbedder::PushFilterToVisitedPlatformViews(
92-
std::shared_ptr<const DlImageFilter> filter,
93-
const SkRect& filter_rect) {
92+
std::shared_ptr<const DlImageFilter> filter) {
9493
for (int64_t id : visited_platform_views_) {
9594
EmbeddedViewParams params = current_composition_params_[id];
96-
params.PushImageFilter(filter, filter_rect);
95+
params.PushImageFilter(filter);
9796
current_composition_params_[id] = params;
9897
mutators_stacks_[id] = params.mutatorsStack();
9998
}

shell/common/shell_test_external_view_embedder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ class ShellTestExternalViewEmbedder final : public ExternalViewEmbedder {
7676

7777
// |ExternalViewEmbedder|
7878
void PushFilterToVisitedPlatformViews(
79-
std::shared_ptr<const DlImageFilter> filter,
80-
const SkRect& filter_rect) override;
79+
std::shared_ptr<const DlImageFilter> filter) override;
8180

8281
// |ExternalViewEmbedder|
8382
void SubmitFrame(GrDirectContext* context,

shell/common/shell_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ TEST_F(ShellTest, PushBackdropFilterToVisitedPlatformViews) {
845845
auto filter = DlBlurImageFilter(5, 5, DlTileMode::kClamp);
846846
auto mutator = *external_view_embedder->GetStack(50).Begin();
847847
ASSERT_EQ(mutator->GetType(), MutatorType::kBackdropFilter);
848-
ASSERT_EQ(mutator->GetFilterMutation().GetFilter(), filter);
848+
ASSERT_EQ(mutator->GetFilter(), filter);
849849

850850
DestroyShell(std::move(shell));
851851
}

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,10 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
321321
}
322322

323323
void FlutterPlatformViewsController::PushFilterToVisitedPlatformViews(
324-
std::shared_ptr<const DlImageFilter> filter,
325-
const SkRect& filter_rect) {
324+
std::shared_ptr<const DlImageFilter> filter) {
326325
for (int64_t id : visited_platform_views_) {
327326
EmbeddedViewParams params = current_composition_params_[id];
328-
params.PushImageFilter(filter, filter_rect);
327+
params.PushImageFilter(filter);
329328
current_composition_params_[id] = params;
330329
}
331330
}
@@ -426,7 +425,7 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
426425
CGRectGetWidth(flutter_view.bounds),
427426
CGRectGetHeight(flutter_view.bounds))] autorelease];
428427

429-
NSMutableArray* blurFilters = [[[NSMutableArray alloc] init] autorelease];
428+
NSMutableArray* blurRadii = [[[NSMutableArray alloc] init] autorelease];
430429

431430
auto iter = mutators_stack.Begin();
432431
while (iter != mutators_stack.End()) {
@@ -449,35 +448,13 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
449448
embedded_view.alpha = (*iter)->GetAlphaFloat() * embedded_view.alpha;
450449
break;
451450
case kBackdropFilter: {
452-
// Only support DlBlurImageFilter for BackdropFilter.
453-
if (!(*iter)->GetFilterMutation().GetFilter().asBlur() || !canApplyBlurBackdrop) {
454-
break;
455-
}
456-
CGRect filterRect =
457-
flutter::GetCGRectFromSkRect((*iter)->GetFilterMutation().GetFilterRect());
458-
// `filterRect` reprents the rect that should be filtered inside the `flutter_view_`.
459-
// The `PlatformViewFilter` needs the frame inside the `clipView` that needs to be
460-
// filtered.
461-
if (CGRectIsNull(CGRectIntersection(filterRect, clipView.frame))) {
462-
break;
463-
}
464-
CGRect intersection = CGRectIntersection(filterRect, clipView.frame);
465-
CGRect frameInClipView = [flutter_view_.get() convertRect:intersection toView:clipView];
466-
// sigma_x is arbitrarily chosen as the radius value because Quartz sets
467-
// sigma_x and sigma_y equal to each other. DlBlurImageFilter's Tile Mode
468-
// is not supported in Quartz's gaussianBlur CAFilter, so it is not used
469-
// to blur the PlatformView.
470-
CGFloat blurRadius = (*iter)->GetFilterMutation().GetFilter().asBlur()->sigma_x();
471-
UIVisualEffectView* visualEffectView = [[[UIVisualEffectView alloc]
472-
initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]] autorelease];
473-
PlatformViewFilter* filter =
474-
[[[PlatformViewFilter alloc] initWithFrame:frameInClipView
475-
blurRadius:blurRadius
476-
visualEffectView:visualEffectView] autorelease];
477-
if (!filter) {
478-
canApplyBlurBackdrop = NO;
479-
} else {
480-
[blurFilters addObject:filter];
451+
// We only support DlBlurImageFilter for BackdropFilter.
452+
if ((*iter)->GetFilter().asBlur() && canApplyBlurBackdrop) {
453+
// sigma_x is arbitrarily chosen as the radius value because Quartz sets
454+
// sigma_x and sigma_y equal to each other. DlBlurImageFilter's Tile Mode
455+
// is not supported in Quartz's gaussianBlur CAFilter, so it is not used
456+
// to blur the PlatformView.
457+
[blurRadii addObject:@((*iter)->GetFilter().asBlur()->sigma_x())];
481458
}
482459
break;
483460
}
@@ -486,16 +463,15 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
486463
}
487464

488465
if (canApplyBlurBackdrop) {
489-
[clipView applyBlurBackdropFilters:blurFilters];
466+
canApplyBlurBackdrop = [clipView applyBlurBackdropFilters:blurRadii];
490467
}
491468

492469
// Reverse the offset of the clipView.
493470
// The clipView's frame includes the final translate of the final transform matrix.
494-
// Thus, this translate needs to be reversed so the platform view can layout at the correct
495-
// offset.
471+
// So we need to revese this translate so the platform view can layout at the correct offset.
496472
//
497-
// Note that the transforms are not applied to the clipping paths because clipping paths happen on
498-
// the mask view, whose origin is always (0,0) to the flutter_view.
473+
// Note that we don't apply this transform matrix the clippings because clippings happen on the
474+
// mask view, whose origin is always (0,0) to the flutter_view.
499475
CATransform3D reverseTranslate =
500476
CATransform3DMakeTranslation(-clipView.frame.origin.x, -clipView.frame.origin.y, 0);
501477
embedded_view.layer.transform = CATransform3DConcat(finalTransform, reverseTranslate);

0 commit comments

Comments
 (0)