Flutter Engine
fl_engine.cc
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 #include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"
6 
7 #include <gmodule.h>
8 
9 #include <cstring>
10 
11 #include "flutter/shell/platform/linux/fl_binary_messenger_private.h"
12 #include "flutter/shell/platform/linux/fl_dart_project_private.h"
13 #include "flutter/shell/platform/linux/fl_engine_private.h"
14 #include "flutter/shell/platform/linux/fl_plugin_registrar_private.h"
15 #include "flutter/shell/platform/linux/fl_renderer.h"
16 #include "flutter/shell/platform/linux/fl_renderer_headless.h"
17 #include "flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registry.h"
18 
19 static constexpr int kMicrosecondsPerNanosecond = 1000;
20 
21 // Unique number associated with platform tasks.
22 static constexpr size_t kPlatformTaskRunnerIdentifier = 1;
23 
24 struct _FlEngine {
25  GObject parent_instance;
26 
27  // Thread the GLib main loop is running on.
28  GThread* thread;
29 
30  FlDartProject* project;
31  FlRenderer* renderer;
32  FlBinaryMessenger* binary_messenger;
35 
36  // Function to call when a platform message is received.
40 };
41 
42 G_DEFINE_QUARK(fl_engine_error_quark, fl_engine_error)
43 
45  FlPluginRegistryInterface* iface);
46 
48  FlEngine,
49  fl_engine,
50  G_TYPE_OBJECT,
51  G_IMPLEMENT_INTERFACE(fl_plugin_registry_get_type(),
53 
54 // Subclass of GSource that integrates Flutter tasks into the GLib main loop.
55 typedef struct {
56  GSource parent;
57  FlEngine* engine;
58  FlutterTask task;
60 
61 // Parse a locale into its components.
62 static void parse_locale(const gchar* locale,
63  gchar** language,
64  gchar** territory,
65  gchar** codeset,
66  gchar** modifier) {
67  gchar* l = g_strdup(locale);
68 
69  // Locales are in the form "language[_territory][.codeset][@modifier]"
70  gchar* match = strrchr(l, '@');
71  if (match != nullptr) {
72  *modifier = g_strdup(match + 1);
73  *match = '\0';
74  } else {
75  *modifier = nullptr;
76  }
77 
78  match = strrchr(l, '.');
79  if (match != nullptr) {
80  *codeset = g_strdup(match + 1);
81  *match = '\0';
82  } else {
83  *codeset = nullptr;
84  }
85 
86  match = strrchr(l, '_');
87  if (match != nullptr) {
88  *territory = g_strdup(match + 1);
89  *match = '\0';
90  } else {
91  *territory = nullptr;
92  }
93 
94  *language = l;
95 }
96 
97 // Passes locale information to the Flutter engine.
98 static void setup_locales(FlEngine* self) {
99  const gchar* const* languages = g_get_language_names();
100  g_autoptr(GPtrArray) locales_array = g_ptr_array_new_with_free_func(g_free);
101  // Helper array to take ownership of the strings passed to Flutter.
102  g_autoptr(GPtrArray) locale_strings = g_ptr_array_new_with_free_func(g_free);
103  for (int i = 0; languages[i] != nullptr; i++) {
104  gchar *language, *territory, *codeset, *modifier;
105  parse_locale(languages[i], &language, &territory, &codeset, &modifier);
106  if (language != nullptr) {
107  g_ptr_array_add(locale_strings, language);
108  }
109  if (territory != nullptr) {
110  g_ptr_array_add(locale_strings, territory);
111  }
112  if (codeset != nullptr) {
113  g_ptr_array_add(locale_strings, codeset);
114  }
115  if (modifier != nullptr) {
116  g_ptr_array_add(locale_strings, modifier);
117  }
118 
119  FlutterLocale* locale =
120  static_cast<FlutterLocale*>(g_malloc0(sizeof(FlutterLocale)));
121  g_ptr_array_add(locales_array, locale);
122  locale->struct_size = sizeof(FlutterLocale);
123  locale->language_code = language;
124  locale->country_code = territory;
125  locale->script_code = codeset;
126  locale->variant_code = modifier;
127  }
128  FlutterLocale** locales =
129  reinterpret_cast<FlutterLocale**>(locales_array->pdata);
131  self->engine, const_cast<const FlutterLocale**>(locales),
132  locales_array->len);
133  if (result != kSuccess) {
134  g_warning("Failed to set up Flutter locales");
135  }
136 }
137 
138 // Callback to run a Flutter task in the GLib main loop.
139 static gboolean flutter_source_dispatch(GSource* source,
140  GSourceFunc callback,
141  gpointer user_data) {
142  FlutterSource* fl_source = reinterpret_cast<FlutterSource*>(source);
143  FlEngine* self = fl_source->engine;
144 
145  FlutterEngineResult result =
146  FlutterEngineRunTask(self->engine, &fl_source->task);
147  if (result != kSuccess) {
148  g_warning("Failed to run Flutter task\n");
149  }
150 
151  return G_SOURCE_REMOVE;
152 }
153 
154 // Called when the engine is disposed.
155 static void engine_weak_notify_cb(gpointer user_data,
156  GObject* where_the_object_was) {
157  FlutterSource* source = reinterpret_cast<FlutterSource*>(user_data);
158  source->engine = nullptr;
159  g_source_destroy(reinterpret_cast<GSource*>(source));
160 }
161 
162 // Called when a flutter source completes.
163 static void flutter_source_finalize(GSource* source) {
164  FlutterSource* fl_source = reinterpret_cast<FlutterSource*>(source);
165  if (fl_source->engine != nullptr) {
166  g_object_weak_unref(G_OBJECT(fl_source->engine), engine_weak_notify_cb,
167  fl_source);
168  fl_source->engine = nullptr;
169  }
170 }
171 
172 // Table of functions for Flutter GLib main loop integration.
173 static GSourceFuncs flutter_source_funcs = {
174  nullptr, // prepare
175  nullptr, // check
176  flutter_source_dispatch, // dispatch
177  flutter_source_finalize, // finalize
178  nullptr,
179  nullptr // Internal usage
180 };
181 
182 // Flutter engine rendering callbacks.
183 
184 static void* fl_engine_gl_proc_resolver(void* user_data, const char* name) {
185  FlEngine* self = static_cast<FlEngine*>(user_data);
186  return fl_renderer_get_proc_address(self->renderer, name);
187 }
188 
190  FlEngine* self = static_cast<FlEngine*>(user_data);
191  g_autoptr(GError) error = nullptr;
192  gboolean result = fl_renderer_make_current(self->renderer, &error);
193  if (!result) {
194  g_warning("%s", error->message);
195  }
196  return result;
197 }
198 
200  FlEngine* self = static_cast<FlEngine*>(user_data);
201  g_autoptr(GError) error = nullptr;
202  gboolean result = fl_renderer_clear_current(self->renderer, &error);
203  if (!result) {
204  g_warning("%s", error->message);
205  }
206  return result;
207 }
208 
209 static uint32_t fl_engine_gl_get_fbo(void* user_data) {
210  FlEngine* self = static_cast<FlEngine*>(user_data);
211  return fl_renderer_get_fbo(self->renderer);
212 }
213 
214 static bool fl_engine_gl_present(void* user_data) {
215  FlEngine* self = static_cast<FlEngine*>(user_data);
216  g_autoptr(GError) error = nullptr;
217  gboolean result = fl_renderer_present(self->renderer, &error);
218  if (!result) {
219  g_warning("%s", error->message);
220  }
221  return result;
222 }
223 
225  FlEngine* self = static_cast<FlEngine*>(user_data);
226  g_autoptr(GError) error = nullptr;
227  gboolean result = fl_renderer_make_resource_current(self->renderer, &error);
228  if (!result) {
229  g_warning("%s", error->message);
230  }
231  return result;
232 }
233 
234 // Called by the engine to determine if it is on the GTK thread.
236  FlEngine* self = static_cast<FlEngine*>(user_data);
237  return self->thread == g_thread_self();
238 }
239 
240 // Called when the engine has a task to perform in the GTK thread.
242  uint64_t target_time_nanos,
243  void* user_data) {
244  FlEngine* self = static_cast<FlEngine*>(user_data);
245 
246  g_autoptr(GSource) source =
247  g_source_new(&flutter_source_funcs, sizeof(FlutterSource));
248  FlutterSource* fl_source = reinterpret_cast<FlutterSource*>(source);
249  fl_source->engine = self;
250  g_object_weak_ref(G_OBJECT(self), engine_weak_notify_cb, fl_source);
251  fl_source->task = task;
252  g_source_set_ready_time(source,
253  target_time_nanos / kMicrosecondsPerNanosecond);
254  g_source_attach(source, nullptr);
255 }
256 
257 // Called when a platform message is received from the engine.
259  void* user_data) {
260  FlEngine* self = FL_ENGINE(user_data);
261 
262  gboolean handled = FALSE;
263  if (self->platform_message_handler != nullptr) {
264  g_autoptr(GBytes) data =
265  g_bytes_new(message->message, message->message_size);
266  handled = self->platform_message_handler(
267  self, message->channel, data, message->response_handle,
268  self->platform_message_handler_data);
269  }
270 
271  if (!handled) {
273  nullptr, nullptr);
274  }
275 }
276 
277 // Called when a response to a sent platform message is received from the
278 // engine.
279 static void fl_engine_platform_message_response_cb(const uint8_t* data,
280  size_t data_length,
281  void* user_data) {
282  g_autoptr(GTask) task = G_TASK(user_data);
283  g_task_return_pointer(task, g_bytes_new(data, data_length),
284  reinterpret_cast<GDestroyNotify>(g_bytes_unref));
285 }
286 
287 // Implements FlPluginRegistry::get_registrar_for_plugin.
288 static FlPluginRegistrar* fl_engine_get_registrar_for_plugin(
289  FlPluginRegistry* registry,
290  const gchar* name) {
291  FlEngine* self = FL_ENGINE(registry);
292 
293  return fl_plugin_registrar_new(nullptr, self->binary_messenger);
294 }
295 
297  FlPluginRegistryInterface* iface) {
298  iface->get_registrar_for_plugin = fl_engine_get_registrar_for_plugin;
299 }
300 
301 static void fl_engine_dispose(GObject* object) {
302  FlEngine* self = FL_ENGINE(object);
303 
304  if (self->engine != nullptr) {
305  FlutterEngineShutdown(self->engine);
306  self->engine = nullptr;
307  }
308 
309  if (self->aot_data != nullptr) {
310  FlutterEngineCollectAOTData(self->aot_data);
311  self->aot_data = nullptr;
312  }
313 
314  g_clear_object(&self->project);
315  g_clear_object(&self->renderer);
316  g_clear_object(&self->binary_messenger);
317 
318  if (self->platform_message_handler_destroy_notify) {
319  self->platform_message_handler_destroy_notify(
320  self->platform_message_handler_data);
321  }
322  self->platform_message_handler_data = nullptr;
323  self->platform_message_handler_destroy_notify = nullptr;
324 
325  G_OBJECT_CLASS(fl_engine_parent_class)->dispose(object);
326 }
327 
328 static void fl_engine_class_init(FlEngineClass* klass) {
329  G_OBJECT_CLASS(klass)->dispose = fl_engine_dispose;
330 }
331 
332 static void fl_engine_init(FlEngine* self) {
333  self->thread = g_thread_self();
334 
335  self->binary_messenger = fl_binary_messenger_new(self);
336 }
337 
338 FlEngine* fl_engine_new(FlDartProject* project, FlRenderer* renderer) {
339  g_return_val_if_fail(FL_IS_DART_PROJECT(project), nullptr);
340  g_return_val_if_fail(FL_IS_RENDERER(renderer), nullptr);
341 
342  FlEngine* self = FL_ENGINE(g_object_new(fl_engine_get_type(), nullptr));
343  self->project = FL_DART_PROJECT(g_object_ref(project));
344  self->renderer = FL_RENDERER(g_object_ref(renderer));
345  return self;
346 }
347 
348 G_MODULE_EXPORT FlEngine* fl_engine_new_headless(FlDartProject* project) {
349  g_autoptr(FlRendererHeadless) renderer = fl_renderer_headless_new();
350  return fl_engine_new(project, FL_RENDERER(renderer));
351 }
352 
353 gboolean fl_engine_start(FlEngine* self, GError** error) {
354  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
355 
356  FlutterRendererConfig config = {};
357  config.type = kOpenGL;
365 
366  FlutterTaskRunnerDescription platform_task_runner = {};
367  platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription);
368  platform_task_runner.user_data = self;
369  platform_task_runner.runs_task_on_current_thread_callback =
371  platform_task_runner.post_task_callback = fl_engine_post_task;
372  platform_task_runner.identifier = kPlatformTaskRunnerIdentifier;
373 
374  FlutterCustomTaskRunners custom_task_runners = {};
375  custom_task_runners.struct_size = sizeof(FlutterCustomTaskRunners);
376  custom_task_runners.platform_task_runner = &platform_task_runner;
377 
378  g_autoptr(GPtrArray) command_line_args =
379  fl_dart_project_get_switches(self->project);
380  // FlutterProjectArgs expects a full argv, so when processing it for flags
381  // the first item is treated as the executable and ignored. Add a dummy value
382  // so that all switches are used.
383  g_ptr_array_insert(command_line_args, 0, g_strdup("flutter"));
384 
385  gchar** dart_entrypoint_args =
387 
389  args.struct_size = sizeof(FlutterProjectArgs);
390  args.assets_path = fl_dart_project_get_assets_path(self->project);
391  args.icu_data_path = fl_dart_project_get_icu_data_path(self->project);
392  args.command_line_argc = command_line_args->len;
393  args.command_line_argv =
394  reinterpret_cast<const char* const*>(command_line_args->pdata);
396  args.custom_task_runners = &custom_task_runners;
397  args.shutdown_dart_vm_when_done = true;
398  args.dart_entrypoint_argc =
399  dart_entrypoint_args != nullptr ? g_strv_length(dart_entrypoint_args) : 0;
400  args.dart_entrypoint_argv =
401  reinterpret_cast<const char* const*>(dart_entrypoint_args);
402 
404  FlutterEngineAOTDataSource source = {};
406  source.elf_path = fl_dart_project_get_aot_library_path(self->project);
407  if (FlutterEngineCreateAOTData(&source, &self->aot_data) != kSuccess) {
408  g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
409  "Failed to create AOT data");
410  return FALSE;
411  }
412  args.aot_data = self->aot_data;
413  }
414 
416  FLUTTER_ENGINE_VERSION, &config, &args, self, &self->engine);
417  if (result != kSuccess) {
418  g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
419  "Failed to initialize Flutter engine");
420  return FALSE;
421  }
422 
423  result = FlutterEngineRunInitialized(self->engine);
424  if (result != kSuccess) {
425  g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
426  "Failed to run Flutter engine");
427  return FALSE;
428  }
429 
430  setup_locales(self);
431 
432  return TRUE;
433 }
434 
436  FlEngine* self,
438  gpointer user_data,
439  GDestroyNotify destroy_notify) {
440  g_return_if_fail(FL_IS_ENGINE(self));
441  g_return_if_fail(handler != nullptr);
442 
443  if (self->platform_message_handler_destroy_notify) {
444  self->platform_message_handler_destroy_notify(
445  self->platform_message_handler_data);
446  }
447 
448  self->platform_message_handler = handler;
449  self->platform_message_handler_data = user_data;
450  self->platform_message_handler_destroy_notify = destroy_notify;
451 }
452 
454  FlEngine* self,
456  GBytes* response,
457  GError** error) {
458  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
459  g_return_val_if_fail(handle != nullptr, FALSE);
460 
461  if (self->engine == nullptr) {
462  g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
463  "No engine to send response to");
464  return FALSE;
465  }
466 
467  gsize data_length = 0;
468  const uint8_t* data = nullptr;
469  if (response != nullptr) {
470  data =
471  static_cast<const uint8_t*>(g_bytes_get_data(response, &data_length));
472  }
474  self->engine, handle, data, data_length);
475 
476  if (result != kSuccess) {
477  g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
478  "Failed to send platorm message response");
479  return FALSE;
480  }
481 
482  return TRUE;
483 }
484 
486  const gchar* channel,
487  GBytes* message,
488  GCancellable* cancellable,
489  GAsyncReadyCallback callback,
490  gpointer user_data) {
491  g_return_if_fail(FL_IS_ENGINE(self));
492 
493  GTask* task = nullptr;
494  FlutterPlatformMessageResponseHandle* response_handle = nullptr;
495  if (callback != nullptr) {
496  task = g_task_new(self, cancellable, callback, user_data);
497 
498  if (self->engine == nullptr) {
499  g_task_return_new_error(task, fl_engine_error_quark(),
500  FL_ENGINE_ERROR_FAILED, "No engine to send to");
501  return;
502  }
503 
505  self->engine, fl_engine_platform_message_response_cb, task,
506  &response_handle);
507  if (result != kSuccess) {
508  g_task_return_new_error(task, fl_engine_error_quark(),
510  "Failed to create response handle");
511  g_object_unref(task);
512  return;
513  }
514  } else if (self->engine == nullptr) {
515  return;
516  }
517 
518  FlutterPlatformMessage fl_message = {};
519  fl_message.struct_size = sizeof(fl_message);
520  fl_message.channel = channel;
521  fl_message.message =
522  message != nullptr
523  ? static_cast<const uint8_t*>(g_bytes_get_data(message, nullptr))
524  : nullptr;
525  fl_message.message_size = message != nullptr ? g_bytes_get_size(message) : 0;
526  fl_message.response_handle = response_handle;
527  FlutterEngineResult result =
528  FlutterEngineSendPlatformMessage(self->engine, &fl_message);
529 
530  if (result != kSuccess && task != nullptr) {
531  g_task_return_new_error(task, fl_engine_error_quark(),
533  "Failed to send platform messages");
534  g_object_unref(task);
535  }
536 
537  if (response_handle != nullptr) {
538  FlutterPlatformMessageReleaseResponseHandle(self->engine, response_handle);
539  }
540 }
541 
543  GAsyncResult* result,
544  GError** error) {
545  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
546  g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
547 
548  return static_cast<GBytes*>(g_task_propagate_pointer(G_TASK(result), error));
549 }
550 
552  size_t width,
553  size_t height,
554  double pixel_ratio) {
555  g_return_if_fail(FL_IS_ENGINE(self));
556 
557  if (self->engine == nullptr) {
558  return;
559  }
560 
561  FlutterWindowMetricsEvent event = {};
562  event.struct_size = sizeof(FlutterWindowMetricsEvent);
563  event.width = width;
564  event.height = height;
565  event.pixel_ratio = pixel_ratio;
567 }
568 
571  size_t timestamp,
572  double x,
573  double y,
574  double scroll_delta_x,
575  double scroll_delta_y,
576  int64_t buttons) {
577  g_return_if_fail(FL_IS_ENGINE(self));
578 
579  if (self->engine == nullptr) {
580  return;
581  }
582 
583  FlutterPointerEvent fl_event = {};
584  fl_event.struct_size = sizeof(fl_event);
585  fl_event.phase = phase;
586  fl_event.timestamp = timestamp;
587  fl_event.x = x;
588  fl_event.y = y;
589  if (scroll_delta_x != 0 || scroll_delta_y != 0) {
591  }
592  fl_event.scroll_delta_x = scroll_delta_x;
593  fl_event.scroll_delta_y = scroll_delta_y;
595  fl_event.buttons = buttons;
596  FlutterEngineSendPointerEvent(self->engine, &fl_event, 1);
597 }
598 
599 G_MODULE_EXPORT FlBinaryMessenger* fl_engine_get_binary_messenger(
600  FlEngine* self) {
601  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
602  return self->binary_messenger;
603 }
size_t struct_size
This size of this struct. Must be sizeof(FlutterLocale).
Definition: embedder.h:944
static void fl_engine_post_task(FlutterTask task, uint64_t target_time_nanos, void *user_data)
Definition: fl_engine.cc:241
G_BEGIN_DECLS FlValue * args
G_MODULE_EXPORT const gchar * fl_dart_project_get_icu_data_path(FlDartProject *self)
FlDartProject * project
Definition: fl_engine.cc:30
gboolean fl_renderer_make_current(FlRenderer *self, GError **error)
Definition: fl_renderer.cc:216
const char * channel
Definition: embedder.h:567
double scroll_delta_y
The y offset of the scroll in physical pixels.
Definition: embedder.h:549
gboolean fl_renderer_clear_current(FlRenderer *self, GError **error)
Definition: fl_renderer.cc:261
FlPluginRegistrar * fl_plugin_registrar_new(FlView *view, FlBinaryMessenger *messenger)
gboolean(* FlEnginePlatformMessageHandler)(FlEngine *engine, const gchar *channel, GBytes *message, const FlutterPlatformMessageResponseHandle *response_handle, gpointer user_data)
FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterPlatformMessageResponseHandle *response)
Collects the handle created using FlutterPlatformMessageCreateResponseHandle.
Definition: embedder.cc:1483
FlBinaryMessenger * binary_messenger
Definition: fl_engine.cc:32
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:1717
const char * icu_data_path
Definition: embedder.h:1151
static gboolean flutter_source_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
Definition: fl_engine.cc:139
double y
The y coordinate of the pointer event in physical pixels.
Definition: embedder.h:541
FlMethodResponse GError ** error
const FlutterPlatformMessageResponseHandle * response_handle
Definition: embedder.h:576
size_t struct_size
The size of this struct. Must be sizeof(FlutterTaskRunnerDescription).
Definition: embedder.h:722
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:1497
const FlutterCustomTaskRunners * custom_task_runners
Definition: embedder.h:1265
FlEnginePlatformMessageHandler platform_message_handler
Definition: fl_engine.cc:37
FlRendererHeadless * fl_renderer_headless_new()
G_MODULE_EXPORT gchar ** fl_dart_project_get_dart_entrypoint_arguments(FlDartProject *self)
G_MODULE_EXPORT const gchar * fl_dart_project_get_aot_library_path(FlDartProject *self)
FlutterPointerPhase
The phase of the pointer event.
Definition: embedder.h:471
void fl_engine_set_platform_message_handler(FlEngine *self, FlEnginePlatformMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_engine.cc:435
gboolean fl_renderer_make_resource_current(FlRenderer *self, GError **error)
Definition: fl_renderer.cc:238
G_DEFINE_TYPE_WITH_CODE(FlEngine, fl_engine, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(fl_plugin_registry_get_type(), fl_engine_plugin_registry_iface_init)) typedef struct
Definition: fl_engine.cc:47
double scroll_delta_x
The x offset of the scroll in physical pixels.
Definition: embedder.h:547
G_DEFINE_QUARK(fl_binary_messenger_codec_error_quark, fl_binary_messenger_codec_error) struct _FlBinaryMessenger
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:1218
const char * variant_code
Definition: embedder.h:963
GPtrArray * fl_dart_project_get_switches(FlDartProject *self)
static void engine_weak_notify_cb(gpointer user_data, GObject *where_the_object_was)
Definition: fl_engine.cc:155
static bool fl_engine_gl_make_resource_current(void *user_data)
Definition: fl_engine.cc:224
FlutterPlatformMessageCallback platform_message_callback
Definition: embedder.h:1174
static void setup_locales(FlEngine *self)
Definition: fl_engine.cc:98
static void fl_engine_platform_message_cb(const FlutterPlatformMessage *message, void *user_data)
Definition: fl_engine.cc:258
const char *const * command_line_argv
Definition: embedder.h:1169
static bool fl_engine_gl_clear_current(void *user_data)
Definition: fl_engine.cc:199
void * fl_renderer_get_proc_address(FlRenderer *self, const char *name)
Definition: fl_renderer.cc:212
const char * script_code
Definition: embedder.h:958
const char * country_code
Definition: embedder.h:953
bool shutdown_dart_vm_when_done
Definition: embedder.h:1284
const char *const * dart_entrypoint_argv
Definition: embedder.h:1338
FlutterEngineAOTData aot_data
Definition: fl_engine.cc:33
static bool fl_engine_gl_present(void *user_data)
Definition: fl_engine.cc:214
G_BEGIN_DECLS FlValue gpointer user_data
void fl_engine_send_platform_message(FlEngine *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:485
#define FLUTTER_ENGINE_VERSION
Definition: embedder.h:63
static void fl_engine_plugin_registry_iface_init(FlPluginRegistryInterface *iface)
Definition: fl_engine.cc:296
gboolean fl_renderer_present(FlRenderer *self, GError **error)
Definition: fl_renderer.cc:281
FlutterRendererType type
Definition: embedder.h:448
GThread * thread
Definition: fl_engine.cc:28
FlutterEngineResult FlutterEngineCollectAOTData(FlutterEngineAOTData data)
Collects the AOT data.
Definition: embedder.cc:651
gboolean fl_engine_start(FlEngine *self, GError **error)
Definition: fl_engine.cc:353
const uint8_t * message
Definition: embedder.h:568
static void parse_locale(const gchar *locale, gchar **language, gchar **territory, gchar **codeset, gchar **modifier)
Definition: fl_engine.cc:62
size_t struct_size
The size of this struct. Must be sizeof(FlutterPointerEvent).
Definition: embedder.h:532
FlutterPointerPhase phase
Definition: fl_view.cc:78
size_t struct_size
The size of this struct. Must be sizeof(FlutterOpenGLRendererConfig).
Definition: embedder.h:379
FlRenderer * renderer
Definition: fl_engine.cc:31
gpointer platform_message_handler_data
Definition: fl_engine.cc:38
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:1761
G_MODULE_EXPORT FlEngine * fl_engine_new_headless(FlDartProject *project)
Definition: fl_engine.cc:348
int32_t height
static void fl_engine_class_init(FlEngineClass *klass)
Definition: fl_engine.cc:328
BoolCallback make_resource_current
Definition: embedder.h:398
BoolCallback clear_current
Definition: embedder.h:381
static constexpr size_t kPlatformTaskRunnerIdentifier
Definition: fl_engine.cc:22
int32_t width
void fl_engine_send_window_metrics_event(FlEngine *self, size_t width, size_t height, double pixel_ratio)
Definition: fl_engine.cc:551
static constexpr int kMicrosecondsPerNanosecond
Definition: fl_engine.cc:19
size_t struct_size
The size of this struct. Must be sizeof(FlutterWindowMetricsEvent).
Definition: embedder.h:457
void fl_engine_send_mouse_pointer_event(FlEngine *self, FlutterPointerPhase phase, size_t timestamp, double x, double y, double scroll_delta_x, double scroll_delta_y, int64_t buttons)
Definition: fl_engine.cc:569
FLUTTER_API_SYMBOL(FlutterEngine) engine
double x
The x coordinate of the pointer event in physical pixels.
Definition: embedder.h:539
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:734
static bool fl_engine_gl_make_current(void *user_data)
Definition: fl_engine.cc:189
static void fl_engine_init(FlEngine *self)
Definition: fl_engine.cc:332
const char * assets_path
Definition: embedder.h:1127
FlutterSource
Definition: fl_engine.cc:59
BoolCallback make_current
Definition: embedder.h:380
FlutterOpenGLRendererConfig open_gl
Definition: embedder.h:450
FlutterEngineResult
Definition: embedder.h:65
size_t struct_size
The size of this struct. Must be sizeof(FlutterProjectArgs).
Definition: embedder.h:1123
const char * name
Definition: fuchsia.cc:50
FlEngine * fl_engine_new(FlDartProject *project, FlRenderer *renderer)
Definition: fl_engine.cc:338
int64_t buttons
The buttons currently pressed, if any.
Definition: embedder.h:557
UIntCallback fbo_callback
Definition: embedder.h:391
return TRUE
Definition: fl_view.cc:107
const FlutterTaskRunnerDescription * platform_task_runner
Definition: embedder.h:752
static bool fl_engine_runs_task_on_current_thread(void *user_data)
Definition: fl_engine.cc:235
guint32 fl_renderer_get_fbo(FlRenderer *self)
Definition: fl_renderer.cc:276
FlutterTaskRunnerPostTaskCallback post_task_callback
Definition: embedder.h:739
G_MODULE_EXPORT FlBinaryMessenger * fl_engine_get_binary_messenger(FlEngine *self)
Definition: fl_engine.cc:599
FlutterEngineAOTDataSourceType type
Definition: embedder.h:1110
FlutterPointerSignalKind signal_kind
Definition: embedder.h:545
GDestroyNotify platform_message_handler_destroy_notify
Definition: fl_engine.cc:39
FlutterEngineResult FlutterEngineSendPointerEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPointerEvent *pointers, size_t events_count)
Definition: embedder.cc:1323
FlutterEngineAOTData aot_data
Definition: embedder.h:1315
static void flutter_source_finalize(GSource *source)
Definition: fl_engine.cc:163
static uint32_t fl_engine_gl_get_fbo(void *user_data)
Definition: fl_engine.cc:209
static void fl_engine_platform_message_response_cb(const uint8_t *data, size_t data_length, void *user_data)
Definition: fl_engine.cc:279
gboolean fl_engine_send_platform_message_response(FlEngine *self, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
Definition: fl_engine.cc:453
FlutterPointerDeviceKind device_kind
Definition: embedder.h:555
ProcResolver gl_proc_resolver
Definition: embedder.h:415
size_t struct_size
The size of this struct. Must be sizeof(FlutterCustomTaskRunners).
Definition: embedder.h:747
size_t struct_size
The size of this struct. Must be sizeof(FlutterPlatformMessage).
Definition: embedder.h:566
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterWindowMetricsEvent *flutter_metrics)
Definition: embedder.cc:1229
GBytes * fl_engine_send_platform_message_finish(FlEngine *self, GAsyncResult *result, GError **error)
Definition: fl_engine.cc:542
static void fl_engine_dispose(GObject *object)
Definition: fl_engine.cc:301
G_MODULE_EXPORT const gchar * fl_dart_project_get_assets_path(FlDartProject *self)
const char * language_code
Definition: embedder.h:948
FlutterPointerPhase phase
Definition: embedder.h:533
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:1167
bool FlutterEngineRunsAOTCompiledDartCode(void)
Returns if the Flutter engine instance will run AOT compiled Dart code. This call has no threading re...
Definition: embedder.cc:1821
G_MODULE_EXPORT GType fl_plugin_registry_get_type()
BoolCallback runs_task_on_current_thread_callback
Definition: embedder.h:728
GQuark fl_engine_error_quark(void) G_GNUC_CONST
int command_line_argc
The command line argument count used to initialize the project.
Definition: embedder.h:1153
const char * elf_path
Absolute path to an ELF library file.
Definition: embedder.h:1113
FlutterEngineResult FlutterEngineSendPlatformMessage(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessage *flutter_message)
Definition: embedder.cc:1396
static void * fl_engine_gl_proc_resolver(void *user_data, const char *name)
Definition: fl_engine.cc:184
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:1448
static FlPluginRegistrar * fl_engine_get_registrar_for_plugin(FlPluginRegistry *registry, const gchar *name)
Definition: fl_engine.cc:288
static GSourceFuncs flutter_source_funcs
Definition: fl_engine.cc:173
GObject parent_instance
Definition: fl_engine.cc:25
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