Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions shell/platform/darwin/ios/framework/Source/FlutterView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,18 @@ - (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)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;
Expand All @@ -96,7 +101,7 @@ - (void)layoutSubviews {
layer.allowsGroupOpacity = YES;
layer.contentsScale = screenScale;
layer.rasterizationScale = screenScale;
layer.framebufferOnly = flutter::Settings::kSurfaceDataAccessible ? NO : YES;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value should match what we set in

layer.framebufferOnly = NO;
if (_isWideGamutEnabled && self.isWideGamutSupported) {
CGColorSpaceRef srgb = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
layer.colorspace = srgb;
Expand Down
22 changes: 22 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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