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)
 
void UnMergeNow ()
 
void ExtendLeaseTo (size_t lease_term)
 
RasterThreadStatus DecrementLease ()
 
bool IsMerged ()
 
void WaitUntilMerged ()
 
 RasterThreadMerger (fml::TaskQueueId platform_queue_id, fml::TaskQueueId gpu_queue_id)
 
bool IsOnRasterizingThread () const
 
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
 

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

Definition at line 25 of file raster_thread_merger.h.

Constructor & Destructor Documentation

◆ RasterThreadMerger()

fml::RasterThreadMerger::RasterThreadMerger ( fml::TaskQueueId  platform_queue_id,
fml::TaskQueueId  gpu_queue_id 
)

Definition at line 15 of file raster_thread_merger.cc.

References FML_CHECK, and fml::MessageLoopTaskQueues::Owns().

17  : platform_queue_id_(platform_queue_id),
18  gpu_queue_id_(gpu_queue_id),
20  lease_term_(kLeaseNotSet),
21  enabled_(true) {
22  FML_CHECK(!task_queues_->Owns(platform_queue_id_, gpu_queue_id_));
23 }
bool Owns(TaskQueueId owner, TaskQueueId subsumed) const
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
#define FML_CHECK(condition)
Definition: logging.h:68

Member Function Documentation

◆ DecrementLease()

RasterThreadStatus fml::RasterThreadMerger::DecrementLease ( )

Definition at line 135 of file raster_thread_merger.cc.

References FML_DCHECK, fml::kRemainsMerged, fml::kRemainsUnmerged, fml::kUnmergedNow, and UnMergeNow().

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

135  {
136  if (TaskQueuesAreSame()) {
138  }
139  std::unique_lock<std::mutex> lock(lease_term_mutex_);
140  if (!IsMergedUnSafe()) {
142  }
143  if (!IsEnabledUnSafe()) {
145  }
146  FML_DCHECK(lease_term_ > 0)
147  << "lease_term should always be positive when merged.";
148  lease_term_--;
149  if (lease_term_ == 0) {
150  // |UnMergeNow| is going to acquire the lock again.
151  lock.unlock();
152  UnMergeNow();
154  }
155 
157 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ Disable()

void fml::RasterThreadMerger::Disable ( )

Definition at line 104 of file raster_thread_merger.cc.

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

104  {
105  std::scoped_lock lock(lease_term_mutex_);
106  enabled_ = false;
107 }

◆ Enable()

void fml::RasterThreadMerger::Enable ( )

Definition at line 99 of file raster_thread_merger.cc.

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

99  {
100  std::scoped_lock lock(lease_term_mutex_);
101  enabled_ = true;
102 }

◆ ExtendLeaseTo()

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

Definition at line 82 of file raster_thread_merger.cc.

References FML_DCHECK.

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

82  {
83  if (TaskQueuesAreSame()) {
84  return;
85  }
86  std::scoped_lock lock(lease_term_mutex_);
87  FML_DCHECK(IsMergedUnSafe()) << "lease_term should be positive.";
88  if (lease_term_ != kLeaseNotSet &&
89  static_cast<int>(lease_term) > lease_term_) {
90  lease_term_ = lease_term;
91  }
92 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ IsEnabled()

bool fml::RasterThreadMerger::IsEnabled ( )

Definition at line 109 of file raster_thread_merger.cc.

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

109  {
110  std::scoped_lock lock(lease_term_mutex_);
111  return IsEnabledUnSafe();
112 }

◆ IsMerged()

bool fml::RasterThreadMerger::IsMerged ( )

Definition at line 94 of file raster_thread_merger.cc.

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

94  {
95  std::scoped_lock lock(lease_term_mutex_);
96  return IsMergedUnSafe();
97 }

◆ IsOnPlatformThread()

bool fml::RasterThreadMerger::IsOnPlatformThread ( ) const

◆ IsOnRasterizingThread()

bool fml::RasterThreadMerger::IsOnRasterizingThread ( ) const

Definition at line 74 of file raster_thread_merger.cc.

References IsOnPlatformThread().

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

74  {
75  if (IsMergedUnSafe()) {
76  return IsOnPlatformThread();
77  } else {
78  return !IsOnPlatformThread();
79  }
80 }

◆ MergeWithLease()

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

Definition at line 29 of file raster_thread_merger.cc.

References FML_CHECK, FML_DCHECK, and fml::MessageLoopTaskQueues::Merge().

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

29  {
30  std::scoped_lock lock(lease_term_mutex_);
31  if (TaskQueuesAreSame()) {
32  return;
33  }
34  if (!IsEnabledUnSafe()) {
35  return;
36  }
37  FML_DCHECK(lease_term > 0) << "lease_term should be positive.";
38 
39  if (IsMergedUnSafe()) {
40  merged_condition_.notify_one();
41  return;
42  }
43 
44  bool success = task_queues_->Merge(platform_queue_id_, gpu_queue_id_);
45  if (success && merge_unmerge_callback_ != nullptr) {
46  merge_unmerge_callback_();
47  }
48  FML_CHECK(success) << "Unable to merge the raster and platform threads.";
49  lease_term_ = lease_term;
50 
51  merged_condition_.notify_one();
52 }
#define FML_DCHECK(condition)
Definition: logging.h:86
bool Merge(TaskQueueId owner, TaskQueueId subsumed)
#define FML_CHECK(condition)
Definition: logging.h:68

◆ SetMergeUnmergeCallback()

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

Definition at line 25 of file raster_thread_merger.cc.

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

25  {
26  merge_unmerge_callback_ = callback;
27 }

◆ UnMergeNow()

void fml::RasterThreadMerger::UnMergeNow ( )

Definition at line 54 of file raster_thread_merger.cc.

References FML_CHECK, and fml::MessageLoopTaskQueues::Unmerge().

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

54  {
55  std::scoped_lock lock(lease_term_mutex_);
56  if (TaskQueuesAreSame()) {
57  return;
58  }
59  if (!IsEnabledUnSafe()) {
60  return;
61  }
62  lease_term_ = 0;
63  bool success = task_queues_->Unmerge(platform_queue_id_);
64  if (success && merge_unmerge_callback_ != nullptr) {
65  merge_unmerge_callback_();
66  }
67  FML_CHECK(success) << "Unable to un-merge the raster and platform threads.";
68 }
#define FML_CHECK(condition)
Definition: logging.h:68

◆ WaitUntilMerged()

void fml::RasterThreadMerger::WaitUntilMerged ( )

Definition at line 126 of file raster_thread_merger.cc.

References FML_CHECK, and IsOnPlatformThread().

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

126  {
127  if (TaskQueuesAreSame()) {
128  return;
129  }
131  std::unique_lock<std::mutex> lock(lease_term_mutex_);
132  merged_condition_.wait(lock, [&] { return IsMergedUnSafe(); });
133 }
#define FML_CHECK(condition)
Definition: logging.h:68

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