| 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 #include <unordered_map>
13 #include <unordered_set>
14
15 #include "flutter/fml/hash_combine.h"
16 #include "flutter/fml/macros.h"
17 #include "impeller/base/comparable.h"
18 #include "impeller/renderer/backend/gles/gles.h"
19
20 namespace impeller {
21
22 enum class HandleType {
23 kUnknown,
24 kTexture,
25 kBuffer,
26 kProgram,
27 kRenderBuffer,
28 kFrameBuffer,
29 };
30
31 std::string HandleTypeToString(HandleType type);
32
33 class ReactorGLES;
34
35 struct HandleGLES {
36 HandleType type = HandleType::kUnknown;
37 std::optional<UniqueID> name;
38
39 static HandleGLES DeadHandle() {
40 return HandleGLES{HandleType::kUnknown, std::nullopt};
41 }
42
43 constexpr bool IsDead() const { return !name.has_value(); }
44
45 struct Hash {
46 std::size_t operator()(const HandleGLES& handle) const {
47 return fml::HashCombine(
48 std::underlying_type_t<decltype(handle.type)>(handle.type),
49 handle.name);
50 }
51 };
52
53 struct Equal {
54 bool operator()(const HandleGLES& lhs, const HandleGLES& rhs) const {
55 return lhs.type == rhs.type && lhs.name == rhs.name;
56 }
57 };
58
59 private:
60 friend class ReactorGLES;
61
62 HandleGLES(HandleType p_type, UniqueID p_name) : type(p_type), name(p_name) {}
63
64 HandleGLES(HandleType p_type, std::optional<UniqueID> p_name)
65 : type(p_type), name(p_name) {}
66
67 static HandleGLES Create(HandleType type) {
68 return HandleGLES{type, UniqueID{}};
69 }
70 };
71
72 } // namespace impeller
73
74 namespace std {
75
76 inline std::ostream& operator<<(std::ostream& out,
77 const impeller::HandleGLES& handle) {
78 out << HandleTypeToString(handle.type) << "(";
79 if (handle.IsDead()) {
80 out << "DEAD";
81 } else {
82 if (handle.name.has_value()) {
83 out << handle.name.value().id;
84 } else {
85 out << "UNNAMED";
86 }
87 }
88 out << ")";
89 return out;
90 }
91
92 } // namespace std
93
94 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_HANDLE_GLES_H_
impeller::HandleGLES::DeadHandle
static HandleGLES DeadHandle()
Definition: handle_gles.h:39
impeller::HandleType::kRenderBuffer
@ kRenderBuffer
impeller::HandleType
HandleType
Definition: handle_gles.h:22
impeller::HandleType::kTexture
@ kTexture
impeller::HandleType::kUnknown
@ kUnknown
std::operator<<
std::ostream & operator<<(std::ostream &out, const impeller::Color &c)
Definition: color.h:951
impeller::HandleGLES::name
std::optional< UniqueID > name
Definition: handle_gles.h:37
impeller::HandleGLES::IsDead
constexpr bool IsDead() const
Definition: handle_gles.h:43
impeller::HandleTypeToString
std::string HandleTypeToString(HandleType type)
Definition: handle_gles.cc:11
impeller::HandleGLES::type
HandleType type
Definition: handle_gles.h:36
impeller::HandleGLES::Equal::operator()
bool operator()(const HandleGLES &lhs, const HandleGLES &rhs) const
Definition: handle_gles.h:54
impeller::HandleGLES
Definition: handle_gles.h:35
impeller::HandleGLES::Hash
Definition: handle_gles.h:45
impeller::HandleGLES::Equal
Definition: handle_gles.h:53
gles.h
impeller::HandleType::kProgram
@ kProgram
comparable.h
impeller::HandleGLES::Hash::operator()
std::size_t operator()(const HandleGLES &handle) const
Definition: handle_gles.h:46
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:56
impeller::HandleType::kFrameBuffer
@ kFrameBuffer
impeller::UniqueID
Definition: comparable.h:16
impeller::HandleType::kBuffer
@ kBuffer
impeller
Definition: aiks_context.cc:10