Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
shader_library.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_LIBRARY_H_
6#define FLUTTER_LIB_GPU_SHADER_LIBRARY_H_
7
8#include <memory>
9#include <string>
10#include <unordered_map>
11
15#include "fml/memory/ref_ptr.h"
16
17namespace flutter {
18namespace gpu {
19
20/// An immutable collection of shaders loaded from a shader bundle asset.
21class ShaderLibrary : public RefCountedDartWrappable<ShaderLibrary> {
22 DEFINE_WRAPPERTYPEINFO();
24
25 public:
26 using ShaderMap = std::unordered_map<std::string, fml::RefPtr<Shader>>;
27
30 const std::string& name,
31 std::string& out_error);
32
34
35 /// `library_id` is a stable identifier (typically the asset path the
36 /// bundle was loaded from) used to namespace the shaders' entrypoints in
37 /// the shared shader registry, so they cannot collide with engine-internal
38 /// shaders or with shaders from a different bundle. If empty, a
39 /// process-unique fallback is generated.
42 std::shared_ptr<fml::Mapping> payload,
43 std::string library_id = "");
44
45 /// Sets a return override for `MakeFromAsset` for testing purposes.
46 static void SetOverride(fml::RefPtr<ShaderLibrary> override_shader_library);
47
48 fml::RefPtr<Shader> GetShader(const std::string& shader_name,
49 Dart_Handle shader_wrapper) const;
50
51 ~ShaderLibrary() override;
52
53 private:
54 /// A global override used to inject a ShaderLibrary when running with the
55 /// Impeller playground. When set, `MakeFromAsset` will always just return
56 /// this library.
57 static fml::RefPtr<ShaderLibrary> override_shader_library_;
58
59 std::shared_ptr<fml::Mapping> payload_;
60 ShaderMap shaders_;
61
62 explicit ShaderLibrary(std::shared_ptr<fml::Mapping> payload,
63 ShaderMap shaders);
64
66};
67
68} // namespace gpu
69} // namespace flutter
70
71//----------------------------------------------------------------------------
72/// Exports
73///
74
75extern "C" {
76
79 Dart_Handle wrapper,
80 Dart_Handle asset_name);
81
85 Dart_Handle shader_name,
86 Dart_Handle shader_wrapper);
87
88} // extern "C"
89
90#endif // FLUTTER_LIB_GPU_SHADER_LIBRARY_H_
An immutable collection of shaders loaded from a shader bundle asset.
static void SetOverride(fml::RefPtr< ShaderLibrary > override_shader_library)
Sets a return override for MakeFromAsset for testing purposes.
static fml::RefPtr< ShaderLibrary > MakeFromAsset(impeller::Context::BackendType backend_type, const std::string &name, std::string &out_error)
static fml::RefPtr< ShaderLibrary > MakeFromFlatbuffer(impeller::Context::BackendType backend_type, std::shared_ptr< fml::Mapping > payload, std::string library_id="")
static fml::RefPtr< ShaderLibrary > MakeFromShaders(ShaderMap shaders)
std::unordered_map< std::string, fml::RefPtr< Shader > > ShaderMap
fml::RefPtr< Shader > GetShader(const std::string &shader_name, Dart_Handle shader_wrapper) const
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
#define FLUTTER_GPU_EXPORT
Definition export.h:13
FLUTTER_GPU_EXPORT Dart_Handle InternalFlutterGpu_ShaderLibrary_InitializeWithAsset(Dart_Handle wrapper, Dart_Handle asset_name)
FLUTTER_GPU_EXPORT Dart_Handle InternalFlutterGpu_ShaderLibrary_GetShader(flutter::gpu::ShaderLibrary *wrapper, Dart_Handle shader_name, Dart_Handle shader_wrapper)
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27
#define FML_FRIEND_MAKE_REF_COUNTED(T)