From 70b4e83c3dcd29d27642d8dc6ed62062f50d193a Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Tue, 19 Sep 2023 14:45:35 -0700 Subject: [PATCH] Made the warning about downgrading wide gamut happen at the correct time (flutter/engine#46064) fixes https://github.com/flutter/flutter/issues/135033 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../ios/framework/Source/FlutterView.mm | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm index daef8b2ab30..8da6ef72660 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -48,6 +48,8 @@ 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 @@ 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 @@ 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 @@ 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 @@ // F16 was chosen over BGRA10_XR since Skia does not support decoding // BGRA10_XR. layer.pixelFormat = MTLPixelFormatRGBA16Float; + } else if (_isWideGamutEnabled && !isWideGamutSupported) { + PrintWideGamutWarningOnce(); } }