Flutter Engine
The Flutter Engine
shader.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_LIB_GPU_SHADER_H_
6#define FLUTTER_LIB_GPU_SHADER_H_
7
8#include <algorithm>
9#include <memory>
10#include <string>
11
12#include "flutter/lib/gpu/context.h"
13#include "flutter/lib/ui/dart_wrapper.h"
14#include "fml/memory/ref_ptr.h"
18
19namespace flutter {
20namespace gpu {
21
22/// An immutable collection of shaders loaded from a shader bundle asset.
23class Shader : public RefCountedDartWrappable<Shader> {
24 DEFINE_WRAPPERTYPEINFO();
25 FML_FRIEND_MAKE_REF_COUNTED(Shader);
26
27 public:
31 size_t size_in_bytes = 0;
32
34 const std::string& name) const;
35 };
36
37 ~Shader() override;
38
40 std::string entrypoint,
42 std::shared_ptr<fml::Mapping> code_mapping,
43 std::vector<impeller::ShaderStageIOSlot> inputs,
44 std::vector<impeller::ShaderStageBufferLayout> layouts,
45 std::unordered_map<std::string, UniformBinding> uniform_structs,
46 std::unordered_map<std::string, impeller::SampledImageSlot>
47 uniform_textures,
48 std::vector<impeller::DescriptorSetLayout> descriptor_set_layouts);
49
50 std::shared_ptr<const impeller::ShaderFunction> GetFunctionFromLibrary(
52
53 bool IsRegistered(Context& context);
54
55 bool RegisterSync(Context& context);
56
57 std::shared_ptr<impeller::VertexDescriptor> CreateVertexDescriptor() const;
58
59 const std::vector<impeller::DescriptorSetLayout>& GetDescriptorSetLayouts()
60 const;
61
63
64 const Shader::UniformBinding* GetUniformStruct(const std::string& name) const;
65
67 const std::string& name) const;
68
69 private:
70 Shader();
71
72 std::string entrypoint_;
74 std::shared_ptr<fml::Mapping> code_mapping_;
75 std::vector<impeller::ShaderStageIOSlot> inputs_;
76 std::vector<impeller::ShaderStageBufferLayout> layouts_;
77 std::unordered_map<std::string, UniformBinding> uniform_structs_;
78 std::unordered_map<std::string, impeller::SampledImageSlot> uniform_textures_;
79 std::vector<impeller::DescriptorSetLayout> descriptor_set_layouts_;
80
81 FML_DISALLOW_COPY_AND_ASSIGN(Shader);
82};
83
84} // namespace gpu
85} // namespace flutter
86
87//----------------------------------------------------------------------------
88/// Exports
89///
90
91extern "C" {
92
95 flutter::gpu::Shader* wrapper,
96 Dart_Handle struct_name_handle);
97
100 flutter::gpu::Shader* wrapper,
101 Dart_Handle struct_name_handle,
102 Dart_Handle member_name_handle);
103
104} // extern "C"
105
106#endif // FLUTTER_LIB_GPU_SHADER_H_
An immutable collection of shaders loaded from a shader bundle asset.
Definition: shader.h:23
const Shader::UniformBinding * GetUniformStruct(const std::string &name) const
Definition: shader.cc:106
impeller::ShaderStage GetShaderStage() const
Definition: shader.cc:97
bool IsRegistered(Context &context)
Definition: shader.cc:65
bool RegisterSync(Context &context)
Definition: shader.cc:70
static fml::RefPtr< 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)
Definition: shader.cc:38
std::shared_ptr< impeller::VertexDescriptor > CreateVertexDescriptor() const
Definition: shader.cc:90
const std::vector< impeller::DescriptorSetLayout > & GetDescriptorSetLayouts() const
Definition: shader.cc:102
const impeller::SampledImageSlot * GetUniformTexture(const std::string &name) const
Definition: shader.cc:115
std::shared_ptr< const impeller::ShaderFunction > GetFunctionFromLibrary(impeller::ShaderLibrary &library)
Definition: shader.cc:60
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
#define FLUTTER_GPU_EXPORT
Definition: export.h:13
FLUTTER_GPU_EXPORT int InternalFlutterGpu_Shader_GetUniformMemberOffset(flutter::gpu::Shader *wrapper, Dart_Handle struct_name_handle, Dart_Handle member_name_handle)
Definition: shader.cc:143
FLUTTER_GPU_EXPORT int InternalFlutterGpu_Shader_GetUniformStructSize(flutter::gpu::Shader *wrapper, Dart_Handle struct_name_handle)
Definition: shader.cc:131
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
impeller::ShaderMetadata metadata
Definition: shader.h:30
impeller::ShaderUniformSlot slot
Definition: shader.h:29
const impeller::ShaderStructMemberMetadata * GetMemberMetadata(const std::string &name) const
Definition: shader.cc:20
Metadata required to bind a combined texture and sampler.
Definition: shader_types.h:98
Metadata required to bind a buffer.
Definition: shader_types.h:81