Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,8 @@ - (BOOL)isWideGamutEnabled {
return _settings.enable_wide_gamut;
}

- (BOOL)isImpellerEnabled {
return _settings.enable_impeller;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,10 @@ - (FlutterDartProject*)project {
return _dartProject.get();
}

- (BOOL)isUsingImpeller {
return self.project.isImpellerEnabled;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is available via the shell, but there's nothing inherently wrong with exposing it on the project either.

}

@end

@implementation FlutterEngineRegistrar {
Expand Down
2 changes: 2 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterView.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

@protocol FlutterViewEngineDelegate <NSObject>

@property(nonatomic, readonly) BOOL isUsingImpeller;

- (flutter::Rasterizer::Screenshot)takeScreenshot:(flutter::Rasterizer::ScreenshotType)type
asBase64Encoded:(BOOL)base64Encode;

Expand Down
41 changes: 26 additions & 15 deletions shell/platform/darwin/ios/framework/Source/FlutterView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<FlutterViewEngineDelegate> _delegate;
BOOL _isWideGamutEnabled;
Expand All @@ -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<FlutterViewEngineDelegate>)delegate
opaque:(BOOL)opaque
enableWideGamut:(BOOL)isWideGamutEnabled {
Expand All @@ -63,7 +74,7 @@ - (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)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.";
}
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

@interface FakeDelegate : NSObject <FlutterViewEngineDelegate>
@property(nonatomic) BOOL callbackCalled;
@property(nonatomic, assign) BOOL isUsingImpeller;
@end

@implementation FakeDelegate {
Expand Down Expand Up @@ -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