Flutter Engine
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 #import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h"
6 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
7 
8 #include <algorithm>
9 #include <vector>
10 
11 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h"
12 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureGL.h"
13 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"
14 #import "flutter/shell/platform/embedder/embedder.h"
15 
16 /**
17  * Constructs and returns a FlutterLocale struct corresponding to |locale|, which must outlive
18  * the returned struct.
19  */
20 static FlutterLocale FlutterLocaleFromNSLocale(NSLocale* locale) {
21  FlutterLocale flutterLocale = {};
22  flutterLocale.struct_size = sizeof(FlutterLocale);
23  flutterLocale.language_code = [[locale objectForKey:NSLocaleLanguageCode] UTF8String];
24  flutterLocale.country_code = [[locale objectForKey:NSLocaleCountryCode] UTF8String];
25  flutterLocale.script_code = [[locale objectForKey:NSLocaleScriptCode] UTF8String];
26  flutterLocale.variant_code = [[locale objectForKey:NSLocaleVariantCode] UTF8String];
27  return flutterLocale;
28 }
29 
30 namespace {
31 
32 struct AotDataDeleter {
33  void operator()(FlutterEngineAOTData aot_data) { FlutterEngineCollectAOTData(aot_data); }
34 };
35 
36 using UniqueAotDataPtr = std::unique_ptr<_FlutterEngineAOTData, AotDataDeleter>;
37 
38 }
39 
40 /**
41  * Private interface declaration for FlutterEngine.
42  */
43 @interface FlutterEngine () <FlutterBinaryMessenger>
44 
45 /**
46  * Sends the list of user-preferred locales to the Flutter engine.
47  */
48 - (void)sendUserLocales;
49 
50 /**
51  * Called by the engine to make the context the engine should draw into current.
52  */
53 - (bool)engineCallbackOnMakeCurrent;
54 
55 /**
56  * Called by the engine to clear the context the engine should draw into.
57  */
58 - (bool)engineCallbackOnClearCurrent;
59 
60 /**
61  * Called by the engine when the context's buffers should be swapped.
62  */
63 - (bool)engineCallbackOnPresent;
64 
65 /**
66  * Makes the resource context the current context.
67  */
68 - (bool)engineCallbackOnMakeResourceCurrent;
69 
70 /**
71  * Handles a platform message from the engine.
72  */
73 - (void)engineCallbackOnPlatformMessage:(const FlutterPlatformMessage*)message;
74 
75 /**
76  * Forwards texture copy request to the corresponding texture via |textureID|.
77  */
78 - (BOOL)populateTextureWithIdentifier:(int64_t)textureID
79  openGLTexture:(FlutterOpenGLTexture*)openGLTexture;
80 
81 /**
82  * Requests that the task be posted back the to the Flutter engine at the target time. The target
83  * time is in the clock used by the Flutter engine.
84  */
85 - (void)postMainThreadTask:(FlutterTask)task targetTimeInNanoseconds:(uint64_t)targetTime;
86 
87 /**
88  * Loads the AOT snapshots and instructions from the elf bundle (app_elf_snapshot.so) if it is
89  * present in the assets directory.
90  */
91 - (UniqueAotDataPtr)loadAOTData:(NSString*)assetsDir;
92 
93 @end
94 
95 #pragma mark -
96 
97 /**
98  * `FlutterPluginRegistrar` implementation handling a single plugin.
99  */
100 @interface FlutterEngineRegistrar : NSObject <FlutterPluginRegistrar>
101 - (instancetype)initWithPlugin:(nonnull NSString*)pluginKey
102  flutterEngine:(nonnull FlutterEngine*)flutterEngine;
103 @end
104 
105 @implementation FlutterEngineRegistrar {
106  NSString* _pluginKey;
108 }
109 
110 - (instancetype)initWithPlugin:(NSString*)pluginKey flutterEngine:(FlutterEngine*)flutterEngine {
111  self = [super init];
112  if (self) {
113  _pluginKey = [pluginKey copy];
114  _flutterEngine = flutterEngine;
115  }
116  return self;
117 }
118 
119 #pragma mark - FlutterPluginRegistrar
120 
121 - (id<FlutterBinaryMessenger>)messenger {
123 }
124 
125 - (id<FlutterTextureRegistry>)textures {
126  return _flutterEngine;
127 }
128 
129 - (NSView*)view {
130  return _flutterEngine.viewController.view;
131 }
132 
133 - (void)addMethodCallDelegate:(nonnull id<FlutterPlugin>)delegate
134  channel:(nonnull FlutterMethodChannel*)channel {
135  [channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
136  [delegate handleMethodCall:call result:result];
137  }];
138 }
139 
140 @end
141 
142 // Callbacks provided to the engine. See the called methods for documentation.
143 #pragma mark - Static methods provided to engine configuration
144 
146  return [engine engineCallbackOnMakeCurrent];
147 }
148 
150  return [engine engineCallbackOnClearCurrent];
151 }
152 
154  return [engine engineCallbackOnPresent];
155 }
156 
157 static uint32_t OnFBO(FlutterEngine* engine) {
158  // There is currently no case where a different FBO is used, so no need to forward.
159  return 0;
160 }
161 
163  return [engine engineCallbackOnMakeResourceCurrent];
164 }
165 
167  [engine engineCallbackOnPlatformMessage:message];
168 }
169 
171  int64_t texture_identifier,
172  size_t width,
173  size_t height,
174  FlutterOpenGLTexture* open_gl_texture) {
175  return [engine populateTextureWithIdentifier:texture_identifier openGLTexture:open_gl_texture];
176 }
177 
178 #pragma mark -
179 
180 @implementation FlutterEngine {
181  // The embedding-API-level engine object.
183 
184  // The project being run by this engine.
186 
187  // The context provided to the Flutter engine for resource loading.
188  NSOpenGLContext* _resourceContext;
189 
190  // The context that is owned by the currently displayed FlutterView. This is stashed in the engine
191  // so that the view doesn't need to be accessed from a background thread.
192  NSOpenGLContext* _mainOpenGLContext;
193 
194  // A mapping of channel names to the registered handlers for those channels.
195  NSMutableDictionary<NSString*, FlutterBinaryMessageHandler>* _messageHandlers;
196 
197  // Whether the engine can continue running after the view controller is removed.
199 
200  // A mapping of textureID to internal FlutterExternalTextureGL adapter.
201  NSMutableDictionary<NSNumber*, FlutterExternalTextureGL*>* _textures;
202 
203  // Pointer to the Dart AOT snapshot and instruction data.
205 }
206 
207 - (instancetype)initWithName:(NSString*)labelPrefix project:(FlutterDartProject*)project {
208  return [self initWithName:labelPrefix project:project allowHeadlessExecution:YES];
209 }
210 
211 - (instancetype)initWithName:(NSString*)labelPrefix
212  project:(FlutterDartProject*)project
213  allowHeadlessExecution:(BOOL)allowHeadlessExecution {
214  self = [super init];
215  NSAssert(self, @"Super init cannot be nil");
216 
217  _project = project ?: [[FlutterDartProject alloc] init];
218  _messageHandlers = [[NSMutableDictionary alloc] init];
219  _textures = [[NSMutableDictionary alloc] init];
220  _allowHeadlessExecution = allowHeadlessExecution;
221 
222  NSNotificationCenter* notificationCenter = [NSNotificationCenter defaultCenter];
223  [notificationCenter addObserver:self
224  selector:@selector(sendUserLocales)
225  name:NSCurrentLocaleDidChangeNotification
226  object:nil];
227 
228  return self;
229 }
230 
231 - (void)dealloc {
232  [self shutDownEngine];
233 }
234 
235 - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
236  if (self.running) {
237  return NO;
238  }
239 
241  NSLog(@"Attempted to run an engine with no view controller without headless mode enabled.");
242  return NO;
243  }
244 
245  const FlutterRendererConfig rendererConfig = {
246  .type = kOpenGL,
247  .open_gl.struct_size = sizeof(FlutterOpenGLRendererConfig),
248  .open_gl.make_current = (BoolCallback)OnMakeCurrent,
249  .open_gl.clear_current = (BoolCallback)OnClearCurrent,
250  .open_gl.present = (BoolCallback)OnPresent,
251  .open_gl.fbo_callback = (UIntCallback)OnFBO,
252  .open_gl.make_resource_current = (BoolCallback)OnMakeResourceCurrent,
253  .open_gl.gl_external_texture_frame_callback = (TextureFrameCallback)OnAcquireExternalTexture,
254  };
255 
256  // TODO(stuartmorgan): Move internal channel registration from FlutterViewController to here.
257 
258  // FlutterProjectArgs is expecting a full argv, so when processing it for
259  // flags the first item is treated as the executable and ignored. Add a dummy
260  // value so that all provided arguments are used.
261  std::vector<std::string> switches = _project.switches;
262  std::vector<const char*> argv = {"placeholder"};
263  std::transform(switches.begin(), switches.end(), std::back_inserter(argv),
264  [](const std::string& arg) -> const char* { return arg.c_str(); });
265 
266  std::vector<const char*> dartEntrypointArgs;
267  for (NSString* argument in [_project dartEntrypointArguments]) {
268  dartEntrypointArgs.push_back([argument UTF8String]);
269  }
270 
271  FlutterProjectArgs flutterArguments = {};
272  flutterArguments.struct_size = sizeof(FlutterProjectArgs);
273  flutterArguments.assets_path = _project.assetsPath.UTF8String;
274  flutterArguments.icu_data_path = _project.ICUDataPath.UTF8String;
275  flutterArguments.command_line_argc = static_cast<int>(argv.size());
276  flutterArguments.command_line_argv = argv.size() > 0 ? argv.data() : nullptr;
278  flutterArguments.custom_dart_entrypoint = entrypoint.UTF8String;
279  flutterArguments.shutdown_dart_vm_when_done = true;
280  flutterArguments.dart_entrypoint_argc = dartEntrypointArgs.size();
281  flutterArguments.dart_entrypoint_argv = dartEntrypointArgs.data();
282 
283  static size_t sTaskRunnerIdentifiers = 0;
284  const FlutterTaskRunnerDescription cocoa_task_runner_description = {
286  .user_data = (void*)CFBridgingRetain(self),
287  .runs_task_on_current_thread_callback = [](void* user_data) -> bool {
288  return [[NSThread currentThread] isMainThread];
289  },
290  .post_task_callback = [](FlutterTask task, uint64_t target_time_nanos,
291  void* user_data) -> void {
292  [((__bridge FlutterEngine*)(user_data)) postMainThreadTask:task
293  targetTimeInNanoseconds:target_time_nanos];
294  },
295  .identifier = ++sTaskRunnerIdentifiers,
296  };
297  const FlutterCustomTaskRunners custom_task_runners = {
299  .platform_task_runner = &cocoa_task_runner_description,
300  .render_task_runner = &cocoa_task_runner_description,
301  };
302  flutterArguments.custom_task_runners = &custom_task_runners;
303 
304  _aotData = [self loadAOTData:_project.assetsPath];
305  if (_aotData) {
306  flutterArguments.aot_data = _aotData.get();
307  }
308 
310  FLUTTER_ENGINE_VERSION, &rendererConfig, &flutterArguments, (__bridge void*)(self), &_engine);
311  if (result != kSuccess) {
312  NSLog(@"Failed to initialize Flutter engine: error %d", result);
313  return NO;
314  }
315 
317  if (result != kSuccess) {
318  NSLog(@"Failed to run an initialized engine: error %d", result);
319  return NO;
320  }
321 
322  [self sendUserLocales];
323  [self updateWindowMetrics];
324  [self updateDisplayConfig];
325  return YES;
326 }
327 
328 - (UniqueAotDataPtr)loadAOTData:(NSString*)assetsDir {
330  return nullptr;
331  }
332 
333  BOOL isDirOut = false; // required for NSFileManager fileExistsAtPath.
334  NSFileManager* fileManager = [NSFileManager defaultManager];
335 
336  // This is the location where the test fixture places the snapshot file.
337  // For applications built by Flutter tool, this is in "App.framework".
338  NSString* elfPath = [NSString pathWithComponents:@[ assetsDir, @"app_elf_snapshot.so" ]];
339 
340  if (![fileManager fileExistsAtPath:elfPath isDirectory:&isDirOut]) {
341  return nullptr;
342  }
343 
344  FlutterEngineAOTDataSource source = {};
346  source.elf_path = [elfPath cStringUsingEncoding:NSUTF8StringEncoding];
347 
348  FlutterEngineAOTData data = nullptr;
349  auto result = FlutterEngineCreateAOTData(&source, &data);
350  if (result != kSuccess) {
351  NSLog(@"Failed to load AOT data from: %@", elfPath);
352  return nullptr;
353  }
354 
355  return UniqueAotDataPtr(data);
356 }
357 
358 - (void)setViewController:(FlutterViewController*)controller {
359  _viewController = controller;
360  _mainOpenGLContext = controller.flutterView.openGLContext;
361  if (!controller && !_allowHeadlessExecution) {
362  [self shutDownEngine];
363  _resourceContext = nil;
364  }
365  [self updateWindowMetrics];
366 }
367 
368 - (id<FlutterBinaryMessenger>)binaryMessenger {
369  // TODO(stuartmorgan): Switch to FlutterBinaryMessengerRelay to avoid plugins
370  // keeping the engine alive.
371  return self;
372 }
373 
374 #pragma mark - Framework-internal methods
375 
376 - (BOOL)running {
377  return _engine != nullptr;
378 }
379 
380 - (NSOpenGLContext*)resourceContext {
381  if (!_resourceContext) {
382  NSOpenGLPixelFormatAttribute attributes[] = {
383  NSOpenGLPFAColorSize, 24, NSOpenGLPFAAlphaSize, 8, NSOpenGLPFADoubleBuffer, 0,
384  };
385  NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
386  _resourceContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
387  }
388  return _resourceContext;
389 }
390 
391 - (void)updateDisplayConfig {
392  if (!_engine) {
393  return;
394  }
395 
396  CVDisplayLinkRef displayLinkRef;
397  CGDirectDisplayID mainDisplayID = CGMainDisplayID();
398  CVDisplayLinkCreateWithCGDisplay(mainDisplayID, &displayLinkRef);
399  CVTime nominal = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(displayLinkRef);
400  if (!(nominal.flags & kCVTimeIsIndefinite)) {
401  double refreshRate = static_cast<double>(nominal.timeScale) / nominal.timeValue;
402 
403  FlutterEngineDisplay display;
404  display.struct_size = sizeof(display);
405  display.display_id = mainDisplayID;
406  display.refresh_rate = round(refreshRate);
407 
408  std::vector<FlutterEngineDisplay> displays = {display};
410  displays.data(), displays.size());
411  }
412 
413  CVDisplayLinkRelease(displayLinkRef);
414 }
415 
416 - (void)updateWindowMetrics {
417  if (!_engine) {
418  return;
419  }
420  NSView* view = _viewController.view;
421  CGSize scaledSize = [view convertRectToBacking:view.bounds].size;
422  double pixelRatio = view.bounds.size.width == 0 ? 1 : scaledSize.width / view.bounds.size.width;
423 
424  const FlutterWindowMetricsEvent event = {
425  .struct_size = sizeof(event),
426  .width = static_cast<size_t>(scaledSize.width),
427  .height = static_cast<size_t>(scaledSize.height),
428  .pixel_ratio = pixelRatio,
429  };
431 }
432 
433 - (void)sendPointerEvent:(const FlutterPointerEvent&)event {
435 }
436 
437 #pragma mark - Private methods
438 
439 - (void)sendUserLocales {
440  if (!self.running) {
441  return;
442  }
443 
444  // Create a list of FlutterLocales corresponding to the preferred languages.
445  NSMutableArray<NSLocale*>* locales = [NSMutableArray array];
446  std::vector<FlutterLocale> flutterLocales;
447  flutterLocales.reserve(locales.count);
448  for (NSString* localeID in [NSLocale preferredLanguages]) {
449  NSLocale* locale = [[NSLocale alloc] initWithLocaleIdentifier:localeID];
450  [locales addObject:locale];
451  flutterLocales.push_back(FlutterLocaleFromNSLocale(locale));
452  }
453  // Convert to a list of pointers, and send to the engine.
454  std::vector<const FlutterLocale*> flutterLocaleList;
455  flutterLocaleList.reserve(flutterLocales.size());
457  flutterLocales.begin(), flutterLocales.end(), std::back_inserter(flutterLocaleList),
458  [](const auto& arg) -> const auto* { return &arg; });
459  FlutterEngineUpdateLocales(_engine, flutterLocaleList.data(), flutterLocaleList.size());
460 }
461 
462 - (bool)engineCallbackOnMakeCurrent {
463  if (!_mainOpenGLContext) {
464  return false;
465  }
466  [_mainOpenGLContext makeCurrentContext];
467  return true;
468 }
469 
470 - (bool)engineCallbackOnClearCurrent {
471  [NSOpenGLContext clearCurrentContext];
472  return true;
473 }
474 
475 - (bool)engineCallbackOnPresent {
476  if (!_mainOpenGLContext) {
477  return false;
478  }
479  [_mainOpenGLContext flushBuffer];
480  return true;
481 }
482 
483 - (bool)engineCallbackOnMakeResourceCurrent {
484  [self.resourceContext makeCurrentContext];
485  return true;
486 }
487 
488 - (void)engineCallbackOnPlatformMessage:(const FlutterPlatformMessage*)message {
489  NSData* messageData = [NSData dataWithBytesNoCopy:(void*)message->message
490  length:message->message_size
491  freeWhenDone:NO];
492  NSString* channel = @(message->channel);
493  __block const FlutterPlatformMessageResponseHandle* responseHandle = message->response_handle;
494 
495  FlutterBinaryReply binaryResponseHandler = ^(NSData* response) {
496  if (responseHandle) {
497  FlutterEngineSendPlatformMessageResponse(self->_engine, responseHandle,
498  static_cast<const uint8_t*>(response.bytes),
499  response.length);
500  responseHandle = NULL;
501  } else {
502  NSLog(@"Error: Message responses can be sent only once. Ignoring duplicate response "
503  "on channel '%@'.",
504  channel);
505  }
506  };
507 
508  FlutterBinaryMessageHandler channelHandler = _messageHandlers[channel];
509  if (channelHandler) {
510  channelHandler(messageData, binaryResponseHandler);
511  } else {
512  binaryResponseHandler(nil);
513  }
514 }
515 
516 /**
517  * Note: Called from dealloc. Should not use accessors or other methods.
518  */
519 - (void)shutDownEngine {
520  if (_engine == nullptr) {
521  return;
522  }
523 
525  if (result != kSuccess) {
526  NSLog(@"Could not de-initialize the Flutter engine: error %d", result);
527  }
528 
529  // Balancing release for the retain in the task runner dispatch table.
530  CFRelease((CFTypeRef)self);
531 
532  result = FlutterEngineShutdown(_engine);
533  if (result != kSuccess) {
534  NSLog(@"Failed to shut down Flutter engine: error %d", result);
535  }
536  _engine = nullptr;
537 }
538 
539 #pragma mark - FlutterBinaryMessenger
540 
541 - (void)sendOnChannel:(nonnull NSString*)channel message:(nullable NSData*)message {
542  [self sendOnChannel:channel message:message binaryReply:nil];
543 }
544 
545 - (void)sendOnChannel:(NSString*)channel
546  message:(NSData* _Nullable)message
547  binaryReply:(FlutterBinaryReply _Nullable)callback {
548  FlutterPlatformMessageResponseHandle* response_handle = nullptr;
549  if (callback) {
550  struct Captures {
551  FlutterBinaryReply reply;
552  };
553  auto captures = std::make_unique<Captures>();
554  captures->reply = callback;
555  auto message_reply = [](const uint8_t* data, size_t data_size, void* user_data) {
556  auto captures = reinterpret_cast<Captures*>(user_data);
557  NSData* reply_data = nil;
558  if (data != nullptr && data_size > 0) {
559  reply_data = [NSData dataWithBytes:static_cast<const void*>(data) length:data_size];
560  }
561  captures->reply(reply_data);
562  delete captures;
563  };
564 
566  _engine, message_reply, captures.get(), &response_handle);
567  if (create_result != kSuccess) {
568  NSLog(@"Failed to create a FlutterPlatformMessageResponseHandle (%d)", create_result);
569  return;
570  }
571  captures.release();
572  }
573 
574  FlutterPlatformMessage platformMessage = {
576  .channel = [channel UTF8String],
577  .message = static_cast<const uint8_t*>(message.bytes),
578  .message_size = message.length,
579  .response_handle = response_handle,
580  };
581 
582  FlutterEngineResult message_result = FlutterEngineSendPlatformMessage(_engine, &platformMessage);
583  if (message_result != kSuccess) {
584  NSLog(@"Failed to send message to Flutter engine on channel '%@' (%d).", channel,
585  message_result);
586  }
587 
588  if (response_handle != nullptr) {
589  FlutterEngineResult release_result =
591  if (release_result != kSuccess) {
592  NSLog(@"Failed to release the response handle (%d).", release_result);
593  };
594  }
595 }
596 
597 - (FlutterBinaryMessengerConnection)setMessageHandlerOnChannel:(nonnull NSString*)channel
598  binaryMessageHandler:
599  (nullable FlutterBinaryMessageHandler)handler {
600  _messageHandlers[channel] = [handler copy];
601  return 0;
602 }
603 
604 - (void)cleanupConnection:(FlutterBinaryMessengerConnection)connection {
605  // There hasn't been a need to implement this yet for macOS.
606 }
607 
608 #pragma mark - FlutterPluginRegistry
609 
610 - (id<FlutterPluginRegistrar>)registrarForPlugin:(NSString*)pluginName {
611  return [[FlutterEngineRegistrar alloc] initWithPlugin:pluginName flutterEngine:self];
612 }
613 
614 #pragma mark - FlutterTextureRegistrar
615 
616 - (BOOL)populateTextureWithIdentifier:(int64_t)textureID
617  openGLTexture:(FlutterOpenGLTexture*)openGLTexture {
618  return [_textures[@(textureID)] populateTexture:openGLTexture];
619 }
620 
621 - (int64_t)registerTexture:(id<FlutterTexture>)texture {
622  FlutterExternalTextureGL* FlutterTexture =
623  [[FlutterExternalTextureGL alloc] initWithFlutterTexture:texture];
624  int64_t textureID = [FlutterTexture textureID];
626  _textures[@(textureID)] = FlutterTexture;
627  return textureID;
628 }
629 
630 - (void)textureFrameAvailable:(int64_t)textureID {
632 }
633 
634 - (void)unregisterTexture:(int64_t)textureID {
636  [_textures removeObjectForKey:@(textureID)];
637 }
638 
639 #pragma mark - Task runner integration
640 
641 - (void)postMainThreadTask:(FlutterTask)task targetTimeInNanoseconds:(uint64_t)targetTime {
642  const auto engine_time = FlutterEngineGetCurrentTime();
643 
644  __weak FlutterEngine* weak_self = self;
645  auto worker = ^{
646  FlutterEngine* strong_self = weak_self;
647  if (strong_self && strong_self->_engine) {
648  auto result = FlutterEngineRunTask(strong_self->_engine, &task);
649  if (result != kSuccess) {
650  NSLog(@"Could not post a task to the Flutter engine.");
651  }
652  }
653  };
654 
655  if (targetTime <= engine_time) {
656  dispatch_async(dispatch_get_main_queue(), worker);
657 
658  } else {
659  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, targetTime - engine_time),
660  dispatch_get_main_queue(), worker);
661  }
662 }
663 
664 @end
FlutterEngineResult FlutterEngineNotifyDisplayUpdate(FLUTTER_API_SYMBOL(FlutterEngine) raw_engine, const FlutterEngineDisplaysUpdateType update_type, const FlutterEngineDisplay *embedder_displays, size_t display_count)
Posts updates corresponding to display changes to a running engine instance.
Definition: embedder.cc:2011
size_t struct_size
This size of this struct. Must be sizeof(FlutterLocale).
Definition: embedder.h:940
static void OnPlatformMessage(const FlutterPlatformMessage *message, FlutterEngine *engine)
bool(* BoolCallback)(void *)
Definition: embedder.h:294
struct _FlutterEngine * FLUTTER_API_SYMBOL(FlutterEngine)
Definition: embedder.h:220
BOOL _allowHeadlessExecution
UniqueAotDataPtr _aotData
FLUTTER_EXPORT FlutterEngineResult FlutterEngineDeinitialize(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Stops running the Flutter engine instance. After this call, the embedder is also guaranteed that no m...
Definition: embedder.cc:1205
FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterPlatformMessageResponseHandle *response)
Collects the handle created using FlutterPlatformMessageCreateResponseHandle.
Definition: embedder.cc:1482
NSObject< FlutterBinaryMessenger > * binaryMessenger
FlutterEngineResult FlutterEngineRunTask(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterTask *task)
Inform the engine to run the specified task. This task has been given to the engine via the FlutterTa...
Definition: embedder.cc:1716
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)
const char * icu_data_path
Definition: embedder.h:1195
size_t struct_size
The size of this struct. Must be sizeof(FlutterTaskRunnerDescription).
Definition: embedder.h:718
FlutterEngineResult FlutterEngineSendPlatformMessageResponse(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
Send a response from the native side to a platform message from the Dart Flutter application.
Definition: embedder.cc:1496
const FlutterCustomTaskRunners * custom_task_runners
Definition: embedder.h:1309
static uint32_t OnFBO(FlutterEngine *engine)
static FlutterLocale FlutterLocaleFromNSLocale(NSLocale *locale)
bool(* TextureFrameCallback)(void *, int64_t, size_t, size_t, FlutterOpenGLTexture *)
Definition: embedder.h:302
FlutterEngineResult FlutterEngineShutdown(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Shuts down a Flutter engine instance. The engine handle is no longer valid for any calls in the embed...
Definition: embedder.cc:1217
const char * variant_code
Definition: embedder.h:959
static bool OnPresent(FlutterEngine *engine)
FlutterEngineResult FlutterEngineMarkExternalTextureFrameAvailable(FLUTTER_API_SYMBOL(FlutterEngine) engine, int64_t texture_identifier)
Mark that a new texture frame is available for a given texture identifier.
Definition: embedder.cc:1568
size_t struct_size
This size of this struct. Must be sizeof(FlutterDisplay).
Definition: embedder.h:973
FlutterPlatformMessageCallback platform_message_callback
Definition: embedder.h:1218
const char *const * command_line_argv
Definition: embedder.h:1213
const char * script_code
Definition: embedder.h:954
const char * country_code
Definition: embedder.h:949
bool shutdown_dart_vm_when_done
Definition: embedder.h:1328
const char *const * dart_entrypoint_argv
Definition: embedder.h:1382
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
static bool OnMakeResourceCurrent(FlutterEngine *engine)
fml::scoped_nsobject< FlutterEngine > _engine
void(* FlutterPlatformMessageCallback)(const FlutterPlatformMessage *, void *)
Definition: embedder.h:575
#define FLUTTER_ENGINE_VERSION
Definition: embedder.h:63
FlutterRendererType type
Definition: embedder.h:448
FlutterDartProject * _project
FlutterEngineResult FlutterEngineCollectAOTData(FlutterEngineAOTData data)
Collects the AOT data.
Definition: embedder.cc:651
NSOpenGLContext * _resourceContext
static bool OnMakeCurrent(FlutterEngine *engine)
NSMutableDictionary< NSString *, FlutterBinaryMessageHandler > * _messageHandlers
FlutterEngineResult FlutterEngineUpdateLocales(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterLocale **locales, size_t locales_count)
Notify a running engine instance that the locale has been updated. The preferred locale must be the f...
Definition: embedder.cc:1760
NSMutableDictionary< NSNumber *, FlutterExternalTextureGL * > * _textures
int32_t height
int32_t width
FlutterEngineResult FlutterEngineRegisterExternalTexture(FLUTTER_API_SYMBOL(FlutterEngine) engine, int64_t texture_identifier)
Register an external texture with a unique (per engine) identifier. Only rendering backends that supp...
Definition: embedder.cc:1528
static bool OnAcquireExternalTexture(FlutterEngine *engine, int64_t texture_identifier, size_t width, size_t height, FlutterOpenGLTexture *open_gl_texture)
size_t struct_size
The size of this struct. Must be sizeof(FlutterWindowMetricsEvent).
Definition: embedder.h:457
G_BEGIN_DECLS FlMethodCall gpointer user_data
GdkEventButton * event
Definition: fl_view.cc:62
FlutterEngineResult FlutterEngineInitialize(size_t version, const FlutterRendererConfig *config, const FlutterProjectArgs *args, void *user_data, FLUTTER_API_SYMBOL(FlutterEngine) *engine_out)
Initialize a Flutter engine instance. This does not run the Flutter application code till the Flutter...
Definition: embedder.cc:733
const char * custom_dart_entrypoint
Definition: embedder.h:1304
const char * assets_path
Definition: embedder.h:1171
uint32_t(* UIntCallback)(void *)
Definition: embedder.h:296
static bool OnClearCurrent(FlutterEngine *engine)
FlutterEngineResult
Definition: embedder.h:65
size_t struct_size
The size of this struct. Must be sizeof(FlutterProjectArgs).
Definition: embedder.h:1167
fml::WeakPtr< FlutterViewController > _viewController
std::vector< std::string > switches
FlutterEngineResult FlutterEngineUnregisterExternalTexture(FLUTTER_API_SYMBOL(FlutterEngine) engine, int64_t texture_identifier)
Unregister a previous texture registration.
Definition: embedder.cc:1547
FlutterEngineAOTDataSourceType type
Definition: embedder.h:1122
FlutterEngineResult FlutterEngineSendPointerEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPointerEvent *pointers, size_t events_count)
Definition: embedder.cc:1322
FlutterEngineAOTData aot_data
Definition: embedder.h:1359
size_t struct_size
The size of this struct. Must be sizeof(FlutterCustomTaskRunners).
Definition: embedder.h:743
size_t struct_size
The size of this struct. Must be sizeof(FlutterPlatformMessage).
Definition: embedder.h:562
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterWindowMetricsEvent *flutter_metrics)
Definition: embedder.cc:1228
int64_t FlutterBinaryMessengerConnection
const char * language_code
Definition: embedder.h:944
FlutterEngineResult FlutterEngineRunInitialized(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Runs an initialized engine instance. An engine can be initialized via FlutterEngineInitialize. An initialized instance can only be run once. During and after this call, custom task runners supplied by the embedder are expected to start servicing tasks.
Definition: embedder.cc:1166
bool FlutterEngineRunsAOTCompiledDartCode(void)
Returns if the Flutter engine instance will run AOT compiled Dart code. This call has no threading re...
Definition: embedder.cc:1820
int command_line_argc
The command line argument count used to initialize the project.
Definition: embedder.h:1197
uint64_t FlutterEngineGetCurrentTime()
Get the current time in nanoseconds from the clock used by the flutter engine. This is the system mon...
Definition: embedder.cc:1712
const char * elf_path
Absolute path to an ELF library file.
Definition: embedder.h:1125
std::unique_ptr< _FlutterEngineAOTData, AOTDataDeleter > UniqueAotDataPtr
FlutterEngineResult FlutterEngineSendPlatformMessage(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessage *flutter_message)
Definition: embedder.cc:1395
FlutterViewController * viewController
FlutterEngineResult FlutterPlatformMessageCreateResponseHandle(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterDataCallback data_callback, void *user_data, FlutterPlatformMessageResponseHandle **response_out)
Creates a platform message response handle that allows the embedder to set a native callback for a re...
Definition: embedder.cc:1447
FlutterEngine * flutterEngine
NSOpenGLContext * _mainOpenGLContext
FlutterEngine * _flutterEngine
FlutterEngineResult FlutterEngineCreateAOTData(const FlutterEngineAOTDataSource *source, FlutterEngineAOTData *data_out)
Creates the necessary data structures to launch a Flutter Dart application in AOT mode...
Definition: embedder.cc:597