diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.h b/shell/platform/darwin/ios/framework/Source/FlutterView.h index 0dd9f610b9d4c..daebc0df5314c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.h @@ -46,6 +46,8 @@ opaque:(BOOL)opaque enableWideGamut:(BOOL)isWideGamutEnabled NS_DESIGNATED_INITIALIZER; +- (UIScreen*)screen; + // Set by FlutterEngine or FlutterViewController to override software rendering. @property(class, nonatomic) BOOL forceSoftwareRendering; @end diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/shell/platform/darwin/ios/framework/Source/FlutterView.mm index 8da6ef72660ed..dfb25224e0e2a 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -100,7 +100,7 @@ - (void)layoutSubviews { #pragma clang diagnostic ignored "-Wunguarded-availability-new" CAMetalLayer* layer = (CAMetalLayer*)self.layer; #pragma clang diagnostic pop - CGFloat screenScale = [UIScreen mainScreen].scale; + CGFloat screenScale = self.screen.scale; layer.allowsGroupOpacity = YES; layer.contentsScale = screenScale; layer.rasterizationScale = screenScale; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm index 78f95210e37e6..b5a0c1002961a 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm @@ -69,4 +69,17 @@ - (void)testIgnoreWideColorWithoutImpeller { XCTAssertEqual(layer.pixelFormat, MTLPixelFormatBGRA8Unorm); } +- (void)testLayerScalesMatchScreenAfterLayoutSubviews { + FakeDelegate* delegate = [[[FakeDelegate alloc] init] autorelease]; + FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate opaque:NO enableWideGamut:NO]; + view.layer.contentsScale = CGFloat(-99.0); + view.layer.rasterizationScale = CGFloat(-99.0); + UIScreen* screen = [view screen]; + XCTAssertNotEqual(view.layer.contentsScale, screen.scale); + XCTAssertNotEqual(view.layer.rasterizationScale, screen.scale); + [view layoutSubviews]; + XCTAssertEqual(view.layer.contentsScale, screen.scale); + XCTAssertEqual(view.layer.rasterizationScale, screen.scale); +} + @end