Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ static FlutterLocale FlutterLocaleFromNSLocale(NSLocale* locale) {
return flutterLocale;
}

namespace {

struct AotDataDeleter {
void operator()(FlutterEngineAOTData aot_data) { FlutterEngineCollectAOTData(aot_data); }
};

using UniqueAotDataPtr = std::unique_ptr<_FlutterEngineAOTData, AotDataDeleter>;

}

/**
* Private interface declaration for FlutterEngine.
*/
Expand Down Expand Up @@ -76,6 +86,12 @@ - (BOOL)populateTextureWithIdentifier:(int64_t)textureID
*/
- (void)postMainThreadTask:(FlutterTask)task targetTimeInNanoseconds:(uint64_t)targetTime;

/**
* Loads the AOT snapshots and instructions from the elf bundle (app_elf_snapshot.so) if it is
* present in the assets directory.
*/
- (UniqueAotDataPtr)loadAOTData:(NSString*)assetsDir;

@end

#pragma mark -
Expand Down Expand Up @@ -163,16 +179,6 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,

#pragma mark -

namespace {

struct AotDataDeleter {
void operator()(FlutterEngineAOTData aot_data) { FlutterEngineCollectAOTData(aot_data); }
};

using UniqueAotDataPtr = std::unique_ptr<_FlutterEngineAOTData, AotDataDeleter>;

}

@implementation FlutterEngine {
// The embedding-API-level engine object.
FLUTTER_API_SYMBOL(FlutterEngine) _engine;
Expand Down Expand Up @@ -289,7 +295,7 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
};
flutterArguments.custom_task_runners = &custom_task_runners;

_aotData = [self loadAotData:flutterArguments.assets_path];
_aotData = [self loadAOTData:_project.assetsPath];
if (_aotData) {
flutterArguments.aot_data = _aotData.get();
}
Expand All @@ -313,12 +319,14 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
return YES;
}

- (UniqueAotDataPtr)loadAotData:(std::string)assetsDir {
- (UniqueAotDataPtr)loadAOTData:(NSString*)assetsDir {
if (!FlutterEngineRunsAOTCompiledDartCode()) {
return nullptr;
}

std::filesystem::path assetsFsDir(assetsDir);
// This is the location where the test fixture places the snapshot file.
// For applications built by Flutter tool, this is in "App.framework".
std::filesystem::path assetsFsDir(assetsDir.UTF8String);
std::filesystem::path elfFile("app_elf_snapshot.so");
auto fullElfPath = assetsFsDir / elfFile;

Expand Down