| Flutter iOS Embedder |

FlutterEngine.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 #define FML_USED_ON_EMBEDDER
6
7 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
8
9 #include <memory>
10
11 #include "flutter/common/constants.h"
12 #include "flutter/fml/message_loop.h"
13 #include "flutter/fml/platform/darwin/platform_version.h"
14 #include "flutter/fml/platform/darwin/weak_nsobject.h"
15 #include "flutter/fml/trace_event.h"
16 #include "flutter/runtime/ptrace_check.h"
17 #include "flutter/shell/common/engine.h"
18 #include "flutter/shell/common/platform_view.h"
19 #include "flutter/shell/common/shell.h"
20 #include "flutter/shell/common/switches.h"
21 #include "flutter/shell/common/thread_host.h"
22 #include "flutter/shell/common/variable_refresh_rate_display.h"
23 #import "flutter/shell/platform/darwin/common/command_line.h"
24 #import "flutter/shell/platform/darwin/common/framework/Source/FlutterBinaryMessengerRelay.h"
25 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h"
26 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartVMServicePublisher.h"
27 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterIndirectScribbleDelegate.h"
28 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h"
29 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterSpellCheckPlugin.h"
30 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h"
31 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.h"
32 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerDelegate.h"
33 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPlugin.h"
34 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
35 #import "flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h"
36 #import "flutter/shell/platform/darwin/ios/framework/Source/connection_collection.h"
37 #import "flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h"
38 #import "flutter/shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.h"
39 #import "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h"
40 #import "flutter/shell/platform/darwin/ios/platform_view_ios.h"
41 #import "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
42 #include "flutter/shell/profiling/sampling_profiler.h"
43
44 /// Inheriting ThreadConfigurer and use iOS platform thread API to configure the thread priorities
45 /// Using iOS platform thread API to configure thread priority
46 static void IOSPlatformThreadConfigSetter(const fml::Thread::ThreadConfig& config) {
47 // set thread name
48 fml::Thread::SetCurrentThreadName(config);
49
50 // set thread priority
51 switch (config.priority) {
52 case fml::Thread::ThreadPriority::kBackground: {
53 pthread_set_qos_class_self_np(QOS_CLASS_BACKGROUND, 0);
54 [[NSThread currentThread] setThreadPriority:0];
55 break;
56 }
57 case fml::Thread::ThreadPriority::kNormal: {
58 pthread_set_qos_class_self_np(QOS_CLASS_DEFAULT, 0);
59 [[NSThread currentThread] setThreadPriority:0.5];
60 break;
61 }
62 case fml::Thread::ThreadPriority::kRaster:
63 case fml::Thread::ThreadPriority::kDisplay: {
64 pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, 0);
65 [[NSThread currentThread] setThreadPriority:1.0];
66 sched_param param;
67 int policy;
68 pthread_t thread = pthread_self();
69 if (!pthread_getschedparam(thread, &policy, &param)) {
70 param.sched_priority = 50;
71 pthread_setschedparam(thread, policy, &param);
72 }
73 break;
74 }
75 }
76 }
77
78 #pragma mark - Public exported constants
79
80 NSString* const FlutterDefaultDartEntrypoint = nil;
81 NSString* const FlutterDefaultInitialRoute = nil;
82
83 #pragma mark - Internal constants
84
85 NSString* const kFlutterEngineWillDealloc = @"FlutterEngineWillDealloc";
86 NSString* const kFlutterKeyDataChannel = @"flutter/keydata";
87 static constexpr int kNumProfilerSamplesPerSec = 5;
88
89 @interface FlutterEngineRegistrar : NSObject <FlutterPluginRegistrar>
90 @property(nonatomic, assign) FlutterEngine* flutterEngine;
91 - (instancetype)initWithPlugin:(NSString*)pluginKey flutterEngine:(FlutterEngine*)flutterEngine;
92 @end
93
94 @interface FlutterEngine () <FlutterIndirectScribbleDelegate,
95 FlutterUndoManagerDelegate,
96 FlutterTextInputDelegate,
97 FlutterBinaryMessenger,
98 FlutterTextureRegistry>
99 // Maintains a dictionary of plugin names that have registered with the engine. Used by
100 // FlutterEngineRegistrar to implement a FlutterPluginRegistrar.
101 @property(nonatomic, readonly) NSMutableDictionary* pluginPublications;
102 @property(nonatomic, readonly) NSMutableDictionary<NSString*, FlutterEngineRegistrar*>* registrars;
103
104 @property(nonatomic, readwrite, copy) NSString* isolateId;
105 @property(nonatomic, copy) NSString* initialRoute;
106 @property(nonatomic, retain) id<NSObject> flutterViewControllerWillDeallocObserver;
107
108 #pragma mark - Embedder API properties
109
110 @property(nonatomic, assign) BOOL enableEmbedderAPI;
111 // Function pointers for interacting with the embedder.h API.
112 @property(nonatomic) FlutterEngineProcTable& embedderAPI;
113 @end
114
115 @implementation FlutterEngine {
116 fml::scoped_nsobject<FlutterDartProject> _dartProject;
117 std::shared_ptr<flutter::ThreadHost> _threadHost;
118 std::unique_ptr<flutter::Shell> _shell;
119 NSString* _labelPrefix;
120 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>> _weakFactory;
121
122 fml::WeakNSObject<FlutterViewController> _viewController;
123 fml::scoped_nsobject<FlutterDartVMServicePublisher> _publisher;
124
125 std::shared_ptr<flutter::FlutterPlatformViewsController> _platformViewsController;
126 flutter::IOSRenderingAPI _renderingApi;
127 std::shared_ptr<flutter::ProfilerMetricsIOS> _profiler_metrics;
128 std::shared_ptr<flutter::SamplingProfiler> _profiler;
129
130 // Channels
131 fml::scoped_nsobject<FlutterPlatformPlugin> _platformPlugin;
132 fml::scoped_nsobject<FlutterTextInputPlugin> _textInputPlugin;
133 fml::scoped_nsobject<FlutterUndoManagerPlugin> _undoManagerPlugin;
134 fml::scoped_nsobject<FlutterSpellCheckPlugin> _spellCheckPlugin;
135 fml::scoped_nsobject<FlutterRestorationPlugin> _restorationPlugin;
136 fml::scoped_nsobject<FlutterMethodChannel> _localizationChannel;
137 fml::scoped_nsobject<FlutterMethodChannel> _navigationChannel;
138 fml::scoped_nsobject<FlutterMethodChannel> _restorationChannel;
139 fml::scoped_nsobject<FlutterMethodChannel> _platformChannel;
140 fml::scoped_nsobject<FlutterMethodChannel> _platformViewsChannel;
141 fml::scoped_nsobject<FlutterMethodChannel> _textInputChannel;
142 fml::scoped_nsobject<FlutterMethodChannel> _undoManagerChannel;
143 fml::scoped_nsobject<FlutterMethodChannel> _scribbleChannel;
144 fml::scoped_nsobject<FlutterMethodChannel> _spellCheckChannel;
145 fml::scoped_nsobject<FlutterBasicMessageChannel> _lifecycleChannel;
146 fml::scoped_nsobject<FlutterBasicMessageChannel> _systemChannel;
147 fml::scoped_nsobject<FlutterBasicMessageChannel> _settingsChannel;
148 fml::scoped_nsobject<FlutterBasicMessageChannel> _keyEventChannel;
149 fml::scoped_nsobject<FlutterMethodChannel> _screenshotChannel;
150
151 int64_t _nextTextureId;
152
153 BOOL _allowHeadlessExecution;
154 BOOL _restorationEnabled;
155 FlutterBinaryMessengerRelay* _binaryMessenger;
156 FlutterTextureRegistryRelay* _textureRegistry;
157 std::unique_ptr<flutter::ConnectionCollection> _connections;
158 }
159
160 - (instancetype)init {
161 return [self initWithName:@"FlutterEngine" project:nil allowHeadlessExecution:YES];
162 }
163
164 - (instancetype)initWithName:(NSString*)labelPrefix {
165 return [self initWithName:labelPrefix project:nil allowHeadlessExecution:YES];
166 }
167
168 - (instancetype)initWithName:(NSString*)labelPrefix project:(FlutterDartProject*)project {
169 return [self initWithName:labelPrefix project:project allowHeadlessExecution:YES];
170 }
171
172 - (instancetype)initWithName:(NSString*)labelPrefix
173 project:(FlutterDartProject*)project
174 allowHeadlessExecution:(BOOL)allowHeadlessExecution {
175 return [self initWithName:labelPrefix
176 project:project
177 allowHeadlessExecution:allowHeadlessExecution
178 restorationEnabled:NO];
179 }
180
181 - (instancetype)initWithName:(NSString*)labelPrefix
182 project:(FlutterDartProject*)project
183 allowHeadlessExecution:(BOOL)allowHeadlessExecution
184 restorationEnabled:(BOOL)restorationEnabled {
185 self = [super init];
186 NSAssert(self, @"Super init cannot be nil");
187 NSAssert(labelPrefix, @"labelPrefix is required");
188
189 _restorationEnabled = restorationEnabled;
190 _allowHeadlessExecution = allowHeadlessExecution;
191 _labelPrefix = [labelPrefix copy];
192
193 _weakFactory = std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(self);
194
195 if (project == nil) {
196 _dartProject.reset([[FlutterDartProject alloc] init]);
197 } else {
198 _dartProject.reset([project retain]);
199 }
200
201 _enableEmbedderAPI = _dartProject.get().settings.enable_embedder_api;
202 if (_enableEmbedderAPI) {
203 NSLog(@"============== iOS: enable_embedder_api is on ==============");
204 _embedderAPI.struct_size = sizeof(FlutterEngineProcTable);
205 FlutterEngineGetProcAddresses(&_embedderAPI);
206 }
207
208 if (!EnableTracingIfNecessary([_dartProject.get() settings])) {
209 NSLog(
210 @"Cannot create a FlutterEngine instance in debug mode without Flutter tooling or "
211 @"Xcode.\n\nTo launch in debug mode in iOS 14+, run flutter run from Flutter tools, run "
212 @"from an IDE with a Flutter IDE plugin or run the iOS project from Xcode.\nAlternatively "
213 @"profile and release mode apps can be launched from the home screen.");
214 [self release];
215 return nil;
216 }
217
218 _pluginPublications = [[NSMutableDictionary alloc] init];
219 _registrars = [[NSMutableDictionary alloc] init];
220 [self recreatePlatformViewController];
221
222 _binaryMessenger = [[FlutterBinaryMessengerRelay alloc] initWithParent:self];
223 _textureRegistry = [[FlutterTextureRegistryRelay alloc] initWithParent:self];
224 _connections.reset(new flutter::ConnectionCollection());
225
226 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
227 [center addObserver:self
228 selector:@selector(onMemoryWarning:)
229 name:UIApplicationDidReceiveMemoryWarningNotification
230 object:nil];
231
232 #if APPLICATION_EXTENSION_API_ONLY
233 if (@available(iOS 13.0, *)) {
234 [self setUpSceneLifecycleNotifications:center];
235 } else {
236 [self setUpApplicationLifecycleNotifications:center];
237 }
238 #else
239 [self setUpApplicationLifecycleNotifications:center];
240 #endif
241
242 [center addObserver:self
243 selector:@selector(onLocaleUpdated:)
244 name:NSCurrentLocaleDidChangeNotification
245 object:nil];
246
247 return self;
248 }
249
250 - (void)setUpSceneLifecycleNotifications:(NSNotificationCenter*)center API_AVAILABLE(ios(13.0)) {
251 [center addObserver:self
252 selector:@selector(sceneWillEnterForeground:)
253 name:UISceneWillEnterForegroundNotification
254 object:nil];
255 [center addObserver:self
256 selector:@selector(sceneDidEnterBackground:)
257 name:UISceneDidEnterBackgroundNotification
258 object:nil];
259 }
260
261 - (void)setUpApplicationLifecycleNotifications:(NSNotificationCenter*)center {
262 [center addObserver:self
263 selector:@selector(applicationWillEnterForeground:)
264 name:UIApplicationWillEnterForegroundNotification
265 object:nil];
266 [center addObserver:self
267 selector:@selector(applicationDidEnterBackground:)
268 name:UIApplicationDidEnterBackgroundNotification
269 object:nil];
270 }
271
272 - (void)recreatePlatformViewController {
273 _renderingApi = flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering);
274 _platformViewsController.reset(new flutter::FlutterPlatformViewsController());
275 }
276
277 - (flutter::IOSRenderingAPI)platformViewsRenderingAPI {
278 return _renderingApi;
279 }
280
281 - (void)dealloc {
282 /// Notify plugins of dealloc. This should happen first in dealloc since the
283 /// plugins may be talking to things like the binaryMessenger.
284 [_pluginPublications enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL* stop) {
285 if ([object respondsToSelector:@selector(detachFromEngineForRegistrar:)]) {
286 NSObject<FlutterPluginRegistrar>* registrar = self.registrars[key];
287 [object detachFromEngineForRegistrar:registrar];
288 }
289 }];
290
291 [[NSNotificationCenter defaultCenter] postNotificationName:kFlutterEngineWillDealloc
292 object:self
293 userInfo:nil];
294
295 // It will be destroyed and invalidate its weak pointers
296 // before any other members are destroyed.
297 _weakFactory.reset();
298
299 /// nil out weak references.
300 [_registrars
301 enumerateKeysAndObjectsUsingBlock:^(id key, FlutterEngineRegistrar* registrar, BOOL* stop) {
302 registrar.flutterEngine = nil;
303 }];
304
305 [_labelPrefix release];
306 [_initialRoute release];
307 [_pluginPublications release];
308 [_registrars release];
309 _binaryMessenger.parent = nil;
310 _textureRegistry.parent = nil;
311 [_binaryMessenger release];
312 [_textureRegistry release];
313 _textureRegistry = nil;
314 [_isolateId release];
315
316 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
317 if (_flutterViewControllerWillDeallocObserver) {
318 [center removeObserver:_flutterViewControllerWillDeallocObserver];
319 [_flutterViewControllerWillDeallocObserver release];
320 }
321 [center removeObserver:self];
322
323 [super dealloc];
324 }
325
326 - (flutter::Shell&)shell {
327 FML_DCHECK(_shell);
328 return *_shell;
329 }
330
331 - (fml::WeakNSObject<FlutterEngine>)getWeakNSObject {
332 return _weakFactory->GetWeakNSObject();
333 }
334
335 - (void)updateViewportMetrics:(flutter::ViewportMetrics)viewportMetrics {
336 if (!self.platformView) {
337 return;
338 }
339 self.platformView->SetViewportMetrics(flutter::kFlutterImplicitViewId, viewportMetrics);
340 }
341
342 - (void)dispatchPointerDataPacket:(std::unique_ptr<flutter::PointerDataPacket>)packet {
343 if (!self.platformView) {
344 return;
345 }
346 self.platformView->DispatchPointerDataPacket(std::move(packet));
347 }
348
349 - (fml::WeakPtr<flutter::PlatformView>)platformView {
350 FML_DCHECK(_shell);
351 return _shell->GetPlatformView();
352 }
353
354 - (flutter::PlatformViewIOS*)iosPlatformView {
355 FML_DCHECK(_shell);
356 return static_cast<flutter::PlatformViewIOS*>(_shell->GetPlatformView().get());
357 }
358
359 - (fml::RefPtr<fml::TaskRunner>)platformTaskRunner {
360 FML_DCHECK(_shell);
361 return _shell->GetTaskRunners().GetPlatformTaskRunner();
362 }
363
364 - (fml::RefPtr<fml::TaskRunner>)uiTaskRunner {
365 FML_DCHECK(_shell);
366 return _shell->GetTaskRunners().GetUITaskRunner();
367 }
368
369 - (fml::RefPtr<fml::TaskRunner>)rasterTaskRunner {
370 FML_DCHECK(_shell);
371 return _shell->GetTaskRunners().GetRasterTaskRunner();
372 }
373
374 - (void)sendKeyEvent:(const FlutterKeyEvent&)event
375 callback:(FlutterKeyEventCallback)callback
376 userData:(void*)userData API_AVAILABLE(ios(13.4)) {
377 if (@available(iOS 13.4, *)) {
378 } else {
379 return;
380 }
381 if (!self.platformView) {
382 return;
383 }
384 const char* character = event.character;
385
386 flutter::KeyData key_data;
387 key_data.Clear();
388 key_data.timestamp = (uint64_t)event.timestamp;
389 switch (event.type) {
390 case kFlutterKeyEventTypeUp:
391 key_data.type = flutter::KeyEventType::kUp;
392 break;
393 case kFlutterKeyEventTypeDown:
394 key_data.type = flutter::KeyEventType::kDown;
395 break;
396 case kFlutterKeyEventTypeRepeat:
397 key_data.type = flutter::KeyEventType::kRepeat;
398 break;
399 }
400 key_data.physical = event.physical;
401 key_data.logical = event.logical;
402 key_data.synthesized = event.synthesized;
403
404 auto packet = std::make_unique<flutter::KeyDataPacket>(key_data, character);
405 NSData* message = [NSData dataWithBytes:packet->data().data() length:packet->data().size()];
406
407 auto response = ^(NSData* reply) {
408 if (callback == nullptr) {
409 return;
410 }
411 BOOL handled = FALSE;
412 if (reply.length == 1 && *reinterpret_cast<const uint8_t*>(reply.bytes) == 1) {
413 handled = TRUE;
414 }
415 callback(handled, userData);
416 };
417
418 [self sendOnChannel:kFlutterKeyDataChannel message:message binaryReply:response];
419 }
420
421 - (void)ensureSemanticsEnabled {
422 self.iosPlatformView->SetSemanticsEnabled(true);
423 }
424
425 - (void)setViewController:(FlutterViewController*)viewController {
426 FML_DCHECK(self.iosPlatformView);
427 _viewController = viewController ? [viewController getWeakNSObject]
428 : fml::WeakNSObject<FlutterViewController>();
429 self.iosPlatformView->SetOwnerViewController(_viewController);
430 [self maybeSetupPlatformViewChannels];
431 [self updateDisplays];
432 _textInputPlugin.get().viewController = viewController;
433 _undoManagerPlugin.get().viewController = viewController;
434
435 if (viewController) {
436 __block FlutterEngine* blockSelf = self;
437 self.flutterViewControllerWillDeallocObserver =
438 [[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc
439 object:viewController
440 queue:[NSOperationQueue mainQueue]
441 usingBlock:^(NSNotification* note) {
442 [blockSelf notifyViewControllerDeallocated];
443 }];
444 } else {
445 self.flutterViewControllerWillDeallocObserver = nil;
446 [self notifyLowMemory];
447 }
448 }
449
450 - (void)attachView {
451 self.iosPlatformView->attachView();
452 }
453
454 - (void)setFlutterViewControllerWillDeallocObserver:(id<NSObject>)observer {
455 if (observer != _flutterViewControllerWillDeallocObserver) {
456 if (_flutterViewControllerWillDeallocObserver) {
457 [[NSNotificationCenter defaultCenter]
458 removeObserver:_flutterViewControllerWillDeallocObserver];
459 [_flutterViewControllerWillDeallocObserver release];
460 }
461 _flutterViewControllerWillDeallocObserver = [observer retain];
462 }
463 }
464
465 - (void)notifyViewControllerDeallocated {
466 [[self lifecycleChannel] sendMessage:@"AppLifecycleState.detached"];
467 _textInputPlugin.get().viewController = nil;
468 _undoManagerPlugin.get().viewController = nil;
469 if (!_allowHeadlessExecution) {
470 [self destroyContext];
471 } else if (_shell) {
472 flutter::PlatformViewIOS* platform_view = [self iosPlatformView];
473 if (platform_view) {
474 platform_view->SetOwnerViewController({});
475 }
476 }
477 [_textInputPlugin.get() resetViewResponder];
478 _viewController.reset();
479 }
480
481 - (void)destroyContext {
482 [self resetChannels];
483 self.isolateId = nil;
484 _shell.reset();
485 _profiler.reset();
486 _threadHost.reset();
487 _platformViewsController.reset();
488 }
489
490 - (FlutterViewController*)viewController {
491 if (!_viewController) {
492 return nil;
493 }
494 return _viewController.get();
495 }
496
497 - (FlutterPlatformPlugin*)platformPlugin {
498 return _platformPlugin.get();
499 }
500 - (std::shared_ptr<flutter::FlutterPlatformViewsController>&)platformViewsController {
501 return _platformViewsController;
502 }
503 - (FlutterTextInputPlugin*)textInputPlugin {
504 return _textInputPlugin.get();
505 }
506 - (FlutterUndoManagerPlugin*)undoManagerPlugin {
507 return _undoManagerPlugin.get();
508 }
509 - (FlutterRestorationPlugin*)restorationPlugin {
510 return _restorationPlugin.get();
511 }
512 - (FlutterMethodChannel*)localizationChannel {
513 return _localizationChannel.get();
514 }
515 - (FlutterMethodChannel*)navigationChannel {
516 return _navigationChannel.get();
517 }
518 - (FlutterMethodChannel*)restorationChannel {
519 return _restorationChannel.get();
520 }
521 - (FlutterMethodChannel*)platformChannel {
522 return _platformChannel.get();
523 }
524 - (FlutterMethodChannel*)textInputChannel {
525 return _textInputChannel.get();
526 }
527 - (FlutterMethodChannel*)undoManagerChannel {
528 return _undoManagerChannel.get();
529 }
530 - (FlutterMethodChannel*)scribbleChannel {
531 return _scribbleChannel.get();
532 }
533 - (FlutterMethodChannel*)spellCheckChannel {
534 return _spellCheckChannel.get();
535 }
536 - (FlutterBasicMessageChannel*)lifecycleChannel {
537 return _lifecycleChannel.get();
538 }
539 - (FlutterBasicMessageChannel*)systemChannel {
540 return _systemChannel.get();
541 }
542 - (FlutterBasicMessageChannel*)settingsChannel {
543 return _settingsChannel.get();
544 }
545 - (FlutterBasicMessageChannel*)keyEventChannel {
546 return _keyEventChannel.get();
547 }
548
549 - (NSURL*)observatoryUrl {
550 return [_publisher.get() url];
551 }
552
553 - (NSURL*)vmServiceUrl {
554 return [_publisher.get() url];
555 }
556
557 - (void)resetChannels {
558 _localizationChannel.reset();
559 _navigationChannel.reset();
560 _restorationChannel.reset();
561 _platformChannel.reset();
562 _platformViewsChannel.reset();
563 _textInputChannel.reset();
564 _undoManagerChannel.reset();
565 _scribbleChannel.reset();
566 _lifecycleChannel.reset();
567 _systemChannel.reset();
568 _settingsChannel.reset();
569 _keyEventChannel.reset();
570 _spellCheckChannel.reset();
571 }
572
573 - (void)startProfiler {
574 FML_DCHECK(!_threadHost->name_prefix.empty());
575 _profiler_metrics = std::make_shared<flutter::ProfilerMetricsIOS>();
576 _profiler = std::make_shared<flutter::SamplingProfiler>(
577 _threadHost->name_prefix.c_str(), _threadHost->profiler_thread->GetTaskRunner(),
578 [self]() { return self->_profiler_metrics->GenerateSample(); }, kNumProfilerSamplesPerSec);
579 _profiler->Start();
580 }
581
582 // If you add a channel, be sure to also update `resetChannels`.
583 // Channels get a reference to the engine, and therefore need manual
584 // cleanup for proper collection.
585 - (void)setUpChannels {
586 // This will be invoked once the shell is done setting up and the isolate ID
587 // for the UI isolate is available.
588 fml::WeakNSObject<FlutterEngine> weakSelf = [self getWeakNSObject];
589 [_binaryMessenger setMessageHandlerOnChannel:@"flutter/isolate"
590 binaryMessageHandler:^(NSData* message, FlutterBinaryReply reply) {
591 if (weakSelf) {
592 weakSelf.get().isolateId =
593 [[FlutterStringCodec sharedInstance] decode:message];
594 }
595 }];
596
597 _localizationChannel.reset([[FlutterMethodChannel alloc]
598 initWithName:@"flutter/localization"
599 binaryMessenger:self.binaryMessenger
600 codec:[FlutterJSONMethodCodec sharedInstance]]);
601
602 _navigationChannel.reset([[FlutterMethodChannel alloc]
603 initWithName:@"flutter/navigation"
604 binaryMessenger:self.binaryMessenger
605 codec:[FlutterJSONMethodCodec sharedInstance]]);
606
607 if ([_initialRoute length] > 0) {
608 // Flutter isn't ready to receive this method call yet but the channel buffer will cache this.
609 [_navigationChannel invokeMethod:@"setInitialRoute" arguments:_initialRoute];
610 [_initialRoute release];
611 _initialRoute = nil;
612 }
613
614 _restorationChannel.reset([[FlutterMethodChannel alloc]
615 initWithName:@"flutter/restoration"
616 binaryMessenger:self.binaryMessenger
617 codec:[FlutterStandardMethodCodec sharedInstance]]);
618
619 _platformChannel.reset([[FlutterMethodChannel alloc]
620 initWithName:@"flutter/platform"
621 binaryMessenger:self.binaryMessenger
622 codec:[FlutterJSONMethodCodec sharedInstance]]);
623
624 _platformViewsChannel.reset([[FlutterMethodChannel alloc]
625 initWithName:@"flutter/platform_views"
626 binaryMessenger:self.binaryMessenger
627 codec:[FlutterStandardMethodCodec sharedInstance]]);
628
629 _textInputChannel.reset([[FlutterMethodChannel alloc]
630 initWithName:@"flutter/textinput"
631 binaryMessenger:self.binaryMessenger
632 codec:[FlutterJSONMethodCodec sharedInstance]]);
633
634 _undoManagerChannel.reset([[FlutterMethodChannel alloc]
635 initWithName:@"flutter/undomanager"
636 binaryMessenger:self.binaryMessenger
637 codec:[FlutterJSONMethodCodec sharedInstance]]);
638
639 _scribbleChannel.reset([[FlutterMethodChannel alloc]
640 initWithName:@"flutter/scribble"
641 binaryMessenger:self.binaryMessenger
642 codec:[FlutterJSONMethodCodec sharedInstance]]);
643
644 _spellCheckChannel.reset([[FlutterMethodChannel alloc]
645 initWithName:@"flutter/spellcheck"
646 binaryMessenger:self.binaryMessenger
647 codec:[FlutterStandardMethodCodec sharedInstance]]);
648
649 _lifecycleChannel.reset([[FlutterBasicMessageChannel alloc]
650 initWithName:@"flutter/lifecycle"
651 binaryMessenger:self.binaryMessenger
652 codec:[FlutterStringCodec sharedInstance]]);
653
654 _systemChannel.reset([[FlutterBasicMessageChannel alloc]
655 initWithName:@"flutter/system"
656 binaryMessenger:self.binaryMessenger
657 codec:[FlutterJSONMessageCodec sharedInstance]]);
658
659 _settingsChannel.reset([[FlutterBasicMessageChannel alloc]
660 initWithName:@"flutter/settings"
661 binaryMessenger:self.binaryMessenger
662 codec:[FlutterJSONMessageCodec sharedInstance]]);
663
664 _keyEventChannel.reset([[FlutterBasicMessageChannel alloc]
665 initWithName:@"flutter/keyevent"
666 binaryMessenger:self.binaryMessenger
667 codec:[FlutterJSONMessageCodec sharedInstance]]);
668
669 FlutterTextInputPlugin* textInputPlugin = [[FlutterTextInputPlugin alloc] initWithDelegate:self];
670 _textInputPlugin.reset(textInputPlugin);
671 textInputPlugin.indirectScribbleDelegate = self;
672 [textInputPlugin setUpIndirectScribbleInteraction:self.viewController];
673
674 FlutterUndoManagerPlugin* undoManagerPlugin =
675 [[FlutterUndoManagerPlugin alloc] initWithDelegate:self];
676 _undoManagerPlugin.reset(undoManagerPlugin);
677
678 _platformPlugin.reset([[FlutterPlatformPlugin alloc] initWithEngine:[self getWeakNSObject]]);
679
680 _restorationPlugin.reset([[FlutterRestorationPlugin alloc]
681 initWithChannel:_restorationChannel.get()
682 restorationEnabled:_restorationEnabled]);
683 _spellCheckPlugin.reset([[FlutterSpellCheckPlugin alloc] init]);
684
685 _screenshotChannel.reset([[FlutterMethodChannel alloc]
686 initWithName:@"flutter/screenshot"
687 binaryMessenger:self.binaryMessenger
688 codec:[FlutterStandardMethodCodec sharedInstance]]);
689
690 [_screenshotChannel.get()
691 setMethodCallHandler:^(FlutterMethodCall* _Nonnull call, FlutterResult _Nonnull result) {
692 if (!(weakSelf.get() && weakSelf.get()->_shell && weakSelf.get()->_shell->IsSetup())) {
693 return result([FlutterError
694 errorWithCode:@"invalid_state"
695 message:@"Requesting screenshot while engine is not running."
696 details:nil]);
697 }
698 flutter::Rasterizer::Screenshot screenshot =
699 [weakSelf.get() screenshot:flutter::Rasterizer::ScreenshotType::SurfaceData
700 base64Encode:NO];
701 if (!screenshot.data) {
702 return result([FlutterError errorWithCode:@"failure"
703 message:@"Unable to get screenshot."
704 details:nil]);
705 }
706 // TODO(gaaclarke): Find way to eliminate this data copy.
707 NSData* data = [NSData dataWithBytes:screenshot.data->writable_data()
708 length:screenshot.data->size()];
709 NSString* format = [NSString stringWithUTF8String:screenshot.format.c_str()];
710 NSNumber* width = @(screenshot.frame_size.fWidth);
711 NSNumber* height = @(screenshot.frame_size.fHeight);
712 return result(@[ width, height, format ?: [NSNull null], data ]);
713 }];
714 }
715
716 - (void)maybeSetupPlatformViewChannels {
717 if (_shell && self.shell.IsSetup()) {
718 FlutterPlatformPlugin* platformPlugin = _platformPlugin.get();
719 [_platformChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
720 [platformPlugin handleMethodCall:call result:result];
721 }];
722
723 fml::WeakNSObject<FlutterEngine> weakSelf = [self getWeakNSObject];
724 [_platformViewsChannel.get()
725 setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
726 if (weakSelf) {
727 weakSelf.get().platformViewsController->OnMethodCall(call, result);
728 }
729 }];
730
731 FlutterTextInputPlugin* textInputPlugin = _textInputPlugin.get();
732 [_textInputChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
733 [textInputPlugin handleMethodCall:call result:result];
734 }];
735
736 FlutterUndoManagerPlugin* undoManagerPlugin = _undoManagerPlugin.get();
737 [_undoManagerChannel.get()
738 setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
739 [undoManagerPlugin handleMethodCall:call result:result];
740 }];
741
742 FlutterSpellCheckPlugin* spellCheckPlugin = _spellCheckPlugin.get();
743 [_spellCheckChannel.get()
744 setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
745 [spellCheckPlugin handleMethodCall:call result:result];
746 }];
747 }
748 }
749
750 - (flutter::Rasterizer::Screenshot)screenshot:(flutter::Rasterizer::ScreenshotType)type
751 base64Encode:(bool)base64Encode {
752 return self.shell.Screenshot(type, base64Encode);
753 }
754
755 - (void)launchEngine:(NSString*)entrypoint
756 libraryURI:(NSString*)libraryOrNil
757 entrypointArgs:(NSArray<NSString*>*)entrypointArgs {
758 // Launch the Dart application with the inferred run configuration.
759 self.shell.RunEngine([_dartProject.get() runConfigurationForEntrypoint:entrypoint
760 libraryOrNil:libraryOrNil
761 entrypointArgs:entrypointArgs]);
762 }
763
764 - (void)setUpShell:(std::unique_ptr<flutter::Shell>)shell
765 withVMServicePublication:(BOOL)doesVMServicePublication {
766 _shell = std::move(shell);
767 [self setUpChannels];
768 [self onLocaleUpdated:nil];
769 [self updateDisplays];
770 _publisher.reset([[FlutterDartVMServicePublisher alloc]
771 initWithEnableVMServicePublication:doesVMServicePublication]);
772 [self maybeSetupPlatformViewChannels];
773 _shell->SetGpuAvailability(_isGpuDisabled ? flutter::GpuAvailability::kUnavailable
774 : flutter::GpuAvailability::kAvailable);
775 }
776
777 + (BOOL)isProfilerEnabled {
778 bool profilerEnabled = false;
779 #if (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG) || \
780 (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_PROFILE)
781 profilerEnabled = true;
782 #endif
783 return profilerEnabled;
784 }
785
786 + (NSString*)generateThreadLabel:(NSString*)labelPrefix {
787 static size_t s_shellCount = 0;
788 return [NSString stringWithFormat:@"%@.%zu", labelPrefix, ++s_shellCount];
789 }
790
791 + (flutter::ThreadHost)makeThreadHost:(NSString*)threadLabel {
792 // The current thread will be used as the platform thread. Ensure that the message loop is
793 // initialized.
794 fml::MessageLoop::EnsureInitializedForCurrentThread();
795
796 uint32_t threadHostType = flutter::ThreadHost::Type::kUi | flutter::ThreadHost::Type::kRaster |
797 flutter::ThreadHost::Type::kIo;
798
799 if ([FlutterEngine isProfilerEnabled]) {
800 threadHostType = threadHostType | flutter::ThreadHost::Type::kProfiler;
801 }
802
803 flutter::ThreadHost::ThreadHostConfig host_config(threadLabel.UTF8String, threadHostType,
804 IOSPlatformThreadConfigSetter);
805
806 host_config.ui_config =
807 fml::Thread::ThreadConfig(flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
808 flutter::ThreadHost::Type::kUi, threadLabel.UTF8String),
809 fml::Thread::ThreadPriority::kDisplay);
810
811 host_config.raster_config =
812 fml::Thread::ThreadConfig(flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
813 flutter::ThreadHost::Type::kRaster, threadLabel.UTF8String),
814 fml::Thread::ThreadPriority::kRaster);
815
816 host_config.io_config =
817 fml::Thread::ThreadConfig(flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
818 flutter::ThreadHost::Type::kIo, threadLabel.UTF8String),
819 fml::Thread::ThreadPriority::kNormal);
820
821 return (flutter::ThreadHost){host_config};
822 }
823
824 static void SetEntryPoint(flutter::Settings* settings, NSString* entrypoint, NSString* libraryURI) {
825 if (libraryURI) {
826 FML_DCHECK(entrypoint) << "Must specify entrypoint if specifying library";
827 settings->advisory_script_entrypoint = entrypoint.UTF8String;
828 settings->advisory_script_uri = libraryURI.UTF8String;
829 } else if (entrypoint) {
830 settings->advisory_script_entrypoint = entrypoint.UTF8String;
831 settings->advisory_script_uri = std::string("main.dart");
832 } else {
833 settings->advisory_script_entrypoint = std::string("main");
834 settings->advisory_script_uri = std::string("main.dart");
835 }
836 }
837
838 - (BOOL)createShell:(NSString*)entrypoint
839 libraryURI:(NSString*)libraryURI
840 initialRoute:(NSString*)initialRoute {
841 if (_shell != nullptr) {
842 FML_LOG(WARNING) << "This FlutterEngine was already invoked.";
843 return NO;
844 }
845
846 self.initialRoute = initialRoute;
847
848 auto settings = [_dartProject.get() settings];
849 if (initialRoute != nil) {
850 self.initialRoute = initialRoute;
851 } else if (settings.route.empty() == false) {
852 self.initialRoute = [NSString stringWithUTF8String:settings.route.c_str()];
853 }
854
855 FlutterView.forceSoftwareRendering = settings.enable_software_rendering;
856
857 auto platformData = [_dartProject.get() defaultPlatformData];
858
859 SetEntryPoint(&settings, entrypoint, libraryURI);
860
861 NSString* threadLabel = [FlutterEngine generateThreadLabel:_labelPrefix];
862 _threadHost = std::make_shared<flutter::ThreadHost>();
863 *_threadHost = [FlutterEngine makeThreadHost:threadLabel];
864
865 // Lambda captures by pointers to ObjC objects are fine here because the
866 // create call is synchronous.
867 flutter::Shell::CreateCallback<flutter::PlatformView> on_create_platform_view =
868 [self](flutter::Shell& shell) {
869 [self recreatePlatformViewController];
870 return std::make_unique<flutter::PlatformViewIOS>(
871 shell, self->_renderingApi, self->_platformViewsController, shell.GetTaskRunners(),
872 shell.GetConcurrentWorkerTaskRunner(), shell.GetIsGpuDisabledSyncSwitch());
873 };
874
875 flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer =
876 [](flutter::Shell& shell) { return std::make_unique<flutter::Rasterizer>(shell); };
877
878 flutter::TaskRunners task_runners(threadLabel.UTF8String, // label
879 fml::MessageLoop::GetCurrent().GetTaskRunner(), // platform
880 _threadHost->raster_thread->GetTaskRunner(), // raster
881 _threadHost->ui_thread->GetTaskRunner(), // ui
882 _threadHost->io_thread->GetTaskRunner() // io
883 );
884
885 #if APPLICATION_EXTENSION_API_ONLY
886 if (@available(iOS 13.0, *)) {
887 _isGpuDisabled = self.viewController.flutterWindowSceneIfViewLoaded.activationState ==
888 UISceneActivationStateBackground;
889 } else {
890 // [UIApplication sharedApplication API is not available for app extension.
891 // We intialize the shell assuming the GPU is required.
892 _isGpuDisabled = NO;
893 }
894 #else
895 _isGpuDisabled =
896 [UIApplication sharedApplication].applicationState == UIApplicationStateBackground;
897 #endif
898
899 // Create the shell. This is a blocking operation.
900 std::unique_ptr<flutter::Shell> shell = flutter::Shell::Create(
901 /*platform_data=*/platformData,
902 /*task_runners=*/task_runners,
903 /*settings=*/settings,
904 /*on_create_platform_view=*/on_create_platform_view,
905 /*on_create_rasterizer=*/on_create_rasterizer,
906 /*is_gpu_disabled=*/_isGpuDisabled);
907
908 if (shell == nullptr) {
909 FML_LOG(ERROR) << "Could not start a shell FlutterEngine with entrypoint: "
910 << entrypoint.UTF8String;
911 } else {
912 // TODO(vashworth): Remove once done debugging https://github.com/flutter/flutter/issues/129836
913 FML_LOG(INFO) << "Enabled VM Service Publication: " << settings.enable_vm_service_publication;
914 [self setUpShell:std::move(shell)
915 withVMServicePublication:settings.enable_vm_service_publication];
916 if ([FlutterEngine isProfilerEnabled]) {
917 [self startProfiler];
918 }
919 }
920
921 return _shell != nullptr;
922 }
923
924 - (void)updateDisplays {
925 if (!_shell) {
926 // Tests may do this.
927 return;
928 }
929 auto vsync_waiter = _shell->GetVsyncWaiter().lock();
930 auto vsync_waiter_ios = std::static_pointer_cast<flutter::VsyncWaiterIOS>(vsync_waiter);
931 std::vector<std::unique_ptr<flutter::Display>> displays;
932 auto screen_size = UIScreen.mainScreen.nativeBounds.size;
933 auto scale = UIScreen.mainScreen.scale;
934 displays.push_back(std::make_unique<flutter::VariableRefreshRateDisplay>(
935 0, vsync_waiter_ios, screen_size.width, screen_size.height, scale));
936 _shell->OnDisplayUpdates(std::move(displays));
937 }
938
939 - (BOOL)run {
940 return [self runWithEntrypoint:FlutterDefaultDartEntrypoint
941 libraryURI:nil
942 initialRoute:FlutterDefaultInitialRoute];
943 }
944
945 - (BOOL)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)libraryURI {
946 return [self runWithEntrypoint:entrypoint
947 libraryURI:libraryURI
948 initialRoute:FlutterDefaultInitialRoute];
949 }
950
951 - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
952 return [self runWithEntrypoint:entrypoint libraryURI:nil initialRoute:FlutterDefaultInitialRoute];
953 }
954
955 - (BOOL)runWithEntrypoint:(NSString*)entrypoint initialRoute:(NSString*)initialRoute {
956 return [self runWithEntrypoint:entrypoint libraryURI:nil initialRoute:initialRoute];
957 }
958
959 - (BOOL)runWithEntrypoint:(NSString*)entrypoint
960 libraryURI:(NSString*)libraryURI
961 initialRoute:(NSString*)initialRoute {
962 return [self runWithEntrypoint:entrypoint
963 libraryURI:libraryURI
964 initialRoute:initialRoute
965 entrypointArgs:nil];
966 }
967
968 - (BOOL)runWithEntrypoint:(NSString*)entrypoint
969 libraryURI:(NSString*)libraryURI
970 initialRoute:(NSString*)initialRoute
971 entrypointArgs:(NSArray<NSString*>*)entrypointArgs {
972 if ([self createShell:entrypoint libraryURI:libraryURI initialRoute:initialRoute]) {
973 [self launchEngine:entrypoint libraryURI:libraryURI entrypointArgs:entrypointArgs];
974 }
975
976 return _shell != nullptr;
977 }
978
979 - (void)notifyLowMemory {
980 if (_shell) {
981 _shell->NotifyLowMemoryWarning();
982 }
983 [_systemChannel sendMessage:@{@"type" : @"memoryPressure"}];
984 }
985
986 #pragma mark - Text input delegate
987
988 - (void)flutterTextInputView:(FlutterTextInputView*)textInputView
989 updateEditingClient:(int)client
990 withState:(NSDictionary*)state {
991 [_textInputChannel.get() invokeMethod:@"TextInputClient.updateEditingState"
992 arguments:@[ @(client), state ]];
993 }
994
995 - (void)flutterTextInputView:(FlutterTextInputView*)textInputView
996 updateEditingClient:(int)client
997 withState:(NSDictionary*)state
998 withTag:(NSString*)tag {
999 [_textInputChannel.get() invokeMethod:@"TextInputClient.updateEditingStateWithTag"
1000 arguments:@[ @(client), @{tag : state} ]];
1001 }
1002
1003 - (void)flutterTextInputView:(FlutterTextInputView*)textInputView
1004 updateEditingClient:(int)client
1005 withDelta:(NSDictionary*)delta {
1006 [_textInputChannel.get() invokeMethod:@"TextInputClient.updateEditingStateWithDeltas"
1007 arguments:@[ @(client), delta ]];
1008 }
1009
1010 - (void)flutterTextInputView:(FlutterTextInputView*)textInputView
1011 updateFloatingCursor:(FlutterFloatingCursorDragState)state
1012 withClient:(int)client
1013 withPosition:(NSDictionary*)position {
1014 NSString* stateString;
1015 switch (state) {
1016 case FlutterFloatingCursorDragStateStart:
1017 stateString = @"FloatingCursorDragState.start";
1018 break;
1019 case FlutterFloatingCursorDragStateUpdate:
1020 stateString = @"FloatingCursorDragState.update";
1021 break;
1022 case FlutterFloatingCursorDragStateEnd:
1023 stateString = @"FloatingCursorDragState.end";
1024 break;
1025 }
1026 [_textInputChannel.get() invokeMethod:@"TextInputClient.updateFloatingCursor"
1027 arguments:@[ @(client), stateString, position ]];
1028 }
1029
1030 - (void)flutterTextInputView:(FlutterTextInputView*)textInputView
1031 performAction:(FlutterTextInputAction)action
1032 withClient:(int)client {
1033 NSString* actionString;
1034 switch (action) {
1035 case FlutterTextInputActionUnspecified:
1036 // Where did the term "unspecified" come from? iOS has a "default" and Android
1037 // has "unspecified." These 2 terms seem to mean the same thing but we need
1038 // to pick just one. "unspecified" was chosen because "default" is often a
1039 // reserved word in languages with switch statements (dart, java, etc).
1040 actionString = @"TextInputAction.unspecified";
1041 break;
1042 case FlutterTextInputActionDone:
1043 actionString = @"TextInputAction.done";
1044 break;
1045 case FlutterTextInputActionGo:
1046 actionString = @"TextInputAction.go";
1047 break;
1048 case FlutterTextInputActionSend:
1049 actionString = @"TextInputAction.send";
1050 break;
1051 case FlutterTextInputActionSearch:
1052 actionString = @"TextInputAction.search";
1053 break;
1054 case FlutterTextInputActionNext:
1055 actionString = @"TextInputAction.next";
1056 break;
1057 case FlutterTextInputActionContinue:
1058 actionString = @"TextInputAction.continueAction";
1059 break;
1060 case FlutterTextInputActionJoin:
1061 actionString = @"TextInputAction.join";
1062 break;
1063 case FlutterTextInputActionRoute:
1064 actionString = @"TextInputAction.route";
1065 break;
1066 case FlutterTextInputActionEmergencyCall:
1067 actionString = @"TextInputAction.emergencyCall";
1068 break;
1069 case FlutterTextInputActionNewline:
1070 actionString = @"TextInputAction.newline";
1071 break;
1072 }
1073 [_textInputChannel.get() invokeMethod:@"TextInputClient.performAction"
1074 arguments:@[ @(client), actionString ]];
1075 }
1076
1077 - (void)flutterTextInputView:(FlutterTextInputView*)textInputView
1078 showAutocorrectionPromptRectForStart:(NSUInteger)start
1079 end:(NSUInteger)end
1080 withClient:(int)client {
1081 [_textInputChannel.get() invokeMethod:@"TextInputClient.showAutocorrectionPromptRect"
1082 arguments:@[ @(client), @(start), @(end) ]];
1083 }
1084
1085 #pragma mark - FlutterViewEngineDelegate
1086
1087 - (void)flutterTextInputView:(FlutterTextInputView*)textInputView showToolbar:(int)client {
1088 // TODO(justinmc): Switch from the TextInputClient to Scribble channel when
1089 // the framework has finished transitioning to the Scribble channel.
1090 // https://github.com/flutter/flutter/pull/115296
1091 [_textInputChannel.get() invokeMethod:@"TextInputClient.showToolbar" arguments:@[ @(client) ]];
1092 }
1093
1094 - (void)flutterTextInputPlugin:(FlutterTextInputPlugin*)textInputPlugin
1095 focusElement:(UIScribbleElementIdentifier)elementIdentifier
1096 atPoint:(CGPoint)referencePoint
1097 result:(FlutterResult)callback {
1098 // TODO(justinmc): Switch from the TextInputClient to Scribble channel when
1099 // the framework has finished transitioning to the Scribble channel.
1100 // https://github.com/flutter/flutter/pull/115296
1101 [_textInputChannel.get()
1102 invokeMethod:@"TextInputClient.focusElement"
1103 arguments:@[ elementIdentifier, @(referencePoint.x), @(referencePoint.y) ]
1104 result:callback];
1105 }
1106
1107 - (void)flutterTextInputPlugin:(FlutterTextInputPlugin*)textInputPlugin
1108 requestElementsInRect:(CGRect)rect
1109 result:(FlutterResult)callback {
1110 // TODO(justinmc): Switch from the TextInputClient to Scribble channel when
1111 // the framework has finished transitioning to the Scribble channel.
1112 // https://github.com/flutter/flutter/pull/115296
1113 [_textInputChannel.get()
1114 invokeMethod:@"TextInputClient.requestElementsInRect"
1115 arguments:@[ @(rect.origin.x), @(rect.origin.y), @(rect.size.width), @(rect.size.height) ]
1116 result:callback];
1117 }
1118
1119 - (void)flutterTextInputViewScribbleInteractionBegan:(FlutterTextInputView*)textInputView {
1120 // TODO(justinmc): Switch from the TextInputClient to Scribble channel when
1121 // the framework has finished transitioning to the Scribble channel.
1122 // https://github.com/flutter/flutter/pull/115296
1123 [_textInputChannel.get() invokeMethod:@"TextInputClient.scribbleInteractionBegan" arguments:nil];
1124 }
1125
1126 - (void)flutterTextInputViewScribbleInteractionFinished:(FlutterTextInputView*)textInputView {
1127 // TODO(justinmc): Switch from the TextInputClient to Scribble channel when
1128 // the framework has finished transitioning to the Scribble channel.
1129 // https://github.com/flutter/flutter/pull/115296
1130 [_textInputChannel.get() invokeMethod:@"TextInputClient.scribbleInteractionFinished"
1131 arguments:nil];
1132 }
1133
1134 - (void)flutterTextInputView:(FlutterTextInputView*)textInputView
1135 insertTextPlaceholderWithSize:(CGSize)size
1136 withClient:(int)client {
1137 // TODO(justinmc): Switch from the TextInputClient to Scribble channel when
1138 // the framework has finished transitioning to the Scribble channel.
1139 // https://github.com/flutter/flutter/pull/115296
1140 [_textInputChannel.get() invokeMethod:@"TextInputClient.insertTextPlaceholder"
1141 arguments:@[ @(client), @(size.width), @(size.height) ]];
1142 }
1143
1144 - (void)flutterTextInputView:(FlutterTextInputView*)textInputView
1145 removeTextPlaceholder:(int)client {
1146 // TODO(justinmc): Switch from the TextInputClient to Scribble channel when
1147 // the framework has finished transitioning to the Scribble channel.
1148 // https://github.com/flutter/flutter/pull/115296
1149 [_textInputChannel.get() invokeMethod:@"TextInputClient.removeTextPlaceholder"
1150 arguments:@[ @(client) ]];
1151 }
1152
1153 - (void)flutterTextInputView:(FlutterTextInputView*)textInputView
1154 didResignFirstResponderWithTextInputClient:(int)client {
1155 // When flutter text input view resign first responder, send a message to
1156 // framework to ensure the focus state is correct. This is useful when close
1157 // keyboard from platform side.
1158 [_textInputChannel.get() invokeMethod:@"TextInputClient.onConnectionClosed"
1159 arguments:@[ @(client) ]];
1160
1161 // Platform view's first responder detection logic:
1162 //
1163 // All text input widgets (e.g. EditableText) are backed by a dummy UITextInput view
1164 // in the TextInputPlugin. When this dummy UITextInput view resigns first responder,
1165 // check if any platform view becomes first responder. If any platform view becomes
1166 // first responder, send a "viewFocused" channel message to inform the framework to un-focus
1167 // the previously focused text input.
1168 //
1169 // Caveat:
1170 // 1. This detection logic does not cover the scenario when a platform view becomes
1171 // first responder without any flutter text input resigning its first responder status
1172 // (e.g. user tapping on platform view first). For now it works fine because the TextInputPlugin
1173 // does not track the focused platform view id (which is different from Android implementation).
1174 //
1175 // 2. This detection logic assumes that all text input widgets are backed by a dummy
1176 // UITextInput view in the TextInputPlugin, which may not hold true in the future.
1177
1178 // Have to check in the next run loop, because iOS requests the previous first responder to
1179 // resign before requesting the next view to become first responder.
1180 dispatch_async(dispatch_get_main_queue(), ^(void) {
1181 long platform_view_id = self.platformViewsController->FindFirstResponderPlatformViewId();
1182 if (platform_view_id == -1) {
1183 return;
1184 }
1185
1186 [_platformViewsChannel.get() invokeMethod:@"viewFocused" arguments:@(platform_view_id)];
1187 });
1188 }
1189
1190 #pragma mark - Undo Manager Delegate
1191
1192 - (void)flutterUndoManagerPlugin:(FlutterUndoManagerPlugin*)undoManagerPlugin
1193 handleUndoWithDirection:(FlutterUndoRedoDirection)direction {
1194 NSString* action = (direction == FlutterUndoRedoDirectionUndo) ? @"undo" : @"redo";
1195 [_undoManagerChannel.get() invokeMethod:@"UndoManagerClient.handleUndo" arguments:@[ action ]];
1196 }
1197
1198 #pragma mark - Screenshot Delegate
1199
1200 - (flutter::Rasterizer::Screenshot)takeScreenshot:(flutter::Rasterizer::ScreenshotType)type
1201 asBase64Encoded:(BOOL)base64Encode {
1202 FML_DCHECK(_shell) << "Cannot takeScreenshot without a shell";
1203 return _shell->Screenshot(type, base64Encode);
1204 }
1205
1206 - (void)flutterViewAccessibilityDidCall {
1207 if (self.viewController.view.accessibilityElements == nil) {
1208 [self ensureSemanticsEnabled];
1209 }
1210 }
1211
1212 - (NSObject<FlutterBinaryMessenger>*)binaryMessenger {
1213 return _binaryMessenger;
1214 }
1215
1216 - (NSObject<FlutterTextureRegistry>*)textureRegistry {
1217 return _textureRegistry;
1218 }
1219
1220 // For test only. Ideally we should create a dependency injector for all dependencies and
1221 // remove this.
1222 - (void)setBinaryMessenger:(FlutterBinaryMessengerRelay*)binaryMessenger {
1223 // Discard the previous messenger and keep the new one.
1224 if (binaryMessenger != _binaryMessenger) {
1225 _binaryMessenger.parent = nil;
1226 [_binaryMessenger release];
1227 _binaryMessenger = [binaryMessenger retain];
1228 }
1229 }
1230
1231 #pragma mark - FlutterBinaryMessenger
1232
1233 - (void)sendOnChannel:(NSString*)channel message:(NSData*)message {
1234 [self sendOnChannel:channel message:message binaryReply:nil];
1235 }
1236
1237 - (void)sendOnChannel:(NSString*)channel
1238 message:(NSData*)message
1239 binaryReply:(FlutterBinaryReply)callback {
1240 NSParameterAssert(channel);
1241 NSAssert(_shell && _shell->IsSetup(),
1242 @"Sending a message before the FlutterEngine has been run.");
1243 fml::RefPtr<flutter::PlatformMessageResponseDarwin> response =
1244 (callback == nil) ? nullptr
1245 : fml::MakeRefCounted<flutter::PlatformMessageResponseDarwin>(
1246 ^(NSData* reply) {
1247 callback(reply);
1248 },
1249 _shell->GetTaskRunners().GetPlatformTaskRunner());
1250 std::unique_ptr<flutter::PlatformMessage> platformMessage =
1251 (message == nil) ? std::make_unique<flutter::PlatformMessage>(channel.UTF8String, response)
1252 : std::make_unique<flutter::PlatformMessage>(
1253 channel.UTF8String, flutter::CopyNSDataToMapping(message), response);
1254
1255 _shell->GetPlatformView()->DispatchPlatformMessage(std::move(platformMessage));
1256 // platformMessage takes ownership of response.
1257 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
1258 }
1259
1260 - (NSObject<FlutterTaskQueue>*)makeBackgroundTaskQueue {
1261 return flutter::PlatformMessageHandlerIos::MakeBackgroundTaskQueue();
1262 }
1263
1264 - (FlutterBinaryMessengerConnection)setMessageHandlerOnChannel:(NSString*)channel
1265 binaryMessageHandler:
1266 (FlutterBinaryMessageHandler)handler {
1267 return [self setMessageHandlerOnChannel:channel binaryMessageHandler:handler taskQueue:nil];
1268 }
1269
1270 - (FlutterBinaryMessengerConnection)
1271 setMessageHandlerOnChannel:(NSString*)channel
1272 binaryMessageHandler:(FlutterBinaryMessageHandler)handler
1273 taskQueue:(NSObject<FlutterTaskQueue>* _Nullable)taskQueue {
1274 NSParameterAssert(channel);
1275 if (_shell && _shell->IsSetup()) {
1276 self.iosPlatformView->GetPlatformMessageHandlerIos()->SetMessageHandler(channel.UTF8String,
1277 handler, taskQueue);
1278 return _connections->AquireConnection(channel.UTF8String);
1279 } else {
1280 NSAssert(!handler, @"Setting a message handler before the FlutterEngine has been run.");
1281 // Setting a handler to nil for a channel that has not yet been set up is a no-op.
1282 return flutter::ConnectionCollection::MakeErrorConnection(-1);
1283 }
1284 }
1285
1286 - (void)cleanUpConnection:(FlutterBinaryMessengerConnection)connection {
1287 if (_shell && _shell->IsSetup()) {
1288 std::string channel = _connections->CleanupConnection(connection);
1289 if (!channel.empty()) {
1290 self.iosPlatformView->GetPlatformMessageHandlerIos()->SetMessageHandler(channel.c_str(), nil,
1291 nil);
1292 }
1293 }
1294 }
1295
1296 #pragma mark - FlutterTextureRegistry
1297
1298 - (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture {
1299 int64_t textureId = _nextTextureId++;
1300 self.iosPlatformView->RegisterExternalTexture(textureId, texture);
1301 return textureId;
1302 }
1303
1304 - (void)unregisterTexture:(int64_t)textureId {
1305 _shell->GetPlatformView()->UnregisterTexture(textureId);
1306 }
1307
1308 - (void)textureFrameAvailable:(int64_t)textureId {
1309 _shell->GetPlatformView()->MarkTextureFrameAvailable(textureId);
1310 }
1311
1312 - (NSString*)lookupKeyForAsset:(NSString*)asset {
1313 return [FlutterDartProject lookupKeyForAsset:asset];
1314 }
1315
1316 - (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package {
1317 return [FlutterDartProject lookupKeyForAsset:asset fromPackage:package];
1318 }
1319
1320 - (id<FlutterPluginRegistry>)pluginRegistry {
1321 return self;
1322 }
1323
1324 #pragma mark - FlutterPluginRegistry
1325
1326 - (NSObject<FlutterPluginRegistrar>*)registrarForPlugin:(NSString*)pluginKey {
1327 NSAssert(self.pluginPublications[pluginKey] == nil, @"Duplicate plugin key: %@", pluginKey);
1328 self.pluginPublications[pluginKey] = [NSNull null];
1329 FlutterEngineRegistrar* result = [[FlutterEngineRegistrar alloc] initWithPlugin:pluginKey
1330 flutterEngine:self];
1331 self.registrars[pluginKey] = result;
1332 return [result autorelease];
1333 }
1334
1335 - (BOOL)hasPlugin:(NSString*)pluginKey {
1336 return _pluginPublications[pluginKey] != nil;
1337 }
1338
1339 - (NSObject*)valuePublishedByPlugin:(NSString*)pluginKey {
1340 return _pluginPublications[pluginKey];
1341 }
1342
1343 #pragma mark - Notifications
1344
1345 #if APPLICATION_EXTENSION_API_ONLY
1346 - (void)sceneWillEnterForeground:(NSNotification*)notification API_AVAILABLE(ios(13.0)) {
1347 [self flutterWillEnterForeground:notification];
1348 }
1349
1350 - (void)sceneDidEnterBackground:(NSNotification*)notification API_AVAILABLE(ios(13.0)) {
1351 [self flutterDidEnterBackground:notification];
1352 }
1353 #else
1354 - (void)applicationWillEnterForeground:(NSNotification*)notification {
1355 [self flutterWillEnterForeground:notification];
1356 }
1357
1358 - (void)applicationDidEnterBackground:(NSNotification*)notification {
1359 [self flutterDidEnterBackground:notification];
1360 }
1361 #endif
1362
1363 - (void)flutterWillEnterForeground:(NSNotification*)notification {
1364 [self setIsGpuDisabled:NO];
1365 }
1366
1367 - (void)flutterDidEnterBackground:(NSNotification*)notification {
1368 [self setIsGpuDisabled:YES];
1369 [self notifyLowMemory];
1370 }
1371
1372 - (void)onMemoryWarning:(NSNotification*)notification {
1373 [self notifyLowMemory];
1374 }
1375
1376 - (void)setIsGpuDisabled:(BOOL)value {
1377 if (_shell) {
1378 _shell->SetGpuAvailability(value ? flutter::GpuAvailability::kUnavailable
1379 : flutter::GpuAvailability::kAvailable);
1380 }
1381 _isGpuDisabled = value;
1382 }
1383
1384 #pragma mark - Locale updates
1385
1386 - (void)onLocaleUpdated:(NSNotification*)notification {
1387 // Get and pass the user's preferred locale list to dart:ui.
1388 NSMutableArray<NSString*>* localeData = [[[NSMutableArray alloc] init] autorelease];
1389 NSArray<NSString*>* preferredLocales = [NSLocale preferredLanguages];
1390 for (NSString* localeID in preferredLocales) {
1391 NSLocale* locale = [[[NSLocale alloc] initWithLocaleIdentifier:localeID] autorelease];
1392 NSString* languageCode = [locale objectForKey:NSLocaleLanguageCode];
1393 NSString* countryCode = [locale objectForKey:NSLocaleCountryCode];
1394 NSString* scriptCode = [locale objectForKey:NSLocaleScriptCode];
1395 NSString* variantCode = [locale objectForKey:NSLocaleVariantCode];
1396 if (!languageCode) {
1397 continue;
1398 }
1399 [localeData addObject:languageCode];
1400 [localeData addObject:(countryCode ? countryCode : @"")];
1401 [localeData addObject:(scriptCode ? scriptCode : @"")];
1402 [localeData addObject:(variantCode ? variantCode : @"")];
1403 }
1404 if (localeData.count == 0) {
1405 return;
1406 }
1407 [self.localizationChannel invokeMethod:@"setLocale" arguments:localeData];
1408 }
1409
1410 - (void)waitForFirstFrame:(NSTimeInterval)timeout
1411 callback:(void (^_Nonnull)(BOOL didTimeout))callback {
1412 dispatch_queue_t queue = dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0);
1413 dispatch_async(queue, ^{
1414 fml::TimeDelta waitTime = fml::TimeDelta::FromMilliseconds(timeout * 1000);
1415 BOOL didTimeout =
1416 self.shell.WaitForFirstFrame(waitTime).code() == fml::StatusCode::kDeadlineExceeded;
1417 dispatch_async(dispatch_get_main_queue(), ^{
1418 callback(didTimeout);
1419 });
1420 });
1421 }
1422
1423 - (FlutterEngine*)spawnWithEntrypoint:(/*nullable*/ NSString*)entrypoint
1424 libraryURI:(/*nullable*/ NSString*)libraryURI
1425 initialRoute:(/*nullable*/ NSString*)initialRoute
1426 entrypointArgs:(/*nullable*/ NSArray<NSString*>*)entrypointArgs {
1427 NSAssert(_shell, @"Spawning from an engine without a shell (possibly not run).");
1428 FlutterEngine* result = [[FlutterEngine alloc] initWithName:_labelPrefix
1429 project:_dartProject.get()
1430 allowHeadlessExecution:_allowHeadlessExecution];
1431 flutter::RunConfiguration configuration =
1432 [_dartProject.get() runConfigurationForEntrypoint:entrypoint
1433 libraryOrNil:libraryURI
1434 entrypointArgs:entrypointArgs];
1435
1436 fml::WeakPtr<flutter::PlatformView> platform_view = _shell->GetPlatformView();
1437 FML_DCHECK(platform_view);
1438 // Static-cast safe since this class always creates PlatformViewIOS instances.
1439 flutter::PlatformViewIOS* ios_platform_view =
1440 static_cast<flutter::PlatformViewIOS*>(platform_view.get());
1441 std::shared_ptr<flutter::IOSContext> context = ios_platform_view->GetIosContext();
1442 FML_DCHECK(context);
1443
1444 // Lambda captures by pointers to ObjC objects are fine here because the
1445 // create call is synchronous.
1446 flutter::Shell::CreateCallback<flutter::PlatformView> on_create_platform_view =
1447 [result, context](flutter::Shell& shell) {
1448 [result recreatePlatformViewController];
1449 return std::make_unique<flutter::PlatformViewIOS>(
1450 shell, context, result->_platformViewsController, shell.GetTaskRunners());
1451 };
1452
1453 flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer =
1454 [](flutter::Shell& shell) { return std::make_unique<flutter::Rasterizer>(shell); };
1455
1456 std::string cppInitialRoute;
1457 if (initialRoute) {
1458 cppInitialRoute = [initialRoute UTF8String];
1459 }
1460
1461 std::unique_ptr<flutter::Shell> shell = _shell->Spawn(
1462 std::move(configuration), cppInitialRoute, on_create_platform_view, on_create_rasterizer);
1463
1464 result->_threadHost = _threadHost;
1465 result->_profiler = _profiler;
1466 result->_profiler_metrics = _profiler_metrics;
1467 result->_isGpuDisabled = _isGpuDisabled;
1468 [result setUpShell:std::move(shell) withVMServicePublication:NO];
1469 return [result autorelease];
1470 }
1471
1472 - (const flutter::ThreadHost&)threadHost {
1473 return *_threadHost;
1474 }
1475
1476 - (FlutterDartProject*)project {
1477 return _dartProject.get();
1478 }
1479
1480 - (BOOL)isUsingImpeller {
1481 return self.project.isImpellerEnabled;
1482 }
1483
1484 @end
1485
1486 @implementation FlutterEngineRegistrar {
1487 NSString* _pluginKey;
1488 }
1489
1490 - (instancetype)initWithPlugin:(NSString*)pluginKey flutterEngine:(FlutterEngine*)flutterEngine {
1491 self = [super init];
1492 NSAssert(self, @"Super init cannot be nil");
1493 _pluginKey = [pluginKey copy];
1494 _flutterEngine = flutterEngine;
1495 return self;
1496 }
1497
1498 - (void)dealloc {
1499 [_pluginKey release];
1500 [super dealloc];
1501 }
1502
1503 - (NSObject<FlutterBinaryMessenger>*)messenger {
1504 return _flutterEngine.binaryMessenger;
1505 }
1506
1507 - (NSObject<FlutterTextureRegistry>*)textures {
1508 return _flutterEngine.textureRegistry;
1509 }
1510
1511 - (void)publish:(NSObject*)value {
1512 _flutterEngine.pluginPublications[_pluginKey] = value;
1513 }
1514
1515 - (void)addMethodCallDelegate:(NSObject<FlutterPlugin>*)delegate
1516 channel:(FlutterMethodChannel*)channel {
1517 [channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
1518 [delegate handleMethodCall:call result:result];
1519 }];
1520 }
1521
1522 - (void)addApplicationDelegate:(NSObject<FlutterPlugin>*)delegate
1523 NS_EXTENSION_UNAVAILABLE_IOS("Disallowed in plugins used in app extensions") {
1524 id<UIApplicationDelegate> appDelegate = [[UIApplication sharedApplication] delegate];
1525 if ([appDelegate conformsToProtocol:@protocol(FlutterAppLifeCycleProvider)]) {
1526 id<FlutterAppLifeCycleProvider> lifeCycleProvider =
1527 (id<FlutterAppLifeCycleProvider>)appDelegate;
1528 [lifeCycleProvider addApplicationLifeCycleDelegate:delegate];
1529 }
1530 }
1531
1532 - (NSString*)lookupKeyForAsset:(NSString*)asset {
1533 return [_flutterEngine lookupKeyForAsset:asset];
1534 }
1535
1536 - (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package {
1537 return [_flutterEngine lookupKeyForAsset:asset fromPackage:package];
1538 }
1539
1540 - (void)registerViewFactory:(NSObject<FlutterPlatformViewFactory>*)factory
1541 withId:(NSString*)factoryId {
1542 [self registerViewFactory:factory
1543 withId:factoryId
1544 gestureRecognizersBlockingPolicy:FlutterPlatformViewGestureRecognizersBlockingPolicyEager];
1545 }
1546
1547 - (void)registerViewFactory:(NSObject<FlutterPlatformViewFactory>*)factory
1548 withId:(NSString*)factoryId
1549 gestureRecognizersBlockingPolicy:
1550 (FlutterPlatformViewGestureRecognizersBlockingPolicy)gestureRecognizersBlockingPolicy {
1551 [_flutterEngine platformViewsController]->RegisterViewFactory(factory, factoryId,
1552 gestureRecognizersBlockingPolicy);
1553 }
1554
1555 @end
_restorationChannel
fml::scoped_nsobject< FlutterMethodChannel > _restorationChannel
Definition: FlutterEngine.mm:138
FlutterTextureRegistryRelay::parent
NSObject< FlutterTextureRegistry > * parent
Definition: FlutterTextureRegistryRelay.h:22
_weakFactory
std::unique_ptr< fml::WeakNSObjectFactory< FlutterEngine > > _weakFactory
Definition: FlutterEngine.mm:120
self
return self
Definition: FlutterTextureRegistryRelay.mm:17
flutter::PlatformMessageHandlerIos::MakeBackgroundTaskQueue
static NSObject< FlutterTaskQueue > * MakeBackgroundTaskQueue()
Definition: platform_message_handler_ios.mm:39
FlutterDartProject::isImpellerEnabled
BOOL isImpellerEnabled
Definition: FlutterDartProject_Internal.h:22
FlutterEngine
Definition: FlutterEngine.h:61
FlutterView::forceSoftwareRendering
BOOL forceSoftwareRendering
Definition: FlutterView.h:54
FlutterPlugin-p
Definition: FlutterPlugin.h:189
_undoManagerChannel
fml::scoped_nsobject< FlutterMethodChannel > _undoManagerChannel
Definition: FlutterEngine.mm:142
FlutterTextInputDelegate-p
Definition: FlutterTextInputDelegate.h:37
_viewController
fml::WeakNSObject< FlutterViewController > _viewController
Definition: FlutterEngine.mm:122
FlutterDefaultInitialRoute
NSString *const FlutterDefaultInitialRoute
Definition: FlutterEngine.mm:81
FlutterTextInputPlugin::indirectScribbleDelegate
id< FlutterIndirectScribbleDelegate > indirectScribbleDelegate
Definition: FlutterTextInputPlugin.h:37
FlutterSpellCheckPlugin
Definition: FlutterSpellCheckPlugin.h:13
FlutterDefaultDartEntrypoint
NSString *const FlutterDefaultDartEntrypoint
Definition: FlutterEngine.mm:80
_labelPrefix
NSString * _labelPrefix
Definition: FlutterEngine.mm:119
FlutterBasicMessageChannel
Definition: FlutterChannels.h:37
flutter::ConnectionCollection
Maintains a current integer assigned to a name (connections).
Definition: connection_collection.h:15
FlutterViewController
Definition: FlutterViewController.h:56
FlutterMethodChannel
Definition: FlutterChannels.h:220
FlutterEngineRegistrar::flutterEngine
FlutterEngine * flutterEngine
Definition: FlutterEngine.mm:90
FlutterEngine(Test)::embedderAPI
FlutterEngineProcTable & embedderAPI
Definition: FlutterEngine_Test.h:22
FlutterEngine::isolateId
NSString * isolateId
Definition: FlutterEngine.h:449
_lifecycleChannel
fml::scoped_nsobject< FlutterBasicMessageChannel > _lifecycleChannel
Definition: FlutterEngine.mm:145
_textInputPlugin
fml::scoped_nsobject< FlutterTextInputPlugin > _textInputPlugin
Definition: FlutterEngine.mm:132
FlutterTextInputDelegate.h
FlutterUndoManagerPlugin.h
-[FlutterEngine initWithName:project:allowHeadlessExecution:]
instancetype initWithName:project:allowHeadlessExecution:(NSString *labelPrefix,[project] nullable FlutterDartProject *project,[allowHeadlessExecution] BOOL allowHeadlessExecution)
FlutterRestorationPlugin
Definition: FlutterRestorationPlugin.h:12
FlutterTextureRegistry-p
Definition: FlutterTexture.h:38
_navigationChannel
fml::scoped_nsobject< FlutterMethodChannel > _navigationChannel
Definition: FlutterEngine.mm:137
connection_collection.h
_textInputChannel
fml::scoped_nsobject< FlutterMethodChannel > _textInputChannel
Definition: FlutterEngine.mm:141
FlutterEngine_Internal.h
command_line.h
+[FlutterDartProject lookupKeyForAsset:]
NSString * lookupKeyForAsset:(NSString *asset)
Definition: FlutterDartProject.mm:389
FlutterError
Definition: FlutterCodecs.h:246
kNumProfilerSamplesPerSec
static constexpr int kNumProfilerSamplesPerSec
Definition: FlutterEngine.mm:87
FlutterDartVMServicePublisher.h
-[FlutterPlatformPlugin handleMethodCall:result:]
void handleMethodCall:result:(FlutterMethodCall *call,[result] FlutterResult result)
Definition: FlutterPlatformPlugin.mm:103
-[FlutterEngine runWithEntrypoint:libraryURI:initialRoute:]
BOOL runWithEntrypoint:libraryURI:initialRoute:(nullable NSString *entrypoint,[libraryURI] nullable NSString *libraryURI,[initialRoute] nullable NSString *initialRoute)
_profiler_metrics
std::shared_ptr< flutter::ProfilerMetricsIOS > _profiler_metrics
Definition: FlutterEngine.mm:127
flutter::CopyNSDataToMapping
fml::MallocMapping CopyNSDataToMapping(NSData *data)
Definition: buffer_conversions.mm:30
_settingsChannel
fml::scoped_nsobject< FlutterBasicMessageChannel > _settingsChannel
Definition: FlutterEngine.mm:147
platform_view
std::unique_ptr< flutter::PlatformViewIOS > platform_view
Definition: FlutterEnginePlatformViewTest.mm:61
+[FlutterError errorWithCode:message:details:]
instancetype errorWithCode:message:details:(NSString *code,[message] NSString *_Nullable message,[details] id _Nullable details)
_connections
std::unique_ptr< flutter::ConnectionCollection > _connections
Definition: FlutterEngine.mm:157
FlutterPluginRegistrar-p
Definition: FlutterPlugin.h:283
-[FlutterTextInputPlugin handleMethodCall:result:]
void handleMethodCall:result:(FlutterMethodCall *call,[result] FlutterResult result)
Definition: FlutterTextInputPlugin.mm:2356
flutter::PlatformViewIOS
Definition: platform_view_ios.h:41
flutter::PlatformViewIOS::GetIosContext
const std::shared_ptr< IOSContext > & GetIosContext()
Definition: platform_view_ios.h:93
_publisher
fml::scoped_nsobject< FlutterDartVMServicePublisher > _publisher
Definition: FlutterEngine.mm:123
_spellCheckChannel
fml::scoped_nsobject< FlutterMethodChannel > _spellCheckChannel
Definition: FlutterEngine.mm:144
FlutterIndirectScribbleDelegate-p
Definition: FlutterIndirectScribbleDelegate.h:13
-[FlutterTextInputPlugin setUpIndirectScribbleInteraction:]
void setUpIndirectScribbleInteraction:(id< FlutterViewResponder > viewResponder)
Definition: FlutterTextInputPlugin.mm:2972
viewController
FlutterViewController * viewController
Definition: FlutterTextInputPluginTest.mm:92
FlutterBinaryMessageHandler
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
Definition: FlutterBinaryMessenger.h:30
_platformViewsController
std::shared_ptr< flutter::FlutterPlatformViewsController > _platformViewsController
Definition: FlutterEngine.mm:125
-[FlutterUndoManagerPlugin handleMethodCall:result:]
void handleMethodCall:result:(FlutterMethodCall *call,[result] FlutterResult result)
Definition: FlutterUndoManagerPlugin.mm:40
FlutterTextInputView
Definition: FlutterTextInputPlugin.mm:801
-[FlutterMethodChannel setMethodCallHandler:]
void setMethodCallHandler:(FlutterMethodCallHandler _Nullable handler)
FlutterBinaryMessengerRelay.h
kFlutterKeyDataChannel
NSString *const kFlutterKeyDataChannel
Definition: FlutterEngine.mm:86
profiler_metrics_ios.h
flutter::ConnectionCollection::MakeErrorConnection
static Connection MakeErrorConnection(int errCode)
Definition: connection_collection.mm:35
flutter::GetRenderingAPIForProcess
IOSRenderingAPI GetRenderingAPIForProcess(bool force_software)
Definition: rendering_api_selection.mm:33
FlutterStringCodec
Definition: FlutterCodecs.h:63
_spellCheckPlugin
fml::scoped_nsobject< FlutterSpellCheckPlugin > _spellCheckPlugin
Definition: FlutterEngine.mm:134
_undoManagerPlugin
fml::scoped_nsobject< FlutterUndoManagerPlugin > _undoManagerPlugin
Definition: FlutterEngine.mm:133
FlutterSpellCheckPlugin.h
flutter
Definition: accessibility_bridge.h:28
_scribbleChannel
fml::scoped_nsobject< FlutterMethodChannel > _scribbleChannel
Definition: FlutterEngine.mm:143
_textureRegistry
FlutterTextureRegistryRelay * _textureRegistry
Definition: FlutterEngine.mm:156
IOSPlatformThreadConfigSetter
static void IOSPlatformThreadConfigSetter(const fml::Thread::ThreadConfig &config)
Definition: FlutterEngine.mm:46
FlutterTextInputPlugin
Definition: FlutterTextInputPlugin.h:33
_systemChannel
fml::scoped_nsobject< FlutterBasicMessageChannel > _systemChannel
Definition: FlutterEngine.mm:146
_profiler
std::shared_ptr< flutter::SamplingProfiler > _profiler
Definition: FlutterEngine.mm:128
flutter::IOSRenderingAPI
IOSRenderingAPI
Definition: rendering_api_selection.h:14
FlutterTextureRegistryRelay
Definition: FlutterTextureRegistryRelay.h:17
FlutterTaskQueue-p
Definition: FlutterBinaryMessenger.h:34
FlutterResult
void(^ FlutterResult)(id _Nullable result)
Definition: FlutterChannels.h:194
UIViewController+FlutterScreenAndSceneIfLoaded.h
FlutterPlatformViewGestureRecognizersBlockingPolicy
FlutterPlatformViewGestureRecognizersBlockingPolicy
Definition: FlutterPlugin.h:252
_keyEventChannel
fml::scoped_nsobject< FlutterBasicMessageChannel > _keyEventChannel
Definition: FlutterEngine.mm:148
FlutterIndirectScribbleDelegate.h
FlutterPlatformPlugin.h
_renderingApi
flutter::IOSRenderingAPI _renderingApi
Definition: FlutterEngine.mm:126
FlutterTexture
Definition: FlutterMetalLayer.mm:54
-[FlutterPlugin-p handleMethodCall:result:]
void handleMethodCall:result:(FlutterMethodCall *call,[result] FlutterResult result)
_binaryMessenger
FlutterBinaryMessengerRelay * _binaryMessenger
Definition: FlutterEngine.mm:155
rendering_api_selection.h
FlutterAppLifeCycleProvider-p
Definition: FlutterPlugin.h:436
FlutterPlatformViewFactory-p
Definition: FlutterPlatformViews.h:26
_screenshotChannel
fml::scoped_nsobject< FlutterMethodChannel > _screenshotChannel
Definition: FlutterEngine.mm:149
_shell
std::unique_ptr< flutter::Shell > _shell
Definition: FlutterEngine.mm:118
FlutterUndoManagerDelegate-p
Definition: FlutterUndoManagerDelegate.h:21
FlutterDartProject_Internal.h
textInputPlugin
FlutterTextInputPlugin * textInputPlugin
Definition: FlutterTextInputPluginTest.mm:90
FlutterViewController_Internal.h
FlutterUndoManagerPlugin
Definition: FlutterUndoManagerPlugin.h:15
FlutterPlatformPlugin
Definition: FlutterPlatformPlugin.h:12
_restorationEnabled
BOOL _restorationEnabled
Definition: FlutterEngine.mm:154
FlutterView
Definition: FlutterView.h:39
_platformChannel
fml::scoped_nsobject< FlutterMethodChannel > _platformChannel
Definition: FlutterEngine.mm:139
FlutterBinaryMessengerRelay
Definition: FlutterBinaryMessengerRelay.h:14
FlutterJSONMethodCodec
Definition: FlutterCodecs.h:455
vsync_waiter_ios.h
+[FlutterDartProject lookupKeyForAsset:fromPackage:]
NSString * lookupKeyForAsset:fromPackage:(NSString *asset,[fromPackage] NSString *package)
Definition: FlutterDartProject.mm:398
FlutterEngineRegistrar
Definition: FlutterEngine.mm:89
platform_view_ios.h
_nextTextureId
int64_t _nextTextureId
Definition: FlutterEngine.mm:151
FlutterEngine(Test)::enableEmbedderAPI
BOOL enableEmbedderAPI
Definition: FlutterEngine_Test.h:23
FlutterDartProject
Definition: FlutterDartProject.mm:262
FlutterTextureRegistryRelay.h
_localizationChannel
fml::scoped_nsobject< FlutterMethodChannel > _localizationChannel
Definition: FlutterEngine.mm:136
_allowHeadlessExecution
BOOL _allowHeadlessExecution
Definition: FlutterEngine.mm:153
FlutterBinaryMessenger-p
Definition: FlutterBinaryMessenger.h:49
FlutterBinaryMessengerRelay::parent
NSObject< FlutterBinaryMessenger > * parent
Definition: FlutterBinaryMessengerRelay.h:15
FlutterDartVMServicePublisher
Definition: FlutterDartVMServicePublisher.h:10
platform_message_response_darwin.h
_threadHost
std::shared_ptr< flutter::ThreadHost > _threadHost
Definition: FlutterEngine.mm:115
FlutterUndoManagerDelegate.h
FlutterStandardMethodCodec
Definition: FlutterCodecs.h:469
kFlutterEngineWillDealloc
NSString *const kFlutterEngineWillDealloc
Definition: FlutterEngine.mm:85
FlutterBinaryMessengerConnection
int64_t FlutterBinaryMessengerConnection
Definition: FlutterBinaryMessenger.h:32
_restorationPlugin
fml::scoped_nsobject< FlutterRestorationPlugin > _restorationPlugin
Definition: FlutterEngine.mm:135
FlutterBinaryReply
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)
_platformViewsChannel
fml::scoped_nsobject< FlutterMethodChannel > _platformViewsChannel
Definition: FlutterEngine.mm:140
+[FlutterMessageCodec-p sharedInstance]
instancetype sharedInstance()
flutter::FlutterPlatformViewsController
Definition: FlutterPlatformViews_Internal.h:201
_platformPlugin
fml::scoped_nsobject< FlutterPlatformPlugin > _platformPlugin
Definition: FlutterEngine.mm:131
-[FlutterSpellCheckPlugin handleMethodCall:result:]
void handleMethodCall:result:(FlutterMethodCall *call,[result] FlutterResult result)
Definition: FlutterSpellCheckPlugin.mm:24
FlutterJSONMessageCodec
Definition: FlutterCodecs.h:81