| Flutter Linux Embedder |

fl_engine.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"
6
7 #include <gmodule.h>
8
9 #include <cstring>
10
11 #include "flutter/shell/platform/common/engine_switches.h"
12 #include "flutter/shell/platform/embedder/embedder.h"
13 #include "flutter/shell/platform/linux/fl_binary_messenger_private.h"
14 #include "flutter/shell/platform/linux/fl_dart_project_private.h"
15 #include "flutter/shell/platform/linux/fl_display_monitor.h"
16 #include "flutter/shell/platform/linux/fl_engine_private.h"
17 #include "flutter/shell/platform/linux/fl_pixel_buffer_texture_private.h"
18 #include "flutter/shell/platform/linux/fl_platform_handler.h"
19 #include "flutter/shell/platform/linux/fl_plugin_registrar_private.h"
20 #include "flutter/shell/platform/linux/fl_renderer.h"
21 #include "flutter/shell/platform/linux/fl_renderer_gdk.h"
22 #include "flutter/shell/platform/linux/fl_renderer_headless.h"
23 #include "flutter/shell/platform/linux/fl_settings_handler.h"
24 #include "flutter/shell/platform/linux/fl_texture_gl_private.h"
25 #include "flutter/shell/platform/linux/fl_texture_registrar_private.h"
26 #include "flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registry.h"
27
28 // Unique number associated with platform tasks.
29 static constexpr size_t kPlatformTaskRunnerIdentifier = 1;
30
31 // Use different device ID for mouse and pan/zoom events, since we can't
32 // differentiate the actual device (mouse v.s. trackpad)
33 static constexpr int32_t kMousePointerDeviceId = 0;
34 static constexpr int32_t kPointerPanZoomDeviceId = 1;
35
36 struct _FlEngine {
37 GObject parent_instance;
38
39 // Thread the GLib main loop is running on.
40 GThread* thread;
41
42 // The project this engine is running.
43 FlDartProject* project;
44
45 // Watches for monitors changes to update engine.
46 FlDisplayMonitor* display_monitor;
47
48 // Renders the Flutter app.
49 FlRenderer* renderer;
50
51 // Messenger used to send and receive platform messages.
52 FlBinaryMessenger* binary_messenger;
53
54 // Implements the flutter/settings channel.
55 FlSettingsHandler* settings_handler;
56
57 // Implements the flutter/platform channel.
58 FlPlatformHandler* platform_handler;
59
60 // Implements the flutter/mousecursor channel.
61 FlMouseCursorHandler* mouse_cursor_handler;
62
63 // Manages textures rendered by native code.
64 FlTextureRegistrar* texture_registrar;
65
66 // Schedules tasks to be run on the appropriate thread.
67 FlTaskRunner* task_runner;
68
69 // Ahead of time data used to make engine run faster.
70 FlutterEngineAOTData aot_data;
71
72 // The Flutter engine.
73 FLUTTER_API_SYMBOL(FlutterEngine) engine;
74
75 // Function table for engine API, used to intercept engine calls for testing
76 // purposes.
77 FlutterEngineProcTable embedder_api;
78
79 // Next ID to use for a view.
80 FlutterViewId next_view_id;
81
82 // Function to call when a platform message is received.
83 FlEnginePlatformMessageHandler platform_message_handler;
84 gpointer platform_message_handler_data;
85 GDestroyNotify platform_message_handler_destroy_notify;
86
87 // Function to call when a semantic node is received.
88 FlEngineUpdateSemanticsHandler update_semantics_handler;
89 gpointer update_semantics_handler_data;
90 GDestroyNotify update_semantics_handler_destroy_notify;
91 };
92
93 G_DEFINE_QUARK(fl_engine_error_quark, fl_engine_error)
94
95 static void fl_engine_plugin_registry_iface_init(
96 FlPluginRegistryInterface* iface);
97
98 enum { SIGNAL_ON_PRE_ENGINE_RESTART, LAST_SIGNAL };
99
100 static guint fl_engine_signals[LAST_SIGNAL];
101
102 G_DEFINE_TYPE_WITH_CODE(
103 FlEngine,
104 fl_engine,
105 G_TYPE_OBJECT,
106 G_IMPLEMENT_INTERFACE(fl_plugin_registry_get_type(),
107 fl_engine_plugin_registry_iface_init))
108
109 enum { PROP_0, PROP_BINARY_MESSENGER, PROP_LAST };
110
111 // Parse a locale into its components.
112 static void parse_locale(const gchar* locale,
113 gchar** language,
114 gchar** territory,
115 gchar** codeset,
116 gchar** modifier) {
117 gchar* l = g_strdup(locale);
118
119 // Locales are in the form "language[_territory][.codeset][@modifier]"
120 gchar* match = strrchr(l, '@');
121 if (match != nullptr) {
122 if (modifier != nullptr) {
123 *modifier = g_strdup(match + 1);
124 }
125 *match = '\0';
126 } else if (modifier != nullptr) {
127 *modifier = nullptr;
128 }
129
130 match = strrchr(l, '.');
131 if (match != nullptr) {
132 if (codeset != nullptr) {
133 *codeset = g_strdup(match + 1);
134 }
135 *match = '\0';
136 } else if (codeset != nullptr) {
137 *codeset = nullptr;
138 }
139
140 match = strrchr(l, '_');
141 if (match != nullptr) {
142 if (territory != nullptr) {
143 *territory = g_strdup(match + 1);
144 }
145 *match = '\0';
146 } else if (territory != nullptr) {
147 *territory = nullptr;
148 }
149
150 if (language != nullptr) {
151 *language = l;
152 }
153 }
154
155 static void view_added_cb(const FlutterAddViewResult* result) {
156 g_autoptr(GTask) task = G_TASK(result->user_data);
157
158 if (result->added) {
159 g_task_return_boolean(task, TRUE);
160 } else {
161 g_task_return_new_error(task, fl_engine_error_quark(),
162 FL_ENGINE_ERROR_FAILED, "Failed to add view");
163 }
164 }
165
166 static void view_removed_cb(const FlutterRemoveViewResult* result) {
167 g_autoptr(GTask) task = G_TASK(result->user_data);
168
169 if (result->removed) {
170 g_task_return_boolean(task, TRUE);
171 } else {
172 g_task_return_new_error(task, fl_engine_error_quark(),
173 FL_ENGINE_ERROR_FAILED, "Failed to remove view");
174 }
175 }
176
177 static void free_locale(FlutterLocale* locale) {
178 free(const_cast<gchar*>(locale->language_code));
179 free(const_cast<gchar*>(locale->country_code));
180 free(locale);
181 }
182
183 // Passes locale information to the Flutter engine.
184 static void setup_locales(FlEngine* self) {
185 const gchar* const* languages = g_get_language_names();
186 g_autoptr(GPtrArray) locales_array = g_ptr_array_new_with_free_func(
187 reinterpret_cast<GDestroyNotify>(free_locale));
188 for (int i = 0; languages[i] != nullptr; i++) {
189 g_autofree gchar* locale_string = g_strstrip(g_strdup(languages[i]));
190
191 // Ignore empty locales, caused by settings like `LANGUAGE=pt_BR:`
192 if (strcmp(locale_string, "") == 0) {
193 continue;
194 }
195
196 g_autofree gchar* language = nullptr;
197 g_autofree gchar* territory = nullptr;
198 parse_locale(locale_string, &language, &territory, nullptr, nullptr);
199
200 // Ignore duplicate locales, caused by settings like `LANGUAGE=C` (returns
201 // two "C") or `LANGUAGE=en:en`
202 gboolean has_locale = FALSE;
203 for (guint j = 0; !has_locale && j < locales_array->len; j++) {
204 FlutterLocale* locale =
205 reinterpret_cast<FlutterLocale*>(g_ptr_array_index(locales_array, j));
206 has_locale = g_strcmp0(locale->language_code, language) == 0 &&
207 g_strcmp0(locale->country_code, territory) == 0;
208 }
209 if (has_locale) {
210 continue;
211 }
212
213 FlutterLocale* locale =
214 static_cast<FlutterLocale*>(g_malloc0(sizeof(FlutterLocale)));
215 g_ptr_array_add(locales_array, locale);
216 locale->struct_size = sizeof(FlutterLocale);
217 locale->language_code =
218 reinterpret_cast<const gchar*>(g_steal_pointer(&language));
219 locale->country_code =
220 reinterpret_cast<const gchar*>(g_steal_pointer(&territory));
221 locale->script_code = nullptr;
222 locale->variant_code = nullptr;
223 }
224 FlutterLocale** locales =
225 reinterpret_cast<FlutterLocale**>(locales_array->pdata);
226 FlutterEngineResult result = self->embedder_api.UpdateLocales(
227 self->engine, const_cast<const FlutterLocale**>(locales),
228 locales_array->len);
229 if (result != kSuccess) {
230 g_warning("Failed to set up Flutter locales");
231 }
232 }
233
234 // Called when engine needs a backing store for a specific #FlutterLayer.
235 static bool compositor_create_backing_store_callback(
236 const FlutterBackingStoreConfig* config,
237 FlutterBackingStore* backing_store_out,
238 void* user_data) {
239 g_return_val_if_fail(FL_IS_RENDERER(user_data), false);
240 return fl_renderer_create_backing_store(FL_RENDERER(user_data), config,
241 backing_store_out);
242 }
243
244 // Called when the backing store is to be released.
245 static bool compositor_collect_backing_store_callback(
246 const FlutterBackingStore* backing_store,
247 void* user_data) {
248 g_return_val_if_fail(FL_IS_RENDERER(user_data), false);
249 return fl_renderer_collect_backing_store(FL_RENDERER(user_data),
250 backing_store);
251 }
252
253 // Called when embedder should composite contents of each layer onto the screen.
254 static bool compositor_present_view_callback(
255 const FlutterPresentViewInfo* info) {
256 g_return_val_if_fail(FL_IS_RENDERER(info->user_data), false);
257 return fl_renderer_present_layers(FL_RENDERER(info->user_data), info->view_id,
258 info->layers, info->layers_count);
259 }
260
261 // Flutter engine rendering callbacks.
262
263 static void* fl_engine_gl_proc_resolver(void* user_data, const char* name) {
264 FlEngine* self = static_cast<FlEngine*>(user_data);
265 return fl_renderer_get_proc_address(self->renderer, name);
266 }
267
268 static bool fl_engine_gl_make_current(void* user_data) {
269 FlEngine* self = static_cast<FlEngine*>(user_data);
270 fl_renderer_make_current(self->renderer);
271 return true;
272 }
273
274 static bool fl_engine_gl_clear_current(void* user_data) {
275 FlEngine* self = static_cast<FlEngine*>(user_data);
276 fl_renderer_clear_current(self->renderer);
277 return true;
278 }
279
280 static uint32_t fl_engine_gl_get_fbo(void* user_data) {
281 FlEngine* self = static_cast<FlEngine*>(user_data);
282 return fl_renderer_get_fbo(self->renderer);
283 }
284
285 static bool fl_engine_gl_present(void* user_data) {
286 // No action required, as this is handled in
287 // compositor_present_view_callback.
288 return true;
289 }
290
291 static bool fl_engine_gl_make_resource_current(void* user_data) {
292 FlEngine* self = static_cast<FlEngine*>(user_data);
293 fl_renderer_make_resource_current(self->renderer);
294 return true;
295 }
296
297 // Called by the engine to retrieve an external texture.
298 static bool fl_engine_gl_external_texture_frame_callback(
299 void* user_data,
300 int64_t texture_id,
301 size_t width,
302 size_t height,
303 FlutterOpenGLTexture* opengl_texture) {
304 FlEngine* self = static_cast<FlEngine*>(user_data);
305 if (!self->texture_registrar) {
306 return false;
307 }
308
309 FlTexture* texture =
310 fl_texture_registrar_lookup_texture(self->texture_registrar, texture_id);
311 if (texture == nullptr) {
312 g_warning("Unable to find texture %" G_GINT64_FORMAT, texture_id);
313 return false;
314 }
315
316 gboolean result;
317 g_autoptr(GError) error = nullptr;
318 if (FL_IS_TEXTURE_GL(texture)) {
319 result = fl_texture_gl_populate(FL_TEXTURE_GL(texture), width, height,
320 opengl_texture, &error);
321 } else if (FL_IS_PIXEL_BUFFER_TEXTURE(texture)) {
322 result =
323 fl_pixel_buffer_texture_populate(FL_PIXEL_BUFFER_TEXTURE(texture),
324 width, height, opengl_texture, &error);
325 } else {
326 g_warning("Unsupported texture type %" G_GINT64_FORMAT, texture_id);
327 return false;
328 }
329
330 if (!result) {
331 g_warning("%s", error->message);
332 return false;
333 }
334
335 return true;
336 }
337
338 // Called by the engine to determine if it is on the GTK thread.
339 static bool fl_engine_runs_task_on_current_thread(void* user_data) {
340 FlEngine* self = static_cast<FlEngine*>(user_data);
341 return self->thread == g_thread_self();
342 }
343
344 // Called when the engine has a task to perform in the GTK thread.
345 static void fl_engine_post_task(FlutterTask task,
346 uint64_t target_time_nanos,
347 void* user_data) {
348 FlEngine* self = static_cast<FlEngine*>(user_data);
349
350 fl_task_runner_post_task(self->task_runner, task, target_time_nanos);
351 }
352
353 // Called when a platform message is received from the engine.
354 static void fl_engine_platform_message_cb(const FlutterPlatformMessage* message,
355 void* user_data) {
356 FlEngine* self = FL_ENGINE(user_data);
357
358 gboolean handled = FALSE;
359 if (self->platform_message_handler != nullptr) {
360 g_autoptr(GBytes) data =
361 g_bytes_new(message->message, message->message_size);
362 handled = self->platform_message_handler(
363 self, message->channel, data, message->response_handle,
364 self->platform_message_handler_data);
365 }
366
367 if (!handled) {
368 fl_engine_send_platform_message_response(self, message->response_handle,
369 nullptr, nullptr);
370 }
371 }
372
373 // Called when a semantic node update is received from the engine.
374 static void fl_engine_update_semantics_cb(const FlutterSemanticsUpdate2* update,
375 void* user_data) {
376 FlEngine* self = FL_ENGINE(user_data);
377
378 if (self->update_semantics_handler != nullptr) {
379 self->update_semantics_handler(self, update,
380 self->update_semantics_handler_data);
381 }
382 }
383
384 // Called right before the engine is restarted.
385 //
386 // This method should reset states to as if the engine has just been started,
387 // which usually indicates the user has requested a hot restart (Shift-R in the
388 // Flutter CLI.)
389 static void fl_engine_on_pre_engine_restart_cb(void* user_data) {
390 FlEngine* self = FL_ENGINE(user_data);
391
392 g_signal_emit(self, fl_engine_signals[SIGNAL_ON_PRE_ENGINE_RESTART], 0);
393 }
394
395 // Called when a response to a sent platform message is received from the
396 // engine.
397 static void fl_engine_platform_message_response_cb(const uint8_t* data,
398 size_t data_length,
399 void* user_data) {
400 g_autoptr(GTask) task = G_TASK(user_data);
401 g_task_return_pointer(task, g_bytes_new(data, data_length),
402 reinterpret_cast<GDestroyNotify>(g_bytes_unref));
403 }
404
405 // Implements FlPluginRegistry::get_registrar_for_plugin.
406 static FlPluginRegistrar* fl_engine_get_registrar_for_plugin(
407 FlPluginRegistry* registry,
408 const gchar* name) {
409 FlEngine* self = FL_ENGINE(registry);
410
411 return fl_plugin_registrar_new(nullptr, self->binary_messenger,
412 self->texture_registrar);
413 }
414
415 static void fl_engine_plugin_registry_iface_init(
416 FlPluginRegistryInterface* iface) {
417 iface->get_registrar_for_plugin = fl_engine_get_registrar_for_plugin;
418 }
419
420 static void fl_engine_set_property(GObject* object,
421 guint prop_id,
422 const GValue* value,
423 GParamSpec* pspec) {
424 FlEngine* self = FL_ENGINE(object);
425 switch (prop_id) {
426 case PROP_BINARY_MESSENGER:
427 g_set_object(&self->binary_messenger,
428 FL_BINARY_MESSENGER(g_value_get_object(value)));
429 break;
430 default:
431 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
432 break;
433 }
434 }
435
436 static void fl_engine_dispose(GObject* object) {
437 FlEngine* self = FL_ENGINE(object);
438
439 if (self->engine != nullptr) {
440 self->embedder_api.Shutdown(self->engine);
441 self->engine = nullptr;
442 }
443
444 if (self->aot_data != nullptr) {
445 self->embedder_api.CollectAOTData(self->aot_data);
446 self->aot_data = nullptr;
447 }
448
449 fl_binary_messenger_shutdown(self->binary_messenger);
450 fl_texture_registrar_shutdown(self->texture_registrar);
451
452 g_clear_object(&self->project);
453 g_clear_object(&self->renderer);
454 g_clear_object(&self->texture_registrar);
455 g_clear_object(&self->binary_messenger);
456 g_clear_object(&self->settings_handler);
457 g_clear_object(&self->platform_handler);
458 g_clear_object(&self->mouse_cursor_handler);
459 g_clear_object(&self->task_runner);
460
461 if (self->platform_message_handler_destroy_notify) {
462 self->platform_message_handler_destroy_notify(
463 self->platform_message_handler_data);
464 }
465 self->platform_message_handler_data = nullptr;
466 self->platform_message_handler_destroy_notify = nullptr;
467
468 if (self->update_semantics_handler_destroy_notify) {
469 self->update_semantics_handler_destroy_notify(
470 self->update_semantics_handler_data);
471 }
472 self->update_semantics_handler_data = nullptr;
473 self->update_semantics_handler_destroy_notify = nullptr;
474
475 G_OBJECT_CLASS(fl_engine_parent_class)->dispose(object);
476 }
477
478 static void fl_engine_class_init(FlEngineClass* klass) {
479 G_OBJECT_CLASS(klass)->dispose = fl_engine_dispose;
480 G_OBJECT_CLASS(klass)->set_property = fl_engine_set_property;
481
482 g_object_class_install_property(
483 G_OBJECT_CLASS(klass), PROP_BINARY_MESSENGER,
484 g_param_spec_object(
485 "binary-messenger", "messenger", "Binary messenger",
486 fl_binary_messenger_get_type(),
487 static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
488 G_PARAM_STATIC_STRINGS)));
489
490 fl_engine_signals[SIGNAL_ON_PRE_ENGINE_RESTART] = g_signal_new(
491 "on-pre-engine-restart", fl_engine_get_type(), G_SIGNAL_RUN_LAST, 0,
492 nullptr, nullptr, nullptr, G_TYPE_NONE, 0);
493 }
494
495 static void fl_engine_init(FlEngine* self) {
496 self->thread = g_thread_self();
497
498 self->embedder_api.struct_size = sizeof(FlutterEngineProcTable);
499 if (FlutterEngineGetProcAddresses(&self->embedder_api) != kSuccess) {
500 g_warning("Failed get get engine function pointers");
501 }
502
503 // Implicit view is 0, so start at 1.
504 self->next_view_id = 1;
505
506 self->texture_registrar = fl_texture_registrar_new(self);
507 }
508
509 FlEngine* fl_engine_new_with_renderer(FlDartProject* project,
510 FlRenderer* renderer) {
511 g_return_val_if_fail(FL_IS_DART_PROJECT(project), nullptr);
512 g_return_val_if_fail(FL_IS_RENDERER(renderer), nullptr);
513
514 FlEngine* self = FL_ENGINE(g_object_new(fl_engine_get_type(), nullptr));
515 self->project = FL_DART_PROJECT(g_object_ref(project));
516 self->renderer = FL_RENDERER(g_object_ref(renderer));
517 self->binary_messenger = fl_binary_messenger_new(self);
518
519 fl_renderer_set_engine(self->renderer, self);
520
521 return self;
522 }
523
524 G_MODULE_EXPORT FlEngine* fl_engine_new(FlDartProject* project) {
525 g_autoptr(FlRendererGdk) renderer = fl_renderer_gdk_new();
526 return fl_engine_new_with_renderer(project, FL_RENDERER(renderer));
527 }
528
529 G_MODULE_EXPORT FlEngine* fl_engine_new_headless(FlDartProject* project) {
530 g_autoptr(FlRendererHeadless) renderer = fl_renderer_headless_new();
531 return fl_engine_new_with_renderer(project, FL_RENDERER(renderer));
532 }
533
534 FlRenderer* fl_engine_get_renderer(FlEngine* self) {
535 g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
536 return self->renderer;
537 }
538
539 FlDisplayMonitor* fl_engine_get_display_monitor(FlEngine* self) {
540 g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
541 return self->display_monitor;
542 }
543
544 gboolean fl_engine_start(FlEngine* self, GError** error) {
545 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
546
547 self->task_runner = fl_task_runner_new(self);
548
549 FlutterRendererConfig config = {};
550 config.type = kOpenGL;
551 config.open_gl.struct_size = sizeof(FlutterOpenGLRendererConfig);
552 config.open_gl.gl_proc_resolver = fl_engine_gl_proc_resolver;
553 config.open_gl.make_current = fl_engine_gl_make_current;
554 config.open_gl.clear_current = fl_engine_gl_clear_current;
555 config.open_gl.fbo_callback = fl_engine_gl_get_fbo;
556 config.open_gl.present = fl_engine_gl_present;
557 config.open_gl.make_resource_current = fl_engine_gl_make_resource_current;
558 config.open_gl.gl_external_texture_frame_callback =
559 fl_engine_gl_external_texture_frame_callback;
560
561 FlutterTaskRunnerDescription platform_task_runner = {};
562 platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription);
563 platform_task_runner.user_data = self;
564 platform_task_runner.runs_task_on_current_thread_callback =
565 fl_engine_runs_task_on_current_thread;
566 platform_task_runner.post_task_callback = fl_engine_post_task;
567 platform_task_runner.identifier = kPlatformTaskRunnerIdentifier;
568
569 FlutterCustomTaskRunners custom_task_runners = {};
570 custom_task_runners.struct_size = sizeof(FlutterCustomTaskRunners);
571 custom_task_runners.platform_task_runner = &platform_task_runner;
572 custom_task_runners.render_task_runner = &platform_task_runner;
573
574 g_autoptr(GPtrArray) command_line_args =
575 g_ptr_array_new_with_free_func(g_free);
576 g_ptr_array_insert(command_line_args, 0, g_strdup("flutter"));
577 for (const auto& env_switch : flutter::GetSwitchesFromEnvironment()) {
578 g_ptr_array_add(command_line_args, g_strdup(env_switch.c_str()));
579 }
580
581 gchar** dart_entrypoint_args =
582 fl_dart_project_get_dart_entrypoint_arguments(self->project);
583
584 FlutterProjectArgs args = {};
585 args.struct_size = sizeof(FlutterProjectArgs);
586 args.assets_path = fl_dart_project_get_assets_path(self->project);
587 args.icu_data_path = fl_dart_project_get_icu_data_path(self->project);
588 args.command_line_argc = command_line_args->len;
589 args.command_line_argv =
590 reinterpret_cast<const char* const*>(command_line_args->pdata);
591 args.platform_message_callback = fl_engine_platform_message_cb;
592 args.update_semantics_callback2 = fl_engine_update_semantics_cb;
593 args.custom_task_runners = &custom_task_runners;
594 args.shutdown_dart_vm_when_done = true;
595 args.on_pre_engine_restart_callback = fl_engine_on_pre_engine_restart_cb;
596 args.dart_entrypoint_argc =
597 dart_entrypoint_args != nullptr ? g_strv_length(dart_entrypoint_args) : 0;
598 args.dart_entrypoint_argv =
599 reinterpret_cast<const char* const*>(dart_entrypoint_args);
600
601 FlutterCompositor compositor = {};
602 compositor.struct_size = sizeof(FlutterCompositor);
603 compositor.user_data = self->renderer;
604 compositor.create_backing_store_callback =
605 compositor_create_backing_store_callback;
606 compositor.collect_backing_store_callback =
607 compositor_collect_backing_store_callback;
608 compositor.present_view_callback = compositor_present_view_callback;
609 args.compositor = &compositor;
610
611 if (self->embedder_api.RunsAOTCompiledDartCode()) {
612 FlutterEngineAOTDataSource source = {};
613 source.type = kFlutterEngineAOTDataSourceTypeElfPath;
614 source.elf_path = fl_dart_project_get_aot_library_path(self->project);
615 if (self->embedder_api.CreateAOTData(&source, &self->aot_data) !=
616 kSuccess) {
617 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
618 "Failed to create AOT data");
619 return FALSE;
620 }
621 args.aot_data = self->aot_data;
622 }
623
624 FlutterEngineResult result = self->embedder_api.Initialize(
625 FLUTTER_ENGINE_VERSION, &config, &args, self, &self->engine);
626 if (result != kSuccess) {
627 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
628 "Failed to initialize Flutter engine");
629 return FALSE;
630 }
631
632 result = self->embedder_api.RunInitialized(self->engine);
633 if (result != kSuccess) {
634 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
635 "Failed to run Flutter engine");
636 return FALSE;
637 }
638
639 setup_locales(self);
640
641 g_autoptr(FlSettings) settings = fl_settings_new();
642 self->settings_handler = fl_settings_handler_new(self);
643 fl_settings_handler_start(self->settings_handler, settings);
644
645 self->platform_handler = fl_platform_handler_new(self->binary_messenger);
646 self->mouse_cursor_handler =
647 fl_mouse_cursor_handler_new(self->binary_messenger);
648
649 result = self->embedder_api.UpdateSemanticsEnabled(self->engine, TRUE);
650 if (result != kSuccess) {
651 g_warning("Failed to enable accessibility features on Flutter engine");
652 }
653
654 self->display_monitor =
655 fl_display_monitor_new(self, gdk_display_get_default());
656 fl_display_monitor_start(self->display_monitor);
657
658 return TRUE;
659 }
660
661 FlutterEngineProcTable* fl_engine_get_embedder_api(FlEngine* self) {
662 return &(self->embedder_api);
663 }
664
665 void fl_engine_notify_display_update(FlEngine* self,
666 const FlutterEngineDisplay* displays,
667 size_t displays_length) {
668 g_return_if_fail(FL_IS_ENGINE(self));
669
670 FlutterEngineResult result = self->embedder_api.NotifyDisplayUpdate(
671 self->engine, kFlutterEngineDisplaysUpdateTypeStartup, displays,
672 displays_length);
673 if (result != kSuccess) {
674 g_warning("Failed to notify display update to Flutter engine: %d", result);
675 }
676 }
677
678 FlutterViewId fl_engine_add_view(FlEngine* self,
679 size_t width,
680 size_t height,
681 double pixel_ratio,
682 GCancellable* cancellable,
683 GAsyncReadyCallback callback,
684 gpointer user_data) {
685 g_return_val_if_fail(FL_IS_ENGINE(self), -1);
686
687 g_autoptr(GTask) task = g_task_new(self, cancellable, callback, user_data);
688
689 FlutterViewId view_id = self->next_view_id;
690 self->next_view_id++;
691
692 // We don't know which display this view will open on, so set to zero and this
693 // will be updated in a following FlutterWindowMetricsEvent
694 FlutterEngineDisplayId display_id = 0;
695
696 FlutterWindowMetricsEvent metrics;
697 metrics.struct_size = sizeof(FlutterWindowMetricsEvent);
698 metrics.width = width;
699 metrics.height = height;
700 metrics.pixel_ratio = pixel_ratio;
701 metrics.display_id = display_id;
702 metrics.view_id = view_id;
703 FlutterAddViewInfo info;
704 info.struct_size = sizeof(FlutterAddViewInfo);
705 info.view_id = view_id;
706 info.view_metrics = &metrics;
707 info.user_data = g_object_ref(task);
708 info.add_view_callback = view_added_cb;
709 FlutterEngineResult result = self->embedder_api.AddView(self->engine, &info);
710 if (result != kSuccess) {
711 g_task_return_new_error(task, fl_engine_error_quark(),
712 FL_ENGINE_ERROR_FAILED, "AddView returned %d",
713 result);
714 // This would have been done in the callback, but that won't occur now.
715 g_object_unref(task);
716 }
717
718 return view_id;
719 }
720
721 gboolean fl_engine_add_view_finish(FlEngine* self,
722 GAsyncResult* result,
723 GError** error) {
724 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
725 return g_task_propagate_boolean(G_TASK(result), error);
726 }
727
728 void fl_engine_remove_view(FlEngine* self,
729 FlutterViewId view_id,
730 GCancellable* cancellable,
731 GAsyncReadyCallback callback,
732 gpointer user_data) {
733 g_return_if_fail(FL_IS_ENGINE(self));
734
735 g_autoptr(GTask) task = g_task_new(self, cancellable, callback, user_data);
736
737 FlutterRemoveViewInfo info;
738 info.struct_size = sizeof(FlutterRemoveViewInfo);
739 info.view_id = view_id;
740 info.user_data = g_object_ref(task);
741 info.remove_view_callback = view_removed_cb;
742 FlutterEngineResult result =
743 self->embedder_api.RemoveView(self->engine, &info);
744 if (result != kSuccess) {
745 g_task_return_new_error(task, fl_engine_error_quark(),
746 FL_ENGINE_ERROR_FAILED, "RemoveView returned %d",
747 result);
748 // This would have been done in the callback, but that won't occur now.
749 g_object_unref(task);
750 }
751 }
752
753 gboolean fl_engine_remove_view_finish(FlEngine* self,
754 GAsyncResult* result,
755 GError** error) {
756 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
757 return g_task_propagate_boolean(G_TASK(result), error);
758 }
759
760 void fl_engine_set_platform_message_handler(
761 FlEngine* self,
762 FlEnginePlatformMessageHandler handler,
763 gpointer user_data,
764 GDestroyNotify destroy_notify) {
765 g_return_if_fail(FL_IS_ENGINE(self));
766 g_return_if_fail(handler != nullptr);
767
768 if (self->platform_message_handler_destroy_notify) {
769 self->platform_message_handler_destroy_notify(
770 self->platform_message_handler_data);
771 }
772
773 self->platform_message_handler = handler;
774 self->platform_message_handler_data = user_data;
775 self->platform_message_handler_destroy_notify = destroy_notify;
776 }
777
778 void fl_engine_set_update_semantics_handler(
779 FlEngine* self,
780 FlEngineUpdateSemanticsHandler handler,
781 gpointer user_data,
782 GDestroyNotify destroy_notify) {
783 g_return_if_fail(FL_IS_ENGINE(self));
784
785 if (self->update_semantics_handler_destroy_notify) {
786 self->update_semantics_handler_destroy_notify(
787 self->update_semantics_handler_data);
788 }
789
790 self->update_semantics_handler = handler;
791 self->update_semantics_handler_data = user_data;
792 self->update_semantics_handler_destroy_notify = destroy_notify;
793 }
794
795 // Note: This function can be called from any thread.
796 gboolean fl_engine_send_platform_message_response(
797 FlEngine* self,
798 const FlutterPlatformMessageResponseHandle* handle,
799 GBytes* response,
800 GError** error) {
801 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
802 g_return_val_if_fail(handle != nullptr, FALSE);
803
804 if (self->engine == nullptr) {
805 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
806 "No engine to send response to");
807 return FALSE;
808 }
809
810 gsize data_length = 0;
811 const uint8_t* data = nullptr;
812 if (response != nullptr) {
813 data =
814 static_cast<const uint8_t*>(g_bytes_get_data(response, &data_length));
815 }
816 FlutterEngineResult result = self->embedder_api.SendPlatformMessageResponse(
817 self->engine, handle, data, data_length);
818
819 if (result != kSuccess) {
820 g_set_error(error, fl_engine_error_quark(), FL_ENGINE_ERROR_FAILED,
821 "Failed to send platform message response");
822 return FALSE;
823 }
824
825 return TRUE;
826 }
827
828 void fl_engine_send_platform_message(FlEngine* self,
829 const gchar* channel,
830 GBytes* message,
831 GCancellable* cancellable,
832 GAsyncReadyCallback callback,
833 gpointer user_data) {
834 g_return_if_fail(FL_IS_ENGINE(self));
835
836 GTask* task = nullptr;
837 FlutterPlatformMessageResponseHandle* response_handle = nullptr;
838 if (callback != nullptr) {
839 task = g_task_new(self, cancellable, callback, user_data);
840
841 if (self->engine == nullptr) {
842 g_task_return_new_error(task, fl_engine_error_quark(),
843 FL_ENGINE_ERROR_FAILED, "No engine to send to");
844 return;
845 }
846
847 FlutterEngineResult result =
848 self->embedder_api.PlatformMessageCreateResponseHandle(
849 self->engine, fl_engine_platform_message_response_cb, task,
850 &response_handle);
851 if (result != kSuccess) {
852 g_task_return_new_error(task, fl_engine_error_quark(),
853 FL_ENGINE_ERROR_FAILED,
854 "Failed to create response handle");
855 g_object_unref(task);
856 return;
857 }
858 } else if (self->engine == nullptr) {
859 return;
860 }
861
862 FlutterPlatformMessage fl_message = {};
863 fl_message.struct_size = sizeof(fl_message);
864 fl_message.channel = channel;
865 fl_message.message =
866 message != nullptr
867 ? static_cast<const uint8_t*>(g_bytes_get_data(message, nullptr))
868 : nullptr;
869 fl_message.message_size = message != nullptr ? g_bytes_get_size(message) : 0;
870 fl_message.response_handle = response_handle;
871 FlutterEngineResult result =
872 self->embedder_api.SendPlatformMessage(self->engine, &fl_message);
873
874 if (result != kSuccess && task != nullptr) {
875 g_task_return_new_error(task, fl_engine_error_quark(),
876 FL_ENGINE_ERROR_FAILED,
877 "Failed to send platform messages");
878 g_object_unref(task);
879 }
880
881 if (response_handle != nullptr) {
882 self->embedder_api.PlatformMessageReleaseResponseHandle(self->engine,
883 response_handle);
884 }
885 }
886
887 GBytes* fl_engine_send_platform_message_finish(FlEngine* self,
888 GAsyncResult* result,
889 GError** error) {
890 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
891 g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
892
893 return static_cast<GBytes*>(g_task_propagate_pointer(G_TASK(result), error));
894 }
895
896 void fl_engine_send_window_metrics_event(FlEngine* self,
897 FlutterEngineDisplayId display_id,
898 FlutterViewId view_id,
899 size_t width,
900 size_t height,
901 double pixel_ratio) {
902 g_return_if_fail(FL_IS_ENGINE(self));
903
904 if (self->engine == nullptr) {
905 return;
906 }
907
908 FlutterWindowMetricsEvent event = {};
909 event.struct_size = sizeof(FlutterWindowMetricsEvent);
910 event.width = width;
911 event.height = height;
912 event.pixel_ratio = pixel_ratio;
913 event.display_id = display_id;
914 event.view_id = view_id;
915 self->embedder_api.SendWindowMetricsEvent(self->engine, &event);
916 }
917
918 void fl_engine_send_mouse_pointer_event(FlEngine* self,
919 FlutterViewId view_id,
920 FlutterPointerPhase phase,
921 size_t timestamp,
922 double x,
923 double y,
924 FlutterPointerDeviceKind device_kind,
925 double scroll_delta_x,
926 double scroll_delta_y,
927 int64_t buttons) {
928 g_return_if_fail(FL_IS_ENGINE(self));
929
930 if (self->engine == nullptr) {
931 return;
932 }
933
934 FlutterPointerEvent fl_event = {};
935 fl_event.struct_size = sizeof(fl_event);
936 fl_event.phase = phase;
937 fl_event.timestamp = timestamp;
938 fl_event.x = x;
939 fl_event.y = y;
940 if (scroll_delta_x != 0 || scroll_delta_y != 0) {
941 fl_event.signal_kind = kFlutterPointerSignalKindScroll;
942 }
943 fl_event.scroll_delta_x = scroll_delta_x;
944 fl_event.scroll_delta_y = scroll_delta_y;
945 fl_event.device_kind = device_kind;
946 fl_event.buttons = buttons;
947 fl_event.device = kMousePointerDeviceId;
948 fl_event.view_id = view_id;
949 self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);
950 }
951
952 void fl_engine_send_touch_up_event(FlEngine* self,
953 FlutterViewId view_id,
954 size_t timestamp,
955 double x,
956 double y,
957 int32_t device) {
958 g_return_if_fail(FL_IS_ENGINE(self));
959
960 if (self->engine == nullptr) {
961 return;
962 }
963
964 FlutterPointerEvent event;
965 event.timestamp = timestamp;
966 event.x = x;
967 event.y = y;
968 event.device_kind = kFlutterPointerDeviceKindTouch;
969 event.device = device;
970 event.buttons = 0;
971 event.view_id = view_id;
972 event.phase = FlutterPointerPhase::kUp;
973 event.struct_size = sizeof(event);
974
975 self->embedder_api.SendPointerEvent(self->engine, &event, 1);
976 }
977
978 void fl_engine_send_touch_down_event(FlEngine* self,
979 FlutterViewId view_id,
980 size_t timestamp,
981 double x,
982 double y,
983 int32_t device) {
984 g_return_if_fail(FL_IS_ENGINE(self));
985
986 if (self->engine == nullptr) {
987 return;
988 }
989
990 FlutterPointerEvent event;
991 event.timestamp = timestamp;
992 event.x = x;
993 event.y = y;
994 event.device_kind = kFlutterPointerDeviceKindTouch;
995 event.device = device;
996 event.buttons = FlutterPointerMouseButtons::kFlutterPointerButtonMousePrimary;
997 event.view_id = view_id;
998 event.phase = FlutterPointerPhase::kDown;
999 event.struct_size = sizeof(event);
1000
1001 self->embedder_api.SendPointerEvent(self->engine, &event, 1);
1002 }
1003
1004 void fl_engine_send_touch_move_event(FlEngine* self,
1005 FlutterViewId view_id,
1006 size_t timestamp,
1007 double x,
1008 double y,
1009 int32_t device) {
1010 g_return_if_fail(FL_IS_ENGINE(self));
1011
1012 if (self->engine == nullptr) {
1013 return;
1014 }
1015
1016 FlutterPointerEvent event;
1017 event.timestamp = timestamp;
1018 event.x = x;
1019 event.y = y;
1020 event.device_kind = kFlutterPointerDeviceKindTouch;
1021 event.device = device;
1022 event.buttons = FlutterPointerMouseButtons::kFlutterPointerButtonMousePrimary;
1023 event.view_id = view_id;
1024 event.phase = FlutterPointerPhase::kMove;
1025 event.struct_size = sizeof(event);
1026
1027 self->embedder_api.SendPointerEvent(self->engine, &event, 1);
1028 }
1029
1030 void fl_engine_send_touch_add_event(FlEngine* self,
1031 FlutterViewId view_id,
1032 size_t timestamp,
1033 double x,
1034 double y,
1035 int32_t device) {
1036 g_return_if_fail(FL_IS_ENGINE(self));
1037
1038 if (self->engine == nullptr) {
1039 return;
1040 }
1041
1042 FlutterPointerEvent event;
1043 event.timestamp = timestamp;
1044 event.x = x;
1045 event.y = y;
1046 event.device_kind = kFlutterPointerDeviceKindTouch;
1047 event.device = device;
1048 event.buttons = 0;
1049 event.view_id = view_id;
1050 event.phase = FlutterPointerPhase::kAdd;
1051 event.struct_size = sizeof(event);
1052
1053 self->embedder_api.SendPointerEvent(self->engine, &event, 1);
1054 }
1055
1056 void fl_engine_send_touch_remove_event(FlEngine* self,
1057 FlutterViewId view_id,
1058 size_t timestamp,
1059 double x,
1060 double y,
1061 int32_t device) {
1062 g_return_if_fail(FL_IS_ENGINE(self));
1063
1064 if (self->engine == nullptr) {
1065 return;
1066 }
1067
1068 FlutterPointerEvent event;
1069 event.timestamp = timestamp;
1070 event.x = x;
1071 event.y = y;
1072 event.device_kind = kFlutterPointerDeviceKindTouch;
1073 event.device = device;
1074 event.buttons = 0;
1075 event.view_id = view_id;
1076 event.phase = FlutterPointerPhase::kRemove;
1077 event.struct_size = sizeof(event);
1078
1079 self->embedder_api.SendPointerEvent(self->engine, &event, 1);
1080 }
1081
1082 void fl_engine_send_pointer_pan_zoom_event(FlEngine* self,
1083 FlutterViewId view_id,
1084 size_t timestamp,
1085 double x,
1086 double y,
1087 FlutterPointerPhase phase,
1088 double pan_x,
1089 double pan_y,
1090 double scale,
1091 double rotation) {
1092 g_return_if_fail(FL_IS_ENGINE(self));
1093
1094 if (self->engine == nullptr) {
1095 return;
1096 }
1097
1098 FlutterPointerEvent fl_event = {};
1099 fl_event.struct_size = sizeof(fl_event);
1100 fl_event.timestamp = timestamp;
1101 fl_event.x = x;
1102 fl_event.y = y;
1103 fl_event.phase = phase;
1104 fl_event.pan_x = pan_x;
1105 fl_event.pan_y = pan_y;
1106 fl_event.scale = scale;
1107 fl_event.rotation = rotation;
1108 fl_event.device = kPointerPanZoomDeviceId;
1109 fl_event.device_kind = kFlutterPointerDeviceKindTrackpad;
1110 fl_event.view_id = view_id;
1111 self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);
1112 }
1113
1114 static void send_key_event_cb(bool handled, void* user_data) {
1115 g_autoptr(GTask) task = G_TASK(user_data);
1116 gboolean* return_value = g_new0(gboolean, 1);
1117 *return_value = handled;
1118 g_task_return_pointer(task, return_value, g_free);
1119 }
1120
1121 void fl_engine_send_key_event(FlEngine* self,
1122 const FlutterKeyEvent* event,
1123 GCancellable* cancellable,
1124 GAsyncReadyCallback callback,
1125 gpointer user_data) {
1126 g_return_if_fail(FL_IS_ENGINE(self));
1127
1128 g_autoptr(GTask) task = g_task_new(self, cancellable, callback, user_data);
1129
1130 if (self->engine == nullptr) {
1131 g_task_return_new_error(task, fl_engine_error_quark(),
1132 FL_ENGINE_ERROR_FAILED, "No engine");
1133 return;
1134 }
1135
1136 if (self->embedder_api.SendKeyEvent(self->engine, event, send_key_event_cb,
1137 g_object_ref(task)) != kSuccess) {
1138 g_task_return_new_error(task, fl_engine_error_quark(),
1139 FL_ENGINE_ERROR_FAILED, "Failed to send key event");
1140 g_object_unref(task);
1141 }
1142 }
1143
1144 gboolean fl_engine_send_key_event_finish(FlEngine* self,
1145 GAsyncResult* result,
1146 gboolean* handled,
1147 GError** error) {
1148 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1149 g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
1150
1151 g_autofree gboolean* return_value =
1152 static_cast<gboolean*>(g_task_propagate_pointer(G_TASK(result), error));
1153 if (return_value == nullptr) {
1154 return FALSE;
1155 }
1156
1157 *handled = *return_value;
1158 return TRUE;
1159 }
1160
1161 void fl_engine_dispatch_semantics_action(FlEngine* self,
1162 uint64_t id,
1163 FlutterSemanticsAction action,
1164 GBytes* data) {
1165 g_return_if_fail(FL_IS_ENGINE(self));
1166
1167 if (self->engine == nullptr) {
1168 return;
1169 }
1170
1171 const uint8_t* action_data = nullptr;
1172 size_t action_data_length = 0;
1173 if (data != nullptr) {
1174 action_data = static_cast<const uint8_t*>(
1175 g_bytes_get_data(data, &action_data_length));
1176 }
1177
1178 self->embedder_api.DispatchSemanticsAction(self->engine, id, action,
1179 action_data, action_data_length);
1180 }
1181
1182 gboolean fl_engine_mark_texture_frame_available(FlEngine* self,
1183 int64_t texture_id) {
1184 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1185 return self->embedder_api.MarkExternalTextureFrameAvailable(
1186 self->engine, texture_id) == kSuccess;
1187 }
1188
1189 gboolean fl_engine_register_external_texture(FlEngine* self,
1190 int64_t texture_id) {
1191 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1192 return self->embedder_api.RegisterExternalTexture(self->engine, texture_id) ==
1193 kSuccess;
1194 }
1195
1196 gboolean fl_engine_unregister_external_texture(FlEngine* self,
1197 int64_t texture_id) {
1198 g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
1199 return self->embedder_api.UnregisterExternalTexture(self->engine,
1200 texture_id) == kSuccess;
1201 }
1202
1203 G_MODULE_EXPORT FlBinaryMessenger* fl_engine_get_binary_messenger(
1204 FlEngine* self) {
1205 g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1206 return self->binary_messenger;
1207 }
1208
1209 FlTaskRunner* fl_engine_get_task_runner(FlEngine* self) {
1210 g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1211 return self->task_runner;
1212 }
1213
1214 void fl_engine_execute_task(FlEngine* self, FlutterTask* task) {
1215 g_return_if_fail(FL_IS_ENGINE(self));
1216 self->embedder_api.RunTask(self->engine, task);
1217 }
1218
1219 G_MODULE_EXPORT FlTextureRegistrar* fl_engine_get_texture_registrar(
1220 FlEngine* self) {
1221 g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1222 return self->texture_registrar;
1223 }
1224
1225 void fl_engine_update_accessibility_features(FlEngine* self, int32_t flags) {
1226 g_return_if_fail(FL_IS_ENGINE(self));
1227
1228 if (self->engine == nullptr) {
1229 return;
1230 }
1231
1232 self->embedder_api.UpdateAccessibilityFeatures(
1233 self->engine, static_cast<FlutterAccessibilityFeature>(flags));
1234 }
1235
1236 void fl_engine_request_app_exit(FlEngine* self) {
1237 g_return_if_fail(FL_IS_ENGINE(self));
1238 fl_platform_handler_request_app_exit(self->platform_handler);
1239 }
1240
1241 FlMouseCursorHandler* fl_engine_get_mouse_cursor_handler(FlEngine* self) {
1242 g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1243 return self->mouse_cursor_handler;
1244 }
_FlEngine::platform_message_handler_data
gpointer platform_message_handler_data
Definition: fl_engine.cc:84
fl_engine_set_platform_message_handler
void fl_engine_set_platform_message_handler(FlEngine *self, FlEnginePlatformMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_engine.cc:760
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
_FlEngine::platform_handler
FlPlatformHandler * platform_handler
Definition: fl_engine.cc:58
fl_binary_messenger_shutdown
void fl_binary_messenger_shutdown(FlBinaryMessenger *self)
Definition: fl_binary_messenger.cc:500
_FlEngine::mouse_cursor_handler
FlMouseCursorHandler * mouse_cursor_handler
Definition: fl_engine.cc:61
fl_settings_handler_new
FlSettingsHandler * fl_settings_handler_new(FlEngine *engine)
Definition: fl_settings_handler.cc:74
fl_renderer_present_layers
gboolean fl_renderer_present_layers(FlRenderer *self, FlutterViewId view_id, const FlutterLayer **layers, size_t layers_count)
Definition: fl_renderer.cc:453
FlEnginePlatformMessageHandler
gboolean(* FlEnginePlatformMessageHandler)(FlEngine *engine, const gchar *channel, GBytes *message, const FlutterPlatformMessageResponseHandle *response_handle, gpointer user_data)
Definition: fl_engine_private.h:43
fl_engine_get_embedder_api
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:661
_FlEngine::embedder_api
FlutterEngineProcTable embedder_api
Definition: fl_engine.cc:77
fl_engine_init
static void fl_engine_init(FlEngine *self)
Definition: fl_engine.cc:495
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:397
fl_engine_gl_get_fbo
static uint32_t fl_engine_gl_get_fbo(void *user_data)
Definition: fl_engine.cc:280
_FlEngine::renderer
FlRenderer * renderer
Definition: fl_engine.cc:49
fl_engine_send_touch_move_event
void fl_engine_send_touch_move_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:1004
fl_engine_gl_make_resource_current
static bool fl_engine_gl_make_resource_current(void *user_data)
Definition: fl_engine.cc:291
FL_ENGINE_ERROR_FAILED
@ FL_ENGINE_ERROR_FAILED
Definition: fl_engine_private.h:26
kMousePointerDeviceId
static constexpr int32_t kMousePointerDeviceId
Definition: fl_engine.cc:33
fl_engine_update_accessibility_features
void fl_engine_update_accessibility_features(FlEngine *self, int32_t flags)
Definition: fl_engine.cc:1225
_FlEngine::next_view_id
FlutterViewId next_view_id
Definition: fl_engine.cc:80
fl_engine_send_key_event_finish
gboolean fl_engine_send_key_event_finish(FlEngine *self, GAsyncResult *result, gboolean *handled, GError **error)
Definition: fl_engine.cc:1144
fl_plugin_registrar_private.h
fl_texture_gl_private.h
_FlEngine::update_semantics_handler_data
gpointer update_semantics_handler_data
Definition: fl_engine.cc:89
fl_texture_registrar_lookup_texture
FlTexture * fl_texture_registrar_lookup_texture(FlTextureRegistrar *self, int64_t texture_id)
Definition: fl_texture_registrar.cc:190
fl_mouse_cursor_handler_new
FlMouseCursorHandler * fl_mouse_cursor_handler_new(FlBinaryMessenger *messenger)
Definition: fl_mouse_cursor_handler.cc:134
compositor_present_view_callback
static bool compositor_present_view_callback(const FlutterPresentViewInfo *info)
Definition: fl_engine.cc:254
FlEngineUpdateSemanticsHandler
void(* FlEngineUpdateSemanticsHandler)(FlEngine *engine, const FlutterSemanticsUpdate2 *update, gpointer user_data)
Definition: fl_engine_private.h:58
fl_platform_handler_request_app_exit
void fl_platform_handler_request_app_exit(FlPlatformHandler *self)
Definition: fl_platform_handler.cc:264
fl_engine_new_headless
G_MODULE_EXPORT FlEngine * fl_engine_new_headless(FlDartProject *project)
Definition: fl_engine.cc:529
PROP_0
@ PROP_0
Definition: fl_accessible_node.cc:84
i
int i
Definition: fl_socket_accessible.cc:18
fl_engine_signals
static guint fl_engine_signals[LAST_SIGNAL]
Definition: fl_engine.cc:100
fl_engine_get_renderer
FlRenderer * fl_engine_get_renderer(FlEngine *self)
Definition: fl_engine.cc:534
fl_engine_send_touch_remove_event
void fl_engine_send_touch_remove_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:1056
fl_settings_new
FlSettings * fl_settings_new()
Definition: fl_settings.cc:55
_FlEngine::aot_data
FlutterEngineAOTData aot_data
Definition: fl_engine.cc:70
fl_engine_gl_present
static bool fl_engine_gl_present(void *user_data)
Definition: fl_engine.cc:285
flags
FlutterSemanticsFlag flags
Definition: fl_accessible_node.cc:106
fl_engine_dispose
static void fl_engine_dispose(GObject *object)
Definition: fl_engine.cc:436
fl_engine_mark_texture_frame_available
gboolean fl_engine_mark_texture_frame_available(FlEngine *self, int64_t texture_id)
Definition: fl_engine.cc:1182
fl_engine_remove_view
void fl_engine_remove_view(FlEngine *self, FlutterViewId view_id, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:728
fl_engine_dispatch_semantics_action
void fl_engine_dispatch_semantics_action(FlEngine *self, uint64_t id, FlutterSemanticsAction action, GBytes *data)
Definition: fl_engine.cc:1161
fl_texture_registrar_new
FlTextureRegistrar * fl_texture_registrar_new(FlEngine *engine)
Definition: fl_texture_registrar.cc:221
pspec
guint const GValue GParamSpec * pspec
Definition: fl_standard_method_codec.cc:33
SIGNAL_ON_PRE_ENGINE_RESTART
@ SIGNAL_ON_PRE_ENGINE_RESTART
Definition: fl_engine.cc:98
fl_platform_handler_new
FlPlatformHandler * fl_platform_handler_new(FlBinaryMessenger *messenger)
Definition: fl_platform_handler.cc:251
fl_engine_on_pre_engine_restart_cb
static void fl_engine_on_pre_engine_restart_cb(void *user_data)
Definition: fl_engine.cc:389
fl_renderer_headless.h
fl_dart_project_get_assets_path
const G_MODULE_EXPORT gchar * fl_dart_project_get_assets_path(FlDartProject *self)
Definition: fl_dart_project.cc:85
fl_renderer_clear_current
void fl_renderer_clear_current(FlRenderer *self)
Definition: fl_renderer.cc:379
fl_engine_get_binary_messenger
G_MODULE_EXPORT FlBinaryMessenger * fl_engine_get_binary_messenger(FlEngine *self)
Definition: fl_engine.cc:1203
fl_engine_send_key_event
void fl_engine_send_key_event(FlEngine *self, const FlutterKeyEvent *event, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:1121
fl_renderer_get_proc_address
void * fl_renderer_get_proc_address(FlRenderer *self, const char *name)
Definition: fl_renderer.cc:363
fl_binary_messenger_new
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
Definition: fl_binary_messenger.cc:391
kPlatformTaskRunnerIdentifier
static constexpr size_t kPlatformTaskRunnerIdentifier
Definition: fl_engine.cc:29
_FlEngine::update_semantics_handler_destroy_notify
GDestroyNotify update_semantics_handler_destroy_notify
Definition: fl_engine.cc:90
fl_engine_new_with_renderer
FlEngine * fl_engine_new_with_renderer(FlDartProject *project, FlRenderer *renderer)
Definition: fl_engine.cc:509
fl_renderer_set_engine
void fl_renderer_set_engine(FlRenderer *self, FlEngine *engine)
Definition: fl_renderer.cc:332
view_removed_cb
static void view_removed_cb(const FlutterRemoveViewResult *result)
Definition: fl_engine.cc:166
user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
Definition: fl_event_channel.h:90
_FlEngine::project
FlDartProject * project
Definition: fl_engine.cc:43
_FlEngine::display_monitor
FlDisplayMonitor * display_monitor
Definition: fl_engine.cc:46
fl_engine_set_property
static void fl_engine_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
Definition: fl_engine.cc:420
_FlEngine
Definition: fl_engine.cc:36
G_DEFINE_QUARK
G_DEFINE_QUARK(fl_binary_messenger_codec_error_quark, fl_binary_messenger_codec_error) G_DECLARE_FINAL_TYPE(FlBinaryMessengerImpl
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)) enum
Definition: fl_engine.cc:102
fl_display_monitor_new
FlDisplayMonitor * fl_display_monitor_new(FlEngine *engine, GdkDisplay *display)
Definition: fl_display_monitor.cc:94
fl_engine_update_semantics_cb
static void fl_engine_update_semantics_cb(const FlutterSemanticsUpdate2 *update, void *user_data)
Definition: fl_engine.cc:374
fl_engine_add_view_finish
gboolean fl_engine_add_view_finish(FlEngine *self, GAsyncResult *result, GError **error)
Definition: fl_engine.cc:721
free_locale
static void free_locale(FlutterLocale *locale)
Definition: fl_engine.cc:177
fl_renderer_collect_backing_store
gboolean fl_renderer_collect_backing_store(FlRenderer *self, const FlutterBackingStore *backing_store)
Definition: fl_renderer.cc:423
fl_engine_remove_view_finish
gboolean fl_engine_remove_view_finish(FlEngine *self, GAsyncResult *result, GError **error)
Definition: fl_engine.cc:753
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_headless_new
FlRendererHeadless * fl_renderer_headless_new()
Definition: fl_renderer_headless.cc:31
fl_texture_registrar_shutdown
void fl_texture_registrar_shutdown(FlTextureRegistrar *self)
Definition: fl_texture_registrar.cc:215
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:161
fl_engine_plugin_registry_iface_init
static void fl_engine_plugin_registry_iface_init(FlPluginRegistryInterface *iface)
Definition: fl_engine.cc:415
fl_settings_handler.h
fl_engine_private.h
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:298
fl_engine_request_app_exit
void fl_engine_request_app_exit(FlEngine *self)
Definition: fl_engine.cc:1236
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
PROP_LAST
@ PROP_LAST
Definition: fl_accessible_node.cc:84
flutter::GetSwitchesFromEnvironment
std::vector< std::string > GetSwitchesFromEnvironment()
Definition: engine_switches.cc:14
_FlEngine::FLUTTER_API_SYMBOL
FLUTTER_API_SYMBOL(FlutterEngine) engine
_FlEngine::platform_message_handler_destroy_notify
GDestroyNotify platform_message_handler_destroy_notify
Definition: fl_engine.cc:85
engine_switches.h
_FlEngine::settings_handler
FlSettingsHandler * settings_handler
Definition: fl_engine.cc:55
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.h
fl_platform_handler.h
fl_renderer_make_resource_current
void fl_renderer_make_resource_current(FlRenderer *self)
Definition: fl_renderer.cc:374
fl_engine_send_platform_message_finish
GBytes * fl_engine_send_platform_message_finish(FlEngine *self, GAsyncResult *result, GError **error)
Definition: fl_engine.cc:887
fl_engine_add_view
FlutterViewId fl_engine_add_view(FlEngine *self, size_t width, size_t height, double pixel_ratio, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:678
fl_engine_get_mouse_cursor_handler
FlMouseCursorHandler * fl_engine_get_mouse_cursor_handler(FlEngine *self)
Definition: fl_engine.cc:1241
fl_engine_get_display_monitor
FlDisplayMonitor * fl_engine_get_display_monitor(FlEngine *self)
Definition: fl_engine.cc:539
fl_settings_handler_start
void fl_settings_handler_start(FlSettingsHandler *self, FlSettings *settings)
Definition: fl_settings_handler.cc:88
fl_engine_runs_task_on_current_thread
static bool fl_engine_runs_task_on_current_thread(void *user_data)
Definition: fl_engine.cc:339
fl_renderer_gdk.h
height
const uint8_t uint32_t uint32_t * height
Definition: fl_pixel_buffer_texture_test.cc:39
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_binary_messenger_private.h
fl_engine_get_registrar_for_plugin
static FlPluginRegistrar * fl_engine_get_registrar_for_plugin(FlPluginRegistry *registry, const gchar *name)
Definition: fl_engine.cc:406
fl_pixel_buffer_texture_private.h
view_added_cb
static void view_added_cb(const FlutterAddViewResult *result)
Definition: fl_engine.cc:155
_FlEngine::update_semantics_handler
FlEngineUpdateSemanticsHandler update_semantics_handler
Definition: fl_engine.cc:88
fl_engine_new
G_MODULE_EXPORT FlEngine * fl_engine_new(FlDartProject *project)
Definition: fl_engine.cc:524
fl_engine_send_touch_down_event
void fl_engine_send_touch_down_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:978
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
fl_engine.h
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
compositor_collect_backing_store_callback
static bool compositor_collect_backing_store_callback(const FlutterBackingStore *backing_store, void *user_data)
Definition: fl_engine.cc:245
fl_engine_get_task_runner
FlTaskRunner * fl_engine_get_task_runner(FlEngine *self)
Definition: fl_engine.cc:1209
fl_renderer_make_current
void fl_renderer_make_current(FlRenderer *self)
Definition: fl_renderer.cc:369
fl_engine_set_update_semantics_handler
void fl_engine_set_update_semantics_handler(FlEngine *self, FlEngineUpdateSemanticsHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_engine.cc:778
fl_engine_gl_proc_resolver
static void * fl_engine_gl_proc_resolver(void *user_data, const char *name)
Definition: fl_engine.cc:263
fl_engine_send_pointer_pan_zoom_event
void fl_engine_send_pointer_pan_zoom_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, FlutterPointerPhase phase, double pan_x, double pan_y, double scale, double rotation)
Definition: fl_engine.cc:1082
_FlEngine::thread
GThread * thread
Definition: fl_engine.cc:40
_FlEngine::binary_messenger
FlBinaryMessenger * binary_messenger
Definition: fl_engine.cc:52
fl_engine_send_platform_message
void fl_engine_send_platform_message(FlEngine *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:828
setup_locales
static void setup_locales(FlEngine *self)
Definition: fl_engine.cc:184
fl_engine_send_touch_add_event
void fl_engine_send_touch_add_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:1030
fl_renderer_gdk_new
FlRendererGdk * fl_renderer_gdk_new()
Definition: fl_renderer_gdk.cc:63
parse_locale
static void parse_locale(const gchar *locale, gchar **language, gchar **territory, gchar **codeset, gchar **modifier)
Definition: fl_engine.cc:112
fl_renderer_create_backing_store
gboolean fl_renderer_create_backing_store(FlRenderer *self, const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
Definition: fl_renderer.cc:391
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:235
_FlEngine::texture_registrar
FlTextureRegistrar * texture_registrar
Definition: fl_engine.cc:64
fl_dart_project_private.h
fl_engine_start
gboolean fl_engine_start(FlEngine *self, GError **error)
Definition: fl_engine.cc:544
fl_texture_registrar_private.h
_FlEngine::task_runner
FlTaskRunner * task_runner
Definition: fl_engine.cc:67
send_key_event_cb
static void send_key_event_cb(bool handled, void *user_data)
Definition: fl_engine.cc:1114
fl_engine_register_external_texture
gboolean fl_engine_register_external_texture(FlEngine *self, int64_t texture_id)
Definition: fl_engine.cc:1189
fl_display_monitor_start
void fl_display_monitor_start(FlDisplayMonitor *self)
Definition: fl_display_monitor.cc:103
fl_plugin_registrar_new
FlPluginRegistrar * fl_plugin_registrar_new(FlView *view, FlBinaryMessenger *messenger, FlTextureRegistrar *texture_registrar)
Definition: fl_plugin_registrar.cc:84
fl_engine_notify_display_update
void fl_engine_notify_display_update(FlEngine *self, const FlutterEngineDisplay *displays, size_t displays_length)
Definition: fl_engine.cc:665
fl_plugin_registry.h
fl_engine_execute_task
void fl_engine_execute_task(FlEngine *self, FlutterTask *task)
Definition: fl_engine.cc:1214
fl_engine_error_quark
GQuark fl_engine_error_quark(void) G_GNUC_CONST
fl_engine_unregister_external_texture
gboolean fl_engine_unregister_external_texture(FlEngine *self, int64_t texture_id)
Definition: fl_engine.cc:1196
fl_engine_send_window_metrics_event
void fl_engine_send_window_metrics_event(FlEngine *self, FlutterEngineDisplayId display_id, FlutterViewId view_id, size_t width, size_t height, double pixel_ratio)
Definition: fl_engine.cc:896
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:268
fl_engine_send_mouse_pointer_event
void fl_engine_send_mouse_pointer_event(FlEngine *self, FlutterViewId view_id, FlutterPointerPhase phase, size_t timestamp, double x, double y, FlutterPointerDeviceKind device_kind, double scroll_delta_x, double scroll_delta_y, int64_t buttons)
Definition: fl_engine.cc:918
fl_renderer_get_fbo
guint32 fl_renderer_get_fbo(FlRenderer *self)
Definition: fl_renderer.cc:384
fl_display_monitor.h
fl_engine_post_task
static void fl_engine_post_task(FlutterTask task, uint64_t target_time_nanos, void *user_data)
Definition: fl_engine.cc:345
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:154
fl_engine_get_texture_registrar
G_MODULE_EXPORT FlTextureRegistrar * fl_engine_get_texture_registrar(FlEngine *self)
Definition: fl_engine.cc:1219
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:796
_FlEngine::platform_message_handler
FlEnginePlatformMessageHandler platform_message_handler
Definition: fl_engine.cc:83
fl_engine_send_touch_up_event
void fl_engine_send_touch_up_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:952
fl_engine_class_init
static void fl_engine_class_init(FlEngineClass *klass)
Definition: fl_engine.cc:478
LAST_SIGNAL
@ LAST_SIGNAL
Definition: fl_engine.cc:98
fl_engine_platform_message_cb
static void fl_engine_platform_message_cb(const FlutterPlatformMessage *message, void *user_data)
Definition: fl_engine.cc:354
kPointerPanZoomDeviceId
static constexpr int32_t kPointerPanZoomDeviceId
Definition: fl_engine.cc:34
_FlEngine::parent_instance
GObject parent_instance
Definition: fl_engine.cc:37
fl_engine_gl_clear_current
static bool fl_engine_gl_clear_current(void *user_data)
Definition: fl_engine.cc:274