| Flutter iOS Embedder |

FlutterEngineGroup.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/ios/framework/Headers/FlutterEngineGroup.h"
6 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
7
8 FLUTTER_ASSERT_ARC
9
10 @implementation FlutterEngineGroupOptions
11 @end
12
13 @interface FlutterEngineGroup ()
14 @property(nonatomic, copy) NSString* name;
15 @property(nonatomic, strong) NSPointerArray* engines;
16 @property(nonatomic, copy) FlutterDartProject* project;
17 @property(nonatomic, assign) NSUInteger enginesCreatedCount;
18 @end
19
20 @implementation FlutterEngineGroup
21
22 - (instancetype)initWithName:(NSString*)name project:(nullable FlutterDartProject*)project {
23 self = [super init];
24 if (self) {
25 _name = [name copy];
26 _engines = [NSPointerArray weakObjectsPointerArray];
27 _project = project;
28 }
29 return self;
30 }
31
32 - (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
33 libraryURI:(nullable NSString*)libraryURI {
34 return [self makeEngineWithEntrypoint:entrypoint libraryURI:libraryURI initialRoute:nil];
35 }
36
37 - (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
38 libraryURI:(nullable NSString*)libraryURI
39 initialRoute:(nullable NSString*)initialRoute {
40 FlutterEngineGroupOptions* options = [[FlutterEngineGroupOptions alloc] init];
41 options.entrypoint = entrypoint;
42 options.libraryURI = libraryURI;
43 options.initialRoute = initialRoute;
44 return [self makeEngineWithOptions:options];
45 }
46
47 - (FlutterEngine*)makeEngineWithOptions:(nullable FlutterEngineGroupOptions*)options {
48 NSString* entrypoint = options.entrypoint;
49 NSString* libraryURI = options.libraryURI;
50 NSString* initialRoute = options.initialRoute;
51 NSArray<NSString*>* entrypointArgs = options.entrypointArgs;
52
53 FlutterEngine* engine;
54 // NSPointerArray is clever and assumes that unless a mutation operation has occurred on it that
55 // has set one of its values to nil, nothing could have changed and it can skip compaction.
56 // That's reasonable behaviour on a regular NSPointerArray but not for a weakObjectPointerArray.
57 // As a workaround, we mutate it first. See: http://www.openradar.me/15396578
58 [self.engines addPointer:nil];
59 [self.engines compact];
60 if (self.engines.count <= 0) {
61 engine = [self makeEngine];
62 [engine runWithEntrypoint:entrypoint
63 libraryURI:libraryURI
64 initialRoute:initialRoute
65 entrypointArgs:entrypointArgs];
66 } else {
67 FlutterEngine* spawner = (__bridge FlutterEngine*)[self.engines pointerAtIndex:0];
68 engine = [spawner spawnWithEntrypoint:entrypoint
69 libraryURI:libraryURI
70 initialRoute:initialRoute
71 entrypointArgs:entrypointArgs];
72 }
73 [self.engines addPointer:(__bridge void*)engine];
74
75 return engine;
76 }
77
78 - (FlutterEngine*)makeEngine {
79 NSString* engineName =
80 [NSString stringWithFormat:@"%@.%lu", self.name, ++self.enginesCreatedCount];
81 return [[FlutterEngine alloc] initWithName:engineName project:self.project];
82 }
83
84 @end
_name
NSString * _name
Definition: FlutterChannels.mm:68
FlutterEngine_Internal.h
FlutterEngineGroup.h
engine
id engine
Definition: FlutterTextInputPluginTest.mm:137
FlutterEngineGroup()::name
NSString * name
Definition: FlutterEngineGroup.mm:14
FlutterDartProject
Definition: FlutterDartProject.mm:268
FlutterEngineGroup
Definition: FlutterEngineGroup.h:57
FlutterEngineGroupOptions
Definition: FlutterEngineGroup.h:17
FlutterEngineGroupOptions::entrypointArgs
NSArray< NSString * > * entrypointArgs
Definition: FlutterEngineGroup.h:41
FlutterEngineGroupOptions::initialRoute
NSString * initialRoute
Definition: FlutterEngineGroup.h:36
FlutterEngineGroupOptions::libraryURI
NSString * libraryURI
Definition: FlutterEngineGroup.h:30
FlutterEngineGroupOptions::entrypoint
NSString * entrypoint
Definition: FlutterEngineGroup.h:24
FlutterEngine
Definition: FlutterEngine.h:61
-[FlutterEngine spawnWithEntrypoint:libraryURI:initialRoute:entrypointArgs:]
FlutterEngine * spawnWithEntrypoint:libraryURI:initialRoute:entrypointArgs:(/*nullable */NSString *entrypoint,[libraryURI]/*nullable */NSString *libraryURI,[initialRoute]/*nullable */NSString *initialRoute,[entrypointArgs]/*nullable */NSArray< NSString * > *entrypointArgs)
-[FlutterEngine runWithEntrypoint:libraryURI:initialRoute:entrypointArgs:]
BOOL runWithEntrypoint:libraryURI:initialRoute:entrypointArgs:(nullable NSString *entrypoint,[libraryURI] nullable NSString *libraryURI,[initialRoute] nullable NSString *initialRoute,[entrypointArgs] nullable NSArray< NSString * > *entrypointArgs)
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13