From 702f23b870da3c882275e81569d9b09988d368e3 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 19 Sep 2023 10:14:56 -0700 Subject: [PATCH] [Impeller] adds hardware check on gpu for wide gamut --- .../framework/Source/FlutterDartProject.mm | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index 3d434eb2179f2..fcaa365bcf4a6 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -8,6 +8,7 @@ #include +#import #include #include @@ -22,6 +23,8 @@ #import "flutter/shell/platform/darwin/common/command_line.h" #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h" +FLUTTER_ASSERT_NOT_ARC + extern "C" { #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG // Used for debugging dart:* sources. @@ -32,6 +35,20 @@ static const char* kApplicationKernelSnapshotFileName = "kernel_blob.bin"; +static BOOL DoesHardwareSupportsWideGamut() { + id device = MTLCreateSystemDefaultDevice(); + BOOL result; + if (@available(iOS 13.0, *)) { + // MTLGPUFamilyApple2 = A9/A10 + result = [device supportsFamily:MTLGPUFamilyApple2]; + } else { + // A9/A10 on iOS 10+ + result = [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v2]; + } + [device release]; + return result; +} + flutter::Settings FLTDefaultSettingsForBundle(NSBundle* bundle, NSProcessInfo* processInfoOrNil) { auto command_line = flutter::CommandLineFromNSProcessInfo(processInfoOrNil); @@ -155,7 +172,8 @@ settings.enable_wide_gamut = false; #else NSNumber* nsEnableWideGamut = [mainBundle objectForInfoDictionaryKey:@"FLTEnableWideGamut"]; - BOOL enableWideGamut = nsEnableWideGamut ? nsEnableWideGamut.boolValue : YES; + BOOL enableWideGamut = + (nsEnableWideGamut ? nsEnableWideGamut.boolValue : YES) && DoesHardwareSupportsWideGamut(); settings.enable_wide_gamut = enableWideGamut; #endif