diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/shell/platform/darwin/ios/framework/Source/FlutterView.mm index daef8b2ab30d3..f5d5b091e9b21 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -72,13 +72,18 @@ - (instancetype)initWithDelegate:(id)delegate FML_DLOG(WARNING) << "Rendering wide gamut colors is turned on but isn't " "supported, downgrading the color gamut to sRGB."; } - self.layer.opaque = opaque; // This line is necessary. CoreAnimation(or UIKit) may take this to do // something to compute the final frame presented on screen, if we don't set this, // it will make it take long time for us to take next CAMetalDrawable and will - // cause constant junk during rendering. + // cause constant junk during rendering. Note: setting any background color will + // disable opaque, which on full screen flutter apps removes the direct to display + // optimization. This can increase presentation time by a frame interval, which + // is problematic on high frame rate devices. self.backgroundColor = UIColor.clearColor; + // Make sure to set this value after backgroundColor above, otherwise it will + // reset the value of opaque. + self.layer.opaque = opaque; } return self; @@ -96,7 +101,7 @@ - (void)layoutSubviews { layer.allowsGroupOpacity = YES; layer.contentsScale = screenScale; layer.rasterizationScale = screenScale; - layer.framebufferOnly = flutter::Settings::kSurfaceDataAccessible ? NO : YES; + layer.framebufferOnly = NO; if (_isWideGamutEnabled && self.isWideGamutSupported) { CGColorSpaceRef srgb = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB); layer.colorspace = srgb; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm index 78f95210e37e6..372f9f14aa949 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm @@ -69,4 +69,26 @@ - (void)testIgnoreWideColorWithoutImpeller { XCTAssertEqual(layer.pixelFormat, MTLPixelFormatBGRA8Unorm); } +- (void)testLayerOpacityIsPreservedYes { + FakeDelegate* delegate = [[[FakeDelegate alloc] init] autorelease]; + FlutterView* view = [[[FlutterView alloc] initWithDelegate:delegate opaque:YES + enableWideGamut:NO] autorelease]; + + XCTAssertTrue(view.layer.opaque); + CGColor* bgColor = view.layer.backgroundColor; + CGColor* expectedColor = [UIColor.clearColor CGColor]; + XCTAssertEqual(bgColor, expectedColor); +} + +- (void)testLayerOpacityIsPreservedNo { + FakeDelegate* delegate = [[[FakeDelegate alloc] init] autorelease]; + FlutterView* view = [[[FlutterView alloc] initWithDelegate:delegate opaque:NO + enableWideGamut:NO] autorelease]; + + XCTAssertFalse(view.layer.opaque); + CGColor* bgColor = view.layer.backgroundColor; + CGColor* expectedColor = [UIColor.clearColor CGColor]; + XCTAssertEqual(bgColor, expectedColor); +} + @end