Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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"
16
17namespace impeller {
18
19class MultiArchShaderArchive;
20
22 public:
24
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:
42
43 struct ShaderKey {
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>,
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_
ShaderArchive(ShaderArchive &&)
size_t IterateAllShaders(const std::function< bool(ArchiveShaderType type, const std::string &name, const std::shared_ptr< fml::Mapping > &mapping)> &) const
size_t GetShaderCount() const
std::shared_ptr< fml::Mapping > GetMapping(ArchiveShaderType type, std::string name) const
const char * name
Definition fuchsia.cc:50
constexpr std::size_t HashCombine()
bool operator()(const ShaderKey &lhs, const ShaderKey &rhs) const
size_t operator()(const ShaderKey &key) const