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

Commit 46477d8

Browse files
committed
[fuchsia][shader warmup] fix for fxbug.dev/90387
Warmup surface was being initialized on the platform thread rather than the raster thread which was causing races in the skia cache, this change just moves the warmup surface intiialization to the raster thread. This change also addresses another minor problem where invoking shader warmup with 0 skps would drop the callback on the floor and that would cause the dart future to hang forever. Simply invoke the dart future if no SKP's are provided.
1 parent e444009 commit 46477d8

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

shell/platform/fuchsia/flutter/engine.cc

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -861,24 +861,10 @@ void Engine::WarmupSkps(
861861
std::shared_ptr<flutter::AssetManager> asset_manager,
862862
std::optional<const std::vector<std::string>> skp_names,
863863
std::optional<std::function<void(uint32_t)>> completion_callback) {
864-
// We use a raw pointer here because we want to keep this alive until all gpu
865-
// work is done and the callbacks skia takes for this are function pointers
866-
// so we are unable to use a lambda that captures the smart pointer.
867-
SurfaceProducerSurface* skp_warmup_surface =
868-
surface_producer->ProduceOffscreenSurface(size).release();
869-
if (!skp_warmup_surface) {
870-
FML_LOG(ERROR) << "Failed to create offscreen warmup surface";
871-
// Tell client that zero shaders were warmed up because warmup failed.
872-
if (completion_callback.has_value() && completion_callback.value()) {
873-
completion_callback.value()(0);
874-
}
875-
return;
876-
}
877-
878864
// tell concurrent task runner to deserialize all skps available from
879865
// the asset manager
880-
concurrent_task_runner->PostTask([raster_task_runner, skp_warmup_surface,
881-
surface_producer, asset_manager, skp_names,
866+
concurrent_task_runner->PostTask([raster_task_runner, size, surface_producer,
867+
asset_manager, skp_names,
882868
completion_callback]() {
883869
TRACE_DURATION("flutter", "DeserializeSkps");
884870
std::vector<std::unique_ptr<fml::Mapping>> skp_mappings;
@@ -895,6 +881,15 @@ void Engine::WarmupSkps(
895881
skp_mappings = asset_manager->GetAsMappings(".*\\.skp$", "shaders");
896882
}
897883

884+
if (skp_mappings.size() == 0) {
885+
FML_LOG(WARNING)
886+
<< "Engine::WarmupSkps got zero SKP mappings, returning early";
887+
if (completion_callback.has_value() && completion_callback.value()) {
888+
completion_callback.value()(0);
889+
}
890+
return;
891+
}
892+
898893
size_t total_size = 0;
899894
for (auto& mapping : skp_mappings) {
900895
total_size += mapping->GetSize();
@@ -920,10 +915,25 @@ void Engine::WarmupSkps(
920915

921916
// Tell raster task runner to warmup have the compositor
922917
// context warm up the newly deserialized picture
923-
raster_task_runner->PostTask([skp_warmup_surface, picture,
924-
surface_producer, completion_callback, i,
918+
raster_task_runner->PostTask([picture, size, surface_producer,
919+
completion_callback, i,
925920
count = skp_mappings.size()] {
926921
TRACE_DURATION("flutter", "WarmupSkp");
922+
923+
// We use a raw pointer here because we want to keep this alive until
924+
// all gpu work is done and the callbacks skia takes for this are
925+
// function pointers so we are unable to use a lambda that captures the
926+
// smart pointer.
927+
static SurfaceProducerSurface* skp_warmup_surface =
928+
surface_producer->ProduceOffscreenSurface(size).release();
929+
if (!skp_warmup_surface) {
930+
FML_LOG(ERROR) << "Failed to create offscreen warmup surface";
931+
// Tell client that zero shaders were warmed up because warmup failed.
932+
if (completion_callback.has_value() && completion_callback.value()) {
933+
completion_callback.value()(0);
934+
}
935+
return;
936+
}
927937
skp_warmup_surface->GetSkiaSurface()->getCanvas()->drawPicture(picture);
928938

929939
if (i == count - 1) {

0 commit comments

Comments
 (0)