| Flutter Impeller |

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
13 #include "flutter/fml/hash_combine.h"
14 #include "impeller/base/comparable.h"
15
16 namespace impeller {
17
18 enum class HandleType {
19 kUnknown,
20 kTexture,
21 kBuffer,
22 kProgram,
23 kRenderBuffer,
24 kFrameBuffer,
25 };
26
27 std::string HandleTypeToString(HandleType type);
28
29 class ReactorGLES;
30
31 //------------------------------------------------------------------------------
32 /// @brief Represents a handle to an underlying OpenGL object. Unlike
33 /// OpenGL object handles, these handles can be collected on any
34 /// thread as long as their destruction is scheduled in a reactor.
35 ///
36 struct HandleGLES {
37 HandleType type = HandleType::kUnknown;
38 std::optional<UniqueID> name;
39
40 //----------------------------------------------------------------------------
41 /// @brief Creates a dead handle.
42 ///
43 /// @return The handle.
44 ///
45 static HandleGLES DeadHandle() {
46 return HandleGLES{HandleType::kUnknown, std::nullopt};
47 }
48
49 //----------------------------------------------------------------------------
50 /// @brief Determines if the handle is dead.
51 ///
52 /// @return True if dead, False otherwise.
53 ///
54 constexpr bool IsDead() const { return !name.has_value(); }
55
56 //----------------------------------------------------------------------------
57 /// @brief Get the hash value of this handle. Handles can be used as map
58 /// keys.
59 ///
60 struct Hash {
61 std::size_t operator()(const HandleGLES& handle) const {
62 return fml::HashCombine(
63 std::underlying_type_t<decltype(handle.type)>(handle.type),
64 handle.name);
65 }
66 };
67
68 //----------------------------------------------------------------------------
69 /// @brief A comparer used to test the equality of two handles.
70 ///
71 struct Equal {
72 bool operator()(const HandleGLES& lhs, const HandleGLES& rhs) const {
73 return lhs.type == rhs.type && lhs.name == rhs.name;
74 }
75 };
76
77 private:
78 friend class ReactorGLES;
79
80 HandleGLES(HandleType p_type, UniqueID p_name) : type(p_type), name(p_name) {}
81
82 HandleGLES(HandleType p_type, std::optional<UniqueID> p_name)
83 : type(p_type), name(p_name) {}
84
85 static HandleGLES Create(HandleType type) {
86 return HandleGLES{type, UniqueID{}};
87 }
88 };
89
90 } // namespace impeller
91
92 namespace std {
93
94 inline std::ostream& operator<<(std::ostream& out,
95 const impeller::HandleGLES& handle) {
96 out << HandleTypeToString(handle.type) << "(";
97 if (handle.IsDead()) {
98 out << "DEAD";
99 } else {
100 if (handle.name.has_value()) {
101 out << handle.name.value().id;
102 } else {
103 out << "UNNAMED";
104 }
105 }
106 out << ")";
107 return out;
108 }
109
110 } // namespace std
111
112 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_HANDLE_GLES_H_
impeller::HandleGLES::DeadHandle
static HandleGLES DeadHandle()
Creates a dead handle.
Definition: handle_gles.h:45
impeller::HandleType::kRenderBuffer
@ kRenderBuffer
impeller::HandleType
HandleType
Definition: handle_gles.h:18
impeller::HandleType::kTexture
@ kTexture
impeller::HandleType::kUnknown
@ kUnknown
std::operator<<
std::ostream & operator<<(std::ostream &out, const impeller::Color &c)
Definition: color.h:926
impeller::HandleGLES::name
std::optional< UniqueID > name
Definition: handle_gles.h:38
impeller::HandleGLES::IsDead
constexpr bool IsDead() const
Determines if the handle is dead.
Definition: handle_gles.h:54
impeller::HandleTypeToString
std::string HandleTypeToString(HandleType type)
Definition: handle_gles.cc:11
impeller::HandleGLES::type
HandleType type
Definition: handle_gles.h:37
impeller::HandleGLES::Equal::operator()
bool operator()(const HandleGLES &lhs, const HandleGLES &rhs) const
Definition: handle_gles.h:72
type
GLenum type
Definition: blit_command_gles.cc:127
impeller::HandleGLES
Represents a handle to an underlying OpenGL object. Unlike OpenGL object handles, these handles can b...
Definition: handle_gles.h:36
impeller::HandleGLES::Hash
Get the hash value of this handle. Handles can be used as map keys.
Definition: handle_gles.h:60
impeller::HandleGLES::Equal
A comparer used to test the equality of two handles.
Definition: handle_gles.h:71
impeller::HandleType::kProgram
@ kProgram
comparable.h
impeller::HandleGLES::Hash::operator()
std::size_t operator()(const HandleGLES &handle) const
Definition: handle_gles.h:61
std
Definition: comparable.h:95
impeller::ReactorGLES
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
Definition: reactor_gles.h:55
impeller::HandleType::kFrameBuffer
@ kFrameBuffer
impeller::UniqueID
Definition: comparable.h:16
impeller::HandleType::kBuffer
@ kBuffer
impeller::interop::Create
ScopedObject< Object > Create(CtorArgs &&... args)
Definition: object.h:160
impeller
Definition: allocation.cc:12