Delay default font manager to run concurrently with isolate setup (flutter/engine#29291)
* Delay default font manager to run concurrently with isolate setup * test
This commit is contained in:
@@ -95,6 +95,7 @@ std::weak_ptr<DartIsolate> DartIsolate::SpawnIsolate(
|
||||
GetIsolateGroupData().GetIsolateSnapshot(), //
|
||||
std::move(platform_configuration), //
|
||||
flags, //
|
||||
nullptr, //
|
||||
isolate_create_callback, //
|
||||
isolate_shutdown_callback, //
|
||||
dart_entrypoint, //
|
||||
@@ -118,6 +119,7 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRunningRootIsolate(
|
||||
fml::RefPtr<const DartSnapshot> isolate_snapshot,
|
||||
std::unique_ptr<PlatformConfiguration> platform_configuration,
|
||||
Flags isolate_flags,
|
||||
fml::closure root_isolate_create_callback,
|
||||
const fml::closure& isolate_create_callback,
|
||||
const fml::closure& isolate_shutdown_callback,
|
||||
std::optional<std::string> dart_entrypoint,
|
||||
@@ -184,6 +186,10 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRunningRootIsolate(
|
||||
settings.root_isolate_create_callback(*isolate.get());
|
||||
}
|
||||
|
||||
if (root_isolate_create_callback) {
|
||||
root_isolate_create_callback();
|
||||
}
|
||||
|
||||
if (!isolate->RunFromLibrary(dart_entrypoint_library, //
|
||||
dart_entrypoint, //
|
||||
settings.dart_entrypoint_args //
|
||||
|
||||
@@ -172,6 +172,13 @@ class DartIsolate : public UIDartState {
|
||||
/// @param[in] isolate_configuration The isolate configuration used to
|
||||
/// configure the isolate before
|
||||
/// invoking the entrypoint.
|
||||
/// @param[in] root_isolate_create_callback A callback called after the root
|
||||
/// isolate is created, _without_
|
||||
/// isolate scope. This gives the
|
||||
/// caller a chance to finish any
|
||||
/// setup before running the Dart
|
||||
/// program, and after any embedder
|
||||
/// callbacks in the settings object.
|
||||
/// @param[in] isolate_create_callback The isolate create callback. This
|
||||
/// will be called when the before the
|
||||
/// main Dart entrypoint is invoked in
|
||||
@@ -186,7 +193,7 @@ class DartIsolate : public UIDartState {
|
||||
/// isolate is still running at this
|
||||
/// point and an isolate scope is
|
||||
/// current.
|
||||
/// @param[in] context Engine-owned state which is
|
||||
/// @param[in] context Engine-owned state which is
|
||||
/// accessed by the root dart isolate.
|
||||
/// @param[in] spawning_isolate The isolate that is spawning the
|
||||
/// new isolate. See also
|
||||
@@ -202,6 +209,7 @@ class DartIsolate : public UIDartState {
|
||||
fml::RefPtr<const DartSnapshot> isolate_snapshot,
|
||||
std::unique_ptr<PlatformConfiguration> platform_configuration,
|
||||
Flags flags,
|
||||
fml::closure root_isolate_create_callback,
|
||||
const fml::closure& isolate_create_callback,
|
||||
const fml::closure& isolate_shutdown_callback,
|
||||
std::optional<std::string> dart_entrypoint,
|
||||
|
||||
@@ -59,6 +59,7 @@ TEST_F(DartIsolateTest, RootIsolateCreationAndShutdown) {
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
nullptr, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
nullptr, // root_isolate_create_callback
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
"main", // dart entrypoint
|
||||
@@ -97,6 +98,7 @@ TEST_F(DartIsolateTest, SpawnIsolate) {
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
nullptr, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
nullptr, // root_isolate_create_callback
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
"main", // dart entrypoint
|
||||
@@ -170,6 +172,7 @@ TEST_F(DartIsolateTest, IsolateShutdownCallbackIsInIsolateScope) {
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
nullptr, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
nullptr, // root_isolate_create_callback
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
"main", // dart entrypoint
|
||||
@@ -392,6 +395,7 @@ TEST_F(DartIsolateTest, CanCreateServiceIsolate) {
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
nullptr, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
nullptr, // root_isolate_create_callback
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
"main", // dart entrypoint
|
||||
@@ -490,6 +494,7 @@ TEST_F(DartIsolateTest, InvalidLoadingUnitFails) {
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
nullptr, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
nullptr, // root_isolate_create_callback
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
"main", // dart entrypoint
|
||||
|
||||
@@ -64,6 +64,7 @@ static std::shared_ptr<DartIsolate> CreateAndRunRootIsolate(
|
||||
vm.GetIsolateSnapshot(), // isolate_snapshot
|
||||
{}, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
nullptr, // root isolate create callback
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback,
|
||||
entrypoint, // dart entrypoint
|
||||
|
||||
@@ -355,6 +355,7 @@ tonic::DartErrorHandleType RuntimeController::GetLastError() {
|
||||
|
||||
bool RuntimeController::LaunchRootIsolate(
|
||||
const Settings& settings,
|
||||
fml::closure root_isolate_create_callback,
|
||||
std::optional<std::string> dart_entrypoint,
|
||||
std::optional<std::string> dart_entrypoint_library,
|
||||
std::unique_ptr<IsolateConfiguration> isolate_configuration) {
|
||||
@@ -369,6 +370,7 @@ bool RuntimeController::LaunchRootIsolate(
|
||||
isolate_snapshot_, //
|
||||
std::make_unique<PlatformConfiguration>(this), //
|
||||
DartIsolate::Flags{}, //
|
||||
root_isolate_create_callback, //
|
||||
isolate_create_callback_, //
|
||||
isolate_shutdown_callback_, //
|
||||
dart_entrypoint, //
|
||||
|
||||
@@ -120,6 +120,12 @@ class RuntimeController : public PlatformConfigurationClient {
|
||||
/// Launch an isolate in that runtime controller instead.
|
||||
///
|
||||
/// @param[in] settings The per engine instance settings.
|
||||
/// @param[in] root_isolate_create_callback A callback invoked before the
|
||||
/// root isolate has launched the Dart
|
||||
/// program, but after it has been
|
||||
/// created. This is called without
|
||||
/// isolate scope, and after any root
|
||||
/// isolate callback in the settings.
|
||||
/// @param[in] dart_entrypoint The dart entrypoint. If
|
||||
/// `std::nullopt` or empty, `main` will
|
||||
/// be attempted.
|
||||
@@ -133,6 +139,7 @@ class RuntimeController : public PlatformConfigurationClient {
|
||||
///
|
||||
[[nodiscard]] bool LaunchRootIsolate(
|
||||
const Settings& settings,
|
||||
fml::closure root_isolate_create_callback,
|
||||
std::optional<std::string> dart_entrypoint,
|
||||
std::optional<std::string> dart_entrypoint_library,
|
||||
std::unique_ptr<IsolateConfiguration> isolate_configuration);
|
||||
|
||||
@@ -202,19 +202,22 @@ Engine::RunStatus Engine::Run(RunConfiguration configuration) {
|
||||
|
||||
UpdateAssetManager(configuration.GetAssetManager());
|
||||
|
||||
// If the embedding prefetched the default font manager, then set up the
|
||||
// font manager later in the engine launch process. This makes it less
|
||||
// likely that the setup will need to wait for the prefetch to complete.
|
||||
if (settings_.prefetched_default_font_manager) {
|
||||
SetupDefaultFontManager();
|
||||
}
|
||||
|
||||
if (runtime_controller_->IsRootIsolateRunning()) {
|
||||
return RunStatus::FailureAlreadyRunning;
|
||||
}
|
||||
|
||||
// If the embedding prefetched the default font manager, then set up the
|
||||
// font manager later in the engine launch process. This makes it less
|
||||
// likely that the setup will need to wait for the prefetch to complete.
|
||||
auto root_isolate_create_callback = [&]() {
|
||||
if (settings_.prefetched_default_font_manager) {
|
||||
SetupDefaultFontManager();
|
||||
}
|
||||
};
|
||||
|
||||
if (!runtime_controller_->LaunchRootIsolate(
|
||||
settings_, //
|
||||
root_isolate_create_callback, //
|
||||
configuration.GetEntrypoint(), //
|
||||
configuration.GetEntrypointLibrary(), //
|
||||
configuration.TakeIsolateConfiguration()) //
|
||||
|
||||
@@ -3093,8 +3093,7 @@ TEST_F(ShellTest, UserTagSetOnStartup) {
|
||||
TEST_F(ShellTest, PrefetchDefaultFontManager) {
|
||||
auto settings = CreateSettingsForFixture();
|
||||
settings.prefetched_default_font_manager = true;
|
||||
|
||||
auto shell = CreateShell(std::move(settings));
|
||||
std::unique_ptr<Shell> shell;
|
||||
|
||||
auto get_font_manager_count = [&] {
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
@@ -3109,8 +3108,17 @@ TEST_F(ShellTest, PrefetchDefaultFontManager) {
|
||||
latch.Wait();
|
||||
return font_manager_count;
|
||||
};
|
||||
size_t initial_font_manager_count = 0;
|
||||
settings.root_isolate_create_callback = [&](const auto& isolate) {
|
||||
ASSERT_GT(initial_font_manager_count, 0ul);
|
||||
// Should not have fetched the default font manager yet, since the root
|
||||
// isolate was only just created.
|
||||
ASSERT_EQ(get_font_manager_count(), initial_font_manager_count);
|
||||
};
|
||||
|
||||
size_t initial_font_manager_count = get_font_manager_count();
|
||||
shell = CreateShell(std::move(settings));
|
||||
|
||||
initial_font_manager_count = get_font_manager_count();
|
||||
|
||||
auto configuration = RunConfiguration::InferFromSettings(settings);
|
||||
configuration.SetEntrypoint("emptyMain");
|
||||
|
||||
@@ -130,6 +130,7 @@ std::unique_ptr<AutoIsolateShutdown> RunDartCodeInIsolateOnUITaskRunner(
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
nullptr, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
nullptr, // root isolate create callback
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
entrypoint, // entrypoint
|
||||
|
||||
@@ -36,6 +36,7 @@ TEST_F(DartState, IsShuttingDown) {
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
nullptr, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
nullptr, // root_isolate_create_callback
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
"main", // dart entrypoint
|
||||
|
||||
Reference in New Issue
Block a user