Flutter Impeller
blob_library.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 #pragma once
6 
7 #include <memory>
8 #include <type_traits>
9 #include <unordered_map>
10 
11 #include "flutter/fml/hash_combine.h"
12 #include "flutter/fml/macros.h"
13 #include "flutter/fml/mapping.h"
15 
16 namespace impeller {
17 
18 class BlobLibrary {
19  public:
20  explicit BlobLibrary(std::shared_ptr<fml::Mapping> payload);
21 
23 
24  ~BlobLibrary();
25 
26  bool IsValid() const;
27 
28  size_t GetShaderCount() const;
29 
30  std::shared_ptr<fml::Mapping> GetMapping(BlobShaderType type,
31  std::string name) const;
32 
33  size_t IterateAllBlobs(
34  const std::function<bool(BlobShaderType type,
35  const std::string& name,
36  const std::shared_ptr<fml::Mapping>& mapping)>&)
37  const;
38 
39  private:
40  struct BlobKey {
42  std::string name;
43 
44  struct Hash {
45  size_t operator()(const BlobKey& 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 BlobKey& lhs, const BlobKey& rhs) const {
54  return lhs.type == rhs.type && lhs.name == rhs.name;
55  }
56  };
57  };
58 
59  using Blobs = std::unordered_map<BlobKey,
60  std::shared_ptr<fml::Mapping>,
61  BlobKey::Hash,
62  BlobKey::Equal>;
63 
64  std::shared_ptr<fml::Mapping> payload_;
65  Blobs blobs_;
66  bool is_valid_ = false;
67 
68  FML_DISALLOW_COPY_AND_ASSIGN(BlobLibrary);
69 };
70 
71 } // namespace impeller
impeller::BlobLibrary
Definition: blob_library.h:18
impeller::BlobLibrary::BlobLibrary
BlobLibrary(std::shared_ptr< fml::Mapping > payload)
Definition: blob_library.cc:28
impeller::BlobLibrary::~BlobLibrary
~BlobLibrary()
impeller::BlobLibrary::BlobKey::Hash
Definition: blob_library.h:44
impeller::BlobLibrary::GetMapping
std::shared_ptr< fml::Mapping > GetMapping(BlobShaderType type, std::string name) const
Definition: blob_library.cc:74
impeller::BlobLibrary::BlobKey::Hash::operator()
size_t operator()(const BlobKey &key) const
Definition: blob_library.h:45
impeller::BlobLibrary::GetShaderCount
size_t GetShaderCount() const
Definition: blob_library.cc:70
impeller::BlobShaderType
BlobShaderType
Definition: blob_types.h:9
impeller::BlobShaderType::kFragment
@ kFragment
impeller::BlobLibrary::BlobKey::Equal
Definition: blob_library.h:52
impeller::BlobLibrary::IsValid
bool IsValid() const
Definition: blob_library.cc:66
impeller::BlobLibrary::IterateAllBlobs
size_t IterateAllBlobs(const std::function< bool(BlobShaderType type, const std::string &name, const std::shared_ptr< fml::Mapping > &mapping)> &) const
Definition: blob_library.cc:83
blob_types.h
impeller::BlobLibrary::BlobKey::Equal::operator()
bool operator()(const BlobKey &lhs, const BlobKey &rhs) const
Definition: blob_library.h:53
impeller
Definition: aiks_context.cc:10