Flutter Linux Embedder
fl_engine.cc File Reference

Go to the source code of this file.

Classes

struct  _FlEngine
 

Enumerations

enum  {
  SIGNAL_ON_PRE_ENGINE_RESTART ,
  SIGNAL_UPDATE_SEMANTICS ,
  LAST_SIGNAL
}
 

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 set_renderable (FlEngine *self, int64_t view_id, FlRenderable *renderable)
 Stores a weak reference to the renderable with the given ID. More...
 
static FlRenderable * get_renderable (FlEngine *self, int64_t view_id)
 
static void remove_renderable (FlEngine *self, int64_t view_id)
 Remove a renderable that no longer exists. More...
 
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 create_opengl_backing_store (FlEngine *self, const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
 
static bool collect_opengl_backing_store (FlEngine *self, const FlutterBackingStore *backing_store)
 
static bool create_software_backing_store (FlEngine *self, const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
 
static bool collect_software_backing_store (FlEngine *self, const FlutterBackingStore *backing_store)
 
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_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 setup_keyboard (FlEngine *self)
 
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)
 
static FlEngine * fl_engine_new_full (FlDartProject *project, FlBinaryMessenger *binary_messenger)
 
FlEngine * fl_engine_for_id (int64_t id)
 
G_MODULE_EXPORT FlEngine * fl_engine_new (FlDartProject *project)
 
FlEngine * fl_engine_new_with_binary_messenger (FlBinaryMessenger *binary_messenger)
 
G_MODULE_EXPORT FlEngine * fl_engine_new_headless (FlDartProject *project)
 
FlutterRendererType fl_engine_get_renderer_type (FlEngine *self)
 
FlOpenGLManager * fl_engine_get_opengl_manager (FlEngine *self)
 
FlDisplayMonitor * fl_engine_get_display_monitor (FlEngine *self)
 
gboolean fl_engine_start (FlEngine *self, GError **error)
 
FlutterEngineProcTable * fl_engine_get_embedder_api (FlEngine *self)
 
void fl_engine_notify_display_update (FlEngine *self, const FlutterEngineDisplay *displays, size_t displays_length)
 
void fl_engine_set_implicit_view (FlEngine *self, FlRenderable *renderable)
 
FlutterViewId fl_engine_add_view (FlEngine *self, FlRenderable *renderable, size_t min_width, size_t min_height, size_t max_width, size_t max_height, double pixel_ratio, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
 
gboolean fl_engine_add_view_finish (FlEngine *self, GAsyncResult *result, GError **error)
 
FlRenderable * fl_engine_get_renderable (FlEngine *self, FlutterViewId view_id)
 
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)
 
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_schedule_frame (FlEngine *self)
 
void fl_engine_send_window_metrics_event (FlEngine *self, FlutterEngineDisplayId display_id, FlutterViewId view_id, size_t min_width, size_t min_height, size_t max_width, size_t max_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, double rotation, double pressure)
 
void fl_engine_send_touch_up_event (FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
 
void fl_engine_send_touch_down_event (FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
 
void fl_engine_send_touch_move_event (FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
 
void fl_engine_send_touch_cancel_event (FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
 
void fl_engine_send_touch_add_event (FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
 
void fl_engine_send_touch_remove_event (FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
 
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)
 
static void send_key_event_cb (bool handled, void *user_data)
 
void fl_engine_send_key_event (FlEngine *self, const FlutterKeyEvent *event, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
 
gboolean fl_engine_send_key_event_finish (FlEngine *self, GAsyncResult *result, gboolean *handled, GError **error)
 
void fl_engine_dispatch_semantics_action (FlEngine *self, FlutterViewId view_id, uint64_t node_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)
 
void fl_engine_request_app_exit (FlEngine *self)
 
FlKeyboardManager * fl_engine_get_keyboard_manager (FlEngine *self)
 
FlTextInputHandler * fl_engine_get_text_input_handler (FlEngine *self)
 
FlMouseCursorHandler * fl_engine_get_mouse_cursor_handler (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 [LAST_SIGNAL]
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SIGNAL_ON_PRE_ENGINE_RESTART 
SIGNAL_UPDATE_SEMANTICS 
LAST_SIGNAL 

Definition at line 117 of file fl_engine.cc.

@ LAST_SIGNAL
Definition: fl_engine.cc:117
@ SIGNAL_UPDATE_SEMANTICS
Definition: fl_engine.cc:117
@ SIGNAL_ON_PRE_ENGINE_RESTART
Definition: fl_engine.cc:117

Function Documentation

◆ collect_opengl_backing_store()

static bool collect_opengl_backing_store ( FlEngine *  self,
const FlutterBackingStore *  backing_store 
)
static

Definition at line 321 of file fl_engine.cc.

323  {
324  if (!fl_opengl_manager_make_current(self->opengl_manager)) {
325  return false;
326  }
327 
328  // OpenGL context is required when destroying #FlFramebuffer.
329  g_object_unref(backing_store->open_gl.framebuffer.user_data);
330  return true;
331 }
gboolean fl_opengl_manager_make_current(FlOpenGLManager *self)

References fl_opengl_manager_make_current().

Referenced by compositor_collect_backing_store_callback().

◆ collect_software_backing_store()

static bool collect_software_backing_store ( FlEngine *  self,
const FlutterBackingStore *  backing_store 
)
static

Definition at line 357 of file fl_engine.cc.

359  {
360  free(const_cast<void*>(backing_store->software.allocation));
361  return true;
362 }

Referenced by compositor_collect_backing_store_callback().

◆ compositor_collect_backing_store_callback()

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

Definition at line 381 of file fl_engine.cc.

383  {
384  FlEngine* self = static_cast<FlEngine*>(user_data);
385  switch (self->renderer_type) {
386  case kOpenGL:
387  return collect_opengl_backing_store(self, backing_store);
388  case kSoftware:
389  return collect_software_backing_store(self, backing_store);
390  default:
391  return false;
392  }
393 }
const char FlTextDirection FlAssertiveness gpointer user_data
static bool collect_opengl_backing_store(FlEngine *self, const FlutterBackingStore *backing_store)
Definition: fl_engine.cc:321
static bool collect_software_backing_store(FlEngine *self, const FlutterBackingStore *backing_store)
Definition: fl_engine.cc:357

References collect_opengl_backing_store(), collect_software_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 365 of file fl_engine.cc.

368  {
369  FlEngine* self = static_cast<FlEngine*>(user_data);
370  switch (self->renderer_type) {
371  case kOpenGL:
372  return create_opengl_backing_store(self, config, backing_store_out);
373  case kSoftware:
374  return create_software_backing_store(self, config, backing_store_out);
375  default:
376  return false;
377  }
378 }
static bool create_opengl_backing_store(FlEngine *self, const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
Definition: fl_engine.cc:282
static bool create_software_backing_store(FlEngine *self, const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
Definition: fl_engine.cc:333

References create_opengl_backing_store(), create_software_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 396 of file fl_engine.cc.

397  {
398  FlEngine* self = static_cast<FlEngine*>(info->user_data);
399 
400  g_autoptr(FlRenderable) renderable = get_renderable(self, info->view_id);
401  if (renderable == nullptr) {
402  return true;
403  }
404 
405  fl_renderable_present_layers(renderable, info->layers, info->layers_count);
406  return true;
407 }
g_autoptr(FlEngine) engine
FlRenderable * renderable
static FlRenderable * get_renderable(FlEngine *self, int64_t view_id)
Definition: fl_engine.cc:187
void fl_renderable_present_layers(FlRenderable *self, const FlutterLayer **layers, size_t layers_count)

References fl_renderable_present_layers(), g_autoptr(), get_renderable(), and renderable.

Referenced by fl_engine_start().

◆ create_opengl_backing_store()

static bool create_opengl_backing_store ( FlEngine *  self,
const FlutterBackingStoreConfig *  config,
FlutterBackingStore *  backing_store_out 
)
static

Definition at line 282 of file fl_engine.cc.

285  {
286  if (!fl_opengl_manager_make_current(self->opengl_manager)) {
287  return false;
288  }
289 
290  GLint general_format = GL_RGBA;
291  GLint sized_format = GL_RGBA8;
292  if (epoxy_has_gl_extension("GL_EXT_texture_format_BGRA8888")) {
293  general_format = GL_BGRA_EXT;
294  sized_format = GL_BGRA8_EXT;
295  }
296 
297  FlFramebuffer* framebuffer = fl_framebuffer_new_multisample(
298  general_format, config->size.width, config->size.height,
299  fl_dart_project_get_enable_impeller(self->project));
300  if (!framebuffer) {
301  g_warning("Failed to create backing store");
302  return false;
303  }
304 
305  backing_store_out->type = kFlutterBackingStoreTypeOpenGL;
306  backing_store_out->open_gl.type = kFlutterOpenGLTargetTypeFramebuffer;
307  backing_store_out->open_gl.framebuffer.user_data = framebuffer;
308  backing_store_out->open_gl.framebuffer.name =
309  fl_framebuffer_get_id(framebuffer);
310  backing_store_out->open_gl.framebuffer.target =
311  fl_framebuffer_get_texture_id(framebuffer) != 0 ? sized_format : GL_RGBA8;
312  backing_store_out->open_gl.framebuffer.destruction_callback = [](void* p) {
313  // Backing store destroyed in fl_compositor_opengl_collect_backing_store(),
314  // set on FlutterCompositor.collect_backing_store_callback during engine
315  // start.
316  };
317 
318  return true;
319 }
G_MODULE_EXPORT gboolean fl_dart_project_get_enable_impeller(FlDartProject *project)
GLuint fl_framebuffer_get_id(FlFramebuffer *self)
GLuint fl_framebuffer_get_texture_id(FlFramebuffer *self)
FlFramebuffer * fl_framebuffer_new_multisample(GLint format, size_t width, size_t height, gboolean use_msaa)

References fl_dart_project_get_enable_impeller(), fl_framebuffer_get_id(), fl_framebuffer_get_texture_id(), fl_framebuffer_new_multisample(), and fl_opengl_manager_make_current().

Referenced by compositor_create_backing_store_callback().

◆ create_software_backing_store()

static bool create_software_backing_store ( FlEngine *  self,
const FlutterBackingStoreConfig *  config,
FlutterBackingStore *  backing_store_out 
)
static

Definition at line 333 of file fl_engine.cc.

336  {
337  size_t allocation_length = config->size.width * config->size.height * 4;
338  uint8_t* allocation = static_cast<uint8_t*>(malloc(allocation_length));
339  if (allocation == nullptr) {
340  return false;
341  }
342 
343  backing_store_out->type = kFlutterBackingStoreTypeSoftware;
344  backing_store_out->software.allocation = allocation;
345  backing_store_out->software.height = config->size.height;
346  backing_store_out->software.row_bytes = config->size.width * 4;
347  backing_store_out->software.user_data = nullptr;
348  backing_store_out->software.destruction_callback = [](void* p) {
349  // Backing store destroyed in
350  // fl_compositor_software_collect_backing_store(), set on
351  // FlutterCompositor.collect_backing_store_callback during engine start.
352  };
353 
354  return true;
355 }

Referenced by compositor_create_backing_store_callback().

◆ fl_engine_add_view()

FlutterViewId fl_engine_add_view ( FlEngine *  engine,
FlRenderable *  renderable,
size_t  min_width,
size_t  min_height,
size_t  max_width,
size_t  max_height,
double  pixel_ratio,
GCancellable *  cancellable,
GAsyncReadyCallback  callback,
gpointer  user_data 
)

fl_engine_add_view: @engine: an #FlEngine. @renderable: the object that will render this view. @min_width: minimum width of view in pixels. @min_height: minimum height of view in pixels. @max_width: maximum width of view in pixels. @max_height: maximum 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 963 of file fl_engine.cc.

972  {
973  g_return_val_if_fail(FL_IS_ENGINE(self), -1);
974 
975  g_autoptr(GTask) task = g_task_new(self, cancellable, callback, user_data);
976 
977  FlutterViewId view_id = self->next_view_id;
978  self->next_view_id++;
979 
981 
982  // We don't know which display this view will open on, so set to zero and this
983  // will be updated in a following FlutterWindowMetricsEvent
984  FlutterEngineDisplayId display_id = 0;
985 
986  FlutterWindowMetricsEvent metrics = {};
987  metrics.struct_size = sizeof(FlutterWindowMetricsEvent);
988  metrics.width = min_width;
989  metrics.height = min_height;
990  metrics.pixel_ratio = pixel_ratio;
991  metrics.display_id = display_id;
992  metrics.view_id = view_id;
993  metrics.has_constraints = true;
994  metrics.min_width_constraint = min_width;
995  metrics.min_height_constraint = min_height;
996  metrics.max_width_constraint = max_width;
997  metrics.max_height_constraint = max_height;
998  FlutterAddViewInfo info;
999  info.struct_size = sizeof(FlutterAddViewInfo);
1000  info.view_id = view_id;
1001  info.view_metrics = &metrics;
1002  info.user_data = g_object_ref(task);
1003  info.add_view_callback = view_added_cb;
1004  FlutterEngineResult result = self->embedder_api.AddView(self->engine, &info);
1005  if (result != kSuccess) {
1006  g_task_return_new_error(task, fl_engine_error_quark(),
1007  FL_ENGINE_ERROR_FAILED, "AddView returned %d",
1008  result);
1009  // This would have been done in the callback, but that won't occur now.
1010  g_object_unref(task);
1011  }
1012 
1013  return view_id;
1014 }
static void view_added_cb(const FlutterAddViewResult *result)
Definition: fl_engine.cc:203
static void set_renderable(FlEngine *self, int64_t view_id, FlRenderable *renderable)
Stores a weak reference to the renderable with the given ID.
Definition: fl_engine.cc:175
GQuark fl_engine_error_quark(void) G_GNUC_CONST
@ FL_ENGINE_ERROR_FAILED
G_BEGIN_DECLS FlutterViewId view_id

References FL_ENGINE_ERROR_FAILED, fl_engine_error_quark(), g_autoptr(), renderable, set_renderable(), user_data, view_added_cb(), and view_id.

Referenced by fl_view_new_for_engine(), fl_view_new_sized_to_content(), and TEST_F().

◆ 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. If error is not NULL, *error must be initialized (typically NULL, but an error from a previous call using GLib error handling is explicitly valid).

Completes request started with fl_engine_add_view().

Returns: TRUE on success.

Definition at line 1016 of file fl_engine.cc.

1018  {
1019  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1020  return g_task_propagate_boolean(G_TASK(result), error);
1021 }
const uint8_t uint32_t uint32_t GError ** error

References error.

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 642 of file fl_engine.cc.

642  {
643  G_OBJECT_CLASS(klass)->dispose = fl_engine_dispose;
644  G_OBJECT_CLASS(klass)->set_property = fl_engine_set_property;
645 
646  g_object_class_install_property(
647  G_OBJECT_CLASS(klass), PROP_BINARY_MESSENGER,
648  g_param_spec_object(
649  "binary-messenger", "messenger", "Binary messenger",
650  fl_binary_messenger_get_type(),
651  static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
652  G_PARAM_STATIC_STRINGS)));
653 
655  "on-pre-engine-restart", fl_engine_get_type(), G_SIGNAL_RUN_LAST, 0,
656  nullptr, nullptr, nullptr, G_TYPE_NONE, 0);
658  "update-semantics", fl_engine_get_type(), G_SIGNAL_RUN_LAST, 0, nullptr,
659  nullptr, nullptr, G_TYPE_NONE, 1, G_TYPE_POINTER);
660 }
static void fl_engine_dispose(GObject *object)
Definition: fl_engine.cc:592
static guint fl_engine_signals[LAST_SIGNAL]
Definition: fl_engine.cc:119
static void fl_engine_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
Definition: fl_engine.cc:576

References fl_engine_dispose(), fl_engine_set_property(), fl_engine_signals, SIGNAL_ON_PRE_ENGINE_RESTART, and SIGNAL_UPDATE_SEMANTICS.

◆ fl_engine_dispatch_semantics_action()

void fl_engine_dispatch_semantics_action ( FlEngine *  engine,
FlutterViewId  view_id,
uint64_t  node_id,
FlutterSemanticsAction  action,
GBytes *  data 
)

fl_engine_dispatch_semantics_action: @engine: an #FlEngine. @view_id: the view that the event occured on. @node_id: the semantics action identifier. @action: the action being dispatched. @data: (allow-none): data associated with the action.

Definition at line 1534 of file fl_engine.cc.

1538  {
1539  g_return_if_fail(FL_IS_ENGINE(self));
1540 
1541  if (self->engine == nullptr) {
1542  return;
1543  }
1544 
1545  const uint8_t* action_data = nullptr;
1546  size_t action_data_length = 0;
1547  if (data != nullptr) {
1548  action_data = static_cast<const uint8_t*>(
1549  g_bytes_get_data(data, &action_data_length));
1550  }
1551 
1552  FlutterSendSemanticsActionInfo info;
1553  info.struct_size = sizeof(FlutterSendSemanticsActionInfo);
1554  info.view_id = view_id;
1555  info.node_id = node_id;
1556  info.action = action;
1557  info.data = action_data;
1558  info.data_length = action_data_length;
1559  if (self->embedder_api.SendSemanticsAction(self->engine, &info) != kSuccess) {
1560  g_warning("Failed to send semantics action");
1561  }
1562 }

References view_id.

Referenced by fl_accessible_node_perform_action_impl(), and TEST_F().

◆ fl_engine_dispose()

static void fl_engine_dispose ( GObject *  object)
static

Definition at line 592 of file fl_engine.cc.

592  {
593  FlEngine* self = FL_ENGINE(object);
594 
595  if (self->engine != nullptr) {
596  if (self->embedder_api.Shutdown(self->engine) != kSuccess) {
597  g_warning("Failed to shutdown Flutter engine");
598  }
599  self->engine = nullptr;
600  }
601 
602  if (self->aot_data != nullptr) {
603  if (self->embedder_api.CollectAOTData(self->aot_data) != kSuccess) {
604  g_warning("Failed to send collect AOT data");
605  }
606  self->aot_data = nullptr;
607  }
608 
609  fl_binary_messenger_shutdown(self->binary_messenger);
610  fl_texture_registrar_shutdown(self->texture_registrar);
611 
612  g_clear_object(&self->project);
613  g_clear_object(&self->display_monitor);
614  g_clear_object(&self->opengl_manager);
615  g_clear_object(&self->texture_registrar);
616  g_clear_object(&self->binary_messenger);
617  g_clear_object(&self->settings_handler);
618  g_clear_object(&self->platform_handler);
619  g_clear_object(&self->accessibility_handler);
620  g_clear_object(&self->keyboard_manager);
621  g_clear_object(&self->text_input_handler);
622  g_clear_object(&self->keyboard_handler);
623  g_clear_object(&self->mouse_cursor_handler);
624  g_clear_object(&self->task_runner);
625  {
626  g_autoptr(GMutexLocker) locker =
627  g_mutex_locker_new(&self->renderables_mutex);
628  g_clear_pointer(&self->renderables_by_view_id, g_hash_table_unref);
629  }
630  g_mutex_clear(&self->renderables_mutex);
631 
632  if (self->platform_message_handler_destroy_notify) {
633  self->platform_message_handler_destroy_notify(
634  self->platform_message_handler_data);
635  }
636  self->platform_message_handler_data = nullptr;
637  self->platform_message_handler_destroy_notify = nullptr;
638 
639  G_OBJECT_CLASS(fl_engine_parent_class)->dispose(object);
640 }
void fl_binary_messenger_shutdown(FlBinaryMessenger *self)
void fl_texture_registrar_shutdown(FlTextureRegistrar *self)

References fl_binary_messenger_shutdown(), fl_texture_registrar_shutdown(), and g_autoptr().

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 1596 of file fl_engine.cc.

1596  {
1597  g_return_if_fail(FL_IS_ENGINE(self));
1598  if (self->embedder_api.RunTask(self->engine, task) != kSuccess) {
1599  g_warning("Failed to run task");
1600  }
1601 }

Referenced by fl_task_runner_process_expired_tasks_locked().

◆ fl_engine_for_id()

FlEngine* fl_engine_for_id ( int64_t  handle)

fl_engine_for_id: @handle: an engine identifier obtained through PlatformDispatcher.instance.engineId.

Returns Flutter engine associated with the identifier. The identifier must be valid and for a running engine otherwise the behavior is undefined. Must be called from the main thread.

Returns: a #FlEngine or NULL.

Definition at line 726 of file fl_engine.cc.

726  {
727  void* engine = reinterpret_cast<void*>(id);
728  g_return_val_if_fail(FL_IS_ENGINE(engine), nullptr);
729  return FL_ENGINE(engine);
730 }
int64_t id

References id.

Referenced by TEST_F().

◆ 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 1585 of file fl_engine.cc.

1586  {
1587  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1588  return self->binary_messenger;
1589 }

Referenced by fl_accessibility_handler_new(), fl_keyboard_manager_new(), fl_settings_handler_new(), fl_view_get_registrar_for_plugin(), realize_cb(), and TEST_F().

◆ fl_engine_get_display_monitor()

FlDisplayMonitor* fl_engine_get_display_monitor ( FlEngine *  engine)

fl_engine_get_display_monitor: @engine: an #FlEngine.

Gets the display monitor used by this engine.

Returns: an #FlDisplayMonitor.

Definition at line 756 of file fl_engine.cc.

756  {
757  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
758  return self->display_monitor;
759 }

Referenced by handle_geometry_changed(), and TEST_F().

◆ 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 942 of file fl_engine.cc.

942  {
943  return &(self->embedder_api);
944 }

Referenced by TEST_F().

◆ fl_engine_get_keyboard_manager()

FlKeyboardManager* fl_engine_get_keyboard_manager ( FlEngine *  engine)

fl_engine_get_keyboard_manager: @engine: an #FlEngine.

Gets the keyboard manager used by this engine.

Returns: an #FlKeyboardManager.

Definition at line 1628 of file fl_engine.cc.

1628  {
1629  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1630  return self->keyboard_manager;
1631 }

Referenced by handle_key_event(), sync_modifier_if_needed(), and TEST_F().

◆ fl_engine_get_mouse_cursor_handler()

FlMouseCursorHandler* fl_engine_get_mouse_cursor_handler ( FlEngine *  engine)

fl_engine_get_mouse_cursor_handler: @engine: an #FlEngine.

Gets the mouse cursor handler used by this engine.

Returns: an #FlMouseCursorHandler.

Definition at line 1638 of file fl_engine.cc.

1638  {
1639  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1640  return self->mouse_cursor_handler;
1641 }

Referenced by cursor_changed_cb(), setup_cursor(), and TEST_F().

◆ fl_engine_get_opengl_manager()

FlOpenGLManager* fl_engine_get_opengl_manager ( FlEngine *  engine)

fl_engine_get_opengl_manager: @engine: an #FlEngine.

Gets the OpenGL manager used by this engine.

Returns: an #FlOpenGLManager.

Definition at line 751 of file fl_engine.cc.

751  {
752  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
753  return self->opengl_manager;
754 }

Referenced by realize_cb().

◆ fl_engine_get_registrar_for_plugin()

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

Definition at line 562 of file fl_engine.cc.

564  {
565  FlEngine* self = FL_ENGINE(registry);
566 
567  return fl_plugin_registrar_new(nullptr, self->binary_messenger,
568  self->texture_registrar);
569 }
FlPluginRegistrar * fl_plugin_registrar_new(FlView *view, FlBinaryMessenger *messenger, FlTextureRegistrar *texture_registrar)

References fl_plugin_registrar_new().

Referenced by fl_engine_plugin_registry_iface_init().

◆ fl_engine_get_renderable()

FlRenderable* fl_engine_get_renderable ( FlEngine *  engine,
FlutterViewId  view_id 
)

fl_engine_get_renderable: @engine: an #FlEngine. @view_id: ID to check.

Gets the renderable associated with the give view ID.

Returns: (transfer full): a reference to an #FlRenderable or NULL if none for this ID.

Definition at line 1023 of file fl_engine.cc.

1023  {
1024  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1025 
1026  return get_renderable(self, view_id);
1027 }

References get_renderable(), and view_id.

◆ fl_engine_get_renderer_type()

FlutterRendererType fl_engine_get_renderer_type ( FlEngine *  engine)

fl_engine_get_renderer_type: @engine: an #FlEngine.

Gets the rendering type used by this engine.

Returns: type of rendering used.

Definition at line 746 of file fl_engine.cc.

746  {
747  g_return_val_if_fail(FL_IS_ENGINE(self), static_cast<FlutterRendererType>(0));
748  return self->renderer_type;
749 }

Referenced by setup_engine().

◆ 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 1591 of file fl_engine.cc.

1591  {
1592  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1593  return self->task_runner;
1594 }

Referenced by TEST_F().

◆ fl_engine_get_text_input_handler()

FlTextInputHandler* fl_engine_get_text_input_handler ( FlEngine *  engine)

fl_engine_get_text_input_handler: @engine: an #FlEngine.

Gets the text input handler used by this engine.

Returns: an #FlTextInputHandler.

Definition at line 1633 of file fl_engine.cc.

1633  {
1634  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1635  return self->text_input_handler;
1636 }

Referenced by fl_view_dispose(), fl_view_focus_in_event(), handle_key_event(), and TEST_F().

◆ 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 1603 of file fl_engine.cc.

1604  {
1605  g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1606  return self->texture_registrar;
1607 }

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 420 of file fl_engine.cc.

420  {
421  FlEngine* self = static_cast<FlEngine*>(user_data);
422  return fl_opengl_manager_clear_current(self->opengl_manager);
423 }
gboolean fl_opengl_manager_clear_current(FlOpenGLManager *self)

References fl_opengl_manager_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 436 of file fl_engine.cc.

441  {
442  FlEngine* self = static_cast<FlEngine*>(user_data);
443  if (!self->texture_registrar) {
444  return false;
445  }
446 
447  FlTexture* texture =
448  fl_texture_registrar_lookup_texture(self->texture_registrar, texture_id);
449  if (texture == nullptr) {
450  g_warning("Unable to find texture %" G_GINT64_FORMAT, texture_id);
451  return false;
452  }
453 
454  gboolean result;
455  g_autoptr(GError) error = nullptr;
456  if (FL_IS_TEXTURE_GL(texture)) {
457  result = fl_texture_gl_populate(FL_TEXTURE_GL(texture), width, height,
458  opengl_texture, &error);
459  } else if (FL_IS_PIXEL_BUFFER_TEXTURE(texture)) {
460  result =
461  fl_pixel_buffer_texture_populate(FL_PIXEL_BUFFER_TEXTURE(texture),
462  width, height, opengl_texture, &error);
463  } else {
464  g_warning("Unsupported texture type %" G_GINT64_FORMAT, texture_id);
465  return false;
466  }
467 
468  if (!result) {
469  g_warning("%s", error->message);
470  return false;
471  }
472 
473  return true;
474 }
gboolean fl_pixel_buffer_texture_populate(FlPixelBufferTexture *texture, uint32_t width, uint32_t height, FlutterOpenGLTexture *opengl_texture, GError **error)
const uint8_t uint32_t uint32_t * height
const uint8_t uint32_t * width
gboolean fl_texture_gl_populate(FlTextureGL *self, uint32_t width, uint32_t height, FlutterOpenGLTexture *opengl_texture, GError **error)
FlTexture * fl_texture_registrar_lookup_texture(FlTextureRegistrar *self, int64_t texture_id)
int64_t texture_id

References error, fl_pixel_buffer_texture_populate(), fl_texture_gl_populate(), fl_texture_registrar_lookup_texture(), g_autoptr(), height, 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 425 of file fl_engine.cc.

425  {
426  // There is only one frame buffer object - always return that.
427  return 0;
428 }

Referenced by fl_engine_start().

◆ fl_engine_gl_make_current()

static bool fl_engine_gl_make_current ( void *  user_data)
static

Definition at line 415 of file fl_engine.cc.

415  {
416  FlEngine* self = static_cast<FlEngine*>(user_data);
417  return fl_opengl_manager_make_current(self->opengl_manager);
418 }

References fl_opengl_manager_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 430 of file fl_engine.cc.

430  {
431  FlEngine* self = static_cast<FlEngine*>(user_data);
432  return fl_opengl_manager_make_resource_current(self->opengl_manager);
433 }
gboolean fl_opengl_manager_make_resource_current(FlOpenGLManager *self)

References fl_opengl_manager_make_resource_current(), and user_data.

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 411 of file fl_engine.cc.

411  {
412  return reinterpret_cast<void*>(eglGetProcAddress(name));
413 }

Referenced by fl_engine_start().

◆ fl_engine_init()

static void fl_engine_init ( FlEngine *  self)
static

Definition at line 662 of file fl_engine.cc.

662  {
663  self->thread = g_thread_self();
664 
665  self->embedder_api.struct_size = sizeof(FlutterEngineProcTable);
666  if (FlutterEngineGetProcAddresses(&self->embedder_api) != kSuccess) {
667  g_warning("Failed get get engine function pointers");
668  }
669 
670  self->opengl_manager = fl_opengl_manager_new();
671 
672  self->display_monitor =
673  fl_display_monitor_new(self, gdk_display_get_default());
674  self->task_runner = fl_task_runner_new(self);
675 
676  // Implicit view is 0, so start at 1.
677  self->next_view_id = 1;
678  g_mutex_init(&self->renderables_mutex);
679  self->renderables_by_view_id = g_hash_table_new_full(
680  g_direct_hash, g_direct_equal, nullptr, [](gpointer value) {
681  GWeakRef* ref = static_cast<GWeakRef*>(value);
682  g_weak_ref_clear(ref);
683  free(ref);
684  });
685 
686  self->texture_registrar = fl_texture_registrar_new(self);
687 }
FlDisplayMonitor * fl_display_monitor_new(FlEngine *engine, GdkDisplay *display)
FlOpenGLManager * fl_opengl_manager_new()
uint8_t value
FlTaskRunner * fl_task_runner_new(FlEngine *engine)
FlTextureRegistrar * fl_texture_registrar_new(FlEngine *engine)

References fl_display_monitor_new(), fl_opengl_manager_new(), fl_task_runner_new(), fl_texture_registrar_new(), and value.

◆ 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 1564 of file fl_engine.cc.

1565  {
1566  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1567  return self->embedder_api.MarkExternalTextureFrameAvailable(
1568  self->engine, texture_id) == kSuccess;
1569 }

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 732 of file fl_engine.cc.

732  {
733  return fl_engine_new_full(project, nullptr);
734 }
static FlEngine * fl_engine_new_full(FlDartProject *project, FlBinaryMessenger *binary_messenger)
Definition: fl_engine.cc:689

References fl_engine_new_full().

Referenced by fl_engine_new_headless(), fl_view_new(), TEST(), and TEST_F().

◆ fl_engine_new_full()

static FlEngine* fl_engine_new_full ( FlDartProject *  project,
FlBinaryMessenger *  binary_messenger 
)
static

Definition at line 689 of file fl_engine.cc.

690  {
691  g_return_val_if_fail(FL_IS_DART_PROJECT(project), nullptr);
692 
693  FlEngine* self = FL_ENGINE(g_object_new(fl_engine_get_type(), nullptr));
694 
695  self->project = FL_DART_PROJECT(g_object_ref(project));
696  const gchar* renderer = g_getenv("FLUTTER_LINUX_RENDERER");
697  if (g_strcmp0(renderer, "software") == 0) {
698  self->renderer_type = kSoftware;
699  g_warning(
700  "Using the software renderer. Not all features are supported. This is "
701  "not recommended.\n"
702  "\n"
703  "To switch back to the default renderer, unset the "
704  "FLUTTER_LINUX_RENDERER environment variable.");
705  } else {
706  if (renderer != nullptr && strcmp(renderer, "opengl") != 0) {
707  g_warning("Unknown renderer type '%s', defaulting to opengl", renderer);
708  }
709  self->renderer_type = kOpenGL;
710  }
711 
712  if (binary_messenger != nullptr) {
713  self->binary_messenger =
714  FL_BINARY_MESSENGER(g_object_ref(binary_messenger));
715  } else {
716  self->binary_messenger = fl_binary_messenger_new(self);
717  }
718  self->keyboard_manager = fl_keyboard_manager_new(self);
719  self->mouse_cursor_handler =
720  fl_mouse_cursor_handler_new(self->binary_messenger);
721  self->accessibility_handler = fl_accessibility_handler_new(self);
722 
723  return self;
724 }
FlAccessibilityHandler * fl_accessibility_handler_new(FlEngine *engine)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
FlKeyboardManager * fl_keyboard_manager_new(FlEngine *engine)
FlMouseCursorHandler * fl_mouse_cursor_handler_new(FlBinaryMessenger *messenger)

References fl_accessibility_handler_new(), fl_binary_messenger_new(), fl_keyboard_manager_new(), and fl_mouse_cursor_handler_new().

Referenced by fl_engine_new(), and fl_engine_new_with_binary_messenger().

◆ 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 742 of file fl_engine.cc.

742  {
743  return fl_engine_new(project);
744 }
G_MODULE_EXPORT FlEngine * fl_engine_new(FlDartProject *project)
Definition: fl_engine.cc:732

References fl_engine_new().

◆ fl_engine_new_with_binary_messenger()

FlEngine* fl_engine_new_with_binary_messenger ( FlBinaryMessenger *  binary_messenger)

fl_engine_new_with_binary_messenger: @binary_messenger: an #FlBinaryMessenger.

Creates a new engine with a custom binary messenger. Used for testing.

Returns: a new #FlEngine.

Definition at line 736 of file fl_engine.cc.

737  {
738  g_autoptr(FlDartProject) project = fl_dart_project_new();
739  return fl_engine_new_full(project, binary_messenger);
740 }
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()

References fl_dart_project_new(), fl_engine_new_full(), and g_autoptr().

Referenced by FlAccessibilityHandlerTest::SetUp(), FlKeyboardHandlerTest::SetUp(), and FlSettingsHandlerTest::SetUp().

◆ fl_engine_notify_display_update()

void fl_engine_notify_display_update ( FlEngine *  engine,
const FlutterEngineDisplay *  displays,
size_t  displays_length 
)

fl_engine_notify_display_update: @engine: an #FlEngine. @displays: displays present on the system. @displays_length: length of @displays.

Notify the current displays that are in the system.

Definition at line 946 of file fl_engine.cc.

948  {
949  g_return_if_fail(FL_IS_ENGINE(self));
950 
951  FlutterEngineResult result = self->embedder_api.NotifyDisplayUpdate(
952  self->engine, kFlutterEngineDisplaysUpdateTypeStartup, displays,
953  displays_length);
954  if (result != kSuccess) {
955  g_warning("Failed to notify display update to Flutter engine: %d", result);
956  }
957 }

Referenced by notify_display_update(), and TEST_F().

◆ fl_engine_on_pre_engine_restart_cb()

static void fl_engine_on_pre_engine_restart_cb ( void *  user_data)
static

Definition at line 543 of file fl_engine.cc.

543  {
544  FlEngine* self = FL_ENGINE(user_data);
545 
546  setup_keyboard(self);
547 
548  g_signal_emit(self, fl_engine_signals[SIGNAL_ON_PRE_ENGINE_RESTART], 0);
549 }
static void setup_keyboard(FlEngine *self)
Definition: fl_engine.cc:519

References fl_engine_signals, setup_keyboard(), SIGNAL_ON_PRE_ENGINE_RESTART, 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 492 of file fl_engine.cc.

493  {
494  FlEngine* self = FL_ENGINE(user_data);
495 
496  gboolean handled = FALSE;
497  if (self->platform_message_handler != nullptr) {
498  g_autoptr(GBytes) data =
499  g_bytes_new(message->message, message->message_size);
500  handled = self->platform_message_handler(
501  self, message->channel, data, message->response_handle,
502  self->platform_message_handler_data);
503  }
504 
505  if (!handled) {
506  fl_engine_send_platform_message_response(self, message->response_handle,
507  nullptr, nullptr);
508  }
509 }
const char * message
gboolean fl_engine_send_platform_message_response(FlEngine *self, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
Definition: fl_engine.cc:1082

References fl_engine_send_platform_message_response(), g_autoptr(), message, 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 553 of file fl_engine.cc.

555  {
556  g_autoptr(GTask) task = G_TASK(user_data);
557  g_task_return_pointer(task, g_bytes_new(data, data_length),
558  reinterpret_cast<GDestroyNotify>(g_bytes_unref));
559 }

References g_autoptr(), and 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 571 of file fl_engine.cc.

572  {
573  iface->get_registrar_for_plugin = fl_engine_get_registrar_for_plugin;
574 }
static FlPluginRegistrar * fl_engine_get_registrar_for_plugin(FlPluginRegistry *registry, const gchar *name)
Definition: fl_engine.cc:562

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 483 of file fl_engine.cc.

485  {
486  FlEngine* self = static_cast<FlEngine*>(user_data);
487 
488  fl_task_runner_post_flutter_task(self->task_runner, task, target_time_nanos);
489 }
void fl_task_runner_post_flutter_task(FlTaskRunner *self, FlutterTask task, uint64_t target_time_nanos)

References fl_task_runner_post_flutter_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 1571 of file fl_engine.cc.

1572  {
1573  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1574  return self->embedder_api.RegisterExternalTexture(self->engine, texture_id) ==
1575  kSuccess;
1576 }

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 1029 of file fl_engine.cc.

1033  {
1034  g_return_if_fail(FL_IS_ENGINE(self));
1035 
1036  remove_renderable(self, view_id);
1037 
1038  g_autoptr(GTask) task = g_task_new(self, cancellable, callback, user_data);
1039 
1040  FlutterRemoveViewInfo info;
1041  info.struct_size = sizeof(FlutterRemoveViewInfo);
1042  info.view_id = view_id;
1043  info.user_data = g_object_ref(task);
1044  info.remove_view_callback = view_removed_cb;
1045  FlutterEngineResult result =
1046  self->embedder_api.RemoveView(self->engine, &info);
1047  if (result != kSuccess) {
1048  g_task_return_new_error(task, fl_engine_error_quark(),
1049  FL_ENGINE_ERROR_FAILED, "RemoveView returned %d",
1050  result);
1051  // This would have been done in the callback, but that won't occur now.
1052  g_object_unref(task);
1053  }
1054 }
static void remove_renderable(FlEngine *self, int64_t view_id)
Remove a renderable that no longer exists.
Definition: fl_engine.cc:198
static void view_removed_cb(const FlutterRemoveViewResult *result)
Definition: fl_engine.cc:214

References FL_ENGINE_ERROR_FAILED, fl_engine_error_quark(), g_autoptr(), remove_renderable(), user_data, view_id, and view_removed_cb().

Referenced by fl_view_dispose(), and TEST_F().

◆ 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. If error is not NULL, *error must be initialized (typically NULL, but an error from a previous call using GLib error handling is explicitly valid).

Completes request started with fl_engine_remove_view().

Returns: TRUE on succcess.

Definition at line 1056 of file fl_engine.cc.

1058  {
1059  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1060  return g_task_propagate_boolean(G_TASK(result), error);
1061 }

References error.

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

◆ fl_engine_request_app_exit()

void fl_engine_request_app_exit ( FlEngine *  engine)

fl_engine_request_app_exit: @engine: an #FlEngine.

Request the application exits.

Definition at line 1623 of file fl_engine.cc.

1623  {
1624  g_return_if_fail(FL_IS_ENGINE(self));
1625  fl_platform_handler_request_app_exit(self->platform_handler);
1626 }
void fl_platform_handler_request_app_exit(FlPlatformHandler *self)

References fl_platform_handler_request_app_exit().

Referenced by window_delete_event_cb().

◆ fl_engine_runs_task_on_current_thread()

static bool fl_engine_runs_task_on_current_thread ( void *  user_data)
static

Definition at line 477 of file fl_engine.cc.

477  {
478  FlEngine* self = static_cast<FlEngine*>(user_data);
479  return self->thread == g_thread_self();
480 }

References user_data.

Referenced by fl_engine_start().

◆ fl_engine_schedule_frame()

void fl_engine_schedule_frame ( FlEngine *  engine)

fl_engine_schedule_frame: @engine: an #FlEngine.

Asks the engine to render another frame. Used when a view needs the current frame again, e.g. because it wasn't able to use the last one.

Definition at line 1185 of file fl_engine.cc.

1185  {
1186  g_return_if_fail(FL_IS_ENGINE(self));
1187 
1188  if (self->engine == nullptr) {
1189  return;
1190  }
1191 
1192  if (self->embedder_api.ScheduleFrame(self->engine) != kSuccess) {
1193  g_warning("Failed to schedule frame");
1194  }
1195 }

Referenced by TEST_F().

◆ fl_engine_send_key_event()

void fl_engine_send_key_event ( FlEngine *  engine,
const FlutterKeyEvent *  event,
GCancellable *  cancellable,
GAsyncReadyCallback  callback,
gpointer  user_data 
)

fl_engine_send_key_event: @engine: an #FlEngine. @event: key event to send. @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.

Send a key event to the engine.

Definition at line 1494 of file fl_engine.cc.

1498  {
1499  g_return_if_fail(FL_IS_ENGINE(self));
1500 
1501  g_autoptr(GTask) task = g_task_new(self, cancellable, callback, user_data);
1502 
1503  if (self->engine == nullptr) {
1504  g_task_return_new_error(task, fl_engine_error_quark(),
1505  FL_ENGINE_ERROR_FAILED, "No engine");
1506  return;
1507  }
1508 
1509  if (self->embedder_api.SendKeyEvent(self->engine, event, send_key_event_cb,
1510  g_object_ref(task)) != kSuccess) {
1511  g_task_return_new_error(task, fl_engine_error_quark(),
1512  FL_ENGINE_ERROR_FAILED, "Failed to send key event");
1513  g_object_unref(task);
1514  }
1515 }
static void send_key_event_cb(bool handled, void *user_data)
Definition: fl_engine.cc:1487

References FL_ENGINE_ERROR_FAILED, fl_engine_error_quark(), g_autoptr(), send_key_event_cb(), and user_data.

Referenced by fl_key_embedder_responder_handle_event(), fl_key_embedder_responder_handle_event_impl(), synthesize_simple_event(), and TEST_F().

◆ fl_engine_send_key_event_finish()

gboolean fl_engine_send_key_event_finish ( FlEngine *  engine,
GAsyncResult *  result,
gboolean *  handled,
GError **  error 
)

fl_engine_send_key_event_finish: @engine: an #FlEngine.

Returns
: a #GAsyncResult. @handled: location to write if this event was handled by the engine. @error: (allow-none): #GError location to store the error occurring, or NULL to ignore. If error is not NULL, *error must be initialized (typically NULL, but an error from a previous call using GLib error handling is explicitly valid).

Completes request started with fl_engine_send_key_event().

Returns: TRUE on success.

Definition at line 1517 of file fl_engine.cc.

1520  {
1521  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1522  g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
1523 
1524  g_autofree gboolean* return_value =
1525  static_cast<gboolean*>(g_task_propagate_pointer(G_TASK(result), error));
1526  if (return_value == nullptr) {
1527  return FALSE;
1528  }
1529 
1530  *handled = *return_value;
1531  return TRUE;
1532 }

References error, and TRUE.

Referenced by TEST_F().

◆ 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,
double  rotation,
double  pressure 
)

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. @rotation: rotation of the pointer device in degrees. @pressure: pressure of the pointer device.

Sends a mouse pointer event to the engine.

Definition at line 1229 of file fl_engine.cc.

1240  {
1241  g_return_if_fail(FL_IS_ENGINE(self));
1242 
1243  if (self->engine == nullptr) {
1244  return;
1245  }
1246 
1247  FlutterPointerEvent fl_event = {};
1248  fl_event.struct_size = sizeof(fl_event);
1249  fl_event.phase = phase;
1250  fl_event.timestamp = timestamp;
1251  fl_event.x = x;
1252  fl_event.y = y;
1253  if (scroll_delta_x != 0 || scroll_delta_y != 0) {
1254  fl_event.signal_kind = kFlutterPointerSignalKindScroll;
1255  }
1256  fl_event.scroll_delta_x = scroll_delta_x;
1257  fl_event.scroll_delta_y = scroll_delta_y;
1258  fl_event.device_kind = device_kind;
1259  fl_event.buttons = buttons;
1260  fl_event.device = kMousePointerDeviceId;
1261  fl_event.view_id = view_id;
1262  // GDK reports tablet pressure through GDK_AXIS_PRESSURE. The GDK input device
1263  // documentation defines pressure as normalized from 0.0 to 1.0, which matches
1264  // Flutter's expected pressure range.
1265  // See: https://refspecs.linuxbase.org/gtk/2.6/gdk/gdk-Input-Devices.html
1266  fl_event.pressure = pressure;
1267  fl_event.pressure_min = 0.0;
1268  fl_event.pressure_max = 1.0;
1269  // GTK reports rotation in degrees, so convert it to radians for
1270  // FlutterPointerEvent.rotation.
1271  fl_event.rotation = rotation * G_PI / 180.0;
1272  if (self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1) !=
1273  kSuccess) {
1274  g_warning("Failed to send pointer event");
1275  }
1276 }
static constexpr int32_t kMousePointerDeviceId
Definition: fl_engine.cc:35

References kMousePointerDeviceId, and view_id.

Referenced by ensure_pointer_added(), fl_pointer_manager_cancel_input(), fl_pointer_manager_handle_button_press(), fl_pointer_manager_handle_button_release(), fl_pointer_manager_handle_leave(), fl_pointer_manager_handle_motion(), fl_scrolling_manager_handle_scroll_event(), and TEST_F().

◆ 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 1114 of file fl_engine.cc.

1119  {
1120  g_return_if_fail(FL_IS_ENGINE(self));
1121 
1122  GTask* task = nullptr;
1123  FlutterPlatformMessageResponseHandle* response_handle = nullptr;
1124  if (callback != nullptr) {
1125  task = g_task_new(self, cancellable, callback, user_data);
1126 
1127  if (self->engine == nullptr) {
1128  g_task_return_new_error(task, fl_engine_error_quark(),
1129  FL_ENGINE_ERROR_FAILED, "No engine to send to");
1130  g_object_unref(task);
1131  return;
1132  }
1133 
1134  FlutterEngineResult result =
1135  self->embedder_api.PlatformMessageCreateResponseHandle(
1136  self->engine, fl_engine_platform_message_response_cb, task,
1137  &response_handle);
1138  if (result != kSuccess) {
1139  g_task_return_new_error(task, fl_engine_error_quark(),
1141  "Failed to create response handle");
1142  g_object_unref(task);
1143  return;
1144  }
1145  } else if (self->engine == nullptr) {
1146  return;
1147  }
1148 
1149  FlutterPlatformMessage fl_message = {};
1150  fl_message.struct_size = sizeof(fl_message);
1151  fl_message.channel = channel;
1152  fl_message.message =
1153  message != nullptr
1154  ? static_cast<const uint8_t*>(g_bytes_get_data(message, nullptr))
1155  : nullptr;
1156  fl_message.message_size = message != nullptr ? g_bytes_get_size(message) : 0;
1157  fl_message.response_handle = response_handle;
1158  FlutterEngineResult result =
1159  self->embedder_api.SendPlatformMessage(self->engine, &fl_message);
1160 
1161  if (result != kSuccess && task != nullptr) {
1162  g_task_return_new_error(task, fl_engine_error_quark(),
1164  "Failed to send platform messages");
1165  g_object_unref(task);
1166  }
1167 
1168  if (response_handle != nullptr) {
1169  if (self->embedder_api.PlatformMessageReleaseResponseHandle(
1170  self->engine, response_handle) != kSuccess) {
1171  g_warning("Failed to release response handle");
1172  }
1173  }
1174 }
static void fl_engine_platform_message_response_cb(const uint8_t *data, size_t data_length, void *user_data)
Definition: fl_engine.cc:553

References FL_ENGINE_ERROR_FAILED, fl_engine_error_quark(), fl_engine_platform_message_response_cb(), message, and user_data.

Referenced by send_on_channel(), and TEST_F().

◆ 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. If error is not NULL, *error must be initialized (typically NULL, but an error from a previous call using GLib error handling is explicitly valid).

Completes request started with fl_engine_send_platform_message().

Returns: message response on success or NULL on error.

Definition at line 1176 of file fl_engine.cc.

1178  {
1179  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1180  g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
1181 
1182  return static_cast<GBytes*>(g_task_propagate_pointer(G_TASK(result), error));
1183 }

References error.

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. If error is not NULL, *error must be initialized (typically NULL, but an error from a previous call using GLib error handling is explicitly valid).

Responds to a platform message.

Returns: TRUE on success.

Definition at line 1082 of file fl_engine.cc.

1086  {
1087  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1088  g_return_val_if_fail(handle != nullptr, FALSE);
1089 
1090  if (self->engine == nullptr) {
1092  "No engine to send response to");
1093  return FALSE;
1094  }
1095 
1096  gsize data_length = 0;
1097  const uint8_t* data = nullptr;
1098  if (response != nullptr) {
1099  data =
1100  static_cast<const uint8_t*>(g_bytes_get_data(response, &data_length));
1101  }
1102  FlutterEngineResult result = self->embedder_api.SendPlatformMessageResponse(
1103  self->engine, handle, data, data_length);
1104 
1105  if (result != kSuccess) {
1107  "Failed to send platform message response");
1108  return FALSE;
1109  }
1110 
1111  return TRUE;
1112 }

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

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

◆ 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 1452 of file fl_engine.cc.

1461  {
1462  g_return_if_fail(FL_IS_ENGINE(self));
1463 
1464  if (self->engine == nullptr) {
1465  return;
1466  }
1467 
1468  FlutterPointerEvent fl_event = {};
1469  fl_event.struct_size = sizeof(fl_event);
1470  fl_event.timestamp = timestamp;
1471  fl_event.x = x;
1472  fl_event.y = y;
1473  fl_event.phase = phase;
1474  fl_event.pan_x = pan_x;
1475  fl_event.pan_y = pan_y;
1476  fl_event.scale = scale;
1477  fl_event.rotation = rotation;
1478  fl_event.device = kPointerPanZoomDeviceId;
1479  fl_event.device_kind = kFlutterPointerDeviceKindTrackpad;
1480  fl_event.view_id = view_id;
1481  if (self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1) !=
1482  kSuccess) {
1483  g_warning("Failed to send pointer event");
1484  }
1485 }
static constexpr int32_t kPointerPanZoomDeviceId
Definition: fl_engine.cc:36
G_BEGIN_DECLS FlSubsurface size_t size_t gint scale

References kPointerPanZoomDeviceId, scale, and view_id.

Referenced by fl_scrolling_manager_handle_rotation_begin(), fl_scrolling_manager_handle_rotation_end(), fl_scrolling_manager_handle_rotation_update(), fl_scrolling_manager_handle_scroll_event(), fl_scrolling_manager_handle_zoom_begin(), fl_scrolling_manager_handle_zoom_end(), fl_scrolling_manager_handle_zoom_update(), and TEST_F().

◆ fl_engine_send_touch_add_event()

void fl_engine_send_touch_add_event ( FlEngine *  engine,
FlutterViewId  view_id,
size_t  timestamp,
double  x,
double  y,
int32_t  device 
)

fl_engine_send_touch_add_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. @device: device id.

Sends a touch add event to the engine.

Definition at line 1394 of file fl_engine.cc.

1399  {
1400  g_return_if_fail(FL_IS_ENGINE(self));
1401 
1402  if (self->engine == nullptr) {
1403  return;
1404  }
1405 
1406  FlutterPointerEvent event = {};
1407  event.timestamp = timestamp;
1408  event.x = x;
1409  event.y = y;
1410  event.device_kind = kFlutterPointerDeviceKindTouch;
1411  event.device = device;
1412  event.buttons = 0;
1413  event.view_id = view_id;
1414  event.phase = FlutterPointerPhase::kAdd;
1415  event.struct_size = sizeof(event);
1416 
1417  if (self->embedder_api.SendPointerEvent(self->engine, &event, 1) !=
1418  kSuccess) {
1419  g_warning("Failed to send pointer event");
1420  }
1421 }

References view_id.

Referenced by ensure_touch_added().

◆ fl_engine_send_touch_cancel_event()

void fl_engine_send_touch_cancel_event ( FlEngine *  engine,
FlutterViewId  view_id,
size_t  timestamp,
double  x,
double  y,
int32_t  device 
)

fl_engine_send_touch_cancel_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. @device: device id.

Sends a touch cancel event to the engine, i.e. the touch sequence was aborted without the touch being lifted.

Definition at line 1365 of file fl_engine.cc.

1370  {
1371  g_return_if_fail(FL_IS_ENGINE(self));
1372 
1373  if (self->engine == nullptr) {
1374  return;
1375  }
1376 
1377  FlutterPointerEvent event = {};
1378  event.timestamp = timestamp;
1379  event.x = x;
1380  event.y = y;
1381  event.device_kind = kFlutterPointerDeviceKindTouch;
1382  event.device = device;
1383  event.buttons = 0;
1384  event.view_id = view_id;
1385  event.phase = FlutterPointerPhase::kCancel;
1386  event.struct_size = sizeof(event);
1387 
1388  if (self->embedder_api.SendPointerEvent(self->engine, &event, 1) !=
1389  kSuccess) {
1390  g_warning("Failed to send touch cancel event");
1391  }
1392 }

References view_id.

Referenced by fl_touch_manager_cancel_input(), and fl_touch_manager_handle_touch_event().

◆ fl_engine_send_touch_down_event()

void fl_engine_send_touch_down_event ( FlEngine *  engine,
FlutterViewId  view_id,
size_t  timestamp,
double  x,
double  y,
int32_t  device 
)

fl_engine_send_touch_down_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. @device: device id.

Sends a touch down event to the engine.

Definition at line 1307 of file fl_engine.cc.

1312  {
1313  g_return_if_fail(FL_IS_ENGINE(self));
1314 
1315  if (self->engine == nullptr) {
1316  return;
1317  }
1318 
1319  FlutterPointerEvent event = {};
1320  event.timestamp = timestamp;
1321  event.x = x;
1322  event.y = y;
1323  event.device_kind = kFlutterPointerDeviceKindTouch;
1324  event.device = device;
1325  event.buttons = FlutterPointerMouseButtons::kFlutterPointerButtonMousePrimary;
1326  event.view_id = view_id;
1327  event.phase = FlutterPointerPhase::kDown;
1328  event.struct_size = sizeof(event);
1329 
1330  if (self->embedder_api.SendPointerEvent(self->engine, &event, 1) !=
1331  kSuccess) {
1332  g_warning("Failed to send pointer event");
1333  }
1334 }

References view_id.

Referenced by fl_touch_manager_handle_touch_event().

◆ fl_engine_send_touch_move_event()

void fl_engine_send_touch_move_event ( FlEngine *  engine,
FlutterViewId  view_id,
size_t  timestamp,
double  x,
double  y,
int32_t  device 
)

fl_engine_send_touch_move_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. @device: device id.

Sends a touch move event to the engine.

Definition at line 1336 of file fl_engine.cc.

1341  {
1342  g_return_if_fail(FL_IS_ENGINE(self));
1343 
1344  if (self->engine == nullptr) {
1345  return;
1346  }
1347 
1348  FlutterPointerEvent event = {};
1349  event.timestamp = timestamp;
1350  event.x = x;
1351  event.y = y;
1352  event.device_kind = kFlutterPointerDeviceKindTouch;
1353  event.device = device;
1354  event.buttons = FlutterPointerMouseButtons::kFlutterPointerButtonMousePrimary;
1355  event.view_id = view_id;
1356  event.phase = FlutterPointerPhase::kMove;
1357  event.struct_size = sizeof(event);
1358 
1359  if (self->embedder_api.SendPointerEvent(self->engine, &event, 1) !=
1360  kSuccess) {
1361  g_warning("Failed to send pointer event");
1362  }
1363 }

References view_id.

Referenced by fl_touch_manager_handle_touch_event().

◆ fl_engine_send_touch_remove_event()

void fl_engine_send_touch_remove_event ( FlEngine *  engine,
FlutterViewId  view_id,
size_t  timestamp,
double  x,
double  y,
int32_t  device 
)

fl_engine_send_touch_remove_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. @device: device id.

Sends a touch remove event to the engine.

Definition at line 1423 of file fl_engine.cc.

1428  {
1429  g_return_if_fail(FL_IS_ENGINE(self));
1430 
1431  if (self->engine == nullptr) {
1432  return;
1433  }
1434 
1435  FlutterPointerEvent event = {};
1436  event.timestamp = timestamp;
1437  event.x = x;
1438  event.y = y;
1439  event.device_kind = kFlutterPointerDeviceKindTouch;
1440  event.device = device;
1441  event.buttons = 0;
1442  event.view_id = view_id;
1443  event.phase = FlutterPointerPhase::kRemove;
1444  event.struct_size = sizeof(event);
1445 
1446  if (self->embedder_api.SendPointerEvent(self->engine, &event, 1) !=
1447  kSuccess) {
1448  g_warning("Failed to send pointer event");
1449  }
1450 }

References view_id.

Referenced by fl_touch_manager_cancel_input(), and fl_touch_manager_handle_touch_event().

◆ fl_engine_send_touch_up_event()

void fl_engine_send_touch_up_event ( FlEngine *  engine,
FlutterViewId  view_id,
size_t  timestamp,
double  x,
double  y,
int32_t  device 
)

fl_engine_send_touch_up_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. @device: device id.

Sends a touch up event to the engine.

Definition at line 1278 of file fl_engine.cc.

1283  {
1284  g_return_if_fail(FL_IS_ENGINE(self));
1285 
1286  if (self->engine == nullptr) {
1287  return;
1288  }
1289 
1290  FlutterPointerEvent event = {};
1291  event.timestamp = timestamp;
1292  event.x = x;
1293  event.y = y;
1294  event.device_kind = kFlutterPointerDeviceKindTouch;
1295  event.device = device;
1296  event.buttons = 0;
1297  event.view_id = view_id;
1298  event.phase = FlutterPointerPhase::kUp;
1299  event.struct_size = sizeof(event);
1300 
1301  if (self->embedder_api.SendPointerEvent(self->engine, &event, 1) !=
1302  kSuccess) {
1303  g_warning("Failed to send pointer event");
1304  }
1305 }

References view_id.

Referenced by fl_touch_manager_handle_touch_event().

◆ fl_engine_send_window_metrics_event()

void fl_engine_send_window_metrics_event ( FlEngine *  engine,
FlutterEngineDisplayId  display_id,
FlutterViewId  view_id,
size_t  min_width,
size_t  min_height,
size_t  max_width,
size_t  max_height,
double  pixel_ratio 
)

fl_engine_send_window_metrics_event: @engine: an #FlEngine. @display_id: the display this view is rendering on. @view_id: the view that the event occured on. @min_width: minimum width of view in pixels. @min_height: minimum height of view in pixels. @max_width: maximum width of view in pixels. @max_height: maximum height of view in pixels. @pixel_ratio: scale factor for view.

Sends a window metrics event to the engine.

Definition at line 1197 of file fl_engine.cc.

1204  {
1205  g_return_if_fail(FL_IS_ENGINE(self));
1206 
1207  if (self->engine == nullptr) {
1208  return;
1209  }
1210 
1211  FlutterWindowMetricsEvent event = {};
1212  event.struct_size = sizeof(FlutterWindowMetricsEvent);
1213  event.width = min_width;
1214  event.height = min_height;
1215  event.pixel_ratio = pixel_ratio;
1216  event.display_id = display_id;
1217  event.view_id = view_id;
1218  event.has_constraints = true;
1219  event.min_width_constraint = min_width;
1220  event.min_height_constraint = min_height;
1221  event.max_width_constraint = max_width;
1222  event.max_height_constraint = max_height;
1223  if (self->embedder_api.SendWindowMetricsEvent(self->engine, &event) !=
1224  kSuccess) {
1225  g_warning("Failed to send window metrics");
1226  }
1227 }

References view_id.

Referenced by handle_geometry_changed(), and TEST_F().

◆ fl_engine_set_implicit_view()

void fl_engine_set_implicit_view ( FlEngine *  engine,
FlRenderable *  renderable 
)

fl_engine_set_implicit_view: @engine: an #FlEngine. @renderable: the object that will render the implicit view.

Sets the object to render the implicit view.

Definition at line 959 of file fl_engine.cc.

959  {
960  set_renderable(self, flutter::kFlutterImplicitViewId, renderable);
961 }

References renderable, and set_renderable().

Referenced by fl_view_new(), and FlCompositorOpenGLTest::SetUp().

◆ 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 1063 of file fl_engine.cc.

1067  {
1068  g_return_if_fail(FL_IS_ENGINE(self));
1069  g_return_if_fail(handler != nullptr);
1070 
1071  if (self->platform_message_handler_destroy_notify) {
1072  self->platform_message_handler_destroy_notify(
1073  self->platform_message_handler_data);
1074  }
1075 
1076  self->platform_message_handler = handler;
1077  self->platform_message_handler_data = user_data;
1078  self->platform_message_handler_destroy_notify = destroy_notify;
1079 }

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 576 of file fl_engine.cc.

579  {
580  FlEngine* self = FL_ENGINE(object);
581  switch (prop_id) {
582  case PROP_BINARY_MESSENGER:
583  g_set_object(&self->binary_messenger,
584  FL_BINARY_MESSENGER(g_value_get_object(value)));
585  break;
586  default:
587  G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
588  break;
589  }
590 }
guint prop_id
guint const GValue GParamSpec * pspec

References prop_id, pspec, and value.

Referenced by fl_engine_class_init().

◆ 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. If error is not NULL, *error must be initialized (typically NULL, but an error from a previous call using GLib error handling is explicitly valid).

Starts the Flutter engine.

Returns: TRUE on success.

Definition at line 761 of file fl_engine.cc.

761  {
762  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
763 
764  FlutterRendererConfig config = {};
765  config.type = self->renderer_type;
766  switch (config.type) {
767  case kSoftware:
768  config.software.struct_size = sizeof(FlutterSoftwareRendererConfig);
769  // No action required, as this is handled in
770  // compositor_present_view_callback.
771  config.software.surface_present_callback =
772  [](void* user_data, const void* allocation, size_t row_bytes,
773  size_t height) { return true; };
774  break;
775  case kOpenGL:
776  config.open_gl.struct_size = sizeof(FlutterOpenGLRendererConfig);
777  config.open_gl.gl_proc_resolver = fl_engine_gl_proc_resolver;
778  config.open_gl.make_current = fl_engine_gl_make_current;
779  config.open_gl.clear_current = fl_engine_gl_clear_current;
780  config.open_gl.fbo_callback = fl_engine_gl_get_fbo;
781  // No action required, as this is handled in
782  // compositor_present_view_callback.
783  config.open_gl.present = [](void* user_data) { return true; };
784  config.open_gl.make_resource_current = fl_engine_gl_make_resource_current;
785  config.open_gl.gl_external_texture_frame_callback =
787  break;
788  case kMetal:
789  case kVulkan:
790  default:
792  "Unsupported renderer type");
793  return FALSE;
794  }
795 
796  FlutterTaskRunnerDescription platform_task_runner = {};
797  platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription);
798  platform_task_runner.user_data = self;
799  platform_task_runner.runs_task_on_current_thread_callback =
801  platform_task_runner.post_task_callback = fl_engine_post_task;
802  platform_task_runner.identifier = kPlatformTaskRunnerIdentifier;
803 
804  FlutterCustomTaskRunners custom_task_runners = {};
805  custom_task_runners.struct_size = sizeof(FlutterCustomTaskRunners);
806  custom_task_runners.platform_task_runner = &platform_task_runner;
807 
808  switch (fl_dart_project_get_ui_thread_policy(self->project)) {
810  break;
813  custom_task_runners.ui_task_runner = &platform_task_runner;
814  break;
815  }
816 
817  const std::vector<std::string> env_switches =
819 
820  gboolean enable_impeller = fl_dart_project_get_enable_impeller(self->project);
821  gboolean has_enable_impeller = FALSE;
822  for (const auto& env_switch : env_switches) {
823  if (env_switch == "--enable-impeller" ||
824  env_switch == "--enable-impeller=true") {
825  enable_impeller = TRUE;
826  has_enable_impeller = TRUE;
827  } else if (env_switch == "--enable-impeller=false") {
828  enable_impeller = FALSE;
829  has_enable_impeller = TRUE;
830  }
831  }
832 
833  g_autoptr(GPtrArray) command_line_args =
834  g_ptr_array_new_with_free_func(g_free);
835  g_ptr_array_insert(command_line_args, 0, g_strdup("flutter"));
836  for (const auto& env_switch : env_switches) {
837  g_ptr_array_add(command_line_args, g_strdup(env_switch.c_str()));
838  }
839  // Linux (and other desktop platforms) always uses SDFs.
840  g_ptr_array_add(command_line_args, g_strdup("--impeller-use-sdfs"));
841 
842  if (enable_impeller && !has_enable_impeller) {
843  g_ptr_array_add(command_line_args, g_strdup("--enable-impeller"));
844  }
845 
846  // Forward the project's Flutter GPU setting unless an environment switch
847  // already carries it (the switch is presence based, so it is only ever
848  // added, never negated).
849  if (fl_dart_project_get_enable_flutter_gpu(self->project)) {
850  gboolean has_enable_flutter_gpu = FALSE;
851  for (const auto& env_switch : env_switches) {
852  if (env_switch == "--enable-flutter-gpu" ||
853  env_switch == "--enable-flutter-gpu=true") {
854  has_enable_flutter_gpu = TRUE;
855  break;
856  }
857  }
858  if (!has_enable_flutter_gpu) {
859  g_ptr_array_add(command_line_args, g_strdup("--enable-flutter-gpu"));
860  }
861  }
862 
863  gchar** dart_entrypoint_args =
865 
866  FlutterProjectArgs args = {};
867  args.struct_size = sizeof(FlutterProjectArgs);
868  args.assets_path = fl_dart_project_get_assets_path(self->project);
869  args.icu_data_path = fl_dart_project_get_icu_data_path(self->project);
870  args.command_line_argc = command_line_args->len;
871  args.command_line_argv =
872  reinterpret_cast<const char* const*>(command_line_args->pdata);
873  args.platform_message_callback = fl_engine_platform_message_cb;
874  args.update_semantics_callback2 = fl_engine_update_semantics_cb;
875  args.custom_task_runners = &custom_task_runners;
876  args.shutdown_dart_vm_when_done = true;
877  args.on_pre_engine_restart_callback = fl_engine_on_pre_engine_restart_cb;
878  args.dart_entrypoint_argc =
879  dart_entrypoint_args != nullptr ? g_strv_length(dart_entrypoint_args) : 0;
880  args.dart_entrypoint_argv =
881  reinterpret_cast<const char* const*>(dart_entrypoint_args);
882  args.engine_id = reinterpret_cast<int64_t>(self);
883 
884  FlutterCompositor compositor = {};
885  compositor.struct_size = sizeof(FlutterCompositor);
886  compositor.user_data = self;
887  compositor.create_backing_store_callback =
889  compositor.collect_backing_store_callback =
891  compositor.present_view_callback = compositor_present_view_callback;
892  args.compositor = &compositor;
893 
894  if (self->embedder_api.RunsAOTCompiledDartCode()) {
895  FlutterEngineAOTDataSource source = {};
896  source.type = kFlutterEngineAOTDataSourceTypeElfPath;
897  source.elf_path = fl_dart_project_get_aot_library_path(self->project);
898  if (self->embedder_api.CreateAOTData(&source, &self->aot_data) !=
899  kSuccess) {
901  "Failed to create AOT data");
902  return FALSE;
903  }
904  args.aot_data = self->aot_data;
905  }
906 
907  FlutterEngineResult result = self->embedder_api.Initialize(
908  FLUTTER_ENGINE_VERSION, &config, &args, self, &self->engine);
909  if (result != kSuccess) {
911  "Failed to initialize Flutter engine");
912  return FALSE;
913  }
914 
915  result = self->embedder_api.RunInitialized(self->engine);
916  if (result != kSuccess) {
918  "Failed to run Flutter engine");
919  return FALSE;
920  }
921 
922  setup_locales(self);
923 
924  g_autoptr(FlSettings) settings = fl_settings_new();
925  self->settings_handler = fl_settings_handler_new(self);
926  fl_settings_handler_start(self->settings_handler, settings);
927 
928  self->platform_handler = fl_platform_handler_new(self->binary_messenger);
929 
930  setup_keyboard(self);
931 
932  result = self->embedder_api.UpdateSemanticsEnabled(self->engine, TRUE);
933  if (result != kSuccess) {
934  g_warning("Failed to enable accessibility features on Flutter engine");
935  }
936 
937  fl_display_monitor_start(self->display_monitor);
938 
939  return TRUE;
940 }
G_MODULE_EXPORT const gchar * fl_dart_project_get_aot_library_path(FlDartProject *self)
G_MODULE_EXPORT gchar ** fl_dart_project_get_dart_entrypoint_arguments(FlDartProject *self)
G_MODULE_EXPORT gboolean fl_dart_project_get_enable_flutter_gpu(FlDartProject *project)
G_MODULE_EXPORT const gchar * fl_dart_project_get_icu_data_path(FlDartProject *self)
G_MODULE_EXPORT const gchar * fl_dart_project_get_assets_path(FlDartProject *self)
G_MODULE_EXPORT FlUIThreadPolicy fl_dart_project_get_ui_thread_policy(FlDartProject *project)
@ FL_UI_THREAD_POLICY_RUN_ON_PLATFORM_THREAD
@ FL_UI_THREAD_POLICY_RUN_ON_SEPARATE_THREAD
@ FL_UI_THREAD_POLICY_DEFAULT
void fl_display_monitor_start(FlDisplayMonitor *self)
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:436
static bool fl_engine_runs_task_on_current_thread(void *user_data)
Definition: fl_engine.cc:477
static void fl_engine_on_pre_engine_restart_cb(void *user_data)
Definition: fl_engine.cc:543
static bool compositor_create_backing_store_callback(const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out, void *user_data)
Definition: fl_engine.cc:365
static bool fl_engine_gl_make_current(void *user_data)
Definition: fl_engine.cc:415
static bool compositor_present_view_callback(const FlutterPresentViewInfo *info)
Definition: fl_engine.cc:396
static bool compositor_collect_backing_store_callback(const FlutterBackingStore *backing_store, void *user_data)
Definition: fl_engine.cc:381
static void fl_engine_post_task(FlutterTask task, uint64_t target_time_nanos, void *user_data)
Definition: fl_engine.cc:483
static uint32_t fl_engine_gl_get_fbo(void *user_data)
Definition: fl_engine.cc:425
static void * fl_engine_gl_proc_resolver(void *user_data, const char *name)
Definition: fl_engine.cc:411
static void setup_locales(FlEngine *self)
Definition: fl_engine.cc:232
static void fl_engine_update_semantics_cb(const FlutterSemanticsUpdate2 *update, void *user_data)
Definition: fl_engine.cc:512
static bool fl_engine_gl_make_resource_current(void *user_data)
Definition: fl_engine.cc:430
static void fl_engine_platform_message_cb(const FlutterPlatformMessage *message, void *user_data)
Definition: fl_engine.cc:492
static constexpr size_t kPlatformTaskRunnerIdentifier
Definition: fl_engine.cc:31
static bool fl_engine_gl_clear_current(void *user_data)
Definition: fl_engine.cc:420
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlPlatformHandler * fl_platform_handler_new(FlBinaryMessenger *messenger)
FlSettings * fl_settings_new()
Definition: fl_settings.cc:55
void fl_settings_handler_start(FlSettingsHandler *self, FlSettings *settings)
FlSettingsHandler * fl_settings_handler_new(FlEngine *engine)
std::vector< std::string > GetSwitchesFromEnvironment()

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_enable_flutter_gpu(), fl_dart_project_get_enable_impeller(), fl_dart_project_get_icu_data_path(), fl_dart_project_get_ui_thread_policy(), fl_display_monitor_start(), FL_ENGINE_ERROR_FAILED, fl_engine_error_quark(), 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_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_platform_handler_new(), fl_settings_handler_new(), fl_settings_handler_start(), fl_settings_new(), FL_UI_THREAD_POLICY_DEFAULT, FL_UI_THREAD_POLICY_RUN_ON_PLATFORM_THREAD, FL_UI_THREAD_POLICY_RUN_ON_SEPARATE_THREAD, g_autoptr(), flutter::GetSwitchesFromEnvironment(), height, kPlatformTaskRunnerIdentifier, setup_keyboard(), setup_locales(), TRUE, and user_data.

Referenced by realize_cb(), and TEST_F().

◆ 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 1578 of file fl_engine.cc.

1579  {
1580  g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1581  return self->embedder_api.UnregisterExternalTexture(self->engine,
1582  texture_id) == kSuccess;
1583 }

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 1609 of file fl_engine.cc.

1609  {
1610  g_return_if_fail(FL_IS_ENGINE(self));
1611 
1612  if (self->engine == nullptr) {
1613  return;
1614  }
1615 
1616  if (self->embedder_api.UpdateAccessibilityFeatures(
1617  self->engine, static_cast<FlutterAccessibilityFeature>(flags)) !=
1618  kSuccess) {
1619  g_warning("Failed to update accessibility features");
1620  }
1621 }

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 512 of file fl_engine.cc.

513  {
514  FlEngine* self = FL_ENGINE(user_data);
515 
516  g_signal_emit(self, fl_engine_signals[SIGNAL_UPDATE_SEMANTICS], 0, update);
517 }

References fl_engine_signals, SIGNAL_UPDATE_SEMANTICS, and user_data.

Referenced by fl_engine_start().

◆ free_locale()

static void free_locale ( FlutterLocale *  locale)
static

Definition at line 225 of file fl_engine.cc.

225  {
226  g_free(const_cast<gchar*>(locale->language_code));
227  g_free(const_cast<gchar*>(locale->country_code));
228  g_free(locale);
229 }

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 121 of file fl_engine.cc.

128  { PROP_0, PROP_BINARY_MESSENGER, PROP_LAST };
@ PROP_LAST
@ PROP_0

References PROP_0, and PROP_LAST.

◆ get_renderable()

static FlRenderable* get_renderable ( FlEngine *  self,
int64_t  view_id 
)
static

Returns the renderable with the given ID, or nullptr if no such view exists. Returns a reference to the renderable.

Definition at line 187 of file fl_engine.cc.

187  {
188  g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->renderables_mutex);
189  GWeakRef* ref = static_cast<GWeakRef*>(g_hash_table_lookup(
190  self->renderables_by_view_id, GINT_TO_POINTER(view_id)));
191  if (ref == nullptr) {
192  return nullptr;
193  }
194  return FL_RENDERABLE(g_weak_ref_get(ref));
195 }

References g_autoptr(), and view_id.

Referenced by compositor_present_view_callback(), and fl_engine_get_renderable().

◆ parse_locale()

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

Definition at line 131 of file fl_engine.cc.

135  {
136  gchar* l = g_strdup(locale);
137 
138  // Locales are in the form "language[_territory][.codeset][@modifier]"
139  gchar* match = strrchr(l, '@');
140  if (match != nullptr) {
141  if (modifier != nullptr) {
142  *modifier = g_strdup(match + 1);
143  }
144  *match = '\0';
145  } else if (modifier != nullptr) {
146  *modifier = nullptr;
147  }
148 
149  match = strrchr(l, '.');
150  if (match != nullptr) {
151  if (codeset != nullptr) {
152  *codeset = g_strdup(match + 1);
153  }
154  *match = '\0';
155  } else if (codeset != nullptr) {
156  *codeset = nullptr;
157  }
158 
159  match = strrchr(l, '_');
160  if (match != nullptr) {
161  if (territory != nullptr) {
162  *territory = g_strdup(match + 1);
163  }
164  *match = '\0';
165  } else if (territory != nullptr) {
166  *territory = nullptr;
167  }
168 
169  if (language != nullptr) {
170  *language = l;
171  }
172 }

Referenced by setup_locales().

◆ remove_renderable()

static void remove_renderable ( FlEngine *  self,
int64_t  view_id 
)
static

Remove a renderable that no longer exists.

Definition at line 198 of file fl_engine.cc.

198  {
199  g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->renderables_mutex);
200  g_hash_table_remove(self->renderables_by_view_id, GINT_TO_POINTER(view_id));
201 }

References g_autoptr(), and view_id.

Referenced by fl_engine_remove_view().

◆ send_key_event_cb()

static void send_key_event_cb ( bool  handled,
void *  user_data 
)
static

Definition at line 1487 of file fl_engine.cc.

1487  {
1488  g_autoptr(GTask) task = G_TASK(user_data);
1489  gboolean* return_value = g_new0(gboolean, 1);
1490  *return_value = handled;
1491  g_task_return_pointer(task, return_value, g_free);
1492 }

References g_autoptr(), and user_data.

Referenced by fl_engine_send_key_event().

◆ set_renderable()

static void set_renderable ( FlEngine *  self,
int64_t  view_id,
FlRenderable *  renderable 
)
static

Stores a weak reference to the renderable with the given ID.

Definition at line 175 of file fl_engine.cc.

177  {
178  g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->renderables_mutex);
179  GWeakRef* ref = g_new(GWeakRef, 1);
180  g_weak_ref_init(ref, G_OBJECT(renderable));
181  g_hash_table_insert(self->renderables_by_view_id, GINT_TO_POINTER(view_id),
182  ref);
183 }

References g_autoptr(), renderable, and view_id.

Referenced by fl_engine_add_view(), and fl_engine_set_implicit_view().

◆ setup_keyboard()

static void setup_keyboard ( FlEngine *  self)
static

Definition at line 519 of file fl_engine.cc.

519  {
520  g_clear_object(&self->keyboard_manager);
521  self->keyboard_manager = fl_keyboard_manager_new(self);
522 
523  g_clear_object(&self->keyboard_handler);
524  self->keyboard_handler =
525  fl_keyboard_handler_new(self->binary_messenger, self->keyboard_manager);
526 
527  GtkWidget* widget =
528  self->text_input_handler != nullptr
529  ? fl_text_input_handler_get_widget(self->text_input_handler)
530  : nullptr;
531  g_clear_object(&self->text_input_handler);
532  self->text_input_handler = fl_text_input_handler_new(self->binary_messenger);
533  if (widget != nullptr) {
534  fl_text_input_handler_set_widget(self->text_input_handler, widget);
535  }
536 }
FlKeyboardHandler * fl_keyboard_handler_new(FlBinaryMessenger *messenger, FlKeyboardManager *keyboard_manager)
FlTextInputHandler * fl_text_input_handler_new(FlBinaryMessenger *messenger)
void fl_text_input_handler_set_widget(FlTextInputHandler *self, GtkWidget *widget)
GtkWidget * fl_text_input_handler_get_widget(FlTextInputHandler *self)

References fl_keyboard_handler_new(), fl_keyboard_manager_new(), fl_text_input_handler_get_widget(), fl_text_input_handler_new(), and fl_text_input_handler_set_widget().

Referenced by fl_engine_on_pre_engine_restart_cb(), and fl_engine_start().

◆ setup_locales()

static void setup_locales ( FlEngine *  self)
static

Definition at line 232 of file fl_engine.cc.

232  {
233  const gchar* const* languages = g_get_language_names();
234  g_autoptr(GPtrArray) locales_array = g_ptr_array_new_with_free_func(
235  reinterpret_cast<GDestroyNotify>(free_locale));
236  for (int i = 0; languages[i] != nullptr; i++) {
237  g_autofree gchar* locale_string = g_strstrip(g_strdup(languages[i]));
238 
239  // Ignore empty locales, caused by settings like `LANGUAGE=pt_BR:`
240  if (strcmp(locale_string, "") == 0) {
241  continue;
242  }
243 
244  g_autofree gchar* language = nullptr;
245  g_autofree gchar* territory = nullptr;
246  parse_locale(locale_string, &language, &territory, nullptr, nullptr);
247 
248  // Ignore duplicate locales, caused by settings like `LANGUAGE=C` (returns
249  // two "C") or `LANGUAGE=en:en`
250  gboolean has_locale = FALSE;
251  for (guint j = 0; !has_locale && j < locales_array->len; j++) {
252  FlutterLocale* locale =
253  reinterpret_cast<FlutterLocale*>(g_ptr_array_index(locales_array, j));
254  has_locale = g_strcmp0(locale->language_code, language) == 0 &&
255  g_strcmp0(locale->country_code, territory) == 0;
256  }
257  if (has_locale) {
258  continue;
259  }
260 
261  FlutterLocale* locale =
262  static_cast<FlutterLocale*>(g_malloc0(sizeof(FlutterLocale)));
263  g_ptr_array_add(locales_array, locale);
264  locale->struct_size = sizeof(FlutterLocale);
265  locale->language_code =
266  reinterpret_cast<const gchar*>(g_steal_pointer(&language));
267  locale->country_code =
268  reinterpret_cast<const gchar*>(g_steal_pointer(&territory));
269  locale->script_code = nullptr;
270  locale->variant_code = nullptr;
271  }
272  FlutterLocale** locales =
273  reinterpret_cast<FlutterLocale**>(locales_array->pdata);
274  FlutterEngineResult result = self->embedder_api.UpdateLocales(
275  self->engine, const_cast<const FlutterLocale**>(locales),
276  locales_array->len);
277  if (result != kSuccess) {
278  g_warning("Failed to set up Flutter locales");
279  }
280 }
static void parse_locale(const gchar *locale, gchar **language, gchar **territory, gchar **codeset, gchar **modifier)
Definition: fl_engine.cc:131
static void free_locale(FlutterLocale *locale)
Definition: fl_engine.cc:225

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

Referenced by fl_engine_start().

◆ view_added_cb()

static void view_added_cb ( const FlutterAddViewResult *  result)
static

Definition at line 203 of file fl_engine.cc.

203  {
204  g_autoptr(GTask) task = G_TASK(result->user_data);
205 
206  if (result->added) {
207  g_task_return_boolean(task, TRUE);
208  } else {
209  g_task_return_new_error(task, fl_engine_error_quark(),
210  FL_ENGINE_ERROR_FAILED, "Failed to add view");
211  }
212 }

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

Referenced by fl_engine_add_view().

◆ view_removed_cb()

static void view_removed_cb ( const FlutterRemoveViewResult *  result)
static

Definition at line 214 of file fl_engine.cc.

214  {
215  g_autoptr(GTask) task = G_TASK(result->user_data);
216 
217  if (result->removed) {
218  g_task_return_boolean(task, TRUE);
219  } else {
220  g_task_return_new_error(task, fl_engine_error_quark(),
221  FL_ENGINE_ERROR_FAILED, "Failed to remove view");
222  }
223 }

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

Referenced by fl_engine_remove_view().

Variable Documentation

◆ fl_engine_signals

guint fl_engine_signals[LAST_SIGNAL]
static

◆ kMousePointerDeviceId

constexpr int32_t kMousePointerDeviceId = 0
staticconstexpr

Definition at line 35 of file fl_engine.cc.

Referenced by fl_engine_send_mouse_pointer_event().

◆ kPlatformTaskRunnerIdentifier

constexpr size_t kPlatformTaskRunnerIdentifier = 1
staticconstexpr

Definition at line 31 of file fl_engine.cc.

Referenced by fl_engine_start().

◆ kPointerPanZoomDeviceId

constexpr int32_t kPointerPanZoomDeviceId = 1
staticconstexpr

Definition at line 36 of file fl_engine.cc.

Referenced by fl_engine_send_pointer_pan_zoom_event().