| Flutter Impeller |

shader_archive.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_SHADER_ARCHIVE_SHADER_ARCHIVE_H_
6 #define FLUTTER_IMPELLER_SHADER_ARCHIVE_SHADER_ARCHIVE_H_
7
8 #include <memory>
9 #include <type_traits>
10 #include <unordered_map>
11
12 #include "flutter/fml/hash_combine.h"
13 #include "flutter/fml/mapping.h"
14 #include "impeller/shader_archive/shader_archive_types.h"
15 #include "third_party/abseil-cpp/absl/status/statusor.h"
16
17 namespace impeller {
18
19 class ShaderArchive {
20 public:
21 static absl::StatusOr<ShaderArchive> Create(
22 std::shared_ptr<fml::Mapping> payload);
23
24 ShaderArchive(ShaderArchive&&);
25
26 ~ShaderArchive();
27
28 size_t GetShaderCount() const;
29
30 std::shared_ptr<fml::Mapping> GetMapping(ArchiveShaderType type,
31 std::string name) const;
32
33 size_t IterateAllShaders(
34 const std::function<bool(ArchiveShaderType type,
35 const std::string& name,
36 const std::shared_ptr<fml::Mapping>& mapping)>&)
37 const;
38
39 private:
40 explicit ShaderArchive(std::shared_ptr<fml::Mapping> payload);
41
42 struct ShaderKey {
43 ArchiveShaderType type = ArchiveShaderType::kFragment;
44 std::string name;
45
46 struct Hash {
47 size_t operator()(const ShaderKey& key) const {
48 return fml::HashCombine(
49 static_cast<std::underlying_type_t<decltype(key.type)>>(key.type),
50 key.name);
51 }
52 };
53
54 struct Equal {
55 bool operator()(const ShaderKey& lhs, const ShaderKey& rhs) const {
56 return lhs.type == rhs.type && lhs.name == rhs.name;
57 }
58 };
59 };
60
61 using Shaders = std::unordered_map<ShaderKey,
62 std::shared_ptr<fml::Mapping>,
63 ShaderKey::Hash,
64 ShaderKey::Equal>;
65
66 std::shared_ptr<fml::Mapping> payload_;
67 Shaders shaders_;
68
69 ShaderArchive(std::shared_ptr<fml::Mapping> payload, Shaders shaders);
70
71 ShaderArchive(const ShaderArchive&) = delete;
72
73 ShaderArchive& operator=(const ShaderArchive&) = delete;
74 };
75
76 } // namespace impeller
77
78 #endif // FLUTTER_IMPELLER_SHADER_ARCHIVE_SHADER_ARCHIVE_H_
type
GLenum type
Definition: blit_command_gles.cc:153
impeller::ShaderArchive
Definition: shader_archive.h:19
impeller::ShaderArchive::~ShaderArchive
~ShaderArchive()
impeller::ShaderArchive::ShaderArchive
ShaderArchive(ShaderArchive &&)
impeller::ShaderArchive::IterateAllShaders
size_t IterateAllShaders(const std::function< bool(ArchiveShaderType type, const std::string &name, const std::shared_ptr< fml::Mapping > &mapping)> &) const
Definition: shader_archive.cc:93
impeller::ShaderArchive::Create
static absl::StatusOr< ShaderArchive > Create(std::shared_ptr< fml::Mapping > payload)
Definition: shader_archive.cc:29
impeller::ShaderArchive::GetShaderCount
size_t GetShaderCount() const
Definition: shader_archive.cc:79
impeller::ShaderArchive::GetMapping
std::shared_ptr< fml::Mapping > GetMapping(ArchiveShaderType type, std::string name) const
Definition: shader_archive.cc:83
impeller
Definition: allocation.cc:12
impeller::ArchiveShaderType
ArchiveShaderType
Definition: shader_archive_types.h:10
impeller::ArchiveShaderType::kFragment
@ kFragment
shader_archive_types.h
impeller::ShaderArchive::ShaderKey::Equal
Definition: shader_archive.h:54
impeller::ShaderArchive::ShaderKey::Equal::operator()
bool operator()(const ShaderKey &lhs, const ShaderKey &rhs) const
Definition: shader_archive.h:55
impeller::ShaderArchive::ShaderKey::Hash
Definition: shader_archive.h:46
impeller::ShaderArchive::ShaderKey::Hash::operator()
size_t operator()(const ShaderKey &key) const
Definition: shader_archive.h:47
impeller::ShaderKey::Equal
Definition: shader_key.h:30
impeller::ShaderKey::Hash
Definition: shader_key.h:24
impeller::ShaderKey
Definition: shader_key.h:17