From 810e4333086fcfcaccae9505892c6364aa0019ae Mon Sep 17 00:00:00 2001 From: David Worsham Date: Wed, 3 Feb 2021 17:42:36 -0800 Subject: [PATCH] Fix use of multiple shells w/ different snapshots (#24152) --- runtime/dart_snapshot.cc | 4 +- runtime/dart_snapshot.h | 4 +- runtime/dart_vm.cc | 4 +- runtime/dart_vm.h | 4 +- runtime/dart_vm_data.cc | 4 +- runtime/dart_vm_data.h | 4 +- runtime/dart_vm_lifecycle.cc | 4 +- runtime/dart_vm_lifecycle.h | 4 +- shell/common/animator_unittests.cc | 2 +- shell/common/engine.cc | 2 +- shell/common/engine.h | 2 +- shell/common/shell.cc | 270 +++++++++--------- shell/common/shell.h | 79 ++--- shell/common/shell_benchmarks.cc | 2 +- shell/common/shell_test.cc | 2 +- shell/common/shell_unittests.cc | 2 +- .../platform/android/android_shell_holder.cc | 4 +- .../ios/framework/Source/FlutterEngine.mm | 4 +- shell/platform/embedder/embedder_engine.cc | 6 +- shell/platform/fuchsia/flutter/component.cc | 5 + shell/platform/fuchsia/flutter/engine.cc | 2 +- shell/testing/tester_main.cc | 3 +- 22 files changed, 190 insertions(+), 227 deletions(-) diff --git a/runtime/dart_snapshot.cc b/runtime/dart_snapshot.cc index aac3f28789f..0dbbab8b12f 100644 --- a/runtime/dart_snapshot.cc +++ b/runtime/dart_snapshot.cc @@ -155,7 +155,7 @@ static std::shared_ptr ResolveIsolateInstructions( #endif // DART_SNAPSHOT_STATIC_LINK } -fml::RefPtr DartSnapshot::VMSnapshotFromSettings( +fml::RefPtr DartSnapshot::VMSnapshotFromSettings( const Settings& settings) { TRACE_EVENT0("flutter", "DartSnapshot::VMSnapshotFromSettings"); auto snapshot = @@ -168,7 +168,7 @@ fml::RefPtr DartSnapshot::VMSnapshotFromSettings( return nullptr; } -fml::RefPtr DartSnapshot::IsolateSnapshotFromSettings( +fml::RefPtr DartSnapshot::IsolateSnapshotFromSettings( const Settings& settings) { TRACE_EVENT0("flutter", "DartSnapshot::IsolateSnapshotFromSettings"); auto snapshot = diff --git a/runtime/dart_snapshot.h b/runtime/dart_snapshot.h index e43b89027db..97b5f40763e 100644 --- a/runtime/dart_snapshot.h +++ b/runtime/dart_snapshot.h @@ -79,7 +79,7 @@ class DartSnapshot : public fml::RefCountedThreadSafe { /// /// @return A valid core snapshot or nullptr. /// - static fml::RefPtr VMSnapshotFromSettings( + static fml::RefPtr VMSnapshotFromSettings( const Settings& settings); //---------------------------------------------------------------------------- @@ -99,7 +99,7 @@ class DartSnapshot : public fml::RefCountedThreadSafe { /// /// @return A valid isolate snapshot or nullptr. /// - static fml::RefPtr IsolateSnapshotFromSettings( + static fml::RefPtr IsolateSnapshotFromSettings( const Settings& settings); //---------------------------------------------------------------------------- diff --git a/runtime/dart_vm.cc b/runtime/dart_vm.cc index ba6dc9dad9e..228f7b9159d 100644 --- a/runtime/dart_vm.cc +++ b/runtime/dart_vm.cc @@ -245,8 +245,8 @@ static void EmbedderInformationCallback(Dart_EmbedderInformation* info) { std::shared_ptr DartVM::Create( Settings settings, - fml::RefPtr vm_snapshot, - fml::RefPtr isolate_snapshot, + fml::RefPtr vm_snapshot, + fml::RefPtr isolate_snapshot, std::shared_ptr isolate_name_server) { auto vm_data = DartVMData::Create(settings, // std::move(vm_snapshot), // diff --git a/runtime/dart_vm.h b/runtime/dart_vm.h index 3a03f82dbb7..829014c9def 100644 --- a/runtime/dart_vm.h +++ b/runtime/dart_vm.h @@ -173,8 +173,8 @@ class DartVM { static std::shared_ptr Create( Settings settings, - fml::RefPtr vm_snapshot, - fml::RefPtr isolate_snapshot, + fml::RefPtr vm_snapshot, + fml::RefPtr isolate_snapshot, std::shared_ptr isolate_name_server); DartVM(std::shared_ptr data, diff --git a/runtime/dart_vm_data.cc b/runtime/dart_vm_data.cc index a0287eba09f..816d428f089 100644 --- a/runtime/dart_vm_data.cc +++ b/runtime/dart_vm_data.cc @@ -8,8 +8,8 @@ namespace flutter { std::shared_ptr DartVMData::Create( Settings settings, - fml::RefPtr vm_snapshot, - fml::RefPtr isolate_snapshot) { + fml::RefPtr vm_snapshot, + fml::RefPtr isolate_snapshot) { if (!vm_snapshot || !vm_snapshot->IsValid()) { // Caller did not provide a valid VM snapshot. Attempt to infer one // from the settings. diff --git a/runtime/dart_vm_data.h b/runtime/dart_vm_data.h index 49ddd316899..f614a24ad0b 100644 --- a/runtime/dart_vm_data.h +++ b/runtime/dart_vm_data.h @@ -37,8 +37,8 @@ class DartVMData { /// static std::shared_ptr Create( Settings settings, - fml::RefPtr vm_snapshot, - fml::RefPtr isolate_snapshot); + fml::RefPtr vm_snapshot, + fml::RefPtr isolate_snapshot); //---------------------------------------------------------------------------- /// @brief Collect the DartVMData instance. diff --git a/runtime/dart_vm_lifecycle.cc b/runtime/dart_vm_lifecycle.cc index 41a3da606ab..e621f00655d 100644 --- a/runtime/dart_vm_lifecycle.cc +++ b/runtime/dart_vm_lifecycle.cc @@ -42,8 +42,8 @@ DartVMRef::~DartVMRef() { } DartVMRef DartVMRef::Create(Settings settings, - fml::RefPtr vm_snapshot, - fml::RefPtr isolate_snapshot) { + fml::RefPtr vm_snapshot, + fml::RefPtr isolate_snapshot) { std::scoped_lock lifecycle_lock(gVMMutex); if (!settings.leak_vm) { diff --git a/runtime/dart_vm_lifecycle.h b/runtime/dart_vm_lifecycle.h index 9a4fbfda45c..7c32882459f 100644 --- a/runtime/dart_vm_lifecycle.h +++ b/runtime/dart_vm_lifecycle.h @@ -29,8 +29,8 @@ class DartVMRef { public: [[nodiscard]] static DartVMRef Create( Settings settings, - fml::RefPtr vm_snapshot = nullptr, - fml::RefPtr isolate_snapshot = nullptr); + fml::RefPtr vm_snapshot = nullptr, + fml::RefPtr isolate_snapshot = nullptr); DartVMRef(const DartVMRef&) = default; diff --git a/shell/common/animator_unittests.cc b/shell/common/animator_unittests.cc index 281f204fb86..ecb9e254a97 100644 --- a/shell/common/animator_unittests.cc +++ b/shell/common/animator_unittests.cc @@ -51,7 +51,7 @@ TEST_F(ShellTest, VSyncTargetTime) { fml::MessageLoop::EnsureInitializedForCurrentThread(); shell = Shell::Create( - task_runners, settings, + flutter::PlatformData(), task_runners, settings, [vsync_clock, &create_vsync_waiter](Shell& shell) { return ShellTestPlatformView::Create( shell, shell.GetTaskRunners(), vsync_clock, diff --git a/shell/common/engine.cc b/shell/common/engine.cc index 669a7cf8785..69b40b2c11c 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -63,7 +63,7 @@ Engine::Engine(Delegate& delegate, DartVM& vm, fml::RefPtr isolate_snapshot, TaskRunners task_runners, - const PlatformData platform_data, + const PlatformData& platform_data, Settings settings, std::unique_ptr animator, fml::WeakPtr io_manager, diff --git a/shell/common/engine.h b/shell/common/engine.h index bcda3d8aca7..ec5778f9907 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -347,7 +347,7 @@ class Engine final : public RuntimeDelegate, DartVM& vm, fml::RefPtr isolate_snapshot, TaskRunners task_runners, - const PlatformData platform_data, + const PlatformData& platform_data, Settings settings, std::unique_ptr animator, fml::WeakPtr io_manager, diff --git a/shell/common/shell.cc b/shell/common/shell.cc index fbf1e22cc89..e64573a45bb 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -40,13 +40,14 @@ constexpr char kTypeKey[] = "type"; constexpr char kFontChange[] = "fontsChange"; namespace { + std::unique_ptr CreateEngine( Engine::Delegate& delegate, const PointerDataDispatcherMaker& dispatcher_maker, DartVM& vm, fml::RefPtr isolate_snapshot, TaskRunners task_runners, - const PlatformData platform_data, + const PlatformData& platform_data, Settings settings, std::unique_ptr animator, fml::WeakPtr io_manager, @@ -66,12 +67,111 @@ std::unique_ptr CreateEngine( snapshot_delegate, // volatile_path_tracker); } + +void Tokenize(const std::string& input, + std::vector* results, + char delimiter) { + std::istringstream ss(input); + std::string token; + while (std::getline(ss, token, delimiter)) { + results->push_back(token); + } +} + +// Though there can be multiple shells, some settings apply to all components in +// the process. These have to be setup before the shell or any of its +// sub-components can be initialized. In a perfect world, this would be empty. +// TODO(chinmaygarde): The unfortunate side effect of this call is that settings +// that cause shell initialization failures will still lead to some of their +// settings being applied. +void PerformInitializationTasks(Settings& settings) { + { + fml::LogSettings log_settings; + log_settings.min_log_level = + settings.verbose_logging ? fml::LOG_INFO : fml::LOG_ERROR; + fml::SetLogSettings(log_settings); + } + + static std::once_flag gShellSettingsInitialization = {}; + std::call_once(gShellSettingsInitialization, [&settings] { + if (settings.engine_start_timestamp.count() == 0) { + settings.engine_start_timestamp = + std::chrono::microseconds(Dart_TimelineGetMicros()); + } + + tonic::SetLogHandler( + [](const char* message) { FML_LOG(ERROR) << message; }); + + if (settings.trace_skia) { + InitSkiaEventTracer(settings.trace_skia); + } + + if (!settings.trace_allowlist.empty()) { + std::vector prefixes; + Tokenize(settings.trace_allowlist, &prefixes, ','); + fml::tracing::TraceSetAllowlist(prefixes); + } + + if (!settings.skia_deterministic_rendering_on_cpu) { + SkGraphics::Init(); + } else { + FML_DLOG(INFO) << "Skia deterministic rendering is enabled."; + } + + if (settings.icu_initialization_required) { + if (settings.icu_data_path.size() != 0) { + fml::icu::InitializeICU(settings.icu_data_path); + } else if (settings.icu_mapper) { + fml::icu::InitializeICUFromMapping(settings.icu_mapper()); + } else { + FML_DLOG(WARNING) << "Skipping ICU initialization in the shell."; + } + } + }); + + PersistentCache::SetCacheSkSL(settings.cache_sksl); +} + } // namespace +std::unique_ptr Shell::Create( + const PlatformData& platform_data, + TaskRunners task_runners, + Settings settings, + const Shell::CreateCallback& on_create_platform_view, + const Shell::CreateCallback& on_create_rasterizer) { + // This must come first as it initializes tracing. + PerformInitializationTasks(settings); + + TRACE_EVENT0("flutter", "Shell::Create"); + + // Always use the `vm_snapshot` and `isolate_snapshot` provided by the + // settings to launch the VM. If the VM is already running, the snapshot + // arguments are ignored. + auto vm_snapshot = DartSnapshot::VMSnapshotFromSettings(settings); + auto isolate_snapshot = DartSnapshot::IsolateSnapshotFromSettings(settings); + auto vm = DartVMRef::Create(settings, vm_snapshot, isolate_snapshot); + FML_CHECK(vm) << "Must be able to initialize the VM."; + + // If the settings did not specify an `isolate_snapshot`, fall back to the + // one the VM was launched with. + if (!isolate_snapshot) { + isolate_snapshot = vm->GetVMData()->GetIsolateSnapshot(); + } + return CreateWithSnapshot(std::move(platform_data), // + std::move(task_runners), // + std::move(settings), // + std::move(vm), // + std::move(isolate_snapshot), // + std::move(on_create_platform_view), // + std::move(on_create_rasterizer), // + CreateEngine); +} + std::unique_ptr Shell::CreateShellOnPlatformThread( DartVMRef vm, TaskRunners task_runners, - const PlatformData platform_data, + const PlatformData& platform_data, Settings settings, fml::RefPtr isolate_snapshot, const Shell::CreateCallback& on_create_platform_view, @@ -207,123 +307,23 @@ std::unique_ptr Shell::CreateShellOnPlatformThread( return shell; } -static void Tokenize(const std::string& input, - std::vector* results, - char delimiter) { - std::istringstream ss(input); - std::string token; - while (std::getline(ss, token, delimiter)) { - results->push_back(token); - } -} - -// Though there can be multiple shells, some settings apply to all components in -// the process. These have to be setup before the shell or any of its -// sub-components can be initialized. In a perfect world, this would be empty. -// TODO(chinmaygarde): The unfortunate side effect of this call is that settings -// that cause shell initialization failures will still lead to some of their -// settings being applied. -static void PerformInitializationTasks(Settings& settings) { - { - fml::LogSettings log_settings; - log_settings.min_log_level = - settings.verbose_logging ? fml::LOG_INFO : fml::LOG_ERROR; - fml::SetLogSettings(log_settings); - } - - static std::once_flag gShellSettingsInitialization = {}; - std::call_once(gShellSettingsInitialization, [&settings] { - if (settings.engine_start_timestamp.count() == 0) { - settings.engine_start_timestamp = - std::chrono::microseconds(Dart_TimelineGetMicros()); - } - - tonic::SetLogHandler( - [](const char* message) { FML_LOG(ERROR) << message; }); - - if (settings.trace_skia) { - InitSkiaEventTracer(settings.trace_skia); - } - - if (!settings.trace_allowlist.empty()) { - std::vector prefixes; - Tokenize(settings.trace_allowlist, &prefixes, ','); - fml::tracing::TraceSetAllowlist(prefixes); - } - - if (!settings.skia_deterministic_rendering_on_cpu) { - SkGraphics::Init(); - } else { - FML_DLOG(INFO) << "Skia deterministic rendering is enabled."; - } - - if (settings.icu_initialization_required) { - if (settings.icu_data_path.size() != 0) { - fml::icu::InitializeICU(settings.icu_data_path); - } else if (settings.icu_mapper) { - fml::icu::InitializeICUFromMapping(settings.icu_mapper()); - } else { - FML_DLOG(WARNING) << "Skipping ICU initialization in the shell."; - } - } - }); -} - -std::unique_ptr Shell::Create( +std::unique_ptr Shell::CreateWithSnapshot( + const PlatformData& platform_data, TaskRunners task_runners, Settings settings, - const Shell::CreateCallback& on_create_platform_view, - const Shell::CreateCallback& on_create_rasterizer) { - return Shell::Create(std::move(task_runners), // - PlatformData{/* default platform data */}, // - std::move(settings), // - std::move(on_create_platform_view), // - std::move(on_create_rasterizer) // - ); -} - -std::unique_ptr Shell::Create( - TaskRunners task_runners, - const PlatformData platform_data, - Settings settings, - Shell::CreateCallback on_create_platform_view, - Shell::CreateCallback on_create_rasterizer) { - PerformInitializationTasks(settings); - PersistentCache::SetCacheSkSL(settings.cache_sksl); - - TRACE_EVENT0("flutter", "Shell::Create"); - - auto vm = DartVMRef::Create(settings); - FML_CHECK(vm) << "Must be able to initialize the VM."; - - auto vm_data = vm->GetVMData(); - - return Shell::Create(std::move(task_runners), // - std::move(platform_data), // - std::move(settings), // - vm_data->GetIsolateSnapshot(), // isolate snapshot - on_create_platform_view, // - on_create_rasterizer, // - std::move(vm), // - CreateEngine); -} - -std::unique_ptr Shell::Create( - TaskRunners task_runners, - const PlatformData platform_data, - Settings settings, + DartVMRef vm, fml::RefPtr isolate_snapshot, const Shell::CreateCallback& on_create_platform_view, const Shell::CreateCallback& on_create_rasterizer, - DartVMRef vm, const Shell::EngineCreateCallback& on_create_engine) { + // This must come first as it initializes tracing. PerformInitializationTasks(settings); - PersistentCache::SetCacheSkSL(settings.cache_sksl); - TRACE_EVENT0("flutter", "Shell::CreateWithSnapshots"); + TRACE_EVENT0("flutter", "Shell::CreateWithSnapshot"); - if (!task_runners.IsValid() || !on_create_platform_view || - !on_create_rasterizer) { + const bool callbacks_valid = + on_create_platform_view && on_create_rasterizer && on_create_engine; + if (!task_runners.IsValid() || !callbacks_valid) { return nullptr; } @@ -331,26 +331,28 @@ std::unique_ptr Shell::Create( std::unique_ptr shell; fml::TaskRunner::RunNowOrPostTask( task_runners.GetPlatformTaskRunner(), - fml::MakeCopyable([&latch, // - vm = std::move(vm), // - &shell, // - task_runners = std::move(task_runners), // - platform_data, // - settings, // - on_create_platform_view, // - on_create_rasterizer, // - &on_create_engine]() mutable { - auto isolate_snapshot = vm->GetVMData()->GetIsolateSnapshot(); - shell = CreateShellOnPlatformThread(std::move(vm), - std::move(task_runners), // - platform_data, // - settings, // - std::move(isolate_snapshot), // - on_create_platform_view, // - on_create_rasterizer, // - on_create_engine); - latch.Signal(); - })); + fml::MakeCopyable( + [&latch, // + &shell, // + task_runners = std::move(task_runners), // + platform_data = std::move(platform_data), // + settings = std::move(settings), // + vm = std::move(vm), // + isolate_snapshot = std::move(isolate_snapshot), // + on_create_platform_view = std::move(on_create_platform_view), // + on_create_rasterizer = std::move(on_create_rasterizer), // + on_create_engine = std::move(on_create_engine)]() mutable { + shell = CreateShellOnPlatformThread( + std::move(vm), // + std::move(task_runners), // + std::move(platform_data), // + std::move(settings), // + std::move(isolate_snapshot), // + std::move(on_create_platform_view), // + std::move(on_create_rasterizer), // + std::move(on_create_engine)); + latch.Signal(); + })); latch.Wait(); return shell; } @@ -479,15 +481,15 @@ std::unique_ptr Shell::Spawn( const CreateCallback& on_create_platform_view, const CreateCallback& on_create_rasterizer) const { FML_DCHECK(task_runners_.IsValid()); - std::unique_ptr result(Shell::Create( - task_runners_, PlatformData{}, GetSettings(), + std::unique_ptr result(CreateWithSnapshot( + PlatformData{}, task_runners_, GetSettings(), vm_, vm_->GetVMData()->GetIsolateSnapshot(), on_create_platform_view, - on_create_rasterizer, vm_, + on_create_rasterizer, [engine = this->engine_.get()]( Engine::Delegate& delegate, const PointerDataDispatcherMaker& dispatcher_maker, DartVM& vm, fml::RefPtr isolate_snapshot, - TaskRunners task_runners, const PlatformData platform_data, + TaskRunners task_runners, const PlatformData& platform_data, Settings settings, std::unique_ptr animator, fml::WeakPtr io_manager, fml::RefPtr unref_queue, diff --git a/shell/common/shell.h b/shell/common/shell.h index fab937891f8..a26c6cf53f6 100644 --- a/shell/common/shell.h +++ b/shell/common/shell.h @@ -30,6 +30,7 @@ #include "flutter/lib/ui/volatile_path_tracker.h" #include "flutter/lib/ui/window/platform_message.h" #include "flutter/runtime/dart_vm_lifecycle.h" +#include "flutter/runtime/platform_data.h" #include "flutter/runtime/service_protocol.h" #include "flutter/shell/common/animator.h" #include "flutter/shell/common/display_manager.h" @@ -104,7 +105,7 @@ class Shell final : public PlatformView::Delegate, DartVM& vm, fml::RefPtr isolate_snapshot, TaskRunners task_runners, - const PlatformData platform_data, + const PlatformData& platform_data, Settings settings, std::unique_ptr animator, fml::WeakPtr io_manager, @@ -119,6 +120,9 @@ class Shell final : public PlatformView::Delegate, /// called on the appropriate threads before this method returns. /// If this is the first instance of a shell in the process, this /// call also bootstraps the Dart VM. + /// @note The root isolate which will run this Shell's Dart code takes + /// its instructions from the passed in settings. This allows + /// embedders to host multiple Shells with different Dart code. /// /// @param[in] task_runners The task runners /// @param[in] settings The settings @@ -140,70 +144,12 @@ class Shell final : public PlatformView::Delegate, /// immediately after getting a pointer to it. /// static std::unique_ptr Create( + const PlatformData& platform_data, TaskRunners task_runners, Settings settings, const CreateCallback& on_create_platform_view, const CreateCallback& on_create_rasterizer); - //---------------------------------------------------------------------------- - /// @brief Creates a shell instance using the provided settings. The - /// callbacks to create the various shell subcomponents will be - /// called on the appropriate threads before this method returns. - /// Unlike the simpler variant of this factory method, this method - /// allows for specification of window data. If this is the first - /// instance of a shell in the process, this call also bootstraps - /// the Dart VM. - /// - /// @param[in] task_runners The task runners - /// @param[in] platform_data The default data for setting up - /// ui.Window that attached to this - /// intance. - /// @param[in] settings The settings - /// @param[in] on_create_platform_view The callback that must return a - /// platform view. This will be called on - /// the platform task runner before this - /// method returns. - /// @param[in] on_create_rasterizer That callback that must provide a - /// valid rasterizer. This will be called - /// on the render task runner before this - /// method returns. - /// - /// @return A full initialized shell if the settings and callbacks are - /// valid. The root isolate has been created but not yet launched. - /// It may be launched by obtaining the engine weak pointer and - /// posting a task onto the UI task runner with a valid run - /// configuration to run the isolate. The embedder must always - /// check the validity of the shell (using the IsSetup call) - /// immediately after getting a pointer to it. - /// - static std::unique_ptr Create( - TaskRunners task_runners, - const PlatformData platform_data, - Settings settings, - CreateCallback on_create_platform_view, - CreateCallback on_create_rasterizer); - - //---------------------------------------------------------------------------- - /// @brief Creates a shell instance using the provided settings. - /// @details This version of Create can take in a running DartVMRef and a - /// function that defines how the Shell's Engine should be - /// created. - /// @param[in] vm A running DartVMRef where this Shell's Dart - /// code will be executed. - /// @param[in] on_create_engine A function that creates an Engine during - /// initialization. - /// @see Shell::Create - /// - static std::unique_ptr Create( - TaskRunners task_runners, - const PlatformData platform_data, - Settings settings, - fml::RefPtr isolate_snapshot, - const CreateCallback& on_create_platform_view, - const CreateCallback& on_create_rasterizer, - DartVMRef vm, - const EngineCreateCallback& on_create_engine); - //---------------------------------------------------------------------------- /// @brief Destroys the shell. This is a synchronous operation and /// synchronous barrier blocks are introduced on the various @@ -216,7 +162,7 @@ class Shell final : public PlatformView::Delegate, /// @brief Creates one Shell from another Shell where the created Shell /// takes the opportunity to share any internal components it can. /// This results is a Shell that has a smaller startup time cost - /// and a smaller memory footprint than an Shell created with a + /// and a smaller memory footprint than an Shell created with the /// Create function. /// /// The new Shell is returned in a running state so RunEngine @@ -472,12 +418,21 @@ class Shell final : public PlatformView::Delegate, static std::unique_ptr CreateShellOnPlatformThread( DartVMRef vm, TaskRunners task_runners, - const PlatformData platform_data, + const PlatformData& platform_data, Settings settings, fml::RefPtr isolate_snapshot, const Shell::CreateCallback& on_create_platform_view, const Shell::CreateCallback& on_create_rasterizer, const EngineCreateCallback& on_create_engine); + static std::unique_ptr CreateWithSnapshot( + const PlatformData& platform_data, + TaskRunners task_runners, + Settings settings, + DartVMRef vm, + fml::RefPtr isolate_snapshot, + const CreateCallback& on_create_platform_view, + const CreateCallback& on_create_rasterizer, + const EngineCreateCallback& on_create_engine); bool Setup(std::unique_ptr platform_view, std::unique_ptr engine, diff --git a/shell/common/shell_benchmarks.cc b/shell/common/shell_benchmarks.cc index 3842507f270..ec93f37d166 100644 --- a/shell/common/shell_benchmarks.cc +++ b/shell/common/shell_benchmarks.cc @@ -54,7 +54,7 @@ static void StartupAndShutdownShell(benchmark::State& state, thread_host->io_thread->GetTaskRunner()); shell = Shell::Create( - std::move(task_runners), settings, + flutter::PlatformData(), std::move(task_runners), settings, [](Shell& shell) { return std::make_unique(shell, shell.GetTaskRunners()); }, diff --git a/shell/common/shell_test.cc b/shell/common/shell_test.cc index 7c455f1b77c..0c753f52303 100644 --- a/shell/common/shell_test.cc +++ b/shell/common/shell_test.cc @@ -326,7 +326,7 @@ std::unique_ptr ShellTest::CreateShell( } }; return Shell::Create( - task_runners, settings, + flutter::PlatformData(), task_runners, settings, [vsync_clock, &create_vsync_waiter, shell_test_external_view_embedder](Shell& shell) { return ShellTestPlatformView::Create( diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index 70a28939c4a..57dfc523c8a 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -301,7 +301,7 @@ TEST_F(ShellTest, thread_host.ui_thread->GetTaskRunner(), thread_host.io_thread->GetTaskRunner()); auto shell = Shell::Create( - std::move(task_runners), settings, + flutter::PlatformData(), std::move(task_runners), settings, [](Shell& shell) { // This is unused in the platform view as we are not using the simulated // vsync mechanism. We should have better DI in the tests. diff --git a/shell/platform/android/android_shell_holder.cc b/shell/platform/android/android_shell_holder.cc index e83980f4bf4..9b2a79e03e9 100644 --- a/shell/platform/android/android_shell_holder.cc +++ b/shell/platform/android/android_shell_holder.cc @@ -124,8 +124,8 @@ AndroidShellHolder::AndroidShellHolder( }); shell_ = - Shell::Create(task_runners, // task runners - GetDefaultPlatformData(), // window data + Shell::Create(GetDefaultPlatformData(), // window data + task_runners, // task runners settings_, // settings on_create_platform_view, // platform view create callback on_create_rasterizer // rasterizer create callback diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 16751c9a440..63b077388c6 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -613,8 +613,8 @@ static void SetEntryPoint(flutter::Settings* settings, NSString* entrypoint, NSS // Create the shell. This is a blocking operation. std::unique_ptr shell = - flutter::Shell::Create(std::move(task_runners), // task runners - std::move(platformData), // window data + flutter::Shell::Create(std::move(platformData), // window data + std::move(task_runners), // task runners std::move(settings), // settings on_create_platform_view, // platform view creation on_create_rasterizer // rasterzier creation diff --git a/shell/platform/embedder/embedder_engine.cc b/shell/platform/embedder/embedder_engine.cc index c1e40cc41b0..d4a55fff95f 100644 --- a/shell/platform/embedder/embedder_engine.cc +++ b/shell/platform/embedder/embedder_engine.cc @@ -58,9 +58,9 @@ bool EmbedderEngine::LaunchShell() { FML_DLOG(ERROR) << "Shell already initialized"; } - shell_ = Shell::Create(task_runners_, shell_args_->settings, - shell_args_->on_create_platform_view, - shell_args_->on_create_rasterizer); + shell_ = Shell::Create( + flutter::PlatformData(), task_runners_, shell_args_->settings, + shell_args_->on_create_platform_view, shell_args_->on_create_rasterizer); // Reset the args no matter what. They will never be used to initialize a // shell again. diff --git a/shell/platform/fuchsia/flutter/component.cc b/shell/platform/fuchsia/flutter/component.cc index 727011f9f42..5eeefe754e0 100644 --- a/shell/platform/fuchsia/flutter/component.cc +++ b/shell/platform/fuchsia/flutter/component.cc @@ -407,6 +407,11 @@ Application::Application( return std::make_unique(isolate_instructions, 0, hold_snapshot); }; + isolate_snapshot_ = fml::MakeRefCounted( + std::make_shared(isolate_data, 0, + hold_snapshot), + std::make_shared(isolate_instructions, 0, + hold_snapshot)); } else { const int namespace_fd = application_data_directory_.get(); settings_.vm_snapshot_data = [namespace_fd]() { diff --git a/shell/platform/fuchsia/flutter/engine.cc b/shell/platform/fuchsia/flutter/engine.cc index c867be19564..0df1d1e5584 100644 --- a/shell/platform/fuchsia/flutter/engine.cc +++ b/shell/platform/fuchsia/flutter/engine.cc @@ -340,8 +340,8 @@ Engine::Engine(Delegate& delegate, { TRACE_EVENT0("flutter", "CreateShell"); shell_ = flutter::Shell::Create( - std::move(task_runners), // host task runners flutter::PlatformData(), // default window data + std::move(task_runners), // host task runners std::move(settings), // shell launch settings std::move(on_create_platform_view), // platform view create callback std::move(on_create_rasterizer) // rasterizer create callback diff --git a/shell/testing/tester_main.cc b/shell/testing/tester_main.cc index f2635402e93..3b55f04289b 100644 --- a/shell/testing/tester_main.cc +++ b/shell/testing/tester_main.cc @@ -144,7 +144,8 @@ int RunTester(const flutter::Settings& settings, return std::make_unique(shell); }; - auto shell = Shell::Create(task_runners, // + auto shell = Shell::Create(flutter::PlatformData(), // + task_runners, // settings, // on_create_platform_view, // on_create_rasterizer //