Flutter Engine
The Flutter Engine
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
12#include "flutter/lib/gpu/export.h"
13#include "flutter/lib/gpu/shader.h"
14#include "flutter/lib/ui/dart_wrapper.h"
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();
23 FML_FRIEND_MAKE_REF_COUNTED(ShaderLibrary);
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
37 std::shared_ptr<fml::Mapping> payload);
38
39 /// Sets a return override for `MakeFromAsset` for testing purposes.
40 static void SetOverride(fml::RefPtr<ShaderLibrary> override_shader_library);
41
42 fml::RefPtr<Shader> GetShader(const std::string& shader_name,
43 Dart_Handle shader_wrapper) const;
44
45 ~ShaderLibrary() override;
46
47 private:
48 /// A global override used to inject a ShaderLibrary when running with the
49 /// Impeller playground. When set, `MakeFromAsset` will always just return
50 /// this library.
51 static fml::RefPtr<ShaderLibrary> override_shader_library_;
52
53 std::shared_ptr<fml::Mapping> payload_;
54 ShaderMap shaders_;
55
56 explicit ShaderLibrary(std::shared_ptr<fml::Mapping> payload,
57 ShaderMap shaders);
58
59 FML_DISALLOW_COPY_AND_ASSIGN(ShaderLibrary);
60};
61
62} // namespace gpu
63} // namespace flutter
64
65//----------------------------------------------------------------------------
66/// Exports
67///
68
69extern "C" {
70
73 Dart_Handle wrapper,
74 Dart_Handle asset_name);
75
79 Dart_Handle shader_name,
80 Dart_Handle shader_wrapper);
81
82} // extern "C"
83
84#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 > MakeFromShaders(ShaderMap shaders)
static fml::RefPtr< ShaderLibrary > MakeFromFlatbuffer(impeller::Context::BackendType backend_type, std::shared_ptr< fml::Mapping > payload)
std::unordered_map< std::string, fml::RefPtr< Shader > > ShaderMap
fml::RefPtr< Shader > GetShader(const std::string &shader_name, Dart_Handle shader_wrapper) const
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
#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: switches.h:32