Flutter Engine
The 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#include <unordered_map>
13#include <unordered_set>
14
15#include "flutter/fml/hash_combine.h"
16#include "flutter/fml/macros.h"
19
20namespace impeller {
21
22enum class HandleType {
25 kBuffer,
29};
30
32
33class ReactorGLES;
34
35struct HandleGLES {
37 std::optional<UniqueID> name;
38
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
74namespace std {
75
76inline 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_
static sk_sp< Effect > Create()
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
constexpr std::size_t HashCombine()
std::string HandleTypeToString(HandleType type)
Definition ref_ptr.h:256
std::ostream & operator<<(std::ostream &out, const impeller::Color &c)
Definition color.h:951
bool operator()(const HandleGLES &lhs, const HandleGLES &rhs) const
Definition handle_gles.h:54
std::size_t operator()(const HandleGLES &handle) const
Definition handle_gles.h:46
constexpr bool IsDead() const
Definition handle_gles.h:43
std::optional< UniqueID > name
Definition handle_gles.h:37
static HandleGLES DeadHandle()
Definition handle_gles.h:39