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