| 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 struct HandleGLES {
32 HandleType type = HandleType::kUnknown;
33 std::optional<UniqueID> name;
34
35 static HandleGLES DeadHandle() {
36 return HandleGLES{HandleType::kUnknown, std::nullopt};
37 }
38
39 constexpr bool IsDead() const { return !name.has_value(); }
40
41 struct Hash {
42 std::size_t operator()(const HandleGLES& handle) const {
43 return fml::HashCombine(
44 std::underlying_type_t<decltype(handle.type)>(handle.type),
45 handle.name);
46 }
47 };
48
49 struct Equal {
50 bool operator()(const HandleGLES& lhs, const HandleGLES& rhs) const {
51 return lhs.type == rhs.type && lhs.name == rhs.name;
52 }
53 };
54
55 private:
56 friend class ReactorGLES;
57
58 HandleGLES(HandleType p_type, UniqueID p_name) : type(p_type), name(p_name) {}
59
60 HandleGLES(HandleType p_type, std::optional<UniqueID> p_name)
61 : type(p_type), name(p_name) {}
62
63 static HandleGLES Create(HandleType type) {
64 return HandleGLES{type, UniqueID{}};
65 }
66 };
67
68 } // namespace impeller
69
70 namespace std {
71
72 inline std::ostream& operator<<(std::ostream& out,
73 const impeller::HandleGLES& handle) {
74 out << HandleTypeToString(handle.type) << "(";
75 if (handle.IsDead()) {
76 out << "DEAD";
77 } else {
78 if (handle.name.has_value()) {
79 out << handle.name.value().id;
80 } else {
81 out << "UNNAMED";
82 }
83 }
84 out << ")";
85 return out;
86 }
87
88 } // namespace std
89
90 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_HANDLE_GLES_H_
impeller::HandleGLES::DeadHandle
static HandleGLES DeadHandle()
Definition: handle_gles.h:35
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:961
impeller::HandleGLES::name
std::optional< UniqueID > name
Definition: handle_gles.h:33
impeller::HandleGLES::IsDead
constexpr bool IsDead() const
Definition: handle_gles.h:39
impeller::HandleTypeToString
std::string HandleTypeToString(HandleType type)
Definition: handle_gles.cc:11
impeller::HandleGLES::type
HandleType type
Definition: handle_gles.h:32
impeller::HandleGLES::Equal::operator()
bool operator()(const HandleGLES &lhs, const HandleGLES &rhs) const
Definition: handle_gles.h:50
type
GLenum type
Definition: blit_command_gles.cc:126
impeller::HandleGLES
Definition: handle_gles.h:31
impeller::HandleGLES::Hash
Definition: handle_gles.h:41
impeller::HandleGLES::Equal
Definition: handle_gles.h:49
impeller::HandleType::kProgram
@ kProgram
comparable.h
impeller::HandleGLES::Hash::operator()
std::size_t operator()(const HandleGLES &handle) const
Definition: handle_gles.h:42
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
Definition: aiks_blend_unittests.cc:18