11 #include "flutter/shell/platform/embedder/embedder.h"
13 #pragma mark - Static callbacks that require the engine.
16 NSCAssert(NO,
@"The renderer config should not be used to get the next drawable.");
17 return FlutterMetalTexture{};
21 NSCAssert(NO,
@"The renderer config should not be used to present drawable.");
26 int64_t textureIdentifier,
29 FlutterMetalExternalTexture* metalTexture) {
31 return [engine.renderer populateTextureWithIdentifier:textureIdentifier
32 metalTexture:metalTexture];
35 #pragma mark - FlutterRenderer implementation
38 FlutterDarwinContextMetalSkia* _darwinMetalContext;
46 id<MTLDevice> SelectMetalDevice() {
47 NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices();
48 for (id<MTLDevice> device in devices) {
49 if (device.hasUnifiedMemory) {
53 return MTLCreateSystemDefaultDevice();
57 - (instancetype)initWithFlutterEngine:(nonnull
FlutterEngine*)flutterEngine {
58 self = [
super initWithDelegate:self engine:flutterEngine];
60 _device = SelectMetalDevice();
62 NSLog(
@"Could not acquire Metal device.");
66 _commandQueue = [_device newCommandQueue];
68 NSLog(
@"Could not create Metal command queue.");
72 _darwinMetalContext = [[FlutterDarwinContextMetalSkia alloc] initWithMTLDevice:_device
73 commandQueue:_commandQueue];
78 - (FlutterRendererConfig)createRendererConfig {
79 FlutterRendererConfig config = {
80 .type = FlutterRendererType::kMetal,
82 .struct_size =
sizeof(FlutterMetalRendererConfig),
83 .device = (__bridge FlutterMetalDeviceHandle)_device,
84 .present_command_queue = (__bridge FlutterMetalCommandQueueHandle)_commandQueue,
85 .get_next_drawable_callback =
87 .present_drawable_callback =
89 .external_texture_frame_callback =
95 #pragma mark - Embedder callback implementations.
97 - (BOOL)populateTextureWithIdentifier:(int64_t)textureID
98 metalTexture:(FlutterMetalExternalTexture*)textureOut {
103 #pragma mark - FlutterTextureRegistrar methods.
107 darwinMetalContext:_darwinMetalContext];