| Flutter Linux Embedder |

Typedefs | Enumerations | Functions
fl_engine_private.h File Reference
`#include <glib-object.h>`
`#include "flutter/shell/platform/embedder/embedder.h"`
`#include "flutter/shell/platform/linux/fl_renderer.h"`
`#include "flutter/shell/platform/linux/fl_task_runner.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_dart_project.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"`

Go to the source code of this file.

## Typedefs
typedef gboolean(* | FlEnginePlatformMessageHandler) (FlEngine *engine, const gchar *channel, GBytes *message, const FlutterPlatformMessageResponseHandle *response_handle, gpointer user_data)
typedef void(* | FlEngineUpdateSemanticsHandler) (FlEngine *engine, const FlutterSemanticsUpdate2 *update, gpointer user_data)
typedef void(* | FlEngineOnPreEngineRestartHandler) (FlEngine *engine, gpointer user_data)

## Enumerations
enum | FlEngineError { FL_ENGINE_ERROR_FAILED }

## Functions
GQuark | fl_engine_error_quark (void) G_GNUC_CONST
FlEngine * | fl_engine_new (FlDartProject *project, FlRenderer *renderer)
FlutterEngineProcTable * | fl_engine_get_embedder_api (FlEngine *engine)
void | fl_engine_set_platform_message_handler (FlEngine *engine, FlEnginePlatformMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
void | fl_engine_set_update_semantics_handler (FlEngine *engine, FlEngineUpdateSemanticsHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
void | fl_engine_set_on_pre_engine_restart_handler (FlEngine *engine, FlEngineOnPreEngineRestartHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
gboolean | fl_engine_start (FlEngine *engine, GError **error)
void | fl_engine_send_window_metrics_event (FlEngine *engine, size_t width, size_t height, double pixel_ratio)
void | fl_engine_send_window_state_event (FlEngine *engine, gboolean visible, gboolean focused)
void | fl_engine_send_mouse_pointer_event (FlEngine *engine, FlutterPointerPhase phase, size_t timestamp, double x, double y, FlutterPointerDeviceKind device_kind, double scroll_delta_x, double scroll_delta_y, int64_t buttons)
void | fl_engine_send_pointer_pan_zoom_event (FlEngine *self, size_t timestamp, double x, double y, FlutterPointerPhase phase, double pan_x, double pan_y, double scale, double rotation)
void | fl_engine_send_key_event (FlEngine *engine, const FlutterKeyEvent *event, FlutterKeyEventCallback callback, void *user_data)
void | fl_engine_dispatch_semantics_action (FlEngine *engine, uint64_t id, FlutterSemanticsAction action, GBytes *data)
gboolean | fl_engine_send_platform_message_response (FlEngine *engine, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
void | fl_engine_send_platform_message (FlEngine *engine, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
GBytes * | fl_engine_send_platform_message_finish (FlEngine *engine, GAsyncResult *result, GError **error)
FlTaskRunner * | fl_engine_get_task_runner (FlEngine *engine)
void | fl_engine_execute_task (FlEngine *engine, FlutterTask *task)
gboolean | fl_engine_mark_texture_frame_available (FlEngine *engine, int64_t texture_id)
gboolean | fl_engine_register_external_texture (FlEngine *engine, int64_t texture_id)
gboolean | fl_engine_unregister_external_texture (FlEngine *engine, int64_t texture_id)
void | fl_engine_update_accessibility_features (FlEngine *engine, int32_t flags)
GPtrArray * | fl_engine_get_switches (FlEngine *engine)

## Typedef Documentation

## ◆ FlEngineOnPreEngineRestartHandler

typedef void(* FlEngineOnPreEngineRestartHandler) (FlEngine *engine, gpointer user_data)

FlEngineOnPreEngineRestartHandler: @engine: an #FlEngine. @user_data: (closure): data provided when registering this handler.

Function called right before the engine is restarted.

Definition at line 70 of file fl_engine_private.h.

## ◆ FlEnginePlatformMessageHandler

typedef gboolean(* FlEnginePlatformMessageHandler) (FlEngine *engine, const gchar *channel, GBytes *message, const FlutterPlatformMessageResponseHandle *response_handle, gpointer user_data)

FlEnginePlatformMessageHandler: @engine: an #FlEngine. @channel: channel message received on. @message: message content received from Dart. @response_handle: a handle to respond to the message with. @user_data: (closure): data provided when registering this handler.

Function called when platform messages are received.

Returns: TRUE if message has been accepted.

Definition at line 43 of file fl_engine_private.h.

## ◆ FlEngineUpdateSemanticsHandler

typedef void(* FlEngineUpdateSemanticsHandler) (FlEngine *engine, const FlutterSemanticsUpdate2 *update, gpointer user_data)

FlEngineUpdateSemanticsHandler: @engine: an #FlEngine. @node: semantic node information. @user_data: (closure): data provided when registering this handler.

Function called when semantics node updates are received.

Definition at line 58 of file fl_engine_private.h.

## Enumeration Type Documentation

## ◆ FlEngineError

enum FlEngineError

FlEngineError: Errors for #FlEngine objects to set on failures.

Enumerator
FL_ENGINE_ERROR_FAILED |

Definition at line 23 of file fl_engine_private.h.

23 {
24 // NOLINTBEGIN(readability-identifier-naming)
25 FL_ENGINE_ERROR_FAILED,
26 // NOLINTEND(readability-identifier-naming)
27 } FlEngineError;

## Function Documentation

## ◆ fl_engine_dispatch_semantics_action()

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

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

Definition at line 876 of file fl_engine.cc.

879 {
880 g_return_if_fail(FL_IS_ENGINE(self));
881
882 if (self->engine == nullptr) {
883 return;
884 }
885
886 const uint8_t* action_data = nullptr;
887 size_t action_data_length = 0;
888 if (data != nullptr) {
889 action_data = static_cast<const uint8_t*>(
890 g_bytes_get_data(data, &action_data_length));
891 }
892
893 self->embedder_api.DispatchSemanticsAction(self->engine, id, action,
894 action_data, action_data_length);
895 }

Referenced by fl_accessible_node_perform_action_impl(), and TEST().

## ◆ fl_engine_error_quark()

GQuark fl_engine_error_quark | ( | void |  | ) |

Referenced by fl_engine_send_platform_message(), fl_engine_send_platform_message_response(), and fl_engine_start().

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

929 {
930 g_return_if_fail(FL_IS_ENGINE(self));
931 self->embedder_api.RunTask(self->engine, task);
932 }

Referenced by fl_task_runner_process_expired_tasks_locked().

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

602 {
603 return &(self->embedder_api);
604 }

Referenced by TEST().

## ◆ fl_engine_get_switches()

GPtrArray* fl_engine_get_switches | ( | FlEngine * | engine | ) |

fl_engine_get_switches: @project: an #FlEngine.

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

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

Definition at line 951 of file fl_engine.cc.

951 {
952 GPtrArray* switches = g_ptr_array_new_with_free_func(g_free);
953 for (const auto& env_switch : flutter::GetSwitchesFromEnvironment()) {
954 g_ptr_array_add(switches, g_strdup(env_switch.c_str()));
955 }
956 return switches;
957 }

References flutter::GetSwitchesFromEnvironment().

Referenced by fl_engine_start(), and TEST().

## ◆ fl_engine_get_task_runner()

FlTaskRunner* fl_engine_get_task_runner | ( | FlEngine * | engine | ) |

fl_engine_get_task_runner: @engine: an #FlEngine.

Returns
  : a #FlTaskRunner.

Returns: task runner responsible for scheduling Flutter tasks.

Definition at line 924 of file fl_engine.cc.

924 {
925 g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
926 return self->task_runner;
927 }

Referenced by fl_renderer_unblock_main_thread(), and fl_renderer_wait_for_frame().

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

898 {
899 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
900 return self->embedder_api.MarkExternalTextureFrameAvailable(
901 self->engine, texture_id) == kSuccess;
902 }

References texture_id.

Referenced by mark_texture_frame_available().

## ◆ fl_engine_new()

FlEngine* fl_engine_new | ( | FlDartProject * | project,
|  | FlRenderer * | renderer
| ) |  |

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

Creates new Flutter engine.

Returns: a new #FlEngine.

Definition at line 458 of file fl_engine.cc.

458 {
459 g_return_val_if_fail(FL_IS_DART_PROJECT(project), nullptr);
460 g_return_val_if_fail(FL_IS_RENDERER(renderer), nullptr);
461
462 FlEngine* self = FL_ENGINE(g_object_new(fl_engine_get_type(), nullptr));
463 self->project = FL_DART_PROJECT(g_object_ref(project));
464 self->renderer = FL_RENDERER(g_object_ref(renderer));
465 self->binary_messenger = fl_binary_messenger_new(self);
466 return self;
467 }

References fl_binary_messenger_new().

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

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

905 {
906 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
907 return self->embedder_api.RegisterExternalTexture(self->engine, texture_id) ==
908 kSuccess;
909 }

References texture_id.

Referenced by register_texture().

## ◆ fl_engine_send_key_event()

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

fl_engine_send_key_event:

Definition at line 863 of file fl_engine.cc.

866 {
867 g_return_if_fail(FL_IS_ENGINE(self));
868
869 if (self->engine == nullptr) {
870 return;
871 }
872
873 self->embedder_api.SendKeyEvent(self->engine, event, callback, user_data);
874 }

References callback, event, and user_data.

Referenced by fl_view_keyboard_delegate_iface_init().

## ◆ fl_engine_send_mouse_pointer_event()

void fl_engine_send_mouse_pointer_event | ( | FlEngine * | engine,
|  | FlutterPointerPhase | phase,
|  | size_t | timestamp,
|  | double | x,
|  | double | y,
|  | FlutterPointerDeviceKind | device_kind,
|  | double | scroll_delta_x,
|  | double | scroll_delta_y,
|  | int64_t | buttons
| ) |  |

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

Sends a mouse pointer event to the engine.

Definition at line 793 of file fl_engine.cc.

801 {
802 g_return_if_fail(FL_IS_ENGINE(self));
803
804 if (self->engine == nullptr) {
805 return;
806 }
807
808 FlutterPointerEvent fl_event = {};
809 fl_event.struct_size = sizeof(fl_event);
810 fl_event.phase = phase;
811 fl_event.timestamp = timestamp;
812 fl_event.x = x;
813 fl_event.y = y;
814 if (scroll_delta_x != 0 || scroll_delta_y != 0) {
815 fl_event.signal_kind = kFlutterPointerSignalKindScroll;
816 }
817 fl_event.scroll_delta_x = scroll_delta_x;
818 fl_event.scroll_delta_y = scroll_delta_y;
819 fl_event.device_kind = device_kind;
820 fl_event.buttons = buttons;
821 fl_event.device = kMousePointerDeviceId;
822 // TODO(dkwingsmt): Assign the correct view ID once the Linux embedder
823 // supports multiple views.
824 // https://github.com/flutter/flutter/issues/138178
825 fl_event.view_id = flutter::kFlutterImplicitViewId;
826 self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);
827 }

References kMousePointerDeviceId.

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

## ◆ fl_engine_send_platform_message()

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

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

Asynchronously sends a platform message.

Definition at line 691 of file fl_engine.cc.

696 {
697 g_return_if_fail(FL_IS_ENGINE(self));
698
699 GTask* task = nullptr;
700 FlutterPlatformMessageResponseHandle* response_handle = nullptr;
701 if (callback != nullptr) {
702 task = g_task_new(self, cancellable, callback, user_data);
703
704 if (self->engine == nullptr) {
705 g_task_return_new_error(task, fl_engine_error_quark(),
706 FL_ENGINE_ERROR_FAILED, "No engine to send to");
707 return;
708 }
709
710 FlutterEngineResult result =
711 self->embedder_api.PlatformMessageCreateResponseHandle(
712 self->engine, fl_engine_platform_message_response_cb, task,
713 &response_handle);
714 if (result != kSuccess) {
715 g_task_return_new_error(task, fl_engine_error_quark(),
716 FL_ENGINE_ERROR_FAILED,
717 "Failed to create response handle");
718 g_object_unref(task);
719 return;
720 }
721 } else if (self->engine == nullptr) {
722 return;
723 }
724
725 FlutterPlatformMessage fl_message = {};
726 fl_message.struct_size = sizeof(fl_message);
727 fl_message.channel = channel;
728 fl_message.message =
729 message != nullptr
730 ? static_cast<const uint8_t*>(g_bytes_get_data(message, nullptr))
731 : nullptr;
732 fl_message.message_size = message != nullptr ? g_bytes_get_size(message) : 0;
733 fl_message.response_handle = response_handle;
734 FlutterEngineResult result =
735 self->embedder_api.SendPlatformMessage(self->engine, &fl_message);
736
737 if (result != kSuccess && task != nullptr) {
738 g_task_return_new_error(task, fl_engine_error_quark(),
739 FL_ENGINE_ERROR_FAILED,
740 "Failed to send platform messages");
741 g_object_unref(task);
742 }
743
744 if (response_handle != nullptr) {
745 self->embedder_api.PlatformMessageReleaseResponseHandle(self->engine,
746 response_handle);
747 }
748 }

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

Referenced by send_on_channel(), and TEST().

## ◆ fl_engine_send_platform_message_finish()

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

fl_engine_send_platform_message_finish: @engine: an #FlEngine.

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

Completes request started with fl_engine_send_platform_message().

Returns: message response on success or NULL on error.

Definition at line 750 of file fl_engine.cc.

752 {
753 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
754 g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
755
756 return static_cast<GBytes*>(g_task_propagate_pointer(G_TASK(result), error));
757 }

References error, and result.

Referenced by send_on_channel_finish().

## ◆ fl_engine_send_platform_message_response()

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

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

Responds to a platform message.

Returns: TRUE on success.

Definition at line 659 of file fl_engine.cc.

663 {
664 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
665 g_return_val_if_fail(handle != nullptr, FALSE);
666
667 if (self->engine == nullptr) {
668 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
669 "No engine to send response to");
670 return FALSE;
671 }
672
673 gsize data_length = 0;
674 const uint8_t* data = nullptr;
675 if (response != nullptr) {
676 data =
677 static_cast<const uint8_t*>(g_bytes_get_data(response, &data_length));
678 }
679 FlutterEngineResult result = self->embedder_api.SendPlatformMessageResponse(
680 self->engine, handle, data, data_length);
681
682 if (result != kSuccess) {
683 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
684 "Failed to send platform message response");
685 return FALSE;
686 }
687
688 return TRUE;
689 }

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

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

## ◆ fl_engine_send_pointer_pan_zoom_event()

void fl_engine_send_pointer_pan_zoom_event | ( | FlEngine * | self,
|  | size_t | timestamp,
|  | double | x,
|  | double | y,
|  | FlutterPointerPhase | phase,
|  | double | pan_x,
|  | double | pan_y,
|  | double | scale,
|  | double | rotation
| ) |  |

Definition at line 829 of file fl_engine.cc.

837 {
838 g_return_if_fail(FL_IS_ENGINE(self));
839
840 if (self->engine == nullptr) {
841 return;
842 }
843
844 FlutterPointerEvent fl_event = {};
845 fl_event.struct_size = sizeof(fl_event);
846 fl_event.timestamp = timestamp;
847 fl_event.x = x;
848 fl_event.y = y;
849 fl_event.phase = phase;
850 fl_event.pan_x = pan_x;
851 fl_event.pan_y = pan_y;
852 fl_event.scale = scale;
853 fl_event.rotation = rotation;
854 fl_event.device = kPointerPanZoomDeviceId;
855 fl_event.device_kind = kFlutterPointerDeviceKindTrackpad;
856 // TODO(dkwingsmt): Assign the correct view ID once the Linux embedder
857 // supports multiple views.
858 // https://github.com/flutter/flutter/issues/138178
859 fl_event.view_id = flutter::kFlutterImplicitViewId;
860 self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);
861 }

References kPointerPanZoomDeviceId.

Referenced by fl_view_scrolling_delegate_iface_init(), and TEST().

## ◆ fl_engine_send_window_metrics_event()

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

fl_engine_send_window_metrics_event: @engine: an #FlEngine. @width: width of the window in pixels. @height: height of the window in pixels. @pixel_ratio: scale factor for window.

Sends a window metrics event to the engine.

Definition at line 771 of file fl_engine.cc.

774 {
775 g_return_if_fail(FL_IS_ENGINE(self));
776
777 if (self->engine == nullptr) {
778 return;
779 }
780
781 FlutterWindowMetricsEvent event = {};
782 event.struct_size = sizeof(FlutterWindowMetricsEvent);
783 event.width = width;
784 event.height = height;
785 event.pixel_ratio = pixel_ratio;
786 // TODO(dkwingsmt): Assign the correct view ID once the Linux embedder
787 // supports multiple views.
788 // https://github.com/flutter/flutter/issues/138178
789 event.view_id = flutter::kFlutterImplicitViewId;
790 self->embedder_api.SendWindowMetricsEvent(self->engine, &event);
791 }

References event, height, and width.

Referenced by handle_geometry_changed(), and TEST().

## ◆ fl_engine_send_window_state_event()

void fl_engine_send_window_state_event | ( | FlEngine * | engine,
|  | gboolean | visible,
|  | gboolean | focused
| ) |  |

fl_engine_send_window_state_event: @engine: an #FlEngine. @visible: whether the window is currently visible or not. @focused: whether the window is currently focused or not.

Sends a window state event to the engine.

Definition at line 759 of file fl_engine.cc.

761 {
762 if (visible && focused) {
763 set_app_lifecycle_state(self, flutter::AppLifecycleState::kResumed);
764 } else if (visible) {
765 set_app_lifecycle_state(self, flutter::AppLifecycleState::kInactive);
766 } else {
767 set_app_lifecycle_state(self, flutter::AppLifecycleState::kHidden);
768 }
769 }

References flutter::kHidden, flutter::kInactive, flutter::kResumed, and set_app_lifecycle_state().

Referenced by TEST(), and window_state_event_cb().

## ◆ fl_engine_set_on_pre_engine_restart_handler()

void fl_engine_set_on_pre_engine_restart_handler | ( | FlEngine * | engine,
|  | FlEngineOnPreEngineRestartHandler | handler,
|  | gpointer | user_data,
|  | GDestroyNotify | destroy_notify
| ) |  |

fl_engine_set_on_pre_engine_restart_handler: @engine: an #FlEngine. @handler: function to call when the engine is restarted. @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 right before the engine is restarted.

Definition at line 641 of file fl_engine.cc.

645 {
646 g_return_if_fail(FL_IS_ENGINE(self));
647
648 if (self->on_pre_engine_restart_handler_destroy_notify) {
649 self->on_pre_engine_restart_handler_destroy_notify(
650 self->on_pre_engine_restart_handler_data);
651 }
652
653 self->on_pre_engine_restart_handler = handler;
654 self->on_pre_engine_restart_handler_data = user_data;
655 self->on_pre_engine_restart_handler_destroy_notify = destroy_notify;
656 }

References user_data.

Referenced by fl_view_constructed(), fl_view_dispose(), and TEST().

## ◆ fl_engine_set_platform_message_handler()

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

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

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

Definition at line 606 of file fl_engine.cc.

610 {
611 g_return_if_fail(FL_IS_ENGINE(self));
612 g_return_if_fail(handler != nullptr);
613
614 if (self->platform_message_handler_destroy_notify) {
615 self->platform_message_handler_destroy_notify(
616 self->platform_message_handler_data);
617 }
618
619 self->platform_message_handler = handler;
620 self->platform_message_handler_data = user_data;
621 self->platform_message_handler_destroy_notify = destroy_notify;
622 }

References user_data.

Referenced by fl_binary_messenger_new().

## ◆ fl_engine_set_update_semantics_handler()

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

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

Registers the function called when a semantics update is received.

Definition at line 624 of file fl_engine.cc.

628 {
629 g_return_if_fail(FL_IS_ENGINE(self));
630
631 if (self->update_semantics_handler_destroy_notify) {
632 self->update_semantics_handler_destroy_notify(
633 self->update_semantics_handler_data);
634 }
635
636 self->update_semantics_handler = handler;
637 self->update_semantics_handler_data = user_data;
638 self->update_semantics_handler_destroy_notify = destroy_notify;
639 }

References user_data.

Referenced by fl_view_constructed(), and fl_view_dispose().

## ◆ fl_engine_start()

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

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

Starts the Flutter engine.

Returns: TRUE on success.

Definition at line 474 of file fl_engine.cc.

474 {
475 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
476
477 self->task_runner = fl_task_runner_new(self);
478
479 FlutterRendererConfig config = {};
480 config.type = kOpenGL;
481 config.open_gl.struct_size = sizeof(FlutterOpenGLRendererConfig);
482 config.open_gl.gl_proc_resolver = fl_engine_gl_proc_resolver;
483 config.open_gl.make_current = fl_engine_gl_make_current;
484 config.open_gl.clear_current = fl_engine_gl_clear_current;
485 config.open_gl.fbo_callback = fl_engine_gl_get_fbo;
486 config.open_gl.present = fl_engine_gl_present;
487 config.open_gl.make_resource_current = fl_engine_gl_make_resource_current;
488 config.open_gl.gl_external_texture_frame_callback =
489 fl_engine_gl_external_texture_frame_callback;
490
491 FlutterTaskRunnerDescription platform_task_runner = {};
492 platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription);
493 platform_task_runner.user_data = self;
494 platform_task_runner.runs_task_on_current_thread_callback =
495 fl_engine_runs_task_on_current_thread;
496 platform_task_runner.post_task_callback = fl_engine_post_task;
497 platform_task_runner.identifier = kPlatformTaskRunnerIdentifier;
498
499 FlutterCustomTaskRunners custom_task_runners = {};
500 custom_task_runners.struct_size = sizeof(FlutterCustomTaskRunners);
501 custom_task_runners.platform_task_runner = &platform_task_runner;
502 custom_task_runners.render_task_runner = &platform_task_runner;
503
504 g_autoptr(GPtrArray) command_line_args = fl_engine_get_switches(self);
505 // FlutterProjectArgs expects a full argv, so when processing it for flags
506 // the first item is treated as the executable and ignored. Add a dummy value
507 // so that all switches are used.
508 g_ptr_array_insert(command_line_args, 0, g_strdup("flutter"));
509
510 gchar** dart_entrypoint_args =
511 fl_dart_project_get_dart_entrypoint_arguments(self->project);
512
513 FlutterProjectArgs args = {};
514 args.struct_size = sizeof(FlutterProjectArgs);
515 args.assets_path = fl_dart_project_get_assets_path(self->project);
516 args.icu_data_path = fl_dart_project_get_icu_data_path(self->project);
517 args.command_line_argc = command_line_args->len;
518 args.command_line_argv =
519 reinterpret_cast<const char* const*>(command_line_args->pdata);
520 args.platform_message_callback = fl_engine_platform_message_cb;
521 args.update_semantics_callback2 = fl_engine_update_semantics_cb;
522 args.custom_task_runners = &custom_task_runners;
523 args.shutdown_dart_vm_when_done = true;
524 args.on_pre_engine_restart_callback = fl_engine_on_pre_engine_restart_cb;
525 args.dart_entrypoint_argc =
526 dart_entrypoint_args != nullptr ? g_strv_length(dart_entrypoint_args) : 0;
527 args.dart_entrypoint_argv =
528 reinterpret_cast<const char* const*>(dart_entrypoint_args);
529
530 FlutterCompositor compositor = {};
531 compositor.struct_size = sizeof(FlutterCompositor);
532 compositor.user_data = self->renderer;
533 compositor.create_backing_store_callback =
534 compositor_create_backing_store_callback;
535 compositor.collect_backing_store_callback =
536 compositor_collect_backing_store_callback;
537 compositor.present_layers_callback = compositor_present_layers_callback;
538 args.compositor = &compositor;
539
540 if (self->embedder_api.RunsAOTCompiledDartCode()) {
541 FlutterEngineAOTDataSource source = {};
542 source.type = kFlutterEngineAOTDataSourceTypeElfPath;
543 source.elf_path = fl_dart_project_get_aot_library_path(self->project);
544 if (self->embedder_api.CreateAOTData(&source, &self->aot_data) !=
545 kSuccess) {
546 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
547 "Failed to create AOT data");
548 return FALSE;
549 }
550 args.aot_data = self->aot_data;
551 }
552
553 FlutterEngineResult result = self->embedder_api.Initialize(
554 FLUTTER_ENGINE_VERSION, &config, &args, self, &self->engine);
555 if (result != kSuccess) {
556 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
557 "Failed to initialize Flutter engine");
558 return FALSE;
559 }
560
561 result = self->embedder_api.RunInitialized(self->engine);
562 if (result != kSuccess) {
563 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
564 "Failed to run Flutter engine");
565 return FALSE;
566 }
567
568 setup_locales(self);
569
570 g_autoptr(FlSettings) settings = fl_settings_new();
571 self->settings_plugin = fl_settings_plugin_new(self);
572 fl_settings_plugin_start(self->settings_plugin, settings);
573
574 result = self->embedder_api.UpdateSemanticsEnabled(self->engine, TRUE);
575 if (result != kSuccess) {
576 g_warning("Failed to enable accessibility features on Flutter engine");
577 }
578
579 gdouble refresh_rate = fl_renderer_get_refresh_rate(self->renderer);
580 // FlutterEngineDisplay::refresh_rate expects 0 if the refresh rate is
581 // unknown.
582 if (refresh_rate <= 0.0) {
583 refresh_rate = 0.0;
584 }
585 FlutterEngineDisplay display = {};
586 display.struct_size = sizeof(FlutterEngineDisplay);
587 display.display_id = 0;
588 display.single_display = true;
589 display.refresh_rate = refresh_rate;
590
591 std::vector displays = {display};
592 result = self->embedder_api.NotifyDisplayUpdate(
593 self->engine, kFlutterEngineDisplaysUpdateTypeStartup, displays.data(),
594 displays.size());
595 if (result != kSuccess) {
596 g_warning("Failed to notify display update to Flutter engine: %d", result);
597 }
598
599 return TRUE;
600 }

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

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

## ◆ fl_engine_unregister_external_texture()

gboolean fl_engine_unregister_external_texture | ( | FlEngine * | engine,
|  | int64_t | texture_id
| ) |  |

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

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

Returns: TRUE on success.

Definition at line 911 of file fl_engine.cc.

912 {
913 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
914 return self->embedder_api.UnregisterExternalTexture(self->engine,
915 texture_id) == kSuccess;
916 }

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

940 {
941 g_return_if_fail(FL_IS_ENGINE(self));
942
943 if (self->engine == nullptr) {
944 return;
945 }
946
947 self->embedder_api.UpdateAccessibilityFeatures(
948 self->engine, static_cast<FlutterAccessibilityFeature>(flags));
949 }

References flags.

Referenced by update_settings().

fl_dart_project_get_aot_library_path
const G_MODULE_EXPORT gchar * fl_dart_project_get_aot_library_path(FlDartProject *self)
Definition: fl_dart_project.cc:72
event
FlKeyEvent * event
Definition: fl_key_channel_responder.cc:118
flutter::AppLifecycleState::kHidden
@ kHidden
fl_engine_platform_message_response_cb
static void fl_engine_platform_message_response_cb(const uint8_t *data, size_t data_length, void *user_data)
Definition: fl_engine.cc:350
fl_engine_gl_get_fbo
static uint32_t fl_engine_gl_get_fbo(void *user_data)
Definition: fl_engine.cc:230
fl_engine_gl_make_resource_current
static bool fl_engine_gl_make_resource_current(void *user_data)
Definition: fl_engine.cc:241
FL_ENGINE_ERROR_FAILED
@ FL_ENGINE_ERROR_FAILED
Definition: fl_engine_private.h:25
kMousePointerDeviceId
static constexpr int32_t kMousePointerDeviceId
Definition: fl_engine.cc:35
set_app_lifecycle_state
static void set_app_lifecycle_state(FlEngine *self, const flutter::AppLifecycleState state)
Definition: fl_engine.cc:130
fl_renderer_get_refresh_rate
gdouble fl_renderer_get_refresh_rate(FlRenderer *self)
Definition: fl_renderer.cc:156
compositor_collect_backing_store_callback
static bool compositor_collect_backing_store_callback(const FlutterBackingStore *renderer, void *user_data)
Definition: fl_engine.cc:195
fl_settings_new
FlSettings * fl_settings_new()
Definition: fl_settings.cc:55
fl_engine_gl_present
static bool fl_engine_gl_present(void *user_data)
Definition: fl_engine.cc:235
flags
FlutterSemanticsFlag flags
Definition: fl_accessible_node.cc:106
user_data
FlKeyEvent uint64_t FlKeyResponderAsyncCallback gpointer user_data
Definition: fl_key_channel_responder.cc:121
fl_engine_on_pre_engine_restart_cb
static void fl_engine_on_pre_engine_restart_cb(void *user_data)
Definition: fl_engine.cc:339
fl_dart_project_get_assets_path
const G_MODULE_EXPORT gchar * fl_dart_project_get_assets_path(FlDartProject *self)
Definition: fl_dart_project.cc:85
height
G_BEGIN_DECLS int height
Definition: fl_backing_store_provider.h:37
fl_binary_messenger_new
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
Definition: fl_binary_messenger.cc:399
fl_settings_plugin_start
void fl_settings_plugin_start(FlSettingsPlugin *self, FlSettings *settings)
Definition: fl_settings_plugin.cc:112
kPlatformTaskRunnerIdentifier
static constexpr size_t kPlatformTaskRunnerIdentifier
Definition: fl_engine.cc:31
flutter::AppLifecycleState::kInactive
@ kInactive
fl_engine_update_semantics_cb
static void fl_engine_update_semantics_cb(const FlutterSemanticsUpdate2 *update, void *user_data)
Definition: fl_engine.cc:324
compositor_present_layers_callback
static bool compositor_present_layers_callback(const FlutterLayer **layers, size_t layers_count, void *user_data)
Definition: fl_engine.cc:203
fl_engine_gl_external_texture_frame_callback
static bool fl_engine_gl_external_texture_frame_callback(void *user_data, int64_t texture_id, size_t width, size_t height, FlutterOpenGLTexture *opengl_texture)
Definition: fl_engine.cc:248
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
flutter::GetSwitchesFromEnvironment
std::vector< std::string > GetSwitchesFromEnvironment()
Definition: engine_switches.cc:14
fl_dart_project_get_dart_entrypoint_arguments
G_MODULE_EXPORT gchar ** fl_dart_project_get_dart_entrypoint_arguments(FlDartProject *self)
Definition: fl_dart_project.cc:104
fl_engine_runs_task_on_current_thread
static bool fl_engine_runs_task_on_current_thread(void *user_data)
Definition: fl_engine.cc:289
result
GAsyncResult * result
Definition: fl_text_input_plugin.cc:106
FlEngineError
FlEngineError
Definition: fl_engine_private.h:23
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
flutter::AppLifecycleState::kResumed
@ kResumed
fl_engine_gl_proc_resolver
static void * fl_engine_gl_proc_resolver(void *user_data, const char *name)
Definition: fl_engine.cc:213
setup_locales
static void setup_locales(FlEngine *self)
Definition: fl_engine.cc:150
compositor_create_backing_store_callback
static bool compositor_create_backing_store_callback(const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out, void *user_data)
Definition: fl_engine.cc:185
callback
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Definition: fl_key_channel_responder.cc:120
fl_engine_error_quark
GQuark fl_engine_error_quark(void) G_GNUC_CONST
fl_dart_project_get_icu_data_path
const G_MODULE_EXPORT gchar * fl_dart_project_get_icu_data_path(FlDartProject *self)
Definition: fl_dart_project.cc:98
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24
width
const uint8_t uint32_t * width
Definition: fl_pixel_buffer_texture_test.cc:38
fl_engine_gl_make_current
static bool fl_engine_gl_make_current(void *user_data)
Definition: fl_engine.cc:218
fl_engine_get_switches
GPtrArray * fl_engine_get_switches(FlEngine *self)
Definition: fl_engine.cc:951
fl_engine_post_task
static void fl_engine_post_task(FlutterTask task, uint64_t target_time_nanos, void *user_data)
Definition: fl_engine.cc:295
fl_task_runner_new
FlTaskRunner * fl_task_runner_new(FlEngine *engine)
Definition: fl_task_runner.cc:154
fl_settings_plugin_new
FlSettingsPlugin * fl_settings_plugin_new(FlEngine *engine)
Definition: fl_settings_plugin.cc:94
fl_engine_platform_message_cb
static void fl_engine_platform_message_cb(const FlutterPlatformMessage *message, void *user_data)
Definition: fl_engine.cc:304
kPointerPanZoomDeviceId
static constexpr int32_t kPointerPanZoomDeviceId
Definition: fl_engine.cc:36
fl_engine_gl_clear_current
static bool fl_engine_gl_clear_current(void *user_data)
Definition: fl_engine.cc:224