Flutter Engine
The Flutter Engine
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@implementation FlutterEngineGroupOptions
9
10- (void)dealloc {
11 [_entrypoint release];
12 [_libraryURI release];
13 [_initialRoute release];
14 [_entrypointArgs release];
15 [super dealloc];
16}
17
18@end
19
20@interface FlutterEngineGroup ()
21@property(nonatomic, copy) NSString* name;
22@property(nonatomic, retain) NSMutableArray<NSValue*>* engines;
23@property(nonatomic, retain) FlutterDartProject* project;
24@end
25
26@implementation FlutterEngineGroup {
27 int _enginesCreatedCount;
28}
29
30- (instancetype)initWithName:(NSString*)name project:(nullable FlutterDartProject*)project {
31 self = [super init];
32 if (self) {
33 _name = [name copy];
34 _engines = [[NSMutableArray<NSValue*> alloc] init];
35 _project = [project retain];
36 }
37 return self;
38}
39
40- (void)dealloc {
41 [_name release];
42 [_engines release];
43 [_project release];
44 [super dealloc];
45}
46
47- (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
48 libraryURI:(nullable NSString*)libraryURI {
49 return [self makeEngineWithEntrypoint:entrypoint libraryURI:libraryURI initialRoute:nil];
50}
51
52- (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
53 libraryURI:(nullable NSString*)libraryURI
54 initialRoute:(nullable NSString*)initialRoute {
55 FlutterEngineGroupOptions* options = [[[FlutterEngineGroupOptions alloc] init] autorelease];
56 options.entrypoint = entrypoint;
57 options.libraryURI = libraryURI;
58 options.initialRoute = initialRoute;
59 return [self makeEngineWithOptions:options];
60}
61
62- (FlutterEngine*)makeEngineWithOptions:(nullable FlutterEngineGroupOptions*)options {
63 NSString* entrypoint = options.entrypoint;
64 NSString* libraryURI = options.libraryURI;
65 NSString* initialRoute = options.initialRoute;
66 NSArray<NSString*>* entrypointArgs = options.entrypointArgs;
67
69 if (self.engines.count <= 0) {
70 engine = [self makeEngine];
71 [engine runWithEntrypoint:entrypoint
72 libraryURI:libraryURI
73 initialRoute:initialRoute
74 entrypointArgs:entrypointArgs];
75 } else {
76 FlutterEngine* spawner = (FlutterEngine*)[self.engines[0] pointerValue];
77 engine = [spawner spawnWithEntrypoint:entrypoint
78 libraryURI:libraryURI
79 initialRoute:initialRoute
80 entrypointArgs:entrypointArgs];
81 }
82 [_engines addObject:[NSValue valueWithPointer:engine]];
83
84 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
85 [center addObserver:self
86 selector:@selector(onEngineWillBeDealloced:)
87 name:kFlutterEngineWillDealloc
88 object:engine];
89
90 return engine;
91}
92
93- (FlutterEngine*)makeEngine {
94 NSString* engineName = [NSString stringWithFormat:@"%@.%d", self.name, ++_enginesCreatedCount];
95 FlutterEngine* result = [[FlutterEngine alloc] initWithName:engineName project:self.project];
96 return [result autorelease];
97}
98
99- (void)onEngineWillBeDealloced:(NSNotification*)notification {
100 [_engines removeObject:[NSValue valueWithPointer:notification.object]];
101}
102
103@end
const char * options
NSString * _name
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
Definition: SkSwizzler.cpp:31
static SkScalar center(float pos0, float pos1)
FlutterEngine engine
Definition: main.cc:68
GAsyncResult * result
NSMutableArray< NSValue * > * engines
FlutterDartProject * project
BOOL runWithEntrypoint:libraryURI:initialRoute:entrypointArgs:(nullable NSString *entrypoint,[libraryURI] nullable NSString *libraryURI,[initialRoute] nullable NSString *initialRoute,[entrypointArgs] nullable NSArray< NSString * > *entrypointArgs)
FlutterDartProject * _project
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32