diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index efac6ae54f..7cd80bdab5 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -249,6 +249,10 @@ static BOOL _preparedOnce = NO; CGRect rectSoFar_; } +- (instancetype)initWithFrame:(CGRect)frame { + return [self initWithFrame:frame screenScale:[UIScreen mainScreen].scale]; +} + - (instancetype)initWithFrame:(CGRect)frame screenScale:(CGFloat)screenScale { if (self = [super initWithFrame:frame]) { self.backgroundColor = UIColor.clearColor; @@ -463,11 +467,12 @@ static BOOL _preparedOnce = NO; return self; } -- (FlutterClippingMaskView*)getMaskViewWithFrame:(CGRect)frame screenScale:(CGFloat)screenScale { +- (FlutterClippingMaskView*)getMaskViewWithFrame:(CGRect)frame { FML_DCHECK(self.pool.count <= self.capacity); if (self.pool.count == 0) { // The pool is empty, alloc a new one. - return [[FlutterClippingMaskView alloc] initWithFrame:frame screenScale:screenScale]; + return [[FlutterClippingMaskView alloc] initWithFrame:frame + screenScale:UIScreen.mainScreen.scale]; } FlutterClippingMaskView* maskView = [self.pool anyObject]; maskView.frame = frame; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.mm index c6710fe5d8..20e3b15bf3 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.mm @@ -12,7 +12,6 @@ #include "flutter/fml/synchronization/count_down_latch.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h" -#import "flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h" #include "flutter/shell/platform/darwin/ios/framework/Source/overlay_layer_pool.h" #import "flutter/shell/platform/darwin/ios/ios_surface.h" @@ -209,8 +208,7 @@ static CGRect GetCGRectFromDlRect(const DlRect& clipDlRect) { /// Runs on the platform thread. - (void)createLayerWithIosContext:(const std::shared_ptr&)iosContext - pixelFormat:(MTLPixelFormat)pixelFormat - screenScale:(CGFloat)screenScale; + pixelFormat:(MTLPixelFormat)pixelFormat; /// Removes overlay views and platform views that aren't needed in the current frame. /// Must run on the platform thread. @@ -484,9 +482,7 @@ static CGRect GetCGRectFromDlRect(const DlRect& clipDlRect) { CGRect frame = CGRectMake(-clipView.frame.origin.x, -clipView.frame.origin.y, CGRectGetWidth(self.flutterView.bounds), CGRectGetHeight(self.flutterView.bounds)); - clipView.maskView = [self.maskViewPool - getMaskViewWithFrame:frame - screenScale:[self.flutterViewController flutterScreenIfViewLoaded].scale]; + clipView.maskView = [self.maskViewPool getMaskViewWithFrame:frame]; } - (void)applyMutators:(const flutter::MutatorsStack&)mutatorsStack @@ -508,7 +504,7 @@ static CGRect GetCGRectFromDlRect(const DlRect& clipDlRect) { [self.maskViewPool insertViewToPoolIfNeeded:(FlutterClippingMaskView*)(clipView.maskView)]; clipView.maskView = nil; } - CGFloat screenScale = [self.flutterViewController flutterScreenIfViewLoaded].scale; + CGFloat screenScale = [UIScreen mainScreen].scale; auto iter = mutatorsStack.Begin(); while (iter != mutatorsStack.End()) { switch ((*iter)->GetType()) { @@ -636,7 +632,7 @@ static CGRect GetCGRectFromDlRect(const DlRect& clipDlRect) { // when we apply the transforms matrix in |applyMutators:embeddedView:boundingRect|, we need // to remember to do a reverse translate. const SkRect& rect = params.finalBoundingRect(); - CGFloat screenScale = [self.flutterViewController flutterScreenIfViewLoaded].scale; + CGFloat screenScale = [UIScreen mainScreen].scale; clippingView.frame = CGRectMake(rect.x() / screenScale, rect.y() / screenScale, rect.width() / screenScale, rect.height() / screenScale); [self applyMutators:mutatorStack embeddedView:touchInterceptor boundingRect:rect]; @@ -796,8 +792,7 @@ static CGRect GetCGRectFromDlRect(const DlRect& clipDlRect) { self.platformTaskRunner, [self, missingLayerCount, iosContext, latch]() { for (auto i = 0u; i < missingLayerCount; i++) { [self createLayerWithIosContext:iosContext - pixelFormat:((FlutterView*)self.flutterView).pixelFormat - screenScale:((FlutterView*)self.flutterView).screen.scale]; + pixelFormat:((FlutterView*)self.flutterView).pixelFormat]; } latch->CountDown(); }); @@ -901,9 +896,8 @@ static CGRect GetCGRectFromDlRect(const DlRect& clipDlRect) { } - (void)createLayerWithIosContext:(const std::shared_ptr&)iosContext - pixelFormat:(MTLPixelFormat)pixelFormat - screenScale:(CGFloat)screenScale { - self.layerPool->CreateLayer(iosContext, pixelFormat, screenScale); + pixelFormat:(MTLPixelFormat)pixelFormat { + self.layerPool->CreateLayer(iosContext, pixelFormat); } - (void)removeUnusedLayers:(const std::vector>&)unusedLayers diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 6299474ff4..4c781e60de 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -16,7 +16,6 @@ #include "flutter/fml/thread.h" #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h" -#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h" @@ -235,24 +234,6 @@ const float kFloatCompareEpsilon = 0.001; } @end -@interface FlutterPlatformViewsTestMockFlutterViewController : FlutterViewController - -- (UIScreen*)flutterScreenIfViewLoaded; - -@end - -@implementation FlutterPlatformViewsTestMockFlutterViewController - -- (UIScreen*)flutterScreenIfViewLoaded { - UIScreen* mockScreen = OCMClassMock([UIScreen class]); - CGFloat screenScale = 3; - OCMStub([mockScreen scale]).andReturn(screenScale); - - return mockScreen; -} - -@end - namespace flutter { namespace { class FlutterPlatformViewsTestMockPlatformViewDelegate : public PlatformView::Delegate { @@ -348,15 +329,12 @@ fml::RefPtr GetDefaultTaskRunner() { @"viewType" : @"MockFlutterPlatformView" }] result:result]; - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a translate matrix @@ -507,15 +485,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a backdrop filter @@ -592,15 +567,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a backdrop filter @@ -677,15 +649,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push backdrop filters @@ -763,15 +732,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a backdrop filter @@ -895,15 +861,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push backdrop filters @@ -1054,15 +1017,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push backdrop filters @@ -1361,15 +1321,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a dilate backdrop filter @@ -1695,15 +1652,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a translate matrix @@ -1762,15 +1716,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); @@ -1873,15 +1824,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a rotate matrix @@ -1954,15 +1902,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params. flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack. - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); flutter::DlMatrix translateMatrix = flutter::DlMatrix::MakeTranslation({5, 5}); @@ -2033,15 +1978,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack. - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); flutter::DlMatrix translateMatrix = flutter::DlMatrix::MakeTranslation({5, 5}); @@ -2111,15 +2053,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a clip rect @@ -2194,15 +2133,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a clip rect @@ -2297,15 +2233,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a clip rrect @@ -2408,15 +2341,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a clip rrect @@ -2536,15 +2466,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a clip path @@ -2647,15 +2574,12 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a clip path @@ -3501,10 +3425,6 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; - // Create embedded view params flutter::MutatorsStack stack; flutter::DlMatrix finalMatrix; @@ -3622,9 +3542,6 @@ fml::RefPtr GetDefaultTaskRunner() { /*worker_task_runner=*/nil, /*is_gpu_disabled_jsync_switch=*/std::make_shared()); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; flutterPlatformViewsController.flutterView = flutterView; @@ -3694,9 +3611,6 @@ fml::RefPtr GetDefaultTaskRunner() { /*worker_task_runner=*/nil, /*is_gpu_disabled_jsync_switch=*/std::make_shared()); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; flutterPlatformViewsController.flutterView = flutterView; @@ -3804,9 +3718,6 @@ fml::RefPtr GetDefaultTaskRunner() { /*worker_task_runner=*/nil, /*is_gpu_disabled_jsync_switch=*/std::make_shared()); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; flutterPlatformViewsController.flutterView = flutterView; @@ -3945,13 +3856,13 @@ fml::RefPtr GetDefaultTaskRunner() { - (void)testFlutterClippingMaskViewPoolReuseViewsAfterRecycle { FlutterClippingMaskViewPool* pool = [[FlutterClippingMaskViewPool alloc] initWithCapacity:2]; - FlutterClippingMaskView* view1 = [pool getMaskViewWithFrame:CGRectZero screenScale:1]; - FlutterClippingMaskView* view2 = [pool getMaskViewWithFrame:CGRectZero screenScale:1]; + FlutterClippingMaskView* view1 = [pool getMaskViewWithFrame:CGRectZero]; + FlutterClippingMaskView* view2 = [pool getMaskViewWithFrame:CGRectZero]; [pool insertViewToPoolIfNeeded:view1]; [pool insertViewToPoolIfNeeded:view2]; CGRect newRect = CGRectMake(0, 0, 10, 10); - FlutterClippingMaskView* view3 = [pool getMaskViewWithFrame:newRect screenScale:1]; - FlutterClippingMaskView* view4 = [pool getMaskViewWithFrame:newRect screenScale:1]; + FlutterClippingMaskView* view3 = [pool getMaskViewWithFrame:newRect]; + FlutterClippingMaskView* view4 = [pool getMaskViewWithFrame:newRect]; // view3 and view4 should randomly get either of view1 and view2. NSSet* set1 = [NSSet setWithObjects:view1, view2, nil]; NSSet* set2 = [NSSet setWithObjects:view3, view4, nil]; @@ -3962,9 +3873,9 @@ fml::RefPtr GetDefaultTaskRunner() { - (void)testFlutterClippingMaskViewPoolAllocsNewMaskViewsAfterReachingCapacity { FlutterClippingMaskViewPool* pool = [[FlutterClippingMaskViewPool alloc] initWithCapacity:2]; - FlutterClippingMaskView* view1 = [pool getMaskViewWithFrame:CGRectZero screenScale:1]; - FlutterClippingMaskView* view2 = [pool getMaskViewWithFrame:CGRectZero screenScale:1]; - FlutterClippingMaskView* view3 = [pool getMaskViewWithFrame:CGRectZero screenScale:1]; + FlutterClippingMaskView* view1 = [pool getMaskViewWithFrame:CGRectZero]; + FlutterClippingMaskView* view2 = [pool getMaskViewWithFrame:CGRectZero]; + FlutterClippingMaskView* view3 = [pool getMaskViewWithFrame:CGRectZero]; XCTAssertNotEqual(view1, view3); XCTAssertNotEqual(view2, view3); } @@ -3973,7 +3884,7 @@ fml::RefPtr GetDefaultTaskRunner() { __weak UIView* weakView; @autoreleasepool { FlutterClippingMaskViewPool* pool = [[FlutterClippingMaskViewPool alloc] initWithCapacity:2]; - FlutterClippingMaskView* view = [pool getMaskViewWithFrame:CGRectZero screenScale:1]; + FlutterClippingMaskView* view = [pool getMaskViewWithFrame:CGRectZero]; weakView = view; XCTAssertNotNil(weakView); } @@ -4016,15 +3927,12 @@ fml::RefPtr GetDefaultTaskRunner() { result:result]; XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack1; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack1.PushTransform(screenScaleMatrix); // Push a clip rect @@ -4132,15 +4040,12 @@ fml::RefPtr GetDefaultTaskRunner() { UIView* view2 = gMockPlatformView; XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack1; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack1.PushTransform(screenScaleMatrix); // Push a clip rect @@ -4212,15 +4117,12 @@ fml::RefPtr GetDefaultTaskRunner() { result:result]; XCTAssertNotNil(gMockPlatformView); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack1; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack1.PushTransform(screenScaleMatrix); // Push a clip rect @@ -4294,9 +4196,6 @@ fml::RefPtr GetDefaultTaskRunner() { /*worker_task_runner=*/nil, /*is_gpu_disabled_jsync_switch=*/std::make_shared()); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; flutterPlatformViewsController.flutterView = flutterView; @@ -4430,15 +4329,12 @@ fml::RefPtr GetDefaultTaskRunner() { @"viewType" : @"MockFlutterPlatformView" }] result:result]; - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a translate matrix @@ -4503,15 +4399,12 @@ fml::RefPtr GetDefaultTaskRunner() { @"viewType" : @"MockFlutterPlatformView" }] result:result]; - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a translate matrix @@ -4578,16 +4471,13 @@ fml::RefPtr GetDefaultTaskRunner() { @"viewType" : @"MockFlutterPlatformView" }] result:result]; - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; flutterPlatformViewsController.flutterView = flutterView; // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack - flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale; + flutter::DlScalar screenScale = [UIScreen mainScreen].scale; flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1}); stack.PushTransform(screenScaleMatrix); // Push a translate matrix @@ -4625,14 +4515,14 @@ fml::RefPtr GetDefaultTaskRunner() { FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"foobar"]; [engine run]; XCTAssertTrue(engine.platformView != nullptr); - std::shared_ptr ios_context = engine.platformView->GetIosContext(); + auto ios_context = engine.platformView->GetIosContext(); - flutter::OverlayLayerPool pool; + auto pool = flutter::OverlayLayerPool{}; // Add layers to the pool. - pool.CreateLayer(ios_context, MTLPixelFormatBGRA8Unorm, 1); + pool.CreateLayer(ios_context, MTLPixelFormatBGRA8Unorm); XCTAssertEqual(pool.size(), 1u); - pool.CreateLayer(ios_context, MTLPixelFormatBGRA8Unorm, 1); + pool.CreateLayer(ios_context, MTLPixelFormatBGRA8Unorm); XCTAssertEqual(pool.size(), 2u); // Mark all layers as unused. @@ -4645,34 +4535,6 @@ fml::RefPtr GetDefaultTaskRunner() { XCTAssertEqual(pool.size(), 1u); } -- (void)testLayerUpdateViewStateWithNilFlutterViewShouldNotCrash { - // Create an IOSContext. - FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"foobar"]; - [engine run]; - XCTAssertTrue(engine.platformView != nullptr); - std::shared_ptr ios_context = engine.platformView->GetIosContext(); - - flutter::OverlayLayerPool pool; - - // Add layers to the pool. - pool.CreateLayer(ios_context, MTLPixelFormatBGRA8Unorm, 1); - XCTAssertEqual(pool.size(), 1u); - - std::shared_ptr layer = pool.GetNextLayer(); - - layer->UpdateViewState(nil, SkRect::MakeXYWH(1, 2, 3, 4), 0, 0); - // Should not update the view state (e.g. overlay_view_wrapper's frame) when FlutterView is nil. - XCTAssertTrue(CGRectEqualToRect(layer->overlay_view_wrapper.frame, CGRectZero)); - - FlutterView* flutterView = [[FlutterView alloc] initWithDelegate:engine - opaque:YES - enableWideGamut:NO]; - layer->UpdateViewState(flutterView, SkRect::MakeXYWH(1, 2, 3, 4), 0, 0); - // Should not update the view state (e.g. overlay_view_wrapper's frame) when FlutterView's screen - // is nil. - XCTAssertTrue(CGRectEqualToRect(layer->overlay_view_wrapper.frame, CGRectZero)); -} - - (void)testFlutterPlatformViewControllerSubmitFramePreservingFrameDamage { flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; @@ -4692,9 +4554,6 @@ fml::RefPtr GetDefaultTaskRunner() { /*worker_task_runner=*/nil, /*is_gpu_disabled_jsync_switch=*/std::make_shared()); - FlutterPlatformViewsTestMockFlutterViewController* mockFlutterViewController = - [[FlutterPlatformViewsTestMockFlutterViewController alloc] init]; - flutterPlatformViewsController.flutterViewController = mockFlutterViewController; UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; flutterPlatformViewsController.flutterView = flutterView; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 6d8bfed936..be0a92cbe8 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -66,7 +66,7 @@ - (instancetype)initWithCapacity:(NSInteger)capacity; // Reuse a maskView from the pool, or allocate a new one. -- (FlutterClippingMaskView*)getMaskViewWithFrame:(CGRect)frame screenScale:(CGFloat)screenScale; +- (FlutterClippingMaskView*)getMaskViewWithFrame:(CGRect)frame; // Insert the `maskView` into the pool. - (void)insertViewToPoolIfNeeded:(FlutterClippingMaskView*)maskView; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/overlay_layer_pool.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/overlay_layer_pool.h index 7f35880faf..8e734e3ec7 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/overlay_layer_pool.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/overlay_layer_pool.h @@ -58,9 +58,7 @@ class OverlayLayerPool { /// @brief Create a new overlay layer. /// /// This method can only be called on the Platform thread. - void CreateLayer(const std::shared_ptr& ios_context, - MTLPixelFormat pixel_format, - CGFloat screenScale); + void CreateLayer(const std::shared_ptr& ios_context, MTLPixelFormat pixel_format); /// @brief Removes unused layers from the pool. Returns the unused layers. std::vector> RemoveUnusedLayers(); diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/overlay_layer_pool.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/overlay_layer_pool.mm index 7e12cfbbf3..a413ab49e7 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/overlay_layer_pool.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/overlay_layer_pool.mm @@ -5,7 +5,6 @@ #include "flutter/shell/platform/darwin/ios/framework/Source/overlay_layer_pool.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h" -#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h" #import "flutter/shell/platform/darwin/ios/ios_surface.h" namespace flutter { @@ -23,15 +22,7 @@ void OverlayLayer::UpdateViewState(UIView* flutter_view, SkRect rect, int64_t view_id, int64_t overlay_id) { - FlutterView* flutterView = (FlutterView*)flutter_view; - // There can be a race where UpdateViewState() is called when flutter_view or flutter_view's - // screen is nil when app is backgrounded. - // It's unlikely for scale to be 0, but just to be safe here since it's used in a scaling - // calculation division below - if (!flutterView || !flutterView.screen || flutterView.screen.scale == 0.0f) { - return; - } - CGFloat screenScale = flutterView.screen.scale; + auto screenScale = [UIScreen mainScreen].scale; // Set the size of the overlay view wrapper. // This wrapper view masks the overlay view. overlay_view_wrapper.frame = CGRectMake(rect.x() / screenScale, rect.y() / screenScale, @@ -62,13 +53,13 @@ std::shared_ptr OverlayLayerPool::GetNextLayer() { } void OverlayLayerPool::CreateLayer(const std::shared_ptr& ios_context, - MTLPixelFormat pixel_format, - CGFloat screenScale) { + MTLPixelFormat pixel_format) { FML_DCHECK([[NSThread currentThread] isMainThread]); std::shared_ptr layer; UIView* overlay_view; UIView* overlay_view_wrapper; + CGFloat screenScale = [UIScreen mainScreen].scale; overlay_view = [[FlutterOverlayView alloc] initWithContentsScale:screenScale pixelFormat:pixel_format]; overlay_view_wrapper = [[FlutterOverlayView alloc] initWithContentsScale:screenScale @@ -80,6 +71,7 @@ void OverlayLayerPool::CreateLayer(const std::shared_ptr& ios_contex layer = std::make_shared(overlay_view, overlay_view_wrapper, std::move(ios_surface), std::move(surface)); + // The overlay view wrapper masks the overlay view. // This is required to keep the backing surface size unchanged between frames. //