From fa435385b6b9f80080997dd38ad66bbe4bb0a152 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Wed, 20 Mar 2019 17:43:53 -0700 Subject: [PATCH] Use the GPU thread for Android surface on-screen context lifecycle operations (#8234) Fixes https://github.com/flutter/flutter/issues/29679 --- .../platform/android/platform_view_android.cc | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/shell/platform/android/platform_view_android.cc b/shell/platform/android/platform_view_android.cc index f31c08456..481713305 100644 --- a/shell/platform/android/platform_view_android.cc +++ b/shell/platform/android/platform_view_android.cc @@ -45,15 +45,33 @@ void PlatformViewAndroid::NotifyCreated( fml::RefPtr native_window) { if (android_surface_) { InstallFirstFrameCallback(); - android_surface_->SetNativeWindow(native_window); + + fml::AutoResetWaitableEvent latch; + fml::TaskRunner::RunNowOrPostTask( + task_runners_.GetGPUTaskRunner(), + [&latch, surface = android_surface_.get(), + native_window = std::move(native_window)]() { + surface->SetNativeWindow(native_window); + latch.Signal(); + }); + latch.Wait(); } + PlatformView::NotifyCreated(); } void PlatformViewAndroid::NotifyDestroyed() { PlatformView::NotifyDestroyed(); + if (android_surface_) { - android_surface_->TeardownOnScreenContext(); + fml::AutoResetWaitableEvent latch; + fml::TaskRunner::RunNowOrPostTask( + task_runners_.GetGPUTaskRunner(), + [&latch, surface = android_surface_.get()]() { + surface->TeardownOnScreenContext(); + latch.Signal(); + }); + latch.Wait(); } } -- GitLab