Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
fml::RasterThreadMerger Class Reference

#include <raster_thread_merger.h>

Inheritance diagram for fml::RasterThreadMerger:
fml::RefCountedThreadSafe< RasterThreadMerger > fml::internal::RefCountedThreadSafeBase

Public Member Functions

void MergeWithLease (size_t lease_term)
 
const fml::RefPtr< SharedThreadMerger > & GetSharedRasterThreadMerger () const
 
void UnMergeNowIfLastOne ()
 
void ExtendLeaseTo (size_t lease_term)
 
RasterThreadStatus DecrementLease ()
 
bool IsMerged ()
 
void WaitUntilMerged ()
 
bool IsOnRasterizingThread ()
 
bool IsOnPlatformThread () const
 
void Enable ()
 
void Disable ()
 
bool IsEnabled ()
 
void SetMergeUnmergeCallback (const fml::closure &callback)
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< RasterThreadMerger >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 

Static Public Member Functions

static fml::RefPtr< fml::RasterThreadMergerCreateOrShareThreadMerger (const fml::RefPtr< fml::RasterThreadMerger > &parent_merger, TaskQueueId platform_id, TaskQueueId raster_id)
 

Additional Inherited Members

- Protected Member Functions inherited from fml::RefCountedThreadSafe< RasterThreadMerger >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 

Detailed Description

This class is a client and proxy between the rasterizer and |SharedThreadMerger|. The multiple |RasterThreadMerger| instances with same owner_queue_id and same subsumed_queue_id share the same |SharedThreadMerger| instance. Whether they share the same inner instance is determined by |RasterThreadMerger::CreateOrShareThreadMerger| method.

Definition at line 31 of file raster_thread_merger.h.

Member Function Documentation

◆ CreateOrShareThreadMerger()

fml::RefPtr< fml::RasterThreadMerger > fml::RasterThreadMerger::CreateOrShareThreadMerger ( const fml::RefPtr< fml::RasterThreadMerger > &  parent_merger,
TaskQueueId  platform_id,
TaskQueueId  raster_id 
)
static

Creates a new merger from parent, share the inside shared_merger member when the platform_queue_id and raster_queue_id are same, otherwise create a new shared_merger instance

Definition at line 40 of file raster_thread_merger.cc.

43 {
44 if (parent_merger && parent_merger->platform_queue_id_ == platform_id &&
45 parent_merger->gpu_queue_id_ == raster_id) {
46 auto shared_merger = parent_merger->GetSharedRasterThreadMerger();
47 return fml::MakeRefCounted<RasterThreadMerger>(shared_merger, platform_id,
48 raster_id);
49 } else {
50 return fml::MakeRefCounted<RasterThreadMerger>(platform_id, raster_id);
51 }
52}
const fml::RefPtr< SharedThreadMerger > & GetSharedRasterThreadMerger() const

◆ DecrementLease()

RasterThreadStatus fml::RasterThreadMerger::DecrementLease ( )

Definition at line 159 of file raster_thread_merger.cc.

159 {
160 if (TaskQueuesAreSame()) {
162 }
163 std::scoped_lock lock(mutex_);
164 if (!IsMergedUnSafe()) {
166 }
167 if (!IsEnabledUnSafe()) {
169 }
170 bool unmerged_after_decrement = shared_merger_->DecrementLease(this);
171 if (unmerged_after_decrement) {
172 if (merge_unmerge_callback_ != nullptr) {
173 merge_unmerge_callback_();
174 }
176 }
177
179}

◆ Disable()

void fml::RasterThreadMerger::Disable ( )

Definition at line 128 of file raster_thread_merger.cc.

128 {
129 std::scoped_lock lock(mutex_);
130 shared_merger_->SetEnabledUnSafe(false);
131}

◆ Enable()

void fml::RasterThreadMerger::Enable ( )

Definition at line 123 of file raster_thread_merger.cc.

123 {
124 std::scoped_lock lock(mutex_);
125 shared_merger_->SetEnabledUnSafe(true);
126}

◆ ExtendLeaseTo()

void fml::RasterThreadMerger::ExtendLeaseTo ( size_t  lease_term)

Definition at line 106 of file raster_thread_merger.cc.

106 {
107 FML_DCHECK(lease_term > 0) << "lease_term should be positive.";
108 if (TaskQueuesAreSame()) {
109 return;
110 }
111 std::scoped_lock lock(mutex_);
112 if (!IsEnabledUnSafe()) {
113 return;
114 }
115 shared_merger_->ExtendLeaseTo(this, lease_term);
116}
#define FML_DCHECK(condition)
Definition: logging.h:103

◆ GetSharedRasterThreadMerger()

const fml::RefPtr< fml::SharedThreadMerger > & fml::RasterThreadMerger::GetSharedRasterThreadMerger ( ) const

Definition at line 35 of file raster_thread_merger.cc.

35 {
36 return shared_merger_;
37}

◆ IsEnabled()

bool fml::RasterThreadMerger::IsEnabled ( )

Definition at line 133 of file raster_thread_merger.cc.

133 {
134 std::scoped_lock lock(mutex_);
135 return IsEnabledUnSafe();
136}

◆ IsMerged()

bool fml::RasterThreadMerger::IsMerged ( )

Definition at line 118 of file raster_thread_merger.cc.

118 {
119 std::scoped_lock lock(mutex_);
120 return IsMergedUnSafe();
121}

◆ IsOnPlatformThread()

bool fml::RasterThreadMerger::IsOnPlatformThread ( ) const

Definition at line 92 of file raster_thread_merger.cc.

92 {
93 return MessageLoop::GetCurrentTaskQueueId() == platform_queue_id_;
94}
static TaskQueueId GetCurrentTaskQueueId()
Definition: message_loop.cc:76

◆ IsOnRasterizingThread()

bool fml::RasterThreadMerger::IsOnRasterizingThread ( )

Definition at line 96 of file raster_thread_merger.cc.

96 {
97 std::scoped_lock lock(mutex_);
98
99 if (IsMergedUnSafe()) {
100 return IsOnPlatformThread();
101 } else {
102 return !IsOnPlatformThread();
103 }
104}

◆ MergeWithLease()

void fml::RasterThreadMerger::MergeWithLease ( size_t  lease_term)

Definition at line 54 of file raster_thread_merger.cc.

54 {
55 std::scoped_lock lock(mutex_);
56 if (TaskQueuesAreSame()) {
57 return;
58 }
59 if (!IsEnabledUnSafe()) {
60 return;
61 }
62 FML_DCHECK(lease_term > 0) << "lease_term should be positive.";
63
64 if (IsMergedUnSafe()) {
65 merged_condition_.notify_one();
66 return;
67 }
68
69 bool success = shared_merger_->MergeWithLease(this, lease_term);
70 if (success && merge_unmerge_callback_ != nullptr) {
71 merge_unmerge_callback_();
72 }
73
74 merged_condition_.notify_one();
75}

◆ SetMergeUnmergeCallback()

void fml::RasterThreadMerger::SetMergeUnmergeCallback ( const fml::closure callback)

Definition at line 30 of file raster_thread_merger.cc.

30 {
31 merge_unmerge_callback_ = callback;
32}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ UnMergeNowIfLastOne()

void fml::RasterThreadMerger::UnMergeNowIfLastOne ( )

Definition at line 77 of file raster_thread_merger.cc.

77 {
78 std::scoped_lock lock(mutex_);
79
80 if (TaskQueuesAreSame()) {
81 return;
82 }
83 if (!IsEnabledUnSafe()) {
84 return;
85 }
86 bool success = shared_merger_->UnMergeNowIfLastOne(this);
87 if (success && merge_unmerge_callback_ != nullptr) {
88 merge_unmerge_callback_();
89 }
90}

◆ WaitUntilMerged()

void fml::RasterThreadMerger::WaitUntilMerged ( )

Definition at line 150 of file raster_thread_merger.cc.

150 {
151 if (TaskQueuesAreSame()) {
152 return;
153 }
155 std::unique_lock<std::mutex> lock(mutex_);
156 merged_condition_.wait(lock, [&] { return IsMergedUnSafe(); });
157}
#define FML_CHECK(condition)
Definition: logging.h:85

The documentation for this class was generated from the following files: