Skip to content

Commit

Permalink
Made the warning about downgrading wide gamut happen at the correct t…
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke authored Sep 19, 2023
1 parent 7c6032d commit 3171f20
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions shell/platform/darwin/ios/framework/Source/FlutterView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -68,10 +70,6 @@ - (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)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
Expand All @@ -84,6 +82,16 @@ - (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)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
Expand All @@ -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);
Expand All @@ -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();
}
}

Expand Down

0 comments on commit 3171f20

Please sign in to comment.