From 51c5bb42b418950ebbe5ee14120640bf59d8b2de Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Thu, 10 Oct 2019 13:03:04 -0700 Subject: [PATCH] Put Metal renderer selection behind runtime flag and plist opt-in. (flutter/engine#13056) --- .../framework/Source/FlutterOverlayView.mm | 11 ++---- .../ios/framework/Source/FlutterView.mm | 36 ++++++++++++++++++- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm index 4140290230..bf4c1c21f6 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm @@ -12,6 +12,7 @@ #include "flutter/fml/trace_event.h" #include "flutter/shell/common/platform_view.h" #include "flutter/shell/common/rasterizer.h" +#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h" #include "flutter/shell/platform/darwin/ios/ios_surface_gl.h" #if FLUTTER_SHELL_ENABLE_METAL #include "flutter/shell/platform/darwin/ios/ios_surface_metal.h" @@ -67,15 +68,7 @@ } + (Class)layerClass { -#if TARGET_IPHONE_SIMULATOR - return [CALayer class]; -#else // TARGET_IPHONE_SIMULATOR -#if FLUTTER_SHELL_ENABLE_METAL - return [CAMetalLayer class]; -#else // FLUTTER_SHELL_ENABLE_METAL - return [CAEAGLLayer class]; -#endif // FLUTTER_SHELL_ENABLE_METAL -#endif // TARGET_IPHONE_SIMULATOR + return [FlutterView layerClass]; } - (std::unique_ptr)createSurface: diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm index 4e4acdfc04..6ea6640135 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -81,12 +81,46 @@ id _delegate; [super layoutSubviews]; } +#if FLUTTER_SHELL_ENABLE_METAL +static bool UseMetalRenderer() { + // If there is a command line argument that says Metal should not be used, that takes precedence + // over everything else. This allows disabling Metal on a per run basis to check for regressions + // on an application that has otherwise opted into Metal on an iOS version that supports it. + if ([[[NSProcessInfo processInfo] arguments] containsObject:@"--disable-metal"]) { + return false; + } + + // If the application wants to use metal on a per run basis with disregard for version checks or + // plist based opt ins, respect that opinion. This allows selectively testing features on older + // version of iOS than those explicitly stated as being supported. + if ([[[NSProcessInfo processInfo] arguments] containsObject:@"--force-metal"]) { + return true; + } + + // This is just a version we picked that is easy to support and has all necessary Metal features. + bool ios_version_supports_metal = false; + if (@available(iOS 11.0, *)) { + ios_version_supports_metal = true; + } + + // The application must opt-in by default to use Metal without command line flags. + bool application_opts_into_metal = + [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"io.flutter.metal_preview"] boolValue]; + + return ios_version_supports_metal && application_opts_into_metal; +} +#endif // FLUTTER_SHELL_ENABLE_METAL + + (Class)layerClass { #if TARGET_IPHONE_SIMULATOR return [CALayer class]; #else // TARGET_IPHONE_SIMULATOR #if FLUTTER_SHELL_ENABLE_METAL - return [CAMetalLayer class]; + if (UseMetalRenderer()) { + return [CAMetalLayer class]; + } else { + return [CAEAGLLayer class]; + } #else // FLUTTER_SHELL_ENABLE_METAL return [CAEAGLLayer class]; #endif // FLUTTER_SHELL_ENABLE_METAL