Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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"
15
16namespace impeller {
17
18enum class HandleType {
19 kUnknown,
21 kBuffer,
25};
26
28
29class ReactorGLES;
30
31struct HandleGLES {
33 std::optional<UniqueID> name;
34
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
70namespace std {
71
72inline 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_
static sk_sp< Effect > Create()
Definition: RefCntTest.cpp:117
GLenum type
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
Definition: reactor_gles.h:55
constexpr std::size_t HashCombine()
Definition: hash_combine.h:25
std::string HandleTypeToString(HandleType type)
Definition: handle_gles.cc:11
Definition: ref_ptr.h:256
std::ostream & operator<<(std::ostream &out, const impeller::Color &c)
Definition: color.h:961
bool operator()(const HandleGLES &lhs, const HandleGLES &rhs) const
Definition: handle_gles.h:50
std::size_t operator()(const HandleGLES &handle) const
Definition: handle_gles.h:42
constexpr bool IsDead() const
Definition: handle_gles.h:39
std::optional< UniqueID > name
Definition: handle_gles.h:33
static HandleGLES DeadHandle()
Definition: handle_gles.h:35