5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_REACTOR_GLES_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_REACTOR_GLES_H_
12 #include "flutter/third_party/abseil-cpp/absl/container/flat_hash_map.h"
13 #include "fml/closure.h"
95 explicit ReactorGLES(std::unique_ptr<ProcTableGLES> gl);
248 const fml::closure& callback);
258 [[nodiscard]]
bool React();
269 static_assert(
sizeof(GLStorage) ==
sizeof(uint64_t));
272 std::optional<GLStorage> name;
273 std::optional<std::string> pending_debug_label;
274 bool pending_collection =
false;
275 fml::ScopedCleanupClosure callback = {};
277 LiveHandle() =
default;
279 explicit LiveHandle(std::optional<GLStorage> p_name) : name(p_name) {}
281 constexpr
bool IsLive()
const {
return name.has_value(); }
284 std::unique_ptr<ProcTableGLES> proc_table_;
286 mutable Mutex ops_mutex_;
287 std::map<std::thread::id, std::vector<Operation>> ops_ IPLR_GUARDED_BY(
290 using LiveHandles = absl::flat_hash_map<
const HandleGLES,
294 mutable RWMutex handles_mutex_;
295 LiveHandles handles_ IPLR_GUARDED_BY(handles_mutex_);
296 int32_t handles_to_collect_count_ IPLR_GUARDED_BY(handles_mutex_) = 0;
298 mutable Mutex workers_mutex_;
299 mutable std::map<WorkerID, std::weak_ptr<Worker>> workers_ IPLR_GUARDED_BY(
302 bool can_set_debug_labels_ =
false;
303 bool is_valid_ =
false;
307 bool HasPendingOperations()
const;
309 bool CanReactOnCurrentThread()
const;
311 bool ConsolidateHandles();
315 void SetupDebugGroups();
317 std::optional<GLStorage> GetHandle(
const HandleGLES& handle)
const;
319 static std::optional<GLStorage> CreateGLHandle(
const ProcTableGLES& gl,
322 static bool CollectGLHandle(
const ProcTableGLES& gl,
Represents a handle to an underlying OpenGL object. Unlike OpenGL object handles, these handles can b...
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.
bool RegisterCleanupCallback(const HandleGLES &handle, const fml::closure &callback)
Register a cleanup callback that will be invokved with the provided user data when the handle is dest...
bool CanSetDebugLabels() const
Whether the device is capable of writing debug labels.
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...
ReactorGLES(std::unique_ptr< ProcTableGLES > gl)
Create a new reactor. There are expensive and only one per application instance is necessary.
HandleGLES CreateUntrackedHandle(HandleType type) const
Create a handle that is not managed by ReactorGLES.
std::optional< GLsync > GetGLFence(const HandleGLES &handle) const
void CollectHandle(HandleGLES handle)
Collect a reactor handle.
HandleGLES CreateHandle(HandleType type, GLuint external_handle=GL_NONE)
Create 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.
bool AddOperation(Operation operation, bool defer=false)
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 ...
void SetDebugLabel(const HandleGLES &handle, std::string_view label)
Set the debug label on a reactor handle.
bool IsValid() const
If this is a valid reactor. Invalid reactors must be discarded immediately.