Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b9aa2b7

Browse files
authored
Made sure not to turn on wide gamut support without impeller. (#41460)
fixes flutter/flutter#125430 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 54f96b2 commit b9aa2b7

File tree

6 files changed

+48
-15
lines changed

6 files changed

+48
-15
lines changed

shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,4 +439,8 @@ - (BOOL)isWideGamutEnabled {
439439
return _settings.enable_wide_gamut;
440440
}
441441

442+
- (BOOL)isImpellerEnabled {
443+
return _settings.enable_impeller;
444+
}
445+
442446
@end

shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ flutter::Settings FLTDefaultSettingsForBundle(NSBundle* _Nullable bundle = nil,
2020
@interface FlutterDartProject ()
2121

2222
@property(nonatomic, readonly) BOOL isWideGamutEnabled;
23+
@property(nonatomic, readonly) BOOL isImpellerEnabled;
2324

2425
/**
2526
* This is currently used for *only for tests* to override settings.

shell/platform/darwin/ios/framework/Source/FlutterEngine.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,10 @@ - (FlutterDartProject*)project {
14021402
return _dartProject.get();
14031403
}
14041404

1405+
- (BOOL)isUsingImpeller {
1406+
return self.project.isImpellerEnabled;
1407+
}
1408+
14051409
@end
14061410

14071411
@implementation FlutterEngineRegistrar {

shell/platform/darwin/ios/framework/Source/FlutterView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
@protocol FlutterViewEngineDelegate <NSObject>
1919

20+
@property(nonatomic, readonly) BOOL isUsingImpeller;
21+
2022
- (flutter::Rasterizer::Screenshot)takeScreenshot:(flutter::Rasterizer::ScreenshotType)type
2123
asBase64Encoded:(BOOL)base64Encode;
2224

shell/platform/darwin/ios/framework/Source/FlutterView.mm

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@
1616
#import "flutter/shell/platform/darwin/ios/ios_surface_software.h"
1717
#include "third_party/skia/include/utils/mac/SkCGUtils.h"
1818

19-
static BOOL IsWideGamutSupported() {
20-
#if TARGET_OS_SIMULATOR
21-
// As of Xcode 14.1, the wide gamut surface pixel formats are not supported by
22-
// the simulator.
23-
return NO;
24-
#else
25-
// This predicates the decision on the capabilities of the iOS device's
26-
// display. This means external displays will not support wide gamut if the
27-
// device's display doesn't support it. It practice that should be never.
28-
return UIScreen.mainScreen.traitCollection.displayGamut != UIDisplayGamutSRGB;
29-
#endif
30-
}
31-
3219
@implementation FlutterView {
3320
id<FlutterViewEngineDelegate> _delegate;
3421
BOOL _isWideGamutEnabled;
@@ -49,6 +36,30 @@ - (instancetype)initWithCoder:(NSCoder*)aDecoder {
4936
return nil;
5037
}
5138

39+
- (UIScreen*)screen {
40+
if (@available(iOS 13.0, *)) {
41+
return self.window.windowScene.screen;
42+
}
43+
return UIScreen.mainScreen;
44+
}
45+
46+
- (BOOL)isWideGamutSupported {
47+
#if TARGET_OS_SIMULATOR
48+
// As of Xcode 14.1, the wide gamut surface pixel formats are not supported by
49+
// the simulator.
50+
return NO;
51+
#endif
52+
53+
if (![_delegate isUsingImpeller]) {
54+
return NO;
55+
}
56+
57+
// This predicates the decision on the capabilities of the iOS device's
58+
// display. This means external displays will not support wide gamut if the
59+
// device's display doesn't support it. It practice that should be never.
60+
return self.screen.traitCollection.displayGamut != UIDisplayGamutSRGB;
61+
}
62+
5263
- (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)delegate
5364
opaque:(BOOL)opaque
5465
enableWideGamut:(BOOL)isWideGamutEnabled {
@@ -63,7 +74,7 @@ - (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)delegate
6374
if (self) {
6475
_delegate = delegate;
6576
_isWideGamutEnabled = isWideGamutEnabled;
66-
if (_isWideGamutEnabled && !IsWideGamutSupported()) {
77+
if (_isWideGamutEnabled && self.isWideGamutSupported) {
6778
FML_DLOG(WARNING) << "Rendering wide gamut colors is turned on but isn't "
6879
"supported, downgrading the color gamut to sRGB.";
6980
}
@@ -92,7 +103,7 @@ - (void)layoutSubviews {
92103
layer.contentsScale = screenScale;
93104
layer.rasterizationScale = screenScale;
94105
layer.framebufferOnly = flutter::Settings::kSurfaceDataAccessible ? NO : YES;
95-
if (_isWideGamutEnabled && IsWideGamutSupported()) {
106+
if (_isWideGamutEnabled && self.isWideGamutSupported) {
96107
CGColorSpaceRef srgb = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
97108
layer.colorspace = srgb;
98109
CFRelease(srgb);

shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
@interface FakeDelegate : NSObject <FlutterViewEngineDelegate>
1111
@property(nonatomic) BOOL callbackCalled;
12+
@property(nonatomic, assign) BOOL isUsingImpeller;
1213
@end
1314

1415
@implementation FakeDelegate {
@@ -55,4 +56,14 @@ - (void)testFlutterViewBackgroundColorIsNotNil {
5556
XCTAssertNotNil(view.backgroundColor);
5657
}
5758

59+
- (void)testIgnoreWideColorWithoutImpeller {
60+
FakeDelegate* delegate = [[FakeDelegate alloc] init];
61+
delegate.isUsingImpeller = NO;
62+
FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate opaque:NO enableWideGamut:YES];
63+
[view layoutSubviews];
64+
XCTAssertTrue([view.layer isKindOfClass:NSClassFromString(@"CAMetalLayer")]);
65+
CAMetalLayer* layer = (CAMetalLayer*)view.layer;
66+
XCTAssertEqual(layer.pixelFormat, MTLPixelFormatBGRA8Unorm);
67+
}
68+
5869
@end

0 commit comments

Comments
 (0)