5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_CONTEXT_MTL_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_CONTEXT_MTL_H_
8 #include <Metal/Metal.h>
13 #include "flutter/fml/concurrent_message_loop.h"
14 #include "flutter/fml/macros.h"
15 #include "flutter/fml/synchronization/sync_switch.h"
27 #if TARGET_OS_SIMULATOR
28 #define IMPELLER_CA_METAL_LAYER_AVAILABLE API_AVAILABLE(macos(10.11), ios(13.0))
29 #else // TARGET_OS_SIMULATOR
30 #define IMPELLER_CA_METAL_LAYER_AVAILABLE API_AVAILABLE(macos(10.11), ios(8.0))
31 #endif // TARGET_OS_SIMULATOR
37 public std::enable_shared_from_this<ContextMTL> {
39 static std::shared_ptr<ContextMTL>
Create(
40 const std::vector<std::string>& shader_library_paths,
41 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
43 static std::shared_ptr<ContextMTL>
Create(
44 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
45 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
46 const std::string& label);
48 static std::shared_ptr<ContextMTL>
Create(
50 id<MTLCommandQueue> command_queue,
51 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
52 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
53 const std::string& label);
88 const std::shared_ptr<const Capabilities>&
GetCapabilities()
const override;
90 void SetCapabilities(
const std::shared_ptr<const Capabilities>& capabilities);
102 #ifdef IMPELLER_DEBUG
103 std::shared_ptr<GPUTracerMTL> GetGPUTracer()
const;
104 #endif // IMPELLER_DEBUG
110 class SyncSwitchObserver :
public fml::SyncSwitch::Observer {
112 explicit SyncSwitchObserver(
ContextMTL& parent);
113 virtual ~SyncSwitchObserver() =
default;
114 void OnSyncSwitchUpdate(
bool new_value)
override;
120 id<MTLDevice> device_ =
nullptr;
121 id<MTLCommandQueue> command_queue_ =
nullptr;
122 std::shared_ptr<ShaderLibraryMTL> shader_library_;
123 std::shared_ptr<PipelineLibraryMTL> pipeline_library_;
124 std::shared_ptr<SamplerLibrary> sampler_library_;
125 std::shared_ptr<AllocatorMTL> resource_allocator_;
126 std::shared_ptr<const Capabilities> device_capabilities_;
127 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch_;
128 #ifdef IMPELLER_DEBUG
129 std::shared_ptr<GPUTracerMTL> gpu_tracer_;
130 #endif // IMPELLER_DEBUG
131 std::deque<std::function<void()>> tasks_awaiting_gpu_;
132 std::unique_ptr<SyncSwitchObserver> sync_switch_observer_;
133 std::shared_ptr<CommandQueue> command_queue_ip_;
134 bool is_valid_ =
false;
137 id<MTLDevice> device,
138 id<MTLCommandQueue> command_queue,
139 NSArray<id<MTLLibrary>>* shader_libraries,
140 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
142 std::shared_ptr<CommandBuffer> CreateCommandBufferInQueue(
143 id<MTLCommandQueue> queue)
const;
145 void FlushTasksAwaitingGPU();
154 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_CONTEXT_MTL_H_