diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/shell/platform/darwin/ios/framework/Source/FlutterView.mm index daef8b2ab30d3..8da6ef72660ed 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -48,6 +48,8 @@ - (BOOL)isWideGamutSupported { return NO; } + FML_DCHECK(self.screen); + // 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. @@ -68,10 +70,6 @@ - (instancetype)initWithDelegate:(id)delegate if (self) { _delegate = delegate; _isWideGamutEnabled = isWideGamutEnabled; - if (_isWideGamutEnabled && !self.isWideGamutSupported) { - 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 @@ -84,6 +82,16 @@ - (instancetype)initWithDelegate:(id)delegate return self; } +static void PrintWideGamutWarningOnce() { + static BOOL did_print = NO; + if (did_print) { + return; + } + FML_DLOG(WARNING) << "Rendering wide gamut colors is turned on but isn't " + "supported, downgrading the color gamut to sRGB."; + did_print = YES; +} + - (void)layoutSubviews { if ([self.layer isKindOfClass:NSClassFromString(@"CAMetalLayer")]) { // It is a known Apple bug that CAMetalLayer incorrectly reports its supported @@ -97,7 +105,8 @@ - (void)layoutSubviews { layer.contentsScale = screenScale; layer.rasterizationScale = screenScale; layer.framebufferOnly = flutter::Settings::kSurfaceDataAccessible ? NO : YES; - if (_isWideGamutEnabled && self.isWideGamutSupported) { + BOOL isWideGamutSupported = self.isWideGamutSupported; + if (_isWideGamutEnabled && isWideGamutSupported) { CGColorSpaceRef srgb = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB); layer.colorspace = srgb; CFRelease(srgb); @@ -106,6 +115,8 @@ - (void)layoutSubviews { // F16 was chosen over BGRA10_XR since Skia does not support decoding // BGRA10_XR. layer.pixelFormat = MTLPixelFormatRGBA16Float; + } else if (_isWideGamutEnabled && !isWideGamutSupported) { + PrintWideGamutWarningOnce(); } }