From d1d5497999fdfab94d4b7d5734b9bb5efa5dc700 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 15 May 2018 17:40:25 -0700 Subject: [PATCH] Drain any pending work on the IO thread before shutting down the platform view (#5272) iOS does not allow usage of OpenGL ES APIs when the app has been moved to the background. With this change, the shell will wait until pending IO thread tasks complete and the Skia unref queue is drained before proceeding with shutdown. See https://github.com/flutter/flutter/issues/17511 --- shell/common/shell.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 3359290f2..8f096d9a7 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -438,13 +438,23 @@ void Shell::OnPlatformViewDestroyed(const PlatformView& view) { fxl::AutoResetWaitableEvent latch; - auto gpu_task = [rasterizer = rasterizer_->GetWeakPtr(), &latch]() { + auto io_task = [io_manager = io_manager_.get(), &latch]() { + // Execute any pending Skia object deletions while GPU access is still + // allowed. + io_manager->GetSkiaUnrefQueue()->Drain(); + // Step 3: All done. Signal the latch that the platform thread is waiting + // on. + latch.Signal(); + }; + + auto gpu_task = [rasterizer = rasterizer_->GetWeakPtr(), + io_task_runner = task_runners_.GetIOTaskRunner(), + io_task]() { if (rasterizer) { rasterizer->Teardown(); } - // Step 2: All done. Signal the latch that the platform thread is waiting - // on. - latch.Signal(); + // Step 2: Next, tell the IO thread to complete its remaining work. + fml::TaskRunner::RunNowOrPostTask(io_task_runner, io_task); }; auto ui_task = [engine = engine_->GetWeakPtr(), -- GitLab