| Flutter Impeller |

Classes | Public Member Functions | List of all members
impeller::ShaderArchive Class Reference

`#include <shader_archive.h>`

## Public Member Functions
| ShaderArchive (std::shared_ptr< fml::Mapping > payload)
| ShaderArchive (ShaderArchive &&)
| ~ShaderArchive ()
bool | IsValid () const
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

## Detailed Description

Definition at line 18 of file shader_archive.h.

## Constructor & Destructor Documentation

## ◆ ShaderArchive() [1/2]

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

Definition at line 28 of file shader_archive.cc.

29 : payload_(std::move(payload)) {
30 if (!payload_ || payload_->GetMapping() == nullptr) {
31 VALIDATION_LOG << "Shader mapping was absent.";
32 return;
33 }
34
35 if (!fb::ShaderArchiveBufferHasIdentifier(payload_->GetMapping())) {
36 VALIDATION_LOG << "Invalid shader magic.";
37 return;
38 }
39
40 auto shader_archive = fb::GetShaderArchive(payload_->GetMapping());
41 if (!shader_archive) {
42 return;
43 }
44
45 if (auto items = shader_archive->items()) {
46 for (auto i = items->begin(), end = items->end(); i != end; i++) {
47 ShaderKey key;
48 key.name = i->name()->str();
49 key.type = ToShaderType(i->stage());
50 shaders_[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 }
impeller::ToShaderType
constexpr ArchiveShaderType ToShaderType(fb::Stage stage)
Definition: shader_archive.cc:16
end
const size_t end
Definition: tessellator_libtess.cc:63
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

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

## ◆ ShaderArchive() [2/2]

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

## ◆ ~ShaderArchive()

impeller::ShaderArchive::~ShaderArchive | ( |  | ) |
| default

## Member Function Documentation

## ◆ GetMapping()

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

Definition at line 74 of file shader_archive.cc.

76 {
77 ShaderKey key;
78 key.type = type;
79 key.name = std::move(name);
80 auto found = shaders_.find(key);
81 return found == shaders_.end() ? nullptr : found->second;
82 }
type
GLenum type
Definition: blit_command_gles.cc:151

References type.

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

## ◆ GetShaderCount()

size_t impeller::ShaderArchive::GetShaderCount | ( |  | ) | const

Definition at line 70 of file shader_archive.cc.

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

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

## ◆ IsValid()

bool impeller::ShaderArchive::IsValid | ( |  | ) | const

Definition at line 66 of file shader_archive.cc.

66 {
67 return is_valid_;
68 }

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

## ◆ 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 84 of file shader_archive.cc.

88 {
89 if (!IsValid() || !callback) {
90 return 0u;
91 }
92 size_t count = 0u;
93 for (const auto& shader : shaders_) {
94 count++;
95 if (!callback(shader.first.type, shader.first.name, shader.second)) {
96 break;
97 }
98 }
99 return count;
100 }
impeller::ShaderArchive::IsValid
bool IsValid() const
Definition: shader_archive.cc:66

References IsValid().

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

- impeller/shader_archive/shader_archive.h
- impeller/shader_archive/shader_archive.cc