@@ -2703,12 +2703,15 @@ - (void)testFlutterClippingMaskViewPoolReuseViewsAfterRecycle {
2703
2703
[[[FlutterClippingMaskViewPool alloc ] initWithCapacity: 2 ] autorelease ];
2704
2704
FlutterClippingMaskView* view1 = [pool getMaskViewWithFrame: CGRectZero];
2705
2705
FlutterClippingMaskView* view2 = [pool getMaskViewWithFrame: CGRectZero];
2706
- [pool recycleMaskViews ];
2706
+ [pool insertViewToPoolIfNeeded: view1];
2707
+ [pool insertViewToPoolIfNeeded: view2];
2707
2708
CGRect newRect = CGRectMake (0 , 0 , 10 , 10 );
2708
2709
FlutterClippingMaskView* view3 = [pool getMaskViewWithFrame: newRect];
2709
2710
FlutterClippingMaskView* view4 = [pool getMaskViewWithFrame: newRect];
2710
- XCTAssertEqual (view1, view3);
2711
- XCTAssertEqual (view2, view4);
2711
+ // view3 and view4 should randomly get either of view1 and view2.
2712
+ NSSet * set1 = [NSSet setWithObjects: view1, view2, nil ];
2713
+ NSSet * set2 = [NSSet setWithObjects: view3, view4, nil ];
2714
+ XCTAssertEqualObjects (set1, set2);
2712
2715
XCTAssertTrue (CGRectEqualToRect (view3.frame , newRect));
2713
2716
XCTAssertTrue (CGRectEqualToRect (view4.frame , newRect));
2714
2717
}
@@ -2783,17 +2786,17 @@ - (void)testClipMaskViewIsReused {
2783
2786
auto embeddedViewParams1 = std::make_unique<flutter::EmbeddedViewParams>(
2784
2787
screenScaleMatrix, SkSize::Make (10 , 10 ), stack1);
2785
2788
2786
- flutter::MutatorsStack stack2;
2787
- auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
2788
- screenScaleMatrix, SkSize::Make (10 , 10 ), stack2);
2789
-
2790
2789
flutterPlatformViewsController->PrerollCompositeEmbeddedView (1 , std::move (embeddedViewParams1));
2791
2790
flutterPlatformViewsController->CompositeEmbeddedView (1 );
2792
2791
UIView* childClippingView1 = gMockPlatformView .superview .superview ;
2793
2792
UIView* maskView1 = childClippingView1.maskView ;
2794
2793
XCTAssertNotNil (maskView1);
2795
2794
2796
2795
// Composite a new frame.
2796
+ flutterPlatformViewsController->BeginFrame (SkISize::Make (100 , 100 ));
2797
+ flutter::MutatorsStack stack2;
2798
+ auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
2799
+ screenScaleMatrix, SkSize::Make (10 , 10 ), stack2);
2797
2800
auto embeddedViewParams3 = std::make_unique<flutter::EmbeddedViewParams>(
2798
2801
screenScaleMatrix, SkSize::Make (10 , 10 ), stack2);
2799
2802
flutterPlatformViewsController->PrerollCompositeEmbeddedView (1 , std::move (embeddedViewParams3));
@@ -2819,6 +2822,79 @@ - (void)testClipMaskViewIsReused {
2819
2822
XCTAssertNil (childClippingView1.maskView );
2820
2823
}
2821
2824
2825
+ - (void )testDifferentClipMaskViewIsUsedForEachView {
2826
+ flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2827
+ auto thread_task_runner = CreateNewThread (" FlutterPlatformViewsTest" );
2828
+ flutter::TaskRunners runners (/* label=*/ self.name .UTF8String ,
2829
+ /* platform=*/ thread_task_runner,
2830
+ /* raster=*/ thread_task_runner,
2831
+ /* ui=*/ thread_task_runner,
2832
+ /* io=*/ thread_task_runner);
2833
+ auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
2834
+ auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2835
+ /* delegate=*/ mock_delegate,
2836
+ /* rendering_api=*/ flutter::IOSRenderingAPI::kSoftware ,
2837
+ /* platform_views_controller=*/ flutterPlatformViewsController,
2838
+ /* task_runners=*/ runners,
2839
+ /* worker_task_runner=*/ nil ,
2840
+ /* is_gpu_disabled_sync_switch=*/ nil );
2841
+
2842
+ FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
2843
+ [[FlutterPlatformViewsTestMockFlutterPlatformFactory new ] autorelease ];
2844
+ flutterPlatformViewsController->RegisterViewFactory (
2845
+ factory, @" MockFlutterPlatformView" ,
2846
+ FlutterPlatformViewGestureRecognizersBlockingPolicyEager);
2847
+ FlutterResult result = ^(id result) {
2848
+ };
2849
+
2850
+ flutterPlatformViewsController->OnMethodCall (
2851
+ [FlutterMethodCall
2852
+ methodCallWithMethodName: @" create"
2853
+ arguments: @{@" id" : @1 , @" viewType" : @" MockFlutterPlatformView" }],
2854
+ result);
2855
+ UIView* view1 = gMockPlatformView ;
2856
+
2857
+ // This overwrites `gMockPlatformView` to another view.
2858
+ flutterPlatformViewsController->OnMethodCall (
2859
+ [FlutterMethodCall
2860
+ methodCallWithMethodName: @" create"
2861
+ arguments: @{@" id" : @2 , @" viewType" : @" MockFlutterPlatformView" }],
2862
+ result);
2863
+ UIView* view2 = gMockPlatformView ;
2864
+
2865
+ XCTAssertNotNil (gMockPlatformView );
2866
+ UIView* mockFlutterView = [[[UIView alloc ] initWithFrame: CGRectMake (0 , 0 , 10 , 10 )] autorelease ];
2867
+ flutterPlatformViewsController->SetFlutterView (mockFlutterView);
2868
+ // Create embedded view params
2869
+ flutter::MutatorsStack stack1;
2870
+ // Layer tree always pushes a screen scale factor to the stack
2871
+ SkMatrix screenScaleMatrix =
2872
+ SkMatrix::Scale ([UIScreen mainScreen ].scale , [UIScreen mainScreen ].scale );
2873
+ stack1.PushTransform (screenScaleMatrix);
2874
+ // Push a clip rect
2875
+ SkRect rect = SkRect::MakeXYWH (2 , 2 , 3 , 3 );
2876
+ stack1.PushClipRect (rect);
2877
+
2878
+ auto embeddedViewParams1 = std::make_unique<flutter::EmbeddedViewParams>(
2879
+ screenScaleMatrix, SkSize::Make (10 , 10 ), stack1);
2880
+
2881
+ flutter::MutatorsStack stack2;
2882
+ stack2.PushClipRect (rect);
2883
+ auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
2884
+ screenScaleMatrix, SkSize::Make (10 , 10 ), stack2);
2885
+
2886
+ flutterPlatformViewsController->PrerollCompositeEmbeddedView (1 , std::move (embeddedViewParams1));
2887
+ flutterPlatformViewsController->CompositeEmbeddedView (1 );
2888
+ UIView* childClippingView1 = view1.superview .superview ;
2889
+
2890
+ flutterPlatformViewsController->PrerollCompositeEmbeddedView (2 , std::move (embeddedViewParams2));
2891
+ flutterPlatformViewsController->CompositeEmbeddedView (2 );
2892
+ UIView* childClippingView2 = view2.superview .superview ;
2893
+ UIView* maskView1 = childClippingView1.maskView ;
2894
+ UIView* maskView2 = childClippingView2.maskView ;
2895
+ XCTAssertNotEqual (maskView1, maskView2);
2896
+ }
2897
+
2822
2898
// Return true if a correct visual effect view is found. It also implies all the validation in this
2823
2899
// method passes.
2824
2900
//
0 commit comments