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"
15 #include "third_party/abseil-cpp/absl/status/statusor.h"
16 
17 namespace impeller {
18 
20  public:
21  static absl::StatusOr<ShaderArchive> Create(
22  std::shared_ptr<fml::Mapping> payload);
23 
25 
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 {
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>,
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_
GLenum type
ShaderArchive(ShaderArchive &&)
size_t IterateAllShaders(const std::function< bool(ArchiveShaderType type, const std::string &name, const std::shared_ptr< fml::Mapping > &mapping)> &) const
static absl::StatusOr< ShaderArchive > Create(std::shared_ptr< fml::Mapping > payload)
size_t GetShaderCount() const
std::shared_ptr< fml::Mapping > GetMapping(ArchiveShaderType type, std::string name) const
bool operator()(const ShaderKey &lhs, const ShaderKey &rhs) const
size_t operator()(const ShaderKey &key) const