5#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_REACTOR_GLES_H_
6#define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_REACTOR_GLES_H_
12#include "flutter/fml/macros.h"
87 using Ref = std::shared_ptr<ReactorGLES>;
96 explicit ReactorGLES(std::unique_ptr<ProcTableGLES> gl);
220 [[nodiscard]]
bool React();
224 std::optional<GLuint> name;
225 std::optional<std::string> pending_debug_label;
226 bool pending_collection =
false;
228 LiveHandle() =
default;
230 explicit LiveHandle(std::optional<GLuint> p_name) : name(p_name) {}
232 constexpr bool IsLive()
const {
return name.has_value(); }
235 std::unique_ptr<ProcTableGLES> proc_table_;
237 Mutex ops_execution_mutex_;
238 mutable Mutex ops_mutex_;
243 using LiveHandles = std::unordered_map<HandleGLES,
247 mutable RWMutex handles_mutex_;
250 mutable Mutex workers_mutex_;
251 mutable std::map<WorkerID, std::weak_ptr<Worker>> workers_
IPLR_GUARDED_BY(
254 bool can_set_debug_labels_ =
false;
255 bool is_valid_ =
false;
259 bool HasPendingOperations() const;
261 bool CanReactOnCurrentThread() const;
263 bool ConsolidateHandles();
267 void SetupDebugGroups();
269 ReactorGLES(const ReactorGLES&) = delete;
271 ReactorGLES& operator=(const ReactorGLES&) = delete;
static void operation(T operation, uint32_t &a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint8_t s, uint32_t t)
A delegate implemented by a thread on which an OpenGL context is current. There may be multiple worke...
virtual bool CanReactorReactOnCurrentThreadNow(const ReactorGLES &reactor) const =0
Determines the ability of the worker to service a reaction on the current thread. The OpenGL context ...
virtual ~Worker()=default
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
std::optional< GLuint > GetGLHandle(const HandleGLES &handle) const
Returns the OpenGL handle for a reactor handle if one is available. This is typically only safe to ca...
void CollectHandle(HandleGLES handle)
Collect a reactor handle.
std::function< void(const ReactorGLES &reactor)> Operation
bool React()
Perform a reaction on the current thread if able.
~ReactorGLES()
Destroy a reactor.
const ProcTableGLES & GetProcTable() const
Get the OpenGL proc. table the reactor uses to manage handles.
std::shared_ptr< ReactorGLES > Ref
HandleGLES CreateHandle(HandleType type)
Create a reactor handle.
void SetDebugLabel(const HandleGLES &handle, std::string label)
Set the debug label on a reactor handle.
bool AddOperation(Operation operation)
Adds an operation that the reactor runs on a worker that ensures that an OpenGL context is current.
bool RemoveWorker(WorkerID id)
Remove a previously added worker from the reactor. If the reactor has no workers, pending added opera...
WorkerID AddWorker(std::weak_ptr< Worker > worker)
Adds a worker to the reactor. Each new worker must ensure that the context it manages is the same as ...
bool IsValid() const
If this is a valid reactor. Invalid reactors must be discarded immediately.
#define IPLR_REQUIRES(...)
#define IPLR_GUARDED_BY(x)