forked from firka/flutter
Fixed image generator registry usage with spawn. (flutter/engine#31622)
This commit is contained in:
@@ -50,11 +50,12 @@ std::unique_ptr<RuntimeController> RuntimeController::Spawn(
|
||||
const fml::closure& p_isolate_shutdown_callback,
|
||||
std::shared_ptr<const fml::Mapping> p_persistent_isolate_data,
|
||||
fml::WeakPtr<IOManager> io_manager,
|
||||
fml::WeakPtr<ImageDecoder> image_decoder) const {
|
||||
fml::WeakPtr<ImageDecoder> image_decoder,
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry) const {
|
||||
UIDartState::Context spawned_context{
|
||||
context_.task_runners, context_.snapshot_delegate,
|
||||
std::move(io_manager), context_.unref_queue,
|
||||
std::move(image_decoder), context_.image_generator_registry,
|
||||
std::move(image_decoder), std::move(image_generator_registry),
|
||||
advisory_script_uri, advisory_script_entrypoint,
|
||||
context_.volatile_path_tracker};
|
||||
auto result =
|
||||
|
||||
@@ -104,7 +104,8 @@ class RuntimeController : public PlatformConfigurationClient {
|
||||
const fml::closure& isolate_shutdown_callback,
|
||||
std::shared_ptr<const fml::Mapping> persistent_isolate_data,
|
||||
fml::WeakPtr<IOManager> io_manager,
|
||||
fml::WeakPtr<ImageDecoder> image_decoder) const;
|
||||
fml::WeakPtr<ImageDecoder> image_decoder,
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry) const;
|
||||
|
||||
// |PlatformConfigurationClient|
|
||||
~RuntimeController() override;
|
||||
@@ -555,6 +556,10 @@ class RuntimeController : public PlatformConfigurationClient {
|
||||
return context_.snapshot_delegate;
|
||||
}
|
||||
|
||||
std::weak_ptr<const DartIsolate> GetRootIsolate() const {
|
||||
return root_isolate_;
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Constructor for Mocks.
|
||||
RuntimeController(RuntimeDelegate& p_client, TaskRunners task_runners);
|
||||
|
||||
@@ -119,16 +119,16 @@ std::unique_ptr<Engine> Engine::Spawn(
|
||||
/*font_collection=*/font_collection_,
|
||||
/*runtime_controller=*/nullptr);
|
||||
result->runtime_controller_ = runtime_controller_->Spawn(
|
||||
*result, // runtime delegate
|
||||
settings.advisory_script_uri, // advisory script uri
|
||||
settings.advisory_script_entrypoint, // advisory script entrypoint
|
||||
settings.idle_notification_callback, // idle notification callback
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
settings.persistent_isolate_data, // persistent isolate data
|
||||
io_manager, // io_manager
|
||||
result->GetImageDecoderWeakPtr() // imageDecoder
|
||||
);
|
||||
/*p_client=*/*result,
|
||||
/*advisory_script_uri=*/settings.advisory_script_uri,
|
||||
/*advisory_script_entrypoint=*/settings.advisory_script_entrypoint,
|
||||
/*idle_notification_callback=*/settings.idle_notification_callback,
|
||||
/*isolate_create_callback=*/settings.isolate_create_callback,
|
||||
/*isolate_shutdown_callback=*/settings.isolate_shutdown_callback,
|
||||
/*persistent_isolate_data=*/settings.persistent_isolate_data,
|
||||
/*io_manager=*/io_manager,
|
||||
/*image_decoder=*/result->GetImageDecoderWeakPtr(),
|
||||
/*image_generator_registry=*/result->GetImageGeneratorRegistry());
|
||||
result->initial_route_ = initial_route;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -3125,6 +3125,54 @@ TEST_F(ShellTest, IOManagerInSpawnedShellIsNotNullAfterParentShellDestroyed) {
|
||||
DestroyShell(std::move(spawn));
|
||||
}
|
||||
|
||||
TEST_F(ShellTest, ImageGeneratorRegistryNotNullAfterParentShellDestroyed) {
|
||||
auto settings = CreateSettingsForFixture();
|
||||
auto shell = CreateShell(settings);
|
||||
ASSERT_TRUE(ValidateShell(shell.get()));
|
||||
|
||||
std::unique_ptr<Shell> spawn;
|
||||
|
||||
PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell, &settings,
|
||||
&spawn] {
|
||||
auto second_configuration = RunConfiguration::InferFromSettings(settings);
|
||||
ASSERT_TRUE(second_configuration.IsValid());
|
||||
second_configuration.SetEntrypoint("emptyMain");
|
||||
const std::string initial_route("/foo");
|
||||
MockPlatformViewDelegate platform_view_delegate;
|
||||
auto child = shell->Spawn(
|
||||
std::move(second_configuration), initial_route,
|
||||
[&platform_view_delegate](Shell& shell) {
|
||||
auto result = std::make_unique<MockPlatformView>(
|
||||
platform_view_delegate, shell.GetTaskRunners());
|
||||
ON_CALL(*result, CreateRenderingSurface())
|
||||
.WillByDefault(::testing::Invoke(
|
||||
[] { return std::make_unique<MockSurface>(); }));
|
||||
return result;
|
||||
},
|
||||
[](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
|
||||
spawn = std::move(child);
|
||||
});
|
||||
|
||||
PostSync(spawn->GetTaskRunners().GetUITaskRunner(), [&spawn] {
|
||||
std::shared_ptr<const DartIsolate> isolate =
|
||||
spawn->GetEngine()->GetRuntimeController()->GetRootIsolate().lock();
|
||||
ASSERT_TRUE(isolate);
|
||||
ASSERT_TRUE(isolate->GetImageGeneratorRegistry());
|
||||
});
|
||||
|
||||
// Destroy the parent shell.
|
||||
DestroyShell(std::move(shell));
|
||||
|
||||
PostSync(spawn->GetTaskRunners().GetUITaskRunner(), [&spawn] {
|
||||
std::shared_ptr<const DartIsolate> isolate =
|
||||
spawn->GetEngine()->GetRuntimeController()->GetRootIsolate().lock();
|
||||
ASSERT_TRUE(isolate);
|
||||
ASSERT_TRUE(isolate->GetImageGeneratorRegistry());
|
||||
});
|
||||
// Destroy the child shell.
|
||||
DestroyShell(std::move(spawn));
|
||||
}
|
||||
|
||||
TEST_F(ShellTest, UpdateAssetResolverByTypeReplaces) {
|
||||
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
|
||||
Settings settings = CreateSettingsForFixture();
|
||||
|
||||
Reference in New Issue
Block a user