Flutter Impeller
impeller::ShaderArchive Class Reference

#include <shader_archive.h>

Public Member Functions

 ShaderArchive (ShaderArchive &&)
 
 ~ShaderArchive ()
 
size_t GetShaderCount () const
 
std::shared_ptr< fml::Mapping > GetMapping (ArchiveShaderType type, std::string name) const
 
size_t IterateAllShaders (const std::function< bool(ArchiveShaderType type, const std::string &name, const std::shared_ptr< fml::Mapping > &mapping)> &) const
 

Static Public Member Functions

static absl::StatusOr< ShaderArchiveCreate (std::shared_ptr< fml::Mapping > payload)
 

Detailed Description

Definition at line 19 of file shader_archive.h.

Constructor & Destructor Documentation

◆ ShaderArchive()

impeller::ShaderArchive::ShaderArchive ( ShaderArchive &&  )
default

Referenced by Create().

◆ ~ShaderArchive()

impeller::ShaderArchive::~ShaderArchive ( )
default

Member Function Documentation

◆ Create()

absl::StatusOr< ShaderArchive > impeller::ShaderArchive::Create ( std::shared_ptr< fml::Mapping >  payload)
static

Definition at line 29 of file shader_archive.cc.

30  {
31  if (!payload || payload->GetMapping() == nullptr) {
32  return absl::InvalidArgumentError("Shader mapping was absent.");
33  }
34 
35  if (!fb::ShaderArchiveBufferHasIdentifier(payload->GetMapping())) {
36  return absl::InvalidArgumentError("Invalid shader magic.");
37  }
38 
39  auto shader_archive = fb::GetShaderArchive(payload->GetMapping());
40  if (!shader_archive) {
41  return absl::InvalidArgumentError("Could not read shader archive.");
42  }
43 
44  const auto version = shader_archive->format_version();
45  const auto expected =
46  static_cast<uint32_t>(fb::ShaderArchiveFormatVersion::kVersion);
47  if (version != expected) {
48  std::stringstream stream;
49  stream << "Unsupported shader archive format version. Expected: "
50  << expected << ", Got: " << version;
51  return absl::InvalidArgumentError(stream.str());
52  }
53 
54  Shaders shaders;
55  if (auto items = shader_archive->items()) {
56  for (auto i = items->begin(), end = items->end(); i != end; i++) {
57  ShaderKey key;
58  key.name = i->name()->str();
59  key.type = ToShaderType(i->stage());
60  shaders[key] = std::make_shared<fml::NonOwnedMapping>(
61  i->mapping()->Data(), i->mapping()->size(), [payload](auto, auto) {
62  // The pointers are into the base payload. Instead of copying the
63  // data, just hold onto the payload.
64  });
65  }
66  }
67 
68  return ShaderArchive(std::move(payload), std::move(shaders));
69 }
ShaderArchive(ShaderArchive &&)
constexpr ArchiveShaderType ToShaderType(fb::Stage stage)
const size_t end

References end, ShaderArchive(), and impeller::ToShaderType().

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

◆ GetMapping()

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

Definition at line 83 of file shader_archive.cc.

85  {
86  ShaderKey key;
87  key.type = type;
88  key.name = std::move(name);
89  auto found = shaders_.find(key);
90  return found == shaders_.end() ? nullptr : found->second;
91 }
GLenum type

References type.

◆ GetShaderCount()

size_t impeller::ShaderArchive::GetShaderCount ( ) const

Definition at line 79 of file shader_archive.cc.

79  {
80  return shaders_.size();
81 }

◆ IterateAllShaders()

size_t impeller::ShaderArchive::IterateAllShaders ( const std::function< bool(ArchiveShaderType type, const std::string &name, const std::shared_ptr< fml::Mapping > &mapping)> &  callback) const

Definition at line 93 of file shader_archive.cc.

97  {
98  if (!callback) {
99  return 0u;
100  }
101  size_t count = 0u;
102  for (const auto& shader : shaders_) {
103  count++;
104  if (!callback(shader.first.type, shader.first.name, shader.second)) {
105  break;
106  }
107  }
108  return count;
109 }

The documentation for this class was generated from the following files: