5#define FML_USED_ON_EMBEDDER
7#include "flutter/fml/raster_thread_merger.h"
11#include "flutter/fml/message_loop_impl.h"
18 MakeRefCounted<SharedThreadMerger>(platform_queue_id, gpu_queue_id),
22RasterThreadMerger::RasterThreadMerger(
26 : platform_queue_id_(platform_queue_id),
27 gpu_queue_id_(gpu_queue_id),
28 shared_merger_(std::move(shared_merger)) {}
36 return shared_merger_;
44 if (parent_merger && parent_merger->platform_queue_id_ == platform_id &&
45 parent_merger->gpu_queue_id_ == raster_id) {
47 return fml::MakeRefCounted<RasterThreadMerger>(shared_merger, platform_id,
50 return fml::MakeRefCounted<RasterThreadMerger>(platform_id, raster_id);
55 std::scoped_lock lock(mutex_);
56 if (TaskQueuesAreSame()) {
59 if (!IsEnabledUnSafe()) {
62 FML_DCHECK(lease_term > 0) <<
"lease_term should be positive.";
64 if (IsMergedUnSafe()) {
65 merged_condition_.notify_one();
69 bool success = shared_merger_->MergeWithLease(
this, lease_term);
70 if (success && merge_unmerge_callback_ !=
nullptr) {
71 merge_unmerge_callback_();
74 merged_condition_.notify_one();
78 std::scoped_lock lock(mutex_);
80 if (TaskQueuesAreSame()) {
83 if (!IsEnabledUnSafe()) {
86 bool success = shared_merger_->UnMergeNowIfLastOne(
this);
87 if (success && merge_unmerge_callback_ !=
nullptr) {
88 merge_unmerge_callback_();
97 std::scoped_lock lock(mutex_);
99 if (IsMergedUnSafe()) {
107 FML_DCHECK(lease_term > 0) <<
"lease_term should be positive.";
108 if (TaskQueuesAreSame()) {
111 std::scoped_lock lock(mutex_);
112 if (!IsEnabledUnSafe()) {
115 shared_merger_->ExtendLeaseTo(
this, lease_term);
119 std::scoped_lock lock(mutex_);
120 return IsMergedUnSafe();
124 std::scoped_lock lock(mutex_);
125 shared_merger_->SetEnabledUnSafe(
true);
129 std::scoped_lock lock(mutex_);
130 shared_merger_->SetEnabledUnSafe(
false);
134 std::scoped_lock lock(mutex_);
135 return IsEnabledUnSafe();
138bool RasterThreadMerger::IsEnabledUnSafe()
const {
139 return shared_merger_->IsEnabledUnSafe();
142bool RasterThreadMerger::IsMergedUnSafe()
const {
143 return TaskQueuesAreSame() || shared_merger_->IsMergedUnSafe();
146bool RasterThreadMerger::TaskQueuesAreSame()
const {
147 return platform_queue_id_ == gpu_queue_id_;
151 if (TaskQueuesAreSame()) {
155 std::unique_lock<std::mutex> lock(mutex_);
156 merged_condition_.wait(lock, [&] {
return IsMergedUnSafe(); });
160 if (TaskQueuesAreSame()) {
163 std::scoped_lock lock(mutex_);
164 if (!IsMergedUnSafe()) {
167 if (!IsEnabledUnSafe()) {
170 bool unmerged_after_decrement = shared_merger_->DecrementLease(
this);
171 if (unmerged_after_decrement) {
172 if (merge_unmerge_callback_ !=
nullptr) {
173 merge_unmerge_callback_();
static TaskQueueId GetCurrentTaskQueueId()
bool IsOnPlatformThread() const
static fml::RefPtr< fml::RasterThreadMerger > CreateOrShareThreadMerger(const fml::RefPtr< fml::RasterThreadMerger > &parent_merger, TaskQueueId platform_id, TaskQueueId raster_id)
void SetMergeUnmergeCallback(const fml::closure &callback)
void UnMergeNowIfLastOne()
void ExtendLeaseTo(size_t lease_term)
void MergeWithLease(size_t lease_term)
const fml::RefPtr< SharedThreadMerger > & GetSharedRasterThreadMerger() const
bool IsOnRasterizingThread()
RasterThreadStatus DecrementLease()
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_CHECK(condition)
#define FML_DCHECK(condition)
std::function< void()> closure