diff --git a/shell/platform/darwin/macos/framework/Source/FlutterDartProject.mm b/shell/platform/darwin/macos/framework/Source/FlutterDartProject.mm index 8391e4f8b4550..7d1c06122f34e 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterDartProject.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterDartProject.mm @@ -59,6 +59,15 @@ - (instancetype)initWithAssetsPath:(NSString*)assets ICUDataPath:(NSString*)icuP return self; } +- (BOOL)enableImpeller { + NSNumber* enableImpeller = + [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FLTEnableImpeller"]; + if (enableImpeller != nil) { + return enableImpeller.boolValue; + } + return NO; +} + - (NSString*)assetsPath { if (_assetsPath) { return _assetsPath; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h b/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h index 0e0cad3757152..0dc1f46ba1dbf 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h @@ -31,6 +31,11 @@ */ @property(nonatomic, nullable) void (*rootIsolateCreateCallback)(void* _Nullable); +/** + * Whether the Impeller rendering backend is enabled + */ +@property(nonatomic, readonly) BOOL enableImpeller; + /** * Instead of looking up the assets and ICU data path in the application bundle, this initializer * allows callers to create a Dart project with custom locations specified for the both. diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm index 2be2f6b70af8f..138ebdc1c6be7 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm @@ -481,6 +481,13 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint { // The first argument of argv is required to be the executable name. std::vector argv = {[self.executableName UTF8String]}; std::vector switches = self.switches; + + // Enable Impeller only if specifically asked for from the project or cmdline arguments. + if (_project.enableImpeller || + std::find(switches.begin(), switches.end(), "--enable-impeller=true") != switches.end()) { + switches.push_back("--enable-impeller=true"); + } + std::transform(switches.begin(), switches.end(), std::back_inserter(argv), [](const std::string& arg) -> const char* { return arg.c_str(); }); diff --git a/shell/platform/embedder/embedder_surface_metal_impeller.h b/shell/platform/embedder/embedder_surface_metal_impeller.h index 4fb2b990029c6..2ddacd96f26ae 100644 --- a/shell/platform/embedder/embedder_surface_metal_impeller.h +++ b/shell/platform/embedder/embedder_surface_metal_impeller.h @@ -62,6 +62,9 @@ class EmbedderSurfaceMetalImpeller final : public EmbedderSurface, // |GPUSurfaceMetalDelegate| bool PresentTexture(GPUMTLTextureInfo texture) const override; + // |EmbedderSurface| + std::shared_ptr CreateImpellerContext() const override; + FML_DISALLOW_COPY_AND_ASSIGN(EmbedderSurfaceMetalImpeller); }; diff --git a/shell/platform/embedder/embedder_surface_metal_impeller.mm b/shell/platform/embedder/embedder_surface_metal_impeller.mm index c7984f4f386ef..ba5615252d706 100644 --- a/shell/platform/embedder/embedder_surface_metal_impeller.mm +++ b/shell/platform/embedder/embedder_surface_metal_impeller.mm @@ -49,6 +49,7 @@ std::make_shared(false), // is_gpu_disabled_sync_switch "Impeller Library" // library_label ); + FML_LOG(ERROR) << "Using the Impeller rendering backend (Metal)."; valid_ = !!context_; } @@ -75,6 +76,10 @@ return surface; } +std::shared_ptr EmbedderSurfaceMetalImpeller::CreateImpellerContext() const { + return context_; +} + GPUCAMetalLayerHandle EmbedderSurfaceMetalImpeller::GetCAMetalLayer( const SkISize& frame_info) const { FML_CHECK(false) << "Only rendering to MTLTexture is supported.";