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

Commit a57f079

Browse files
author
Emmanuel Garcia
committed
Fix deadlock
1 parent 5f0d843 commit a57f079

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

shell/common/rasterizer.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ void Rasterizer::Setup(std::unique_ptr<Surface> surface) {
8181
}
8282
}
8383

84+
void Rasterizer::TeardownExternalViewEmbedder() {
85+
if (external_view_embedder_) {
86+
external_view_embedder_->Teardown();
87+
}
88+
}
89+
8490
void Rasterizer::Teardown() {
8591
auto context_switch =
8692
surface_ ? surface_->MakeRenderContextCurrent() : nullptr;
@@ -97,10 +103,6 @@ void Rasterizer::Teardown() {
97103
raster_thread_merger_->UnMergeNowIfLastOne();
98104
raster_thread_merger_->SetMergeUnmergeCallback(nullptr);
99105
}
100-
101-
if (external_view_embedder_) {
102-
external_view_embedder_->Teardown();
103-
}
104106
}
105107

106108
void Rasterizer::EnableThreadMergerIfNeeded() {

shell/common/rasterizer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ class Rasterizer final : public SnapshotDelegate {
140140
///
141141
void Teardown();
142142

143+
//----------------------------------------------------------------------------
144+
/// @brief Releases any resource used by the external view embedder.
145+
/// For example, overlay surfaces or Android views.
146+
/// On Android, this method post a task to the platform thread,
147+
/// and waits until it completes.
148+
void TeardownExternalViewEmbedder();
149+
143150
//----------------------------------------------------------------------------
144151
/// @brief Notifies the rasterizer that there is a low memory situation
145152
/// and it must purge as many unnecessary resources as possible.

shell/common/shell.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,11 @@ void Shell::OnPlatformViewDestroyed() {
885885
fml::TaskRunner::RunNowOrPostTask(task_runners_.GetRasterTaskRunner(),
886886
raster_task);
887887
latch.Wait();
888+
// On Android, the external view embedder posts a task to the platform thread,
889+
// and waits until it completes.
890+
// As a result, the platform thread must not be blocked prior to calling
891+
// this method.
892+
rasterizer_->TeardownExternalViewEmbedder();
888893
}
889894

890895
// |PlatformView::Delegate|

shell/platform/android/platform_view_android.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ std::unique_ptr<Surface> PlatformViewAndroid::CreateRenderingSurface() {
254254
std::shared_ptr<ExternalViewEmbedder>
255255
PlatformViewAndroid::CreateExternalViewEmbedder() {
256256
return std::make_shared<AndroidExternalViewEmbedder>(
257-
*android_context_, jni_facade_, surface_factory_,
258-
std::move(task_runners_));
257+
*android_context_, jni_facade_, surface_factory_, task_runners_);
259258
}
260259

261260
// |PlatformView|

0 commit comments

Comments
 (0)