| 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/macros.h"
14 #include "flutter/fml/mapping.h"
15 #include "impeller/shader_archive/shader_archive_types.h"
16
17 namespace impeller {
18
19 class MultiArchShaderArchive;
20
21 class ShaderArchive {
22 public:
23 ShaderArchive(ShaderArchive&&);
24
25 ~ShaderArchive();
26
27 bool IsValid() const;
28
29 size_t GetShaderCount() const;
30
31 std::shared_ptr<fml::Mapping> GetMapping(ArchiveShaderType type,
32 std::string name) const;
33
34 size_t IterateAllShaders(
35 const std::function<bool(ArchiveShaderType type,
36 const std::string& name,
37 const std::shared_ptr<fml::Mapping>& mapping)>&)
38 const;
39
40 private:
41 friend MultiArchShaderArchive;
42
43 struct ShaderKey {
44 ArchiveShaderType type = ArchiveShaderType::kFragment;
45 std::string name;
46
47 struct Hash {
48 size_t operator()(const ShaderKey& key) const {
49 return fml::HashCombine(
50 static_cast<std::underlying_type_t<decltype(key.type)>>(key.type),
51 key.name);
52 }
53 };
54
55 struct Equal {
56 bool operator()(const ShaderKey& lhs, const ShaderKey& rhs) const {
57 return lhs.type == rhs.type && lhs.name == rhs.name;
58 }
59 };
60 };
61
62 using Shaders = std::unordered_map<ShaderKey,
63 std::shared_ptr<fml::Mapping>,
64 ShaderKey::Hash,
65 ShaderKey::Equal>;
66
67 std::shared_ptr<const fml::Mapping> payload_;
68 Shaders shaders_;
69 bool is_valid_ = false;
70
71 explicit ShaderArchive(std::shared_ptr<const fml::Mapping> payload);
72
73 ShaderArchive(const ShaderArchive&) = delete;
74
75 ShaderArchive& operator=(const ShaderArchive&) = delete;
76 };
77
78 } // namespace impeller
79
80 #endif // FLUTTER_IMPELLER_SHADER_ARCHIVE_SHADER_ARCHIVE_H_
impeller::ShaderKey::Hash
Definition: shader_key.h:25
impeller::ShaderArchive
Definition: shader_archive.h:21
impeller::ShaderArchive::GetShaderCount
size_t GetShaderCount() const
Definition: shader_archive.cc:70
impeller::ShaderArchive::~ShaderArchive
~ShaderArchive()
impeller::ArchiveShaderType
ArchiveShaderType
Definition: shader_archive_types.h:10
impeller::ShaderArchive::ShaderKey::Equal
Definition: shader_archive.h:55
impeller::ShaderArchive::ShaderKey::Hash::operator()
size_t operator()(const ShaderKey &key) const
Definition: shader_archive.h:48
shader_archive_types.h
impeller::MultiArchShaderArchive
Definition: multi_arch_shader_archive.h:18
impeller::ShaderArchive::IsValid
bool IsValid() const
Definition: shader_archive.cc:66
impeller::ShaderArchive::ShaderKey::Hash
Definition: shader_archive.h:47
impeller::ArchiveShaderType::kFragment
@ kFragment
impeller::ShaderKey
Definition: shader_key.h:18
impeller::ShaderKey::Equal
Definition: shader_key.h:31
impeller::ShaderArchive::ShaderArchive
ShaderArchive(ShaderArchive &&)
impeller::ShaderArchive::ShaderKey::Equal::operator()
bool operator()(const ShaderKey &lhs, const ShaderKey &rhs) const
Definition: shader_archive.h:56
impeller::ShaderArchive::GetMapping
std::shared_ptr< fml::Mapping > GetMapping(ArchiveShaderType type, std::string name) const
Definition: shader_archive.cc:74
impeller
Definition: aiks_context.cc:10
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:84