Use the GPU thread for Android surface on-screen context lifecycle operations (#8234)

Fixes https://github.com/flutter/flutter/issues/29679
This commit is contained in:
Jason Simmons 2019-03-20 17:43:53 -07:00 committed by GitHub
parent 10e1addd8d
commit fa435385b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,15 +45,33 @@ void PlatformViewAndroid::NotifyCreated(
fml::RefPtr<AndroidNativeWindow> 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();
}
}