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

Commit bac5f99

Browse files
author
Chris Yang
committed
recycle maskView at the begining of the frame
1 parent 66fec20 commit bac5f99

12 files changed

+376
-47
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
1919
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
2020

21-
static const NSUInteger kFlutterClippingMaskViewPoolCapacity = 5;
22-
2321
@implementation UIView (FirstResponder)
2422
- (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
2523
if (self.isFirstResponder) {
@@ -461,11 +459,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
461459
NSMutableArray* blurFilters = [[[NSMutableArray alloc] init] autorelease];
462460
FML_DCHECK(!clipView.maskView ||
463461
[clipView.maskView isKindOfClass:[FlutterClippingMaskView class]]);
464-
if (mask_view_pool_.get() == nil) {
465-
mask_view_pool_.reset([[FlutterClippingMaskViewPool alloc]
466-
initWithCapacity:kFlutterClippingMaskViewPoolCapacity]);
467-
}
468-
[mask_view_pool_.get() recycleMaskViews];
462+
469463
clipView.maskView = nil;
470464
CGFloat screenScale = [UIScreen mainScreen].scale;
471465
auto iter = mutators_stack.Begin();
@@ -899,6 +893,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
899893
slices_.clear();
900894
composition_order_.clear();
901895
visited_platform_views_.clear();
896+
[mask_view_pool_.get() recycleMaskViews];
902897
}
903898

904899
} // namespace flutter

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

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,17 +2727,17 @@ - (void)testClipMaskViewIsReused {
27272727
auto embeddedViewParams1 = std::make_unique<flutter::EmbeddedViewParams>(
27282728
screenScaleMatrix, SkSize::Make(10, 10), stack1);
27292729

2730-
flutter::MutatorsStack stack2;
2731-
auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
2732-
screenScaleMatrix, SkSize::Make(10, 10), stack2);
2733-
27342730
flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
27352731
flutterPlatformViewsController->CompositeEmbeddedView(1);
27362732
UIView* childClippingView1 = gMockPlatformView.superview.superview;
27372733
UIView* maskView1 = childClippingView1.maskView;
27382734
XCTAssertNotNil(maskView1);
27392735

27402736
// Composite a new frame.
2737+
flutterPlatformViewsController->BeginFrame(SkISize::Make(100, 100));
2738+
flutter::MutatorsStack stack2;
2739+
auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
2740+
screenScaleMatrix, SkSize::Make(10, 10), stack2);
27412741
auto embeddedViewParams3 = std::make_unique<flutter::EmbeddedViewParams>(
27422742
screenScaleMatrix, SkSize::Make(10, 10), stack2);
27432743
flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams3));
@@ -2763,6 +2763,77 @@ - (void)testClipMaskViewIsReused {
27632763
XCTAssertNil(childClippingView1.maskView);
27642764
}
27652765

2766+
- (void)testDifferentClipMaskViewIsUsedForEachView {
2767+
flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2768+
auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest");
2769+
flutter::TaskRunners runners(/*label=*/self.name.UTF8String,
2770+
/*platform=*/thread_task_runner,
2771+
/*raster=*/thread_task_runner,
2772+
/*ui=*/thread_task_runner,
2773+
/*io=*/thread_task_runner);
2774+
auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
2775+
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2776+
/*delegate=*/mock_delegate,
2777+
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
2778+
/*platform_views_controller=*/flutterPlatformViewsController,
2779+
/*task_runners=*/runners);
2780+
2781+
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
2782+
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
2783+
flutterPlatformViewsController->RegisterViewFactory(
2784+
factory, @"MockFlutterPlatformView",
2785+
FlutterPlatformViewGestureRecognizersBlockingPolicyEager);
2786+
FlutterResult result = ^(id result) {
2787+
};
2788+
2789+
flutterPlatformViewsController->OnMethodCall(
2790+
[FlutterMethodCall
2791+
methodCallWithMethodName:@"create"
2792+
arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}],
2793+
result);
2794+
UIView* view1 = gMockPlatformView;
2795+
2796+
// This overwrites `gMockPlatformView` to another view.
2797+
flutterPlatformViewsController->OnMethodCall(
2798+
[FlutterMethodCall
2799+
methodCallWithMethodName:@"create"
2800+
arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}],
2801+
result);
2802+
UIView* view2 = gMockPlatformView;
2803+
2804+
XCTAssertNotNil(gMockPlatformView);
2805+
UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease];
2806+
flutterPlatformViewsController->SetFlutterView(mockFlutterView);
2807+
// Create embedded view params
2808+
flutter::MutatorsStack stack1;
2809+
// Layer tree always pushes a screen scale factor to the stack
2810+
SkMatrix screenScaleMatrix =
2811+
SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
2812+
stack1.PushTransform(screenScaleMatrix);
2813+
// Push a clip rect
2814+
SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3);
2815+
stack1.PushClipRect(rect);
2816+
2817+
auto embeddedViewParams1 = std::make_unique<flutter::EmbeddedViewParams>(
2818+
screenScaleMatrix, SkSize::Make(10, 10), stack1);
2819+
2820+
flutter::MutatorsStack stack2;
2821+
stack2.PushClipRect(rect);
2822+
auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
2823+
screenScaleMatrix, SkSize::Make(10, 10), stack2);
2824+
2825+
flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
2826+
flutterPlatformViewsController->CompositeEmbeddedView(1);
2827+
UIView* childClippingView1 = view1.superview.superview;
2828+
2829+
flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams2));
2830+
flutterPlatformViewsController->CompositeEmbeddedView(2);
2831+
UIView* childClippingView2 = view2.superview.superview;
2832+
UIView* maskView1 = childClippingView1.maskView;
2833+
UIView* maskView2 = childClippingView2.maskView;
2834+
XCTAssertNotEqual(maskView1, maskView2);
2835+
}
2836+
27662837
// Return true if a correct visual effect view is found. It also implies all the validation in this
27672838
// method passes.
27682839
//

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
1010

1111
static int kMaxPointsInVerb = 4;
12+
static const NSUInteger kFlutterClippingMaskViewPoolCapacity = 5;
1213

1314
namespace flutter {
1415

@@ -26,7 +27,10 @@
2627

2728
FlutterPlatformViewsController::FlutterPlatformViewsController()
2829
: layer_pool_(std::make_unique<FlutterPlatformViewLayerPool>()),
29-
weak_factory_(std::make_unique<fml::WeakPtrFactory<FlutterPlatformViewsController>>(this)){};
30+
weak_factory_(std::make_unique<fml::WeakPtrFactory<FlutterPlatformViewsController>>(this)) {
31+
mask_view_pool_.reset(
32+
[[FlutterClippingMaskViewPool alloc] initWithCapacity:kFlutterClippingMaskViewPoolCapacity]);
33+
};
3034

3135
FlutterPlatformViewsController::~FlutterPlatformViewsController() = default;
3236

testing/scenario_app/ios/Scenarios/Scenarios.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
6816DBA12317573300A51400 /* GoldenImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 6816DBA02317573300A51400 /* GoldenImage.m */; };
3939
6816DBA42318358200A51400 /* GoldenTestManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6816DBA32318358200A51400 /* GoldenTestManager.m */; };
4040
682C5873299C182A00915E5C /* golden_platform_view_cliprect_after_moved_iPhone 8_16.0_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 682C5872299C182A00915E5C /* golden_platform_view_cliprect_after_moved_iPhone 8_16.0_simulator.png */; };
41+
684FFF9329FB89EF00281002 /* golden_two_platform_view_clip_rrect_iPhone 8_16.0_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 684FFF9029FB89EE00281002 /* golden_two_platform_view_clip_rrect_iPhone 8_16.0_simulator.png */; };
42+
684FFF9429FB89EF00281002 /* golden_two_platform_view_clip_path_iPhone 8_16.0_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 684FFF9129FB89EF00281002 /* golden_two_platform_view_clip_path_iPhone 8_16.0_simulator.png */; };
43+
684FFF9529FB89EF00281002 /* golden_two_platform_view_clip_rect_iPhone 8_16.0_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 684FFF9229FB89EF00281002 /* golden_two_platform_view_clip_rect_iPhone 8_16.0_simulator.png */; };
4144
685B9F392977B73100B45442 /* golden_platform_view_large_cliprrect_with_transform_iPhone 8_16.0_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 685B9F372977B73100B45442 /* golden_platform_view_large_cliprrect_with_transform_iPhone 8_16.0_simulator.png */; };
4245
685B9F3A2977B73100B45442 /* golden_platform_view_large_cliprrect_iPhone 8_16.0_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 685B9F382977B73100B45442 /* golden_platform_view_large_cliprrect_iPhone 8_16.0_simulator.png */; };
4346
687AF8E9291EBDE0003912C7 /* golden_platform_view_clippath_with_transform_iPhone 8_16.0_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 687AF8E8291EBDE0003912C7 /* golden_platform_view_clippath_with_transform_iPhone 8_16.0_simulator.png */; };
@@ -155,6 +158,9 @@
155158
6816DBA22318358200A51400 /* GoldenTestManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GoldenTestManager.h; sourceTree = "<group>"; };
156159
6816DBA32318358200A51400 /* GoldenTestManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GoldenTestManager.m; sourceTree = "<group>"; };
157160
682C5872299C182A00915E5C /* golden_platform_view_cliprect_after_moved_iPhone 8_16.0_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_platform_view_cliprect_after_moved_iPhone 8_16.0_simulator.png"; sourceTree = "<group>"; };
161+
684FFF9029FB89EE00281002 /* golden_two_platform_view_clip_rrect_iPhone 8_16.0_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_two_platform_view_clip_rrect_iPhone 8_16.0_simulator.png"; sourceTree = "<group>"; };
162+
684FFF9129FB89EF00281002 /* golden_two_platform_view_clip_path_iPhone 8_16.0_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_two_platform_view_clip_path_iPhone 8_16.0_simulator.png"; sourceTree = "<group>"; };
163+
684FFF9229FB89EF00281002 /* golden_two_platform_view_clip_rect_iPhone 8_16.0_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_two_platform_view_clip_rect_iPhone 8_16.0_simulator.png"; sourceTree = "<group>"; };
158164
685B9F372977B73100B45442 /* golden_platform_view_large_cliprrect_with_transform_iPhone 8_16.0_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_platform_view_large_cliprrect_with_transform_iPhone 8_16.0_simulator.png"; sourceTree = "<group>"; };
159165
685B9F382977B73100B45442 /* golden_platform_view_large_cliprrect_iPhone 8_16.0_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_platform_view_large_cliprrect_iPhone 8_16.0_simulator.png"; sourceTree = "<group>"; };
160166
687AF8E8291EBDE0003912C7 /* golden_platform_view_clippath_with_transform_iPhone 8_16.0_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_platform_view_clippath_with_transform_iPhone 8_16.0_simulator.png"; sourceTree = "<group>"; };
@@ -302,6 +308,9 @@
302308
F7B464DC2759D02B00079189 /* Goldens */ = {
303309
isa = PBXGroup;
304310
children = (
311+
684FFF9129FB89EF00281002 /* golden_two_platform_view_clip_path_iPhone 8_16.0_simulator.png */,
312+
684FFF9229FB89EF00281002 /* golden_two_platform_view_clip_rect_iPhone 8_16.0_simulator.png */,
313+
684FFF9029FB89EE00281002 /* golden_two_platform_view_clip_rrect_iPhone 8_16.0_simulator.png */,
305314
682C5872299C182A00915E5C /* golden_platform_view_cliprect_after_moved_iPhone 8_16.0_simulator.png */,
306315
685B9F382977B73100B45442 /* golden_platform_view_large_cliprrect_iPhone 8_16.0_simulator.png */,
307316
685B9F372977B73100B45442 /* golden_platform_view_large_cliprrect_with_transform_iPhone 8_16.0_simulator.png */,
@@ -461,15 +470,18 @@
461470
F7B464EE2759D0A900079189 /* golden_platform_view_transform_iPhone 8_16.0_simulator.png in Resources */,
462471
F7B464F32759D0A900079189 /* golden_platform_view_multiple_background_foreground_iPhone 8_16.0_simulator.png in Resources */,
463472
F7B464F72759D0A900079189 /* golden_platform_view_rotate_iPhone 8_16.0_simulator.png in Resources */,
473+
684FFF9329FB89EF00281002 /* golden_two_platform_view_clip_rrect_iPhone 8_16.0_simulator.png in Resources */,
464474
F7B464ED2759D0A900079189 /* golden_platform_view_cliprrect_iPhone 8_16.0_simulator.png in Resources */,
465475
685B9F3A2977B73100B45442 /* golden_platform_view_large_cliprrect_iPhone 8_16.0_simulator.png in Resources */,
466476
68D5003F291ED645001ACFE1 /* golden_platform_view_cliprrect_with_transform_iPhone 8_16.0_simulator.png in Resources */,
467477
F7B464EB2759D0A900079189 /* golden_two_platform_views_with_other_backdrop_filter_iPhone 8_16.0_simulator.png in Resources */,
478+
684FFF9529FB89EF00281002 /* golden_two_platform_view_clip_rect_iPhone 8_16.0_simulator.png in Resources */,
468479
F7B464F42759D0A900079189 /* golden_platform_view_with_other_backdrop_filter_iPhone 8_16.0_simulator.png in Resources */,
469480
687AF8E9291EBDE0003912C7 /* golden_platform_view_clippath_with_transform_iPhone 8_16.0_simulator.png in Resources */,
470481
685B9F392977B73100B45442 /* golden_platform_view_large_cliprrect_with_transform_iPhone 8_16.0_simulator.png in Resources */,
471482
F769EB53276312BB007AC10F /* golden_platform_view_cliprect_iPhone 8_16.0_simulator.png in Resources */,
472483
F7B464EF2759D0A900079189 /* golden_platform_view_multiple_iPhone 8_16.0_simulator.png in Resources */,
484+
684FFF9429FB89EF00281002 /* golden_two_platform_view_clip_path_iPhone 8_16.0_simulator.png in Resources */,
473485
);
474486
runOnlyForDeploymentPostprocessing = 0;
475487
};

testing/scenario_app/ios/Scenarios/Scenarios/AppDelegate.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ - (BOOL)application:(UIApplication*)application
6969
@"--spawn-engine-works" : @"spawn_engine_works",
7070
@"--pointer-events" : @"pointer_events",
7171
@"--platform-view-scrolling-under-widget" : @"platform_view_scrolling_under_widget",
72-
@"--platform-view-cliprect-after-moved" : @"platform_view_cliprect_after_moved"
72+
@"--platform-view-cliprect-after-moved" : @"platform_view_cliprect_after_moved",
73+
@"--two-platform-view-clip-rect" : @"two_platform_view_clip_rect",
74+
@"--two-platform-view-clip-rrect" : @"two_platform_view_clip_rrect",
75+
@"--two-platform-view-clip-path" : @"two_platform_view_clip_path",
7376
};
7477
__block NSString* flutterViewControllerTestName = nil;
7578
[launchArgsMap

testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenTestManager.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ - (instancetype)initWithLaunchArg:(NSString*)launchArg {
4747
@"--bogus-font-text" : @"bogus_font_text",
4848
@"--spawn-engine-works" : @"spawn_engine_works",
4949
@"--platform-view-cliprect-after-moved" : @"platform_view_cliprect_after_moved",
50+
@"--two-platform-view-clip-rect" : @"two_platform_view_clip_rect",
51+
@"--two-platform-view-clip-rrect" : @"two_platform_view_clip_rrect",
52+
@"--two-platform-view-clip-path" : @"two_platform_view_clip_path",
5053
};
5154
});
5255
_identifier = launchArgsMap[launchArg];

testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,60 @@ - (void)testPlatformView {
254254

255255
@end
256256

257+
@interface TwoPlatformViewClipRectTests : GoldenPlatformViewTests
258+
259+
@end
260+
261+
@implementation TwoPlatformViewClipRectTests
262+
263+
- (instancetype)initWithInvocation:(NSInvocation*)invocation {
264+
GoldenTestManager* manager =
265+
[[GoldenTestManager alloc] initWithLaunchArg:@"--two-platform-view-clip-rect"];
266+
return [super initWithManager:manager invocation:invocation];
267+
}
268+
269+
- (void)testPlatformView {
270+
[self checkPlatformViewGolden];
271+
}
272+
273+
@end
274+
275+
@interface TwoPlatformViewClipRRectTests : GoldenPlatformViewTests
276+
277+
@end
278+
279+
@implementation TwoPlatformViewClipRRectTests
280+
281+
- (instancetype)initWithInvocation:(NSInvocation*)invocation {
282+
GoldenTestManager* manager =
283+
[[GoldenTestManager alloc] initWithLaunchArg:@"--two-platform-view-clip-rrect"];
284+
return [super initWithManager:manager invocation:invocation];
285+
}
286+
287+
- (void)testPlatformView {
288+
[self checkPlatformViewGolden];
289+
}
290+
291+
@end
292+
293+
@interface TwoPlatformViewClipPathTests : GoldenPlatformViewTests
294+
295+
@end
296+
297+
@implementation TwoPlatformViewClipPathTests
298+
299+
- (instancetype)initWithInvocation:(NSInvocation*)invocation {
300+
GoldenTestManager* manager =
301+
[[GoldenTestManager alloc] initWithLaunchArg:@"--two-platform-view-clip-path"];
302+
return [super initWithManager:manager invocation:invocation];
303+
}
304+
305+
- (void)testPlatformView {
306+
[self checkPlatformViewGolden];
307+
}
308+
309+
@end
310+
257311
@interface PlatformViewMutationTransformTests : GoldenPlatformViewTests
258312

259313
@end

0 commit comments

Comments
 (0)