diff --git a/flow/skia_gpu_object.cc b/flow/skia_gpu_object.cc index bf1b0a1d2a779..4ac7d31ed8c3e 100644 --- a/flow/skia_gpu_object.cc +++ b/flow/skia_gpu_object.cc @@ -6,12 +6,16 @@ #include "flutter/fml/message_loop.h" +#include + namespace flutter { SkiaUnrefQueue::SkiaUnrefQueue(fml::RefPtr task_runner, - fml::TimeDelta delay) + fml::TimeDelta delay, + fml::WeakPtr context) : task_runner_(std::move(task_runner)), drain_delay_(delay), + context_(context), drain_pending_(false) {} SkiaUnrefQueue::~SkiaUnrefQueue() { @@ -39,6 +43,9 @@ void SkiaUnrefQueue::Drain() { for (SkRefCnt* skia_object : skia_objects) { skia_object->unref(); } + if (context_) { + context_->performDeferredCleanup(std::chrono::milliseconds(250)); + } } } // namespace flutter diff --git a/flow/skia_gpu_object.h b/flow/skia_gpu_object.h index 4c079af96ee95..77de3d7522478 100644 --- a/flow/skia_gpu_object.h +++ b/flow/skia_gpu_object.h @@ -12,6 +12,7 @@ #include "flutter/fml/memory/weak_ptr.h" #include "flutter/fml/task_runner.h" #include "third_party/skia/include/core/SkRefCnt.h" +#include "third_party/skia/include/gpu/GrContext.h" namespace flutter { @@ -31,12 +32,14 @@ class SkiaUnrefQueue : public fml::RefCountedThreadSafe { private: const fml::RefPtr task_runner_; const fml::TimeDelta drain_delay_; + const fml::WeakPtr context_; std::mutex mutex_; std::deque objects_; bool drain_pending_; SkiaUnrefQueue(fml::RefPtr task_runner, - fml::TimeDelta delay); + fml::TimeDelta delay, + fml::WeakPtr context); ~SkiaUnrefQueue(); diff --git a/shell/common/shell_io_manager.cc b/shell/common/shell_io_manager.cc index f1155c2e883a0..3817b72e89838 100644 --- a/shell/common/shell_io_manager.cc +++ b/shell/common/shell_io_manager.cc @@ -52,7 +52,8 @@ ShellIOManager::ShellIOManager( : nullptr), unref_queue_(fml::MakeRefCounted( std::move(unref_queue_task_runner), - fml::TimeDelta::FromMilliseconds(250))), + fml::TimeDelta::FromMilliseconds(250), + resource_context_weak_factory_->GetWeakPtr())), weak_factory_(this) { if (!resource_context_) { #ifndef OS_FUCHSIA