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