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;
41 - (instancetype)initWithFlutterEngine:(nonnull
FlutterEngine*)flutterEngine {
42 self = [
super initWithDelegate:self engine:flutterEngine];
44 _device = MTLCreateSystemDefaultDevice();
46 NSLog(
@"Could not acquire Metal device.");
50 _commandQueue = [_device newCommandQueue];
52 NSLog(
@"Could not create Metal command queue.");
56 _darwinMetalContext = [[FlutterDarwinContextMetalSkia alloc] initWithMTLDevice:_device
57 commandQueue:_commandQueue];
62 - (FlutterRendererConfig)createRendererConfig {
63 FlutterRendererConfig config = {
64 .type = FlutterRendererType::kMetal,
66 .struct_size =
sizeof(FlutterMetalRendererConfig),
67 .device = (__bridge FlutterMetalDeviceHandle)_device,
68 .present_command_queue = (__bridge FlutterMetalCommandQueueHandle)_commandQueue,
69 .get_next_drawable_callback =
71 .present_drawable_callback =
73 .external_texture_frame_callback =
79 #pragma mark - Embedder callback implementations.
81 - (BOOL)populateTextureWithIdentifier:(int64_t)textureID
82 metalTexture:(FlutterMetalExternalTexture*)textureOut {
87 #pragma mark - FlutterTextureRegistrar methods.
91 darwinMetalContext:_darwinMetalContext];