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

Commit 835838c

Browse files
authored
Put Metal renderer selection behind runtime flag and plist opt-in. (#13056)
1 parent cef6751 commit 835838c

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "flutter/fml/trace_event.h"
1313
#include "flutter/shell/common/platform_view.h"
1414
#include "flutter/shell/common/rasterizer.h"
15+
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
1516
#include "flutter/shell/platform/darwin/ios/ios_surface_gl.h"
1617
#if FLUTTER_SHELL_ENABLE_METAL
1718
#include "flutter/shell/platform/darwin/ios/ios_surface_metal.h"
@@ -67,15 +68,7 @@ - (instancetype)initWithContentsScale:(CGFloat)contentsScale {
6768
}
6869

6970
+ (Class)layerClass {
70-
#if TARGET_IPHONE_SIMULATOR
71-
return [CALayer class];
72-
#else // TARGET_IPHONE_SIMULATOR
73-
#if FLUTTER_SHELL_ENABLE_METAL
74-
return [CAMetalLayer class];
75-
#else // FLUTTER_SHELL_ENABLE_METAL
76-
return [CAEAGLLayer class];
77-
#endif // FLUTTER_SHELL_ENABLE_METAL
78-
#endif // TARGET_IPHONE_SIMULATOR
71+
return [FlutterView layerClass];
7972
}
8073

8174
- (std::unique_ptr<flutter::IOSSurface>)createSurface:

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,46 @@ - (void)layoutSubviews {
8181
[super layoutSubviews];
8282
}
8383

84+
#if FLUTTER_SHELL_ENABLE_METAL
85+
static bool UseMetalRenderer() {
86+
// If there is a command line argument that says Metal should not be used, that takes precedence
87+
// over everything else. This allows disabling Metal on a per run basis to check for regressions
88+
// on an application that has otherwise opted into Metal on an iOS version that supports it.
89+
if ([[[NSProcessInfo processInfo] arguments] containsObject:@"--disable-metal"]) {
90+
return false;
91+
}
92+
93+
// If the application wants to use metal on a per run basis with disregard for version checks or
94+
// plist based opt ins, respect that opinion. This allows selectively testing features on older
95+
// version of iOS than those explicitly stated as being supported.
96+
if ([[[NSProcessInfo processInfo] arguments] containsObject:@"--force-metal"]) {
97+
return true;
98+
}
99+
100+
// This is just a version we picked that is easy to support and has all necessary Metal features.
101+
bool ios_version_supports_metal = false;
102+
if (@available(iOS 11.0, *)) {
103+
ios_version_supports_metal = true;
104+
}
105+
106+
// The application must opt-in by default to use Metal without command line flags.
107+
bool application_opts_into_metal =
108+
[[[NSBundle mainBundle] objectForInfoDictionaryKey:@"io.flutter.metal_preview"] boolValue];
109+
110+
return ios_version_supports_metal && application_opts_into_metal;
111+
}
112+
#endif // FLUTTER_SHELL_ENABLE_METAL
113+
84114
+ (Class)layerClass {
85115
#if TARGET_IPHONE_SIMULATOR
86116
return [CALayer class];
87117
#else // TARGET_IPHONE_SIMULATOR
88118
#if FLUTTER_SHELL_ENABLE_METAL
89-
return [CAMetalLayer class];
119+
if (UseMetalRenderer()) {
120+
return [CAMetalLayer class];
121+
} else {
122+
return [CAEAGLLayer class];
123+
}
90124
#else // FLUTTER_SHELL_ENABLE_METAL
91125
return [CAEAGLLayer class];
92126
#endif // FLUTTER_SHELL_ENABLE_METAL

0 commit comments

Comments
 (0)