[Impeller] remove unref queue usage on Impeller. (flutter/engine#41050)

[Impeller] remove unref queue usage on Impeller.
This commit is contained in:
Jonah Williams
2023-04-11 09:49:04 -07:00
committed by GitHub
parent 0eec476411
commit e14c6ed93d
2 changed files with 15 additions and 3 deletions

View File

@@ -26,6 +26,10 @@ class UnrefQueue : public fml::RefCountedThreadSafe<UnrefQueue<T>> {
using ResourceContext = T;
void Unref(SkRefCnt* object) {
if (drain_immediate_) {
object->unref();
return;
}
std::scoped_lock lock(mutex_);
objects_.push_back(object);
if (!drain_pending_) {
@@ -36,6 +40,8 @@ class UnrefQueue : public fml::RefCountedThreadSafe<UnrefQueue<T>> {
}
void DeleteTexture(GrBackendTexture texture) {
// drain_immediate_ should only be used on Impeller.
FML_DCHECK(!drain_immediate_);
std::scoped_lock lock(mutex_);
textures_.push_back(texture);
if (!drain_pending_) {
@@ -75,17 +81,22 @@ class UnrefQueue : public fml::RefCountedThreadSafe<UnrefQueue<T>> {
std::deque<GrBackendTexture> textures_;
bool drain_pending_;
sk_sp<ResourceContext> context_;
// Enabled when there is an impeller context, which removes the usage of
// the queue altogether.
bool drain_immediate_;
// The `GrDirectContext* context` is only used for signaling Skia to
// performDeferredCleanup. It can be nullptr when such signaling is not needed
// (e.g., in unit tests).
UnrefQueue(fml::RefPtr<fml::TaskRunner> task_runner,
fml::TimeDelta delay,
sk_sp<ResourceContext> context = nullptr)
sk_sp<ResourceContext> context = nullptr,
bool drain_immediate = false)
: task_runner_(std::move(task_runner)),
drain_delay_(delay),
drain_pending_(false),
context_(context) {}
context_(context),
drain_immediate_(drain_immediate) {}
~UnrefQueue() {
// The ResourceContext must be deleted on the task runner thread.

View File

@@ -48,7 +48,8 @@ ShellIOManager::ShellIOManager(
unref_queue_(fml::MakeRefCounted<flutter::SkiaUnrefQueue>(
std::move(unref_queue_task_runner),
unref_queue_drain_delay,
resource_context_)),
resource_context_,
/*drain_immediate=*/!!impeller_context)),
is_gpu_disabled_sync_switch_(std::move(is_gpu_disabled_sync_switch)),
impeller_context_(std::move(impeller_context)),
weak_factory_(this) {