Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] allowing enabling Impeller on macOS. #42639

Merged
merged 5 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,13 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
// 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 ||
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to only using switches

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(); });

Expand Down
3 changes: 3 additions & 0 deletions shell/platform/embedder/embedder_surface_metal_impeller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to override this so we get a context for image decoding.


FML_DISALLOW_COPY_AND_ASSIGN(EmbedderSurfaceMetalImpeller);
};

Expand Down
5 changes: 5 additions & 0 deletions shell/platform/embedder/embedder_surface_metal_impeller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
std::make_shared<fml::SyncSwitch>(false), // is_gpu_disabled_sync_switch
"Impeller Library" // library_label
);
FML_LOG(ERROR) << "Using the Impeller rendering backend (Metal).";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an error log here to match the other backends


valid_ = !!context_;
}
Expand All @@ -75,6 +76,10 @@
return surface;
}

std::shared_ptr<impeller::Context> EmbedderSurfaceMetalImpeller::CreateImpellerContext() const {
return context_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this is fine because it's set up in the ctor)

}

GPUCAMetalLayerHandle EmbedderSurfaceMetalImpeller::GetCAMetalLayer(
const SkISize& frame_info) const {
FML_CHECK(false) << "Only rendering to MTLTexture is supported.";
Expand Down