Flutter Impeller
impeller::ReactorGLES Class Reference

#include <reactor_gles.h>

Classes

class  Worker
 

Public Types

using WorkerID = UniqueID
 
using Ref = std::shared_ptr< ReactorGLES >
 
using Operation = std::function< void(const ReactorGLES &reactor)>
 

Public Member Functions

 ReactorGLES (std::unique_ptr< ProcTableGLES > gl)
 
 ~ReactorGLES ()
 
bool IsValid () const
 
WorkerID AddWorker (std::weak_ptr< Worker > worker)
 
bool RemoveWorker (WorkerID)
 
const ProcTableGLESGetProcTable () const
 
std::optional< GLuint > GetGLHandle (const HandleGLES &handle) const
 
HandleGLES CreateHandle (HandleType type)
 
void CollectHandle (HandleGLES handle)
 
void SetDebugLabel (const HandleGLES &handle, std::string label)
 
bool AddOperation (Operation operation)
 
bool React ()
 

Detailed Description

Definition at line 19 of file reactor_gles.h.

Member Typedef Documentation

◆ Operation

using impeller::ReactorGLES::Operation = std::function<void(const ReactorGLES& reactor)>

Definition at line 53 of file reactor_gles.h.

◆ Ref

using impeller::ReactorGLES::Ref = std::shared_ptr<ReactorGLES>

Definition at line 31 of file reactor_gles.h.

◆ WorkerID

Definition at line 21 of file reactor_gles.h.

Constructor & Destructor Documentation

◆ ReactorGLES()

impeller::ReactorGLES::ReactorGLES ( std::unique_ptr< ProcTableGLES gl)

Definition at line 14 of file reactor_gles.cc.

15  : proc_table_(std::move(gl)) {
16  if (!proc_table_ || !proc_table_->IsValid()) {
17  VALIDATION_LOG << "Proc table was invalid.";
18  return;
19  }
20  can_set_debug_labels_ = proc_table_->GetDescription()->HasDebugExtension();
21  is_valid_ = true;
22 }

References VALIDATION_LOG.

◆ ~ReactorGLES()

impeller::ReactorGLES::~ReactorGLES ( )
default

Member Function Documentation

◆ AddOperation()

bool impeller::ReactorGLES::AddOperation ( Operation  operation)

Definition at line 70 of file reactor_gles.cc.

70  {
71  if (!operation) {
72  return false;
73  }
74  {
75  Lock ops_lock(ops_mutex_);
76  ops_.emplace_back(std::move(operation));
77  }
78  // Attempt a reaction if able but it is not an error if this isn't possible.
79  [[maybe_unused]] auto result = React();
80  return true;
81 }

References React().

◆ AddWorker()

ReactorGLES::WorkerID impeller::ReactorGLES::AddWorker ( std::weak_ptr< Worker worker)

Definition at line 30 of file reactor_gles.cc.

30  {
31  Lock lock(workers_mutex_);
32  auto id = WorkerID{};
33  workers_[id] = std::move(worker);
34  return id;
35 }

◆ CollectHandle()

void impeller::ReactorGLES::CollectHandle ( HandleGLES  handle)

Definition at line 148 of file reactor_gles.cc.

148  {
149  WriterLock handles_lock(handles_mutex_);
150  if (auto found = handles_.find(handle); found != handles_.end()) {
151  found->second.pending_collection = true;
152  }
153 }

◆ CreateHandle()

HandleGLES impeller::ReactorGLES::CreateHandle ( HandleType  type)

Definition at line 132 of file reactor_gles.cc.

132  {
133  if (type == HandleType::kUnknown) {
134  return HandleGLES::DeadHandle();
135  }
136  auto new_handle = HandleGLES::Create(type);
137  if (new_handle.IsDead()) {
138  return HandleGLES::DeadHandle();
139  }
140  WriterLock handles_lock(handles_mutex_);
141  auto gl_handle = CanReactOnCurrentThread()
142  ? CreateGLHandle(GetProcTable(), type)
143  : std::nullopt;
144  handles_[new_handle] = LiveHandle{gl_handle};
145  return new_handle;
146 }

References impeller::CreateGLHandle(), impeller::HandleGLES::DeadHandle(), GetProcTable(), and impeller::kUnknown.

◆ GetGLHandle()

std::optional< GLuint > impeller::ReactorGLES::GetGLHandle ( const HandleGLES handle) const

Definition at line 52 of file reactor_gles.cc.

52  {
53  ReaderLock handles_lock(handles_mutex_);
54  if (auto found = handles_.find(handle); found != handles_.end()) {
55  if (found->second.pending_collection) {
57  << "Attempted to acquire a handle that was pending collection.";
58  return std::nullopt;
59  }
60  if (!found->second.name.has_value()) {
61  VALIDATION_LOG << "Attempt to acquire a handle outside of an operation.";
62  return std::nullopt;
63  }
64  return found->second.name;
65  }
66  VALIDATION_LOG << "Attempted to acquire an invalid GL handle.";
67  return std::nullopt;
68 }

References VALIDATION_LOG.

Referenced by impeller::LinkProgram().

◆ GetProcTable()

const ProcTableGLES & impeller::ReactorGLES::GetProcTable ( ) const

◆ IsValid()

bool impeller::ReactorGLES::IsValid ( ) const

Definition at line 26 of file reactor_gles.cc.

26  {
27  return is_valid_;
28 }

Referenced by GetProcTable().

◆ React()

bool impeller::ReactorGLES::React ( )

Definition at line 155 of file reactor_gles.cc.

155  {
156  if (!CanReactOnCurrentThread()) {
157  return false;
158  }
159  TRACE_EVENT0("impeller", "ReactorGLES::React");
160  while (HasPendingOperations()) {
161  if (!ReactOnce()) {
162  return false;
163  }
164  }
165  return true;
166 }

Referenced by AddOperation().

◆ RemoveWorker()

bool impeller::ReactorGLES::RemoveWorker ( WorkerID  worker)

Definition at line 37 of file reactor_gles.cc.

37  {
38  Lock lock(workers_mutex_);
39  return workers_.erase(worker) == 1;
40 }

◆ SetDebugLabel()

void impeller::ReactorGLES::SetDebugLabel ( const HandleGLES handle,
std::string  label 
)

Definition at line 250 of file reactor_gles.cc.

250  {
251  if (!can_set_debug_labels_) {
252  return;
253  }
254  if (handle.IsDead()) {
255  return;
256  }
257  WriterLock handles_lock(handles_mutex_);
258  if (auto found = handles_.find(handle); found != handles_.end()) {
259  found->second.pending_debug_label = std::move(label);
260  }
261 }

References impeller::HandleGLES::IsDead().


The documentation for this class was generated from the following files:
impeller::ReactorGLES::GetProcTable
const ProcTableGLES & GetProcTable() const
Definition: reactor_gles.cc:47
impeller::HandleGLES::DeadHandle
static HandleGLES DeadHandle()
Definition: handle_gles.h:38
impeller::HandleType::kUnknown
@ kUnknown
impeller::ReactorGLES::React
bool React()
Definition: reactor_gles.cc:155
impeller::ReactorGLES::WorkerID
UniqueID WorkerID
Definition: reactor_gles.h:21
impeller::ReactorGLES::IsValid
bool IsValid() const
Definition: reactor_gles.cc:26
impeller::CreateGLHandle
static std::optional< GLuint > CreateGLHandle(const ProcTableGLES &gl, HandleType type)
Definition: reactor_gles.cc:83
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
std
Definition: comparable.h:98