| Flutter macOS Embedder |

FlutterTextureRegistrar.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/FlutterTextureRegistrar.h"
6
7 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
8
9 @implementation FlutterTextureRegistrar {
10 __weak id<FlutterTextureRegistrarDelegate> _delegate;
11
12 __weak FlutterEngine* _flutterEngine;
13
14 // A mapping of textureID to internal FlutterExternalTexture wrapper.
15 NSMutableDictionary<NSNumber*, FlutterExternalTexture*>* _textures;
16 }
17
18 - (instancetype)initWithDelegate:(id<FlutterTextureRegistrarDelegate>)delegate
19 engine:(FlutterEngine*)engine {
20 if (self = [super init]) {
21 _delegate = delegate;
22 _flutterEngine = engine;
23 _textures = [[NSMutableDictionary alloc] init];
24 }
25 return self;
26 }
27
28 - (int64_t)registerTexture:(id<FlutterTexture>)texture {
29 FlutterExternalTexture* externalTexture = [_delegate onRegisterTexture:texture];
30 int64_t textureID = [externalTexture textureID];
31 BOOL success = [_flutterEngine registerTextureWithID:textureID];
32 if (success) {
33 _textures[@(textureID)] = externalTexture;
34 return textureID;
35 } else {
36 NSLog(@"Unable to register the texture with id: %lld.", textureID);
37 return 0;
38 }
39 }
40
41 - (void)textureFrameAvailable:(int64_t)textureID {
42 BOOL success = [_flutterEngine markTextureFrameAvailable:textureID];
43 if (!success) {
44 NSLog(@"Unable to mark texture with id %lld as available.", textureID);
45 }
46 }
47
48 - (void)unregisterTexture:(int64_t)textureID {
49 bool success = [_flutterEngine unregisterTextureWithID:textureID];
50 if (success) {
51 [_textures removeObjectForKey:@(textureID)];
52 } else {
53 NSLog(@"Unable to unregister texture with id: %lld.", textureID);
54 }
55 }
56
57 - (FlutterExternalTexture*)getTextureWithID:(int64_t)textureID {
58 return _textures[@(textureID)];
59 }
60
61 @end
FlutterEngine_Internal.h
FlutterTextureRegistrar.h
_textures
NSMutableDictionary< NSNumber *, FlutterExternalTexture * > * _textures
Definition: FlutterTextureRegistrar.mm:15
_flutterEngine
__weak FlutterEngine * _flutterEngine
Definition: FlutterTextureRegistrar.mm:9
FlutterEngine
Definition: FlutterEngine.h:32
FlutterExternalTexture
Definition: FlutterExternalTexture.h:19
-[FlutterExternalTexture textureID]
int64_t textureID()
Definition: FlutterExternalTexture.mm:30
FlutterTextureRegistrar
Definition: FlutterTextureRegistrar.h:28
FlutterTexture-p
Definition: FlutterTexture.h:21
FlutterTextureRegistrarDelegate-p
Definition: FlutterTextureRegistrar.h:16