Flutter Impeller
impeller::BlobLibrary Class Reference

#include <blob_library.h>

Public Member Functions

 BlobLibrary (std::shared_ptr< fml::Mapping > payload)
 
 BlobLibrary (BlobLibrary &&)
 
 ~BlobLibrary ()
 
bool IsValid () const
 
size_t GetShaderCount () const
 
std::shared_ptr< fml::Mapping > GetMapping (BlobShaderType type, std::string name) const
 
size_t IterateAllBlobs (const std::function< bool(BlobShaderType type, const std::string &name, const std::shared_ptr< fml::Mapping > &mapping)> &) const
 

Detailed Description

Definition at line 18 of file blob_library.h.

Constructor & Destructor Documentation

◆ BlobLibrary() [1/2]

impeller::BlobLibrary::BlobLibrary ( std::shared_ptr< fml::Mapping >  payload)
explicit

Definition at line 28 of file blob_library.cc.

29  : payload_(std::move(payload)) {
30  if (!payload_ || payload_->GetMapping() == nullptr) {
31  VALIDATION_LOG << "Blob mapping was absent.";
32  return;
33  }
34 
35  if (!fb::BlobLibraryBufferHasIdentifier(payload_->GetMapping())) {
36  VALIDATION_LOG << "Invalid blob magic.";
37  return;
38  }
39 
40  auto blob_library = fb::GetBlobLibrary(payload_->GetMapping());
41  if (!blob_library) {
42  return;
43  }
44 
45  if (auto items = blob_library->items()) {
46  for (auto i = items->begin(), end = items->end(); i != end; i++) {
47  BlobKey key;
48  key.name = i->name()->str();
49  key.type = ToShaderType(i->stage());
50  blobs_[key] = std::make_shared<fml::NonOwnedMapping>(
51  i->mapping()->Data(), i->mapping()->size(),
52  [payload = payload_](auto, auto) {
53  // The pointers are into the base payload. Instead of copying the
54  // data, just hold onto the payload.
55  });
56  }
57  }
58 
59  is_valid_ = true;
60 }

References impeller::ToShaderType(), and VALIDATION_LOG.

◆ BlobLibrary() [2/2]

impeller::BlobLibrary::BlobLibrary ( BlobLibrary &&  )
default

◆ ~BlobLibrary()

impeller::BlobLibrary::~BlobLibrary ( )
default

Member Function Documentation

◆ GetMapping()

std::shared_ptr< fml::Mapping > impeller::BlobLibrary::GetMapping ( BlobShaderType  type,
std::string  name 
) const

Definition at line 74 of file blob_library.cc.

75  {
76  BlobKey key;
77  key.type = type;
78  key.name = std::move(name);
79  auto found = blobs_.find(key);
80  return found == blobs_.end() ? nullptr : found->second;
81 }

Referenced by impeller::testing::TEST().

◆ GetShaderCount()

size_t impeller::BlobLibrary::GetShaderCount ( ) const

Definition at line 70 of file blob_library.cc.

70  {
71  return blobs_.size();
72 }

Referenced by impeller::testing::TEST().

◆ IsValid()

bool impeller::BlobLibrary::IsValid ( ) const

Definition at line 66 of file blob_library.cc.

66  {
67  return is_valid_;
68 }

Referenced by IterateAllBlobs(), and impeller::testing::TEST().

◆ IterateAllBlobs()

size_t impeller::BlobLibrary::IterateAllBlobs ( const std::function< bool(BlobShaderType type, const std::string &name, const std::shared_ptr< fml::Mapping > &mapping)> &  callback) const

Definition at line 83 of file blob_library.cc.

87  {
88  if (!IsValid() || !callback) {
89  return 0u;
90  }
91  size_t count = 0u;
92  for (const auto& blob : blobs_) {
93  count++;
94  if (!callback(blob.first.type, blob.first.name, blob.second)) {
95  break;
96  }
97  }
98  return count;
99 }

References IsValid().


The documentation for this class was generated from the following files:
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
impeller::ToShaderType
constexpr BlobShaderType ToShaderType(fb::Stage stage)
Definition: blob_library.cc:16
impeller::BlobLibrary::IsValid
bool IsValid() const
Definition: blob_library.cc:66