未验证 提交 15739917 编写于 作者: K Kaushik Iska 提交者: GitHub

[macOS] Allow loading of AOT snapshots and instructions from elf bundle (#21670)

上级 2eac514f
......@@ -7,6 +7,7 @@
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
#include <algorithm>
#include <filesystem>
#include <vector>
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h"
......@@ -162,6 +163,16 @@ 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;
......@@ -184,6 +195,9 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
// A mapping of textureID to internal FlutterExternalTextureGL adapter.
NSMutableDictionary<NSNumber*, FlutterExternalTextureGL*>* _textures;
// Pointer to the Dart AOT snapshot and instruction data.
UniqueAotDataPtr _aotData;
}
- (instancetype)initWithName:(NSString*)labelPrefix project:(FlutterDartProject*)project {
......@@ -274,6 +288,11 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
};
flutterArguments.custom_task_runners = &custom_task_runners;
_aotData = [self loadAotData:flutterArguments.assets_path];
if (_aotData) {
flutterArguments.aot_data = _aotData.get();
}
FlutterEngineResult result = FlutterEngineInitialize(
FLUTTER_ENGINE_VERSION, &rendererConfig, &flutterArguments, (__bridge void*)(self), &_engine);
if (result != kSuccess) {
......@@ -293,6 +312,33 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
return YES;
}
- (UniqueAotDataPtr)loadAotData:(std::string)assetsDir {
if (!FlutterEngineRunsAOTCompiledDartCode()) {
return nullptr;
}
std::filesystem::path assetsFsDir(assetsDir);
std::filesystem::path elfFile("app_elf_snapshot.so");
auto fullElfPath = assetsFsDir / elfFile;
if (!std::filesystem::exists(fullElfPath)) {
return nullptr;
}
FlutterEngineAOTDataSource source = {};
source.type = kFlutterEngineAOTDataSourceTypeElfPath;
source.elf_path = fullElfPath.c_str();
FlutterEngineAOTData data = nullptr;
auto result = FlutterEngineCreateAOTData(&source, &data);
if (result != kSuccess) {
NSLog(@"Failed to load AOT data from: %@", @(fullElfPath.c_str()));
return nullptr;
}
return UniqueAotDataPtr(data);
}
- (void)setViewController:(FlutterViewController*)controller {
_viewController = controller;
_mainOpenGLContext = controller.flutterView.openGLContext;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册