1010#if FLUTTER_SHELL_ENABLE_METAL
1111#include < Metal/Metal.h>
1212#endif // FLUTTER_SHELL_ENABLE_METAL
13+ #import < TargetConditionals.h>
1314
1415#include " flutter/fml/logging.h"
1516
1617namespace flutter {
1718
1819#if FLUTTER_SHELL_ENABLE_METAL
1920bool ShouldUseMetalRenderer () {
20- // Flutter supports Metal on all devices with Apple A7 SoC or above that have been updated to or
21- // past iOS 10.0. The processor was selected as it is the first version at which Metal was
22- // supported. The iOS version floor was selected due to the availability of features used by Skia.
2321 bool ios_version_supports_metal = false ;
24- if (@available (iOS 10.0 , *)) {
22+ if (@available (iOS METAL_IOS_VERSION_BASELINE , *)) {
2523 auto device = MTLCreateSystemDefaultDevice ();
2624 ios_version_supports_metal = [device supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily1_v3];
2725 }
2826 return ios_version_supports_metal;
2927}
3028#endif // FLUTTER_SHELL_ENABLE_METAL
3129
32- IOSRenderingAPI GetRenderingAPIForProcess () {
33- #if TARGET_IPHONE_SIMULATOR
34- return IOSRenderingAPI::kSoftware ;
35- #endif // TARGET_IPHONE_SIMULATOR
30+ IOSRenderingAPI GetRenderingAPIForProcess (bool force_software) {
31+ #if TARGET_OS_SIMULATOR
32+ if (force_software) {
33+ return IOSRenderingAPI::kSoftware ;
34+ }
35+ #else
36+ if (force_software) {
37+ FML_LOG (WARNING) << " The --enable-software-rendering is only supported on Simulator targets "
38+ " and will be ignored." ;
39+ }
40+ #endif // TARGET_OS_SIMULATOR
3641
3742#if FLUTTER_SHELL_ENABLE_METAL
3843 static bool should_use_metal = ShouldUseMetalRenderer ();
3944 if (should_use_metal) {
4045 return IOSRenderingAPI::kMetal ;
4146 }
4247#endif // FLUTTER_SHELL_ENABLE_METAL
48+
49+ // OpenGL will be emulated using software rendering by Apple on the simulator, so we use the
50+ // Skia software rendering since it performs a little better than the emulated OpenGL.
51+ #if TARGET_OS_SIMULATOR
52+ return IOSRenderingAPI::kSoftware ;
53+ #else
4354 return IOSRenderingAPI::kOpenGLES ;
55+ #endif // TARGET_OS_SIMULATOR
4456}
4557
4658Class GetCoreAnimationLayerClassForRenderingAPI (IOSRenderingAPI rendering_api) {
@@ -49,10 +61,12 @@ Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api) {
4961 return [CALayer class ];
5062 case IOSRenderingAPI::kOpenGLES :
5163 return [CAEAGLLayer class ];
52- #if !TARGET_IPHONE_SIMULATOR
5364 case IOSRenderingAPI::kMetal :
54- return [CAMetalLayer class ];
55- #endif // !TARGET_IPHONE_SIMULATOR
65+ if (@available (iOS METAL_IOS_VERSION_BASELINE, *)) {
66+ return [CAMetalLayer class ];
67+ }
68+ FML_CHECK (false ) << " Metal availability should already have been checked" ;
69+ break ;
5670 default :
5771 break ;
5872 }
0 commit comments