Flutter Linux Embedder
fl_engine.cc File Reference

Go to the source code of this file.

Classes

struct  _FlEngine
 

Enumerations

enum  {
  kSignalOnPreEngineRestart,
  kSignalLastSignal
}
 

Functions

static void fl_engine_plugin_registry_iface_init (FlPluginRegistryInterface *iface)
 
 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
 
static void parse_locale (const gchar *locale, gchar **language, gchar **territory, gchar **codeset, gchar **modifier)
 
static void view_added_cb (const FlutterAddViewResult *result)
 
static void view_removed_cb (const FlutterRemoveViewResult *result)
 
static void free_locale (FlutterLocale *locale)
 
static void setup_locales (FlEngine *self)
 
static bool compositor_create_backing_store_callback (const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out, void *user_data)
 
static bool compositor_collect_backing_store_callback (const FlutterBackingStore *backing_store, void *user_data)
 
static bool compositor_present_view_callback (const FlutterPresentViewInfo *info)
 
static void * fl_engine_gl_proc_resolver (void *user_data, const char *name)
 
static bool fl_engine_gl_make_current (void *user_data)
 
static bool fl_engine_gl_clear_current (void *user_data)
 
static uint32_t fl_engine_gl_get_fbo (void *user_data)
 
static bool fl_engine_gl_present (void *user_data)
 
static bool fl_engine_gl_make_resource_current (void *user_data)
 
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)
 
static bool fl_engine_runs_task_on_current_thread (void *user_data)
 
static void fl_engine_post_task (FlutterTask task, uint64_t target_time_nanos, void *user_data)
 
static void fl_engine_platform_message_cb (const FlutterPlatformMessage *message, void *user_data)
 
static void fl_engine_update_semantics_cb (const FlutterSemanticsUpdate2 *update, void *user_data)
 
static void fl_engine_on_pre_engine_restart_cb (void *user_data)
 
static void fl_engine_platform_message_response_cb (const uint8_t *data, size_t data_length, void *user_data)
 
static FlPluginRegistrar * fl_engine_get_registrar_for_plugin (FlPluginRegistry *registry, const gchar *name)
 
static void fl_engine_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 
static void fl_engine_dispose (GObject *object)
 
static void fl_engine_class_init (FlEngineClass *klass)
 
static void fl_engine_init (FlEngine *self)
 
FlEngine * fl_engine_new_with_renderer (FlDartProject *project, FlRenderer *renderer)
 
G_MODULE_EXPORT FlEngine * fl_engine_new (FlDartProject *project)
 
G_MODULE_EXPORT FlEngine * fl_engine_new_headless (FlDartProject *project)
 
FlRenderer * fl_engine_get_renderer (FlEngine *self)
 
gboolean fl_engine_start (FlEngine *self, GError **error)
 
FlutterEngineProcTable * fl_engine_get_embedder_api (FlEngine *self)
 
FlutterViewId fl_engine_add_view (FlEngine *self, size_t width, size_t height, double pixel_ratio, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
 
gboolean fl_engine_add_view_finish (FlEngine *self, GAsyncResult *result, GError **error)
 
void fl_engine_remove_view (FlEngine *self, FlutterViewId view_id, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
 
gboolean fl_engine_remove_view_finish (FlEngine *self, GAsyncResult *result, GError **error)
 
void fl_engine_set_platform_message_handler (FlEngine *self, FlEnginePlatformMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
 
void fl_engine_set_update_semantics_handler (FlEngine *self, FlEngineUpdateSemanticsHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
 
gboolean fl_engine_send_platform_message_response (FlEngine *self, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
 
void fl_engine_send_platform_message (FlEngine *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
 
GBytes * fl_engine_send_platform_message_finish (FlEngine *self, GAsyncResult *result, GError **error)
 
void fl_engine_send_window_metrics_event (FlEngine *self, FlutterViewId view_id, size_t width, size_t height, double pixel_ratio)
 
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)
 
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)
 
void fl_engine_send_key_event (FlEngine *self, const FlutterKeyEvent *event, FlutterKeyEventCallback callback, void *user_data)
 
void fl_engine_dispatch_semantics_action (FlEngine *self, uint64_t id, FlutterSemanticsAction action, GBytes *data)
 
gboolean fl_engine_mark_texture_frame_available (FlEngine *self, int64_t texture_id)
 
gboolean fl_engine_register_external_texture (FlEngine *self, int64_t texture_id)
 
gboolean fl_engine_unregister_external_texture (FlEngine *self, int64_t texture_id)
 
G_MODULE_EXPORT FlBinaryMessenger * fl_engine_get_binary_messenger (FlEngine *self)
 
FlTaskRunner * fl_engine_get_task_runner (FlEngine *self)
 
void fl_engine_execute_task (FlEngine *self, FlutterTask *task)
 
G_MODULE_EXPORT FlTextureRegistrar * fl_engine_get_texture_registrar (FlEngine *self)
 
void fl_engine_update_accessibility_features (FlEngine *self, int32_t flags)
 
GPtrArray * fl_engine_get_switches (FlEngine *self)
 

Variables

static constexpr size_t kPlatformTaskRunnerIdentifier = 1
 
static constexpr int32_t kMousePointerDeviceId = 0
 
static constexpr int32_t kPointerPanZoomDeviceId = 1
 
static guint fl_engine_signals [kSignalLastSignal]
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kSignalOnPreEngineRestart 
kSignalLastSignal 

Definition at line 72 of file fl_engine.cc.

Function Documentation

◆ compositor_collect_backing_store_callback()

static bool compositor_collect_backing_store_callback ( const FlutterBackingStore *  backing_store,
void *  user_data 
)
static

Definition at line 219 of file fl_engine.cc.

221  {
222  g_return_val_if_fail(FL_IS_RENDERER(user_data), false);
223  return fl_renderer_collect_backing_store(FL_RENDERER(user_data),
224  backing_store);
225 }

References fl_renderer_collect_backing_store(), and user_data.

Referenced by fl_engine_start().

◆ compositor_create_backing_store_callback()

static bool compositor_create_backing_store_callback ( const FlutterBackingStoreConfig *  config,
FlutterBackingStore *  backing_store_out,
void *  user_data 
)
static

Definition at line 209 of file fl_engine.cc.

212  {
213  g_return_val_if_fail(FL_IS_RENDERER(user_data), false);
214  return fl_renderer_create_backing_store(FL_RENDERER(user_data), config,
215  backing_store_out);
216 }

References fl_renderer_create_backing_store(), and user_data.

Referenced by fl_engine_start().

◆ compositor_present_view_callback()

static bool compositor_present_view_callback ( const FlutterPresentViewInfo *  info)
static

Definition at line 228 of file fl_engine.cc.

229  {
230  g_return_val_if_fail(FL_IS_RENDERER(info->user_data), false);
231  return fl_renderer_present_layers(FL_RENDERER(info->user_data), info->view_id,
232  info->layers, info->layers_count);
233 }

References fl_renderer_present_layers().

Referenced by fl_engine_start().

◆ fl_engine_add_view()

FlutterViewId fl_engine_add_view ( FlEngine *  engine,
size_t  width,
size_t  height,
double  pixel_ratio,
GCancellable *  cancellable,
GAsyncReadyCallback  callback,
gpointer  user_data 
)

fl_engine_add_view: @engine: an #FlEngine. @width: width of view in pixels. @height: height of view in pixels. @pixel_ratio: scale factor for view. @cancellable: (allow-none): a #GCancellable or NULL. @callback: (scope async): a #GAsyncReadyCallback to call when the view is added. @user_data: (closure): user data to pass to @callback.

Asynchronously add a new view. The returned view ID should not be used until this function completes.

Returns: the ID for the view.

Definition at line 641 of file fl_engine.cc.

647  {
648  g_return_val_if_fail(FL_IS_ENGINE(self), -1);
649 
650  g_autoptr(GTask) task = g_task_new(self, cancellable, callback, user_data);
651 
652  FlutterViewId view_id = self->next_view_id;
653  self->next_view_id++;
654 
655  FlutterWindowMetricsEvent metrics;
656  metrics.struct_size = sizeof(FlutterWindowMetricsEvent);
657  metrics.width = width;
658  metrics.height = height;
659  metrics.pixel_ratio = pixel_ratio;
660  metrics.view_id = view_id;
661  FlutterAddViewInfo info;
662  info.struct_size = sizeof(FlutterAddViewInfo);
663  info.view_id = view_id;
664  info.view_metrics = &metrics;
665  info.user_data = g_object_ref(task);
666  info.add_view_callback = view_added_cb;
667  FlutterEngineResult result = self->embedder_api.AddView(self->engine, &info);
668  if (result != kSuccess) {
669  g_task_return_new_error(task, fl_engine_error_quark(),
670  FL_ENGINE_ERROR_FAILED, "AddView returned %d",
671  result);
672  // This would have been done in the callback, but that won't occur now.
673  g_object_unref(task);
674  }
675 
676  return view_id;
677 }

References callback, FL_ENGINE_ERROR_FAILED, fl_engine_error_quark(), height, result, user_data, view_added_cb(), and width.

Referenced by fl_view_new_for_engine(), and TEST().

◆ fl_engine_add_view_finish()

gboolean fl_engine_add_view_finish ( FlEngine *  engine,
GAsyncResult *  result,
GError **  error 
)

fl_engine_add_view_finish: @engine: an #FlEngine.

Returns
: a #GAsyncResult. @error: (allow-none): #GError location to store the error occurring, or NULL to ignore.

Completes request started with fl_engine_add_view().

Returns: TRUE on success.

Definition at line 679 of file fl_engine.cc.

681  {
682  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
683  return g_task_propagate_boolean(G_TASK(result), error);
684 }

References error, and result.

Referenced by add_view_cb(), add_view_engine_error_cb(), add_view_error_cb(), and view_added_cb().

◆ fl_engine_class_init()

static void fl_engine_class_init ( FlEngineClass *  klass)
static

Definition at line 450 of file fl_engine.cc.

450  {
451  G_OBJECT_CLASS(klass)->dispose = fl_engine_dispose;
452  G_OBJECT_CLASS(klass)->set_property = fl_engine_set_property;
453 
454  g_object_class_install_property(
455  G_OBJECT_CLASS(klass), kPropBinaryMessenger,
456  g_param_spec_object(
457  "binary-messenger", "messenger", "Binary messenger",
458  fl_binary_messenger_get_type(),
459  static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
460  G_PARAM_STATIC_STRINGS)));
461 
463  "on-pre-engine-restart", fl_engine_get_type(), G_SIGNAL_RUN_LAST, 0,
464  nullptr, nullptr, nullptr, G_TYPE_NONE, 0);
465 }

References fl_engine_dispose(), fl_engine_set_property(), fl_engine_signals, and kSignalOnPreEngineRestart.

◆ fl_engine_dispatch_semantics_action()

void fl_engine_dispatch_semantics_action ( FlEngine *  engine,
uint64_t  id,
FlutterSemanticsAction  action,
GBytes *  data 
)

fl_engine_dispatch_semantics_action: @engine: an #FlEngine. @id: the semantics action identifier. @action: the action being dispatched. @data: (allow-none): data associated with the action.

Definition at line 953 of file fl_engine.cc.

956  {
957  g_return_if_fail(FL_IS_ENGINE(self));
958 
959  if (self->engine == nullptr) {
960  return;
961  }
962 
963  const uint8_t* action_data = nullptr;
964  size_t action_data_length = 0;
965  if (data != nullptr) {
966  action_data = static_cast<const uint8_t*>(
967  g_bytes_get_data(data, &action_data_length));
968  }
969 
970  self->embedder_api.DispatchSemanticsAction(self->engine, id, action,
971  action_data, action_data_length);
972 }

Referenced by fl_accessible_node_perform_action_impl(), and TEST().

◆ fl_engine_dispose()

static void fl_engine_dispose ( GObject *  object)
static

Definition at line 410 of file fl_engine.cc.

410  {
411  FlEngine* self = FL_ENGINE(object);
412 
413  if (self->engine != nullptr) {
414  self->embedder_api.Shutdown(self->engine);
415  self->engine = nullptr;
416  }
417 
418  if (self->aot_data != nullptr) {
419  self->embedder_api.CollectAOTData(self->aot_data);
420  self->aot_data = nullptr;
421  }
422 
423  fl_binary_messenger_shutdown(self->binary_messenger);
424  fl_texture_registrar_shutdown(self->texture_registrar);
425 
426  g_clear_object(&self->project);
427  g_clear_object(&self->renderer);
428  g_clear_object(&self->texture_registrar);
429  g_clear_object(&self->binary_messenger);
430  g_clear_object(&self->settings_handler);
431  g_clear_object(&self->task_runner);
432 
433  if (self->platform_message_handler_destroy_notify) {
434  self->platform_message_handler_destroy_notify(
435  self->platform_message_handler_data);
436  }
437  self->platform_message_handler_data = nullptr;
438  self->platform_message_handler_destroy_notify = nullptr;
439 
440  if (self->update_semantics_handler_destroy_notify) {
441  self->update_semantics_handler_destroy_notify(
442  self->update_semantics_handler_data);
443  }
444  self->update_semantics_handler_data = nullptr;
445  self->update_semantics_handler_destroy_notify = nullptr;
446 
447  G_OBJECT_CLASS(fl_engine_parent_class)->dispose(object);
448 }

References fl_binary_messenger_shutdown(), and fl_texture_registrar_shutdown().

Referenced by fl_engine_class_init().

◆ fl_engine_execute_task()

void fl_engine_execute_task ( FlEngine *  engine,
FlutterTask *  task 
)

fl_engine_execute_task: @engine: an #FlEngine. @task: a #FlutterTask to execute.

Executes given Flutter task.

Definition at line 1006 of file fl_engine.cc.

1006  {
1007  g_return_if_fail(FL_IS_ENGINE(self));
1008  self->embedder_api.RunTask(self->engine, task);
1009 }

Referenced by fl_task_runner_process_expired_tasks_locked().

◆ fl_engine_get_binary_messenger()

G_MODULE_EXPORT FlBinaryMessenger* fl_engine_get_binary_messenger ( FlEngine *  engine)

fl_engine_get_binary_messenger: @engine: an #FlEngine.

Gets the messenger to communicate with this engine.

Returns: an #FlBinaryMessenger.

Definition at line 995 of file fl_engine.cc.

996  {
997  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
998  return self->binary_messenger;
999 }

Referenced by create_context_cb(), fl_settings_handler_new(), fl_view_get_registrar_for_plugin(), fl_view_keyboard_delegate_iface_init(), init_keyboard(), realize_cb(), and TEST().

◆ fl_engine_get_embedder_api()

FlutterEngineProcTable* fl_engine_get_embedder_api ( FlEngine *  engine)

fl_engine_get_embedder_api: @engine: an #FlEngine.

Gets the embedder API proc table, allowing modificiations for unit testing.

Returns: a mutable pointer to the embedder API proc table.

Definition at line 637 of file fl_engine.cc.

637  {
638  return &(self->embedder_api);
639 }

Referenced by TEST().

◆ fl_engine_get_registrar_for_plugin()

static FlPluginRegistrar* fl_engine_get_registrar_for_plugin ( FlPluginRegistry *  registry,
const gchar *  name 
)
static

Definition at line 380 of file fl_engine.cc.

382  {
383  FlEngine* self = FL_ENGINE(registry);
384 
385  return fl_plugin_registrar_new(nullptr, self->binary_messenger,
386  self->texture_registrar);
387 }

References fl_plugin_registrar_new().

Referenced by fl_engine_plugin_registry_iface_init().

◆ fl_engine_get_renderer()

FlRenderer* fl_engine_get_renderer ( FlEngine *  engine)

fl_engine_get_renderer: @engine: an #FlEngine.

Gets the renderer used by this engine.

Returns: an #FlRenderer.

Definition at line 504 of file fl_engine.cc.

504  {
505  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
506  return self->renderer;
507 }

Referenced by fl_view_new(), and fl_view_new_for_engine().

◆ fl_engine_get_switches()

GPtrArray* fl_engine_get_switches ( FlEngine *  engine)

fl_engine_get_switches: @project: an #FlEngine.

Determines the switches that should be passed to the Flutter engine.

Returns: an array of switches to pass to the Flutter engine.

Definition at line 1028 of file fl_engine.cc.

1028  {
1029  GPtrArray* switches = g_ptr_array_new_with_free_func(g_free);
1030  for (const auto& env_switch : flutter::GetSwitchesFromEnvironment()) {
1031  g_ptr_array_add(switches, g_strdup(env_switch.c_str()));
1032  }
1033  return switches;
1034 }

References flutter::GetSwitchesFromEnvironment().

Referenced by fl_engine_start(), and TEST().

◆ fl_engine_get_task_runner()

FlTaskRunner* fl_engine_get_task_runner ( FlEngine *  engine)

fl_engine_get_task_runner: @engine: an #FlEngine.

Returns
: a #FlTaskRunner.

Returns: task runner responsible for scheduling Flutter tasks.

Definition at line 1001 of file fl_engine.cc.

1001  {
1002  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1003  return self->task_runner;
1004 }

Referenced by fl_renderer_unblock_main_thread(), and fl_renderer_wait_for_frame().

◆ fl_engine_get_texture_registrar()

G_MODULE_EXPORT FlTextureRegistrar* fl_engine_get_texture_registrar ( FlEngine *  engine)

fl_engine_get_texture_registrar: @engine: an #FlEngine.

Gets the texture registrar for registering textures.

Returns: an #FlTextureRegistrar.

Definition at line 1011 of file fl_engine.cc.

1012  {
1013  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1014  return self->texture_registrar;
1015 }

Referenced by fl_view_get_registrar_for_plugin().

◆ fl_engine_gl_clear_current()

static bool fl_engine_gl_clear_current ( void *  user_data)
static

Definition at line 248 of file fl_engine.cc.

248  {
249  FlEngine* self = static_cast<FlEngine*>(user_data);
250  fl_renderer_clear_current(self->renderer);
251  return true;
252 }

References fl_renderer_clear_current(), and user_data.

Referenced by fl_engine_start().

◆ 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 
)
static

Definition at line 272 of file fl_engine.cc.

277  {
278  FlEngine* self = static_cast<FlEngine*>(user_data);
279  if (!self->texture_registrar) {
280  return false;
281  }
282 
283  FlTexture* texture =
284  fl_texture_registrar_lookup_texture(self->texture_registrar, texture_id);
285  if (texture == nullptr) {
286  g_warning("Unable to find texture %" G_GINT64_FORMAT, texture_id);
287  return false;
288  }
289 
290  gboolean result;
291  g_autoptr(GError) error = nullptr;
292  if (FL_IS_TEXTURE_GL(texture)) {
293  result = fl_texture_gl_populate(FL_TEXTURE_GL(texture), width, height,
294  opengl_texture, &error);
295  } else if (FL_IS_PIXEL_BUFFER_TEXTURE(texture)) {
296  result =
297  fl_pixel_buffer_texture_populate(FL_PIXEL_BUFFER_TEXTURE(texture),
298  width, height, opengl_texture, &error);
299  } else {
300  g_warning("Unsupported texture type %" G_GINT64_FORMAT, texture_id);
301  return false;
302  }
303 
304  if (!result) {
305  g_warning("%s", error->message);
306  return false;
307  }
308 
309  return true;
310 }

References error, fl_pixel_buffer_texture_populate(), fl_texture_gl_populate(), fl_texture_registrar_lookup_texture(), height, result, texture_id, user_data, and width.

Referenced by fl_engine_start().

◆ fl_engine_gl_get_fbo()

static uint32_t fl_engine_gl_get_fbo ( void *  user_data)
static

Definition at line 254 of file fl_engine.cc.

254  {
255  FlEngine* self = static_cast<FlEngine*>(user_data);
256  return fl_renderer_get_fbo(self->renderer);
257 }

References fl_renderer_get_fbo(), and user_data.

Referenced by fl_engine_start().

◆ fl_engine_gl_make_current()

static bool fl_engine_gl_make_current ( void *  user_data)
static

Definition at line 242 of file fl_engine.cc.

242  {
243  FlEngine* self = static_cast<FlEngine*>(user_data);
244  fl_renderer_make_current(self->renderer);
245  return true;
246 }

References fl_renderer_make_current(), and user_data.

Referenced by fl_engine_start().

◆ fl_engine_gl_make_resource_current()

static bool fl_engine_gl_make_resource_current ( void *  user_data)
static

Definition at line 265 of file fl_engine.cc.

265  {
266  FlEngine* self = static_cast<FlEngine*>(user_data);
267  fl_renderer_make_resource_current(self->renderer);
268  return true;
269 }

References fl_renderer_make_resource_current(), and user_data.

Referenced by fl_engine_start().

◆ fl_engine_gl_present()

static bool fl_engine_gl_present ( void *  user_data)
static

Definition at line 259 of file fl_engine.cc.

259  {
260  // No action required, as this is handled in
261  // compositor_present_view_callback.
262  return true;
263 }

Referenced by fl_engine_start().

◆ fl_engine_gl_proc_resolver()

static void* fl_engine_gl_proc_resolver ( void *  user_data,
const char *  name 
)
static

Definition at line 237 of file fl_engine.cc.

237  {
238  FlEngine* self = static_cast<FlEngine*>(user_data);
239  return fl_renderer_get_proc_address(self->renderer, name);
240 }

References fl_renderer_get_proc_address(), and user_data.

Referenced by fl_engine_start().

◆ fl_engine_init()

static void fl_engine_init ( FlEngine *  self)
static

Definition at line 467 of file fl_engine.cc.

467  {
468  self->thread = g_thread_self();
469 
470  self->embedder_api.struct_size = sizeof(FlutterEngineProcTable);
471  FlutterEngineGetProcAddresses(&self->embedder_api);
472 
473  // Implicit view is 0, so start at 1.
474  self->next_view_id = 1;
475 
476  self->texture_registrar = fl_texture_registrar_new(self);
477 }

References fl_texture_registrar_new().

◆ fl_engine_mark_texture_frame_available()

gboolean fl_engine_mark_texture_frame_available ( FlEngine *  engine,
int64_t  texture_id 
)

fl_engine_mark_texture_frame_available: @engine: an #FlEngine. @texture_id: the identifier of the texture whose frame has been updated.

Tells the Flutter engine that a new texture frame is available for the given texture.

Returns: TRUE on success.

Definition at line 974 of file fl_engine.cc.

975  {
976  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
977  return self->embedder_api.MarkExternalTextureFrameAvailable(
978  self->engine, texture_id) == kSuccess;
979 }

References texture_id.

Referenced by mark_texture_frame_available().

◆ fl_engine_new()

G_MODULE_EXPORT FlEngine* fl_engine_new ( FlDartProject *  project)

FlEngine:

#FlEngine is an object that contains a running Flutter engine. fl_engine_new: @project: an #FlDartProject.

Creates new Flutter engine.

Returns: a new #FlEngine.

Definition at line 494 of file fl_engine.cc.

494  {
495  g_autoptr(FlRendererGdk) renderer = fl_renderer_gdk_new();
496  return fl_engine_new_with_renderer(project, FL_RENDERER(renderer));
497 }

References fl_engine_new_with_renderer(), and fl_renderer_gdk_new().

Referenced by fl_view_new().

◆ fl_engine_new_headless()

G_MODULE_EXPORT FlEngine* fl_engine_new_headless ( FlDartProject *  project)

fl_engine_new_headless: @project: an #FlDartProject.

Creates new Flutter engine running in headless mode.

Returns: a new #FlEngine.

Definition at line 499 of file fl_engine.cc.

499  {
500  g_autoptr(FlRendererHeadless) renderer = fl_renderer_headless_new();
501  return fl_engine_new_with_renderer(project, FL_RENDERER(renderer));
502 }

References fl_engine_new_with_renderer(), and fl_renderer_headless_new().

◆ fl_engine_new_with_renderer()

FlEngine* fl_engine_new_with_renderer ( FlDartProject *  project,
FlRenderer *  renderer 
)

fl_engine_new_with_renderer: @project: an #FlDartProject. @renderer: an #FlRenderer.

Creates new Flutter engine.

Returns: a new #FlEngine.

Definition at line 479 of file fl_engine.cc.

480  {
481  g_return_val_if_fail(FL_IS_DART_PROJECT(project), nullptr);
482  g_return_val_if_fail(FL_IS_RENDERER(renderer), nullptr);
483 
484  FlEngine* self = FL_ENGINE(g_object_new(fl_engine_get_type(), nullptr));
485  self->project = FL_DART_PROJECT(g_object_ref(project));
486  self->renderer = FL_RENDERER(g_object_ref(renderer));
487  self->binary_messenger = fl_binary_messenger_new(self);
488 
489  fl_renderer_set_engine(self->renderer, self);
490 
491  return self;
492 }

References fl_binary_messenger_new(), and fl_renderer_set_engine().

Referenced by fl_engine_new(), fl_engine_new_headless(), and make_mock_engine().

◆ fl_engine_on_pre_engine_restart_cb()

static void fl_engine_on_pre_engine_restart_cb ( void *  user_data)
static

Definition at line 363 of file fl_engine.cc.

363  {
364  FlEngine* self = FL_ENGINE(user_data);
365 
366  g_signal_emit(self, fl_engine_signals[kSignalOnPreEngineRestart], 0);
367 }

References fl_engine_signals, kSignalOnPreEngineRestart, and user_data.

Referenced by fl_engine_start().

◆ fl_engine_platform_message_cb()

static void fl_engine_platform_message_cb ( const FlutterPlatformMessage *  message,
void *  user_data 
)
static

Definition at line 328 of file fl_engine.cc.

329  {
330  FlEngine* self = FL_ENGINE(user_data);
331 
332  gboolean handled = FALSE;
333  if (self->platform_message_handler != nullptr) {
334  g_autoptr(GBytes) data =
335  g_bytes_new(message->message, message->message_size);
336  handled = self->platform_message_handler(
337  self, message->channel, data, message->response_handle,
338  self->platform_message_handler_data);
339  }
340 
341  if (!handled) {
342  fl_engine_send_platform_message_response(self, message->response_handle,
343  nullptr, nullptr);
344  }
345 }

References fl_engine_send_platform_message_response(), and user_data.

Referenced by fl_engine_start().

◆ 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 
)
static

Definition at line 371 of file fl_engine.cc.

373  {
374  g_autoptr(GTask) task = G_TASK(user_data);
375  g_task_return_pointer(task, g_bytes_new(data, data_length),
376  reinterpret_cast<GDestroyNotify>(g_bytes_unref));
377 }

References user_data.

Referenced by fl_engine_send_platform_message().

◆ fl_engine_plugin_registry_iface_init()

static void fl_engine_plugin_registry_iface_init ( FlPluginRegistryInterface *  iface)
static

Definition at line 389 of file fl_engine.cc.

390  {
391  iface->get_registrar_for_plugin = fl_engine_get_registrar_for_plugin;
392 }

References fl_engine_get_registrar_for_plugin().

◆ fl_engine_post_task()

static void fl_engine_post_task ( FlutterTask  task,
uint64_t  target_time_nanos,
void *  user_data 
)
static

Definition at line 319 of file fl_engine.cc.

321  {
322  FlEngine* self = static_cast<FlEngine*>(user_data);
323 
324  fl_task_runner_post_task(self->task_runner, task, target_time_nanos);
325 }

References fl_task_runner_post_task(), and user_data.

Referenced by fl_engine_start().

◆ fl_engine_register_external_texture()

gboolean fl_engine_register_external_texture ( FlEngine *  engine,
int64_t  texture_id 
)

fl_engine_register_external_texture: @engine: an #FlEngine. @texture_id: the identifier of the texture that is available.

Tells the Flutter engine that a new external texture is available.

Returns: TRUE on success.

Definition at line 981 of file fl_engine.cc.

982  {
983  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
984  return self->embedder_api.RegisterExternalTexture(self->engine, texture_id) ==
985  kSuccess;
986 }

References texture_id.

Referenced by register_texture().

◆ fl_engine_remove_view()

void fl_engine_remove_view ( FlEngine *  engine,
FlutterViewId  view_id,
GCancellable *  cancellable,
GAsyncReadyCallback  callback,
gpointer  user_data 
)

fl_engine_remove_view: @engine: an #FlEngine. @view_id: ID to remove. @cancellable: (allow-none): a #GCancellable or NULL. @callback: (scope async): a #GAsyncReadyCallback to call when the view is added. @user_data: (closure): user data to pass to @callback.

Removes a view previously added with fl_engine_add_view().

Definition at line 686 of file fl_engine.cc.

690  {
691  g_return_if_fail(FL_IS_ENGINE(self));
692 
693  g_autoptr(GTask) task = g_task_new(self, cancellable, callback, user_data);
694 
695  FlutterRemoveViewInfo info;
696  info.struct_size = sizeof(FlutterRemoveViewInfo);
697  info.view_id = view_id;
698  info.user_data = g_object_ref(task);
699  info.remove_view_callback = view_removed_cb;
700  FlutterEngineResult result =
701  self->embedder_api.RemoveView(self->engine, &info);
702  if (result != kSuccess) {
703  g_task_return_new_error(task, fl_engine_error_quark(),
704  FL_ENGINE_ERROR_FAILED, "RemoveView returned %d",
705  result);
706  // This would have been done in the callback, but that won't occur now.
707  g_object_unref(task);
708  }
709 }

References callback, FL_ENGINE_ERROR_FAILED, fl_engine_error_quark(), result, user_data, and view_removed_cb().

Referenced by fl_view_dispose(), and TEST().

◆ fl_engine_remove_view_finish()

gboolean fl_engine_remove_view_finish ( FlEngine *  engine,
GAsyncResult *  result,
GError **  error 
)

fl_engine_remove_view_finish: @engine: an #FlEngine.

Returns
: a #GAsyncResult. @error: (allow-none): #GError location to store the error occurring, or NULL to ignore.

Completes request started with fl_engine_remove_view().

Returns: TRUE on succcess.

Definition at line 711 of file fl_engine.cc.

713  {
714  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
715  return g_task_propagate_boolean(G_TASK(result), error);
716 }

References error, and result.

Referenced by remove_view_cb(), remove_view_engine_error_cb(), and remove_view_error_cb().

◆ fl_engine_runs_task_on_current_thread()

static bool fl_engine_runs_task_on_current_thread ( void *  user_data)
static

Definition at line 313 of file fl_engine.cc.

313  {
314  FlEngine* self = static_cast<FlEngine*>(user_data);
315  return self->thread == g_thread_self();
316 }

References user_data.

Referenced by fl_engine_start().

◆ fl_engine_send_key_event()

void fl_engine_send_key_event ( FlEngine *  engine,
const FlutterKeyEvent *  event,
FlutterKeyEventCallback  callback,
void *  user_data 
)

fl_engine_send_key_event:

Definition at line 940 of file fl_engine.cc.

943  {
944  g_return_if_fail(FL_IS_ENGINE(self));
945 
946  if (self->engine == nullptr) {
947  return;
948  }
949 
950  self->embedder_api.SendKeyEvent(self->engine, event, callback, user_data);
951 }

References callback, event, and user_data.

Referenced by fl_view_keyboard_delegate_iface_init().

◆ fl_engine_send_mouse_pointer_event()

void fl_engine_send_mouse_pointer_event ( FlEngine *  engine,
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 
)

fl_engine_send_mouse_pointer_event: @engine: an #FlEngine. @view_id: the view that the event occured on. @phase: mouse phase. @timestamp: time when event occurred in microseconds. @x: x location of mouse cursor. @y: y location of mouse cursor. @device_kind: kind of pointing device. @scroll_delta_x: x offset of scroll. @scroll_delta_y: y offset of scroll. @buttons: buttons that are pressed.

Sends a mouse pointer event to the engine.

Definition at line 874 of file fl_engine.cc.

883  {
884  g_return_if_fail(FL_IS_ENGINE(self));
885 
886  if (self->engine == nullptr) {
887  return;
888  }
889 
890  FlutterPointerEvent fl_event = {};
891  fl_event.struct_size = sizeof(fl_event);
892  fl_event.phase = phase;
893  fl_event.timestamp = timestamp;
894  fl_event.x = x;
895  fl_event.y = y;
896  if (scroll_delta_x != 0 || scroll_delta_y != 0) {
897  fl_event.signal_kind = kFlutterPointerSignalKindScroll;
898  }
899  fl_event.scroll_delta_x = scroll_delta_x;
900  fl_event.scroll_delta_y = scroll_delta_y;
901  fl_event.device_kind = device_kind;
902  fl_event.buttons = buttons;
903  fl_event.device = kMousePointerDeviceId;
904  fl_event.view_id = view_id;
905  self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);
906 }

References kMousePointerDeviceId.

Referenced by check_pointer_inside(), fl_view_scrolling_delegate_iface_init(), leave_notify_event_cb(), motion_notify_event_cb(), send_pointer_button_event(), and TEST().

◆ fl_engine_send_platform_message()

void fl_engine_send_platform_message ( FlEngine *  engine,
const gchar *  channel,
GBytes *  message,
GCancellable *  cancellable,
GAsyncReadyCallback  callback,
gpointer  user_data 
)

fl_engine_send_platform_message: @engine: an #FlEngine. @channel: channel to send to. @message: (allow-none): message buffer to send or NULL for an empty message @cancellable: (allow-none): a #GCancellable or NULL. @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied. @user_data: (closure): user data to pass to @callback.

Asynchronously sends a platform message.

Definition at line 786 of file fl_engine.cc.

791  {
792  g_return_if_fail(FL_IS_ENGINE(self));
793 
794  GTask* task = nullptr;
795  FlutterPlatformMessageResponseHandle* response_handle = nullptr;
796  if (callback != nullptr) {
797  task = g_task_new(self, cancellable, callback, user_data);
798 
799  if (self->engine == nullptr) {
800  g_task_return_new_error(task, fl_engine_error_quark(),
801  FL_ENGINE_ERROR_FAILED, "No engine to send to");
802  return;
803  }
804 
805  FlutterEngineResult result =
806  self->embedder_api.PlatformMessageCreateResponseHandle(
807  self->engine, fl_engine_platform_message_response_cb, task,
808  &response_handle);
809  if (result != kSuccess) {
810  g_task_return_new_error(task, fl_engine_error_quark(),
812  "Failed to create response handle");
813  g_object_unref(task);
814  return;
815  }
816  } else if (self->engine == nullptr) {
817  return;
818  }
819 
820  FlutterPlatformMessage fl_message = {};
821  fl_message.struct_size = sizeof(fl_message);
822  fl_message.channel = channel;
823  fl_message.message =
824  message != nullptr
825  ? static_cast<const uint8_t*>(g_bytes_get_data(message, nullptr))
826  : nullptr;
827  fl_message.message_size = message != nullptr ? g_bytes_get_size(message) : 0;
828  fl_message.response_handle = response_handle;
829  FlutterEngineResult result =
830  self->embedder_api.SendPlatformMessage(self->engine, &fl_message);
831 
832  if (result != kSuccess && task != nullptr) {
833  g_task_return_new_error(task, fl_engine_error_quark(),
835  "Failed to send platform messages");
836  g_object_unref(task);
837  }
838 
839  if (response_handle != nullptr) {
840  self->embedder_api.PlatformMessageReleaseResponseHandle(self->engine,
841  response_handle);
842  }
843 }

References callback, FL_ENGINE_ERROR_FAILED, fl_engine_error_quark(), fl_engine_platform_message_response_cb(), result, and user_data.

Referenced by send_on_channel(), and TEST().

◆ fl_engine_send_platform_message_finish()

GBytes* fl_engine_send_platform_message_finish ( FlEngine *  engine,
GAsyncResult *  result,
GError **  error 
)

fl_engine_send_platform_message_finish: @engine: an #FlEngine.

Returns
: a #GAsyncResult. @error: (allow-none): #GError location to store the error occurring, or NULL to ignore.

Completes request started with fl_engine_send_platform_message().

Returns: message response on success or NULL on error.

Definition at line 845 of file fl_engine.cc.

847  {
848  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
849  g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
850 
851  return static_cast<GBytes*>(g_task_propagate_pointer(G_TASK(result), error));
852 }

References error, and result.

Referenced by send_on_channel_finish().

◆ fl_engine_send_platform_message_response()

gboolean fl_engine_send_platform_message_response ( FlEngine *  engine,
const FlutterPlatformMessageResponseHandle *  handle,
GBytes *  response,
GError **  error 
)

fl_engine_send_platform_message_response: @engine: an #FlEngine. @handle: handle that was provided in FlEnginePlatformMessageHandler. @response: (allow-none): response to send or NULL for an empty response. @error: (allow-none): #GError location to store the error occurring, or NULL to ignore.

Responds to a platform message.

Returns: TRUE on success.

Definition at line 754 of file fl_engine.cc.

758  {
759  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
760  g_return_val_if_fail(handle != nullptr, FALSE);
761 
762  if (self->engine == nullptr) {
764  "No engine to send response to");
765  return FALSE;
766  }
767 
768  gsize data_length = 0;
769  const uint8_t* data = nullptr;
770  if (response != nullptr) {
771  data =
772  static_cast<const uint8_t*>(g_bytes_get_data(response, &data_length));
773  }
774  FlutterEngineResult result = self->embedder_api.SendPlatformMessageResponse(
775  self->engine, handle, data, data_length);
776 
777  if (result != kSuccess) {
779  "Failed to send platform message response");
780  return FALSE;
781  }
782 
783  return TRUE;
784 }

References error, FL_ENGINE_ERROR_FAILED, fl_engine_error_quark(), result, and TRUE.

Referenced by fl_engine_platform_message_cb(), send_response(), and TEST().

◆ fl_engine_send_pointer_pan_zoom_event()

void fl_engine_send_pointer_pan_zoom_event ( FlEngine *  engine,
FlutterViewId  view_id,
size_t  timestamp,
double  x,
double  y,
FlutterPointerPhase  phase,
double  pan_x,
double  pan_y,
double  scale,
double  rotation 
)

fl_engine_send_pointer_pan_zoom_event: @engine: an #FlEngine. @view_id: the view that the event occured on. @timestamp: time when event occurred in microseconds. @x: x location of mouse cursor. @y: y location of mouse cursor. @phase: mouse phase. @pan_x: x offset of the pan/zoom in pixels. @pan_y: y offset of the pan/zoom in pixels. @scale: scale of the pan/zoom. @rotation: rotation of the pan/zoom in radians.

Sends a pan/zoom pointer event to the engine.

Definition at line 908 of file fl_engine.cc.

917  {
918  g_return_if_fail(FL_IS_ENGINE(self));
919 
920  if (self->engine == nullptr) {
921  return;
922  }
923 
924  FlutterPointerEvent fl_event = {};
925  fl_event.struct_size = sizeof(fl_event);
926  fl_event.timestamp = timestamp;
927  fl_event.x = x;
928  fl_event.y = y;
929  fl_event.phase = phase;
930  fl_event.pan_x = pan_x;
931  fl_event.pan_y = pan_y;
932  fl_event.scale = scale;
933  fl_event.rotation = rotation;
934  fl_event.device = kPointerPanZoomDeviceId;
935  fl_event.device_kind = kFlutterPointerDeviceKindTrackpad;
936  fl_event.view_id = view_id;
937  self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);
938 }

References kPointerPanZoomDeviceId.

Referenced by fl_view_scrolling_delegate_iface_init(), and TEST().

◆ fl_engine_send_window_metrics_event()

void fl_engine_send_window_metrics_event ( FlEngine *  engine,
FlutterViewId  view_id,
size_t  width,
size_t  height,
double  pixel_ratio 
)

fl_engine_send_window_metrics_event: @engine: an #FlEngine. @view_id: the view that the event occured on. @width: width of the window in pixels. @height: height of the window in pixels. @pixel_ratio: scale factor for window.

Sends a window metrics event to the engine.

Definition at line 854 of file fl_engine.cc.

858  {
859  g_return_if_fail(FL_IS_ENGINE(self));
860 
861  if (self->engine == nullptr) {
862  return;
863  }
864 
865  FlutterWindowMetricsEvent event = {};
866  event.struct_size = sizeof(FlutterWindowMetricsEvent);
867  event.width = width;
868  event.height = height;
869  event.pixel_ratio = pixel_ratio;
870  event.view_id = view_id;
871  self->embedder_api.SendWindowMetricsEvent(self->engine, &event);
872 }

References event, height, and width.

Referenced by handle_geometry_changed(), and TEST().

◆ fl_engine_set_platform_message_handler()

void fl_engine_set_platform_message_handler ( FlEngine *  engine,
FlEnginePlatformMessageHandler  handler,
gpointer  user_data,
GDestroyNotify  destroy_notify 
)

fl_engine_set_platform_message_handler: @engine: an #FlEngine. @handler: function to call when a platform message is received. @user_data: (closure): user data to pass to @handler. @destroy_notify: (allow-none): a function which gets called to free @user_data, or NULL.

Registers the function called when a platform message is received. Call fl_engine_send_platform_message_response() with the response to this message. Ownership of #FlutterPlatformMessageResponseHandle is transferred to the caller, and the message must be responded to avoid memory leaks.

Definition at line 718 of file fl_engine.cc.

722  {
723  g_return_if_fail(FL_IS_ENGINE(self));
724  g_return_if_fail(handler != nullptr);
725 
726  if (self->platform_message_handler_destroy_notify) {
727  self->platform_message_handler_destroy_notify(
728  self->platform_message_handler_data);
729  }
730 
731  self->platform_message_handler = handler;
732  self->platform_message_handler_data = user_data;
733  self->platform_message_handler_destroy_notify = destroy_notify;
734 }

References user_data.

Referenced by fl_binary_messenger_new().

◆ fl_engine_set_property()

static void fl_engine_set_property ( GObject *  object,
guint  prop_id,
const GValue *  value,
GParamSpec *  pspec 
)
static

Definition at line 394 of file fl_engine.cc.

397  {
398  FlEngine* self = FL_ENGINE(object);
399  switch (prop_id) {
400  case kPropBinaryMessenger:
401  g_set_object(&self->binary_messenger,
402  FL_BINARY_MESSENGER(g_value_get_object(value)));
403  break;
404  default:
405  G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
406  break;
407  }
408 }

References prop_id, pspec, and value.

Referenced by fl_engine_class_init().

◆ fl_engine_set_update_semantics_handler()

void fl_engine_set_update_semantics_handler ( FlEngine *  engine,
FlEngineUpdateSemanticsHandler  handler,
gpointer  user_data,
GDestroyNotify  destroy_notify 
)

fl_engine_set_update_semantics_handler: @engine: an #FlEngine. @handler: function to call when a semantics update is received. @user_data: (closure): user data to pass to @handler. @destroy_notify: (allow-none): a function which gets called to free @user_data, or NULL.

Registers the function called when a semantics update is received.

Definition at line 736 of file fl_engine.cc.

740  {
741  g_return_if_fail(FL_IS_ENGINE(self));
742 
743  if (self->update_semantics_handler_destroy_notify) {
744  self->update_semantics_handler_destroy_notify(
745  self->update_semantics_handler_data);
746  }
747 
748  self->update_semantics_handler = handler;
749  self->update_semantics_handler_data = user_data;
750  self->update_semantics_handler_destroy_notify = destroy_notify;
751 }

References user_data.

Referenced by fl_view_dispose(), and fl_view_new().

◆ fl_engine_start()

gboolean fl_engine_start ( FlEngine *  engine,
GError **  error 
)

fl_engine_start: @engine: an #FlEngine. @error: (allow-none): #GError location to store the error occurring, or NULL to ignore.

Starts the Flutter engine.

Returns: TRUE on success.

Definition at line 509 of file fl_engine.cc.

509  {
510  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
511 
512  self->task_runner = fl_task_runner_new(self);
513 
514  FlutterRendererConfig config = {};
515  config.type = kOpenGL;
516  config.open_gl.struct_size = sizeof(FlutterOpenGLRendererConfig);
517  config.open_gl.gl_proc_resolver = fl_engine_gl_proc_resolver;
518  config.open_gl.make_current = fl_engine_gl_make_current;
519  config.open_gl.clear_current = fl_engine_gl_clear_current;
520  config.open_gl.fbo_callback = fl_engine_gl_get_fbo;
521  config.open_gl.present = fl_engine_gl_present;
522  config.open_gl.make_resource_current = fl_engine_gl_make_resource_current;
523  config.open_gl.gl_external_texture_frame_callback =
525 
526  FlutterTaskRunnerDescription platform_task_runner = {};
527  platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription);
528  platform_task_runner.user_data = self;
529  platform_task_runner.runs_task_on_current_thread_callback =
531  platform_task_runner.post_task_callback = fl_engine_post_task;
532  platform_task_runner.identifier = kPlatformTaskRunnerIdentifier;
533 
534  FlutterCustomTaskRunners custom_task_runners = {};
535  custom_task_runners.struct_size = sizeof(FlutterCustomTaskRunners);
536  custom_task_runners.platform_task_runner = &platform_task_runner;
537  custom_task_runners.render_task_runner = &platform_task_runner;
538 
539  g_autoptr(GPtrArray) command_line_args = fl_engine_get_switches(self);
540  // FlutterProjectArgs expects a full argv, so when processing it for flags
541  // the first item is treated as the executable and ignored. Add a dummy value
542  // so that all switches are used.
543  g_ptr_array_insert(command_line_args, 0, g_strdup("flutter"));
544 
545  gchar** dart_entrypoint_args =
547 
548  FlutterProjectArgs args = {};
549  args.struct_size = sizeof(FlutterProjectArgs);
550  args.assets_path = fl_dart_project_get_assets_path(self->project);
551  args.icu_data_path = fl_dart_project_get_icu_data_path(self->project);
552  args.command_line_argc = command_line_args->len;
553  args.command_line_argv =
554  reinterpret_cast<const char* const*>(command_line_args->pdata);
555  args.platform_message_callback = fl_engine_platform_message_cb;
556  args.update_semantics_callback2 = fl_engine_update_semantics_cb;
557  args.custom_task_runners = &custom_task_runners;
558  args.shutdown_dart_vm_when_done = true;
559  args.on_pre_engine_restart_callback = fl_engine_on_pre_engine_restart_cb;
560  args.dart_entrypoint_argc =
561  dart_entrypoint_args != nullptr ? g_strv_length(dart_entrypoint_args) : 0;
562  args.dart_entrypoint_argv =
563  reinterpret_cast<const char* const*>(dart_entrypoint_args);
564 
565  FlutterCompositor compositor = {};
566  compositor.struct_size = sizeof(FlutterCompositor);
567  compositor.user_data = self->renderer;
568  compositor.create_backing_store_callback =
570  compositor.collect_backing_store_callback =
572  compositor.present_view_callback = compositor_present_view_callback;
573  args.compositor = &compositor;
574 
575  if (self->embedder_api.RunsAOTCompiledDartCode()) {
576  FlutterEngineAOTDataSource source = {};
577  source.type = kFlutterEngineAOTDataSourceTypeElfPath;
578  source.elf_path = fl_dart_project_get_aot_library_path(self->project);
579  if (self->embedder_api.CreateAOTData(&source, &self->aot_data) !=
580  kSuccess) {
582  "Failed to create AOT data");
583  return FALSE;
584  }
585  args.aot_data = self->aot_data;
586  }
587 
588  FlutterEngineResult result = self->embedder_api.Initialize(
589  FLUTTER_ENGINE_VERSION, &config, &args, self, &self->engine);
590  if (result != kSuccess) {
592  "Failed to initialize Flutter engine");
593  return FALSE;
594  }
595 
596  result = self->embedder_api.RunInitialized(self->engine);
597  if (result != kSuccess) {
599  "Failed to run Flutter engine");
600  return FALSE;
601  }
602 
603  setup_locales(self);
604 
605  g_autoptr(FlSettings) settings = fl_settings_new();
606  self->settings_handler = fl_settings_handler_new(self);
607  fl_settings_handler_start(self->settings_handler, settings);
608 
609  result = self->embedder_api.UpdateSemanticsEnabled(self->engine, TRUE);
610  if (result != kSuccess) {
611  g_warning("Failed to enable accessibility features on Flutter engine");
612  }
613 
614  gdouble refresh_rate = fl_renderer_get_refresh_rate(self->renderer);
615  // FlutterEngineDisplay::refresh_rate expects 0 if the refresh rate is
616  // unknown.
617  if (refresh_rate <= 0.0) {
618  refresh_rate = 0.0;
619  }
620  FlutterEngineDisplay display = {};
621  display.struct_size = sizeof(FlutterEngineDisplay);
622  display.display_id = 0;
623  display.single_display = true;
624  display.refresh_rate = refresh_rate;
625 
626  std::vector displays = {display};
627  result = self->embedder_api.NotifyDisplayUpdate(
628  self->engine, kFlutterEngineDisplaysUpdateTypeStartup, displays.data(),
629  displays.size());
630  if (result != kSuccess) {
631  g_warning("Failed to notify display update to Flutter engine: %d", result);
632  }
633 
634  return TRUE;
635 }

References args, compositor_collect_backing_store_callback(), compositor_create_backing_store_callback(), compositor_present_view_callback(), error, fl_dart_project_get_aot_library_path(), fl_dart_project_get_assets_path(), fl_dart_project_get_dart_entrypoint_arguments(), fl_dart_project_get_icu_data_path(), FL_ENGINE_ERROR_FAILED, fl_engine_error_quark(), fl_engine_get_switches(), fl_engine_gl_clear_current(), fl_engine_gl_external_texture_frame_callback(), fl_engine_gl_get_fbo(), fl_engine_gl_make_current(), fl_engine_gl_make_resource_current(), fl_engine_gl_present(), fl_engine_gl_proc_resolver(), fl_engine_on_pre_engine_restart_cb(), fl_engine_platform_message_cb(), fl_engine_post_task(), fl_engine_runs_task_on_current_thread(), fl_engine_update_semantics_cb(), fl_renderer_get_refresh_rate(), fl_settings_handler_new(), fl_settings_handler_start(), fl_settings_new(), fl_task_runner_new(), kPlatformTaskRunnerIdentifier, result, setup_locales(), and TRUE.

Referenced by make_mock_engine(), realize_cb(), and TEST().

◆ fl_engine_unregister_external_texture()

gboolean fl_engine_unregister_external_texture ( FlEngine *  engine,
int64_t  texture_id 
)

fl_engine_unregister_external_texture: @engine: an #FlEngine. @texture_id: the identifier of the texture that is not available anymore.

Tells the Flutter engine that an existing external texture is not available anymore.

Returns: TRUE on success.

Definition at line 988 of file fl_engine.cc.

989  {
990  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
991  return self->embedder_api.UnregisterExternalTexture(self->engine,
992  texture_id) == kSuccess;
993 }

References texture_id.

Referenced by unregister_texture().

◆ fl_engine_update_accessibility_features()

void fl_engine_update_accessibility_features ( FlEngine *  engine,
int32_t  flags 
)

fl_engine_update_accessibility_features: @engine: an #FlEngine. @flags: the features to enable in the accessibility tree.

Tells the Flutter engine to update the flags on the accessibility tree.

Definition at line 1017 of file fl_engine.cc.

1017  {
1018  g_return_if_fail(FL_IS_ENGINE(self));
1019 
1020  if (self->engine == nullptr) {
1021  return;
1022  }
1023 
1024  self->embedder_api.UpdateAccessibilityFeatures(
1025  self->engine, static_cast<FlutterAccessibilityFeature>(flags));
1026 }

References flags.

Referenced by update_settings().

◆ fl_engine_update_semantics_cb()

static void fl_engine_update_semantics_cb ( const FlutterSemanticsUpdate2 *  update,
void *  user_data 
)
static

Definition at line 348 of file fl_engine.cc.

349  {
350  FlEngine* self = FL_ENGINE(user_data);
351 
352  if (self->update_semantics_handler != nullptr) {
353  self->update_semantics_handler(self, update,
354  self->update_semantics_handler_data);
355  }
356 }

References user_data.

Referenced by fl_engine_start().

◆ free_locale()

static void free_locale ( FlutterLocale *  locale)
static

Definition at line 151 of file fl_engine.cc.

151  {
152  free(const_cast<gchar*>(locale->language_code));
153  free(const_cast<gchar*>(locale->country_code));
154  free(locale);
155 }

Referenced by setup_locales().

◆ 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  
)

Definition at line 76 of file fl_engine.cc.

83  { kProp0, kPropBinaryMessenger, kPropLast };

References kProp0, and kPropLast.

◆ parse_locale()

static void parse_locale ( const gchar *  locale,
gchar **  language,
gchar **  territory,
gchar **  codeset,
gchar **  modifier 
)
static

Definition at line 86 of file fl_engine.cc.

90  {
91  gchar* l = g_strdup(locale);
92 
93  // Locales are in the form "language[_territory][.codeset][@modifier]"
94  gchar* match = strrchr(l, '@');
95  if (match != nullptr) {
96  if (modifier != nullptr) {
97  *modifier = g_strdup(match + 1);
98  }
99  *match = '\0';
100  } else if (modifier != nullptr) {
101  *modifier = nullptr;
102  }
103 
104  match = strrchr(l, '.');
105  if (match != nullptr) {
106  if (codeset != nullptr) {
107  *codeset = g_strdup(match + 1);
108  }
109  *match = '\0';
110  } else if (codeset != nullptr) {
111  *codeset = nullptr;
112  }
113 
114  match = strrchr(l, '_');
115  if (match != nullptr) {
116  if (territory != nullptr) {
117  *territory = g_strdup(match + 1);
118  }
119  *match = '\0';
120  } else if (territory != nullptr) {
121  *territory = nullptr;
122  }
123 
124  if (language != nullptr) {
125  *language = l;
126  }
127 }

Referenced by setup_locales().

◆ setup_locales()

static void setup_locales ( FlEngine *  self)
static

Definition at line 158 of file fl_engine.cc.

158  {
159  const gchar* const* languages = g_get_language_names();
160  g_autoptr(GPtrArray) locales_array = g_ptr_array_new_with_free_func(
161  reinterpret_cast<GDestroyNotify>(free_locale));
162  for (int i = 0; languages[i] != nullptr; i++) {
163  g_autofree gchar* locale_string = g_strstrip(g_strdup(languages[i]));
164 
165  // Ignore empty locales, caused by settings like `LANGUAGE=pt_BR:`
166  if (strcmp(locale_string, "") == 0) {
167  continue;
168  }
169 
170  g_autofree gchar* language = nullptr;
171  g_autofree gchar* territory = nullptr;
172  parse_locale(locale_string, &language, &territory, nullptr, nullptr);
173 
174  // Ignore duplicate locales, caused by settings like `LANGUAGE=C` (returns
175  // two "C") or `LANGUAGE=en:en`
176  gboolean has_locale = FALSE;
177  for (guint j = 0; !has_locale && j < locales_array->len; j++) {
178  FlutterLocale* locale =
179  reinterpret_cast<FlutterLocale*>(g_ptr_array_index(locales_array, j));
180  has_locale = g_strcmp0(locale->language_code, language) == 0 &&
181  g_strcmp0(locale->country_code, territory) == 0;
182  }
183  if (has_locale) {
184  continue;
185  }
186 
187  FlutterLocale* locale =
188  static_cast<FlutterLocale*>(g_malloc0(sizeof(FlutterLocale)));
189  g_ptr_array_add(locales_array, locale);
190  locale->struct_size = sizeof(FlutterLocale);
191  locale->language_code =
192  reinterpret_cast<const gchar*>(g_steal_pointer(&language));
193  locale->country_code =
194  reinterpret_cast<const gchar*>(g_steal_pointer(&territory));
195  locale->script_code = nullptr;
196  locale->variant_code = nullptr;
197  }
198  FlutterLocale** locales =
199  reinterpret_cast<FlutterLocale**>(locales_array->pdata);
200  FlutterEngineResult result = self->embedder_api.UpdateLocales(
201  self->engine, const_cast<const FlutterLocale**>(locales),
202  locales_array->len);
203  if (result != kSuccess) {
204  g_warning("Failed to set up Flutter locales");
205  }
206 }

References free_locale(), i, parse_locale(), and result.

Referenced by fl_engine_start().

◆ view_added_cb()

static void view_added_cb ( const FlutterAddViewResult *  result)
static

Definition at line 129 of file fl_engine.cc.

129  {
130  g_autoptr(GTask) task = G_TASK(result->user_data);
131 
132  if (result->added) {
133  g_task_return_boolean(task, TRUE);
134  } else {
135  g_task_return_new_error(task, fl_engine_error_quark(),
136  FL_ENGINE_ERROR_FAILED, "Failed to add view");
137  }
138 }

References FL_ENGINE_ERROR_FAILED, fl_engine_error_quark(), result, and TRUE.

Referenced by fl_engine_add_view().

◆ view_removed_cb()

static void view_removed_cb ( const FlutterRemoveViewResult *  result)
static

Definition at line 140 of file fl_engine.cc.

140  {
141  g_autoptr(GTask) task = G_TASK(result->user_data);
142 
143  if (result->removed) {
144  g_task_return_boolean(task, TRUE);
145  } else {
146  g_task_return_new_error(task, fl_engine_error_quark(),
147  FL_ENGINE_ERROR_FAILED, "Failed to remove view");
148  }
149 }

References FL_ENGINE_ERROR_FAILED, fl_engine_error_quark(), result, and TRUE.

Referenced by fl_engine_remove_view().

Variable Documentation

◆ fl_engine_signals

guint fl_engine_signals[kSignalLastSignal]
static

Definition at line 74 of file fl_engine.cc.

Referenced by fl_engine_class_init(), and fl_engine_on_pre_engine_restart_cb().

◆ kMousePointerDeviceId

constexpr int32_t kMousePointerDeviceId = 0
staticconstexpr

Definition at line 34 of file fl_engine.cc.

Referenced by fl_engine_send_mouse_pointer_event().

◆ kPlatformTaskRunnerIdentifier

constexpr size_t kPlatformTaskRunnerIdentifier = 1
staticconstexpr

Definition at line 30 of file fl_engine.cc.

Referenced by fl_engine_start().

◆ kPointerPanZoomDeviceId

constexpr int32_t kPointerPanZoomDeviceId = 1
staticconstexpr

Definition at line 35 of file fl_engine.cc.

Referenced by fl_engine_send_pointer_pan_zoom_event().

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
fl_binary_messenger_shutdown
void fl_binary_messenger_shutdown(FlBinaryMessenger *self)
Definition: fl_binary_messenger.cc:486
fl_settings_handler_new
FlSettingsHandler * fl_settings_handler_new(FlEngine *engine)
Definition: fl_settings_handler.cc:94
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:429
event
FlKeyEvent * event
Definition: fl_key_channel_responder.cc:118
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:371
fl_engine_gl_get_fbo
static uint32_t fl_engine_gl_get_fbo(void *user_data)
Definition: fl_engine.cc:254
fl_engine_gl_make_resource_current
static bool fl_engine_gl_make_resource_current(void *user_data)
Definition: fl_engine.cc:265
FL_ENGINE_ERROR_FAILED
@ FL_ENGINE_ERROR_FAILED
Definition: fl_engine_private.h:25
kMousePointerDeviceId
static constexpr int32_t kMousePointerDeviceId
Definition: fl_engine.cc:34
fl_renderer_get_refresh_rate
gdouble fl_renderer_get_refresh_rate(FlRenderer *self)
Definition: fl_renderer.cc:355
fl_texture_registrar_lookup_texture
FlTexture * fl_texture_registrar_lookup_texture(FlTextureRegistrar *self, int64_t texture_id)
Definition: fl_texture_registrar.cc:190
compositor_present_view_callback
static bool compositor_present_view_callback(const FlutterPresentViewInfo *info)
Definition: fl_engine.cc:228
i
int i
Definition: fl_socket_accessible.cc:18
fl_settings_new
FlSettings * fl_settings_new()
Definition: fl_settings.cc:55
fl_engine_gl_present
static bool fl_engine_gl_present(void *user_data)
Definition: fl_engine.cc:259
flags
FlutterSemanticsFlag flags
Definition: fl_accessible_node.cc:106
fl_engine_dispose
static void fl_engine_dispose(GObject *object)
Definition: fl_engine.cc:410
user_data
FlKeyEvent uint64_t FlKeyResponderAsyncCallback gpointer user_data
Definition: fl_key_channel_responder.cc:121
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
kSignalLastSignal
@ kSignalLastSignal
Definition: fl_engine.cc:72
fl_engine_on_pre_engine_restart_cb
static void fl_engine_on_pre_engine_restart_cb(void *user_data)
Definition: fl_engine.cc:363
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:350
kSignalOnPreEngineRestart
@ kSignalOnPreEngineRestart
Definition: fl_engine.cc:72
fl_renderer_get_proc_address
void * fl_renderer_get_proc_address(FlRenderer *self, const char *name)
Definition: fl_renderer.cc:334
fl_binary_messenger_new
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
Definition: fl_binary_messenger.cc:399
kPlatformTaskRunnerIdentifier
static constexpr size_t kPlatformTaskRunnerIdentifier
Definition: fl_engine.cc:30
fl_engine_new_with_renderer
FlEngine * fl_engine_new_with_renderer(FlDartProject *project, FlRenderer *renderer)
Definition: fl_engine.cc:479
fl_renderer_set_engine
void fl_renderer_set_engine(FlRenderer *self, FlEngine *engine)
Definition: fl_renderer.cc:305
kPropLast
@ kPropLast
Definition: fl_accessible_node.cc:84
view_removed_cb
static void view_removed_cb(const FlutterRemoveViewResult *result)
Definition: fl_engine.cc:140
fl_engine_set_property
static void fl_engine_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
Definition: fl_engine.cc:394
fl_engine_update_semantics_cb
static void fl_engine_update_semantics_cb(const FlutterSemanticsUpdate2 *update, void *user_data)
Definition: fl_engine.cc:348
free_locale
static void free_locale(FlutterLocale *locale)
Definition: fl_engine.cc:151
fl_renderer_collect_backing_store
gboolean fl_renderer_collect_backing_store(FlRenderer *self, const FlutterBackingStore *backing_store)
Definition: fl_renderer.cc:399
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:38
fl_texture_registrar_shutdown
void fl_texture_registrar_shutdown(FlTextureRegistrar *self)
Definition: fl_texture_registrar.cc:215
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
kProp0
@ kProp0
Definition: fl_accessible_node.cc:84
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:272
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
flutter::GetSwitchesFromEnvironment
std::vector< std::string > GetSwitchesFromEnvironment()
Definition: engine_switches.cc:14
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_make_resource_current
void fl_renderer_make_resource_current(FlRenderer *self)
Definition: fl_renderer.cc:345
fl_engine_signals
static guint fl_engine_signals[kSignalLastSignal]
Definition: fl_engine.cc:74
fl_settings_handler_start
void fl_settings_handler_start(FlSettingsHandler *self, FlSettings *settings)
Definition: fl_settings_handler.cc:112
fl_engine_runs_task_on_current_thread
static bool fl_engine_runs_task_on_current_thread(void *user_data)
Definition: fl_engine.cc:313
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
result
GAsyncResult * result
Definition: fl_text_input_handler.cc:106
fl_engine_get_registrar_for_plugin
static FlPluginRegistrar * fl_engine_get_registrar_for_plugin(FlPluginRegistry *registry, const gchar *name)
Definition: fl_engine.cc:380
view_added_cb
static void view_added_cb(const FlutterAddViewResult *result)
Definition: fl_engine.cc:129
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
compositor_collect_backing_store_callback
static bool compositor_collect_backing_store_callback(const FlutterBackingStore *backing_store, void *user_data)
Definition: fl_engine.cc:219
fl_renderer_make_current
void fl_renderer_make_current(FlRenderer *self)
Definition: fl_renderer.cc:340
fl_engine_gl_proc_resolver
static void * fl_engine_gl_proc_resolver(void *user_data, const char *name)
Definition: fl_engine.cc:237
setup_locales
static void setup_locales(FlEngine *self)
Definition: fl_engine.cc:158
fl_renderer_gdk_new
FlRendererGdk * fl_renderer_gdk_new()
Definition: fl_renderer_gdk.cc:82
parse_locale
static void parse_locale(const gchar *locale, gchar **language, gchar **territory, gchar **codeset, gchar **modifier)
Definition: fl_engine.cc:86
fl_renderer_create_backing_store
gboolean fl_renderer_create_backing_store(FlRenderer *self, const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
Definition: fl_renderer.cc:367
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:209
fl_plugin_registrar_new
FlPluginRegistrar * fl_plugin_registrar_new(FlView *view, FlBinaryMessenger *messenger, FlTextureRegistrar *texture_registrar)
Definition: fl_plugin_registrar.cc:87
callback
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Definition: fl_key_channel_responder.cc:120
fl_engine_error_quark
GQuark fl_engine_error_quark(void) G_GNUC_CONST
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_gl_make_current
static bool fl_engine_gl_make_current(void *user_data)
Definition: fl_engine.cc:242
fl_engine_get_switches
GPtrArray * fl_engine_get_switches(FlEngine *self)
Definition: fl_engine.cc:1028
fl_renderer_get_fbo
guint32 fl_renderer_get_fbo(FlRenderer *self)
Definition: fl_renderer.cc:360
fl_engine_post_task
static void fl_engine_post_task(FlutterTask task, uint64_t target_time_nanos, void *user_data)
Definition: fl_engine.cc:319
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_send_platform_message_response
gboolean fl_engine_send_platform_message_response(FlEngine *self, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
Definition: fl_engine.cc:754
fl_engine_platform_message_cb
static void fl_engine_platform_message_cb(const FlutterPlatformMessage *message, void *user_data)
Definition: fl_engine.cc:328
kPointerPanZoomDeviceId
static constexpr int32_t kPointerPanZoomDeviceId
Definition: fl_engine.cc:35
fl_engine_gl_clear_current
static bool fl_engine_gl_clear_current(void *user_data)
Definition: fl_engine.cc:248