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"
26 #if TARGET_OS_SIMULATOR
27 #define IMPELLER_CA_METAL_LAYER_AVAILABLE API_AVAILABLE(macos(10.11), ios(13.0))
28 #else // TARGET_OS_SIMULATOR
29 #define IMPELLER_CA_METAL_LAYER_AVAILABLE API_AVAILABLE(macos(10.11), ios(8.0))
30 #endif // TARGET_OS_SIMULATOR
36 public std::enable_shared_from_this<ContextMTL> {
38 static std::shared_ptr<ContextMTL>
Create(
39 const std::vector<std::string>& shader_library_paths,
40 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
42 static std::shared_ptr<ContextMTL>
Create(
43 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
44 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
45 const std::string& label);
47 static std::shared_ptr<ContextMTL>
Create(
49 id<MTLCommandQueue> command_queue,
50 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
51 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
52 const std::string& label);
84 const std::shared_ptr<const Capabilities>&
GetCapabilities()
const override;
86 void SetCapabilities(
const std::shared_ptr<const Capabilities>& capabilities);
100 #ifdef IMPELLER_DEBUG
101 std::shared_ptr<GPUTracerMTL> GetGPUTracer()
const;
102 #endif // IMPELLER_DEBUG
108 class SyncSwitchObserver :
public fml::SyncSwitch::Observer {
110 explicit SyncSwitchObserver(
ContextMTL& parent);
111 virtual ~SyncSwitchObserver() =
default;
112 void OnSyncSwitchUpdate(
bool new_value)
override;
118 id<MTLDevice> device_ =
nullptr;
119 id<MTLCommandQueue> command_queue_ =
nullptr;
120 std::shared_ptr<ShaderLibraryMTL> shader_library_;
121 std::shared_ptr<PipelineLibraryMTL> pipeline_library_;
122 std::shared_ptr<SamplerLibrary> sampler_library_;
123 std::shared_ptr<AllocatorMTL> resource_allocator_;
124 std::shared_ptr<const Capabilities> device_capabilities_;
125 std::shared_ptr<fml::ConcurrentMessageLoop> raster_message_loop_;
126 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch_;
127 #ifdef IMPELLER_DEBUG
128 std::shared_ptr<GPUTracerMTL> gpu_tracer_;
129 #endif // IMPELLER_DEBUG
130 std::deque<std::function<void()>> tasks_awaiting_gpu_;
131 std::unique_ptr<SyncSwitchObserver> sync_switch_observer_;
132 bool is_valid_ =
false;
135 id<MTLDevice> device,
136 id<MTLCommandQueue> command_queue,
137 NSArray<id<MTLLibrary>>* shader_libraries,
138 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
140 std::shared_ptr<CommandBuffer> CreateCommandBufferInQueue(
141 id<MTLCommandQueue> queue)
const;
143 void FlushTasksAwaitingGPU();
152 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_CONTEXT_MTL_H_