Pass option to reuse an existing runtime controller (flutter/engine#4253)
This commit is contained in:
@@ -189,12 +189,14 @@ void Engine::Init() {
|
||||
const std::string Engine::main_entrypoint_ = "main";
|
||||
|
||||
void Engine::RunBundle(const std::string& bundle_path,
|
||||
const std::string& entrypoint) {
|
||||
const std::string& entrypoint,
|
||||
bool reuse_runtime_controller) {
|
||||
TRACE_EVENT0("flutter", "Engine::RunBundle");
|
||||
ConfigureAssetBundle(bundle_path);
|
||||
std::vector<uint8_t> platform_kernel;
|
||||
GetAssetAsBuffer(blink::kPlatformKernelAssetKey, &platform_kernel);
|
||||
ConfigureRuntime(GetScriptUriFromPath(bundle_path), platform_kernel);
|
||||
ConfigureRuntime(GetScriptUriFromPath(bundle_path), platform_kernel,
|
||||
reuse_runtime_controller);
|
||||
|
||||
if (blink::IsRunningPrecompiledCode()) {
|
||||
runtime_->dart_controller()->RunFromPrecompiledSnapshot(entrypoint);
|
||||
@@ -214,14 +216,16 @@ void Engine::RunBundle(const std::string& bundle_path,
|
||||
|
||||
void Engine::RunBundleAndSnapshot(const std::string& bundle_path,
|
||||
const std::string& snapshot_override,
|
||||
const std::string& entrypoint) {
|
||||
const std::string& entrypoint,
|
||||
bool reuse_runtime_controller) {
|
||||
TRACE_EVENT0("flutter", "Engine::RunBundleAndSnapshot");
|
||||
if (snapshot_override.empty()) {
|
||||
RunBundle(bundle_path, entrypoint);
|
||||
return;
|
||||
}
|
||||
ConfigureAssetBundle(bundle_path);
|
||||
ConfigureRuntime(GetScriptUriFromPath(bundle_path));
|
||||
ConfigureRuntime(GetScriptUriFromPath(bundle_path), std::vector<uint8_t>(),
|
||||
reuse_runtime_controller);
|
||||
if (blink::IsRunningPrecompiledCode()) {
|
||||
runtime_->dart_controller()->RunFromPrecompiledSnapshot(entrypoint);
|
||||
} else {
|
||||
@@ -235,7 +239,8 @@ void Engine::RunBundleAndSnapshot(const std::string& bundle_path,
|
||||
|
||||
void Engine::RunBundleAndSource(const std::string& bundle_path,
|
||||
const std::string& main,
|
||||
const std::string& packages) {
|
||||
const std::string& packages,
|
||||
bool reuse_runtime_controller) {
|
||||
TRACE_EVENT0("flutter", "Engine::RunBundleAndSource");
|
||||
FXL_CHECK(!blink::IsRunningPrecompiledCode())
|
||||
<< "Cannot run from source in a precompiled build.";
|
||||
@@ -248,7 +253,8 @@ void Engine::RunBundleAndSource(const std::string& bundle_path,
|
||||
ConfigureAssetBundle(bundle_path);
|
||||
GetAssetAsBuffer(blink::kPlatformKernelAssetKey, &platform_kernel);
|
||||
}
|
||||
ConfigureRuntime(GetScriptUriFromPath(bundle_path), platform_kernel);
|
||||
ConfigureRuntime(GetScriptUriFromPath(bundle_path), platform_kernel,
|
||||
reuse_runtime_controller);
|
||||
|
||||
if (!platform_kernel.empty()) {
|
||||
std::vector<uint8_t> kernel;
|
||||
@@ -477,17 +483,19 @@ void Engine::ConfigureAssetBundle(const std::string& path) {
|
||||
}
|
||||
|
||||
void Engine::ConfigureRuntime(const std::string& script_uri,
|
||||
const std::vector<uint8_t>& platform_kernel) {
|
||||
if (!runtime_) {
|
||||
runtime_ = blink::RuntimeController::Create(this);
|
||||
runtime_->CreateDartController(
|
||||
std::move(script_uri), default_isolate_snapshot_data,
|
||||
default_isolate_snapshot_instr, platform_kernel);
|
||||
runtime_->SetViewportMetrics(viewport_metrics_);
|
||||
runtime_->SetLocale(language_code_, country_code_);
|
||||
runtime_->SetUserSettingsData(user_settings_data_);
|
||||
runtime_->SetSemanticsEnabled(semantics_enabled_);
|
||||
const std::vector<uint8_t>& platform_kernel,
|
||||
bool reuse_runtime_controller) {
|
||||
if (runtime_ && reuse_runtime_controller) {
|
||||
return;
|
||||
}
|
||||
runtime_ = blink::RuntimeController::Create(this);
|
||||
runtime_->CreateDartController(
|
||||
std::move(script_uri), default_isolate_snapshot_data,
|
||||
default_isolate_snapshot_instr, platform_kernel);
|
||||
runtime_->SetViewportMetrics(viewport_metrics_);
|
||||
runtime_->SetLocale(language_code_, country_code_);
|
||||
runtime_->SetUserSettingsData(user_settings_data_);
|
||||
runtime_->SetSemanticsEnabled(semantics_enabled_);
|
||||
}
|
||||
|
||||
void Engine::DidCreateMainIsolate(Dart_Isolate isolate) {
|
||||
|
||||
@@ -36,20 +36,23 @@ class Engine : public blink::RuntimeDelegate {
|
||||
static void Init();
|
||||
|
||||
void RunBundle(const std::string& bundle_path,
|
||||
const std::string& entrypoint = main_entrypoint_);
|
||||
const std::string& entrypoint = main_entrypoint_,
|
||||
bool reuse_runtime_controller = false);
|
||||
|
||||
// Uses the given snapshot instead of looking inside the bundle for the
|
||||
// snapshot. If |snapshot_override| is empty, this function looks for the
|
||||
// snapshot in the bundle itself.
|
||||
void RunBundleAndSnapshot(const std::string& bundle_path,
|
||||
const std::string& snapshot_override,
|
||||
const std::string& entrypoint = main_entrypoint_);
|
||||
const std::string& entrypoint = main_entrypoint_,
|
||||
bool reuse_runtime_controller = false);
|
||||
|
||||
// Uses the given source code instead of looking inside the bundle for the
|
||||
// source code.
|
||||
void RunBundleAndSource(const std::string& bundle_path,
|
||||
const std::string& main,
|
||||
const std::string& packages);
|
||||
const std::string& packages,
|
||||
bool reuse_runtime_controller = false);
|
||||
|
||||
void BeginFrame(fxl::TimePoint frame_time);
|
||||
void NotifyIdle(int64_t deadline);
|
||||
@@ -91,7 +94,8 @@ class Engine : public blink::RuntimeDelegate {
|
||||
void ConfigureAssetBundle(const std::string& path);
|
||||
void ConfigureRuntime(
|
||||
const std::string& script_uri,
|
||||
const std::vector<uint8_t>& platform_kernel = std::vector<uint8_t>());
|
||||
const std::vector<uint8_t>& platform_kernel = std::vector<uint8_t>(),
|
||||
bool reuse_runtime_controller = false);
|
||||
|
||||
bool HandleLifecyclePlatformMessage(blink::PlatformMessage* message);
|
||||
bool HandleNavigationPlatformMessage(
|
||||
|
||||
@@ -565,13 +565,17 @@ public class FlutterView extends SurfaceView
|
||||
}
|
||||
|
||||
public void runFromBundle(String bundlePath, String snapshotOverride) {
|
||||
runFromBundle(bundlePath, snapshotOverride, "main");
|
||||
runFromBundle(bundlePath, snapshotOverride, "main", false);
|
||||
}
|
||||
|
||||
public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint) {
|
||||
runFromBundle(bundlePath, snapshotOverride, entrypoint, false);
|
||||
}
|
||||
|
||||
public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, boolean reuseRuntimeController) {
|
||||
assertAttached();
|
||||
preRun();
|
||||
nativeRunBundleAndSnapshot(mNativePlatformView, bundlePath, snapshotOverride, entrypoint);
|
||||
nativeRunBundleAndSnapshot(mNativePlatformView, bundlePath, snapshotOverride, entrypoint, reuseRuntimeController);
|
||||
postRun();
|
||||
}
|
||||
|
||||
@@ -631,7 +635,8 @@ public class FlutterView extends SurfaceView
|
||||
private static native void nativeRunBundleAndSnapshot(long nativePlatformViewAndroid,
|
||||
String bundlePath,
|
||||
String snapshotOverride,
|
||||
String entrypoint);
|
||||
String entrypoint,
|
||||
boolean reuseRuntimeController);
|
||||
|
||||
private static native void nativeRunBundleAndSource(long nativePlatformViewAndroid,
|
||||
String bundlePath,
|
||||
|
||||
@@ -210,16 +210,18 @@ void PlatformViewAndroid::SurfaceDestroyed() {
|
||||
|
||||
void PlatformViewAndroid::RunBundleAndSnapshot(std::string bundle_path,
|
||||
std::string snapshot_override,
|
||||
std::string entrypoint) {
|
||||
std::string entrypoint,
|
||||
bool reuse_runtime_controller) {
|
||||
blink::Threads::UI()->PostTask([
|
||||
engine = engine_->GetWeakPtr(), bundle_path = std::move(bundle_path),
|
||||
snapshot_override = std::move(snapshot_override),
|
||||
entrypoint = std::move(entrypoint)
|
||||
entrypoint = std::move(entrypoint),
|
||||
reuse_runtime_controller = reuse_runtime_controller
|
||||
] {
|
||||
if (engine)
|
||||
engine->RunBundleAndSnapshot(std::move(bundle_path),
|
||||
std::move(snapshot_override),
|
||||
std::move(entrypoint));
|
||||
engine->RunBundleAndSnapshot(
|
||||
std::move(bundle_path), std::move(snapshot_override),
|
||||
std::move(entrypoint), reuse_runtime_controller);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,8 @@ class PlatformViewAndroid : public PlatformView {
|
||||
|
||||
void RunBundleAndSnapshot(std::string bundle_path,
|
||||
std::string snapshot_override,
|
||||
std::string entrypoint);
|
||||
std::string entrypoint,
|
||||
bool reuse_isolate);
|
||||
|
||||
void RunBundleAndSource(std::string bundle_path,
|
||||
std::string main,
|
||||
|
||||
@@ -105,11 +105,13 @@ static void RunBundleAndSnapshot(JNIEnv* env,
|
||||
jlong platform_view,
|
||||
jstring bundlePath,
|
||||
jstring snapshotOverride,
|
||||
jstring entrypoint) {
|
||||
jstring entrypoint,
|
||||
jboolean reuse_runtime_controller) {
|
||||
return PLATFORM_VIEW->RunBundleAndSnapshot(
|
||||
fml::jni::JavaStringToString(env, bundlePath), //
|
||||
fml::jni::JavaStringToString(env, snapshotOverride), //
|
||||
fml::jni::JavaStringToString(env, entrypoint) //
|
||||
fml::jni::JavaStringToString(env, entrypoint), //
|
||||
reuse_runtime_controller //
|
||||
);
|
||||
}
|
||||
|
||||
@@ -260,7 +262,7 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
|
||||
{
|
||||
.name = "nativeRunBundleAndSnapshot",
|
||||
.signature =
|
||||
"(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
|
||||
"(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V",
|
||||
.fnPtr = reinterpret_cast<void*>(&shell::RunBundleAndSnapshot),
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user