diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index a9bbe4fa7bda9..a12f4651a2a9b 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -439,4 +439,8 @@ - (BOOL)isWideGamutEnabled { return _settings.enable_wide_gamut; } +- (BOOL)isImpellerEnabled { + return _settings.enable_impeller; +} + @end diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h index 3888a785eb421..5501cdc1cfb9c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h @@ -20,6 +20,7 @@ flutter::Settings FLTDefaultSettingsForBundle(NSBundle* _Nullable bundle = nil, @interface FlutterDartProject () @property(nonatomic, readonly) BOOL isWideGamutEnabled; +@property(nonatomic, readonly) BOOL isImpellerEnabled; /** * This is currently used for *only for tests* to override settings. diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index f434b9305bc11..10b87e099a50b 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -1402,6 +1402,10 @@ - (FlutterDartProject*)project { return _dartProject.get(); } +- (BOOL)isUsingImpeller { + return self.project.isImpellerEnabled; +} + @end @implementation FlutterEngineRegistrar { diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.h b/shell/platform/darwin/ios/framework/Source/FlutterView.h index 2f5e26d7d402b..0dd9f610b9d4c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.h @@ -17,6 +17,8 @@ @protocol FlutterViewEngineDelegate +@property(nonatomic, readonly) BOOL isUsingImpeller; + - (flutter::Rasterizer::Screenshot)takeScreenshot:(flutter::Rasterizer::ScreenshotType)type asBase64Encoded:(BOOL)base64Encode; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/shell/platform/darwin/ios/framework/Source/FlutterView.mm index aa95fb844591d..ae9fbffe14817 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -16,19 +16,6 @@ #import "flutter/shell/platform/darwin/ios/ios_surface_software.h" #include "third_party/skia/include/utils/mac/SkCGUtils.h" -static BOOL IsWideGamutSupported() { -#if TARGET_OS_SIMULATOR - // As of Xcode 14.1, the wide gamut surface pixel formats are not supported by - // the simulator. - return NO; -#else - // This predicates the decision on the capabilities of the iOS device's - // display. This means external displays will not support wide gamut if the - // device's display doesn't support it. It practice that should be never. - return UIScreen.mainScreen.traitCollection.displayGamut != UIDisplayGamutSRGB; -#endif -} - @implementation FlutterView { id _delegate; BOOL _isWideGamutEnabled; @@ -49,6 +36,30 @@ - (instancetype)initWithCoder:(NSCoder*)aDecoder { return nil; } +- (UIScreen*)screen { + if (@available(iOS 13.0, *)) { + return self.window.windowScene.screen; + } + return UIScreen.mainScreen; +} + +- (BOOL)isWideGamutSupported { +#if TARGET_OS_SIMULATOR + // As of Xcode 14.1, the wide gamut surface pixel formats are not supported by + // the simulator. + return NO; +#endif + + if (![_delegate isUsingImpeller]) { + return NO; + } + + // This predicates the decision on the capabilities of the iOS device's + // display. This means external displays will not support wide gamut if the + // device's display doesn't support it. It practice that should be never. + return self.screen.traitCollection.displayGamut != UIDisplayGamutSRGB; +} + - (instancetype)initWithDelegate:(id)delegate opaque:(BOOL)opaque enableWideGamut:(BOOL)isWideGamutEnabled { @@ -63,7 +74,7 @@ - (instancetype)initWithDelegate:(id)delegate if (self) { _delegate = delegate; _isWideGamutEnabled = isWideGamutEnabled; - if (_isWideGamutEnabled && !IsWideGamutSupported()) { + if (_isWideGamutEnabled && self.isWideGamutSupported) { FML_DLOG(WARNING) << "Rendering wide gamut colors is turned on but isn't " "supported, downgrading the color gamut to sRGB."; } @@ -92,7 +103,7 @@ - (void)layoutSubviews { layer.contentsScale = screenScale; layer.rasterizationScale = screenScale; layer.framebufferOnly = flutter::Settings::kSurfaceDataAccessible ? NO : YES; - if (_isWideGamutEnabled && IsWideGamutSupported()) { + if (_isWideGamutEnabled && self.isWideGamutSupported) { CGColorSpaceRef srgb = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB); layer.colorspace = srgb; CFRelease(srgb); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm index ed694afe85edf..23d9b2dc527e6 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm @@ -9,6 +9,7 @@ @interface FakeDelegate : NSObject @property(nonatomic) BOOL callbackCalled; +@property(nonatomic, assign) BOOL isUsingImpeller; @end @implementation FakeDelegate { @@ -55,4 +56,14 @@ - (void)testFlutterViewBackgroundColorIsNotNil { XCTAssertNotNil(view.backgroundColor); } +- (void)testIgnoreWideColorWithoutImpeller { + FakeDelegate* delegate = [[FakeDelegate alloc] init]; + delegate.isUsingImpeller = NO; + FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate opaque:NO enableWideGamut:YES]; + [view layoutSubviews]; + XCTAssertTrue([view.layer isKindOfClass:NSClassFromString(@"CAMetalLayer")]); + CAMetalLayer* layer = (CAMetalLayer*)view.layer; + XCTAssertEqual(layer.pixelFormat, MTLPixelFormatBGRA8Unorm); +} + @end