Flutter Linux Embedder
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 
6 
7 #include <gmodule.h>
8 
9 #include <cstring>
10 
12 #include "flutter/shell/platform/embedder/embedder.h"
29 
30 // Unique number associated with platform tasks.
31 static constexpr size_t kPlatformTaskRunnerIdentifier = 1;
32 
33 // Use different device ID for mouse and pan/zoom events, since we can't
34 // differentiate the actual device (mouse v.s. trackpad)
35 static constexpr int32_t kMousePointerDeviceId = 0;
36 static constexpr int32_t kPointerPanZoomDeviceId = 1;
37 
38 struct _FlEngine {
39  GObject parent_instance;
40 
41  // Thread the GLib main loop is running on.
42  GThread* thread;
43 
44  // The project this engine is running.
45  FlDartProject* project;
46 
47  // Watches for monitors changes to update engine.
48  FlDisplayMonitor* display_monitor;
49 
50  // Renders the Flutter app.
51  FlRenderer* renderer;
52 
53  // Messenger used to send and receive platform messages.
54  FlBinaryMessenger* binary_messenger;
55 
56  // Implements the flutter/settings channel.
57  FlSettingsHandler* settings_handler;
58 
59  // Implements the flutter/platform channel.
60  FlPlatformHandler* platform_handler;
61 
62  // Implements the flutter/windowing channel.
63  FlWindowingHandler* windowing_handler;
64 
65  // Process keyboard events.
66  FlKeyboardManager* keyboard_manager;
67 
68  // Implements the flutter/textinput channel.
69  FlTextInputHandler* text_input_handler;
70 
71  // Implements the flutter/keyboard channel.
72  FlKeyboardHandler* keyboard_handler;
73 
74  // Implements the flutter/mousecursor channel.
75  FlMouseCursorHandler* mouse_cursor_handler;
76 
77  // Manages textures rendered by native code.
78  FlTextureRegistrar* texture_registrar;
79 
80  // Schedules tasks to be run on the appropriate thread.
81  FlTaskRunner* task_runner;
82 
83  // Ahead of time data used to make engine run faster.
84  FlutterEngineAOTData aot_data;
85 
86  // The Flutter engine.
87  FLUTTER_API_SYMBOL(FlutterEngine) engine;
88 
89  // Function table for engine API, used to intercept engine calls for testing
90  // purposes.
91  FlutterEngineProcTable embedder_api;
92 
93  // Next ID to use for a view.
94  FlutterViewId next_view_id;
95 
96  // Function to call when a platform message is received.
100 };
101 
102 G_DEFINE_QUARK(fl_engine_error_quark, fl_engine_error)
103 
105  FlPluginRegistryInterface* iface);
106 
108 
110 
112  FlEngine,
113  fl_engine,
114  G_TYPE_OBJECT,
115  G_IMPLEMENT_INTERFACE(fl_plugin_registry_get_type(),
117 
118 enum { PROP_0, PROP_BINARY_MESSENGER, PROP_LAST };
119 
120 // Parse a locale into its components.
121 static void parse_locale(const gchar* locale,
122  gchar** language,
123  gchar** territory,
124  gchar** codeset,
125  gchar** modifier) {
126  gchar* l = g_strdup(locale);
127 
128  // Locales are in the form "language[_territory][.codeset][@modifier]"
129  gchar* match = strrchr(l, '@');
130  if (match != nullptr) {
131  if (modifier != nullptr) {
132  *modifier = g_strdup(match + 1);
133  }
134  *match = '\0';
135  } else if (modifier != nullptr) {
136  *modifier = nullptr;
137  }
138 
139  match = strrchr(l, '.');
140  if (match != nullptr) {
141  if (codeset != nullptr) {
142  *codeset = g_strdup(match + 1);
143  }
144  *match = '\0';
145  } else if (codeset != nullptr) {
146  *codeset = nullptr;
147  }
148 
149  match = strrchr(l, '_');
150  if (match != nullptr) {
151  if (territory != nullptr) {
152  *territory = g_strdup(match + 1);
153  }
154  *match = '\0';
155  } else if (territory != nullptr) {
156  *territory = nullptr;
157  }
158 
159  if (language != nullptr) {
160  *language = l;
161  }
162 }
163 
164 static void view_added_cb(const FlutterAddViewResult* result) {
165  g_autoptr(GTask) task = G_TASK(result->user_data);
166 
167  if (result->added) {
168  g_task_return_boolean(task, TRUE);
169  } else {
170  g_task_return_new_error(task, fl_engine_error_quark(),
171  FL_ENGINE_ERROR_FAILED, "Failed to add view");
172  }
173 }
174 
175 static void view_removed_cb(const FlutterRemoveViewResult* result) {
176  g_autoptr(GTask) task = G_TASK(result->user_data);
177 
178  if (result->removed) {
179  g_task_return_boolean(task, TRUE);
180  } else {
181  g_task_return_new_error(task, fl_engine_error_quark(),
182  FL_ENGINE_ERROR_FAILED, "Failed to remove view");
183  }
184 }
185 
186 static void free_locale(FlutterLocale* locale) {
187  free(const_cast<gchar*>(locale->language_code));
188  free(const_cast<gchar*>(locale->country_code));
189  free(locale);
190 }
191 
192 // Passes locale information to the Flutter engine.
193 static void setup_locales(FlEngine* self) {
194  const gchar* const* languages = g_get_language_names();
195  g_autoptr(GPtrArray) locales_array = g_ptr_array_new_with_free_func(
196  reinterpret_cast<GDestroyNotify>(free_locale));
197  for (int i = 0; languages[i] != nullptr; i++) {
198  g_autofree gchar* locale_string = g_strstrip(g_strdup(languages[i]));
199 
200  // Ignore empty locales, caused by settings like `LANGUAGE=pt_BR:`
201  if (strcmp(locale_string, "") == 0) {
202  continue;
203  }
204 
205  g_autofree gchar* language = nullptr;
206  g_autofree gchar* territory = nullptr;
207  parse_locale(locale_string, &language, &territory, nullptr, nullptr);
208 
209  // Ignore duplicate locales, caused by settings like `LANGUAGE=C` (returns
210  // two "C") or `LANGUAGE=en:en`
211  gboolean has_locale = FALSE;
212  for (guint j = 0; !has_locale && j < locales_array->len; j++) {
213  FlutterLocale* locale =
214  reinterpret_cast<FlutterLocale*>(g_ptr_array_index(locales_array, j));
215  has_locale = g_strcmp0(locale->language_code, language) == 0 &&
216  g_strcmp0(locale->country_code, territory) == 0;
217  }
218  if (has_locale) {
219  continue;
220  }
221 
222  FlutterLocale* locale =
223  static_cast<FlutterLocale*>(g_malloc0(sizeof(FlutterLocale)));
224  g_ptr_array_add(locales_array, locale);
225  locale->struct_size = sizeof(FlutterLocale);
226  locale->language_code =
227  reinterpret_cast<const gchar*>(g_steal_pointer(&language));
228  locale->country_code =
229  reinterpret_cast<const gchar*>(g_steal_pointer(&territory));
230  locale->script_code = nullptr;
231  locale->variant_code = nullptr;
232  }
233  FlutterLocale** locales =
234  reinterpret_cast<FlutterLocale**>(locales_array->pdata);
235  FlutterEngineResult result = self->embedder_api.UpdateLocales(
236  self->engine, const_cast<const FlutterLocale**>(locales),
237  locales_array->len);
238  if (result != kSuccess) {
239  g_warning("Failed to set up Flutter locales");
240  }
241 }
242 
243 // Called when engine needs a backing store for a specific #FlutterLayer.
245  const FlutterBackingStoreConfig* config,
246  FlutterBackingStore* backing_store_out,
247  void* user_data) {
248  g_return_val_if_fail(FL_IS_RENDERER(user_data), false);
249  return fl_renderer_create_backing_store(FL_RENDERER(user_data), config,
250  backing_store_out);
251 }
252 
253 // Called when the backing store is to be released.
255  const FlutterBackingStore* backing_store,
256  void* user_data) {
257  g_return_val_if_fail(FL_IS_RENDERER(user_data), false);
258  return fl_renderer_collect_backing_store(FL_RENDERER(user_data),
259  backing_store);
260 }
261 
262 // Called when embedder should composite contents of each layer onto the screen.
264  const FlutterPresentViewInfo* info) {
265  g_return_val_if_fail(FL_IS_RENDERER(info->user_data), false);
266  return fl_renderer_present_layers(FL_RENDERER(info->user_data), info->view_id,
267  info->layers, info->layers_count);
268 }
269 
270 // Flutter engine rendering callbacks.
271 
272 static void* fl_engine_gl_proc_resolver(void* user_data, const char* name) {
273  FlEngine* self = static_cast<FlEngine*>(user_data);
274  return fl_renderer_get_proc_address(self->renderer, name);
275 }
276 
278  FlEngine* self = static_cast<FlEngine*>(user_data);
279  fl_renderer_make_current(self->renderer);
280  return true;
281 }
282 
284  FlEngine* self = static_cast<FlEngine*>(user_data);
285  fl_renderer_clear_current(self->renderer);
286  return true;
287 }
288 
289 static uint32_t fl_engine_gl_get_fbo(void* user_data) {
290  FlEngine* self = static_cast<FlEngine*>(user_data);
291  return fl_renderer_get_fbo(self->renderer);
292 }
293 
294 static bool fl_engine_gl_present(void* user_data) {
295  // No action required, as this is handled in
296  // compositor_present_view_callback.
297  return true;
298 }
299 
301  FlEngine* self = static_cast<FlEngine*>(user_data);
302  fl_renderer_make_resource_current(self->renderer);
303  return true;
304 }
305 
306 // Called by the engine to retrieve an external texture.
308  void* user_data,
309  int64_t texture_id,
310  size_t width,
311  size_t height,
312  FlutterOpenGLTexture* opengl_texture) {
313  FlEngine* self = static_cast<FlEngine*>(user_data);
314  if (!self->texture_registrar) {
315  return false;
316  }
317 
318  FlTexture* texture =
319  fl_texture_registrar_lookup_texture(self->texture_registrar, texture_id);
320  if (texture == nullptr) {
321  g_warning("Unable to find texture %" G_GINT64_FORMAT, texture_id);
322  return false;
323  }
324 
325  gboolean result;
326  g_autoptr(GError) error = nullptr;
327  if (FL_IS_TEXTURE_GL(texture)) {
328  result = fl_texture_gl_populate(FL_TEXTURE_GL(texture), width, height,
329  opengl_texture, &error);
330  } else if (FL_IS_PIXEL_BUFFER_TEXTURE(texture)) {
331  result =
332  fl_pixel_buffer_texture_populate(FL_PIXEL_BUFFER_TEXTURE(texture),
333  width, height, opengl_texture, &error);
334  } else {
335  g_warning("Unsupported texture type %" G_GINT64_FORMAT, texture_id);
336  return false;
337  }
338 
339  if (!result) {
340  g_warning("%s", error->message);
341  return false;
342  }
343 
344  return true;
345 }
346 
347 // Called by the engine to determine if it is on the GTK thread.
349  FlEngine* self = static_cast<FlEngine*>(user_data);
350  return self->thread == g_thread_self();
351 }
352 
353 // Called when the engine has a task to perform in the GTK thread.
354 static void fl_engine_post_task(FlutterTask task,
355  uint64_t target_time_nanos,
356  void* user_data) {
357  FlEngine* self = static_cast<FlEngine*>(user_data);
358 
359  fl_task_runner_post_task(self->task_runner, task, target_time_nanos);
360 }
361 
362 // Called when a platform message is received from the engine.
363 static void fl_engine_platform_message_cb(const FlutterPlatformMessage* message,
364  void* user_data) {
365  FlEngine* self = FL_ENGINE(user_data);
366 
367  gboolean handled = FALSE;
368  if (self->platform_message_handler != nullptr) {
369  g_autoptr(GBytes) data =
370  g_bytes_new(message->message, message->message_size);
371  handled = self->platform_message_handler(
372  self, message->channel, data, message->response_handle,
373  self->platform_message_handler_data);
374  }
375 
376  if (!handled) {
377  fl_engine_send_platform_message_response(self, message->response_handle,
378  nullptr, nullptr);
379  }
380 }
381 
382 // Called when a semantic node update is received from the engine.
383 static void fl_engine_update_semantics_cb(const FlutterSemanticsUpdate2* update,
384  void* user_data) {
385  FlEngine* self = FL_ENGINE(user_data);
386 
388 }
389 
390 static void setup_keyboard(FlEngine* self) {
391  g_clear_object(&self->keyboard_manager);
392  self->keyboard_manager = fl_keyboard_manager_new(self);
393 
394  g_clear_object(&self->keyboard_handler);
395  self->keyboard_handler =
396  fl_keyboard_handler_new(self->binary_messenger, self->keyboard_manager);
397 
398  GtkWidget* widget =
399  self->text_input_handler != nullptr
400  ? fl_text_input_handler_get_widget(self->text_input_handler)
401  : nullptr;
402  g_clear_object(&self->text_input_handler);
403  self->text_input_handler = fl_text_input_handler_new(self->binary_messenger);
404  if (widget != nullptr) {
405  fl_text_input_handler_set_widget(self->text_input_handler, widget);
406  }
407 }
408 
409 // Called right before the engine is restarted.
410 //
411 // This method should reset states to as if the engine has just been started,
412 // which usually indicates the user has requested a hot restart (Shift-R in the
413 // Flutter CLI.)
415  FlEngine* self = FL_ENGINE(user_data);
416 
417  setup_keyboard(self);
418 
420 }
421 
422 // Called when a response to a sent platform message is received from the
423 // engine.
424 static void fl_engine_platform_message_response_cb(const uint8_t* data,
425  size_t data_length,
426  void* user_data) {
427  g_autoptr(GTask) task = G_TASK(user_data);
428  g_task_return_pointer(task, g_bytes_new(data, data_length),
429  reinterpret_cast<GDestroyNotify>(g_bytes_unref));
430 }
431 
432 // Implements FlPluginRegistry::get_registrar_for_plugin.
433 static FlPluginRegistrar* fl_engine_get_registrar_for_plugin(
434  FlPluginRegistry* registry,
435  const gchar* name) {
436  FlEngine* self = FL_ENGINE(registry);
437 
438  return fl_plugin_registrar_new(nullptr, self->binary_messenger,
439  self->texture_registrar);
440 }
441 
443  FlPluginRegistryInterface* iface) {
444  iface->get_registrar_for_plugin = fl_engine_get_registrar_for_plugin;
445 }
446 
447 static void fl_engine_set_property(GObject* object,
448  guint prop_id,
449  const GValue* value,
450  GParamSpec* pspec) {
451  FlEngine* self = FL_ENGINE(object);
452  switch (prop_id) {
453  case PROP_BINARY_MESSENGER:
454  g_set_object(&self->binary_messenger,
455  FL_BINARY_MESSENGER(g_value_get_object(value)));
456  break;
457  default:
458  G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
459  break;
460  }
461 }
462 
463 static void fl_engine_dispose(GObject* object) {
464  FlEngine* self = FL_ENGINE(object);
465 
466  if (self->engine != nullptr) {
467  self->embedder_api.Shutdown(self->engine);
468  self->engine = nullptr;
469  }
470 
471  if (self->aot_data != nullptr) {
472  self->embedder_api.CollectAOTData(self->aot_data);
473  self->aot_data = nullptr;
474  }
475 
476  fl_binary_messenger_shutdown(self->binary_messenger);
477  fl_texture_registrar_shutdown(self->texture_registrar);
478 
479  g_clear_object(&self->project);
480  g_clear_object(&self->display_monitor);
481  g_clear_object(&self->renderer);
482  g_clear_object(&self->texture_registrar);
483  g_clear_object(&self->binary_messenger);
484  g_clear_object(&self->settings_handler);
485  g_clear_object(&self->platform_handler);
486  g_clear_object(&self->windowing_handler);
487  g_clear_object(&self->keyboard_manager);
488  g_clear_object(&self->text_input_handler);
489  g_clear_object(&self->keyboard_handler);
490  g_clear_object(&self->mouse_cursor_handler);
491  g_clear_object(&self->task_runner);
492 
493  if (self->platform_message_handler_destroy_notify) {
494  self->platform_message_handler_destroy_notify(
495  self->platform_message_handler_data);
496  }
497  self->platform_message_handler_data = nullptr;
498  self->platform_message_handler_destroy_notify = nullptr;
499 
500  G_OBJECT_CLASS(fl_engine_parent_class)->dispose(object);
501 }
502 
503 static void fl_engine_class_init(FlEngineClass* klass) {
504  G_OBJECT_CLASS(klass)->dispose = fl_engine_dispose;
505  G_OBJECT_CLASS(klass)->set_property = fl_engine_set_property;
506 
507  g_object_class_install_property(
508  G_OBJECT_CLASS(klass), PROP_BINARY_MESSENGER,
509  g_param_spec_object(
510  "binary-messenger", "messenger", "Binary messenger",
511  fl_binary_messenger_get_type(),
512  static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
513  G_PARAM_STATIC_STRINGS)));
514 
516  "on-pre-engine-restart", fl_engine_get_type(), G_SIGNAL_RUN_LAST, 0,
517  nullptr, nullptr, nullptr, G_TYPE_NONE, 0);
519  "update-semantics", fl_engine_get_type(), G_SIGNAL_RUN_LAST, 0, nullptr,
520  nullptr, nullptr, G_TYPE_NONE, 1, G_TYPE_POINTER);
521 }
522 
523 static void fl_engine_init(FlEngine* self) {
524  self->thread = g_thread_self();
525 
526  self->embedder_api.struct_size = sizeof(FlutterEngineProcTable);
527  if (FlutterEngineGetProcAddresses(&self->embedder_api) != kSuccess) {
528  g_warning("Failed get get engine function pointers");
529  }
530 
531  self->display_monitor =
532  fl_display_monitor_new(self, gdk_display_get_default());
533  self->task_runner = fl_task_runner_new(self);
534 
535  // Implicit view is 0, so start at 1.
536  self->next_view_id = 1;
537 
538  self->texture_registrar = fl_texture_registrar_new(self);
539 }
540 
541 static FlEngine* fl_engine_new_full(FlDartProject* project,
542  FlRenderer* renderer,
543  FlBinaryMessenger* binary_messenger) {
544  g_return_val_if_fail(FL_IS_DART_PROJECT(project), nullptr);
545  g_return_val_if_fail(FL_IS_RENDERER(renderer), nullptr);
546 
547  FlEngine* self = FL_ENGINE(g_object_new(fl_engine_get_type(), nullptr));
548 
549  self->project = FL_DART_PROJECT(g_object_ref(project));
550  self->renderer = FL_RENDERER(g_object_ref(renderer));
551  if (binary_messenger != nullptr) {
552  self->binary_messenger =
553  FL_BINARY_MESSENGER(g_object_ref(binary_messenger));
554  } else {
555  self->binary_messenger = fl_binary_messenger_new(self);
556  }
557  self->keyboard_manager = fl_keyboard_manager_new(self);
558  self->mouse_cursor_handler =
559  fl_mouse_cursor_handler_new(self->binary_messenger);
560  self->windowing_handler = fl_windowing_handler_new(self);
561 
562  fl_renderer_set_engine(self->renderer, self);
563 
564  return self;
565 }
566 
567 FlEngine* fl_engine_for_id(int64_t id) {
568  void* engine = reinterpret_cast<void*>(id);
569  g_return_val_if_fail(FL_IS_ENGINE(engine), nullptr);
570  return FL_ENGINE(engine);
571 }
572 
573 FlEngine* fl_engine_new_with_renderer(FlDartProject* project,
574  FlRenderer* renderer) {
575  g_return_val_if_fail(FL_IS_DART_PROJECT(project), nullptr);
576  g_return_val_if_fail(FL_IS_RENDERER(renderer), nullptr);
577  return fl_engine_new_full(project, renderer, nullptr);
578 }
579 
580 G_MODULE_EXPORT FlEngine* fl_engine_new(FlDartProject* project) {
581  g_autoptr(FlRendererGdk) renderer = fl_renderer_gdk_new();
582  return fl_engine_new_with_renderer(project, FL_RENDERER(renderer));
583 }
584 
586  FlBinaryMessenger* binary_messenger) {
587  g_autoptr(FlDartProject) project = fl_dart_project_new();
588  g_autoptr(FlRendererGdk) renderer = fl_renderer_gdk_new();
589  return fl_engine_new_full(project, FL_RENDERER(renderer), binary_messenger);
590 }
591 
592 G_MODULE_EXPORT FlEngine* fl_engine_new_headless(FlDartProject* project) {
593  g_autoptr(FlRendererHeadless) renderer = fl_renderer_headless_new();
594  return fl_engine_new_with_renderer(project, FL_RENDERER(renderer));
595 }
596 
597 FlRenderer* fl_engine_get_renderer(FlEngine* self) {
598  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
599  return self->renderer;
600 }
601 
602 FlDisplayMonitor* fl_engine_get_display_monitor(FlEngine* self) {
603  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
604  return self->display_monitor;
605 }
606 
607 gboolean fl_engine_start(FlEngine* self, GError** error) {
608  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
609 
610  FlutterRendererConfig config = {};
611  config.type = kOpenGL;
612  config.open_gl.struct_size = sizeof(FlutterOpenGLRendererConfig);
613  config.open_gl.gl_proc_resolver = fl_engine_gl_proc_resolver;
614  config.open_gl.make_current = fl_engine_gl_make_current;
615  config.open_gl.clear_current = fl_engine_gl_clear_current;
616  config.open_gl.fbo_callback = fl_engine_gl_get_fbo;
617  config.open_gl.present = fl_engine_gl_present;
618  config.open_gl.make_resource_current = fl_engine_gl_make_resource_current;
619  config.open_gl.gl_external_texture_frame_callback =
621 
622  FlutterTaskRunnerDescription platform_task_runner = {};
623  platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription);
624  platform_task_runner.user_data = self;
625  platform_task_runner.runs_task_on_current_thread_callback =
627  platform_task_runner.post_task_callback = fl_engine_post_task;
628  platform_task_runner.identifier = kPlatformTaskRunnerIdentifier;
629 
630  FlutterCustomTaskRunners custom_task_runners = {};
631  custom_task_runners.struct_size = sizeof(FlutterCustomTaskRunners);
632  custom_task_runners.platform_task_runner = &platform_task_runner;
633  custom_task_runners.render_task_runner = &platform_task_runner;
634 
635  g_autoptr(GPtrArray) command_line_args =
636  g_ptr_array_new_with_free_func(g_free);
637  g_ptr_array_insert(command_line_args, 0, g_strdup("flutter"));
638  for (const auto& env_switch : flutter::GetSwitchesFromEnvironment()) {
639  g_ptr_array_add(command_line_args, g_strdup(env_switch.c_str()));
640  }
641 
642  gchar** dart_entrypoint_args =
644 
645  FlutterProjectArgs args = {};
646  args.struct_size = sizeof(FlutterProjectArgs);
647  args.assets_path = fl_dart_project_get_assets_path(self->project);
648  args.icu_data_path = fl_dart_project_get_icu_data_path(self->project);
649  args.command_line_argc = command_line_args->len;
650  args.command_line_argv =
651  reinterpret_cast<const char* const*>(command_line_args->pdata);
652  args.platform_message_callback = fl_engine_platform_message_cb;
653  args.update_semantics_callback2 = fl_engine_update_semantics_cb;
654  args.custom_task_runners = &custom_task_runners;
655  args.shutdown_dart_vm_when_done = true;
656  args.on_pre_engine_restart_callback = fl_engine_on_pre_engine_restart_cb;
657  args.dart_entrypoint_argc =
658  dart_entrypoint_args != nullptr ? g_strv_length(dart_entrypoint_args) : 0;
659  args.dart_entrypoint_argv =
660  reinterpret_cast<const char* const*>(dart_entrypoint_args);
661  args.engine_id = reinterpret_cast<int64_t>(self);
662 
663  FlutterCompositor compositor = {};
664  compositor.struct_size = sizeof(FlutterCompositor);
665  compositor.user_data = self->renderer;
666  compositor.create_backing_store_callback =
668  compositor.collect_backing_store_callback =
670  compositor.present_view_callback = compositor_present_view_callback;
671  args.compositor = &compositor;
672 
673  if (self->embedder_api.RunsAOTCompiledDartCode()) {
674  FlutterEngineAOTDataSource source = {};
675  source.type = kFlutterEngineAOTDataSourceTypeElfPath;
676  source.elf_path = fl_dart_project_get_aot_library_path(self->project);
677  if (self->embedder_api.CreateAOTData(&source, &self->aot_data) !=
678  kSuccess) {
680  "Failed to create AOT data");
681  return FALSE;
682  }
683  args.aot_data = self->aot_data;
684  }
685 
686  FlutterEngineResult result = self->embedder_api.Initialize(
687  FLUTTER_ENGINE_VERSION, &config, &args, self, &self->engine);
688  if (result != kSuccess) {
690  "Failed to initialize Flutter engine");
691  return FALSE;
692  }
693 
694  result = self->embedder_api.RunInitialized(self->engine);
695  if (result != kSuccess) {
697  "Failed to run Flutter engine");
698  return FALSE;
699  }
700 
701  setup_locales(self);
702 
703  g_autoptr(FlSettings) settings = fl_settings_new();
704  self->settings_handler = fl_settings_handler_new(self);
705  fl_settings_handler_start(self->settings_handler, settings);
706 
707  self->platform_handler = fl_platform_handler_new(self->binary_messenger);
708 
709  setup_keyboard(self);
710 
711  result = self->embedder_api.UpdateSemanticsEnabled(self->engine, TRUE);
712  if (result != kSuccess) {
713  g_warning("Failed to enable accessibility features on Flutter engine");
714  }
715 
716  fl_display_monitor_start(self->display_monitor);
717 
718  return TRUE;
719 }
720 
721 FlutterEngineProcTable* fl_engine_get_embedder_api(FlEngine* self) {
722  return &(self->embedder_api);
723 }
724 
726  const FlutterEngineDisplay* displays,
727  size_t displays_length) {
728  g_return_if_fail(FL_IS_ENGINE(self));
729 
730  FlutterEngineResult result = self->embedder_api.NotifyDisplayUpdate(
731  self->engine, kFlutterEngineDisplaysUpdateTypeStartup, displays,
732  displays_length);
733  if (result != kSuccess) {
734  g_warning("Failed to notify display update to Flutter engine: %d", result);
735  }
736 }
737 
738 FlutterViewId fl_engine_add_view(FlEngine* self,
739  size_t width,
740  size_t height,
741  double pixel_ratio,
742  GCancellable* cancellable,
743  GAsyncReadyCallback callback,
744  gpointer user_data) {
745  g_return_val_if_fail(FL_IS_ENGINE(self), -1);
746 
747  g_autoptr(GTask) task = g_task_new(self, cancellable, callback, user_data);
748 
749  FlutterViewId view_id = self->next_view_id;
750  self->next_view_id++;
751 
752  // We don't know which display this view will open on, so set to zero and this
753  // will be updated in a following FlutterWindowMetricsEvent
754  FlutterEngineDisplayId display_id = 0;
755 
756  FlutterWindowMetricsEvent metrics;
757  metrics.struct_size = sizeof(FlutterWindowMetricsEvent);
758  metrics.width = width;
759  metrics.height = height;
760  metrics.pixel_ratio = pixel_ratio;
761  metrics.display_id = display_id;
762  metrics.view_id = view_id;
763  FlutterAddViewInfo info;
764  info.struct_size = sizeof(FlutterAddViewInfo);
765  info.view_id = view_id;
766  info.view_metrics = &metrics;
767  info.user_data = g_object_ref(task);
768  info.add_view_callback = view_added_cb;
769  FlutterEngineResult result = self->embedder_api.AddView(self->engine, &info);
770  if (result != kSuccess) {
771  g_task_return_new_error(task, fl_engine_error_quark(),
772  FL_ENGINE_ERROR_FAILED, "AddView returned %d",
773  result);
774  // This would have been done in the callback, but that won't occur now.
775  g_object_unref(task);
776  }
777 
778  return view_id;
779 }
780 
781 gboolean fl_engine_add_view_finish(FlEngine* self,
782  GAsyncResult* result,
783  GError** error) {
784  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
785  return g_task_propagate_boolean(G_TASK(result), error);
786 }
787 
788 void fl_engine_remove_view(FlEngine* self,
789  FlutterViewId view_id,
790  GCancellable* cancellable,
791  GAsyncReadyCallback callback,
792  gpointer user_data) {
793  g_return_if_fail(FL_IS_ENGINE(self));
794 
795  g_autoptr(GTask) task = g_task_new(self, cancellable, callback, user_data);
796 
797  FlutterRemoveViewInfo info;
798  info.struct_size = sizeof(FlutterRemoveViewInfo);
799  info.view_id = view_id;
800  info.user_data = g_object_ref(task);
801  info.remove_view_callback = view_removed_cb;
802  FlutterEngineResult result =
803  self->embedder_api.RemoveView(self->engine, &info);
804  if (result != kSuccess) {
805  g_task_return_new_error(task, fl_engine_error_quark(),
806  FL_ENGINE_ERROR_FAILED, "RemoveView returned %d",
807  result);
808  // This would have been done in the callback, but that won't occur now.
809  g_object_unref(task);
810  }
811 }
812 
813 gboolean fl_engine_remove_view_finish(FlEngine* self,
814  GAsyncResult* result,
815  GError** error) {
816  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
817  return g_task_propagate_boolean(G_TASK(result), error);
818 }
819 
821  FlEngine* self,
823  gpointer user_data,
824  GDestroyNotify destroy_notify) {
825  g_return_if_fail(FL_IS_ENGINE(self));
826  g_return_if_fail(handler != nullptr);
827 
828  if (self->platform_message_handler_destroy_notify) {
829  self->platform_message_handler_destroy_notify(
830  self->platform_message_handler_data);
831  }
832 
833  self->platform_message_handler = handler;
834  self->platform_message_handler_data = user_data;
835  self->platform_message_handler_destroy_notify = destroy_notify;
836 }
837 
838 // Note: This function can be called from any thread.
840  FlEngine* self,
841  const FlutterPlatformMessageResponseHandle* handle,
842  GBytes* response,
843  GError** error) {
844  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
845  g_return_val_if_fail(handle != nullptr, FALSE);
846 
847  if (self->engine == nullptr) {
849  "No engine to send response to");
850  return FALSE;
851  }
852 
853  gsize data_length = 0;
854  const uint8_t* data = nullptr;
855  if (response != nullptr) {
856  data =
857  static_cast<const uint8_t*>(g_bytes_get_data(response, &data_length));
858  }
859  FlutterEngineResult result = self->embedder_api.SendPlatformMessageResponse(
860  self->engine, handle, data, data_length);
861 
862  if (result != kSuccess) {
864  "Failed to send platform message response");
865  return FALSE;
866  }
867 
868  return TRUE;
869 }
870 
872  const gchar* channel,
873  GBytes* message,
874  GCancellable* cancellable,
875  GAsyncReadyCallback callback,
876  gpointer user_data) {
877  g_return_if_fail(FL_IS_ENGINE(self));
878 
879  GTask* task = nullptr;
880  FlutterPlatformMessageResponseHandle* response_handle = nullptr;
881  if (callback != nullptr) {
882  task = g_task_new(self, cancellable, callback, user_data);
883 
884  if (self->engine == nullptr) {
885  g_task_return_new_error(task, fl_engine_error_quark(),
886  FL_ENGINE_ERROR_FAILED, "No engine to send to");
887  return;
888  }
889 
890  FlutterEngineResult result =
891  self->embedder_api.PlatformMessageCreateResponseHandle(
892  self->engine, fl_engine_platform_message_response_cb, task,
893  &response_handle);
894  if (result != kSuccess) {
895  g_task_return_new_error(task, fl_engine_error_quark(),
897  "Failed to create response handle");
898  g_object_unref(task);
899  return;
900  }
901  } else if (self->engine == nullptr) {
902  return;
903  }
904 
905  FlutterPlatformMessage fl_message = {};
906  fl_message.struct_size = sizeof(fl_message);
907  fl_message.channel = channel;
908  fl_message.message =
909  message != nullptr
910  ? static_cast<const uint8_t*>(g_bytes_get_data(message, nullptr))
911  : nullptr;
912  fl_message.message_size = message != nullptr ? g_bytes_get_size(message) : 0;
913  fl_message.response_handle = response_handle;
914  FlutterEngineResult result =
915  self->embedder_api.SendPlatformMessage(self->engine, &fl_message);
916 
917  if (result != kSuccess && task != nullptr) {
918  g_task_return_new_error(task, fl_engine_error_quark(),
920  "Failed to send platform messages");
921  g_object_unref(task);
922  }
923 
924  if (response_handle != nullptr) {
925  self->embedder_api.PlatformMessageReleaseResponseHandle(self->engine,
926  response_handle);
927  }
928 }
929 
931  GAsyncResult* result,
932  GError** error) {
933  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
934  g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
935 
936  return static_cast<GBytes*>(g_task_propagate_pointer(G_TASK(result), error));
937 }
938 
940  FlutterEngineDisplayId display_id,
941  FlutterViewId view_id,
942  size_t width,
943  size_t height,
944  double pixel_ratio) {
945  g_return_if_fail(FL_IS_ENGINE(self));
946 
947  if (self->engine == nullptr) {
948  return;
949  }
950 
951  FlutterWindowMetricsEvent event = {};
952  event.struct_size = sizeof(FlutterWindowMetricsEvent);
953  event.width = width;
954  event.height = height;
955  event.pixel_ratio = pixel_ratio;
956  event.display_id = display_id;
957  event.view_id = view_id;
958  self->embedder_api.SendWindowMetricsEvent(self->engine, &event);
959 }
960 
962  FlutterViewId view_id,
963  FlutterPointerPhase phase,
964  size_t timestamp,
965  double x,
966  double y,
967  FlutterPointerDeviceKind device_kind,
968  double scroll_delta_x,
969  double scroll_delta_y,
970  int64_t buttons) {
971  g_return_if_fail(FL_IS_ENGINE(self));
972 
973  if (self->engine == nullptr) {
974  return;
975  }
976 
977  FlutterPointerEvent fl_event = {};
978  fl_event.struct_size = sizeof(fl_event);
979  fl_event.phase = phase;
980  fl_event.timestamp = timestamp;
981  fl_event.x = x;
982  fl_event.y = y;
983  if (scroll_delta_x != 0 || scroll_delta_y != 0) {
984  fl_event.signal_kind = kFlutterPointerSignalKindScroll;
985  }
986  fl_event.scroll_delta_x = scroll_delta_x;
987  fl_event.scroll_delta_y = scroll_delta_y;
988  fl_event.device_kind = device_kind;
989  fl_event.buttons = buttons;
990  fl_event.device = kMousePointerDeviceId;
991  fl_event.view_id = view_id;
992  self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);
993 }
994 
995 void fl_engine_send_touch_up_event(FlEngine* self,
996  FlutterViewId view_id,
997  size_t timestamp,
998  double x,
999  double y,
1000  int32_t device) {
1001  g_return_if_fail(FL_IS_ENGINE(self));
1002 
1003  if (self->engine == nullptr) {
1004  return;
1005  }
1006 
1007  FlutterPointerEvent event;
1008  event.timestamp = timestamp;
1009  event.x = x;
1010  event.y = y;
1011  event.device_kind = kFlutterPointerDeviceKindTouch;
1012  event.device = device;
1013  event.buttons = 0;
1014  event.view_id = view_id;
1015  event.phase = FlutterPointerPhase::kUp;
1016  event.struct_size = sizeof(event);
1017 
1018  self->embedder_api.SendPointerEvent(self->engine, &event, 1);
1019 }
1020 
1022  FlutterViewId view_id,
1023  size_t timestamp,
1024  double x,
1025  double y,
1026  int32_t device) {
1027  g_return_if_fail(FL_IS_ENGINE(self));
1028 
1029  if (self->engine == nullptr) {
1030  return;
1031  }
1032 
1033  FlutterPointerEvent event;
1034  event.timestamp = timestamp;
1035  event.x = x;
1036  event.y = y;
1037  event.device_kind = kFlutterPointerDeviceKindTouch;
1038  event.device = device;
1039  event.buttons = FlutterPointerMouseButtons::kFlutterPointerButtonMousePrimary;
1040  event.view_id = view_id;
1041  event.phase = FlutterPointerPhase::kDown;
1042  event.struct_size = sizeof(event);
1043 
1044  self->embedder_api.SendPointerEvent(self->engine, &event, 1);
1045 }
1046 
1048  FlutterViewId view_id,
1049  size_t timestamp,
1050  double x,
1051  double y,
1052  int32_t device) {
1053  g_return_if_fail(FL_IS_ENGINE(self));
1054 
1055  if (self->engine == nullptr) {
1056  return;
1057  }
1058 
1059  FlutterPointerEvent event;
1060  event.timestamp = timestamp;
1061  event.x = x;
1062  event.y = y;
1063  event.device_kind = kFlutterPointerDeviceKindTouch;
1064  event.device = device;
1065  event.buttons = FlutterPointerMouseButtons::kFlutterPointerButtonMousePrimary;
1066  event.view_id = view_id;
1067  event.phase = FlutterPointerPhase::kMove;
1068  event.struct_size = sizeof(event);
1069 
1070  self->embedder_api.SendPointerEvent(self->engine, &event, 1);
1071 }
1072 
1074  FlutterViewId view_id,
1075  size_t timestamp,
1076  double x,
1077  double y,
1078  int32_t device) {
1079  g_return_if_fail(FL_IS_ENGINE(self));
1080 
1081  if (self->engine == nullptr) {
1082  return;
1083  }
1084 
1085  FlutterPointerEvent event;
1086  event.timestamp = timestamp;
1087  event.x = x;
1088  event.y = y;
1089  event.device_kind = kFlutterPointerDeviceKindTouch;
1090  event.device = device;
1091  event.buttons = 0;
1092  event.view_id = view_id;
1093  event.phase = FlutterPointerPhase::kAdd;
1094  event.struct_size = sizeof(event);
1095 
1096  self->embedder_api.SendPointerEvent(self->engine, &event, 1);
1097 }
1098 
1100  FlutterViewId view_id,
1101  size_t timestamp,
1102  double x,
1103  double y,
1104  int32_t device) {
1105  g_return_if_fail(FL_IS_ENGINE(self));
1106 
1107  if (self->engine == nullptr) {
1108  return;
1109  }
1110 
1111  FlutterPointerEvent event;
1112  event.timestamp = timestamp;
1113  event.x = x;
1114  event.y = y;
1115  event.device_kind = kFlutterPointerDeviceKindTouch;
1116  event.device = device;
1117  event.buttons = 0;
1118  event.view_id = view_id;
1119  event.phase = FlutterPointerPhase::kRemove;
1120  event.struct_size = sizeof(event);
1121 
1122  self->embedder_api.SendPointerEvent(self->engine, &event, 1);
1123 }
1124 
1126  FlutterViewId view_id,
1127  size_t timestamp,
1128  double x,
1129  double y,
1130  FlutterPointerPhase phase,
1131  double pan_x,
1132  double pan_y,
1133  double scale,
1134  double rotation) {
1135  g_return_if_fail(FL_IS_ENGINE(self));
1136 
1137  if (self->engine == nullptr) {
1138  return;
1139  }
1140 
1141  FlutterPointerEvent fl_event = {};
1142  fl_event.struct_size = sizeof(fl_event);
1143  fl_event.timestamp = timestamp;
1144  fl_event.x = x;
1145  fl_event.y = y;
1146  fl_event.phase = phase;
1147  fl_event.pan_x = pan_x;
1148  fl_event.pan_y = pan_y;
1149  fl_event.scale = scale;
1150  fl_event.rotation = rotation;
1151  fl_event.device = kPointerPanZoomDeviceId;
1152  fl_event.device_kind = kFlutterPointerDeviceKindTrackpad;
1153  fl_event.view_id = view_id;
1154  self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);
1155 }
1156 
1157 static void send_key_event_cb(bool handled, void* user_data) {
1158  g_autoptr(GTask) task = G_TASK(user_data);
1159  gboolean* return_value = g_new0(gboolean, 1);
1160  *return_value = handled;
1161  g_task_return_pointer(task, return_value, g_free);
1162 }
1163 
1164 void fl_engine_send_key_event(FlEngine* self,
1165  const FlutterKeyEvent* event,
1166  GCancellable* cancellable,
1167  GAsyncReadyCallback callback,
1168  gpointer user_data) {
1169  g_return_if_fail(FL_IS_ENGINE(self));
1170 
1171  g_autoptr(GTask) task = g_task_new(self, cancellable, callback, user_data);
1172 
1173  if (self->engine == nullptr) {
1174  g_task_return_new_error(task, fl_engine_error_quark(),
1175  FL_ENGINE_ERROR_FAILED, "No engine");
1176  return;
1177  }
1178 
1179  if (self->embedder_api.SendKeyEvent(self->engine, event, send_key_event_cb,
1180  g_object_ref(task)) != kSuccess) {
1181  g_task_return_new_error(task, fl_engine_error_quark(),
1182  FL_ENGINE_ERROR_FAILED, "Failed to send key event");
1183  g_object_unref(task);
1184  }
1185 }
1186 
1187 gboolean fl_engine_send_key_event_finish(FlEngine* self,
1188  GAsyncResult* result,
1189  gboolean* handled,
1190  GError** error) {
1191  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1192  g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
1193 
1194  g_autofree gboolean* return_value =
1195  static_cast<gboolean*>(g_task_propagate_pointer(G_TASK(result), error));
1196  if (return_value == nullptr) {
1197  return FALSE;
1198  }
1199 
1200  *handled = *return_value;
1201  return TRUE;
1202 }
1203 
1205  uint64_t id,
1206  FlutterSemanticsAction action,
1207  GBytes* data) {
1208  g_return_if_fail(FL_IS_ENGINE(self));
1209 
1210  if (self->engine == nullptr) {
1211  return;
1212  }
1213 
1214  const uint8_t* action_data = nullptr;
1215  size_t action_data_length = 0;
1216  if (data != nullptr) {
1217  action_data = static_cast<const uint8_t*>(
1218  g_bytes_get_data(data, &action_data_length));
1219  }
1220 
1221  self->embedder_api.DispatchSemanticsAction(self->engine, id, action,
1222  action_data, action_data_length);
1223 }
1224 
1226  int64_t texture_id) {
1227  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1228  return self->embedder_api.MarkExternalTextureFrameAvailable(
1229  self->engine, texture_id) == kSuccess;
1230 }
1231 
1232 gboolean fl_engine_register_external_texture(FlEngine* self,
1233  int64_t texture_id) {
1234  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1235  return self->embedder_api.RegisterExternalTexture(self->engine, texture_id) ==
1236  kSuccess;
1237 }
1238 
1240  int64_t texture_id) {
1241  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1242  return self->embedder_api.UnregisterExternalTexture(self->engine,
1243  texture_id) == kSuccess;
1244 }
1245 
1246 G_MODULE_EXPORT FlBinaryMessenger* fl_engine_get_binary_messenger(
1247  FlEngine* self) {
1248  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1249  return self->binary_messenger;
1250 }
1251 
1252 FlTaskRunner* fl_engine_get_task_runner(FlEngine* self) {
1253  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1254  return self->task_runner;
1255 }
1256 
1257 void fl_engine_execute_task(FlEngine* self, FlutterTask* task) {
1258  g_return_if_fail(FL_IS_ENGINE(self));
1259  self->embedder_api.RunTask(self->engine, task);
1260 }
1261 
1262 G_MODULE_EXPORT FlTextureRegistrar* fl_engine_get_texture_registrar(
1263  FlEngine* self) {
1264  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1265  return self->texture_registrar;
1266 }
1267 
1268 void fl_engine_update_accessibility_features(FlEngine* self, int32_t flags) {
1269  g_return_if_fail(FL_IS_ENGINE(self));
1270 
1271  if (self->engine == nullptr) {
1272  return;
1273  }
1274 
1275  self->embedder_api.UpdateAccessibilityFeatures(
1276  self->engine, static_cast<FlutterAccessibilityFeature>(flags));
1277 }
1278 
1279 void fl_engine_request_app_exit(FlEngine* self) {
1280  g_return_if_fail(FL_IS_ENGINE(self));
1281  fl_platform_handler_request_app_exit(self->platform_handler);
1282 }
1283 
1284 FlWindowingHandler* fl_engine_get_windowing_handler(FlEngine* self) {
1285  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1286  return self->windowing_handler;
1287 }
1288 
1289 FlKeyboardManager* fl_engine_get_keyboard_manager(FlEngine* self) {
1290  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1291  return self->keyboard_manager;
1292 }
1293 
1294 FlTextInputHandler* fl_engine_get_text_input_handler(FlEngine* self) {
1295  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1296  return self->text_input_handler;
1297 }
1298 
1299 FlMouseCursorHandler* fl_engine_get_mouse_cursor_handler(FlEngine* self) {
1300  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1301  return self->mouse_cursor_handler;
1302 }
_FlEngine::platform_message_handler_data
gpointer platform_message_handler_data
Definition: fl_engine.cc:98
fl_engine_set_platform_message_handler
void fl_engine_set_platform_message_handler(FlEngine *self, FlEnginePlatformMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_engine.cc:820
prop_id
guint prop_id
Definition: fl_standard_method_codec.cc:31
fl_dart_project_get_aot_library_path
const G_MODULE_EXPORT gchar * fl_dart_project_get_aot_library_path(FlDartProject *self)
Definition: fl_dart_project.cc:72
_FlEngine::platform_handler
FlPlatformHandler * platform_handler
Definition: fl_engine.cc:60
fl_binary_messenger_shutdown
void fl_binary_messenger_shutdown(FlBinaryMessenger *self)
Definition: fl_binary_messenger.cc:500
_FlEngine::mouse_cursor_handler
FlMouseCursorHandler * mouse_cursor_handler
Definition: fl_engine.cc:75
fl_settings_handler_new
FlSettingsHandler * fl_settings_handler_new(FlEngine *engine)
Definition: fl_settings_handler.cc:74
SIGNAL_UPDATE_SEMANTICS
@ SIGNAL_UPDATE_SEMANTICS
Definition: fl_engine.cc:107
fl_renderer_present_layers
gboolean fl_renderer_present_layers(FlRenderer *self, FlutterViewId view_id, const FlutterLayer **layers, size_t layers_count)
Definition: fl_renderer.cc:453
FlEnginePlatformMessageHandler
gboolean(* FlEnginePlatformMessageHandler)(FlEngine *engine, const gchar *channel, GBytes *message, const FlutterPlatformMessageResponseHandle *response_handle, gpointer user_data)
Definition: fl_engine_private.h:46
fl_engine_get_embedder_api
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:721
_FlEngine::embedder_api
FlutterEngineProcTable embedder_api
Definition: fl_engine.cc:91
fl_engine_init
static void fl_engine_init(FlEngine *self)
Definition: fl_engine.cc:523
fl_engine_platform_message_response_cb
static void fl_engine_platform_message_response_cb(const uint8_t *data, size_t data_length, void *user_data)
Definition: fl_engine.cc:424
fl_engine_gl_get_fbo
static uint32_t fl_engine_gl_get_fbo(void *user_data)
Definition: fl_engine.cc:289
_FlEngine::renderer
FlRenderer * renderer
Definition: fl_engine.cc:51
fl_engine_send_touch_move_event
void fl_engine_send_touch_move_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:1047
fl_engine_gl_make_resource_current
static bool fl_engine_gl_make_resource_current(void *user_data)
Definition: fl_engine.cc:300
FL_ENGINE_ERROR_FAILED
@ FL_ENGINE_ERROR_FAILED
Definition: fl_engine_private.h:29
kMousePointerDeviceId
static constexpr int32_t kMousePointerDeviceId
Definition: fl_engine.cc:35
fl_engine_update_accessibility_features
void fl_engine_update_accessibility_features(FlEngine *self, int32_t flags)
Definition: fl_engine.cc:1268
fl_engine_new_full
static FlEngine * fl_engine_new_full(FlDartProject *project, FlRenderer *renderer, FlBinaryMessenger *binary_messenger)
Definition: fl_engine.cc:541
_FlEngine::next_view_id
FlutterViewId next_view_id
Definition: fl_engine.cc:94
fl_engine_send_key_event_finish
gboolean fl_engine_send_key_event_finish(FlEngine *self, GAsyncResult *result, gboolean *handled, GError **error)
Definition: fl_engine.cc:1187
fl_plugin_registrar_private.h
fl_texture_gl_private.h
fl_texture_registrar_lookup_texture
FlTexture * fl_texture_registrar_lookup_texture(FlTextureRegistrar *self, int64_t texture_id)
Definition: fl_texture_registrar.cc:190
fl_text_input_handler_new
FlTextInputHandler * fl_text_input_handler_new(FlBinaryMessenger *messenger)
Definition: fl_text_input_handler.cc:422
fl_mouse_cursor_handler_new
FlMouseCursorHandler * fl_mouse_cursor_handler_new(FlBinaryMessenger *messenger)
Definition: fl_mouse_cursor_handler.cc:134
compositor_present_view_callback
static bool compositor_present_view_callback(const FlutterPresentViewInfo *info)
Definition: fl_engine.cc:263
fl_platform_handler_request_app_exit
void fl_platform_handler_request_app_exit(FlPlatformHandler *self)
Definition: fl_platform_handler.cc:264
fl_engine_get_keyboard_manager
FlKeyboardManager * fl_engine_get_keyboard_manager(FlEngine *self)
Definition: fl_engine.cc:1289
fl_engine_new_headless
G_MODULE_EXPORT FlEngine * fl_engine_new_headless(FlDartProject *project)
Definition: fl_engine.cc:592
PROP_0
@ PROP_0
Definition: fl_accessible_node.cc:84
i
int i
Definition: fl_socket_accessible.cc:18
fl_engine_signals
static guint fl_engine_signals[LAST_SIGNAL]
Definition: fl_engine.cc:109
fl_engine_get_renderer
FlRenderer * fl_engine_get_renderer(FlEngine *self)
Definition: fl_engine.cc:597
fl_engine_send_touch_remove_event
void fl_engine_send_touch_remove_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:1099
fl_settings_new
FlSettings * fl_settings_new()
Definition: fl_settings.cc:55
_FlEngine::aot_data
FlutterEngineAOTData aot_data
Definition: fl_engine.cc:84
fl_engine_gl_present
static bool fl_engine_gl_present(void *user_data)
Definition: fl_engine.cc:294
flags
FlutterSemanticsFlag flags
Definition: fl_accessible_node.cc:106
fl_engine_dispose
static void fl_engine_dispose(GObject *object)
Definition: fl_engine.cc:463
fl_engine_mark_texture_frame_available
gboolean fl_engine_mark_texture_frame_available(FlEngine *self, int64_t texture_id)
Definition: fl_engine.cc:1225
fl_engine_remove_view
void fl_engine_remove_view(FlEngine *self, FlutterViewId view_id, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:788
id
int64_t id
Definition: fl_pixel_buffer_texture.cc:28
fl_engine_dispatch_semantics_action
void fl_engine_dispatch_semantics_action(FlEngine *self, uint64_t id, FlutterSemanticsAction action, GBytes *data)
Definition: fl_engine.cc:1204
fl_texture_registrar_new
FlTextureRegistrar * fl_texture_registrar_new(FlEngine *engine)
Definition: fl_texture_registrar.cc:221
pspec
guint const GValue GParamSpec * pspec
Definition: fl_standard_method_codec.cc:33
SIGNAL_ON_PRE_ENGINE_RESTART
@ SIGNAL_ON_PRE_ENGINE_RESTART
Definition: fl_engine.cc:107
fl_platform_handler_new
FlPlatformHandler * fl_platform_handler_new(FlBinaryMessenger *messenger)
Definition: fl_platform_handler.cc:251
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:50
fl_engine_on_pre_engine_restart_cb
static void fl_engine_on_pre_engine_restart_cb(void *user_data)
Definition: fl_engine.cc:414
fl_renderer_headless.h
fl_dart_project_get_assets_path
const G_MODULE_EXPORT gchar * fl_dart_project_get_assets_path(FlDartProject *self)
Definition: fl_dart_project.cc:85
fl_renderer_clear_current
void fl_renderer_clear_current(FlRenderer *self)
Definition: fl_renderer.cc:379
fl_engine_get_binary_messenger
G_MODULE_EXPORT FlBinaryMessenger * fl_engine_get_binary_messenger(FlEngine *self)
Definition: fl_engine.cc:1246
fl_engine_send_key_event
void fl_engine_send_key_event(FlEngine *self, const FlutterKeyEvent *event, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:1164
fl_renderer_get_proc_address
void * fl_renderer_get_proc_address(FlRenderer *self, const char *name)
Definition: fl_renderer.cc:363
fl_binary_messenger_new
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
Definition: fl_binary_messenger.cc:391
kPlatformTaskRunnerIdentifier
static constexpr size_t kPlatformTaskRunnerIdentifier
Definition: fl_engine.cc:31
fl_engine_new_with_renderer
FlEngine * fl_engine_new_with_renderer(FlDartProject *project, FlRenderer *renderer)
Definition: fl_engine.cc:573
fl_keyboard_handler.h
fl_renderer_set_engine
void fl_renderer_set_engine(FlRenderer *self, FlEngine *engine)
Definition: fl_renderer.cc:332
_FlEngine::text_input_handler
FlTextInputHandler * text_input_handler
Definition: fl_engine.cc:69
view_removed_cb
static void view_removed_cb(const FlutterRemoveViewResult *result)
Definition: fl_engine.cc:175
user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
Definition: fl_event_channel.h:90
_FlEngine::project
FlDartProject * project
Definition: fl_engine.cc:45
_FlEngine::display_monitor
FlDisplayMonitor * display_monitor
Definition: fl_engine.cc:48
fl_engine_set_property
static void fl_engine_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
Definition: fl_engine.cc:447
_FlEngine
Definition: fl_engine.cc:38
G_DEFINE_QUARK
G_DEFINE_QUARK(fl_binary_messenger_codec_error_quark, fl_binary_messenger_codec_error) G_DECLARE_FINAL_TYPE(FlBinaryMessengerImpl
G_DEFINE_TYPE_WITH_CODE
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)) enum
Definition: fl_engine.cc:111
fl_display_monitor_new
FlDisplayMonitor * fl_display_monitor_new(FlEngine *engine, GdkDisplay *display)
Definition: fl_display_monitor.cc:94
_FlEngine::windowing_handler
FlWindowingHandler * windowing_handler
Definition: fl_engine.cc:63
fl_engine_update_semantics_cb
static void fl_engine_update_semantics_cb(const FlutterSemanticsUpdate2 *update, void *user_data)
Definition: fl_engine.cc:383
fl_engine_add_view_finish
gboolean fl_engine_add_view_finish(FlEngine *self, GAsyncResult *result, GError **error)
Definition: fl_engine.cc:781
fl_keyboard_handler_new
FlKeyboardHandler * fl_keyboard_handler_new(FlBinaryMessenger *messenger, FlKeyboardManager *keyboard_manager)
Definition: fl_keyboard_handler.cc:63
fl_text_input_handler_set_widget
void fl_text_input_handler_set_widget(FlTextInputHandler *self, GtkWidget *widget)
Definition: fl_text_input_handler.cc:464
free_locale
static void free_locale(FlutterLocale *locale)
Definition: fl_engine.cc:186
fl_renderer_collect_backing_store
gboolean fl_renderer_collect_backing_store(FlRenderer *self, const FlutterBackingStore *backing_store)
Definition: fl_renderer.cc:423
fl_engine_remove_view_finish
gboolean fl_engine_remove_view_finish(FlEngine *self, GAsyncResult *result, GError **error)
Definition: fl_engine.cc:813
fl_pixel_buffer_texture_populate
gboolean fl_pixel_buffer_texture_populate(FlPixelBufferTexture *texture, uint32_t width, uint32_t height, FlutterOpenGLTexture *opengl_texture, GError **error)
Definition: fl_pixel_buffer_texture.cc:71
fl_renderer_headless_new
FlRendererHeadless * fl_renderer_headless_new()
Definition: fl_renderer_headless.cc:31
fl_texture_registrar_shutdown
void fl_texture_registrar_shutdown(FlTextureRegistrar *self)
Definition: fl_texture_registrar.cc:215
_FlEngine::keyboard_manager
FlKeyboardManager * keyboard_manager
Definition: fl_engine.cc:66
fl_task_runner_post_task
void fl_task_runner_post_task(FlTaskRunner *self, FlutterTask task, uint64_t target_time_nanos)
Definition: fl_task_runner.cc:161
fl_engine_plugin_registry_iface_init
static void fl_engine_plugin_registry_iface_init(FlPluginRegistryInterface *iface)
Definition: fl_engine.cc:442
fl_settings_handler.h
fl_engine_private.h
fl_engine_gl_external_texture_frame_callback
static bool fl_engine_gl_external_texture_frame_callback(void *user_data, int64_t texture_id, size_t width, size_t height, FlutterOpenGLTexture *opengl_texture)
Definition: fl_engine.cc:307
fl_engine_request_app_exit
void fl_engine_request_app_exit(FlEngine *self)
Definition: fl_engine.cc:1279
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
PROP_LAST
@ PROP_LAST
Definition: fl_accessible_node.cc:84
flutter::GetSwitchesFromEnvironment
std::vector< std::string > GetSwitchesFromEnvironment()
Definition: engine_switches.cc:14
_FlEngine::FLUTTER_API_SYMBOL
FLUTTER_API_SYMBOL(FlutterEngine) engine
fl_engine_get_text_input_handler
FlTextInputHandler * fl_engine_get_text_input_handler(FlEngine *self)
Definition: fl_engine.cc:1294
_FlEngine::platform_message_handler_destroy_notify
GDestroyNotify platform_message_handler_destroy_notify
Definition: fl_engine.cc:99
engine_switches.h
_FlEngine::settings_handler
FlSettingsHandler * settings_handler
Definition: fl_engine.cc:57
fl_dart_project_get_dart_entrypoint_arguments
G_MODULE_EXPORT gchar ** fl_dart_project_get_dart_entrypoint_arguments(FlDartProject *self)
Definition: fl_dart_project.cc:104
fl_renderer.h
fl_platform_handler.h
fl_renderer_make_resource_current
void fl_renderer_make_resource_current(FlRenderer *self)
Definition: fl_renderer.cc:374
fl_engine_send_platform_message_finish
GBytes * fl_engine_send_platform_message_finish(FlEngine *self, GAsyncResult *result, GError **error)
Definition: fl_engine.cc:930
fl_engine_add_view
FlutterViewId fl_engine_add_view(FlEngine *self, size_t width, size_t height, double pixel_ratio, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:738
fl_engine_get_mouse_cursor_handler
FlMouseCursorHandler * fl_engine_get_mouse_cursor_handler(FlEngine *self)
Definition: fl_engine.cc:1299
fl_engine_get_display_monitor
FlDisplayMonitor * fl_engine_get_display_monitor(FlEngine *self)
Definition: fl_engine.cc:602
fl_settings_handler_start
void fl_settings_handler_start(FlSettingsHandler *self, FlSettings *settings)
Definition: fl_settings_handler.cc:88
fl_engine_runs_task_on_current_thread
static bool fl_engine_runs_task_on_current_thread(void *user_data)
Definition: fl_engine.cc:348
fl_renderer_gdk.h
fl_text_input_handler_get_widget
GtkWidget * fl_text_input_handler_get_widget(FlTextInputHandler *self)
Definition: fl_text_input_handler.cc:472
height
const uint8_t uint32_t uint32_t * height
Definition: fl_pixel_buffer_texture_test.cc:39
fl_texture_gl_populate
gboolean fl_texture_gl_populate(FlTextureGL *self, uint32_t width, uint32_t height, FlutterOpenGLTexture *opengl_texture, GError **error)
Definition: fl_texture_gl.cc:50
fl_binary_messenger_private.h
fl_engine_get_registrar_for_plugin
static FlPluginRegistrar * fl_engine_get_registrar_for_plugin(FlPluginRegistry *registry, const gchar *name)
Definition: fl_engine.cc:433
fl_pixel_buffer_texture_private.h
view_added_cb
static void view_added_cb(const FlutterAddViewResult *result)
Definition: fl_engine.cc:164
fl_engine_new
G_MODULE_EXPORT FlEngine * fl_engine_new(FlDartProject *project)
Definition: fl_engine.cc:580
fl_engine_send_touch_down_event
void fl_engine_send_touch_down_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:1021
fl_engine_get_windowing_handler
FlWindowingHandler * fl_engine_get_windowing_handler(FlEngine *self)
Definition: fl_engine.cc:1284
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
fl_engine.h
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_engine_for_id
FlEngine * fl_engine_for_id(int64_t id)
Definition: fl_engine.cc:567
compositor_collect_backing_store_callback
static bool compositor_collect_backing_store_callback(const FlutterBackingStore *backing_store, void *user_data)
Definition: fl_engine.cc:254
fl_engine_get_task_runner
FlTaskRunner * fl_engine_get_task_runner(FlEngine *self)
Definition: fl_engine.cc:1252
fl_renderer_make_current
void fl_renderer_make_current(FlRenderer *self)
Definition: fl_renderer.cc:369
fl_keyboard_manager_new
FlKeyboardManager * fl_keyboard_manager_new(FlEngine *engine)
Definition: fl_keyboard_manager.cc:356
fl_engine_gl_proc_resolver
static void * fl_engine_gl_proc_resolver(void *user_data, const char *name)
Definition: fl_engine.cc:272
fl_engine_send_pointer_pan_zoom_event
void fl_engine_send_pointer_pan_zoom_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, FlutterPointerPhase phase, double pan_x, double pan_y, double scale, double rotation)
Definition: fl_engine.cc:1125
_FlEngine::thread
GThread * thread
Definition: fl_engine.cc:42
_FlEngine::binary_messenger
FlBinaryMessenger * binary_messenger
Definition: fl_engine.cc:54
fl_engine_send_platform_message
void fl_engine_send_platform_message(FlEngine *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:871
setup_locales
static void setup_locales(FlEngine *self)
Definition: fl_engine.cc:193
fl_engine_send_touch_add_event
void fl_engine_send_touch_add_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:1073
fl_renderer_gdk_new
FlRendererGdk * fl_renderer_gdk_new()
Definition: fl_renderer_gdk.cc:63
parse_locale
static void parse_locale(const gchar *locale, gchar **language, gchar **territory, gchar **codeset, gchar **modifier)
Definition: fl_engine.cc:121
fl_renderer_create_backing_store
gboolean fl_renderer_create_backing_store(FlRenderer *self, const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
Definition: fl_renderer.cc:391
compositor_create_backing_store_callback
static bool compositor_create_backing_store_callback(const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out, void *user_data)
Definition: fl_engine.cc:244
_FlEngine::texture_registrar
FlTextureRegistrar * texture_registrar
Definition: fl_engine.cc:78
fl_dart_project_private.h
fl_engine_start
gboolean fl_engine_start(FlEngine *self, GError **error)
Definition: fl_engine.cc:607
fl_texture_registrar_private.h
_FlEngine::keyboard_handler
FlKeyboardHandler * keyboard_handler
Definition: fl_engine.cc:72
_FlEngine::task_runner
FlTaskRunner * task_runner
Definition: fl_engine.cc:81
send_key_event_cb
static void send_key_event_cb(bool handled, void *user_data)
Definition: fl_engine.cc:1157
fl_windowing_handler.h
fl_engine_register_external_texture
gboolean fl_engine_register_external_texture(FlEngine *self, int64_t texture_id)
Definition: fl_engine.cc:1232
fl_display_monitor_start
void fl_display_monitor_start(FlDisplayMonitor *self)
Definition: fl_display_monitor.cc:103
fl_plugin_registrar_new
FlPluginRegistrar * fl_plugin_registrar_new(FlView *view, FlBinaryMessenger *messenger, FlTextureRegistrar *texture_registrar)
Definition: fl_plugin_registrar.cc:84
fl_engine_notify_display_update
void fl_engine_notify_display_update(FlEngine *self, const FlutterEngineDisplay *displays, size_t displays_length)
Definition: fl_engine.cc:725
fl_plugin_registry.h
fl_engine_execute_task
void fl_engine_execute_task(FlEngine *self, FlutterTask *task)
Definition: fl_engine.cc:1257
fl_engine_error_quark
GQuark fl_engine_error_quark(void) G_GNUC_CONST
fl_engine_unregister_external_texture
gboolean fl_engine_unregister_external_texture(FlEngine *self, int64_t texture_id)
Definition: fl_engine.cc:1239
fl_engine_send_window_metrics_event
void fl_engine_send_window_metrics_event(FlEngine *self, FlutterEngineDisplayId display_id, FlutterViewId view_id, size_t width, size_t height, double pixel_ratio)
Definition: fl_engine.cc:939
fl_dart_project_get_icu_data_path
const G_MODULE_EXPORT gchar * fl_dart_project_get_icu_data_path(FlDartProject *self)
Definition: fl_dart_project.cc:98
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24
width
const uint8_t uint32_t * width
Definition: fl_pixel_buffer_texture_test.cc:38
fl_engine_new_with_binary_messenger
FlEngine * fl_engine_new_with_binary_messenger(FlBinaryMessenger *binary_messenger)
Definition: fl_engine.cc:585
fl_engine_gl_make_current
static bool fl_engine_gl_make_current(void *user_data)
Definition: fl_engine.cc:277
fl_engine_send_mouse_pointer_event
void fl_engine_send_mouse_pointer_event(FlEngine *self, FlutterViewId view_id, FlutterPointerPhase phase, size_t timestamp, double x, double y, FlutterPointerDeviceKind device_kind, double scroll_delta_x, double scroll_delta_y, int64_t buttons)
Definition: fl_engine.cc:961
fl_renderer_get_fbo
guint32 fl_renderer_get_fbo(FlRenderer *self)
Definition: fl_renderer.cc:384
fl_display_monitor.h
fl_engine_post_task
static void fl_engine_post_task(FlutterTask task, uint64_t target_time_nanos, void *user_data)
Definition: fl_engine.cc:354
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
fl_task_runner_new
FlTaskRunner * fl_task_runner_new(FlEngine *engine)
Definition: fl_task_runner.cc:154
fl_engine_get_texture_registrar
G_MODULE_EXPORT FlTextureRegistrar * fl_engine_get_texture_registrar(FlEngine *self)
Definition: fl_engine.cc:1262
fl_windowing_handler_new
FlWindowingHandler * fl_windowing_handler_new(FlEngine *engine)
Definition: fl_windowing_handler.cc:260
fl_engine_send_platform_message_response
gboolean fl_engine_send_platform_message_response(FlEngine *self, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
Definition: fl_engine.cc:839
_FlEngine::platform_message_handler
FlEnginePlatformMessageHandler platform_message_handler
Definition: fl_engine.cc:97
fl_engine_send_touch_up_event
void fl_engine_send_touch_up_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:995
fl_engine_class_init
static void fl_engine_class_init(FlEngineClass *klass)
Definition: fl_engine.cc:503
LAST_SIGNAL
@ LAST_SIGNAL
Definition: fl_engine.cc:107
fl_engine_platform_message_cb
static void fl_engine_platform_message_cb(const FlutterPlatformMessage *message, void *user_data)
Definition: fl_engine.cc:363
kPointerPanZoomDeviceId
static constexpr int32_t kPointerPanZoomDeviceId
Definition: fl_engine.cc:36
setup_keyboard
static void setup_keyboard(FlEngine *self)
Definition: fl_engine.cc:390
_FlEngine::parent_instance
GObject parent_instance
Definition: fl_engine.cc:39
g_signal_emit
g_signal_emit(self, fl_application_signals[SIGNAL_CREATE_WINDOW], 0, view, &window)
fl_engine_gl_clear_current
static bool fl_engine_gl_clear_current(void *user_data)
Definition: fl_engine.cc:283