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

Commit c1e3f4e

Browse files
author
Chris Yang
committed
format
1 parent 3a28609 commit c1e3f4e

10 files changed

+164
-165
lines changed

flow/embedded_views.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ void MutatorsStack::PushOpacity(const int& alpha) {
101101

102102
void MutatorsStack::PushBackdropFilter(
103103
const std::shared_ptr<const DlImageFilter>& filter,
104-
const SkRect& paint_bounds) {
104+
const SkRect& filter_rect) {
105105
std::shared_ptr<Mutator> element =
106-
std::make_shared<Mutator>(filter, paint_bounds);
106+
std::make_shared<Mutator>(filter, filter_rect);
107107
vector_.push_back(element);
108108
};
109109

flow/embedded_views.h

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,25 @@ enum MutatorType {
3838
// TODO(cyanglaz): Refactor this into a ImageFilterMutator class.
3939
// https://github.com/flutter/flutter/issues/108470
4040
class ImageFilterMutation {
41-
public:
42-
ImageFilterMutation(std::shared_ptr<const DlImageFilter> filter, const SkRect& paint_bounds):filter_(filter), paint_bounds_(paint_bounds){}
41+
public:
42+
ImageFilterMutation(std::shared_ptr<const DlImageFilter> filter,
43+
const SkRect& filter_rect)
44+
: filter_(filter), filter_rect_(filter_rect) {}
4345

44-
const DlImageFilter& GetFilter() const { return *filter_; }
45-
const SkRect& GetPaintBounds() const { return paint_bounds_; }
46+
const DlImageFilter& GetFilter() const { return *filter_; }
47+
const SkRect& GetFilterRect() const { return filter_rect_; }
4648

47-
bool operator==(const ImageFilterMutation& other) const {
48-
return *filter_ == *other.filter_ && paint_bounds_ == other.paint_bounds_;
49-
}
49+
bool operator==(const ImageFilterMutation& other) const {
50+
return *filter_ == *other.filter_ && filter_rect_ == other.filter_rect_;
51+
}
5052

51-
bool operator!=(const ImageFilterMutation& other) const { return !operator==(other); }
53+
bool operator!=(const ImageFilterMutation& other) const {
54+
return !operator==(other);
55+
}
5256

53-
private:
54-
std::shared_ptr<const DlImageFilter> filter_;
55-
// Used for filter_
56-
const SkRect& paint_bounds_;
57+
private:
58+
std::shared_ptr<const DlImageFilter> filter_;
59+
const SkRect filter_rect_;
5760
};
5861

5962
// Stores mutation information like clipping or kTransform.
@@ -97,8 +100,10 @@ class Mutator {
97100
explicit Mutator(const SkMatrix& matrix)
98101
: type_(kTransform), matrix_(matrix) {}
99102
explicit Mutator(const int& alpha) : type_(kOpacity), alpha_(alpha) {}
100-
explicit Mutator(std::shared_ptr<const DlImageFilter> filter, const SkRect& paint_bounds)
101-
: type_(kBackdropFilter), filter_(std::make_shared<ImageFilterMutation>(filter, paint_bounds)) {}
103+
explicit Mutator(std::shared_ptr<const DlImageFilter> filter,
104+
const SkRect& filter_rect)
105+
: type_(kBackdropFilter),
106+
filter_(std::make_shared<ImageFilterMutation>(filter, filter_rect)) {}
102107

103108
const MutatorType& GetType() const { return type_; }
104109
const SkRect& GetRect() const { return rect_; }
@@ -177,8 +182,8 @@ class MutatorsStack {
177182
void PushClipPath(const SkPath& path);
178183
void PushTransform(const SkMatrix& matrix);
179184
void PushOpacity(const int& alpha);
180-
void PushBackdropFilter(const std::shared_ptr<const DlImageFilter>const filter,
181-
const SkRect& paint_bounds);
185+
void PushBackdropFilter(const std::shared_ptr<const DlImageFilter>& filter,
186+
const SkRect& filter_rect);
182187

183188
// Removes the `Mutator` on the top of the stack
184189
// and destroys it.
@@ -273,8 +278,9 @@ class EmbeddedViewParams {
273278
const SkRect& finalBoundingRect() const { return final_bounding_rect_; }
274279

275280
// Pushes the stored DlImageFilter object to the mutators stack.
276-
void PushImageFilter(std::shared_ptr<const DlImageFilter> filter, const SkRect& paint_bounds) {
277-
mutators_stack_.PushBackdropFilter(filter, paint_bounds);
281+
void PushImageFilter(std::shared_ptr<const DlImageFilter> filter,
282+
const SkRect& filter_rect) {
283+
mutators_stack_.PushBackdropFilter(filter, filter_rect);
278284
}
279285

280286
// Whether the embedder should construct DisplayList objects to hold the
@@ -478,7 +484,8 @@ class ExternalViewEmbedder {
478484
// See also: |PushVisitedPlatformView| for pushing platform view ids to the
479485
// visited platform views list.
480486
virtual void PushFilterToVisitedPlatformViews(
481-
std::shared_ptr<const DlImageFilter> filter, const SkRect& paint_bounds) {}
487+
std::shared_ptr<const DlImageFilter> filter,
488+
const SkRect& filter_rect) {}
482489

483490
private:
484491
bool used_this_frame_ = false;

flow/layers/backdrop_filter_layer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ void BackdropFilterLayer::Preroll(PrerollContext* context,
4949
set_paint_bounds(child_paint_bounds);
5050
context->subtree_can_inherit_opacity = true;
5151
if (context->view_embedder != nullptr) {
52-
context->view_embedder->PushFilterToVisitedPlatformViews(filter_,
53-
paint_bounds());
52+
context->view_embedder->PushFilterToVisitedPlatformViews(
53+
filter_, context->cull_rect);
5454
}
5555
}
5656

shell/common/shell_test_external_view_embedder.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ void ShellTestExternalViewEmbedder::PushVisitedPlatformView(int64_t view_id) {
9090
// |ExternalViewEmbedder|
9191
void ShellTestExternalViewEmbedder::PushFilterToVisitedPlatformViews(
9292
std::shared_ptr<const DlImageFilter> filter,
93-
const SkRect& paint_bounds) {
93+
const SkRect& filter_rect) {
9494
for (int64_t id : visited_platform_views_) {
9595
EmbeddedViewParams params = current_composition_params_[id];
96-
params.PushImageFilter(filter, paint_bounds);
96+
params.PushImageFilter(filter, filter_rect);
9797
current_composition_params_[id] = params;
9898
mutators_stacks_[id] = params.mutatorsStack();
9999
}

shell/common/shell_test_external_view_embedder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ShellTestExternalViewEmbedder final : public ExternalViewEmbedder {
7777
// |ExternalViewEmbedder|
7878
void PushFilterToVisitedPlatformViews(
7979
std::shared_ptr<const DlImageFilter> filter,
80-
const SkRect& paint_bounds) override;
80+
const SkRect& filter_rect) override;
8181

8282
// |ExternalViewEmbedder|
8383
void SubmitFrame(GrDirectContext* context,

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
323323

324324
void FlutterPlatformViewsController::PushFilterToVisitedPlatformViews(
325325
std::shared_ptr<const DlImageFilter> filter,
326-
const SkRect& paint_bounds) {
326+
const SkRect& filter_rect) {
327327
for (int64_t id : visited_platform_views_) {
328328
EmbeddedViewParams params = current_composition_params_[id];
329-
params.PushImageFilter(filter, paint_bounds);
329+
params.PushImageFilter(filter, filter_rect);
330330
current_composition_params_[id] = params;
331331
}
332332
}
@@ -431,7 +431,7 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
431431
CGRectGetWidth(flutter_view.bounds),
432432
CGRectGetHeight(flutter_view.bounds))] autorelease];
433433

434-
NSMutableArray* blurRadii = [[[NSMutableArray alloc] init] autorelease];
434+
NSMutableArray* blurFilters = [[[NSMutableArray alloc] init] autorelease];
435435

436436
auto iter = mutators_stack.Begin();
437437
while (iter != mutators_stack.End()) {
@@ -460,7 +460,18 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
460460
// sigma_x and sigma_y equal to each other. DlBlurImageFilter's Tile Mode
461461
// is not supported in Quartz's gaussianBlur CAFilter, so it is not used
462462
// to blur the PlatformView.
463-
[blurRadii addObject:@((*iter)->GetFilter().GetFilter().asBlur()->sigma_x())];
463+
CGFloat blurRadius = (*iter)->GetFilter().GetFilter().asBlur()->sigma_x();
464+
CGRect filterRect = flutter::GetCGRectFromSkRect((*iter)->GetFilter().GetFilterRect());
465+
// `filterRect` reprents the rect that shouuld be filtered inside the `flutter_view_`.
466+
// The `PlatformViewFilter` needs the frame inside the `clipView` that needs to be
467+
// filtered.
468+
CGRect intersection = CGRectIntersection(filterRect, clipView.frame);
469+
if (CGRectContainsRect(clipView.frame, intersection)) {
470+
CGRect frameInClipView = [flutter_view_.get() convertRect:intersection toView:clipView];
471+
PlatformViewFilter* filter = [[PlatformViewFilter alloc] initWithFrame:frameInClipView
472+
blurRadius:blurRadius];
473+
[blurFilters addObject:filter];
474+
}
464475
}
465476
break;
466477
}
@@ -469,8 +480,7 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
469480
}
470481

471482
if (canApplyBlurBackdrop) {
472-
canApplyBlurBackdrop = [clipView applyBlurBackdropFilters:blurRadii
473-
atFrame:CGRectMake(50, 50, 200, 200)];
483+
canApplyBlurBackdrop = [clipView applyBlurBackdropFilters:blurFilters];
474484
}
475485

476486
// Reverse the offset of the clipView.

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,26 @@
4848
// An object represents a filter.
4949
@interface PlatformViewFilter : NSObject
5050

51-
@property(assign, nonatomic) CGRect frame;
52-
@property(assign, nonatomic) CGFloat blurRadius;
53-
54-
- (void)initWithFrame:(CGRect)frame blurRadius:(CGFloat)blurRadius;
55-
56-
@end
57-
58-
// A view that applies filter to the |ChildClippingView|.
59-
//
60-
// The filter information is provided with a single |PlatformViewFilter|.
61-
@interface PlatformViewFilterView : UIView
51+
@property(assign, nonatomic, readonly) CGRect frame;
52+
@property(assign, nonatomic, readonly) CGFloat blurRadius;
53+
// The UIView used to extract the gaussianBlur filter. This must be a UIVisualEffectView
54+
// initalized with UIBlurEffect to extract the correct filter. Made a public property
55+
// for custom unit tests.
56+
@property(nonatomic, retain) UIView* blurEffectView;
6257

63-
// Applies blur backdrop filters to the PlatformViewFilterView with blur radius values from
64-
// blurRadii.
65-
- (void)applyBlurBackdropFilters:(NSArray*)blurRadii gaussianFilter:(NSObject*)gaussianFilter;
58+
- (instancetype)initWithFrame:(CGRect)frame blurRadius:(CGFloat)blurRadius;
59+
// Returns the blur backdrop filter view based on the `frame` and `blurRadius` property.
60+
- (UIView*)backdropFilterView;
6661

6762
@end
6863

6964
// The parent view handles clipping to its subviews.
7065
@interface ChildClippingView : UIView
7166

72-
// The UIView used to extract the gaussianBlur filter. This must be a UIVisualEffectView
73-
// initalized with UIBlurEffect to extract the correct filter. Made a public property
74-
// for custom unit tests.
75-
@property(nonatomic, retain) UIView* blurEffectView;
76-
7767
// Applies blur backdrop filters to the ChildClippingView with blur radius values from
7868
// blurRadii. Returns NO if Apple's API has changed and blurred backdrop filters cannot
7969
// be applied, otherwise returns YES.
80-
- (BOOL)applyBlurBackdropFilters:(NSArray*)blurRadii atFrame:(CGRect)frame;
70+
- (BOOL)applyBlurBackdropFilters:(NSMutableArray<PlatformViewFilter*>*)filters;
8171

8272
@end
8373

@@ -90,6 +80,8 @@ CATransform3D GetCATransform3DFromSkMatrix(const SkMatrix& matrix);
9080
// The position of the `layer` should be unchanged after resetting the anchor.
9181
void ResetAnchor(CALayer* layer);
9282

83+
CGRect GetCGRectFromSkRect(const SkRect& clipSkRect);
84+
9385
class IOSContextGL;
9486
class IOSSurface;
9587

@@ -219,7 +211,7 @@ class FlutterPlatformViewsController {
219211

220212
// Pushes backdrop filter mutation to the mutator stack of each visited platform view.
221213
void PushFilterToVisitedPlatformViews(std::shared_ptr<const DlImageFilter> filter,
222-
const SkRect& paint_bounds);
214+
const SkRect& filter_rect);
223215

224216
// Pushes the view id of a visted platform view to the list of visied platform views.
225217
void PushVisitedPlatformView(int64_t view_id) { visited_platform_views_.push_back(view_id); }

0 commit comments

Comments
 (0)