[Impeller] allowing enabling Impeller on macOS. (flutter/engine#42639)

Ship it?
This commit is contained in:
Jonah Williams
2023-06-12 13:02:46 -07:00
committed by GitHub
parent ab09f653a6
commit 260d931b1c
5 changed files with 29 additions and 0 deletions

View File

@@ -59,6 +59,15 @@ static NSString* const kAppBundleIdentifier = @"io.flutter.flutter.app";
return self;
}
- (BOOL)enableImpeller {
NSNumber* enableImpeller =
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"FLTEnableImpeller"];
if (enableImpeller != nil) {
return enableImpeller.boolValue;
}
return NO;
}
- (NSString*)assetsPath {
if (_assetsPath) {
return _assetsPath;

View File

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

View File

@@ -481,6 +481,13 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
// The first argument of argv is required to be the executable name.
std::vector<const char*> argv = {[self.executableName UTF8String]};
std::vector<std::string> 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(); });

View File

@@ -62,6 +62,9 @@ class EmbedderSurfaceMetalImpeller final : public EmbedderSurface,
// |GPUSurfaceMetalDelegate|
bool PresentTexture(GPUMTLTextureInfo texture) const override;
// |EmbedderSurface|
std::shared_ptr<impeller::Context> CreateImpellerContext() const override;
FML_DISALLOW_COPY_AND_ASSIGN(EmbedderSurfaceMetalImpeller);
};

View File

@@ -49,6 +49,7 @@ EmbedderSurfaceMetalImpeller::EmbedderSurfaceMetalImpeller(
std::make_shared<fml::SyncSwitch>(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 @@ std::unique_ptr<Surface> EmbedderSurfaceMetalImpeller::CreateGPUSurface()
return surface;
}
std::shared_ptr<impeller::Context> EmbedderSurfaceMetalImpeller::CreateImpellerContext() const {
return context_;
}
GPUCAMetalLayerHandle EmbedderSurfaceMetalImpeller::GetCAMetalLayer(
const SkISize& frame_info) const {
FML_CHECK(false) << "Only rendering to MTLTexture is supported.";