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

Commit 12a5d88

Browse files
gaaclarkeharryterkelsen
authored andcommitted
Made the warning about downgrading wide gamut happen at the correct time (#46064)
fixes flutter/flutter#135033 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 4f4ea9b commit 12a5d88

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ - (BOOL)isWideGamutSupported {
4848
return NO;
4949
}
5050

51+
FML_DCHECK(self.screen);
52+
5153
// This predicates the decision on the capabilities of the iOS device's
5254
// display. This means external displays will not support wide gamut if the
5355
// device's display doesn't support it. It practice that should be never.
@@ -68,10 +70,6 @@ - (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)delegate
6870
if (self) {
6971
_delegate = delegate;
7072
_isWideGamutEnabled = isWideGamutEnabled;
71-
if (_isWideGamutEnabled && !self.isWideGamutSupported) {
72-
FML_DLOG(WARNING) << "Rendering wide gamut colors is turned on but isn't "
73-
"supported, downgrading the color gamut to sRGB.";
74-
}
7573
self.layer.opaque = opaque;
7674

7775
// This line is necessary. CoreAnimation(or UIKit) may take this to do
@@ -84,6 +82,16 @@ - (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)delegate
8482
return self;
8583
}
8684

85+
static void PrintWideGamutWarningOnce() {
86+
static BOOL did_print = NO;
87+
if (did_print) {
88+
return;
89+
}
90+
FML_DLOG(WARNING) << "Rendering wide gamut colors is turned on but isn't "
91+
"supported, downgrading the color gamut to sRGB.";
92+
did_print = YES;
93+
}
94+
8795
- (void)layoutSubviews {
8896
if ([self.layer isKindOfClass:NSClassFromString(@"CAMetalLayer")]) {
8997
// It is a known Apple bug that CAMetalLayer incorrectly reports its supported
@@ -97,7 +105,8 @@ - (void)layoutSubviews {
97105
layer.contentsScale = screenScale;
98106
layer.rasterizationScale = screenScale;
99107
layer.framebufferOnly = flutter::Settings::kSurfaceDataAccessible ? NO : YES;
100-
if (_isWideGamutEnabled && self.isWideGamutSupported) {
108+
BOOL isWideGamutSupported = self.isWideGamutSupported;
109+
if (_isWideGamutEnabled && isWideGamutSupported) {
101110
CGColorSpaceRef srgb = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
102111
layer.colorspace = srgb;
103112
CFRelease(srgb);
@@ -106,6 +115,8 @@ - (void)layoutSubviews {
106115
// F16 was chosen over BGRA10_XR since Skia does not support decoding
107116
// BGRA10_XR.
108117
layer.pixelFormat = MTLPixelFormatRGBA16Float;
118+
} else if (_isWideGamutEnabled && !isWideGamutSupported) {
119+
PrintWideGamutWarningOnce();
109120
}
110121
}
111122

0 commit comments

Comments
 (0)