Flutter Engine
The Flutter Engine
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)
 
FlutterEngineProcTablefl_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

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)
26 // NOLINTEND(readability-identifier-naming)
FlEngineError
@ FL_ENGINE_ERROR_FAILED

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

876 {
877 g_return_if_fail(FL_IS_ENGINE(self));
878
879 if (self->engine == nullptr) {
880 return;
881 }
882
883 const uint8_t* action_data = nullptr;
884 size_t action_data_length = 0;
885 if (data != nullptr) {
886 action_data = static_cast<const uint8_t*>(
887 g_bytes_get_data(data, &action_data_length));
888 }
889
890 self->embedder_api.DispatchSemanticsAction(self->engine, id, action,
891 action_data, action_data_length);
892}
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ fl_engine_error_quark()

GQuark fl_engine_error_quark ( void  )

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

926 {
927 g_return_if_fail(FL_IS_ENGINE(self));
928 self->embedder_api.RunTask(self->engine, task);
929}

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

599 {
600 return &(self->embedder_api);
601}

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

948 {
949 GPtrArray* switches = g_ptr_array_new_with_free_func(g_free);
950 for (const auto& env_switch : flutter::GetSwitchesFromEnvironment()) {
951 g_ptr_array_add(switches, g_strdup(env_switch.c_str()));
952 }
953 return switches;
954}
std::vector< std::string > GetSwitchesFromEnvironment()

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

921 {
922 g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
923 return self->task_runner;
924}

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

895 {
896 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
897 return self->embedder_api.MarkExternalTextureFrameAvailable(
898 self->engine, texture_id) == kSuccess;
899}
@ kSuccess
Definition: embedder.h:73
return FALSE
int64_t texture_id

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

455 {
456 g_return_val_if_fail(FL_IS_DART_PROJECT(project), nullptr);
457 g_return_val_if_fail(FL_IS_RENDERER(renderer), nullptr);
458
459 FlEngine* self = FL_ENGINE(g_object_new(fl_engine_get_type(), nullptr));
460 self->project = FL_DART_PROJECT(g_object_ref(project));
461 self->renderer = FL_RENDERER(g_object_ref(renderer));
462 self->binary_messenger = fl_binary_messenger_new(self);
463 return self;
464}
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *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 901 of file fl_engine.cc.

902 {
903 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
904 return self->embedder_api.RegisterExternalTexture(self->engine, texture_id) ==
905 kSuccess;
906}

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

863 {
864 g_return_if_fail(FL_IS_ENGINE(self));
865
866 if (self->engine == nullptr) {
867 return;
868 }
869
870 self->embedder_api.SendKeyEvent(self->engine, event, callback, user_data);
871}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
FlKeyEvent * event
void * user_data

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

798 {
799 g_return_if_fail(FL_IS_ENGINE(self));
800
801 if (self->engine == nullptr) {
802 return;
803 }
804
805 FlutterPointerEvent fl_event = {};
806 fl_event.struct_size = sizeof(fl_event);
807 fl_event.phase = phase;
808 fl_event.timestamp = timestamp;
809 fl_event.x = x;
810 fl_event.y = y;
811 if (scroll_delta_x != 0 || scroll_delta_y != 0) {
813 }
814 fl_event.scroll_delta_x = scroll_delta_x;
815 fl_event.scroll_delta_y = scroll_delta_y;
816 fl_event.device_kind = device_kind;
817 fl_event.buttons = buttons;
818 fl_event.device = kMousePointerDeviceId;
819 // TODO(dkwingsmt): Assign the correct view ID once the Linux embedder
820 // supports multiple views.
821 // https://github.com/flutter/flutter/issues/138178
823 self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);
824}
@ kFlutterPointerSignalKindScroll
Definition: embedder.h:1029
static constexpr int32_t kMousePointerDeviceId
Definition: fl_engine.cc:35
double y
double x
constexpr int64_t kFlutterImplicitViewId
Definition: constants.h:35
double scroll_delta_y
The y offset of the scroll in physical pixels.
Definition: embedder.h:1053
int64_t buttons
The buttons currently pressed, if any.
Definition: embedder.h:1061
size_t struct_size
The size of this struct. Must be sizeof(FlutterPointerEvent).
Definition: embedder.h:1036
FlutterViewId view_id
The identifier of the view that received the pointer event.
Definition: embedder.h:1071
FlutterPointerSignalKind signal_kind
Definition: embedder.h:1049
double scroll_delta_x
The x offset of the scroll in physical pixels.
Definition: embedder.h:1051
double y
The y coordinate of the pointer event in physical pixels.
Definition: embedder.h:1045
double x
The x coordinate of the pointer event in physical pixels.
Definition: embedder.h:1043
FlutterPointerDeviceKind device_kind
Definition: embedder.h:1059
FlutterPointerPhase phase
Definition: embedder.h:1037

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

693 {
694 g_return_if_fail(FL_IS_ENGINE(self));
695
696 GTask* task = nullptr;
697 FlutterPlatformMessageResponseHandle* response_handle = nullptr;
698 if (callback != nullptr) {
699 task = g_task_new(self, cancellable, callback, user_data);
700
701 if (self->engine == nullptr) {
702 g_task_return_new_error(task, fl_engine_error_quark(),
703 FL_ENGINE_ERROR_FAILED, "No engine to send to");
704 return;
705 }
706
708 self->embedder_api.PlatformMessageCreateResponseHandle(
710 &response_handle);
711 if (result != kSuccess) {
712 g_task_return_new_error(task, fl_engine_error_quark(),
714 "Failed to create response handle");
715 g_object_unref(task);
716 return;
717 }
718 } else if (self->engine == nullptr) {
719 return;
720 }
721
722 FlutterPlatformMessage fl_message = {};
723 fl_message.struct_size = sizeof(fl_message);
724 fl_message.channel = channel;
725 fl_message.message =
726 message != nullptr
727 ? static_cast<const uint8_t*>(g_bytes_get_data(message, nullptr))
728 : nullptr;
729 fl_message.message_size = message != nullptr ? g_bytes_get_size(message) : 0;
730 fl_message.response_handle = response_handle;
732 self->embedder_api.SendPlatformMessage(self->engine, &fl_message);
733
734 if (result != kSuccess && task != nullptr) {
735 g_task_return_new_error(task, fl_engine_error_quark(),
737 "Failed to send platform messages");
738 g_object_unref(task);
739 }
740
741 if (response_handle != nullptr) {
742 self->embedder_api.PlatformMessageReleaseResponseHandle(self->engine,
743 response_handle);
744 }
745}
FlutterEngineResult
Definition: embedder.h:72
static void fl_engine_platform_message_response_cb(const uint8_t *data, size_t data_length, void *user_data)
Definition: fl_engine.cc:350
GQuark fl_engine_error_quark(void) G_GNUC_CONST
GAsyncResult * result
Win32Message message
size_t struct_size
The size of this struct. Must be sizeof(FlutterPlatformMessage).
Definition: embedder.h:1164
const FlutterPlatformMessageResponseHandle * response_handle
Definition: embedder.h:1174
const char * channel
Definition: embedder.h:1165
const uint8_t * message
Definition: embedder.h:1166

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

749 {
750 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
751 g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
752
753 return static_cast<GBytes*>(g_task_propagate_pointer(G_TASK(result), error));
754}
const uint8_t uint32_t uint32_t GError ** error

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

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

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

834 {
835 g_return_if_fail(FL_IS_ENGINE(self));
836
837 if (self->engine == nullptr) {
838 return;
839 }
840
841 FlutterPointerEvent fl_event = {};
842 fl_event.struct_size = sizeof(fl_event);
843 fl_event.timestamp = timestamp;
844 fl_event.x = x;
845 fl_event.y = y;
846 fl_event.phase = phase;
847 fl_event.pan_x = pan_x;
848 fl_event.pan_y = pan_y;
849 fl_event.scale = scale;
850 fl_event.rotation = rotation;
853 // TODO(dkwingsmt): Assign the correct view ID once the Linux embedder
854 // supports multiple views.
855 // https://github.com/flutter/flutter/issues/138178
857 self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);
858}
@ kFlutterPointerDeviceKindTrackpad
Definition: embedder.h:1011
static constexpr int32_t kPointerPanZoomDeviceId
Definition: fl_engine.cc:36
const Scalar scale
double scale
The scale of the pan/zoom, where 1.0 is the initial scale.
Definition: embedder.h:1067
double rotation
The rotation of the pan/zoom in radians, where 0.0 is the initial angle.
Definition: embedder.h:1069
double pan_x
The x offset of the pan/zoom in physical pixels.
Definition: embedder.h:1063
double pan_y
The y offset of the pan/zoom in physical pixels.
Definition: embedder.h:1065

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

771 {
772 g_return_if_fail(FL_IS_ENGINE(self));
773
774 if (self->engine == nullptr) {
775 return;
776 }
777
778 FlutterWindowMetricsEvent event = {};
780 event.width = width;
781 event.height = height;
782 event.pixel_ratio = pixel_ratio;
783 // TODO(dkwingsmt): Assign the correct view ID once the Linux embedder
784 // supports multiple views.
785 // https://github.com/flutter/flutter/issues/138178
786 event.view_id = flutter::kFlutterImplicitViewId;
787 self->embedder_api.SendWindowMetricsEvent(self->engine, &event);
788}
int32_t height
int32_t width
size_t struct_size
The size of this struct. Must be sizeof(FlutterWindowMetricsEvent).
Definition: embedder.h:843

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

758 {
759 if (visible && focused) {
761 } else if (visible) {
763 } else {
765 }
766}
static void set_app_lifecycle_state(FlEngine *self, const flutter::AppLifecycleState state)
Definition: fl_engine.cc:130

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

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

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

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

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

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

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

471 {
472 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
473
474 self->task_runner = fl_task_runner_new(self);
475
476 FlutterRendererConfig config = {};
477 config.type = kOpenGL;
487
488 FlutterTaskRunnerDescription platform_task_runner = {};
489 platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription);
490 platform_task_runner.user_data = self;
491 platform_task_runner.runs_task_on_current_thread_callback =
493 platform_task_runner.post_task_callback = fl_engine_post_task;
494 platform_task_runner.identifier = kPlatformTaskRunnerIdentifier;
495
496 FlutterCustomTaskRunners custom_task_runners = {};
497 custom_task_runners.struct_size = sizeof(FlutterCustomTaskRunners);
498 custom_task_runners.platform_task_runner = &platform_task_runner;
499 custom_task_runners.render_task_runner = &platform_task_runner;
500
501 g_autoptr(GPtrArray) command_line_args = fl_engine_get_switches(self);
502 // FlutterProjectArgs expects a full argv, so when processing it for flags
503 // the first item is treated as the executable and ignored. Add a dummy value
504 // so that all switches are used.
505 g_ptr_array_insert(command_line_args, 0, g_strdup("flutter"));
506
507 gchar** dart_entrypoint_args =
509
511 args.struct_size = sizeof(FlutterProjectArgs);
512 args.assets_path = fl_dart_project_get_assets_path(self->project);
513 args.icu_data_path = fl_dart_project_get_icu_data_path(self->project);
514 args.command_line_argc = command_line_args->len;
515 args.command_line_argv =
516 reinterpret_cast<const char* const*>(command_line_args->pdata);
517 args.platform_message_callback = fl_engine_platform_message_cb;
518 args.update_semantics_callback2 = fl_engine_update_semantics_cb;
519 args.custom_task_runners = &custom_task_runners;
520 args.shutdown_dart_vm_when_done = true;
521 args.on_pre_engine_restart_callback = fl_engine_on_pre_engine_restart_cb;
522 args.dart_entrypoint_argc =
523 dart_entrypoint_args != nullptr ? g_strv_length(dart_entrypoint_args) : 0;
524 args.dart_entrypoint_argv =
525 reinterpret_cast<const char* const*>(dart_entrypoint_args);
526
527 FlutterCompositor compositor = {};
528 compositor.struct_size = sizeof(FlutterCompositor);
529 compositor.user_data = self->renderer;
535 args.compositor = &compositor;
536
537 if (self->embedder_api.RunsAOTCompiledDartCode()) {
541 if (self->embedder_api.CreateAOTData(&source, &self->aot_data) !=
542 kSuccess) {
544 "Failed to create AOT data");
545 return FALSE;
546 }
547 args.aot_data = self->aot_data;
548 }
549
550 FlutterEngineResult result = self->embedder_api.Initialize(
551 FLUTTER_ENGINE_VERSION, &config, &args, self, &self->engine);
552 if (result != kSuccess) {
554 "Failed to initialize Flutter engine");
555 return FALSE;
556 }
557
558 result = self->embedder_api.RunInitialized(self->engine);
559 if (result != kSuccess) {
561 "Failed to run Flutter engine");
562 return FALSE;
563 }
564
566
567 g_autoptr(FlSettings) settings = fl_settings_new();
568 self->settings_plugin = fl_settings_plugin_new(self);
569 fl_settings_plugin_start(self->settings_plugin, settings);
570
571 result = self->embedder_api.UpdateSemanticsEnabled(self->engine, TRUE);
572 if (result != kSuccess) {
573 g_warning("Failed to enable accessibility features on Flutter engine");
574 }
575
576 gdouble refresh_rate = fl_renderer_get_refresh_rate(self->renderer);
577 // FlutterEngineDisplay::refresh_rate expects 0 if the refresh rate is
578 // unknown.
579 if (refresh_rate <= 0.0) {
580 refresh_rate = 0.0;
581 }
582 FlutterEngineDisplay display = {};
583 display.struct_size = sizeof(FlutterEngineDisplay);
584 display.display_id = 0;
585 display.single_display = true;
586 display.refresh_rate = refresh_rate;
587
588 std::vector displays = {display};
589 result = self->embedder_api.NotifyDisplayUpdate(
590 self->engine, kFlutterEngineDisplaysUpdateTypeStartup, displays.data(),
591 displays.size());
592 if (result != kSuccess) {
593 g_warning("Failed to notify display update to Flutter engine: %d", result);
594 }
595
596 return TRUE;
597}
@ kFlutterEngineAOTDataSourceTypeElfPath
Definition: embedder.h:2110
@ kOpenGL
Definition: embedder.h:80
@ kFlutterEngineDisplaysUpdateTypeStartup
Definition: embedder.h:2006
#define FLUTTER_ENGINE_VERSION
Definition: embedder.h:70
SkBitmap source
Definition: examples.cpp:28
G_MODULE_EXPORT const gchar * fl_dart_project_get_assets_path(FlDartProject *self)
G_MODULE_EXPORT const gchar * fl_dart_project_get_aot_library_path(FlDartProject *self)
G_MODULE_EXPORT const gchar * fl_dart_project_get_icu_data_path(FlDartProject *self)
G_MODULE_EXPORT gchar ** fl_dart_project_get_dart_entrypoint_arguments(FlDartProject *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:248
static bool fl_engine_runs_task_on_current_thread(void *user_data)
Definition: fl_engine.cc:289
static void fl_engine_on_pre_engine_restart_cb(void *user_data)
Definition: fl_engine.cc:339
static bool compositor_create_backing_store_callback(const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out, void *user_data)
Definition: fl_engine.cc:185
static bool fl_engine_gl_make_current(void *user_data)
Definition: fl_engine.cc:218
static void * fl_engine_gl_proc_resolver(void *user_data, const char *name)
Definition: fl_engine.cc:213
static void fl_engine_post_task(FlutterTask task, uint64_t target_time_nanos, void *user_data)
Definition: fl_engine.cc:295
static uint32_t fl_engine_gl_get_fbo(void *user_data)
Definition: fl_engine.cc:230
static bool fl_engine_gl_present(void *user_data)
Definition: fl_engine.cc:235
GPtrArray * fl_engine_get_switches(FlEngine *self)
Definition: fl_engine.cc:948
static void setup_locales(FlEngine *self)
Definition: fl_engine.cc:150
static bool compositor_present_layers_callback(const FlutterLayer **layers, size_t layers_count, void *user_data)
Definition: fl_engine.cc:203
static void fl_engine_update_semantics_cb(const FlutterSemanticsUpdate2 *update, void *user_data)
Definition: fl_engine.cc:324
static bool fl_engine_gl_make_resource_current(void *user_data)
Definition: fl_engine.cc:241
static void fl_engine_platform_message_cb(const FlutterPlatformMessage *message, void *user_data)
Definition: fl_engine.cc:304
static bool compositor_collect_backing_store_callback(const FlutterBackingStore *renderer, void *user_data)
Definition: fl_engine.cc:195
static constexpr size_t kPlatformTaskRunnerIdentifier
Definition: fl_engine.cc:31
static bool fl_engine_gl_clear_current(void *user_data)
Definition: fl_engine.cc:224
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
gdouble fl_renderer_get_refresh_rate(FlRenderer *self)
Definition: fl_renderer.cc:156
FlSettings * fl_settings_new()
Definition: fl_settings.cc:55
FlSettingsPlugin * fl_settings_plugin_new(FlEngine *engine)
void fl_settings_plugin_start(FlSettingsPlugin *self, FlSettings *settings)
FlTaskRunner * fl_task_runner_new(FlEngine *engine)
FlutterBackingStoreCreateCallback create_backing_store_callback
Definition: embedder.h:1903
FlutterLayersPresentCallback present_layers_callback
Definition: embedder.h:1921
size_t struct_size
This size of this struct. Must be sizeof(FlutterCompositor).
Definition: embedder.h:1887
FlutterBackingStoreCollectCallback collect_backing_store_callback
Definition: embedder.h:1908
const FlutterTaskRunnerDescription * render_task_runner
Definition: embedder.h:1601
const FlutterTaskRunnerDescription * platform_task_runner
Definition: embedder.h:1596
size_t struct_size
The size of this struct. Must be sizeof(FlutterCustomTaskRunners).
Definition: embedder.h:1591
size_t struct_size
This size of this struct. Must be sizeof(FlutterDisplay).
Definition: embedder.h:1973
FlutterEngineDisplayId display_id
Definition: embedder.h:1975
ProcResolver gl_proc_resolver
Definition: embedder.h:554
BoolCallback make_current
Definition: embedder.h:516
UIntCallback fbo_callback
Definition: embedder.h:530
size_t struct_size
The size of this struct. Must be sizeof(FlutterOpenGLRendererConfig).
Definition: embedder.h:515
TextureFrameCallback gl_external_texture_frame_callback
Definition: embedder.h:559
BoolCallback make_resource_current
Definition: embedder.h:537
BoolCallback clear_current
Definition: embedder.h:517
FlutterOpenGLRendererConfig open_gl
Definition: embedder.h:829
FlutterRendererType type
Definition: embedder.h:827
size_t struct_size
The size of this struct. Must be sizeof(FlutterTaskRunnerDescription).
Definition: embedder.h:1566
BoolCallback runs_task_on_current_thread_callback
Definition: embedder.h:1572
FlutterTaskRunnerPostTaskCallback post_task_callback
Definition: embedder.h:1583

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

909 {
910 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
911 return self->embedder_api.UnregisterExternalTexture(self->engine,
913}

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

937 {
938 g_return_if_fail(FL_IS_ENGINE(self));
939
940 if (self->engine == nullptr) {
941 return;
942 }
943
944 self->embedder_api.UpdateAccessibilityFeatures(
945 self->engine, static_cast<FlutterAccessibilityFeature>(flags));
946}
FlutterAccessibilityFeature
Definition: embedder.h:91
FlutterSemanticsFlag flags