@@ -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