Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 35f201d

Browse files
committed
[fuchsia] shader warmup fixes
This change contains a couple of changes that should have been in github.com/flutter/engine/commit/3105db8ee856ffef281d018774d21a6164c81236 but fell through the cracks First one lifts the initialization of the flutter::RunConfiguration so that the asset manager gets set on the persistant cache before the shader warmup happens. I'm not sure how this didnt end up in the first PR I think it got mangled during merge conflict resolution. no test coverage for that code because its in the middle of a 400 line constructor Second one fixes a race condition that the tests dont catch because the tests are single threaded. This change restructures the test that missed this bug so that it would have caught that bug and will catch comparable bugs.
1 parent 9ba6727 commit 35f201d

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

shell/platform/fuchsia/flutter/engine.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ Engine::Engine(Delegate& delegate,
201201
});
202202
};
203203

204+
// Launch the engine in the appropriate configuration.
205+
// Note: this initializes the Asset Manager on the global PersistantCache
206+
// so it must be called before WarmupSkps() is called below.
207+
auto run_configuration = flutter::RunConfiguration::InferFromSettings(
208+
settings, task_runners.GetIOTaskRunner());
209+
204210
// Setup the callback that will instantiate the platform view.
205211
flutter::Shell::CreateCallback<flutter::PlatformView>
206212
on_create_platform_view = fml::MakeCopyable(
@@ -375,10 +381,6 @@ Engine::Engine(Delegate& delegate,
375381
};
376382
}
377383

378-
// Launch the engine in the appropriate configuration.
379-
auto run_configuration = flutter::RunConfiguration::InferFromSettings(
380-
shell_->GetSettings(), shell_->GetTaskRunners().GetIOTaskRunner());
381-
382384
auto on_run_failure = [weak = weak_factory_.GetWeakPtr()]() {
383385
// The engine could have been killed by the caller right after the
384386
// constructor was called but before it could run on the UI thread.
@@ -647,7 +649,7 @@ void Engine::WarmupSkps(fml::BasicTaskRunner* concurrent_task_runner,
647649

648650
// tell concurrent task runner to deserialize all skps available from
649651
// the asset manager
650-
concurrent_task_runner->PostTask([&raster_task_runner, skp_warmup_surface,
652+
concurrent_task_runner->PostTask([raster_task_runner, skp_warmup_surface,
651653
&surface_producer]() {
652654
TRACE_DURATION("flutter", "DeserializeSkps");
653655
std::vector<std::unique_ptr<fml::Mapping>> skp_mappings =

shell/platform/fuchsia/flutter/tests/engine_unittests.cc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,22 @@ class MockTaskRunner : public fml::BasicTaskRunner {
3434
virtual ~MockTaskRunner() {}
3535

3636
void PostTask(const fml::closure& task) override {
37-
task_count_++;
38-
task();
37+
outstanding_tasks_.push(task);
3938
}
4039

4140
int GetTaskCount() { return task_count_; }
4241

42+
void Run() {
43+
while (!outstanding_tasks_.empty()) {
44+
outstanding_tasks_.front()();
45+
outstanding_tasks_.pop();
46+
task_count_++;
47+
}
48+
}
49+
4350
private:
4451
int task_count_ = 0;
52+
std::queue<const fml::closure> outstanding_tasks_;
4553
};
4654

4755
class EngineTest : public ::testing::Test {
@@ -53,15 +61,16 @@ class EngineTest : public ::testing::Test {
5361

5462
fuchsia::ui::scenic::SessionPtr session_ptr;
5563
scenic::Session session(std::move(session_ptr));
56-
VulkanSurfaceProducer surface_producer(&session);
64+
surface_producer_ = std::make_unique<VulkanSurfaceProducer>(&session);
5765

5866
Engine::WarmupSkps(&concurrent_task_runner_, &raster_task_runner_,
59-
surface_producer);
67+
*surface_producer_);
6068
}
6169

6270
protected:
6371
MockTaskRunner concurrent_task_runner_;
6472
MockTaskRunner raster_task_runner_;
73+
std::unique_ptr<VulkanSurfaceProducer> surface_producer_;
6574
};
6675

6776
TEST_F(EngineTest, SkpWarmup) {
@@ -100,6 +109,8 @@ TEST_F(EngineTest, SkpWarmup) {
100109
PersistentCache::GetCacheForProcess()->SetAssetManager(asset_manager);
101110

102111
WarmupSkps();
112+
concurrent_task_runner_.Run();
113+
raster_task_runner_.Run();
103114

104115
EXPECT_EQ(concurrent_task_runner_.GetTaskCount(), 1);
105116
EXPECT_EQ(raster_task_runner_.GetTaskCount(), 1);

0 commit comments

Comments
 (0)