diff --git a/shell/platform/fuchsia/flutter/engine.cc b/shell/platform/fuchsia/flutter/engine.cc index 4ef7e620615d5..8acdbd3cd78d8 100644 --- a/shell/platform/fuchsia/flutter/engine.cc +++ b/shell/platform/fuchsia/flutter/engine.cc @@ -201,6 +201,12 @@ Engine::Engine(Delegate& delegate, }); }; + // Launch the engine in the appropriate configuration. + // Note: this initializes the Asset Manager on the global PersistantCache + // so it must be called before WarmupSkps() is called below. + auto run_configuration = flutter::RunConfiguration::InferFromSettings( + settings, task_runners.GetIOTaskRunner()); + // Setup the callback that will instantiate the platform view. flutter::Shell::CreateCallback on_create_platform_view = fml::MakeCopyable( @@ -375,10 +381,6 @@ Engine::Engine(Delegate& delegate, }; } - // Launch the engine in the appropriate configuration. - auto run_configuration = flutter::RunConfiguration::InferFromSettings( - shell_->GetSettings(), shell_->GetTaskRunners().GetIOTaskRunner()); - auto on_run_failure = [weak = weak_factory_.GetWeakPtr()]() { // The engine could have been killed by the caller right after the // constructor was called but before it could run on the UI thread. @@ -647,7 +649,7 @@ void Engine::WarmupSkps(fml::BasicTaskRunner* concurrent_task_runner, // tell concurrent task runner to deserialize all skps available from // the asset manager - concurrent_task_runner->PostTask([&raster_task_runner, skp_warmup_surface, + concurrent_task_runner->PostTask([raster_task_runner, skp_warmup_surface, &surface_producer]() { TRACE_DURATION("flutter", "DeserializeSkps"); std::vector> skp_mappings = diff --git a/shell/platform/fuchsia/flutter/tests/engine_unittests.cc b/shell/platform/fuchsia/flutter/tests/engine_unittests.cc index d3a78b697fec8..95cf266384c3c 100644 --- a/shell/platform/fuchsia/flutter/tests/engine_unittests.cc +++ b/shell/platform/fuchsia/flutter/tests/engine_unittests.cc @@ -34,14 +34,22 @@ class MockTaskRunner : public fml::BasicTaskRunner { virtual ~MockTaskRunner() {} void PostTask(const fml::closure& task) override { - task_count_++; - task(); + outstanding_tasks_.push(task); } int GetTaskCount() { return task_count_; } + void Run() { + while (!outstanding_tasks_.empty()) { + outstanding_tasks_.front()(); + outstanding_tasks_.pop(); + task_count_++; + } + } + private: int task_count_ = 0; + std::queue outstanding_tasks_; }; class EngineTest : public ::testing::Test { @@ -53,15 +61,16 @@ class EngineTest : public ::testing::Test { fuchsia::ui::scenic::SessionPtr session_ptr; scenic::Session session(std::move(session_ptr)); - VulkanSurfaceProducer surface_producer(&session); + surface_producer_ = std::make_unique(&session); Engine::WarmupSkps(&concurrent_task_runner_, &raster_task_runner_, - surface_producer); + *surface_producer_); } protected: MockTaskRunner concurrent_task_runner_; MockTaskRunner raster_task_runner_; + std::unique_ptr surface_producer_; }; TEST_F(EngineTest, SkpWarmup) { @@ -100,6 +109,8 @@ TEST_F(EngineTest, SkpWarmup) { PersistentCache::GetCacheForProcess()->SetAssetManager(asset_manager); WarmupSkps(); + concurrent_task_runner_.Run(); + raster_task_runner_.Run(); EXPECT_EQ(concurrent_task_runner_.GetTaskCount(), 1); EXPECT_EQ(raster_task_runner_.GetTaskCount(), 1);