| Flutter Impeller |

shader_library_mtl.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_IMPELLER_RENDERER_BACKEND_METAL_SHADER_LIBRARY_MTL_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_SHADER_LIBRARY_MTL_H_
7
8 #include <Foundation/Foundation.h>
9 #include <Metal/Metal.h>
10
11 #include <memory>
12 #include <string>
13 #include <unordered_map>
14
15 #include "impeller/base/comparable.h"
16 #include "impeller/base/thread.h"
17 #include "impeller/renderer/shader_key.h"
18 #include "impeller/renderer/shader_library.h"
19
20 namespace impeller {
21
22 class ShaderLibraryMTL final : public ShaderLibrary {
23 public:
24 ShaderLibraryMTL();
25
26 // |ShaderLibrary|
27 ~ShaderLibraryMTL() override;
28
29 // |ShaderLibrary|
30 bool IsValid() const override;
31
32 private:
33 friend class ContextMTL;
34
35 UniqueID library_id_;
36 mutable RWMutex libraries_mutex_;
37 NSMutableArray<id<MTLLibrary>>* libraries_ IPLR_GUARDED_BY(libraries_mutex_) =
38 nullptr;
39 ShaderFunctionMap functions_;
40 bool is_valid_ = false;
41
42 explicit ShaderLibraryMTL(NSArray<id<MTLLibrary>>* libraries);
43
44 // |ShaderLibrary|
45 std::shared_ptr<const ShaderFunction> GetFunction(std::string_view name,
46 ShaderStage stage) override;
47
48 // |ShaderLibrary|
49 void RegisterFunction(std::string name,
50 ShaderStage stage,
51 std::shared_ptr<fml::Mapping> code,
52 RegistrationCallback callback) override;
53
54 // |ShaderLibrary|
55 void UnregisterFunction(std::string name, ShaderStage stage) override;
56
57 id<MTLDevice> GetDevice() const;
58
59 void RegisterLibrary(id<MTLLibrary> library);
60
61 ShaderLibraryMTL(const ShaderLibraryMTL&) = delete;
62
63 ShaderLibraryMTL& operator=(const ShaderLibraryMTL&) = delete;
64 };
65
66 } // namespace impeller
67
68 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_SHADER_LIBRARY_MTL_H_
impeller::ShaderLibraryMTL::~ShaderLibraryMTL
~ShaderLibraryMTL() override
shader_library.h
shader_key.h
impeller::ShaderLibrary::RegistrationCallback
std::function< void(bool)> RegistrationCallback
Definition: shader_library.h:30
impeller::ShaderLibrary
Definition: shader_library.h:20
impeller::ShaderStage
ShaderStage
Definition: shader_types.h:22
impeller::ShaderFunctionMap
std::unordered_map< ShaderKey, std::shared_ptr< const ShaderFunction >, ShaderKey::Hash, ShaderKey::Equal > ShaderFunctionMap
Definition: shader_key.h:43
impeller::ShaderLibraryMTL::ShaderLibraryMTL
ShaderLibraryMTL()
comparable.h
impeller::ShaderLibraryMTL
Definition: shader_library_mtl.h:22
IPLR_GUARDED_BY
#define IPLR_GUARDED_BY(x)
Definition: thread_safety.h:19
impeller::UniqueID
Definition: comparable.h:16
impeller::ContextMTL
Definition: context_mtl.h:34
thread.h
impeller
Definition: aiks_blend_unittests.cc:18
impeller::ShaderLibraryMTL::IsValid
bool IsValid() const override
Definition: shader_library_mtl.mm:24