Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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< T > 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::VertexDescriptorGetVertexDescriptor () 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< T >
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
 
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::shared_ptr< impeller::VertexDescriptor > vertex_desc, std::unordered_map< std::string, UniformBinding > uniform_structs, std::unordered_map< std::string, impeller::SampledImageSlot > uniform_textures)
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields { kPeerIndex , kNumberOfNativeFields }
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< T >
 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

◆ GetFunctionFromLibrary()

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

Definition at line 56 of file shader.cc.

57 {
58 return library.GetFunction(entrypoint_, stage_);
59}
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 91 of file shader.cc.

91 {
92 return stage_;
93}

◆ GetUniformStruct()

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

Definition at line 95 of file shader.cc.

96 {
97 auto uniform = uniform_structs_.find(name);
98 if (uniform == uniform_structs_.end()) {
99 return nullptr;
100 }
101 return &uniform->second;
102}
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 104 of file shader.cc.

105 {
106 auto uniform = uniform_textures_.find(name);
107 if (uniform == uniform_textures_.end()) {
108 return nullptr;
109 }
110 return &uniform->second;
111}

◆ GetVertexDescriptor()

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

Definition at line 86 of file shader.cc.

87 {
88 return vertex_desc_;
89}

◆ IsRegistered()

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

Definition at line 61 of file shader.cc.

61 {
62 auto& lib = *context.GetContext()->GetShaderLibrary();
63 return GetFunctionFromLibrary(lib) != nullptr;
64}
std::shared_ptr< const impeller::ShaderFunction > GetFunctionFromLibrary(impeller::ShaderLibrary &library)
Definition shader.cc:56

◆ Make()

fml::RefPtr< Shader > flutter::gpu::Shader::Make ( std::string  entrypoint,
impeller::ShaderStage  stage,
std::shared_ptr< fml::Mapping code_mapping,
std::shared_ptr< impeller::VertexDescriptor vertex_desc,
std::unordered_map< std::string, UniformBinding uniform_structs,
std::unordered_map< std::string, impeller::SampledImageSlot uniform_textures 
)
static

Definition at line 38 of file shader.cc.

45 {
46 auto shader = fml::MakeRefCounted<Shader>();
47 shader->entrypoint_ = std::move(entrypoint);
48 shader->stage_ = stage;
49 shader->code_mapping_ = std::move(code_mapping);
50 shader->vertex_desc_ = std::move(vertex_desc);
51 shader->uniform_structs_ = std::move(uniform_structs);
52 shader->uniform_textures_ = std::move(uniform_textures);
53 return shader;
54}

◆ RegisterSync()

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

Definition at line 66 of file shader.cc.

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

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