| 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 #pragma once
6
7 #include <Foundation/Foundation.h>
8 #include <Metal/Metal.h>
9
10 #include <memory>
11 #include <string>
12 #include <unordered_map>
13
14 #include "flutter/fml/macros.h"
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 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 FML_DISALLOW_COPY_AND_ASSIGN(ShaderLibraryMTL);
62 };
63
64 } // namespace impeller
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:20
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:18
impeller::UniqueID
Definition: comparable.h:19
impeller::ContextMTL
Definition: context_mtl.h:32
thread.h
impeller
Definition: aiks_context.cc:10
impeller::ShaderLibraryMTL::IsValid
bool IsValid() const override
Definition: shader_library_mtl.mm:24