Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
FlutterRenderer.mm
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#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h"
6
7#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
8#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h"
9#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"
10#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.h"
11#include "flutter/shell/platform/embedder/embedder.h"
12
13#pragma mark - Static callbacks that require the engine.
14
16 const FlutterFrameInfo* frameInfo) {
17 NSCAssert(NO, @"The renderer config should not be used to get the next drawable.");
18 return FlutterMetalTexture{};
19}
20
22 NSCAssert(NO, @"The renderer config should not be used to present drawable.");
23 return false;
24}
25
27 int64_t textureIdentifier,
28 size_t width,
29 size_t height,
30 FlutterMetalExternalTexture* metalTexture) {
31 return [engine.renderer populateTextureWithIdentifier:textureIdentifier
32 metalTexture:metalTexture];
33}
34
35#pragma mark - FlutterRenderer implementation
36
37@implementation FlutterRenderer {
38 FlutterDarwinContextMetalSkia* _darwinMetalContext;
39}
40
41- (instancetype)initWithFlutterEngine:(nonnull FlutterEngine*)flutterEngine {
42 self = [super initWithDelegate:self engine:flutterEngine];
43 if (self) {
44 _device = MTLCreateSystemDefaultDevice();
45 if (!_device) {
46 NSLog(@"Could not acquire Metal device.");
47 return nil;
48 }
49
50 _commandQueue = [_device newCommandQueue];
51 if (!_commandQueue) {
52 NSLog(@"Could not create Metal command queue.");
53 return nil;
54 }
55
56 _darwinMetalContext = [[FlutterDarwinContextMetalSkia alloc] initWithMTLDevice:_device
57 commandQueue:_commandQueue];
58 }
59 return self;
60}
61
62- (FlutterRendererConfig)createRendererConfig {
63 FlutterRendererConfig config = {
65 .metal = {
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 =
75 }};
76 return config;
77}
78
79#pragma mark - Embedder callback implementations.
80
81- (BOOL)populateTextureWithIdentifier:(int64_t)textureID
82 metalTexture:(FlutterMetalExternalTexture*)textureOut {
83 FlutterExternalTexture* texture = [self getTextureWithID:textureID];
84 return [texture populateTexture:textureOut];
85}
86
87#pragma mark - FlutterTextureRegistrar methods.
88
89- (FlutterExternalTexture*)onRegisterTexture:(id<FlutterTexture>)texture {
90 return [[FlutterExternalTexture alloc] initWithFlutterTexture:texture
91 darwinMetalContext:_darwinMetalContext];
92}
93
94@end
static bool OnPresentDrawable(FlutterEngine *engine, const FlutterMetalTexture *texture)
static bool OnAcquireExternalTexture(FlutterEngine *engine, int64_t textureIdentifier, size_t width, size_t height, FlutterMetalExternalTexture *metalTexture)
static FlutterMetalTexture OnGetNextDrawable(FlutterEngine *engine, const FlutterFrameInfo *frameInfo)
bool(* FlutterMetalPresentCallback)(void *, const FlutterMetalTexture *)
Definition embedder.h:677
const void * FlutterMetalDeviceHandle
Alias for id<MTLDevice>.
Definition embedder.h:594
@ kMetal
Definition embedder.h:85
bool(* FlutterMetalTextureFrameCallback)(void *, int64_t, size_t, size_t, FlutterMetalExternalTexture *)
Definition embedder.h:640
const void * FlutterMetalCommandQueueHandle
Alias for id<MTLCommandQueue>.
Definition embedder.h:597
FlutterMetalTexture(* FlutterMetalTextureCallback)(void *, const FlutterFrameInfo *)
Callback for when a metal texture is requested.
Definition embedder.h:670
VkDevice device
Definition main.cc:53
FlutterEngine engine
Definition main.cc:68
FlutterRenderer * renderer
BOOL populateTexture:(nonnull FlutterMetalExternalTexture *metalTexture)
FlTexture * texture
int32_t height
int32_t width
FlutterRendererType type
Definition embedder.h:825
int BOOL