Flutter Engine
 
Loading...
Searching...
No Matches
handle_gles.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_HANDLE_GLES_H_
6#define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_HANDLE_GLES_H_
7
8#include <optional>
9#include <sstream>
10#include <string>
11#include <type_traits>
12
15
16namespace impeller {
17
18enum class HandleType {
21 kBuffer,
25 kFence,
26};
27
29
30class ReactorGLES;
31
32//------------------------------------------------------------------------------
33/// @brief Represents a handle to an underlying OpenGL object. Unlike
34/// OpenGL object handles, these handles can be collected on any
35/// thread as long as their destruction is scheduled in a reactor.
36///
38 public:
39 //----------------------------------------------------------------------------
40 /// @brief Creates a dead handle.
41 ///
42 /// @return The handle.
43 ///
45 return HandleGLES{HandleType::kUnknown, std::nullopt};
46 }
47
48 //----------------------------------------------------------------------------
49 /// @brief Determines if the handle is dead.
50 ///
51 /// @return True if dead, False otherwise.
52 ///
53 constexpr bool IsDead() const { return !name_.has_value(); }
54
55 //----------------------------------------------------------------------------
56 /// @brief Get the hash value of this handle. Handles can be used as map
57 /// keys.
58 ///
59 struct Hash {
60 std::size_t operator()(const HandleGLES& handle) const {
61 return handle.GetHash();
62 }
63 };
64
65 //----------------------------------------------------------------------------
66 /// @brief A comparer used to test the equality of two handles.
67 ///
68 struct Equal {
69 bool operator()(const HandleGLES& lhs, const HandleGLES& rhs) const {
70 return lhs.type_ == rhs.type_ && lhs.name_ == rhs.name_;
71 }
72 };
73
74 HandleType GetType() const { return type_; }
75 const std::optional<UniqueID>& GetName() const { return name_; }
76 std::size_t GetHash() const { return hash_; }
77
78 private:
80 std::optional<UniqueID> name_;
81 std::size_t hash_;
82 std::optional<uint64_t> untracked_id_;
83
84 friend class ReactorGLES;
85
86 HandleGLES(HandleType p_type, UniqueID p_name)
87 : type_(p_type),
88 name_(p_name),
89 hash_(fml::HashCombine(
90 static_cast<std::underlying_type_t<decltype(p_type)>>(p_type),
91 p_name)) {}
92
93 HandleGLES(HandleType p_type, std::optional<UniqueID> p_name)
94 : type_(p_type),
95 name_(p_name),
96 hash_(fml::HashCombine(
97 static_cast<std::underlying_type_t<decltype(p_type)>>(p_type),
98 p_name)) {}
99
100 static HandleGLES Create(HandleType type) {
101 return HandleGLES{type, UniqueID{}};
102 }
103};
104
105} // namespace impeller
106
107namespace std {
108
109inline std::ostream& operator<<(std::ostream& out,
110 const impeller::HandleGLES& handle) {
111 out << HandleTypeToString(handle.GetType()) << "(";
112 if (handle.IsDead()) {
113 out << "DEAD";
114 } else {
115 const std::optional<impeller::UniqueID>& name = handle.GetName();
116 if (name.has_value()) {
117 out << name.value().id;
118 } else {
119 out << "UNNAMED";
120 }
121 }
122 out << ")";
123 return out;
124}
125
126} // namespace std
127
128#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_HANDLE_GLES_H_
GLenum type
Represents a handle to an underlying OpenGL object. Unlike OpenGL object handles, these handles can b...
Definition handle_gles.h:37
constexpr bool IsDead() const
Determines if the handle is dead.
Definition handle_gles.h:53
HandleType GetType() const
Definition handle_gles.h:74
std::size_t GetHash() const
Definition handle_gles.h:76
static HandleGLES DeadHandle()
Creates a dead handle.
Definition handle_gles.h:44
const std::optional< UniqueID > & GetName() const
Definition handle_gles.h:75
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
const char * name
Definition fuchsia.cc:49
std::string HandleTypeToString(HandleType type)
Definition ref_ptr.h:261
std::ostream & operator<<(std::ostream &out, const impeller::Arc &a)
Definition arc.h:141
A comparer used to test the equality of two handles.
Definition handle_gles.h:68
bool operator()(const HandleGLES &lhs, const HandleGLES &rhs) const
Definition handle_gles.h:69
Get the hash value of this handle. Handles can be used as map keys.
Definition handle_gles.h:59
std::size_t operator()(const HandleGLES &handle) const
Definition handle_gles.h:60