| Flutter Linux Embedder |

Classes | Functions | Variables
fl_engine.cc File Reference
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"`
`#include <gmodule.h>`
`#include <cstring>`
`#include <string>`
`#include <vector>`
`#include "flutter/common/constants.h"`
`#include "flutter/shell/platform/common/app_lifecycle_state.h"`
`#include "flutter/shell/platform/common/engine_switches.h"`
`#include "flutter/shell/platform/embedder/embedder.h"`
`#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"`
`#include "flutter/shell/platform/linux/fl_dart_project_private.h"`
`#include "flutter/shell/platform/linux/fl_engine_private.h"`
`#include "flutter/shell/platform/linux/fl_pixel_buffer_texture_private.h"`
`#include "flutter/shell/platform/linux/fl_plugin_registrar_private.h"`
`#include "flutter/shell/platform/linux/fl_renderer.h"`
`#include "flutter/shell/platform/linux/fl_renderer_headless.h"`
`#include "flutter/shell/platform/linux/fl_settings_plugin.h"`
`#include "flutter/shell/platform/linux/fl_texture_gl_private.h"`
`#include "flutter/shell/platform/linux/fl_texture_registrar_private.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registry.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_string_codec.h"`

Go to the source code of this file.

## Classes
struct | _FlEngine

## Functions
static void | fl_engine_plugin_registry_iface_init (FlPluginRegistryInterface *iface)
| G_DEFINE_TYPE_WITH_CODE (FlEngine, fl_engine, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(fl_plugin_registry_get_type(), fl_engine_plugin_registry_iface_init)) enum
static void | parse_locale (const gchar *locale, gchar **language, gchar **territory, gchar **codeset, gchar **modifier)
static void | set_app_lifecycle_state (FlEngine *self, const flutter::AppLifecycleState state)
static void | setup_locales (FlEngine *self)
static bool | compositor_create_backing_store_callback (const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out, void *user_data)
static bool | compositor_collect_backing_store_callback (const FlutterBackingStore *renderer, void *user_data)
static bool | compositor_present_layers_callback (const FlutterLayer **layers, size_t layers_count, void *user_data)
static void * | fl_engine_gl_proc_resolver (void *user_data, const char *name)
static bool | fl_engine_gl_make_current (void *user_data)
static bool | fl_engine_gl_clear_current (void *user_data)
static uint32_t | fl_engine_gl_get_fbo (void *user_data)
static bool | fl_engine_gl_present (void *user_data)
static bool | fl_engine_gl_make_resource_current (void *user_data)
static bool | fl_engine_gl_external_texture_frame_callback (void *user_data, int64_t texture_id, size_t width, size_t height, FlutterOpenGLTexture *opengl_texture)
static bool | fl_engine_runs_task_on_current_thread (void *user_data)
static void | fl_engine_post_task (FlutterTask task, uint64_t target_time_nanos, void *user_data)
static void | fl_engine_platform_message_cb (const FlutterPlatformMessage *message, void *user_data)
static void | fl_engine_update_semantics_cb (const FlutterSemanticsUpdate2 *update, void *user_data)
static void | fl_engine_on_pre_engine_restart_cb (void *user_data)
static void | fl_engine_platform_message_response_cb (const uint8_t *data, size_t data_length, void *user_data)
static FlPluginRegistrar * | fl_engine_get_registrar_for_plugin (FlPluginRegistry *registry, const gchar *name)
static void | fl_engine_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
static void | fl_engine_dispose (GObject *object)
static void | fl_engine_class_init (FlEngineClass *klass)
static void | fl_engine_init (FlEngine *self)
FlEngine * | fl_engine_new (FlDartProject *project, FlRenderer *renderer)
G_MODULE_EXPORT FlEngine * | fl_engine_new_headless (FlDartProject *project)
gboolean | fl_engine_start (FlEngine *self, GError **error)
FlutterEngineProcTable * | fl_engine_get_embedder_api (FlEngine *self)
void | fl_engine_set_platform_message_handler (FlEngine *self, FlEnginePlatformMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
void | fl_engine_set_update_semantics_handler (FlEngine *self, FlEngineUpdateSemanticsHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
void | fl_engine_set_on_pre_engine_restart_handler (FlEngine *self, FlEngineOnPreEngineRestartHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
gboolean | fl_engine_send_platform_message_response (FlEngine *self, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
void | fl_engine_send_platform_message (FlEngine *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
GBytes * | fl_engine_send_platform_message_finish (FlEngine *self, GAsyncResult *result, GError **error)
void | fl_engine_send_window_state_event (FlEngine *self, gboolean visible, gboolean focused)
void | fl_engine_send_window_metrics_event (FlEngine *self, size_t width, size_t height, double pixel_ratio)
void | fl_engine_send_mouse_pointer_event (FlEngine *self, FlutterPointerPhase phase, size_t timestamp, double x, double y, 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 *self, const FlutterKeyEvent *event, FlutterKeyEventCallback callback, void *user_data)
void | fl_engine_dispatch_semantics_action (FlEngine *self, uint64_t id, FlutterSemanticsAction action, GBytes *data)
gboolean | fl_engine_mark_texture_frame_available (FlEngine *self, int64_t texture_id)
gboolean | fl_engine_register_external_texture (FlEngine *self, int64_t texture_id)
gboolean | fl_engine_unregister_external_texture (FlEngine *self, int64_t texture_id)
G_MODULE_EXPORT FlBinaryMessenger * | fl_engine_get_binary_messenger (FlEngine *self)
FlTaskRunner * | fl_engine_get_task_runner (FlEngine *self)
void | fl_engine_execute_task (FlEngine *self, FlutterTask *task)
G_MODULE_EXPORT FlTextureRegistrar * | fl_engine_get_texture_registrar (FlEngine *self)
void | fl_engine_update_accessibility_features (FlEngine *self, int32_t flags)
GPtrArray * | fl_engine_get_switches (FlEngine *self)

## Variables
static constexpr size_t | kPlatformTaskRunnerIdentifier = 1
static constexpr int32_t | kMousePointerDeviceId = 0
static constexpr int32_t | kPointerPanZoomDeviceId = 1
static constexpr const char * | kFlutterLifecycleChannel = "flutter/lifecycle"

## Function Documentation

## ◆ compositor_collect_backing_store_callback()

static bool compositor_collect_backing_store_callback | ( | const FlutterBackingStore * | renderer,
|  | void * | user_data
| ) |  |
| static

Definition at line 195 of file fl_engine.cc.

197 {
198 g_return_val_if_fail(FL_IS_RENDERER(user_data), false);
199 return fl_renderer_collect_backing_store(FL_RENDERER(user_data), renderer);
200 }

References fl_renderer_collect_backing_store(), and user_data.

Referenced by fl_engine_start().

## ◆ compositor_create_backing_store_callback()

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

Definition at line 185 of file fl_engine.cc.

188 {
189 g_return_val_if_fail(FL_IS_RENDERER(user_data), false);
190 return fl_renderer_create_backing_store(FL_RENDERER(user_data), config,
191 backing_store_out);
192 }

References fl_renderer_create_backing_store(), and user_data.

Referenced by fl_engine_start().

## ◆ compositor_present_layers_callback()

static bool compositor_present_layers_callback | ( | const FlutterLayer ** | layers,
|  | size_t | layers_count,
|  | void * | user_data
| ) |  |
| static

Definition at line 203 of file fl_engine.cc.

205 {
206 g_return_val_if_fail(FL_IS_RENDERER(user_data), false);
207 return fl_renderer_present_layers(FL_RENDERER(user_data), layers,
208 layers_count);
209 }

References fl_renderer_present_layers(), and user_data.

Referenced by fl_engine_start().

## ◆ fl_engine_class_init()

static void fl_engine_class_init | ( | FlEngineClass * | klass | ) |
| static

Definition at line 433 of file fl_engine.cc.

433 {
434 G_OBJECT_CLASS(klass)->dispose = fl_engine_dispose;
435 G_OBJECT_CLASS(klass)->set_property = fl_engine_set_property;
436
437 g_object_class_install_property(
438 G_OBJECT_CLASS(klass), kPropBinaryMessenger,
439 g_param_spec_object(
440 "binary-messenger", "messenger", "Binary messenger",
441 fl_binary_messenger_get_type(),
442 static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
443 G_PARAM_STATIC_STRINGS)));
444 }

References fl_engine_dispose(), and fl_engine_set_property().

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

855 {
856 g_return_if_fail(FL_IS_ENGINE(self));
857
858 if (self->engine == nullptr) {
859 return;
860 }
861
862 const uint8_t* action_data = nullptr;
863 size_t action_data_length = 0;
864 if (data != nullptr) {
865 action_data = static_cast<const uint8_t*>(
866 g_bytes_get_data(data, &action_data_length));
867 }
868
869 self->embedder_api.DispatchSemanticsAction(self->engine, id, action,
870 action_data, action_data_length);
871 }

Referenced by fl_accessible_node_perform_action_impl(), and TEST().

## ◆ fl_engine_dispose()

static void fl_engine_dispose | ( | GObject * | object | ) |
| static

Definition at line 389 of file fl_engine.cc.

389 {
390 FlEngine* self = FL_ENGINE(object);
391
392 if (self->engine != nullptr) {
393 self->embedder_api.Shutdown(self->engine);
394 self->engine = nullptr;
395 }
396
397 if (self->aot_data != nullptr) {
398 self->embedder_api.CollectAOTData(self->aot_data);
399 self->aot_data = nullptr;
400 }
401
402 g_clear_object(&self->project);
403 g_clear_object(&self->renderer);
404 g_clear_object(&self->texture_registrar);
405 g_clear_object(&self->binary_messenger);
406 g_clear_object(&self->settings_plugin);
407 g_clear_object(&self->task_runner);
408
409 if (self->platform_message_handler_destroy_notify) {
410 self->platform_message_handler_destroy_notify(
411 self->platform_message_handler_data);
412 }
413 self->platform_message_handler_data = nullptr;
414 self->platform_message_handler_destroy_notify = nullptr;
415
416 if (self->update_semantics_handler_destroy_notify) {
417 self->update_semantics_handler_destroy_notify(
418 self->update_semantics_handler_data);
419 }
420 self->update_semantics_handler_data = nullptr;
421 self->update_semantics_handler_destroy_notify = nullptr;
422
423 if (self->on_pre_engine_restart_handler_destroy_notify) {
424 self->on_pre_engine_restart_handler_destroy_notify(
425 self->on_pre_engine_restart_handler_data);
426 }
427 self->on_pre_engine_restart_handler_data = nullptr;
428 self->on_pre_engine_restart_handler_destroy_notify = nullptr;
429
430 G_OBJECT_CLASS(fl_engine_parent_class)->dispose(object);
431 }

Referenced by fl_engine_class_init().

## ◆ fl_engine_execute_task()

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

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

Executes given Flutter task.

Definition at line 905 of file fl_engine.cc.

905 {
906 g_return_if_fail(FL_IS_ENGINE(self));
907 self->embedder_api.RunTask(self->engine, task);
908 }

Referenced by fl_task_runner_process_expired_tasks_locked().

## ◆ fl_engine_get_binary_messenger()

G_MODULE_EXPORT FlBinaryMessenger* fl_engine_get_binary_messenger | ( | FlEngine * | engine | ) |

fl_engine_get_binary_messenger: @engine: an #FlEngine.

Gets the messenger to communicate with this engine.

Returns: an #FlBinaryMessenger.

Definition at line 894 of file fl_engine.cc.

895 {
896 g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
897 return self->binary_messenger;
898 }

Referenced by create_context_cb(), fl_settings_plugin_new(), fl_view_get_registrar_for_plugin(), fl_view_keyboard_delegate_iface_init(), init_keyboard(), and set_app_lifecycle_state().

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

579 {
580 return &(self->embedder_api);
581 }

Referenced by TEST().

## ◆ fl_engine_get_registrar_for_plugin()

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

Definition at line 359 of file fl_engine.cc.

361 {
362 FlEngine* self = FL_ENGINE(registry);
363
364 return fl_plugin_registrar_new(nullptr, self->binary_messenger,
365 self->texture_registrar);
366 }

References fl_plugin_registrar_new().

Referenced by fl_engine_plugin_registry_iface_init().

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

927 {
928 GPtrArray* switches = g_ptr_array_new_with_free_func(g_free);
929 for (const auto& env_switch : flutter::GetSwitchesFromEnvironment()) {
930 g_ptr_array_add(switches, g_strdup(env_switch.c_str()));
931 }
932 return switches;
933 }

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

900 {
901 g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
902 return self->task_runner;
903 }

Referenced by fl_renderer_unblock_main_thread(), and fl_renderer_wait_for_frame().

## ◆ fl_engine_get_texture_registrar()

G_MODULE_EXPORT FlTextureRegistrar* fl_engine_get_texture_registrar | ( | FlEngine * | engine | ) |

fl_engine_get_texture_registrar: @engine: an #FlEngine.

Gets the texture registrar for registering textures.

Returns: an #FlTextureRegistrar.

Definition at line 910 of file fl_engine.cc.

911 {
912 g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
913 return self->texture_registrar;
914 }

Referenced by fl_view_get_registrar_for_plugin().

## ◆ fl_engine_gl_clear_current()

static bool fl_engine_gl_clear_current | ( | void * | user_data | ) |
| static

Definition at line 224 of file fl_engine.cc.

224 {
225 FlEngine* self = static_cast<FlEngine*>(user_data);
226 fl_renderer_clear_current(self->renderer);
227 return true;
228 }

References fl_renderer_clear_current(), and user_data.

Referenced by fl_engine_start().

## ◆ fl_engine_gl_external_texture_frame_callback()

static bool fl_engine_gl_external_texture_frame_callback | ( | void * | user_data,
|  | int64_t | texture_id,
|  | size_t | width,
|  | size_t | height,
|  | FlutterOpenGLTexture * | opengl_texture
| ) |  |
| static

Definition at line 248 of file fl_engine.cc.

253 {
254 FlEngine* self = static_cast<FlEngine*>(user_data);
255 if (!self->texture_registrar) {
256 return false;
257 }
258
259 FlTexture* texture =
260 fl_texture_registrar_lookup_texture(self->texture_registrar, texture_id);
261 if (texture == nullptr) {
262 g_warning("Unable to find texture %" G_GINT64_FORMAT, texture_id);
263 return false;
264 }
265
266 gboolean result;
267 g_autoptr(GError) error = nullptr;
268 if (FL_IS_TEXTURE_GL(texture)) {
269 result = fl_texture_gl_populate(FL_TEXTURE_GL(texture), width, height,
270 opengl_texture, &error);
271 } else if (FL_IS_PIXEL_BUFFER_TEXTURE(texture)) {
272 result =
273 fl_pixel_buffer_texture_populate(FL_PIXEL_BUFFER_TEXTURE(texture),
274 width, height, opengl_texture, &error);
275 } else {
276 g_warning("Unsupported texture type %" G_GINT64_FORMAT, texture_id);
277 return false;
278 }
279
280 if (!result) {
281 g_warning("%s", error->message);
282 return false;
283 }
284
285 return true;
286 }

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

Referenced by fl_engine_start().

## ◆ fl_engine_gl_get_fbo()

static uint32_t fl_engine_gl_get_fbo | ( | void * | user_data | ) |
| static

Definition at line 230 of file fl_engine.cc.

230 {
231 FlEngine* self = static_cast<FlEngine*>(user_data);
232 return fl_renderer_get_fbo(self->renderer);
233 }

References fl_renderer_get_fbo(), and user_data.

Referenced by fl_engine_start().

## ◆ fl_engine_gl_make_current()

static bool fl_engine_gl_make_current | ( | void * | user_data | ) |
| static

Definition at line 218 of file fl_engine.cc.

218 {
219 FlEngine* self = static_cast<FlEngine*>(user_data);
220 fl_renderer_make_current(self->renderer);
221 return true;
222 }

References fl_renderer_make_current(), and user_data.

Referenced by fl_engine_start().

## ◆ fl_engine_gl_make_resource_current()

static bool fl_engine_gl_make_resource_current | ( | void * | user_data | ) |
| static

Definition at line 241 of file fl_engine.cc.

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

References fl_renderer_make_resource_current(), and user_data.

Referenced by fl_engine_start().

## ◆ fl_engine_gl_present()

static bool fl_engine_gl_present | ( | void * | user_data | ) |
| static

Definition at line 235 of file fl_engine.cc.

235 {
236 // No action required, as this is handled in
237 // compositor_present_layers_callback.
238 return true;
239 }

Referenced by fl_engine_start().

## ◆ fl_engine_gl_proc_resolver()

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

Definition at line 213 of file fl_engine.cc.

213 {
214 FlEngine* self = static_cast<FlEngine*>(user_data);
215 return fl_renderer_get_proc_address(self->renderer, name);
216 }

References fl_renderer_get_proc_address(), and user_data.

Referenced by fl_engine_start().

## ◆ fl_engine_init()

static void fl_engine_init | ( | FlEngine * | self | ) |
| static

Definition at line 446 of file fl_engine.cc.

446 {
447 self->thread = g_thread_self();
448
449 self->embedder_api.struct_size = sizeof(FlutterEngineProcTable);
450 FlutterEngineGetProcAddresses(&self->embedder_api);
451
452 self->texture_registrar = fl_texture_registrar_new(self);
453 }

References fl_texture_registrar_new().

## ◆ fl_engine_mark_texture_frame_available()

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

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

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

Returns: TRUE on success.

Definition at line 873 of file fl_engine.cc.

874 {
875 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
876 return self->embedder_api.MarkExternalTextureFrameAvailable(
877 self->engine, texture_id) == kSuccess;
878 }

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

References fl_binary_messenger_new().

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

## ◆ fl_engine_new_headless()

G_MODULE_EXPORT FlEngine* fl_engine_new_headless | ( | FlDartProject * | project | ) |

FlEngine:

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

Creates new Flutter engine running in headless mode.

Returns: a new #FlEngine.

Definition at line 466 of file fl_engine.cc.

466 {
467 g_autoptr(FlRendererHeadless) renderer = fl_renderer_headless_new();
468 return fl_engine_new(project, FL_RENDERER(renderer));
469 }

References fl_engine_new(), and fl_renderer_headless_new().

## ◆ fl_engine_on_pre_engine_restart_cb()

static void fl_engine_on_pre_engine_restart_cb | ( | void * | user_data | ) |
| static

Definition at line 339 of file fl_engine.cc.

339 {
340 FlEngine* self = FL_ENGINE(user_data);
341
342 if (self->on_pre_engine_restart_handler != nullptr) {
343 self->on_pre_engine_restart_handler(
344 self, self->on_pre_engine_restart_handler_data);
345 }
346 }

References user_data.

Referenced by fl_engine_start().

## ◆ fl_engine_platform_message_cb()

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

Definition at line 304 of file fl_engine.cc.

305 {
306 FlEngine* self = FL_ENGINE(user_data);
307
308 gboolean handled = FALSE;
309 if (self->platform_message_handler != nullptr) {
310 g_autoptr(GBytes) data =
311 g_bytes_new(message->message, message->message_size);
312 handled = self->platform_message_handler(
313 self, message->channel, data, message->response_handle,
314 self->platform_message_handler_data);
315 }
316
317 if (!handled) {
318 fl_engine_send_platform_message_response(self, message->response_handle,
319 nullptr, nullptr);
320 }
321 }

References fl_engine_send_platform_message_response(), and user_data.

Referenced by fl_engine_start().

## ◆ fl_engine_platform_message_response_cb()

static void fl_engine_platform_message_response_cb | ( | const uint8_t * | data,
|  | size_t | data_length,
|  | void * | user_data
| ) |  |
| static

Definition at line 350 of file fl_engine.cc.

352 {
353 g_autoptr(GTask) task = G_TASK(user_data);
354 g_task_return_pointer(task, g_bytes_new(data, data_length),
355 reinterpret_cast<GDestroyNotify>(g_bytes_unref));
356 }

References user_data.

Referenced by fl_engine_send_platform_message().

## ◆ fl_engine_plugin_registry_iface_init()

static void fl_engine_plugin_registry_iface_init | ( | FlPluginRegistryInterface * | iface | ) |
| static

Definition at line 368 of file fl_engine.cc.

369 {
370 iface->get_registrar_for_plugin = fl_engine_get_registrar_for_plugin;
371 }

References fl_engine_get_registrar_for_plugin().

## ◆ fl_engine_post_task()

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

Definition at line 295 of file fl_engine.cc.

297 {
298 FlEngine* self = static_cast<FlEngine*>(user_data);
299
300 fl_task_runner_post_task(self->task_runner, task, target_time_nanos);
301 }

References fl_task_runner_post_task(), and user_data.

Referenced by fl_engine_start().

## ◆ fl_engine_register_external_texture()

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

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

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

Returns: TRUE on success.

Definition at line 880 of file fl_engine.cc.

881 {
882 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
883 return self->embedder_api.RegisterExternalTexture(self->engine, texture_id) ==
884 kSuccess;
885 }

References texture_id.

Referenced by register_texture().

## ◆ fl_engine_runs_task_on_current_thread()

static bool fl_engine_runs_task_on_current_thread | ( | void * | user_data | ) |
| static

Definition at line 289 of file fl_engine.cc.

289 {
290 FlEngine* self = static_cast<FlEngine*>(user_data);
291 return self->thread == g_thread_self();
292 }

References user_data.

Referenced by fl_engine_start().

## ◆ fl_engine_send_key_event()

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

fl_engine_send_key_event:

Definition at line 839 of file fl_engine.cc.

842 {
843 g_return_if_fail(FL_IS_ENGINE(self));
844
845 if (self->engine == nullptr) {
846 return;
847 }
848
849 self->embedder_api.SendKeyEvent(self->engine, event, callback, user_data);
850 }

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,
|  | 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. @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 770 of file fl_engine.cc.

777 {
778 g_return_if_fail(FL_IS_ENGINE(self));
779
780 if (self->engine == nullptr) {
781 return;
782 }
783
784 FlutterPointerEvent fl_event = {};
785 fl_event.struct_size = sizeof(fl_event);
786 fl_event.phase = phase;
787 fl_event.timestamp = timestamp;
788 fl_event.x = x;
789 fl_event.y = y;
790 if (scroll_delta_x != 0 || scroll_delta_y != 0) {
791 fl_event.signal_kind = kFlutterPointerSignalKindScroll;
792 }
793 fl_event.scroll_delta_x = scroll_delta_x;
794 fl_event.scroll_delta_y = scroll_delta_y;
795 fl_event.device_kind = kFlutterPointerDeviceKindMouse;
796 fl_event.buttons = buttons;
797 fl_event.device = kMousePointerDeviceId;
798 // TODO(dkwingsmt): Assign the correct view ID once the Linux embedder
799 // supports multiple views.
800 // https://github.com/flutter/flutter/issues/138178
801 fl_event.view_id = flutter::kFlutterImplicitViewId;
802 self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);
803 }

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

673 {
674 g_return_if_fail(FL_IS_ENGINE(self));
675
676 GTask* task = nullptr;
677 FlutterPlatformMessageResponseHandle* response_handle = nullptr;
678 if (callback != nullptr) {
679 task = g_task_new(self, cancellable, callback, user_data);
680
681 if (self->engine == nullptr) {
682 g_task_return_new_error(task, fl_engine_error_quark(),
683 FL_ENGINE_ERROR_FAILED, "No engine to send to");
684 return;
685 }
686
687 FlutterEngineResult result =
688 self->embedder_api.PlatformMessageCreateResponseHandle(
689 self->engine, fl_engine_platform_message_response_cb, task,
690 &response_handle);
691 if (result != kSuccess) {
692 g_task_return_new_error(task, fl_engine_error_quark(),
693 FL_ENGINE_ERROR_FAILED,
694 "Failed to create response handle");
695 g_object_unref(task);
696 return;
697 }
698 } else if (self->engine == nullptr) {
699 return;
700 }
701
702 FlutterPlatformMessage fl_message = {};
703 fl_message.struct_size = sizeof(fl_message);
704 fl_message.channel = channel;
705 fl_message.message =
706 message != nullptr
707 ? static_cast<const uint8_t*>(g_bytes_get_data(message, nullptr))
708 : nullptr;
709 fl_message.message_size = message != nullptr ? g_bytes_get_size(message) : 0;
710 fl_message.response_handle = response_handle;
711 FlutterEngineResult result =
712 self->embedder_api.SendPlatformMessage(self->engine, &fl_message);
713
714 if (result != kSuccess && task != nullptr) {
715 g_task_return_new_error(task, fl_engine_error_quark(),
716 FL_ENGINE_ERROR_FAILED,
717 "Failed to send platform messages");
718 g_object_unref(task);
719 }
720
721 if (response_handle != nullptr) {
722 self->embedder_api.PlatformMessageReleaseResponseHandle(self->engine,
723 response_handle);
724 }
725 }

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

729 {
730 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
731 g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
732
733 return static_cast<GBytes*>(g_task_propagate_pointer(G_TASK(result), error));
734 }

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

640 {
641 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
642 g_return_val_if_fail(handle != nullptr, FALSE);
643
644 if (self->engine == nullptr) {
645 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
646 "No engine to send response to");
647 return FALSE;
648 }
649
650 gsize data_length = 0;
651 const uint8_t* data = nullptr;
652 if (response != nullptr) {
653 data =
654 static_cast<const uint8_t*>(g_bytes_get_data(response, &data_length));
655 }
656 FlutterEngineResult result = self->embedder_api.SendPlatformMessageResponse(
657 self->engine, handle, data, data_length);
658
659 if (result != kSuccess) {
660 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
661 "Failed to send platform message response");
662 return FALSE;
663 }
664
665 return TRUE;
666 }

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

813 {
814 g_return_if_fail(FL_IS_ENGINE(self));
815
816 if (self->engine == nullptr) {
817 return;
818 }
819
820 FlutterPointerEvent fl_event = {};
821 fl_event.struct_size = sizeof(fl_event);
822 fl_event.timestamp = timestamp;
823 fl_event.x = x;
824 fl_event.y = y;
825 fl_event.phase = phase;
826 fl_event.pan_x = pan_x;
827 fl_event.pan_y = pan_y;
828 fl_event.scale = scale;
829 fl_event.rotation = rotation;
830 fl_event.device = kPointerPanZoomDeviceId;
831 fl_event.device_kind = kFlutterPointerDeviceKindTrackpad;
832 // TODO(dkwingsmt): Assign the correct view ID once the Linux embedder
833 // supports multiple views.
834 // https://github.com/flutter/flutter/issues/138178
835 fl_event.view_id = flutter::kFlutterImplicitViewId;
836 self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);
837 }

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

751 {
752 g_return_if_fail(FL_IS_ENGINE(self));
753
754 if (self->engine == nullptr) {
755 return;
756 }
757
758 FlutterWindowMetricsEvent event = {};
759 event.struct_size = sizeof(FlutterWindowMetricsEvent);
760 event.width = width;
761 event.height = height;
762 event.pixel_ratio = pixel_ratio;
763 // TODO(dkwingsmt): Assign the correct view ID once the Linux embedder
764 // supports multiple views.
765 // https://github.com/flutter/flutter/issues/138178
766 event.view_id = flutter::kFlutterImplicitViewId;
767 self->embedder_api.SendWindowMetricsEvent(self->engine, &event);
768 }

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

738 {
739 if (visible && focused) {
740 set_app_lifecycle_state(self, flutter::AppLifecycleState::kResumed);
741 } else if (visible) {
742 set_app_lifecycle_state(self, flutter::AppLifecycleState::kInactive);
743 } else {
744 set_app_lifecycle_state(self, flutter::AppLifecycleState::kHidden);
745 }
746 }

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

622 {
623 g_return_if_fail(FL_IS_ENGINE(self));
624
625 if (self->on_pre_engine_restart_handler_destroy_notify) {
626 self->on_pre_engine_restart_handler_destroy_notify(
627 self->on_pre_engine_restart_handler_data);
628 }
629
630 self->on_pre_engine_restart_handler = handler;
631 self->on_pre_engine_restart_handler_data = user_data;
632 self->on_pre_engine_restart_handler_destroy_notify = destroy_notify;
633 }

References user_data.

Referenced by create_context_cb(), 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 583 of file fl_engine.cc.

587 {
588 g_return_if_fail(FL_IS_ENGINE(self));
589 g_return_if_fail(handler != nullptr);
590
591 if (self->platform_message_handler_destroy_notify) {
592 self->platform_message_handler_destroy_notify(
593 self->platform_message_handler_data);
594 }
595
596 self->platform_message_handler = handler;
597 self->platform_message_handler_data = user_data;
598 self->platform_message_handler_destroy_notify = destroy_notify;
599 }

References user_data.

Referenced by fl_binary_messenger_new().

## ◆ fl_engine_set_property()

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

Definition at line 373 of file fl_engine.cc.

376 {
377 FlEngine* self = FL_ENGINE(object);
378 switch (prop_id) {
379 case kPropBinaryMessenger:
380 g_set_object(&self->binary_messenger,
381 FL_BINARY_MESSENGER(g_value_get_object(value)));
382 break;
383 default:
384 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
385 break;
386 }
387 }

References prop_id, pspec, and value.

Referenced by fl_engine_class_init().

## ◆ fl_engine_set_update_semantics_handler()

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

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

Registers the function called when a semantics update is received.

Definition at line 601 of file fl_engine.cc.

605 {
606 g_return_if_fail(FL_IS_ENGINE(self));
607
608 if (self->update_semantics_handler_destroy_notify) {
609 self->update_semantics_handler_destroy_notify(
610 self->update_semantics_handler_data);
611 }
612
613 self->update_semantics_handler = handler;
614 self->update_semantics_handler_data = user_data;
615 self->update_semantics_handler_destroy_notify = destroy_notify;
616 }

References user_data.

Referenced by create_context_cb(), 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 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;
478 config.open_gl.struct_size = sizeof(FlutterOpenGLRendererConfig);
479 config.open_gl.gl_proc_resolver = fl_engine_gl_proc_resolver;
480 config.open_gl.make_current = fl_engine_gl_make_current;
481 config.open_gl.clear_current = fl_engine_gl_clear_current;
482 config.open_gl.fbo_callback = fl_engine_gl_get_fbo;
483 config.open_gl.present = fl_engine_gl_present;
484 config.open_gl.make_resource_current = fl_engine_gl_make_resource_current;
485 config.open_gl.gl_external_texture_frame_callback =
486 fl_engine_gl_external_texture_frame_callback;
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 =
492 fl_engine_runs_task_on_current_thread;
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 =
508 fl_dart_project_get_dart_entrypoint_arguments(self->project);
509
510 FlutterProjectArgs args = {};
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;
530 compositor.create_backing_store_callback =
531 compositor_create_backing_store_callback;
532 compositor.collect_backing_store_callback =
533 compositor_collect_backing_store_callback;
534 compositor.present_layers_callback = compositor_present_layers_callback;
535 args.compositor = &compositor;
536
537 if (self->embedder_api.RunsAOTCompiledDartCode()) {
538 FlutterEngineAOTDataSource source = {};
539 source.type = kFlutterEngineAOTDataSourceTypeElfPath;
540 source.elf_path = fl_dart_project_get_aot_library_path(self->project);
541 if (self->embedder_api.CreateAOTData(&source, &self->aot_data) !=
542 kSuccess) {
543 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
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) {
553 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
554 "Failed to initialize Flutter engine");
555 return FALSE;
556 }
557
558 result = self->embedder_api.RunInitialized(self->engine);
559 if (result != kSuccess) {
560 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
561 "Failed to run Flutter engine");
562 return FALSE;
563 }
564
565 setup_locales(self);
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 return TRUE;
577 }

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

888 {
889 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
890 return self->embedder_api.UnregisterExternalTexture(self->engine,
891 texture_id) == kSuccess;
892 }

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

916 {
917 g_return_if_fail(FL_IS_ENGINE(self));
918
919 if (self->engine == nullptr) {
920 return;
921 }
922
923 self->embedder_api.UpdateAccessibilityFeatures(
924 self->engine, static_cast<FlutterAccessibilityFeature>(flags));
925 }

References flags.

Referenced by update_settings().

## ◆ fl_engine_update_semantics_cb()

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

Definition at line 324 of file fl_engine.cc.

325 {
326 FlEngine* self = FL_ENGINE(user_data);
327
328 if (self->update_semantics_handler != nullptr) {
329 self->update_semantics_handler(self, update,
330 self->update_semantics_handler_data);
331 }
332 }

References update, and user_data.

Referenced by fl_engine_start().

## ◆ G_DEFINE_TYPE_WITH_CODE()

G_DEFINE_TYPE_WITH_CODE | ( | FlEngine | ,
|  | fl_engine | ,
|  | G_TYPE_OBJECT | ,
|  | G_IMPLEMENT_INTERFACE(fl_plugin_registry_get_type(), fl_engine_plugin_registry_iface_init) |
| ) |  |

Definition at line 77 of file fl_engine.cc.

84 { kProp0, kPropBinaryMessenger, kPropLast };

References kProp0, and kPropLast.

## ◆ parse_locale()

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

Definition at line 87 of file fl_engine.cc.

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

Referenced by setup_locales().

## ◆ set_app_lifecycle_state()

static void set_app_lifecycle_state | ( | FlEngine * | self,
|  | const flutter::AppLifecycleState | state
| ) |  |
| static

Definition at line 130 of file fl_engine.cc.

131 {
132 FlBinaryMessenger* binary_messenger = fl_engine_get_binary_messenger(self);
133
134 g_autoptr(FlValue) value =
135 fl_value_new_string(flutter::AppLifecycleStateToString(state));
136 g_autoptr(FlStringCodec) codec = fl_string_codec_new();
137 g_autoptr(GBytes) message =
138 fl_message_codec_encode_message(FL_MESSAGE_CODEC(codec), value, nullptr);
139
140 if (message == nullptr) {
141 return;
142 }
143
144 fl_binary_messenger_send_on_channel(binary_messenger,
145 kFlutterLifecycleChannel, message,
146 nullptr, nullptr, nullptr);
147 }

References flutter::AppLifecycleStateToString(), fl_binary_messenger_send_on_channel(), fl_engine_get_binary_messenger(), fl_message_codec_encode_message(), fl_string_codec_new(), fl_value_new_string(), kFlutterLifecycleChannel, state, and value.

Referenced by fl_engine_send_window_state_event().

## ◆ setup_locales()

static void setup_locales | ( | FlEngine * | self | ) |
| static

Definition at line 150 of file fl_engine.cc.

150 {
151 const gchar* const* languages = g_get_language_names();
152 g_autoptr(GPtrArray) locales_array = g_ptr_array_new_with_free_func(g_free);
153 // Helper array to take ownership of the strings passed to Flutter.
154 g_autoptr(GPtrArray) locale_strings = g_ptr_array_new_with_free_func(g_free);
155 for (int i = 0; languages[i] != nullptr; i++) {
156 gchar *language, *territory;
157 parse_locale(languages[i], &language, &territory, nullptr, nullptr);
158 if (language != nullptr) {
159 g_ptr_array_add(locale_strings, language);
160 }
161 if (territory != nullptr) {
162 g_ptr_array_add(locale_strings, territory);
163 }
164
165 FlutterLocale* locale =
166 static_cast<FlutterLocale*>(g_malloc0(sizeof(FlutterLocale)));
167 g_ptr_array_add(locales_array, locale);
168 locale->struct_size = sizeof(FlutterLocale);
169 locale->language_code = language;
170 locale->country_code = territory;
171 locale->script_code = nullptr;
172 locale->variant_code = nullptr;
173 }
174 FlutterLocale** locales =
175 reinterpret_cast<FlutterLocale**>(locales_array->pdata);
176 FlutterEngineResult result = self->embedder_api.UpdateLocales(
177 self->engine, const_cast<const FlutterLocale**>(locales),
178 locales_array->len);
179 if (result != kSuccess) {
180 g_warning("Failed to set up Flutter locales");
181 }
182 }

References parse_locale(), and result.

Referenced by fl_engine_start().

## Variable Documentation

## ◆ kFlutterLifecycleChannel

constexpr const char* kFlutterLifecycleChannel = "flutter/lifecycle"
| static constexpr

Definition at line 38 of file fl_engine.cc.

Referenced by set_app_lifecycle_state().

## ◆ kMousePointerDeviceId

constexpr int32_t kMousePointerDeviceId = 0
| static constexpr

Definition at line 35 of file fl_engine.cc.

Referenced by fl_engine_send_mouse_pointer_event().

## ◆ kPlatformTaskRunnerIdentifier

constexpr size_t kPlatformTaskRunnerIdentifier = 1
| static constexpr

Definition at line 31 of file fl_engine.cc.

Referenced by fl_engine_start().

## ◆ kPointerPanZoomDeviceId

constexpr int32_t kPointerPanZoomDeviceId = 1
| static constexpr

Definition at line 36 of file fl_engine.cc.

Referenced by fl_engine_send_pointer_pan_zoom_event().

prop_id
guint prop_id
Definition: fl_standard_method_codec.cc:31
fl_dart_project_get_aot_library_path
const G_MODULE_EXPORT gchar * fl_dart_project_get_aot_library_path(FlDartProject *self)
Definition: fl_dart_project.cc:72
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_texture_registrar_lookup_texture
FlTexture * fl_texture_registrar_lookup_texture(FlTextureRegistrar *self, int64_t texture_id)
Definition: fl_texture_registrar.cc:191
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
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
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:105
fl_engine_dispose
static void fl_engine_dispose(GObject *object)
Definition: fl_engine.cc:389
user_data
FlKeyEvent uint64_t FlKeyResponderAsyncCallback gpointer user_data
Definition: fl_key_channel_responder.cc:121
fl_texture_registrar_new
FlTextureRegistrar * fl_texture_registrar_new(FlEngine *engine)
Definition: fl_texture_registrar.cc:216
pspec
guint const GValue GParamSpec * pspec
Definition: fl_standard_method_codec.cc:33
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_renderer_clear_current
void fl_renderer_clear_current(FlRenderer *self)
Definition: fl_renderer.cc:151
fl_engine_get_binary_messenger
G_MODULE_EXPORT FlBinaryMessenger * fl_engine_get_binary_messenger(FlEngine *self)
Definition: fl_engine.cc:894
fl_renderer_get_proc_address
void * fl_renderer_get_proc_address(FlRenderer *self, const char *name)
Definition: fl_renderer.cc:135
state
AtkStateType state
Definition: fl_accessible_node.cc:10
fl_binary_messenger_new
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
Definition: fl_binary_messenger.cc:406
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
update
G_BEGIN_DECLS const FlutterSemanticsUpdate2 * update
Definition: fl_view_accessible.h:40
kPropLast
@ kPropLast
Definition: fl_accessible_node.cc:83
fl_engine_set_property
static void fl_engine_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
Definition: fl_engine.cc:373
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
fl_engine_new
FlEngine * fl_engine_new(FlDartProject *project, FlRenderer *renderer)
Definition: fl_engine.cc:455
fl_renderer_collect_backing_store
gboolean fl_renderer_collect_backing_store(FlRenderer *self, const FlutterBackingStore *backing_store)
Definition: fl_renderer.cc:192
fl_pixel_buffer_texture_populate
gboolean fl_pixel_buffer_texture_populate(FlPixelBufferTexture *texture, uint32_t width, uint32_t height, FlutterOpenGLTexture *opengl_texture, GError **error)
Definition: fl_pixel_buffer_texture.cc:71
fl_renderer_present_layers
gboolean fl_renderer_present_layers(FlRenderer *self, const FlutterLayer **layers, size_t layers_count)
Definition: fl_renderer.cc:221
fl_renderer_headless_new
FlRendererHeadless * fl_renderer_headless_new()
Definition: fl_renderer_headless.cc:31
fl_task_runner_post_task
void fl_task_runner_post_task(FlTaskRunner *self, FlutterTask task, uint64_t target_time_nanos)
Definition: fl_task_runner.cc:169
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
kProp0
@ kProp0
Definition: fl_accessible_node.cc:83
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_renderer_create_backing_store
gboolean fl_renderer_create_backing_store(FlRenderer *renderer, const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
Definition: fl_renderer.cc:163
fl_dart_project_get_dart_entrypoint_arguments
G_MODULE_EXPORT gchar ** fl_dart_project_get_dart_entrypoint_arguments(FlDartProject *self)
Definition: fl_dart_project.cc:104
fl_renderer_make_resource_current
void fl_renderer_make_resource_current(FlRenderer *self)
Definition: fl_renderer.cc:146
fl_engine_runs_task_on_current_thread
static bool fl_engine_runs_task_on_current_thread(void *user_data)
Definition: fl_engine.cc:289
fl_texture_gl_populate
gboolean fl_texture_gl_populate(FlTextureGL *self, uint32_t width, uint32_t height, FlutterOpenGLTexture *opengl_texture, GError **error)
Definition: fl_texture_gl.cc:50
fl_engine_get_registrar_for_plugin
static FlPluginRegistrar * fl_engine_get_registrar_for_plugin(FlPluginRegistry *registry, const gchar *name)
Definition: fl_engine.cc:359
result
GAsyncResult * result
Definition: fl_text_input_plugin.cc:106
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
fl_renderer_make_current
void fl_renderer_make_current(FlRenderer *self)
Definition: fl_renderer.cc:141
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
parse_locale
static void parse_locale(const gchar *locale, gchar **language, gchar **territory, gchar **codeset, gchar **modifier)
Definition: fl_engine.cc:87
fl_string_codec_new
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new()
Definition: fl_string_codec.cc:53
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
fl_message_codec_encode_message
G_MODULE_EXPORT GBytes * fl_message_codec_encode_message(FlMessageCodec *self, FlValue *message, GError **error)
Definition: fl_message_codec.cc:17
flutter::AppLifecycleStateToString
constexpr const char * AppLifecycleStateToString(AppLifecycleState state)
Definition: app_lifecycle_state.h:72
fl_plugin_registrar_new
FlPluginRegistrar * fl_plugin_registrar_new(FlView *view, FlBinaryMessenger *messenger, FlTextureRegistrar *texture_registrar)
Definition: fl_plugin_registrar.cc:87
callback
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Definition: fl_key_channel_responder.cc:120
fl_engine_error_quark
GQuark fl_engine_error_quark(void) G_GNUC_CONST
fl_dart_project_get_icu_data_path
const G_MODULE_EXPORT gchar * fl_dart_project_get_icu_data_path(FlDartProject *self)
Definition: fl_dart_project.cc:98
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24
width
const uint8_t uint32_t * width
Definition: fl_pixel_buffer_texture_test.cc:38
fl_engine_gl_make_current
static bool fl_engine_gl_make_current(void *user_data)
Definition: fl_engine.cc:218
fl_engine_get_switches
GPtrArray * fl_engine_get_switches(FlEngine *self)
Definition: fl_engine.cc:927
fl_renderer_get_fbo
guint32 fl_renderer_get_fbo(FlRenderer *self)
Definition: fl_renderer.cc:156
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
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
fl_task_runner_new
FlTaskRunner * fl_task_runner_new(FlEngine *engine)
Definition: fl_task_runner.cc:161
fl_engine_send_platform_message_response
gboolean fl_engine_send_platform_message_response(FlEngine *self, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
Definition: fl_engine.cc:636
fl_binary_messenger_send_on_channel
G_MODULE_EXPORT void fl_binary_messenger_send_on_channel(FlBinaryMessenger *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_binary_messenger.cc:451
fl_settings_plugin_new
FlSettingsPlugin * fl_settings_plugin_new(FlEngine *engine)
Definition: fl_settings_plugin.cc:94
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
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
kFlutterLifecycleChannel
static constexpr const char * kFlutterLifecycleChannel
Definition: fl_engine.cc:38
fl_engine_gl_clear_current
static bool fl_engine_gl_clear_current(void *user_data)
Definition: fl_engine.cc:224