Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | List of all members
flutter::gpu::Shader Class Reference

An immutable collection of shaders loaded from a shader bundle asset. More...

#include <shader.h>

Inheritance diagram for flutter::gpu::Shader:
flutter::RefCountedDartWrappable< Shader > fml::RefCountedThreadSafe< Shader > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase

Classes

struct  UniformBinding
 

Public Member Functions

 ~Shader () override
 
std::shared_ptr< const impeller::ShaderFunctionGetFunctionFromLibrary (impeller::ShaderLibrary &library)
 
bool IsRegistered (Context &context)
 
bool RegisterSync (Context &context)
 
std::shared_ptr< impeller::VertexDescriptorCreateVertexDescriptor () const
 
const std::vector< impeller::DescriptorSetLayout > & GetDescriptorSetLayouts () const
 
impeller::ShaderStage GetShaderStage () const
 
const Shader::UniformBindingGetUniformStruct (const std::string &name) const
 
const impeller::SampledImageSlotGetUniformTexture (const std::string &name) const
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< Shader >
virtual void RetainDartWrappableReference () const override
 
virtual void ReleaseDartWrappableReference () const override
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< Shader >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
virtual void RetainDartWrappableReference () const =0
 
virtual void ReleaseDartWrappableReference () const =0
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Static Public Member Functions

static fml::RefPtr< ShaderMake (std::string entrypoint, impeller::ShaderStage stage, std::shared_ptr< fml::Mapping > code_mapping, std::vector< impeller::ShaderStageIOSlot > inputs, std::vector< impeller::ShaderStageBufferLayout > layouts, std::unordered_map< std::string, UniformBinding > uniform_structs, std::unordered_map< std::string, impeller::SampledImageSlot > uniform_textures, std::vector< impeller::DescriptorSetLayout > descriptor_set_layouts)
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields { kPeerIndex , kNumberOfNativeFields }
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< Shader >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
 
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

An immutable collection of shaders loaded from a shader bundle asset.

Definition at line 23 of file shader.h.

Constructor & Destructor Documentation

◆ ~Shader()

flutter::gpu::Shader::~Shader ( )
overridedefault

Member Function Documentation

◆ CreateVertexDescriptor()

std::shared_ptr< impeller::VertexDescriptor > flutter::gpu::Shader::CreateVertexDescriptor ( ) const

Definition at line 90 of file shader.cc.

91 {
92 auto vertex_descriptor = std::make_shared<impeller::VertexDescriptor>();
93 vertex_descriptor->SetStageInputs(inputs_, layouts_);
94 return vertex_descriptor;
95}

◆ GetDescriptorSetLayouts()

const std::vector< impeller::DescriptorSetLayout > & flutter::gpu::Shader::GetDescriptorSetLayouts ( ) const

Definition at line 102 of file shader.cc.

102 {
103 return descriptor_set_layouts_;
104}

◆ GetFunctionFromLibrary()

std::shared_ptr< const impeller::ShaderFunction > flutter::gpu::Shader::GetFunctionFromLibrary ( impeller::ShaderLibrary library)

Definition at line 60 of file shader.cc.

61 {
62 return library.GetFunction(entrypoint_, stage_);
63}
virtual std::shared_ptr< const ShaderFunction > GetFunction(std::string_view name, ShaderStage stage)=0

◆ GetShaderStage()

impeller::ShaderStage flutter::gpu::Shader::GetShaderStage ( ) const

Definition at line 97 of file shader.cc.

97 {
98 return stage_;
99}

◆ GetUniformStruct()

const Shader::UniformBinding * flutter::gpu::Shader::GetUniformStruct ( const std::string &  name) const

Definition at line 106 of file shader.cc.

107 {
108 auto uniform = uniform_structs_.find(name);
109 if (uniform == uniform_structs_.end()) {
110 return nullptr;
111 }
112 return &uniform->second;
113}
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ GetUniformTexture()

const impeller::SampledImageSlot * flutter::gpu::Shader::GetUniformTexture ( const std::string &  name) const

Definition at line 115 of file shader.cc.

116 {
117 auto uniform = uniform_textures_.find(name);
118 if (uniform == uniform_textures_.end()) {
119 return nullptr;
120 }
121 return &uniform->second;
122}

◆ IsRegistered()

bool flutter::gpu::Shader::IsRegistered ( Context context)

Definition at line 65 of file shader.cc.

65 {
66 auto& lib = *context.GetContext()->GetShaderLibrary();
67 return GetFunctionFromLibrary(lib) != nullptr;
68}
std::shared_ptr< const impeller::ShaderFunction > GetFunctionFromLibrary(impeller::ShaderLibrary &library)
Definition: shader.cc:60

◆ Make()

fml::RefPtr< Shader > flutter::gpu::Shader::Make ( std::string  entrypoint,
impeller::ShaderStage  stage,
std::shared_ptr< fml::Mapping code_mapping,
std::vector< impeller::ShaderStageIOSlot inputs,
std::vector< impeller::ShaderStageBufferLayout layouts,
std::unordered_map< std::string, UniformBinding uniform_structs,
std::unordered_map< std::string, impeller::SampledImageSlot uniform_textures,
std::vector< impeller::DescriptorSetLayout descriptor_set_layouts 
)
static

Definition at line 38 of file shader.cc.

47 {
48 auto shader = fml::MakeRefCounted<Shader>();
49 shader->entrypoint_ = std::move(entrypoint);
50 shader->stage_ = stage;
51 shader->code_mapping_ = std::move(code_mapping);
52 shader->inputs_ = std::move(inputs);
53 shader->layouts_ = std::move(layouts);
54 shader->uniform_structs_ = std::move(uniform_structs);
55 shader->uniform_textures_ = std::move(uniform_textures);
56 shader->descriptor_set_layouts_ = std::move(descriptor_set_layouts);
57 return shader;
58}

◆ RegisterSync()

bool flutter::gpu::Shader::RegisterSync ( Context context)

Definition at line 70 of file shader.cc.

70 {
71 if (IsRegistered(context)) {
72 return true; // Already registered.
73 }
74
75 auto& lib = *context.GetContext()->GetShaderLibrary();
76
77 std::promise<bool> promise;
78 auto future = promise.get_future();
79 lib.RegisterFunction(
80 entrypoint_, stage_, code_mapping_,
81 fml::MakeCopyable([promise = std::move(promise)](bool result) mutable {
82 promise.set_value(result);
83 }));
84 if (!future.get()) {
85 return false; // Registration failed.
86 }
87 return true;
88}
bool IsRegistered(Context &context)
Definition: shader.cc:65
GAsyncResult * result
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57

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