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

## Enumerations
enum | FlEngineError { FL_ENGINE_ERROR_FAILED }

## Functions
GQuark | fl_engine_error_quark (void) G_GNUC_CONST
FlEngine * | fl_engine_new_with_renderer (FlDartProject *project, FlRenderer *renderer)
FlRenderer * | fl_engine_get_renderer (FlEngine *engine)
gboolean | fl_engine_start (FlEngine *engine, GError **error)
FlutterEngineProcTable * | fl_engine_get_embedder_api (FlEngine *engine)
FlutterViewId | fl_engine_add_view (FlEngine *engine, size_t width, size_t height, double pixel_ratio, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
gboolean | fl_engine_add_view_finish (FlEngine *engine, GAsyncResult *result, GError **error)
void | fl_engine_remove_view (FlEngine *engine, FlutterViewId view_id, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
gboolean | fl_engine_remove_view_finish (FlEngine *engine, GAsyncResult *result, GError **error)
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_send_window_metrics_event (FlEngine *engine, FlutterViewId view_id, size_t width, size_t height, double pixel_ratio)
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)
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)
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

## ◆ 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_add_view()

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

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

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

Returns: the ID for the view.

Definition at line 641 of file fl_engine.cc.

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

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

Referenced by fl_view_new_for_engine(), and TEST().

## ◆ fl_engine_add_view_finish()

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

fl_engine_add_view_finish: @engine: an #FlEngine.

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

Completes request started with fl_engine_add_view().

Returns: TRUE on success.

Definition at line 679 of file fl_engine.cc.

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

References error, and result.

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

## ◆ fl_engine_dispatch_semantics_action()

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

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

Definition at line 953 of file fl_engine.cc.

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

Referenced by fl_accessible_node_perform_action_impl(), and TEST().

## ◆ fl_engine_error_quark()

GQuark fl_engine_error_quark | ( | void |  | ) |

Referenced by fl_engine_add_view(), fl_engine_remove_view(), fl_engine_send_platform_message(), fl_engine_send_platform_message_response(), fl_engine_start(), view_added_cb(), and view_removed_cb().

## ◆ fl_engine_execute_task()

void fl_engine_execute_task | ( | FlEngine * | engine,
|  | FlutterTask * | task
| ) |  |

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

Executes given Flutter task.

Definition at line 1006 of file fl_engine.cc.

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

Referenced by fl_task_runner_process_expired_tasks_locked().

## ◆ fl_engine_get_embedder_api()

FlutterEngineProcTable* fl_engine_get_embedder_api | ( | FlEngine * | engine | ) |

fl_engine_get_embedder_api: @engine: an #FlEngine.

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

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

Definition at line 637 of file fl_engine.cc.

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

Referenced by TEST().

## ◆ fl_engine_get_renderer()

FlRenderer* fl_engine_get_renderer | ( | FlEngine * | engine | ) |

fl_engine_get_renderer: @engine: an #FlEngine.

Gets the renderer used by this engine.

Returns: an #FlRenderer.

Definition at line 504 of file fl_engine.cc.

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

Referenced by fl_view_new(), and fl_view_new_for_engine().

## ◆ fl_engine_get_switches()

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

fl_engine_get_switches: @project: an #FlEngine.

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

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

Definition at line 1028 of file fl_engine.cc.

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

References flutter::GetSwitchesFromEnvironment().

Referenced by fl_engine_start(), and TEST().

## ◆ fl_engine_get_task_runner()

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

fl_engine_get_task_runner: @engine: an #FlEngine.

Returns
  : a #FlTaskRunner.

Returns: task runner responsible for scheduling Flutter tasks.

Definition at line 1001 of file fl_engine.cc.

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

Referenced by fl_renderer_unblock_main_thread(), and fl_renderer_wait_for_frame().

## ◆ fl_engine_mark_texture_frame_available()

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

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

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

Returns: TRUE on success.

Definition at line 974 of file fl_engine.cc.

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

References texture_id.

Referenced by mark_texture_frame_available().

## ◆ fl_engine_new_with_renderer()

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

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

Creates new Flutter engine.

Returns: a new #FlEngine.

Definition at line 479 of file fl_engine.cc.

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

References fl_binary_messenger_new(), and fl_renderer_set_engine().

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

## ◆ fl_engine_register_external_texture()

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

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

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

Returns: TRUE on success.

Definition at line 981 of file fl_engine.cc.

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

References texture_id.

Referenced by register_texture().

## ◆ fl_engine_remove_view()

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

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

Removes a view previously added with fl_engine_add_view().

Definition at line 686 of file fl_engine.cc.

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

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

Referenced by fl_view_dispose(), and TEST().

## ◆ fl_engine_remove_view_finish()

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

fl_engine_remove_view_finish: @engine: an #FlEngine.

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

Completes request started with fl_engine_remove_view().

Returns: TRUE on succcess.

Definition at line 711 of file fl_engine.cc.

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

References error, and result.

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

## ◆ fl_engine_send_key_event()

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

fl_engine_send_key_event:

Definition at line 940 of file fl_engine.cc.

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

References callback, event, and user_data.

Referenced by fl_view_keyboard_delegate_iface_init().

## ◆ fl_engine_send_mouse_pointer_event()

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

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

Sends a mouse pointer event to the engine.

Definition at line 874 of file fl_engine.cc.

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

References kMousePointerDeviceId.

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

## ◆ fl_engine_send_platform_message()

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

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

Asynchronously sends a platform message.

Definition at line 786 of file fl_engine.cc.

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

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

Referenced by send_on_channel(), and TEST().

## ◆ fl_engine_send_platform_message_finish()

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

fl_engine_send_platform_message_finish: @engine: an #FlEngine.

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

Completes request started with fl_engine_send_platform_message().

Returns: message response on success or NULL on error.

Definition at line 845 of file fl_engine.cc.

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

References error, and result.

Referenced by send_on_channel_finish().

## ◆ fl_engine_send_platform_message_response()

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

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

Responds to a platform message.

Returns: TRUE on success.

Definition at line 754 of file fl_engine.cc.

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

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

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

## ◆ fl_engine_send_pointer_pan_zoom_event()

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

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

Sends a pan/zoom pointer event to the engine.

Definition at line 908 of file fl_engine.cc.

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

References kPointerPanZoomDeviceId.

Referenced by fl_view_scrolling_delegate_iface_init(), and TEST().

## ◆ fl_engine_send_window_metrics_event()

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

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

Sends a window metrics event to the engine.

Definition at line 854 of file fl_engine.cc.

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

References event, height, and width.

Referenced by handle_geometry_changed(), and TEST().

## ◆ fl_engine_set_platform_message_handler()

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

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

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

Definition at line 718 of file fl_engine.cc.

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

References user_data.

Referenced by fl_binary_messenger_new().

## ◆ fl_engine_set_update_semantics_handler()

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

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

Registers the function called when a semantics update is received.

Definition at line 736 of file fl_engine.cc.

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

References user_data.

Referenced by fl_view_dispose(), and fl_view_new().

## ◆ fl_engine_start()

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

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

Starts the Flutter engine.

Returns: TRUE on success.

Definition at line 509 of file fl_engine.cc.

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

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

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

## ◆ fl_engine_unregister_external_texture()

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

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

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

Returns: TRUE on success.

Definition at line 988 of file fl_engine.cc.

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

References texture_id.

Referenced by unregister_texture().

## ◆ fl_engine_update_accessibility_features()

void fl_engine_update_accessibility_features | ( | FlEngine * | engine,
|  | int32_t | flags
| ) |  |

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

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

Definition at line 1017 of file fl_engine.cc.

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

References flags.

Referenced by update_settings().

fl_dart_project_get_aot_library_path
const G_MODULE_EXPORT gchar * fl_dart_project_get_aot_library_path(FlDartProject *self)
Definition: fl_dart_project.cc:72
fl_settings_handler_new
FlSettingsHandler * fl_settings_handler_new(FlEngine *engine)
Definition: fl_settings_handler.cc:94
event
FlKeyEvent * event
Definition: fl_key_channel_responder.cc:118
fl_engine_platform_message_response_cb
static void fl_engine_platform_message_response_cb(const uint8_t *data, size_t data_length, void *user_data)
Definition: fl_engine.cc:371
fl_engine_gl_get_fbo
static uint32_t fl_engine_gl_get_fbo(void *user_data)
Definition: fl_engine.cc:254
fl_engine_gl_make_resource_current
static bool fl_engine_gl_make_resource_current(void *user_data)
Definition: fl_engine.cc:265
FL_ENGINE_ERROR_FAILED
@ FL_ENGINE_ERROR_FAILED
Definition: fl_engine_private.h:25
kMousePointerDeviceId
static constexpr int32_t kMousePointerDeviceId
Definition: fl_engine.cc:34
fl_renderer_get_refresh_rate
gdouble fl_renderer_get_refresh_rate(FlRenderer *self)
Definition: fl_renderer.cc:355
compositor_present_view_callback
static bool compositor_present_view_callback(const FlutterPresentViewInfo *info)
Definition: fl_engine.cc:228
fl_settings_new
FlSettings * fl_settings_new()
Definition: fl_settings.cc:55
fl_engine_gl_present
static bool fl_engine_gl_present(void *user_data)
Definition: fl_engine.cc:259
flags
FlutterSemanticsFlag flags
Definition: fl_accessible_node.cc:106
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:363
fl_dart_project_get_assets_path
const G_MODULE_EXPORT gchar * fl_dart_project_get_assets_path(FlDartProject *self)
Definition: fl_dart_project.cc:85
fl_binary_messenger_new
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
Definition: fl_binary_messenger.cc:399
kPlatformTaskRunnerIdentifier
static constexpr size_t kPlatformTaskRunnerIdentifier
Definition: fl_engine.cc:30
fl_renderer_set_engine
void fl_renderer_set_engine(FlRenderer *self, FlEngine *engine)
Definition: fl_renderer.cc:305
view_removed_cb
static void view_removed_cb(const FlutterRemoveViewResult *result)
Definition: fl_engine.cc:140
fl_engine_update_semantics_cb
static void fl_engine_update_semantics_cb(const FlutterSemanticsUpdate2 *update, void *user_data)
Definition: fl_engine.cc:348
fl_engine_gl_external_texture_frame_callback
static bool fl_engine_gl_external_texture_frame_callback(void *user_data, int64_t texture_id, size_t width, size_t height, FlutterOpenGLTexture *opengl_texture)
Definition: fl_engine.cc:272
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
flutter::GetSwitchesFromEnvironment
std::vector< std::string > GetSwitchesFromEnvironment()
Definition: engine_switches.cc:14
fl_dart_project_get_dart_entrypoint_arguments
G_MODULE_EXPORT gchar ** fl_dart_project_get_dart_entrypoint_arguments(FlDartProject *self)
Definition: fl_dart_project.cc:104
fl_settings_handler_start
void fl_settings_handler_start(FlSettingsHandler *self, FlSettings *settings)
Definition: fl_settings_handler.cc:112
fl_engine_runs_task_on_current_thread
static bool fl_engine_runs_task_on_current_thread(void *user_data)
Definition: fl_engine.cc:313
height
const uint8_t uint32_t uint32_t * height
Definition: fl_pixel_buffer_texture_test.cc:39
result
GAsyncResult * result
Definition: fl_text_input_handler.cc:106
view_added_cb
static void view_added_cb(const FlutterAddViewResult *result)
Definition: fl_engine.cc:129
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
compositor_collect_backing_store_callback
static bool compositor_collect_backing_store_callback(const FlutterBackingStore *backing_store, void *user_data)
Definition: fl_engine.cc:219
fl_engine_gl_proc_resolver
static void * fl_engine_gl_proc_resolver(void *user_data, const char *name)
Definition: fl_engine.cc:237
setup_locales
static void setup_locales(FlEngine *self)
Definition: fl_engine.cc:158
compositor_create_backing_store_callback
static bool compositor_create_backing_store_callback(const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out, void *user_data)
Definition: fl_engine.cc:209
callback
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Definition: fl_key_channel_responder.cc:120
fl_engine_error_quark
GQuark fl_engine_error_quark(void) G_GNUC_CONST
fl_dart_project_get_icu_data_path
const G_MODULE_EXPORT gchar * fl_dart_project_get_icu_data_path(FlDartProject *self)
Definition: fl_dart_project.cc:98
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24
width
const uint8_t uint32_t * width
Definition: fl_pixel_buffer_texture_test.cc:38
fl_engine_gl_make_current
static bool fl_engine_gl_make_current(void *user_data)
Definition: fl_engine.cc:242
fl_engine_get_switches
GPtrArray * fl_engine_get_switches(FlEngine *self)
Definition: fl_engine.cc:1028
fl_engine_post_task
static void fl_engine_post_task(FlutterTask task, uint64_t target_time_nanos, void *user_data)
Definition: fl_engine.cc:319
fl_task_runner_new
FlTaskRunner * fl_task_runner_new(FlEngine *engine)
Definition: fl_task_runner.cc:154
fl_engine_platform_message_cb
static void fl_engine_platform_message_cb(const FlutterPlatformMessage *message, void *user_data)
Definition: fl_engine.cc:328
kPointerPanZoomDeviceId
static constexpr int32_t kPointerPanZoomDeviceId
Definition: fl_engine.cc:35
fl_engine_gl_clear_current
static bool fl_engine_gl_clear_current(void *user_data)
Definition: fl_engine.cc:248