Flutter Engine
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 38 of file raster_thread_merger.cc.

References GetSharedRasterThreadMerger().

Referenced by flutter::Rasterizer::Setup(), and fml::testing::TEST().

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

◆ DecrementLease()

RasterThreadStatus fml::RasterThreadMerger::DecrementLease ( )

Definition at line 157 of file raster_thread_merger.cc.

References fml::SharedThreadMerger::DecrementLease(), fml::kRemainsMerged, fml::kRemainsUnmerged, and fml::kUnmergedNow.

Referenced by flutter::Rasterizer::Draw(), and fml::testing::TEST().

157  {
158  if (TaskQueuesAreSame()) {
160  }
161  std::scoped_lock lock(mutex_);
162  if (!IsMergedUnSafe()) {
164  }
165  if (!IsEnabledUnSafe()) {
167  }
168  bool unmerged_after_decrement = shared_merger_->DecrementLease(this);
169  if (unmerged_after_decrement) {
170  if (merge_unmerge_callback_ != nullptr) {
171  merge_unmerge_callback_();
172  }
174  }
175 
177 }
bool DecrementLease(RasterThreadMergerId caller)

◆ Disable()

void fml::RasterThreadMerger::Disable ( )

Definition at line 126 of file raster_thread_merger.cc.

References fml::SharedThreadMerger::SetEnabledUnSafe().

Referenced by flutter::Rasterizer::DisableThreadMergerIfNeeded().

126  {
127  std::scoped_lock lock(mutex_);
128  shared_merger_->SetEnabledUnSafe(false);
129 }
void SetEnabledUnSafe(bool enabled)

◆ Enable()

void fml::RasterThreadMerger::Enable ( )

Definition at line 121 of file raster_thread_merger.cc.

References fml::SharedThreadMerger::SetEnabledUnSafe().

Referenced by flutter::Rasterizer::EnableThreadMergerIfNeeded().

121  {
122  std::scoped_lock lock(mutex_);
123  shared_merger_->SetEnabledUnSafe(true);
124 }
void SetEnabledUnSafe(bool enabled)

◆ ExtendLeaseTo()

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

Definition at line 104 of file raster_thread_merger.cc.

References fml::SharedThreadMerger::ExtendLeaseTo(), and FML_DCHECK.

Referenced by flutter::AndroidExternalViewEmbedder::PostPrerollAction(), and flutter::FlutterPlatformViewsController::PostPrerollAction.

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

◆ GetSharedRasterThreadMerger()

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

Definition at line 33 of file raster_thread_merger.cc.

Referenced by CreateOrShareThreadMerger().

33  {
34  return shared_merger_;
35 }

◆ IsEnabled()

bool fml::RasterThreadMerger::IsEnabled ( )

Definition at line 131 of file raster_thread_merger.cc.

References fml::SharedThreadMerger::IsEnabledUnSafe(), and fml::SharedThreadMerger::IsMergedUnSafe().

Referenced by flutter::Rasterizer::Teardown(), and flutter::testing::TEST_F().

131  {
132  std::scoped_lock lock(mutex_);
133  return IsEnabledUnSafe();
134 }

◆ IsMerged()

bool fml::RasterThreadMerger::IsMerged ( )

◆ IsOnPlatformThread()

bool fml::RasterThreadMerger::IsOnPlatformThread ( ) const

◆ IsOnRasterizingThread()

bool fml::RasterThreadMerger::IsOnRasterizingThread ( )

Definition at line 94 of file raster_thread_merger.cc.

References IsOnPlatformThread().

Referenced by flutter::Rasterizer::Draw().

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

◆ MergeWithLease()

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

Definition at line 52 of file raster_thread_merger.cc.

References FML_DCHECK, and fml::SharedThreadMerger::MergeWithLease().

Referenced by flutter::AndroidExternalViewEmbedder::PostPrerollAction(), flutter::FlutterPlatformViewsController::PostPrerollAction, fml::testing::TEST(), and flutter::testing::TEST_F().

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

◆ SetMergeUnmergeCallback()

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

Definition at line 28 of file raster_thread_merger.cc.

References callback.

Referenced by flutter::Rasterizer::Setup(), and flutter::Rasterizer::Teardown().

28  {
29  merge_unmerge_callback_ = callback;
30 }
FlKeyEvent FlKeyResponderAsyncCallback callback

◆ UnMergeNowIfLastOne()

void fml::RasterThreadMerger::UnMergeNowIfLastOne ( )

Definition at line 75 of file raster_thread_merger.cc.

References fml::SharedThreadMerger::UnMergeNowIfLastOne().

Referenced by flutter::Rasterizer::Teardown().

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

◆ WaitUntilMerged()

void fml::RasterThreadMerger::WaitUntilMerged ( )

Definition at line 148 of file raster_thread_merger.cc.

References FML_CHECK, and IsOnPlatformThread().

Referenced by fml::testing::TEST().

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

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