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

Commit 8891f30

Browse files
committed
[Impeller] adds hardware check on gpu for wide gamut
1 parent b5e5f0f commit 8891f30

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <syslog.h>
1010

11+
#import <Metal/Metal.h>
1112
#include <sstream>
1213
#include <string>
1314

@@ -22,6 +23,8 @@
2223
#import "flutter/shell/platform/darwin/common/command_line.h"
2324
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
2425

26+
FLUTTER_ASSERT_NOT_ARC
27+
2528
extern "C" {
2629
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
2730
// Used for debugging dart:* sources.
@@ -32,6 +35,20 @@
3235

3336
static const char* kApplicationKernelSnapshotFileName = "kernel_blob.bin";
3437

38+
static BOOL DoesHardwareSupportsWideGamut() {
39+
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
40+
BOOL result;
41+
if (@available(iOS 13.0, *)) {
42+
// MTLGPUFamilyApple2 = A9/A10
43+
result = [device supportsFamily:MTLGPUFamilyApple2];
44+
} else {
45+
// A9/A10 on iOS 10+
46+
result = [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v2];
47+
}
48+
[device release];
49+
return result;
50+
}
51+
3552
flutter::Settings FLTDefaultSettingsForBundle(NSBundle* bundle, NSProcessInfo* processInfoOrNil) {
3653
auto command_line = flutter::CommandLineFromNSProcessInfo(processInfoOrNil);
3754

@@ -155,7 +172,8 @@
155172
settings.enable_wide_gamut = false;
156173
#else
157174
NSNumber* nsEnableWideGamut = [mainBundle objectForInfoDictionaryKey:@"FLTEnableWideGamut"];
158-
BOOL enableWideGamut = nsEnableWideGamut ? nsEnableWideGamut.boolValue : YES;
175+
BOOL enableWideGamut =
176+
(nsEnableWideGamut ? nsEnableWideGamut.boolValue : YES) && DoesHardwareSupportsWideGamut();
159177
settings.enable_wide_gamut = enableWideGamut;
160178
#endif
161179

0 commit comments

Comments
 (0)