Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions | Variables
flutter_glfw.cc File Reference
#include "flutter/shell/platform/glfw/public/flutter_glfw.h"
#include <GLFW/glfw3.h>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <string>
#include "flutter/common/constants.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h"
#include "flutter/shell/platform/common/incoming_message_dispatcher.h"
#include "flutter/shell/platform/common/path_utils.h"
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/glfw/glfw_event_loop.h"
#include "flutter/shell/platform/glfw/headless_event_loop.h"
#include "flutter/shell/platform/glfw/key_event_handler.h"
#include "flutter/shell/platform/glfw/keyboard_hook_handler.h"
#include "flutter/shell/platform/glfw/platform_handler.h"
#include "flutter/shell/platform/glfw/system_utils.h"
#include "flutter/shell/platform/glfw/text_input_plugin.h"

Go to the source code of this file.

Classes

struct  FlutterDesktopWindowControllerState
 
struct  FlutterDesktopWindow
 
struct  AOTDataDeleter
 
struct  FlutterDesktopEngineState
 
struct  FlutterDesktopPluginRegistrar
 
struct  FlutterDesktopMessenger
 

Macros

#define GLFW_TRUE   1
 
#define GLFW_FALSE   0
 

Typedefs

using UniqueGLFWwindowPtr = std::unique_ptr< GLFWwindow, void(*)(GLFWwindow *)>
 
using UniqueAotDataPtr = std::unique_ptr< _FlutterEngineAOTData, AOTDataDeleter >
 
using FlutterDesktopMessengerReferenceOwner = std::unique_ptr< FlutterDesktopMessenger, decltype(&FlutterDesktopMessengerRelease)>
 Maintains one ref on the FlutterDesktopMessenger's internal reference count.
 

Functions

FlutterDesktopMessengerRef FlutterDesktopMessengerAddRef (FlutterDesktopMessengerRef messenger)
 
void FlutterDesktopMessengerRelease (FlutterDesktopMessengerRef messenger)
 
bool FlutterDesktopMessengerIsAvailable (FlutterDesktopMessengerRef messenger)
 
FlutterDesktopMessengerRef FlutterDesktopMessengerLock (FlutterDesktopMessengerRef messenger)
 
void FlutterDesktopMessengerUnlock (FlutterDesktopMessengerRef messenger)
 
static FlutterDesktopWindowControllerStateGetWindowController (GLFWwindow *window)
 
static UniqueGLFWwindowPtr CreateShareWindowForWindow (GLFWwindow *window)
 
static FlutterDesktopMessage ConvertToDesktopMessage (const FlutterPlatformMessage &engine_message)
 
static double GetScreenCoordinatesPerInch ()
 
static void SendWindowMetrics (FlutterDesktopWindowControllerState *controller, int width, int height)
 
static void ConfigurePlatformTaskRunner (FlutterTaskRunnerDescription *task_runner, FlutterDesktopEngineState *engine_state)
 
static void GLFWFramebufferSizeCallback (GLFWwindow *window, int width_px, int height_px)
 
void GLFWWindowRefreshCallback (GLFWwindow *window)
 
static void SendPointerEventWithData (GLFWwindow *window, const FlutterPointerEvent &event_data)
 
static void SetEventLocationFromCursorPosition (GLFWwindow *window, FlutterPointerEvent *event_data)
 
static void SetEventPhaseFromCursorButtonState (GLFWwindow *window, FlutterPointerEvent *event_data, int64_t buttons)
 
static void GLFWCursorEnterCallback (GLFWwindow *window, int entered)
 
static void GLFWCursorPositionCallback (GLFWwindow *window, double x, double y)
 
static void GLFWMouseButtonCallback (GLFWwindow *window, int key, int action, int mods)
 
static void GLFWScrollCallback (GLFWwindow *window, double delta_x, double delta_y)
 
static void GLFWCharCallback (GLFWwindow *window, unsigned int code_point)
 
static void GLFWKeyCallback (GLFWwindow *window, int key, int scancode, int action, int mods)
 
static void SetHoverCallbacksEnabled (GLFWwindow *window, bool enabled)
 
static void GLFWAssignEventCallbacks (GLFWwindow *window)
 
static void GLFWClearEventCallbacks (GLFWwindow *window)
 
static void EngineOnFlutterPlatformMessage (const FlutterPlatformMessage *engine_message, void *user_data)
 
static bool EngineMakeContextCurrent (void *user_data)
 
static bool EngineMakeResourceContextCurrent (void *user_data)
 
static bool EngineClearContext (void *user_data)
 
static bool EnginePresent (void *user_data)
 
static uint32_t EngineGetActiveFbo (void *user_data)
 
static void * EngineProcResolver (void *user_data, const char *name)
 
static void GLFWClearCanvas (GLFWwindow *window)
 
static void GLFWErrorCallback (int error_code, const char *description)
 
UniqueAotDataPtr LoadAotData (const std::filesystem::path &aot_data_path)
 
static bool RunFlutterEngine (FlutterDesktopEngineState *engine_state, const FlutterDesktopEngineProperties &engine_properties, std::unique_ptr< flutter::EventLoop > event_loop)
 
static void SetUpLocales (FlutterDesktopEngineState *state)
 
static void SetUpCommonEngineState (FlutterDesktopEngineState *state, GLFWwindow *window)
 
bool FlutterDesktopInit ()
 
void FlutterDesktopTerminate ()
 
FlutterDesktopWindowControllerRef FlutterDesktopCreateWindow (const FlutterDesktopWindowProperties &window_properties, const FlutterDesktopEngineProperties &engine_properties)
 
void FlutterDesktopDestroyWindow (FlutterDesktopWindowControllerRef controller)
 
void FlutterDesktopWindowSetHoverEnabled (FlutterDesktopWindowRef flutter_window, bool enabled)
 
void FlutterDesktopWindowSetTitle (FlutterDesktopWindowRef flutter_window, const char *title)
 
void FlutterDesktopWindowSetIcon (FlutterDesktopWindowRef flutter_window, uint8_t *pixel_data, int width, int height)
 
void FlutterDesktopWindowGetFrame (FlutterDesktopWindowRef flutter_window, int *x, int *y, int *width, int *height)
 
void FlutterDesktopWindowSetFrame (FlutterDesktopWindowRef flutter_window, int x, int y, int width, int height)
 
double FlutterDesktopWindowGetScaleFactor (FlutterDesktopWindowRef flutter_window)
 
void FlutterDesktopWindowSetPixelRatioOverride (FlutterDesktopWindowRef flutter_window, double pixel_ratio)
 
void FlutterDesktopWindowSetSizeLimits (FlutterDesktopWindowRef flutter_window, FlutterDesktopSize minimum_size, FlutterDesktopSize maximum_size)
 
bool FlutterDesktopRunWindowEventLoopWithTimeout (FlutterDesktopWindowControllerRef controller, uint32_t timeout_milliseconds)
 
FlutterDesktopWindowRef FlutterDesktopGetWindow (FlutterDesktopWindowControllerRef controller)
 
FlutterDesktopEngineRef FlutterDesktopGetEngine (FlutterDesktopWindowControllerRef controller)
 
FlutterDesktopPluginRegistrarRef FlutterDesktopGetPluginRegistrar (FlutterDesktopEngineRef engine, const char *plugin_name)
 
FlutterDesktopEngineRef FlutterDesktopRunEngine (const FlutterDesktopEngineProperties &properties)
 
void FlutterDesktopRunEngineEventLoopWithTimeout (FlutterDesktopEngineRef engine, uint32_t timeout_milliseconds)
 
bool FlutterDesktopShutDownEngine (FlutterDesktopEngineRef engine)
 
void FlutterDesktopPluginRegistrarEnableInputBlocking (FlutterDesktopPluginRegistrarRef registrar, const char *channel)
 
FlutterDesktopMessengerRef FlutterDesktopPluginRegistrarGetMessenger (FlutterDesktopPluginRegistrarRef registrar)
 
void FlutterDesktopPluginRegistrarSetDestructionHandler (FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopOnPluginRegistrarDestroyed callback)
 
FlutterDesktopWindowRef FlutterDesktopPluginRegistrarGetWindow (FlutterDesktopPluginRegistrarRef registrar)
 
bool FlutterDesktopMessengerSendWithReply (FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size, const FlutterDesktopBinaryReply reply, void *user_data)
 
bool FlutterDesktopMessengerSend (FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size)
 
void FlutterDesktopMessengerSendResponse (FlutterDesktopMessengerRef messenger, const FlutterDesktopMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
 
void FlutterDesktopMessengerSetCallback (FlutterDesktopMessengerRef messenger, const char *channel, FlutterDesktopMessageCallback callback, void *user_data)
 
FlutterDesktopTextureRegistrarRef FlutterDesktopRegistrarGetTextureRegistrar (FlutterDesktopPluginRegistrarRef registrar)
 
int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture (FlutterDesktopTextureRegistrarRef texture_registrar, const FlutterDesktopTextureInfo *texture_info)
 
void FlutterDesktopTextureRegistrarUnregisterExternalTexture (FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id, void(*callback)(void *user_data), void *user_data)
 
bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable (FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id)
 

Variables

const int kFlutterDesktopDontCare = GLFW_DONT_CARE
 
static constexpr double kDpPerInch = 160.0
 

Macro Definition Documentation

◆ GLFW_FALSE

#define GLFW_FALSE   0

Definition at line 36 of file flutter_glfw.cc.

◆ GLFW_TRUE

#define GLFW_TRUE   1

Definition at line 33 of file flutter_glfw.cc.

Typedef Documentation

◆ FlutterDesktopMessengerReferenceOwner

Maintains one ref on the FlutterDesktopMessenger's internal reference count.

Definition at line 112 of file flutter_glfw.cc.

◆ UniqueAotDataPtr

Definition at line 110 of file flutter_glfw.cc.

◆ UniqueGLFWwindowPtr

using UniqueGLFWwindowPtr = std::unique_ptr<GLFWwindow, void (*)(GLFWwindow*)>

Definition at line 39 of file flutter_glfw.cc.

Function Documentation

◆ ConfigurePlatformTaskRunner()

static void ConfigurePlatformTaskRunner ( FlutterTaskRunnerDescription task_runner,
FlutterDesktopEngineState engine_state 
)
static

Definition at line 309 of file flutter_glfw.cc.

311 {
312 task_runner->struct_size = sizeof(FlutterTaskRunnerDescription);
313 task_runner->user_data = engine_state;
314 task_runner->runs_task_on_current_thread_callback = [](void* state) -> bool {
315 return reinterpret_cast<FlutterDesktopEngineState*>(state)
316 ->event_loop->RunsTasksOnCurrentThread();
317 };
318 task_runner->post_task_callback =
319 [](FlutterTask task, uint64_t target_time_nanos, void* state) -> void {
320 reinterpret_cast<FlutterDesktopEngineState*>(state)->event_loop->PostTask(
321 task, target_time_nanos);
322 };
323}
AtkStateType state
size_t struct_size
The size of this struct. Must be sizeof(FlutterTaskRunnerDescription).
Definition embedder.h:1564
BoolCallback runs_task_on_current_thread_callback
Definition embedder.h:1570
FlutterTaskRunnerPostTaskCallback post_task_callback
Definition embedder.h:1581

◆ ConvertToDesktopMessage()

static FlutterDesktopMessage ConvertToDesktopMessage ( const FlutterPlatformMessage engine_message)
static

Definition at line 251 of file flutter_glfw.cc.

252 {
254 message.struct_size = sizeof(message);
255 message.channel = engine_message.channel;
256 message.message = engine_message.message;
257 message.message_size = engine_message.message_size;
258 message.response_handle = engine_message.response_handle;
259 return message;
260}
Win32Message message
const FlutterPlatformMessageResponseHandle * response_handle
Definition embedder.h:1172
const char * channel
Definition embedder.h:1163
const uint8_t * message
Definition embedder.h:1164

◆ CreateShareWindowForWindow()

static UniqueGLFWwindowPtr CreateShareWindowForWindow ( GLFWwindow *  window)
static

Definition at line 237 of file flutter_glfw.cc.

237 {
238 glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
239 glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
240#if defined(__linux__)
241 glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
242 glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
243 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
244#endif
245 GLFWwindow* share_window = glfwCreateWindow(1, 1, "", NULL, window);
246 glfwDefaultWindowHints();
247 return UniqueGLFWwindowPtr(share_window, glfwDestroyWindow);
248}
GLFWwindow * window
Definition main.cc:45
std::unique_ptr< GLFWwindow, void(*)(GLFWwindow *)> UniqueGLFWwindowPtr
#define GLFW_FALSE

◆ EngineClearContext()

static bool EngineClearContext ( void *  user_data)
static

Definition at line 621 of file flutter_glfw.cc.

621 {
622 FlutterDesktopEngineState* engine_state =
624 FlutterDesktopWindowControllerState* window_controller =
625 engine_state->window_controller;
626 if (!window_controller) {
627 return false;
628 }
629 glfwMakeContextCurrent(nullptr);
630 return true;
631}
FlutterDesktopWindowControllerState * window_controller

◆ EngineGetActiveFbo()

static uint32_t EngineGetActiveFbo ( void *  user_data)
static

Definition at line 645 of file flutter_glfw.cc.

645 {
646 return 0;
647}

◆ EngineMakeContextCurrent()

static bool EngineMakeContextCurrent ( void *  user_data)
static

Definition at line 597 of file flutter_glfw.cc.

597 {
598 FlutterDesktopEngineState* engine_state =
600 FlutterDesktopWindowControllerState* window_controller =
601 engine_state->window_controller;
602 if (!window_controller) {
603 return false;
604 }
605 glfwMakeContextCurrent(window_controller->window.get());
606 return true;
607}

◆ EngineMakeResourceContextCurrent()

static bool EngineMakeResourceContextCurrent ( void *  user_data)
static

Definition at line 609 of file flutter_glfw.cc.

609 {
610 FlutterDesktopEngineState* engine_state =
612 FlutterDesktopWindowControllerState* window_controller =
613 engine_state->window_controller;
614 if (!window_controller) {
615 return false;
616 }
617 glfwMakeContextCurrent(window_controller->resource_window.get());
618 return true;
619}

◆ EngineOnFlutterPlatformMessage()

static void EngineOnFlutterPlatformMessage ( const FlutterPlatformMessage engine_message,
void *  user_data 
)
static

Definition at line 566 of file flutter_glfw.cc.

568 {
569 if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) {
570 std::cerr << "Invalid message size received. Expected: "
571 << sizeof(FlutterPlatformMessage) << " but received "
572 << engine_message->struct_size << std::endl;
573 return;
574 }
575
576 FlutterDesktopEngineState* engine_state =
578 GLFWwindow* window = engine_state->window_controller == nullptr
579 ? nullptr
580 : engine_state->window_controller->window.get();
581
582 auto message = ConvertToDesktopMessage(*engine_message);
583 engine_state->message_dispatcher->HandleMessage(
584 message,
585 [window] {
586 if (window) {
588 }
589 },
590 [window] {
591 if (window) {
593 }
594 });
595}
static FlutterDesktopMessage ConvertToDesktopMessage(const FlutterPlatformMessage &engine_message)
static void GLFWAssignEventCallbacks(GLFWwindow *window)
static void GLFWClearEventCallbacks(GLFWwindow *window)
std::unique_ptr< flutter::IncomingMessageDispatcher > message_dispatcher
size_t struct_size
The size of this struct. Must be sizeof(FlutterPlatformMessage).
Definition embedder.h:1162

◆ EnginePresent()

static bool EnginePresent ( void *  user_data)
static

Definition at line 633 of file flutter_glfw.cc.

633 {
634 FlutterDesktopEngineState* engine_state =
636 FlutterDesktopWindowControllerState* window_controller =
637 engine_state->window_controller;
638 if (!window_controller) {
639 return false;
640 }
641 glfwSwapBuffers(window_controller->window.get());
642 return true;
643}

◆ EngineProcResolver()

static void * EngineProcResolver ( void *  user_data,
const char *  name 
)
static

Definition at line 651 of file flutter_glfw.cc.

651 {
652 return reinterpret_cast<void*>(glfwGetProcAddress(name));
653}
const char * name
Definition fuchsia.cc:50

◆ FlutterDesktopCreateWindow()

FlutterDesktopWindowControllerRef FlutterDesktopCreateWindow ( const FlutterDesktopWindowProperties window_properties,
const FlutterDesktopEngineProperties engine_properties 
)

Definition at line 859 of file flutter_glfw.cc.

861 {
862 auto state = std::make_unique<FlutterDesktopWindowControllerState>();
863
864 // Create the window, and set the state as its user data.
865 if (window_properties.prevent_resize) {
866 glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
867 }
868#if defined(__linux__)
869 glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
870#endif
871 state->window = UniqueGLFWwindowPtr(
872 glfwCreateWindow(window_properties.width, window_properties.height,
873 window_properties.title, NULL, NULL),
874 glfwDestroyWindow);
875 glfwDefaultWindowHints();
876 GLFWwindow* window = state->window.get();
877 if (window == nullptr) {
878 return nullptr;
879 }
881 glfwSetWindowUserPointer(window, state.get());
882
883 // Create the share window before starting the engine, since it may call
884 // EngineMakeResourceContextCurrent immediately.
885 state->resource_window = CreateShareWindowForWindow(window);
886
887 state->engine = std::make_unique<FlutterDesktopEngineState>();
888 state->engine->window_controller = state.get();
889
890 // Create an event loop for the window. It is not running yet.
891 auto event_loop = std::make_unique<flutter::GLFWEventLoop>(
892 std::this_thread::get_id(), // main GLFW thread
893 [engine_state = state->engine.get()](const auto* task) {
894 if (FlutterEngineRunTask(engine_state->flutter_engine, task) !=
895 kSuccess) {
896 std::cerr << "Could not post an engine task." << std::endl;
897 }
898 });
899
900 // Start the engine.
901 if (!RunFlutterEngine(state->engine.get(), engine_properties,
902 std::move(event_loop))) {
903 return nullptr;
904 }
905 SetUpCommonEngineState(state->engine.get(), window);
906
907 state->window_wrapper = std::make_unique<FlutterDesktopWindow>();
908 state->window_wrapper->window = window;
909
910 // Set up the keyboard handlers
911 auto internal_plugin_messenger =
912 state->engine->internal_plugin_registrar->messenger();
913 state->keyboard_hook_handlers.push_back(
914 std::make_unique<flutter::KeyEventHandler>(internal_plugin_messenger));
915 state->keyboard_hook_handlers.push_back(
916 std::make_unique<flutter::TextInputPlugin>(internal_plugin_messenger));
917
918 // Trigger an initial size callback to send size information to Flutter.
919 state->monitor_screen_coordinates_per_inch = GetScreenCoordinatesPerInch();
920 int width_px, height_px;
921 glfwGetFramebufferSize(window, &width_px, &height_px);
922 GLFWFramebufferSizeCallback(window, width_px, height_px);
923
924 // Set up GLFW callbacks for the window.
925 glfwSetFramebufferSizeCallback(window, GLFWFramebufferSizeCallback);
926 glfwSetWindowRefreshCallback(window, GLFWWindowRefreshCallback);
928
929 return state.release();
930}
void GLFWWindowRefreshCallback(GLFWwindow *window)
static UniqueGLFWwindowPtr CreateShareWindowForWindow(GLFWwindow *window)
static bool RunFlutterEngine(FlutterDesktopEngineState *engine_state, const FlutterDesktopEngineProperties &engine_properties, std::unique_ptr< flutter::EventLoop > event_loop)
static void GLFWFramebufferSizeCallback(GLFWwindow *window, int width_px, int height_px)
static void SetUpCommonEngineState(FlutterDesktopEngineState *state, GLFWwindow *window)
static double GetScreenCoordinatesPerInch()
static void GLFWClearCanvas(GLFWwindow *window)

◆ FlutterDesktopDestroyWindow()

void FlutterDesktopDestroyWindow ( FlutterDesktopWindowControllerRef  controller)

Definition at line 932 of file flutter_glfw.cc.

932 {
933 controller->engine->messenger->SetEngine(nullptr);
935 controller->engine->plugin_registrar.get();
936 if (registrar->destruction_handler) {
937 registrar->destruction_handler(registrar);
938 }
939 FlutterEngineShutdown(controller->engine->flutter_engine);
940 delete controller;
941}
FlutterEngineResult FlutterEngineShutdown(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Shuts down a Flutter engine instance. The engine handle is no longer valid for any calls in the embed...
Definition embedder.cc:2303
FlutterDesktopOnPluginRegistrarDestroyed destruction_handler
std::unique_ptr< FlutterDesktopEngineState > engine

◆ FlutterDesktopGetEngine()

FlutterDesktopEngineRef FlutterDesktopGetEngine ( FlutterDesktopWindowControllerRef  controller)

Definition at line 1046 of file flutter_glfw.cc.

1047 {
1048 return controller->engine.get();
1049}

◆ FlutterDesktopGetPluginRegistrar()

FlutterDesktopPluginRegistrarRef FlutterDesktopGetPluginRegistrar ( FlutterDesktopEngineRef  engine,
const char *  plugin_name 
)

Definition at line 1051 of file flutter_glfw.cc.

1053 {
1054 // Currently, one registrar acts as the registrar for all plugins, so the
1055 // name is ignored. It is part of the API to reduce churn in the future when
1056 // aligning more closely with the Flutter registrar system.
1057 return engine->plugin_registrar.get();
1058}
FlutterEngine engine
Definition main.cc:68

◆ FlutterDesktopGetWindow()

FlutterDesktopWindowRef FlutterDesktopGetWindow ( FlutterDesktopWindowControllerRef  controller)

Definition at line 1038 of file flutter_glfw.cc.

1039 {
1040 // Currently, one registrar acts as the registrar for all plugins, so the
1041 // name is ignored. It is part of the API to reduce churn in the future when
1042 // aligning more closely with the Flutter registrar system.
1043 return controller->window_wrapper.get();
1044}
std::unique_ptr< FlutterDesktopWindow > window_wrapper

◆ FlutterDesktopInit()

bool FlutterDesktopInit ( )

Definition at line 849 of file flutter_glfw.cc.

849 {
850 // Before making any GLFW calls, set up a logging error handler.
851 glfwSetErrorCallback(GLFWErrorCallback);
852 return glfwInit();
853}
static void GLFWErrorCallback(int error_code, const char *description)

◆ FlutterDesktopMessengerAddRef()

FlutterDesktopMessengerRef FlutterDesktopMessengerAddRef ( FlutterDesktopMessengerRef  messenger)

Definition at line 204 of file flutter_glfw.cc.

205 {
206 messenger->AddRef();
207 return messenger;
208}

◆ FlutterDesktopMessengerIsAvailable()

bool FlutterDesktopMessengerIsAvailable ( FlutterDesktopMessengerRef  messenger)

Definition at line 214 of file flutter_glfw.cc.

214 {
215 return messenger->GetEngine() != nullptr;
216}
FlutterDesktopEngineState * GetEngine() const
Getter for the engine field.

◆ FlutterDesktopMessengerLock()

FlutterDesktopMessengerRef FlutterDesktopMessengerLock ( FlutterDesktopMessengerRef  messenger)

Definition at line 218 of file flutter_glfw.cc.

219 {
220 messenger->GetMutex().lock();
221 return messenger;
222}

◆ FlutterDesktopMessengerRelease()

void FlutterDesktopMessengerRelease ( FlutterDesktopMessengerRef  messenger)

Definition at line 210 of file flutter_glfw.cc.

210 {
211 messenger->Release();
212}

◆ FlutterDesktopMessengerSend()

bool FlutterDesktopMessengerSend ( FlutterDesktopMessengerRef  messenger,
const char *  channel,
const uint8_t *  message,
const size_t  message_size 
)

Definition at line 1160 of file flutter_glfw.cc.

1163 {
1164 return FlutterDesktopMessengerSendWithReply(messenger, channel, message,
1165 message_size, nullptr, nullptr);
1166}
bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size, const FlutterDesktopBinaryReply reply, void *user_data)

◆ FlutterDesktopMessengerSendResponse()

void FlutterDesktopMessengerSendResponse ( FlutterDesktopMessengerRef  messenger,
const FlutterDesktopMessageResponseHandle handle,
const uint8_t *  data,
size_t  data_length 
)

Definition at line 1168 of file flutter_glfw.cc.

1172 {
1174 messenger->GetEngine()->flutter_engine, handle, data, data_length);
1175}
FlutterEngineResult FlutterEngineSendPlatformMessageResponse(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
Send a response from the native side to a platform message from the Dart Flutter application.
Definition embedder.cc:2731

◆ FlutterDesktopMessengerSendWithReply()

bool FlutterDesktopMessengerSendWithReply ( FlutterDesktopMessengerRef  messenger,
const char *  channel,
const uint8_t *  message,
const size_t  message_size,
const FlutterDesktopBinaryReply  reply,
void *  user_data 
)

Definition at line 1124 of file flutter_glfw.cc.

1129 {
1130 FlutterPlatformMessageResponseHandle* response_handle = nullptr;
1131 if (reply != nullptr && user_data != nullptr) {
1133 messenger->GetEngine()->flutter_engine, reply, user_data,
1134 &response_handle);
1135 if (result != kSuccess) {
1136 std::cout << "Failed to create response handle\n";
1137 return false;
1138 }
1139 }
1140
1141 FlutterPlatformMessage platform_message = {
1142 sizeof(FlutterPlatformMessage),
1143 channel,
1144 message,
1145 message_size,
1146 response_handle,
1147 };
1148
1150 messenger->GetEngine()->flutter_engine, &platform_message);
1151
1152 if (response_handle != nullptr) {
1154 messenger->GetEngine()->flutter_engine, response_handle);
1155 }
1156
1157 return message_result == kSuccess;
1158}
FlutterEngineResult FlutterPlatformMessageCreateResponseHandle(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterDataCallback data_callback, void *user_data, FlutterPlatformMessageResponseHandle **response_out)
Creates a platform message response handle that allows the embedder to set a native callback for a re...
Definition embedder.cc:2681
FlutterEngineResult FlutterEngineSendPlatformMessage(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessage *flutter_message)
Definition embedder.cc:2630
FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterPlatformMessageResponseHandle *response)
Collects the handle created using FlutterPlatformMessageCreateResponseHandle.
Definition embedder.cc:2716
FlutterEngineResult
Definition embedder.h:72
@ kSuccess
Definition embedder.h:73
GAsyncResult * result

◆ FlutterDesktopMessengerSetCallback()

void FlutterDesktopMessengerSetCallback ( FlutterDesktopMessengerRef  messenger,
const char *  channel,
FlutterDesktopMessageCallback  callback,
void *  user_data 
)

Definition at line 1177 of file flutter_glfw.cc.

1180 {
1181 messenger->GetEngine()->message_dispatcher->SetMessageCallback(
1182 channel, callback, user_data);
1183}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ FlutterDesktopMessengerUnlock()

void FlutterDesktopMessengerUnlock ( FlutterDesktopMessengerRef  messenger)

Definition at line 224 of file flutter_glfw.cc.

224 {
225 messenger->GetMutex().unlock();
226}

◆ FlutterDesktopPluginRegistrarEnableInputBlocking()

void FlutterDesktopPluginRegistrarEnableInputBlocking ( FlutterDesktopPluginRegistrarRef  registrar,
const char *  channel 
)

Definition at line 1097 of file flutter_glfw.cc.

1099 {
1100 registrar->engine->message_dispatcher->EnableInputBlockingForChannel(channel);
1101}
FlutterDesktopEngineState * engine

◆ FlutterDesktopPluginRegistrarGetMessenger()

FlutterDesktopMessengerRef FlutterDesktopPluginRegistrarGetMessenger ( FlutterDesktopPluginRegistrarRef  registrar)

Definition at line 1103 of file flutter_glfw.cc.

1104 {
1105 return registrar->engine->messenger.get();
1106}
FlutterDesktopMessengerReferenceOwner messenger

◆ FlutterDesktopPluginRegistrarGetWindow()

FlutterDesktopWindowRef FlutterDesktopPluginRegistrarGetWindow ( FlutterDesktopPluginRegistrarRef  registrar)

Definition at line 1114 of file flutter_glfw.cc.

1115 {
1117 registrar->engine->window_controller;
1118 if (!controller) {
1119 return nullptr;
1120 }
1121 return controller->window_wrapper.get();
1122}

◆ FlutterDesktopPluginRegistrarSetDestructionHandler()

void FlutterDesktopPluginRegistrarSetDestructionHandler ( FlutterDesktopPluginRegistrarRef  registrar,
FlutterDesktopOnPluginRegistrarDestroyed  callback 
)

Definition at line 1108 of file flutter_glfw.cc.

1110 {
1111 registrar->destruction_handler = callback;
1112}

◆ FlutterDesktopRegistrarGetTextureRegistrar()

FlutterDesktopTextureRegistrarRef FlutterDesktopRegistrarGetTextureRegistrar ( FlutterDesktopPluginRegistrarRef  registrar)

Definition at line 1185 of file flutter_glfw.cc.

1186 {
1187 std::cerr << "GLFW Texture support is not implemented yet." << std::endl;
1188 return nullptr;
1189}

◆ FlutterDesktopRunEngine()

FlutterDesktopEngineRef FlutterDesktopRunEngine ( const FlutterDesktopEngineProperties properties)

Definition at line 1060 of file flutter_glfw.cc.

1061 {
1062 auto engine_state = std::make_unique<FlutterDesktopEngineState>();
1063
1064 auto event_loop = std::make_unique<flutter::HeadlessEventLoop>(
1065 std::this_thread::get_id(),
1066 [state = engine_state.get()](const auto* task) {
1067 if (FlutterEngineRunTask(state->flutter_engine, task) != kSuccess) {
1068 std::cerr << "Could not post an engine task." << std::endl;
1069 }
1070 });
1071
1072 if (!RunFlutterEngine(engine_state.get(), properties,
1073 std::move(event_loop))) {
1074 return nullptr;
1075 }
1076 SetUpCommonEngineState(engine_state.get(), nullptr);
1077
1078 return engine_state.release();
1079}

◆ FlutterDesktopRunEngineEventLoopWithTimeout()

void FlutterDesktopRunEngineEventLoopWithTimeout ( FlutterDesktopEngineRef  engine,
uint32_t  timeout_milliseconds 
)

Definition at line 1081 of file flutter_glfw.cc.

1083 {
1084 std::chrono::nanoseconds wait_duration =
1085 timeout_milliseconds == 0
1086 ? std::chrono::nanoseconds::max()
1087 : std::chrono::milliseconds(timeout_milliseconds);
1088 engine->event_loop->WaitForEvents(wait_duration);
1089}
Definition ref_ptr.h:256

◆ FlutterDesktopRunWindowEventLoopWithTimeout()

bool FlutterDesktopRunWindowEventLoopWithTimeout ( FlutterDesktopWindowControllerRef  controller,
uint32_t  timeout_milliseconds 
)

Definition at line 1030 of file flutter_glfw.cc.

1032 {
1034 timeout_milliseconds);
1035 return !glfwWindowShouldClose(controller->window.get());
1036}
void FlutterDesktopRunEngineEventLoopWithTimeout(FlutterDesktopEngineRef engine, uint32_t timeout_milliseconds)

◆ FlutterDesktopShutDownEngine()

bool FlutterDesktopShutDownEngine ( FlutterDesktopEngineRef  engine)

Definition at line 1091 of file flutter_glfw.cc.

1091 {
1092 auto result = FlutterEngineShutdown(engine->flutter_engine);
1093 delete engine;
1094 return (result == kSuccess);
1095}

◆ FlutterDesktopTerminate()

void FlutterDesktopTerminate ( )

Definition at line 855 of file flutter_glfw.cc.

855 {
856 glfwTerminate();
857}

◆ FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable()

bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable ( FlutterDesktopTextureRegistrarRef  texture_registrar,
int64_t  texture_id 
)

Definition at line 1206 of file flutter_glfw.cc.

1208 {
1209 std::cerr << "GLFW Texture support is not implemented yet." << std::endl;
1210 return false;
1211}

◆ FlutterDesktopTextureRegistrarRegisterExternalTexture()

int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture ( FlutterDesktopTextureRegistrarRef  texture_registrar,
const FlutterDesktopTextureInfo texture_info 
)

Definition at line 1191 of file flutter_glfw.cc.

1193 {
1194 std::cerr << "GLFW Texture support is not implemented yet." << std::endl;
1195 return -1;
1196}

◆ FlutterDesktopTextureRegistrarUnregisterExternalTexture()

void FlutterDesktopTextureRegistrarUnregisterExternalTexture ( FlutterDesktopTextureRegistrarRef  texture_registrar,
int64_t  texture_id,
void(*)(void *user_data callback,
void *  user_data 
)

Definition at line 1198 of file flutter_glfw.cc.

1202 {
1203 std::cerr << "GLFW Texture support is not implemented yet." << std::endl;
1204}

◆ FlutterDesktopWindowGetFrame()

void FlutterDesktopWindowGetFrame ( FlutterDesktopWindowRef  flutter_window,
int x,
int y,
int width,
int height 
)

Definition at line 963 of file flutter_glfw.cc.

967 {
968 glfwGetWindowPos(flutter_window->window, x, y);
969 glfwGetWindowSize(flutter_window->window, width, height);
970 // The above gives content area size and position; adjust for the window
971 // decoration to give actual window frame.
972 int frame_left, frame_top, frame_right, frame_bottom;
973 glfwGetWindowFrameSize(flutter_window->window, &frame_left, &frame_top,
974 &frame_right, &frame_bottom);
975 if (x) {
976 *x -= frame_left;
977 }
978 if (y) {
979 *y -= frame_top;
980 }
981 if (width) {
982 *width += frame_left + frame_right;
983 }
984 if (height) {
985 *height += frame_top + frame_bottom;
986 }
987}
double y
double x
int32_t height
int32_t width

◆ FlutterDesktopWindowGetScaleFactor()

double FlutterDesktopWindowGetScaleFactor ( FlutterDesktopWindowRef  flutter_window)

Definition at line 1004 of file flutter_glfw.cc.

1005 {
1006 return flutter_window->pixels_per_screen_coordinate;
1007}
double pixels_per_screen_coordinate

◆ FlutterDesktopWindowSetFrame()

void FlutterDesktopWindowSetFrame ( FlutterDesktopWindowRef  flutter_window,
int  x,
int  y,
int  width,
int  height 
)

Definition at line 989 of file flutter_glfw.cc.

993 {
994 // Get the window decoration sizes to adjust, since the GLFW setters take
995 // content position and size.
996 int frame_left, frame_top, frame_right, frame_bottom;
997 glfwGetWindowFrameSize(flutter_window->window, &frame_left, &frame_top,
998 &frame_right, &frame_bottom);
999 glfwSetWindowPos(flutter_window->window, x + frame_left, y + frame_top);
1000 glfwSetWindowSize(flutter_window->window, width - frame_left - frame_right,
1001 height - frame_top - frame_bottom);
1002}

◆ FlutterDesktopWindowSetHoverEnabled()

void FlutterDesktopWindowSetHoverEnabled ( FlutterDesktopWindowRef  flutter_window,
bool  enabled 
)

Definition at line 943 of file flutter_glfw.cc.

944 {
945 flutter_window->hover_tracking_enabled = enabled;
946 SetHoverCallbacksEnabled(flutter_window->window, enabled);
947}
static void SetHoverCallbacksEnabled(GLFWwindow *window, bool enabled)

◆ FlutterDesktopWindowSetIcon()

void FlutterDesktopWindowSetIcon ( FlutterDesktopWindowRef  flutter_window,
uint8_t *  pixel_data,
int  width,
int  height 
)

Definition at line 955 of file flutter_glfw.cc.

958 {
959 GLFWimage image = {width, height, static_cast<unsigned char*>(pixel_data)};
960 glfwSetWindowIcon(flutter_window->window, pixel_data ? 1 : 0, &image);
961}
sk_sp< SkImage > image
Definition examples.cpp:29

◆ FlutterDesktopWindowSetPixelRatioOverride()

void FlutterDesktopWindowSetPixelRatioOverride ( FlutterDesktopWindowRef  flutter_window,
double  pixel_ratio 
)

Definition at line 1009 of file flutter_glfw.cc.

1011 {
1012 flutter_window->pixel_ratio_override = pixel_ratio;
1013 // Send a metrics update using the new pixel ratio.
1014 int width_px, height_px;
1015 glfwGetFramebufferSize(flutter_window->window, &width_px, &height_px);
1016 if (width_px > 0 && height_px > 0) {
1017 auto* controller = GetWindowController(flutter_window->window);
1018 SendWindowMetrics(controller, width_px, height_px);
1019 }
1020}
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)
static void SendWindowMetrics(FlutterDesktopWindowControllerState *controller, int width, int height)

◆ FlutterDesktopWindowSetSizeLimits()

void FlutterDesktopWindowSetSizeLimits ( FlutterDesktopWindowRef  flutter_window,
FlutterDesktopSize  minimum_size,
FlutterDesktopSize  maximum_size 
)

Definition at line 1022 of file flutter_glfw.cc.

1024 {
1025 glfwSetWindowSizeLimits(flutter_window->window, minimum_size.width,
1026 minimum_size.height, maximum_size.width,
1027 maximum_size.height);
1028}

◆ FlutterDesktopWindowSetTitle()

void FlutterDesktopWindowSetTitle ( FlutterDesktopWindowRef  flutter_window,
const char *  title 
)

Definition at line 949 of file flutter_glfw.cc.

950 {
951 GLFWwindow* window = flutter_window->window;
952 glfwSetWindowTitle(window, title);
953}

◆ GetScreenCoordinatesPerInch()

static double GetScreenCoordinatesPerInch ( )
static

Definition at line 265 of file flutter_glfw.cc.

265 {
266 auto* primary_monitor = glfwGetPrimaryMonitor();
267 if (primary_monitor == nullptr) {
268 return kDpPerInch;
269 }
270 auto* primary_monitor_mode = glfwGetVideoMode(primary_monitor);
271 int primary_monitor_width_mm;
272 glfwGetMonitorPhysicalSize(primary_monitor, &primary_monitor_width_mm,
273 nullptr);
274 if (primary_monitor_width_mm == 0) {
275 return kDpPerInch;
276 }
277 return primary_monitor_mode->width / (primary_monitor_width_mm / 25.4);
278}
static constexpr double kDpPerInch

◆ GetWindowController()

static FlutterDesktopWindowControllerState * GetWindowController ( GLFWwindow *  window)
static

Definition at line 229 of file flutter_glfw.cc.

230 {
231 return reinterpret_cast<FlutterDesktopWindowControllerState*>(
232 glfwGetWindowUserPointer(window));
233}

◆ GLFWAssignEventCallbacks()

static void GLFWAssignEventCallbacks ( GLFWwindow *  window)
static

Definition at line 544 of file flutter_glfw.cc.

544 {
545 glfwPollEvents();
546 glfwSetKeyCallback(window, GLFWKeyCallback);
547 glfwSetCharCallback(window, GLFWCharCallback);
548 glfwSetMouseButtonCallback(window, GLFWMouseButtonCallback);
549 glfwSetScrollCallback(window, GLFWScrollCallback);
550 if (GetWindowController(window)->window_wrapper->hover_tracking_enabled) {
552 }
553}
static void GLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
static void GLFWCharCallback(GLFWwindow *window, unsigned int code_point)
static void GLFWMouseButtonCallback(GLFWwindow *window, int key, int action, int mods)
static void GLFWScrollCallback(GLFWwindow *window, double delta_x, double delta_y)

◆ GLFWCharCallback()

static void GLFWCharCallback ( GLFWwindow *  window,
unsigned int  code_point 
)
static

Definition at line 516 of file flutter_glfw.cc.

516 {
517 for (const auto& handler :
518 GetWindowController(window)->keyboard_hook_handlers) {
519 handler->CharHook(window, code_point);
520 }
521}

◆ GLFWClearCanvas()

static void GLFWClearCanvas ( GLFWwindow *  window)
static

Definition at line 663 of file flutter_glfw.cc.

663 {
664 glfwMakeContextCurrent(window);
665 // This color is Material Blue Grey.
666 glClearColor(236.0f / 255.0f, 239.0f / 255.0f, 241.0f / 255.0f, 0.0f);
667 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
668 glFlush();
669 glfwSwapBuffers(window);
670 glfwMakeContextCurrent(nullptr);
671}

◆ GLFWClearEventCallbacks()

static void GLFWClearEventCallbacks ( GLFWwindow *  window)
static

Definition at line 556 of file flutter_glfw.cc.

556 {
557 glfwSetKeyCallback(window, nullptr);
558 glfwSetCharCallback(window, nullptr);
559 glfwSetMouseButtonCallback(window, nullptr);
560 glfwSetScrollCallback(window, nullptr);
562}

◆ GLFWCursorEnterCallback()

static void GLFWCursorEnterCallback ( GLFWwindow *  window,
int  entered 
)
static

Definition at line 439 of file flutter_glfw.cc.

439 {
440 FlutterPointerEvent event = {};
441 event.phase =
445}
@ kRemove
Definition embedder.h:993
@ kAdd
Definition embedder.h:988
FlKeyEvent * event
static void SendPointerEventWithData(GLFWwindow *window, const FlutterPointerEvent &event_data)
static void SetEventLocationFromCursorPosition(GLFWwindow *window, FlutterPointerEvent *event_data)
FlutterPointerPhase phase
Definition embedder.h:1035

◆ GLFWCursorPositionCallback()

static void GLFWCursorPositionCallback ( GLFWwindow *  window,
double  x,
double  y 
)
static

Definition at line 448 of file flutter_glfw.cc.

448 {
449 FlutterPointerEvent event = {};
450 event.x = x;
451 event.y = y;
452 auto* controller = GetWindowController(window);
453 SetEventPhaseFromCursorButtonState(window, &event, controller->buttons);
455}
static void SetEventPhaseFromCursorButtonState(GLFWwindow *window, FlutterPointerEvent *event_data, int64_t buttons)
double x
The x coordinate of the pointer event in physical pixels.
Definition embedder.h:1041

◆ GLFWErrorCallback()

static void GLFWErrorCallback ( int  error_code,
const char *  description 
)
static

Definition at line 673 of file flutter_glfw.cc.

673 {
674 std::cerr << "GLFW error " << error_code << ": " << description << std::endl;
675}

◆ GLFWFramebufferSizeCallback()

static void GLFWFramebufferSizeCallback ( GLFWwindow *  window,
int  width_px,
int  height_px 
)
static

Definition at line 327 of file flutter_glfw.cc.

329 {
330 int width;
331 glfwGetWindowSize(window, &width, nullptr);
332 auto* controller = GetWindowController(window);
333 controller->window_wrapper->pixels_per_screen_coordinate =
334 width > 0 ? width_px / width : 1;
335
336 SendWindowMetrics(controller, width_px, height_px);
337 controller->window_wrapper->skip_next_window_refresh = true;
338}

◆ GLFWKeyCallback()

static void GLFWKeyCallback ( GLFWwindow *  window,
int  key,
int  scancode,
int  action,
int  mods 
)
static

Definition at line 524 of file flutter_glfw.cc.

528 {
529 for (const auto& handler :
530 GetWindowController(window)->keyboard_hook_handlers) {
531 handler->KeyboardHook(window, key, scancode, action, mods);
532 }
533}

◆ GLFWMouseButtonCallback()

static void GLFWMouseButtonCallback ( GLFWwindow *  window,
int  key,
int  action,
int  mods 
)
static

Definition at line 458 of file flutter_glfw.cc.

461 {
462 int64_t button;
463 if (key == GLFW_MOUSE_BUTTON_LEFT) {
465 } else if (key == GLFW_MOUSE_BUTTON_RIGHT) {
467 } else {
468 return;
469 }
470
471 auto* controller = GetWindowController(window);
472 controller->buttons = (action == GLFW_PRESS) ? controller->buttons | button
473 : controller->buttons & ~button;
474
475 FlutterPointerEvent event = {};
476 SetEventPhaseFromCursorButtonState(window, &event, controller->buttons);
479
480 // If mouse tracking isn't already enabled, turn it on for the duration of
481 // the drag to generate kMove events.
482 bool hover_enabled =
483 GetWindowController(window)->window_wrapper->hover_tracking_enabled;
484 if (!hover_enabled) {
485 glfwSetCursorPosCallback(window, (controller->buttons != 0)
487 : nullptr);
488 }
489 // Disable enter/exit events while the mouse button is down; GLFW will send
490 // an exit event when the mouse button is released, and the pointer should
491 // stay valid until then.
492 if (hover_enabled) {
493 glfwSetCursorEnterCallback(
494 window, (controller->buttons != 0) ? nullptr : GLFWCursorEnterCallback);
495 }
496}
@ kFlutterPointerButtonMousePrimary
Definition embedder.h:1015
@ kFlutterPointerButtonMouseSecondary
Definition embedder.h:1016
static void GLFWCursorPositionCallback(GLFWwindow *window, double x, double y)
static void GLFWCursorEnterCallback(GLFWwindow *window, int entered)

◆ GLFWScrollCallback()

static void GLFWScrollCallback ( GLFWwindow *  window,
double  delta_x,
double  delta_y 
)
static

Definition at line 499 of file flutter_glfw.cc.

501 {
502 FlutterPointerEvent event = {};
504 auto* controller = GetWindowController(window);
505 SetEventPhaseFromCursorButtonState(window, &event, controller->buttons);
507 // TODO(chrome-bot): See if this can be queried from the OS; this value is
508 // chosen arbitrarily to get something that feels reasonable.
509 const int kScrollOffsetMultiplier = 20;
510 event.scroll_delta_x = delta_x * kScrollOffsetMultiplier;
511 event.scroll_delta_y = -delta_y * kScrollOffsetMultiplier;
513}
@ kFlutterPointerSignalKindScroll
Definition embedder.h:1027

◆ GLFWWindowRefreshCallback()

void GLFWWindowRefreshCallback ( GLFWwindow *  window)

Definition at line 341 of file flutter_glfw.cc.

341 {
342 auto* controller = GetWindowController(window);
343 if (controller->window_wrapper->skip_next_window_refresh) {
344 controller->window_wrapper->skip_next_window_refresh = false;
345 return;
346 }
347 // There's no engine API to request a redraw explicitly, so instead send a
348 // window metrics event with the current size to trigger it.
349 int width_px, height_px;
350 glfwGetFramebufferSize(window, &width_px, &height_px);
351 if (width_px > 0 && height_px > 0) {
352 SendWindowMetrics(controller, width_px, height_px);
353 }
354}

◆ LoadAotData()

UniqueAotDataPtr LoadAotData ( const std::filesystem::path &  aot_data_path)

Definition at line 679 of file flutter_glfw.cc.

679 {
680 if (aot_data_path.empty()) {
681 std::cerr
682 << "Attempted to load AOT data, but no aot_data_path was provided."
683 << std::endl;
684 return nullptr;
685 }
686 std::string path_string = aot_data_path.string();
687 if (!std::filesystem::exists(aot_data_path)) {
688 std::cerr << "Can't load AOT data from " << path_string << "; no such file."
689 << std::endl;
690 return nullptr;
691 }
694 source.elf_path = path_string.c_str();
695 FlutterEngineAOTData data = nullptr;
697 if (result != kSuccess) {
698 std::cerr << "Failed to load AOT data from: " << path_string << std::endl;
699 return nullptr;
700 }
701 return UniqueAotDataPtr(data);
702}
FlutterEngineResult FlutterEngineCreateAOTData(const FlutterEngineAOTDataSource *source, FlutterEngineAOTData *data_out)
Creates the necessary data structures to launch a Flutter Dart application in AOT mode....
Definition embedder.cc:1422
@ kFlutterEngineAOTDataSourceTypeElfPath
Definition embedder.h:2108
SkBitmap source
Definition examples.cpp:28
std::unique_ptr< _FlutterEngineAOTData, AOTDataDeleter > UniqueAotDataPtr
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

◆ RunFlutterEngine()

static bool RunFlutterEngine ( FlutterDesktopEngineState engine_state,
const FlutterDesktopEngineProperties engine_properties,
std::unique_ptr< flutter::EventLoop event_loop 
)
static

Definition at line 711 of file flutter_glfw.cc.

714 {
715 // FlutterProjectArgs is expecting a full argv, so when processing it for
716 // flags the first item is treated as the executable and ignored. Add a dummy
717 // value so that all provided arguments are used.
718 std::vector<const char*> argv = {"placeholder"};
719 if (engine_properties.switches_count > 0) {
720 argv.insert(argv.end(), &engine_properties.switches[0],
721 &engine_properties.switches[engine_properties.switches_count]);
722 }
723
724 std::filesystem::path assets_path =
725 std::filesystem::u8path(engine_properties.assets_path);
726 std::filesystem::path icu_path =
727 std::filesystem::u8path(engine_properties.icu_data_path);
728 std::filesystem::path aot_library_path =
729 std::filesystem::u8path(engine_properties.aot_library_path);
730 if (assets_path.is_relative() || icu_path.is_relative() ||
731 (!aot_library_path.empty() && aot_library_path.is_relative())) {
732 // Treat relative paths as relative to the directory of this executable.
733 std::filesystem::path executable_location =
735 if (executable_location.empty()) {
736 std::cerr << "Unable to find executable location to resolve paths."
737 << std::endl;
738 return false;
739 }
740 assets_path = std::filesystem::path(executable_location) / assets_path;
741 icu_path = std::filesystem::path(executable_location) / icu_path;
742 if (!aot_library_path.empty()) {
743 aot_library_path =
744 std::filesystem::path(executable_location) / aot_library_path;
745 }
746 }
747 // Configure a task runner using the event loop.
748 engine_state->event_loop = std::move(event_loop);
749 FlutterTaskRunnerDescription platform_task_runner = {};
750 ConfigurePlatformTaskRunner(&platform_task_runner, engine_state);
751 FlutterCustomTaskRunners task_runners = {};
752 task_runners.struct_size = sizeof(FlutterCustomTaskRunners);
753 task_runners.platform_task_runner = &platform_task_runner;
754
755 FlutterRendererConfig config = {};
756 config.type = kOpenGL;
757 config.open_gl.struct_size = sizeof(config.open_gl);
763 // Don't provide a resolver in headless mode, since headless mode should
764 // work even if GLFW initialization failed.
765 if (engine_state->window_controller != nullptr) {
767 }
768 const std::string assets_path_string = assets_path.string();
769 const std::string icu_path_string = icu_path.string();
772 args.assets_path = assets_path_string.c_str();
773 args.icu_data_path = icu_path_string.c_str();
774 args.command_line_argc = static_cast<int>(argv.size());
775 args.command_line_argv = &argv[0];
776 args.platform_message_callback = EngineOnFlutterPlatformMessage;
777 args.custom_task_runners = &task_runners;
778
780 engine_state->aot_data = LoadAotData(aot_library_path);
781 if (!engine_state->aot_data) {
782 std::cerr << "Unable to start engine without AOT data." << std::endl;
783 return false;
784 }
785 args.aot_data = engine_state->aot_data.get();
786 }
787
790 engine_state, &engine);
791 if (result != kSuccess || engine == nullptr) {
792 std::cerr << "Failed to start Flutter engine: error " << result
793 << std::endl;
794 return false;
795 }
796 engine_state->flutter_engine = engine;
797 return true;
798}
FlutterEngineResult FlutterEngineRun(size_t version, const FlutterRendererConfig *config, const FlutterProjectArgs *args, void *user_data, FLUTTER_API_SYMBOL(FlutterEngine) *engine_out)
Initialize and run a Flutter engine instance and return a handle to it. This is a convenience method ...
Definition embedder.cc:1711
bool FlutterEngineRunsAOTCompiledDartCode(void)
Returns if the Flutter engine instance will run AOT compiled Dart code. This call has no threading re...
Definition embedder.cc:3057
#define FLUTTER_API_SYMBOL(symbol)
Definition embedder.h:67
@ kOpenGL
Definition embedder.h:80
#define FLUTTER_ENGINE_VERSION
Definition embedder.h:70
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
UniqueAotDataPtr LoadAotData(const std::filesystem::path &aot_data_path)
static bool EngineClearContext(void *user_data)
static void EngineOnFlutterPlatformMessage(const FlutterPlatformMessage *engine_message, void *user_data)
static bool EngineMakeResourceContextCurrent(void *user_data)
static void ConfigurePlatformTaskRunner(FlutterTaskRunnerDescription *task_runner, FlutterDesktopEngineState *engine_state)
static bool EngineMakeContextCurrent(void *user_data)
static uint32_t EngineGetActiveFbo(void *user_data)
static bool EnginePresent(void *user_data)
static void * EngineProcResolver(void *user_data, const char *name)
char ** argv
Definition library.h:9
std::filesystem::path GetExecutableDirectory()
Definition path_utils.cc:16
const FlutterTaskRunnerDescription * platform_task_runner
Definition embedder.h:1594
size_t struct_size
The size of this struct. Must be sizeof(FlutterCustomTaskRunners).
Definition embedder.h:1589
UniqueAotDataPtr aot_data
std::unique_ptr< flutter::EventLoop > event_loop
ProcResolver gl_proc_resolver
Definition embedder.h:552
size_t struct_size
The size of this struct. Must be sizeof(FlutterOpenGLRendererConfig).
Definition embedder.h:513
BoolCallback make_resource_current
Definition embedder.h:535
size_t struct_size
The size of this struct. Must be sizeof(FlutterProjectArgs).
Definition embedder.h:2138
FlutterOpenGLRendererConfig open_gl
Definition embedder.h:827
FlutterRendererType type
Definition embedder.h:825

◆ SendPointerEventWithData()

static void SendPointerEventWithData ( GLFWwindow *  window,
const FlutterPointerEvent event_data 
)
static

Definition at line 360 of file flutter_glfw.cc.

361 {
362 auto* controller = GetWindowController(window);
363 // If sending anything other than an add, and the pointer isn't already added,
364 // synthesize an add to satisfy Flutter's expectations about events.
365 if (!controller->pointer_currently_added &&
366 event_data.phase != FlutterPointerPhase::kAdd) {
367 FlutterPointerEvent event = {};
369 event.x = event_data.x;
370 event.y = event_data.y;
372 }
373 // Don't double-add (e.g., if events are delivered out of order, so an add has
374 // already been synthesized).
375 if (controller->pointer_currently_added &&
376 event_data.phase == FlutterPointerPhase::kAdd) {
377 return;
378 }
379
380 FlutterPointerEvent event = event_data;
381 // Set metadata that's always the same regardless of the event.
382 event.struct_size = sizeof(event);
383 event.timestamp =
384 std::chrono::duration_cast<std::chrono::microseconds>(
385 std::chrono::high_resolution_clock::now().time_since_epoch())
386 .count();
388 event.buttons =
389 (event.phase == FlutterPointerPhase::kAdd) ? 0 : controller->buttons;
390
391 // Convert all screen coordinates to pixel coordinates.
392 double pixels_per_coordinate =
393 controller->window_wrapper->pixels_per_screen_coordinate;
394 event.x *= pixels_per_coordinate;
395 event.y *= pixels_per_coordinate;
396 event.scroll_delta_x *= pixels_per_coordinate;
397 event.scroll_delta_y *= pixels_per_coordinate;
398 // The GLFW embedder doesn't support multiple views. We assume all pointer
399 // events come from the only view, the implicit view.
400 event.view_id = flutter::kFlutterImplicitViewId;
401
402 FlutterEngineSendPointerEvent(controller->engine->flutter_engine, &event, 1);
403
404 if (event_data.phase == FlutterPointerPhase::kAdd) {
405 controller->pointer_currently_added = true;
406 } else if (event_data.phase == FlutterPointerPhase::kRemove) {
407 controller->pointer_currently_added = false;
408 } else if (event_data.phase == FlutterPointerPhase::kDown) {
409 controller->pointer_currently_down = true;
410 } else if (event_data.phase == FlutterPointerPhase::kUp) {
411 controller->pointer_currently_down = false;
412 }
413}
FlutterEngineResult FlutterEngineSendPointerEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPointerEvent *pointers, size_t events_count)
Definition embedder.cc:2423
@ kUp
Definition embedder.h:971
@ kDown
Definition embedder.h:978
@ kFlutterPointerDeviceKindMouse
Definition embedder.h:1006
constexpr int64_t kFlutterImplicitViewId
Definition constants.h:35
size_t struct_size
The size of this struct. Must be sizeof(FlutterPointerEvent).
Definition embedder.h:1034
double y
The y coordinate of the pointer event in physical pixels.
Definition embedder.h:1043

◆ SendWindowMetrics()

static void SendWindowMetrics ( FlutterDesktopWindowControllerState controller,
int  width,
int  height 
)
static

Definition at line 282 of file flutter_glfw.cc.

284 {
285 double dpi = controller->window_wrapper->pixels_per_screen_coordinate *
287
288 FlutterWindowMetricsEvent event = {};
289 event.struct_size = sizeof(event);
290 event.width = width;
291 event.height = height;
292 if (controller->window_wrapper->pixel_ratio_override == 0.0) {
293 // The Flutter pixel_ratio is defined as DPI/dp. Limit the ratio to a
294 // minimum of 1 to avoid rendering a smaller UI on standard resolution
295 // monitors.
296 event.pixel_ratio = std::max(dpi / kDpPerInch, 1.0);
297 } else {
298 event.pixel_ratio = controller->window_wrapper->pixel_ratio_override;
299 }
300 // The GLFW embedder doesn't support multiple views. We assume all pointer
301 // events come from the only view, the implicit view.
302 event.view_id = flutter::kFlutterImplicitViewId;
303 FlutterEngineSendWindowMetricsEvent(controller->engine->flutter_engine,
304 &event);
305}
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterWindowMetricsEvent *flutter_metrics)
Definition embedder.cc:2314
size_t struct_size
The size of this struct. Must be sizeof(FlutterWindowMetricsEvent).
Definition embedder.h:841

◆ SetEventLocationFromCursorPosition()

static void SetEventLocationFromCursorPosition ( GLFWwindow *  window,
FlutterPointerEvent event_data 
)
static

Definition at line 416 of file flutter_glfw.cc.

418 {
419 glfwGetCursorPos(window, &event_data->x, &event_data->y);
420}

◆ SetEventPhaseFromCursorButtonState()

static void SetEventPhaseFromCursorButtonState ( GLFWwindow *  window,
FlutterPointerEvent event_data,
int64_t  buttons 
)
static

Definition at line 426 of file flutter_glfw.cc.

428 {
429 auto* controller = GetWindowController(window);
430 event_data->phase =
431 (buttons == 0)
432 ? (controller->pointer_currently_down ? FlutterPointerPhase::kUp
434 : (controller->pointer_currently_down ? FlutterPointerPhase::kMove
436}
FlutterPointerPhase
The phase of the pointer event.
Definition embedder.h:963
@ kHover
The pointer moved while up.
Definition embedder.h:995
@ kMove
Definition embedder.h:983

◆ SetHoverCallbacksEnabled()

static void SetHoverCallbacksEnabled ( GLFWwindow *  window,
bool  enabled 
)
static

Definition at line 536 of file flutter_glfw.cc.

536 {
537 glfwSetCursorEnterCallback(window,
538 enabled ? GLFWCursorEnterCallback : nullptr);
539 glfwSetCursorPosCallback(window,
540 enabled ? GLFWCursorPositionCallback : nullptr);
541}

◆ SetUpCommonEngineState()

static void SetUpCommonEngineState ( FlutterDesktopEngineState state,
GLFWwindow *  window 
)
static

Definition at line 825 of file flutter_glfw.cc.

826 {
827 // Messaging.
831 state->messenger->SetEngine(state);
832 state->message_dispatcher =
833 std::make_unique<flutter::IncomingMessageDispatcher>(
834 state->messenger.get());
835
836 // Plugins.
837 state->plugin_registrar = std::make_unique<FlutterDesktopPluginRegistrar>();
838 state->plugin_registrar->engine = state;
839 state->internal_plugin_registrar =
840 std::make_unique<flutter::PluginRegistrar>(state->plugin_registrar.get());
841
842 // System channel handler.
843 state->platform_handler = std::make_unique<flutter::PlatformHandler>(
844 state->internal_plugin_registrar->messenger(), window);
845
847}
static void SetUpLocales(FlutterDesktopEngineState *state)
std::unique_ptr< FlutterDesktopMessenger, decltype(&FlutterDesktopMessengerRelease)> FlutterDesktopMessengerReferenceOwner
Maintains one ref on the FlutterDesktopMessenger's internal reference count.
void FlutterDesktopMessengerRelease(FlutterDesktopMessengerRef messenger)
FlutterDesktopMessengerRef FlutterDesktopMessengerAddRef(FlutterDesktopMessengerRef messenger)

◆ SetUpLocales()

static void SetUpLocales ( FlutterDesktopEngineState state)
static

Definition at line 801 of file flutter_glfw.cc.

801 {
802 std::vector<flutter::LanguageInfo> languages =
804 std::vector<FlutterLocale> flutter_locales =
806 // Convert the locale list to the locale pointer list that must be provided.
807 std::vector<const FlutterLocale*> flutter_locale_list;
808 flutter_locale_list.reserve(flutter_locales.size());
809 std::transform(flutter_locales.begin(), flutter_locales.end(),
810 std::back_inserter(flutter_locale_list),
811 [](const auto& arg) -> const auto* { return &arg; });
813 state->flutter_engine, flutter_locale_list.data(),
814 flutter_locale_list.size());
815 if (result != kSuccess) {
816 std::cerr << "Failed to set up Flutter locales." << std::endl;
817 }
818}
FlutterEngineResult FlutterEngineUpdateLocales(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterLocale **locales, size_t locales_count)
Notify a running engine instance that the locale has been updated. The preferred locale must be the f...
Definition embedder.cc:2998
std::vector< FlutterLocale > ConvertToFlutterLocale(const std::vector< LanguageInfo > &languages)
std::vector< LanguageInfo > GetPreferredLanguageInfo()

Variable Documentation

◆ kDpPerInch

constexpr double kDpPerInch = 160.0
staticconstexpr

Definition at line 45 of file flutter_glfw.cc.

◆ kFlutterDesktopDontCare

const int kFlutterDesktopDontCare = GLFW_DONT_CARE

Definition at line 43 of file flutter_glfw.cc.