forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accumulate a batch of Skia objects that will be destructed later on t…
…he IO thread (flutter#3888) See dart-lang/sdk#29971
- Loading branch information
1 parent
bd22943
commit dd2fb3c
Showing
4 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/common/threads.h" | ||
#include "flutter/lib/ui/painting/utils.h" | ||
|
||
namespace blink { | ||
|
||
namespace { | ||
|
||
constexpr ftl::TimeDelta kDrainDelay = ftl::TimeDelta::FromMilliseconds(250); | ||
|
||
} // anonymous namespace | ||
|
||
SkiaUnrefQueue::SkiaUnrefQueue() | ||
: drain_pending_(false) {} | ||
|
||
SkiaUnrefQueue SkiaUnrefQueue::instance_; | ||
|
||
SkiaUnrefQueue& SkiaUnrefQueue::Get() { | ||
return instance_; | ||
} | ||
|
||
void SkiaUnrefQueue::Unref(SkRefCnt* object) { | ||
ftl::MutexLocker lock(&mutex_); | ||
objects_.push_back(object); | ||
if (!drain_pending_) { | ||
drain_pending_ = true; | ||
Threads::IO()->PostDelayedTask([this] { Drain(); }, | ||
kDrainDelay); | ||
} | ||
} | ||
|
||
void SkiaUnrefQueue::Drain() { | ||
std::deque<SkRefCnt*> skia_objects; | ||
{ | ||
ftl::MutexLocker lock(&mutex_); | ||
objects_.swap(skia_objects); | ||
drain_pending_ = false; | ||
} | ||
|
||
for (SkRefCnt* skia_object : skia_objects) { | ||
skia_object->unref(); | ||
} | ||
} | ||
|
||
} // namespace blink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters