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