### Setup and send message via FlBasicMessageChannel Source: https://api.flutter.dev/linux-embedder/fl__basic__message__channel_8h_source.html Complete example showing channel initialization with a standard codec, setting a message handler, and sending a message with an async response callback. Demonstrates typical setup pattern for bidirectional communication. ```C static void message_cb (FlBasicMessageChannel* channel, FlValue* message, FlBasicMessageChannelResponseHandle* response_handle, gpointer user_data) { g_autoptr(FlValue) response = fl_value_new_string ("Response"); g_autoptr(GError) error = NULL; if (!fl_basic_message_channel_respond (channel, response_handle, response, &error)) { g_warning ("Failed to send channel response: %s", error->message); } } static void message_response_cb (GObject *object, GAsyncResult *result, gpointer user_data) { g_autoptr(GError) error = NULL; g_autoptr(FlValue) response = fl_basic_message_channel_send_finish (FL_BASIC_MESSAGE_CHANNEL (object), result, &error); if (response == NULL) { g_warning ("Failed to send message: %s", error->message); return; } handle_response (response); } static void setup_channel () { g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new (); channel = fl_basic_message_channel_new (messenger, "flutter/foo", FL_MESSAGE_CODEC (codec)); fl_basic_message_channel_set_message_handler (channel, message_cb, NULL, NULL); g_autoptr(FlValue) message = fl_value_new_string ("Hello World"); fl_basic_message_channel_send (channel, message, NULL, message_response_cb, NULL); } ``` -------------------------------- ### Create FlView and get engine in C++ Source: https://api.flutter.dev/linux-embedder/fl__view__test_8cc_source.html Demonstrates creating an `FlView` from a project, retrieving its `FlEngine`, mocking an engine procedure, starting the engine, and creating a secondary view associated with the engine. Shows proper destruction of views. ```cpp FlView* implicit_view = fl_view_new(project); FlEngine* engine = fl_view_get_engine(implicit_view); fl_engine_get_embedder_api(engine)->RemoveView = MOCK_ENGINE_PROC( RemoveView, ([](auto engine, const FlutterRemoveViewInfo* info) { return kInvalidArguments; })); g_autoptr(GError) error = nullptr; EXPECT_TRUE(fl_engine_start(engine, &error)); FlView* secondary_view = fl_view_new_for_engine(engine); fl_gtk_widget_destroy(GTK_WIDGET(secondary_view)); fl_gtk_widget_destroy(GTK_WIDGET(implicit_view)); ``` -------------------------------- ### Initialize Keyboard Manager for Unhandled Async Event Test (Partial) Source: https://api.flutter.dev/linux-embedder/fl__keyboard__manager__test_8cc_source.html Partial setup for a test case where keyboard events are expected to be unhandled asynchronously by both the engine and the channel. Initializes mock components and starts the engine. ```C++ TEST(FlKeyboardManagerTest, EngineNotHandledChannelNotHandledAsync) { ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlKeyboardManager) manager = fl_keyboard_manager_new(engine); EXPECT_TRUE(fl_engine_start(engine, nullptr); ``` -------------------------------- ### FlBasicMessageChannel Setup and Message Handling Source: https://api.flutter.dev/linux-embedder/fl__basic__message__channel_8h.html Complete example showing channel initialization with a standard message codec, message handler registration, and asynchronous message sending with response callback. Demonstrates the full lifecycle of setting up bidirectional communication between platform and Dart code. ```C static FlBasicMessageChannel *channel = NULL; static void message_cb (FlBasicMessageChannel* channel, FlValue* message, FlBasicMessageChannelResponseHandle* response_handle, gpointer user_data) { g_autoptr(FlValue) response = handle_message (message); g_autoptr(GError) error = NULL; if (!fl_basic_message_channel_respond (channel, response_handle, response, &error)) g_warning ("Failed to send channel response: %s", error->message); } static void message_response_cb (GObject *object, GAsyncResult *result, gpointer user_data) { g_autoptr(GError) error = NULL; g_autoptr(FlValue) response = fl_basic_message_channel_send_finish (FL_BASIC_MESSAGE_CHANNEL (object), result, &error); if (response == NULL) { g_warning ("Failed to send message: %s", error->message); return; } handle_response (response); } static void setup_channel () { g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new (); channel = fl_basic_message_channel_new (messenger, "flutter/foo", FL_MESSAGE_CODEC (codec)); fl_basic_message_channel_set_message_handler (channel, message_cb, NULL, NULL); g_autoptr(FlValue) message = fl_value_new_string ("Hello World"); fl_basic_message_channel_send (channel, message, NULL, message_response_cb, NULL); } ``` -------------------------------- ### start() - Get Start Position Source: https://api.flutter.dev/macos-embedder/classflutter_1_1_text_range.html Returns the start position of the text range. The start is the minimum of the base and extent values. ```APIDOC ## size_t start() const ### Description Returns the start position of the text range. The start is calculated as the minimum of the base and extent values, representing the beginning of the range. ### Method Signature ```cpp size_t start() const ``` ### Return Value - **size_t** - The start position (minimum of base and extent) ### Example ```cpp flutter::TextRange range(15, 5); size_t startPos = range.start(); // startPos is 5 (the minimum) ``` ``` -------------------------------- ### setup_software() - Initialize Software Rendering Compositor Source: https://api.flutter.dev/linux-embedder/fl__view_8cc.html Creates a software-based compositor as an alternative to OpenGL rendering. Used when hardware acceleration is unavailable or disabled. ```C { self->compositor = FL_COMPOSITOR( fl_compositor_software_new(fl_engine_get_task_runner(self->engine))); } ``` -------------------------------- ### Handle Pointer Pan/Zoom Start Event in C++ Source: https://api.flutter.dev/windows-embedder/flutter__windows__view_8cc_source.html This method initiates a pan/zoom gesture by getting the primary pointer location and sending the start event to the Flutter engine. ```C++ void FlutterWindowsView::OnPointerPanZoomStart(int32_t device_id) { PointerLocation point = binding_handler_->GetPrimaryPointerLocation(); SendPointerPanZoomStart(device_id, point.x, point.y); } ``` -------------------------------- ### Initialize Test Environment (SetUp) Source: https://api.flutter.dev/windows-embedder/classflutter_1_1testing_1_1_accessibility_plugin_test.html This snippet shows the `SetUp()` method, which initializes the test environment by building a `FlutterWindowsEngine`, creating a mock view, and setting up the `AccessibilityPlugin`. ```C++ { WindowsTest::SetUp(); FlutterWindowsEngineBuilder builder{GetContext()}; engine_ = builder.Build(); auto window = std::make_unique>(); view_ = std::make_unique>( engine_.get(), std::move(window)); EngineModifier modifier{engine_.get()}; modifier.SetSemanticsEnabled(true); modifier.SetImplicitView(view_.get()); plugin_ = std::make_unique(engine_.get()); AccessibilityPlugin::SetUp(&messenger_, plugin_.get()); } ``` -------------------------------- ### Spell Check Result Encoding Example Source: https://api.flutter.dev/javadoc/io/flutter/plugin/editing/SpellCheckPlugin.html Example of the dictionary format used to encode spell check results, including start index, end index, and a list of suggestions. ```JSON { startIndex: 0, endIndex: 5, suggestions: [hello, ...] } ``` -------------------------------- ### FlGnomeSettingsTest::SetUp() Method Implementation Source: https://api.flutter.dev/linux-embedder/class_fl_gnome_settings_test.html This snippet shows the implementation of the `SetUp()` method, which calls `g_settings_backend_get_default()` to force the registration of GIO module extension points. ```C++ { // force _g_io_modules_ensure_extension_points_registered() to get called g_settings_backend_get_default(); } ``` -------------------------------- ### DartProject::dart_entrypoint Source: https://api.flutter.dev/windows-embedder/flutter__engine_8cc_source.html Gets the name of the Dart entrypoint function for the project. This is the function that will be called when the engine starts. ```APIDOC ## DartProject::dart_entrypoint ### Description Gets the name of the Dart entrypoint function for the project. ### Signature ```cpp const std::string & dart_entrypoint() const ``` ### Return Value - **const std::string&** - The Dart entrypoint function name ### Definition dart_project.h:96 ``` -------------------------------- ### launchEngine Source: https://api.flutter.dev/macos-embedder/category_flutter_view_controller_07_08.html Starts running the engine, including any initial setup. This method initializes the Flutter engine for the view controller. ```APIDOC ## launchEngine ### Description Starts running the engine, including any initial setup. ### Method Signature ```objc - (BOOL) launchEngine ``` ### Return Value - **(BOOL)** - Returns YES if the engine was successfully launched, NO otherwise. ### Usage Call this method to initialize and start the Flutter engine for the view controller. ``` -------------------------------- ### Engine Initialization with EGL Manager Setup Source: https://api.flutter.dev/windows-embedder/flutter__windows__engine__unittests_8cc_source.html Demonstrates setting up an EGL manager for ANGLE rendering and running the engine with mocked embedder API procedures. ```cpp // Set the EGL manager to !nullptr to test ANGLE rendering. modifier.SetEGLManager(std::make_unique()); engine->Run(); EXPECT_TRUE(run_called); EXPECT_TRUE(update_locales_called); EXPECT_TRUE(settings_message_sent); EXPECT_TRUE(notify_display_update_called); ``` -------------------------------- ### length() - Get Range Length Source: https://api.flutter.dev/macos-embedder/classflutter_1_1_text_range.html Returns the length of the text range, calculated as the difference between the end and start positions. ```APIDOC ## size_t length() const ### Description Returns the length of the text range. The length is calculated as the difference between the end and start positions. ### Method Signature ```cpp size_t length() const ``` ### Return Value - **size_t** - The length of the range (end - start) ### Example ```cpp flutter::TextRange range(5, 15); size_t len = range.length(); // len is 10 (15 - 5) ``` ``` -------------------------------- ### startInitialization(Context applicationContext) Source: https://api.flutter.dev/javadoc/io/flutter/embedding/engine/loader/FlutterLoader.html Starts initialization of the native system. ```APIDOC ## Method: void startInitialization(Context applicationContext) ### Description Starts initialization of the native system. ### Signature `void startInitialization(Context applicationContext)` ### Parameters - **applicationContext** (`Context`) - The application's context. ### Return Value `void` ``` -------------------------------- ### startInitialization(Context applicationContext) Source: https://api.flutter.dev/javadoc/io/flutter/embedding/engine/loader/FlutterLoader.html Starts initialization of the native system. ```APIDOC ## METHOD startInitialization(Context applicationContext) ### Description Starts initialization of the native system. ### Signature public void startInitialization(@NonNull Context applicationContext) ### Parameters - **applicationContext** (`Context`) - Required - The Android application context. ``` -------------------------------- ### static void SetUp(BinaryMessenger* binary_messenger, AccessibilityPlugin* plugin) Source: https://api.flutter.dev/windows-embedder/accessibility__plugin_8h_source.html Sets up the `AccessibilityPlugin` to begin handling accessibility messages on the provided `binary_messenger`. ```APIDOC ## STATIC METHOD SetUp ### Description This static method initializes the `AccessibilityPlugin` to start processing accessibility messages. It binds the plugin to a `BinaryMessenger` for communication. ### Method Static Method ### Endpoint static void SetUp(BinaryMessenger* binary_messenger, AccessibilityPlugin* plugin) ### Parameters #### Path Parameters - **binary_messenger** (BinaryMessenger*) - Required - The binary messenger to use for handling accessibility messages. - **plugin** (AccessibilityPlugin*) - Required - A pointer to the `AccessibilityPlugin` instance to set up. ``` -------------------------------- ### GET flutterWindowSceneIfViewLoaded Source: https://api.flutter.dev/ios-embedder/_u_i_view_controller_09_flutter_screen_and_scene_if_loaded_8h_source.html Retrieves the UIWindowScene associated with the UIViewController if the view is currently loaded. This method is available starting from iOS 13.0. ```APIDOC ## GET flutterWindowSceneIfViewLoaded ### Description Returns a UIWindowScene if the UIViewController's view is loaded, and nil otherwise. ### Method Objective-C Instance Method ### Endpoint - (UIWindowScene*)flutterWindowSceneIfViewLoaded ### Parameters None. ### Request Example [myViewController flutterWindowSceneIfViewLoaded]; ### Response #### Success Response (200) - **return** (UIWindowScene*) - The UIWindowScene instance if the view is loaded; otherwise, nil. ### Response Example { "status": "success", "result": "UIWindowScene object or nil" } ``` -------------------------------- ### GetCursorOffset() - Get UTF-8 Cursor Position Source: https://api.flutter.dev/ios-embedder/classflutter_1_1_text_input_model.html Returns the cursor offset in UTF-8 bytes from the start of the text, converting from the internal UTF-16 representation. ```cpp { // Measure the length of the current text up to the selection extent. // There is probably a much more efficient way of doing this. auto leading_text = text_.substr(0, selection_.extent()); return fml::Utf16ToUtf8(leading_text).size(); } ``` -------------------------------- ### Play System Sound Test Setup Source: https://api.flutter.dev/windows-embedder/platform__handler__unittests_8cc_source.html Initializes test setup for system sound functionality with headless engine and mock platform handler. ```C++ TEST_F(PlatformHandlerTest, PlaySystemSound) { UseHeadlessEngine(); TestBinaryMessenger messenger; MockPlatformHandler platform_handler(&messenger, engine()); ``` -------------------------------- ### Create a new FlView Source: https://api.flutter.dev/linux-embedder/fl__view_8h.html Creates a new FlView widget to display a Flutter application. Requires a FlDartProject. The example shows setup for channels and plugins. ```c FlDartProject *project = fl_dart_project_new (); FlView *view = fl_view_new (project); gtk_widget_show (GTK_WIDGET (view)); gtk_container_add (GTK_CONTAINER (parent), view); FlBinaryMessenger *messenger = fl_engine_get_binary_messenger (fl_view_get_engine (view)); setup_channels_or_plugins (messenger); ``` -------------------------------- ### fl_settings_new() Source: https://api.flutter.dev/linux-embedder/fl__settings_8h.html Creates a new settings instance. Attempts to initialize settings via XDG desktop portal, falling back to GNOME settings if the portal is unavailable. ```APIDOC ## fl_settings_new() ### Description Creates a new settings instance for managing Flutter Linux platform settings. The function attempts to initialize settings through the XDG desktop portal, and falls back to GNOME settings if the portal is unavailable. ### Signature ```c FlSettings* fl_settings_new(void) ``` ### Parameters None ### Return Value - **FlSettings*** - A new FlSettings instance. Returns a portal-based settings object if available, otherwise returns a GNOME settings object. ### Behavior - Attempts to create and start an XDG desktop portal settings instance - If portal initialization fails, logs a debug message and falls back to GNOME settings - The returned FlSettings object should be properly managed by the caller ### References Referenced by fl_engine_start() ``` -------------------------------- ### Flutter Display Monitor Functions Source: https://api.flutter.dev/linux-embedder/globals_func_f.html Functions for managing display monitors, including initialization, disposal, getting display information, and starting monitor services. ```APIDOC ## Flutter Display Monitor Functions ### Description Functions for managing display monitors, including initialization, disposal, getting display information, and starting monitor services. ### Functions - `fl_display_monitor_class_init()` - `fl_display_monitor_dispose()` - `fl_display_monitor_get_display_id()` - `fl_display_monitor_init()` - `fl_display_monitor_new()` - `fl_display_monitor_start()` ``` -------------------------------- ### UseEngineWithView() setup method Source: https://api.flutter.dev/windows-embedder/classflutter_1_1testing_1_1_cursor_handler_test.html Initializes a Flutter Windows engine with a mock window and view. Sets up expectations for window binding handler calls and creates a view with specified constraints. ```cpp { windows_proc_table_ = std::make_shared(); FlutterWindowsEngineBuilder builder{GetContext()}; builder.SetWindowsProcTable(windows_proc_table_); auto window = std::make_unique(); EXPECT_CALL(*window.get(), SetView).Times(1); EXPECT_CALL(*window.get(), GetWindowHandle).WillRepeatedly(Return(nullptr)); window_ = window.get(); engine_ = builder.Build(); view_ = engine_->CreateView(std::move(window), /*is_sized_to_content=*/false, BoxConstraints()); } ``` -------------------------------- ### setup_opengl() - Configure OpenGL Rendering Context Source: https://api.flutter.dev/linux-embedder/fl__view_8cc.html Creates and realizes an OpenGL context for rendering, with platform-specific optimizations for Wayland (EGL) vs X11 (GLX). Logs warnings if context creation or realization fails and returns early without setting up the compositor. ```C { g_autoptr(GError) error = nullptr; self->render_context = gdk_window_create_gl_context( gtk_widget_get_window(GTK_WIDGET(self->render_area)), &error); if (self->render_context == nullptr) { g_warning("Failed to create OpenGL context: %s", error->message); return; } if (!gdk_gl_context_realize(self->render_context, &error)) { g_warning("Failed to realize OpenGL context: %s", error->message); return; } // If using Wayland, then EGL is in use and we can access the frame // from the Flutter context using EGLImage. If not (i.e. X11 using GLX) // then we have to copy the texture via the CPU. gboolean shareable = GDK_IS_WAYLAND_DISPLAY(gtk_widget_get_display(GTK_WIDGET(self))); self->compositor = FL_COMPOSITOR(fl_compositor_opengl_new( fl_engine_get_task_runner(self->engine), fl_engine_get_opengl_manager(self->engine), shareable)); } ``` -------------------------------- ### Get Substring (AtkText) Source: https://api.flutter.dev/linux-embedder/fl__accessible__text__field_8cc_source.html Returns a substring of the text field's content based on the provided start and end offsets, implementing AtkText::get_text. ```cpp static gchar* fl_accessible_text_field_get_text(AtkText* text, gint start_offset, gint end_offset) { g_return_val_if_fail(FL_IS_ACCESSIBLE_TEXT_FIELD(text), nullptr); FlAccessibleTextField* self = FL_ACCESSIBLE_TEXT_FIELD(text); return get_substring(self, start_offset, end_offset); } ``` -------------------------------- ### Get Run Configuration for Entrypoint Source: https://api.flutter.dev/ios-embedder/_flutter_dart_project___internal_8h_source.html Generates a run configuration for a specific Dart entrypoint. Allows specifying a custom starting point for the Flutter application. ```Objective-C - (flutter::RunConfiguration)runConfigurationForEntrypoint:(nullable NSString*)entrypointOrNil; ``` -------------------------------- ### Class Initialization with Property Installation Source: https://api.flutter.dev/linux-embedder/fl__gnome__settings_8cc_source.html Sets up the FlGnomeSettings GObject class by installing dispose and set_property handlers, and registering the interface_settings property as a writable, construct-only object property. ```C static void fl_gnome_settings_class_init(FlGnomeSettingsClass* klass) { GObjectClass* object_class = G_OBJECT_CLASS(klass); object_class->dispose = fl_gnome_settings_dispose; object_class->set_property = fl_gnome_settings_set_property; g_object_class_install_property( object_class, PROP_INTERFACE_SETTINGS, g_param_spec_object( kInterfaceSettings, kInterfaceSettings, kDesktopInterfaceSchema, g_settings_get_type(), static_cast(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS))); } ``` -------------------------------- ### Engine Setup: Locales, Settings, and Keyboard Configuration Source: https://api.flutter.dev/linux-embedder/fl__engine__private_8h.html Configures locales, initializes settings handler, creates platform handler, and sets up keyboard input after engine initialization. Must be called after engine is running. ```C setup_locales(self); g_autoptr(FlSettings) settings = fl_settings_new(); self->settings_handler = fl_settings_handler_new(self); fl_settings_handler_start(self->settings_handler, settings); self->platform_handler = fl_platform_handler_new(self->binary_messenger); setup_keyboard(self); ``` -------------------------------- ### @property(nonatomic, weak) FlutterViewController* viewController; Source: https://api.flutter.dev/ios-embedder/_flutter_engine_8h_source.html Sets or gets the `FlutterViewController` for this engine instance. Setting it signals the engine to start animations and drawing, while unsetting it stops them. ```APIDOC ## @property(nonatomic, weak) FlutterViewController* viewController; ### Description Sets the `FlutterViewController` for this instance. The FlutterEngine must be running (e.g. a successful call to `-runWithEntrypoint:` or `-runWithEntrypoint:libraryURI`) before calling this method. Callers may pass nil to remove the viewController and have the engine run headless in the current process. A FlutterEngine can only have one `FlutterViewController` at a time. If there is already a `FlutterViewController` associated with this instance, this method will replace the engine's current viewController with the newly specified one. Setting the viewController will signal the engine to start animations and drawing, and unsetting it will signal the engine to stop animations and drawing. However, neither will impact the state of the Dart program's execution. ### Type `FlutterViewController*` ### Access Read/Write ``` -------------------------------- ### fl_settings_portal_start() Source: https://api.flutter.dev/linux-embedder/fl__settings__portal_8cc.html Initializes the FlSettingsPortal by reading current settings and setting up monitoring for changes in desktop portal settings. ```APIDOC ## `fl_settings_portal_start()` ### Description Reads the current settings and starts monitoring for changes in the desktop portal settings. ### Signature `gboolean fl_settings_portal_start(FlSettingsPortal * _portal_, GError ** _error_)` ### Parameters - `_portal_` (`FlSettingsPortal *`) - An #FlSettingsPortal. - `_error_` (`GError **`) - (allow-none): #GError location to store the error occurring, or NULL. If `error` is not NULL, `*error` must be initialized (typically NULL, but an error from a previous call using GLib error handling is explicitly valid). ### Returns `gboolean` - TRUE on success, or FALSE if the portal is not available. ``` -------------------------------- ### Get focused widget from FlTextInputHandler Source: https://api.flutter.dev/linux-embedder/fl__text__input__handler_8h.html Retrieves the GTK widget that currently has input focus. Returns nullptr if no widget is active; used internally by keyboard setup routines. ```C { g_return_val_if_fail(FL_IS_TEXT_INPUT_HANDLER(self), nullptr); return self->widget; } ``` -------------------------------- ### OnListen Source: https://api.flutter.dev/macos-embedder/classflutter_1_1_stream_handler.html This method is invoked when a client starts listening to the stream. Implementations should set up the stream and use the provided EventSink to send events. Return an error if stream setup fails. ```APIDOC ## Method: std::unique_ptr > OnListen(const T *arguments, std::unique_ptr> &&events) ### Description This method is invoked when a client starts listening to the stream. Implementations should set up the stream and use the provided EventSink to send events. Return an error if stream setup fails. ### Parameters - **arguments** (const T *) - Arguments passed by the client when starting to listen. - **events** (std::unique_ptr> &&) - An event sink to send events to the client. ### Returns (std::unique_ptr >) - An error object if stream setup fails, otherwise nullptr. ``` -------------------------------- ### setup_shader() - OpenGL Shader Compilation and Program Linking Source: https://api.flutter.dev/linux-embedder/fl__compositor__opengl_8cc.html Initializes OpenGL shaders by compiling vertex and fragment shaders, linking them into a program, and setting up vertex buffer data. Requires an active OpenGL context and handles compilation/linking errors with warnings. ```C { if (!fl_opengl_manager_make_platform_current(self->opengl_manager)) { g_warning( "Failed to setup compositor shaders, unable to make OpenGL context " "current"); return; } GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertex_shader, 1, &vertex_shader_src, nullptr); glCompileShader(vertex_shader); GLint vertex_compile_status; glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &vertex_compile_status); if (vertex_compile_status == GL_FALSE) { g_autofree gchar* shader_log = get_shader_log(vertex_shader); g_warning("Failed to compile vertex shader: %s", shader_log); } GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragment_shader, 1, &fragment_shader_src, nullptr); glCompileShader(fragment_shader); GLint fragment_compile_status; glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &fragment_compile_status); if (fragment_compile_status == GL_FALSE) { g_autofree gchar* shader_log = get_shader_log(fragment_shader); g_warning("Failed to compile fragment shader: %s", shader_log); } self->program = glCreateProgram(); glAttachShader(self->program, vertex_shader); glAttachShader(self->program, fragment_shader); glLinkProgram(self->program); GLint link_status; glGetProgramiv(self->program, GL_LINK_STATUS, &link_status); if (link_status == GL_FALSE) { g_autofree gchar* program_log = get_program_log(self->program); g_warning("Failed to link program: %s", program_log); } self->offset_location = glGetUniformLocation(self->program, "offset"); self->scale_location = glGetUniformLocation(self->program, "scale"); glDeleteShader(vertex_shader); glDeleteShader(fragment_shader); // The uniform square abcd in two triangles cba + cdb // a--b // | | // c--d GLfloat vertex_data[] = {-1, -1, 0, 0, 1, 1, 1, 1, -1, 1, 0, 1, -1, -1, 0, 0, 1, -1, 1, 0, 1, 1, 1, 1}; glGenBuffers(1, &self->vertex_buffer); glBindBuffer(GL_ARRAY_BUFFER, self->vertex_buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); } ``` -------------------------------- ### Simulate Edit Menu Presentation with FlutterTextInputPlugin (Objective-C) Source: https://api.flutter.dev/ios-embedder/_flutter_text_input_plugin_test_8mm_source.html This example shows the setup required to test the showEditMenu method of FlutterTextInputPlugin, including mocking dependencies and setting up an expectation for presentEditMenuWithConfiguration. ```Objective-C if (@available(iOS 16.0, *)) { FlutterTextInputPlugin* myInputPlugin = [[FlutterTextInputPlugin alloc] initWithDelegate:OCMClassMock([FlutterEngine class])]; FlutterViewController* myViewController = [[FlutterViewController alloc] init]; myInputPlugin.viewController = myViewController; [myViewController loadView]; FlutterMethodCall* setClientCall = [FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient" arguments:@[ @(123), self.mutableTemplateCopy ]]; [myInputPlugin handleMethodCall:setClientCall result:^(id _Nullable result){ }]; FlutterTextInputView* myInputView = myInputPlugin.activeView; FlutterTextInputView* mockInputView = OCMPartialMock(myInputView); OCMStub([mockInputView isFirstResponder]).andReturn(YES); XCTestExpectation* expectation = [[XCTestExpectation alloc] initWithDescription:@"presentEditMenuWithConfiguration must be called."]; id mockInteraction = OCMClassMock([UIEditMenuInteraction class]); OCMStub([mockInputView editMenuInteraction]).andReturn(mockInteraction); OCMStub([mockInteraction presentEditMenuWithConfiguration:[OCMArg any]]) .andDo(^(NSInvocation* invocation) { [expectation fulfill]; }); myInputView.frame = CGRectMake(10, 20, 30, 40); NSDictionary* encodedTargetRect = @{@"x" : @(100), @"y" : @(200), @"width" : @(300), @"height" : @(400)}; NSArray*>* encodedItems = @[ @{@"type" : @"cut"}, @{@"type" : @"paste"}, @{@"type" : @"copy"} ]; BOOL shownEditMenu = [myInputPlugin showEditMenu:@{@"targetRect" : encodedTargetRect, @"items" : encodedItems}]; XCTAssertTrue(shownEditMenu, @"Should show edit menu with correct configuration."); [self waitForExpectations:@[ expectation ] timeout:1.0]; ``` -------------------------------- ### SetUp Static Method Source: https://api.flutter.dev/windows-embedder/classflutter_1_1_accessibility_plugin.html Initializes the AccessibilityPlugin with a binary messenger. This static method must be called to set up the plugin and establish communication channels for accessibility functionality. ```APIDOC ## Static Method ### SetUp ```cpp static void SetUp(BinaryMessenger *binary_messenger, AccessibilityPlugin *plugin) ``` ### Description Sets up the AccessibilityPlugin with a binary messenger for communication. ### Parameters - **binary_messenger** (BinaryMessenger*) - Required - Pointer to the BinaryMessenger instance used for plugin communication - **plugin** (AccessibilityPlugin*) - Required - Pointer to the AccessibilityPlugin instance to set up ``` -------------------------------- ### Get Subtree List for Accessibility Source: https://api.flutter.dev/linux-embedder/accessibility__bridge_8cc_source.html Recursively collects all semantics nodes starting from a target node, including those that have pending updates. This is used to build a complete subtree for accessibility processing. ```cpp void AccessibilityBridge::GetSubTreeList(const SemanticsNode& target, std::vector& result) { result.push_back(target); for (int32_t child : target.children_in_traversal_order) { auto iter = pending_semantics_node_updates_.find(child); if (iter != pending_semantics_node_updates_.end()) { SemanticsNode node = iter->second; GetSubTreeList(node, result); pending_semantics_node_updates_.erase(iter); } } } ``` -------------------------------- ### Initial Setup for Asynchronous Key Event Handling Test (Engine Not Handled, Channel Handled) Source: https://api.flutter.dev/linux-embedder/fl__keyboard__manager__test_8cc_source.html This snippet provides the initial setup for a test case where `FlKeyboardManager` handles key events asynchronously. It initializes the mock GTK environment, binary messenger, Flutter engine, and keyboard manager. ```cpp TEST(FlKeyboardManagerTest, EngineNotHandledChannelHandledAsync) { ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlKeyboardManager) manager = fl_keyboard_manager_new(engine); EXPECT_TRUE(fl_engine_start(engine, nullptr)); ``` -------------------------------- ### startInitialization(Context applicationContext, FlutterLoader.Settings settings) Source: https://api.flutter.dev/javadoc/io/flutter/embedding/engine/loader/FlutterLoader.html Starts initialization of the native system. ```APIDOC ## Method: void startInitialization(Context applicationContext, FlutterLoader.Settings settings) ### Description Starts initialization of the native system. ### Signature `void startInitialization(Context applicationContext, FlutterLoader.Settings settings)` ### Parameters - **applicationContext** (`Context`) - The application's context. - **settings** (`FlutterLoader.Settings`) - Settings for the Flutter initialization. ### Return Value `void` ``` -------------------------------- ### Get Character Range at Point (Objective-C) Source: https://api.flutter.dev/ios-embedder/_flutter_text_input_plugin_8mm_source.html Returns a text range for the character at a given point. This implementation is a placeholder and currently returns a range based on the current selection start. ```Objective-C - (UITextRange*)characterRangeAtPoint:(CGPoint)point { // TODO(cbracken) Implement. NSUInteger currentIndex = ((FlutterTextPosition*)_selectedTextRange.start).index; return [FlutterTextRange rangeWithNSRange:fml::RangeForCharacterAtIndex(self.text, currentIndex)]; } ``` -------------------------------- ### Setup for Platform View Deallocation Test Source: https://api.flutter.dev/ios-embedder/_flutter_platform_views_test_8mm_source.html This code block defines the start of a test method focusing on platform view deallocation. It initializes mock delegates, task runners, and the FlutterPlatformViewsController. ```Objective-C++ - (void) testFlutterPlatformViewControllerResetDeallocsPlatformViewWhenRootViewsNotBindedToFlutterView { flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; flutter::TaskRunners runners(/*label=*/self.name.UTF8String, /*platform=*/GetDefaultTaskRunner(), /*raster=*/GetDefaultTaskRunner(), /*ui=*/GetDefaultTaskRunner(), /*io=*/GetDefaultTaskRunner()); FlutterPlatformViewsController* flutterPlatformViewsController = [[FlutterPlatformViewsController alloc] init]; flutterPlatformViewsController.taskRunner = GetDefaultTaskRunner(); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kMetal, /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners, /*worker_task_runner=*/nil, /*is_gpu_disabled_jsync_switch=*/std::make_shared()); ``` -------------------------------- ### gboolean fl_settings_portal_start(FlSettingsPortal *portal, GError **error) Source: https://api.flutter.dev/linux-embedder/fl__settings__portal_8h.html Reads the current settings and starts monitoring for changes in the desktop portal settings. ```APIDOC ## Function: gboolean fl_settings_portal_start(FlSettingsPortal *portal, GError **error) ### Description Reads the current settings and starts monitoring for changes in the desktop portal settings. ### Parameters - **portal** (FlSettingsPortal *) - An #FlSettingsPortal. - **error** (GError **) - (allow-none): #GError location to store the error occurring, or NULL. If `error` is not NULL, `*error` must be initialized (typically NULL, but an error from a previous call using GLib error handling is explicitly valid). ### Returns (gboolean) - TRUE on success, or FALSE if the portal is not available. ``` -------------------------------- ### Test FlBinaryMessenger Handling Send Failure Setup Source: https://api.flutter.dev/linux-embedder/fl__binary__messenger__test_8cc_source.html This test sets up the environment to verify how FlBinaryMessenger handles a send failure reported by the engine. It initializes a GMainLoop, FlDartProject, and FlEngine, then starts the engine. ```cpp TEST(FlBinaryMessengerTest, SendFailure) { g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0); g_autoptr(FlDartProject) project = fl_dart_project_new(); g_autoptr(FlEngine) engine = fl_engine_new(project); g_autoptr(GError) error = nullptr; EXPECT_TRUE(fl_engine_start(engine, &error)); EXPECT_EQ(error, nullptr); ``` -------------------------------- ### FlutterDesktopGetDpiForMonitor() Source: https://api.flutter.dev/windows-embedder/flutter__windows_8h.html Gets the DPI (dots per inch) for a given monitor. This utility function retrieves the DPI scaling factor for a specific monitor, enabling proper scaling awareness for multi-monitor setups. ```APIDOC ## FlutterDesktopGetDpiForMonitor() ### Description Gets the DPI (dots per inch) for a given monitor. ### Signature ```c FLUTTER_EXPORT UINT FlutterDesktopGetDpiForMonitor( HMONITOR monitor ) ``` ### Parameters - **monitor** (HMONITOR) - Required - Windows monitor handle ### Return Value - **UINT** - The DPI value for the specified monitor ### Definition Defined at line 337 of flutter_windows.cc ``` -------------------------------- ### Get Paragraph at Offset in FlAccessibleTextField (C++) Source: https://api.flutter.dev/linux-embedder/fl__accessible__text__field_8cc.html Extracts the text of the paragraph containing the specified offset from an `FlAccessibleTextField`. It uses Pango layout's paragraph start attributes to determine paragraph boundaries. ```cpp { g_autoptr(PangoLayout) layout = create_pango_layout(self); PangoLayoutLine* start = nullptr; PangoLayoutLine* end = nullptr; gint n_lines = pango_layout_get_line_count(layout); for (gint i = 0; i < n_lines; ++i) { PangoLayoutLine* line = pango_layout_get_line(layout, i); if (line->is_paragraph_start) { end = line; } if (start != nullptr && end != nullptr && offset >= start->start_index && offset <= end->start_index + end->length) { if (start_offset != nullptr) { *start_offset = start->start_index; } if (end_offset != nullptr) { *end_offset = end->start_index + end->length; } return get_substring(self, start->start_index, end->start_index + end->length); } if (line->is_paragraph_start) { start = line; } } return nullptr; } ``` -------------------------------- ### FlutterEngineTest Setup Method Source: https://api.flutter.dev/macos-embedder/_flutter_engine_test_utils_8mm_source.html Initializes the `FlutterEngineTest` fixture, setting up a `TestDartNativeResolver` and a `FlutterDartProject` with test fixtures, then creates a `FlutterEngine` instance. ```Objective-C++ FlutterEngineTest::FlutterEngineTest() = default; void FlutterEngineTest::SetUp() { native_resolver_ = std::make_shared(); NSString* fixtures = @(testing::GetFixturesPath()); project_ = [[FlutterDartProject alloc] initWithAssetsPath:fixtures ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]]; project_.rootIsolateCreateCallback = FlutterEngineTest::IsolateCreateCallback; engine_ = [[FlutterEngine alloc] initWithName:@"test" project:project_ allowHeadlessExecution:true]; } ``` -------------------------------- ### Implement fl_keyboard_layout_init for GObject Instance Setup Source: https://api.flutter.dev/linux-embedder/fl__keyboard__layout_8cc_source.html Initializes a new instance of FlKeyboardLayout, creating the hash table for storing group mappings. ```C static void fl_keyboard_layout_init(FlKeyboardLayout* self) { self->groups = g_hash_table_new_full( g_direct_hash, g_direct_equal, nullptr, reinterpret_cast(g_hash_table_unref)); } ``` -------------------------------- ### Initialize Software Compositor Class in C Source: https://api.flutter.dev/linux-embedder/fl__compositor__software_8cc_source.html Initializes the FlCompositorSoftwareClass by assigning virtual methods for presenting layers, getting frame size, rendering, and object disposal. This is part of the GObject type system setup. ```c FL_COMPOSITOR_CLASS(klass)->present_layers = fl_compositor_software_present_layers; FL_COMPOSITOR_CLASS(klass)->get_frame_size = fl_compositor_software_get_frame_size; FL_COMPOSITOR_CLASS(klass)->render = fl_compositor_software_render; G_OBJECT_CLASS(klass)->dispose = fl_compositor_software_dispose; ``` -------------------------------- ### Setup mock EGL surface and window view Source: https://api.flutter.dev/windows-embedder/flutter__windows__view__unittests_8cc_source.html Creates a mock EGL manager and window surface, then creates a FlutterWindowsView with mock binding handler. The surface is configured to report as valid. ```cpp auto egl_manager = std::make_unique(); auto surface = std::make_unique(); EXPECT_CALL(*surface.get(), IsValid).WillRepeatedly(Return(true)); EXPECT_CALL(*surface.get(), Destroy).WillOnce(Return(true)); std::unique_ptr view = engine->CreateView(std::make_unique>(), /*is_sized_to_content=*/false, BoxConstraints()); ViewModifier view_modifier{view.get()}; engine_modifier.SetEGLManager(std::move(egl_manager)); view_modifier.SetSurface(std::move(surface)); ``` -------------------------------- ### Ensure Only Active View Can Become First Responder (Partial) Source: https://api.flutter.dev/ios-embedder/_flutter_text_input_plugin_test_8mm_source.html This snippet shows the start of a loop intended to iterate through installed input views, likely to ensure that only the active view can become the first responder. ```Objective-C for (FlutterTextInputView* inputView in self.installedInputViews) { ``` -------------------------------- ### Initialize and Monitor Desktop Portal Settings (C++) Source: https://api.flutter.dev/linux-embedder/fl__settings__portal_8cc.html This function initializes the FlSettingsPortal by connecting to the D-Bus session bus, reading current desktop portal settings, and setting up a signal handler to monitor for changes. It returns TRUE on success or FALSE if the D-Bus proxy cannot be created. ```C++ gboolean fl_settings_portal_start | ( | FlSettingsPortal * | _portal_ , ---|---|---|--- | | GError ** | _error_ | ) | | fl_settings_portal_start: @portal: an #FlSettingsPortal. @error: (allow-none): #GError location to store the error occurring, or NULL. If `error` is not NULL, `*error` must be initialized (typically NULL, but an error from a previous call using GLib error handling is explicitly valid). Reads the current settings and starts monitoring for changes in the desktop portal settings. Returns: TRUE on success, or FALSE if the portal is not available. Definition at line 280 of file fl_settings_portal.cc. 280 { 281 g_return_val_if_fail(FL_IS_SETTINGS_PORTAL(self), false); 282 g_return_val_if_fail(self->dbus_proxy == nullptr, false); 283 284 self->dbus_proxy = g_dbus_proxy_new_for_bus_sync( 285 G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, nullptr, kPortalName, 286 kPortalPath, kPortalSettings, nullptr, error); 287 288 if (self->dbus_proxy == nullptr) { 289 return FALSE; 290 } 291 292 for (const FlSetting setting : kAllSettings) { 293 g_autoptr(GVariant) value = nullptr; 294 if (settings_portal_read(self->dbus_proxy, setting.ns, setting.key, 295 &value)) { 296 set_value(self, &setting, value); 297 } 298 } 299 300 g_signal_connect_object(self->dbus_proxy, "g-signal", 301 G_CALLBACK(settings_portal_changed_cb), self, 302 static_cast(0)); 303 304 return true; 305 } ``` -------------------------------- ### SetUp Method Implementation (C++) Source: https://api.flutter.dev/windows-embedder/classflutter_1_1_accessibility_plugin.html Sets up the message handler for the accessibility channel using a `BasicMessageChannel`. It processes incoming messages via `HandleMessage` and always returns an empty response, as the channel does not support error handling. ```C++ { BasicMessageChannel<> channel{binary_messenger, kAccessibilityChannelName, &StandardMessageCodec::GetInstance()}; channel.SetMessageHandler( [plugin](const EncodableValue& message, const MessageReply& reply) { HandleMessage(plugin, message); // The accessibility channel does not support error handling. // Always return an empty response even on failure. reply(EncodableValue{std::monostate{}}); }); } ``` -------------------------------- ### Set Up Flutter Engine and Key Embedder Responder Source: https://api.flutter.dev/linux-embedder/fl__key__embedder__responder__test_8cc_source.html Initialize a Flutter Dart project, create an engine, start it, and instantiate a key embedder responder. This is the standard setup for testing key event handling in the embedder. ```C g_autoptr(FlDartProject) project = fl_dart_project_new(); g_autoptr(FlEngine) engine = fl_engine_new(project); EXPECT_TRUE(fl_engine_start(engine, nullptr)); g_autoptr(FlKeyEmbedderResponder) responder = fl_key_embedder_responder_new(engine); ``` -------------------------------- ### void onBeginFrame() Source: https://api.flutter.dev/javadoc/io/flutter/plugin/platform/PlatformViewsController.html No description provided. ```APIDOC ## void onBeginFrame() ### Description No description provided. ### Method void onBeginFrame() ### Parameters (None) ``` -------------------------------- ### application:didFinishLaunchingWithOptions: Source: https://api.flutter.dev/ios-embedder/protocol_flutter_application_life_cycle_delegate-p.html Called when the application has finished launching. This method allows plugins to perform initialization tasks during app startup. Return NO to veto the application launch. ```APIDOC ## application:didFinishLaunchingWithOptions: ### Description Called if this has been registered for UIApplicationDelegate callbacks. Allows plugins to respond to application launch completion. ### Method Signature ```objc - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions ``` ### Parameters - **application** (UIApplication *) - Required - The singleton application instance - **launchOptions** (NSDictionary *) - Required - Dictionary containing launch options ### Return Value - **BOOL** - Return NO if this vetos application launch, YES otherwise ### Availability - Optional method ``` -------------------------------- ### Get OpenGL Frame Buffer Object for FlEngine Source: https://api.flutter.dev/linux-embedder/fl__engine_8cc_source.html This callback returns the ID of the frame buffer object (FBO) used by the FlEngine. In this implementation, it consistently returns 0, indicating a default FBO or a single FBO setup. ```cpp static uint32_t fl_engine_gl_get_fbo(void* user_data) { // There is only one frame buffer object - always return that. return 0; } ``` -------------------------------- ### Get Line at Offset in FlAccessibleTextField (C++) Source: https://api.flutter.dev/linux-embedder/fl__accessible__text__field_8cc.html Retrieves the text of the line containing the given offset within an `FlAccessibleTextField`, along with its start and end offsets. This function iterates through Pango layout lines to find the correct line. ```cpp { g_autoptr(PangoLayout) layout = create_pango_layout(self); GSList* lines = pango_layout_get_lines_readonly(layout); while (lines != nullptr) { PangoLayoutLine* line = static_cast(lines->data); if (offset >= line->start_index && offset <= line->start_index + line->length) { if (start_offset != nullptr) { *start_offset = line->start_index; } if (end_offset != nullptr) { *end_offset = line->start_index + line->length; } return get_substring(self, line->start_index, line->start_index + line->length); } lines = lines->next; } return nullptr; } ``` -------------------------------- ### onStart() Source: https://api.flutter.dev/javadoc/io/flutter/embedding/android/FlutterFragment.html Called when the fragment is visible to the user. ```APIDOC ## void onStart() ### Description Called when the fragment is visible to the user. ### Parameters None ``` -------------------------------- ### std::unique_ptr< StreamHandlerError< T > > OnListen (const T *arguments, std::unique_ptr< EventSink< T >> &&events) Source: https://api.flutter.dev/windows-embedder/classflutter_1_1_stream_handler.html This method is invoked when a new listener is registered for the stream. Implement this to perform any necessary setup for the stream and start sending events to the provided `EventSink`. ```APIDOC ## OnListen ### Description This method is invoked when a new listener is registered for the stream. Implement this to perform any necessary setup for the stream and start sending events to the provided `EventSink`. ### Method Signature `std::unique_ptr< StreamHandlerError< T > > OnListen (const T *arguments, std::unique_ptr< EventSink< T >> &&events)` ### Parameters #### Function Parameters - **arguments** (const T *) - Optional - Arguments passed during the listen request. - **events** (std::unique_ptr< EventSink< T >> &&) - Required - An `EventSink` object to which events should be sent. ### Return Value - **std::unique_ptr< StreamHandlerError< T > >** - Returns a `StreamHandlerError` if an error occurs during setup, otherwise `nullptr` on success. ``` -------------------------------- ### Get Generic String Segment at Offset in FlAccessibleTextField (C++) Source: https://api.flutter.dev/linux-embedder/fl__accessible__text__field_8cc.html A general-purpose function to retrieve a text segment defined by custom start and end boundary callbacks. It uses Pango log attributes to find the segment and returns the substring. ```cpp { g_autoptr(PangoLayout) layout = create_pango_layout(self); gint n_attrs = 0; const PangoLogAttr* attrs = pango_layout_get_log_attrs_readonly(layout, &n_attrs); while (start > 0 && !is_start(&attrs[start])) { --start; } if (start_offset != nullptr) { *start_offset = start; } while (end < n_attrs && !is_end(&attrs[end])) { ++end; } if (end_offset != nullptr) { *end_offset = end; } return get_substring(self, start, end); } ``` -------------------------------- ### Create New FlSettings Instance (C) Source: https://api.flutter.dev/linux-embedder/fl__settings_8h.html Creates a new `FlSettings` instance, attempting to use an XDG desktop portal. If the portal is unavailable, it falls back to GNOME settings. ```c { g_autoptr(FlSettingsPortal) portal = fl_settings_portal_new(); g_autoptr(GError) error = nullptr; if (!fl_settings_portal_start(portal, &error)) { g_debug("XDG desktop portal settings unavailable: %s", error->message); return fl_gnome_settings_new(); } return FL_SETTINGS(g_object_ref(portal)); } ``` -------------------------------- ### Handle system_initialization_complete Source: https://api.flutter.dev/linux-embedder/fl__platform__channel_8cc.html Notifies the platform that system initialization is complete and returns a success response. ```C { self->vtable->system_initialization_complete(self->user_data); return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr)); } ``` -------------------------------- ### Test FlMethodChannel Not Implemented Response Setup (C++) Source: https://api.flutter.dev/linux-embedder/fl__method__channel__test_8cc_source.html This C++ snippet initializes an `FlMethodChannel` and sets up a method call handler. It prepares the channel to receive method calls, but the response logic for 'not implemented' is not fully shown in this partial example. ```cpp TEST(FlMethodChannelTest, ReceiveMethodCallRespondNotImplemented) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new(); g_autoptr(FlMethodChannel) channel = fl_method_channel_new( FL_BINARY_MESSENGER(messenger), "test", FL_METHOD_CODEC(codec)); fl_method_channel_set_method_call_handler( channel, ```