| 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
16 namespace impeller {
17
18 class ShaderArchive {
19 public:
20 explicit ShaderArchive(std::shared_ptr<fml::Mapping> payload);
21
22 ShaderArchive(ShaderArchive&&);
23
24 ~ShaderArchive();
25
26 bool IsValid() const;
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 struct ShaderKey {
41 ArchiveShaderType type = ArchiveShaderType::kFragment;
42 std::string name;
43
44 struct Hash {
45 size_t operator()(const ShaderKey& key) const {
46 return fml::HashCombine(
47 static_cast<std::underlying_type_t<decltype(key.type)>>(key.type),
48 key.name);
49 }
50 };
51
52 struct Equal {
53 bool operator()(const ShaderKey& lhs, const ShaderKey& rhs) const {
54 return lhs.type == rhs.type && lhs.name == rhs.name;
55 }
56 };
57 };
58
59 using Shaders = std::unordered_map<ShaderKey,
60 std::shared_ptr<fml::Mapping>,
61 ShaderKey::Hash,
62 ShaderKey::Equal>;
63
64 std::shared_ptr<fml::Mapping> payload_;
65 Shaders shaders_;
66 bool is_valid_ = false;
67
68 ShaderArchive(const ShaderArchive&) = delete;
69
70 ShaderArchive& operator=(const ShaderArchive&) = delete;
71 };
72
73 } // namespace impeller
74
75 #endif // FLUTTER_IMPELLER_SHADER_ARCHIVE_SHADER_ARCHIVE_H_
impeller::ShaderKey::Hash
Definition: shader_key.h:24
impeller::ShaderArchive::ShaderArchive
ShaderArchive(std::shared_ptr< fml::Mapping > payload)
Definition: shader_archive.cc:28
impeller::ShaderArchive
Definition: shader_archive.h:18
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:52
impeller::ShaderArchive::ShaderKey::Hash::operator()
size_t operator()(const ShaderKey &key) const
Definition: shader_archive.h:45
shader_archive_types.h
impeller::ShaderArchive::IsValid
bool IsValid() const
Definition: shader_archive.cc:66
type
GLenum type
Definition: blit_command_gles.cc:127
impeller::ShaderArchive::ShaderKey::Hash
Definition: shader_archive.h:44
impeller::ArchiveShaderType::kFragment
@ kFragment
impeller::ShaderKey
Definition: shader_key.h:17
impeller::ShaderKey::Equal
Definition: shader_key.h:30
impeller::ShaderArchive::ShaderKey::Equal::operator()
bool operator()(const ShaderKey &lhs, const ShaderKey &rhs) const
Definition: shader_archive.h:53
impeller::ShaderArchive::GetMapping
std::shared_ptr< fml::Mapping > GetMapping(ArchiveShaderType type, std::string name) const
Definition: shader_archive.cc:74
impeller
Definition: allocation.cc:12
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