Flutter Engine
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 "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 >
 

Functions

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 (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)
 
bool FlutterDesktopTextureRegistrarUnregisterExternalTexture (FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id)
 
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 34 of file flutter_glfw.cc.

Referenced by CreateShareWindowForWindow(), and FlutterDesktopCreateWindow().

◆ GLFW_TRUE

#define GLFW_TRUE   1

Definition at line 31 of file flutter_glfw.cc.

Referenced by GLFWKeyCallback(), and main().

Typedef Documentation

◆ UniqueAotDataPtr

Definition at line 108 of file flutter_glfw.cc.

◆ UniqueGLFWwindowPtr

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

Definition at line 37 of file flutter_glfw.cc.

Function Documentation

◆ ConfigurePlatformTaskRunner()

static void ConfigurePlatformTaskRunner ( FlutterTaskRunnerDescription task_runner,
FlutterDesktopEngineState engine_state 
)
static

Definition at line 232 of file flutter_glfw.cc.

References FlutterTaskRunnerDescription::post_task_callback, FlutterTaskRunnerDescription::runs_task_on_current_thread_callback, state, FlutterTaskRunnerDescription::struct_size, and FlutterTaskRunnerDescription::user_data.

Referenced by RunFlutterEngine().

234  {
235  task_runner->struct_size = sizeof(FlutterTaskRunnerDescription);
236  task_runner->user_data = engine_state;
237  task_runner->runs_task_on_current_thread_callback = [](void* state) -> bool {
238  return reinterpret_cast<FlutterDesktopEngineState*>(state)
239  ->event_loop->RunsTasksOnCurrentThread();
240  };
241  task_runner->post_task_callback =
242  [](FlutterTask task, uint64_t target_time_nanos, void* state) -> void {
243  reinterpret_cast<FlutterDesktopEngineState*>(state)->event_loop->PostTask(
244  task, target_time_nanos);
245  };
246 }
size_t struct_size
The size of this struct. Must be sizeof(FlutterTaskRunnerDescription).
Definition: embedder.h:913
FlutterTaskRunnerPostTaskCallback post_task_callback
Definition: embedder.h:930
BoolCallback runs_task_on_current_thread_callback
Definition: embedder.h:919
AtkStateType state

◆ ConvertToDesktopMessage()

static FlutterDesktopMessage ConvertToDesktopMessage ( const FlutterPlatformMessage engine_message)
static

Definition at line 177 of file flutter_glfw.cc.

References FlutterDesktopMessage::channel, FlutterPlatformMessage::channel, FlutterDesktopMessage::message, FlutterPlatformMessage::message, FlutterDesktopMessage::message_size, FlutterPlatformMessage::message_size, FlutterDesktopMessage::response_handle, FlutterPlatformMessage::response_handle, and FlutterDesktopMessage::struct_size.

Referenced by EngineOnFlutterPlatformMessage(), and flutter::FlutterWindowsEngine::HandlePlatformMessage().

178  {
179  FlutterDesktopMessage message = {};
180  message.struct_size = sizeof(message);
181  message.channel = engine_message.channel;
182  message.message = engine_message.message;
183  message.message_size = engine_message.message_size;
184  message.response_handle = engine_message.response_handle;
185  return message;
186 }
const char * channel
Definition: embedder.h:758
const FlutterPlatformMessageResponseHandle * response_handle
Definition: embedder.h:767
const FlutterDesktopMessageResponseHandle * response_handle
const uint8_t * message
Definition: embedder.h:759
const uint8_t * message

◆ CreateShareWindowForWindow()

static UniqueGLFWwindowPtr CreateShareWindowForWindow ( GLFWwindow *  window)
static

Definition at line 165 of file flutter_glfw.cc.

References GLFW_FALSE.

Referenced by FlutterDesktopCreateWindow().

165  {
166  glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
167  glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
168 #if defined(__linux__)
169  glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
170 #endif
171  GLFWwindow* share_window = glfwCreateWindow(1, 1, "", NULL, window);
172  glfwDefaultWindowHints();
173  return UniqueGLFWwindowPtr(share_window, glfwDestroyWindow);
174 }
#define GLFW_FALSE
Definition: flutter_glfw.cc:34
std::unique_ptr< GLFWwindow, void(*)(GLFWwindow *)> UniqueGLFWwindowPtr
Definition: flutter_glfw.cc:37

◆ EngineClearContext()

static bool EngineClearContext ( void *  user_data)
static

Definition at line 541 of file flutter_glfw.cc.

References user_data, and FlutterDesktopEngineState::window_controller.

Referenced by RunFlutterEngine().

541  {
542  FlutterDesktopEngineState* engine_state =
543  static_cast<FlutterDesktopEngineState*>(user_data);
544  FlutterDesktopWindowControllerState* window_controller =
545  engine_state->window_controller;
546  if (!window_controller) {
547  return false;
548  }
549  glfwMakeContextCurrent(nullptr);
550  return true;
551 }
void * user_data
FlutterDesktopWindowControllerState * window_controller

◆ EngineGetActiveFbo()

static uint32_t EngineGetActiveFbo ( void *  user_data)
static

Definition at line 565 of file flutter_glfw.cc.

Referenced by RunFlutterEngine().

565  {
566  return 0;
567 }

◆ EngineMakeContextCurrent()

static bool EngineMakeContextCurrent ( void *  user_data)
static

Definition at line 517 of file flutter_glfw.cc.

References user_data, FlutterDesktopWindowControllerState::window, and FlutterDesktopEngineState::window_controller.

Referenced by RunFlutterEngine().

517  {
518  FlutterDesktopEngineState* engine_state =
519  static_cast<FlutterDesktopEngineState*>(user_data);
520  FlutterDesktopWindowControllerState* window_controller =
521  engine_state->window_controller;
522  if (!window_controller) {
523  return false;
524  }
525  glfwMakeContextCurrent(window_controller->window.get());
526  return true;
527 }
void * user_data
FlutterDesktopWindowControllerState * window_controller

◆ EngineMakeResourceContextCurrent()

static bool EngineMakeResourceContextCurrent ( void *  user_data)
static

Definition at line 529 of file flutter_glfw.cc.

References FlutterDesktopWindowControllerState::resource_window, user_data, and FlutterDesktopEngineState::window_controller.

Referenced by RunFlutterEngine().

529  {
530  FlutterDesktopEngineState* engine_state =
531  static_cast<FlutterDesktopEngineState*>(user_data);
532  FlutterDesktopWindowControllerState* window_controller =
533  engine_state->window_controller;
534  if (!window_controller) {
535  return false;
536  }
537  glfwMakeContextCurrent(window_controller->resource_window.get());
538  return true;
539 }
void * user_data
UniqueGLFWwindowPtr resource_window
Definition: flutter_glfw.cc:51
FlutterDesktopWindowControllerState * window_controller

◆ EngineOnFlutterPlatformMessage()

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

Definition at line 486 of file flutter_glfw.cc.

References ConvertToDesktopMessage(), GLFWAssignEventCallbacks(), GLFWClearEventCallbacks(), FlutterDesktopEngineState::message_dispatcher, FlutterPlatformMessage::struct_size, user_data, FlutterDesktopWindowControllerState::window, and FlutterDesktopEngineState::window_controller.

Referenced by RunFlutterEngine().

488  {
489  if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) {
490  std::cerr << "Invalid message size received. Expected: "
491  << sizeof(FlutterPlatformMessage) << " but received "
492  << engine_message->struct_size << std::endl;
493  return;
494  }
495 
496  FlutterDesktopEngineState* engine_state =
497  static_cast<FlutterDesktopEngineState*>(user_data);
498  GLFWwindow* window = engine_state->window_controller == nullptr
499  ? nullptr
500  : engine_state->window_controller->window.get();
501 
502  auto message = ConvertToDesktopMessage(*engine_message);
503  engine_state->message_dispatcher->HandleMessage(
504  message,
505  [window] {
506  if (window) {
507  GLFWClearEventCallbacks(window);
508  }
509  },
510  [window] {
511  if (window) {
512  GLFWAssignEventCallbacks(window);
513  }
514  });
515 }
static void GLFWClearEventCallbacks(GLFWwindow *window)
std::unique_ptr< flutter::IncomingMessageDispatcher > message_dispatcher
void * user_data
static void GLFWAssignEventCallbacks(GLFWwindow *window)
static FlutterDesktopMessage ConvertToDesktopMessage(const FlutterPlatformMessage &engine_message)
FlutterDesktopWindowControllerState * window_controller
size_t struct_size
The size of this struct. Must be sizeof(FlutterPlatformMessage).
Definition: embedder.h:757

◆ EnginePresent()

static bool EnginePresent ( void *  user_data)
static

Definition at line 553 of file flutter_glfw.cc.

References user_data, FlutterDesktopWindowControllerState::window, and FlutterDesktopEngineState::window_controller.

Referenced by RunFlutterEngine().

553  {
554  FlutterDesktopEngineState* engine_state =
555  static_cast<FlutterDesktopEngineState*>(user_data);
556  FlutterDesktopWindowControllerState* window_controller =
557  engine_state->window_controller;
558  if (!window_controller) {
559  return false;
560  }
561  glfwSwapBuffers(window_controller->window.get());
562  return true;
563 }
void * user_data
FlutterDesktopWindowControllerState * window_controller

◆ EngineProcResolver()

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

Definition at line 571 of file flutter_glfw.cc.

Referenced by RunFlutterEngine().

571  {
572  return reinterpret_cast<void*>(glfwGetProcAddress(name));
573 }
const char * name
Definition: fuchsia.cc:50

◆ FlutterDesktopCreateWindow()

FlutterDesktopWindowControllerRef FlutterDesktopCreateWindow ( const FlutterDesktopWindowProperties window_properties,
const FlutterDesktopEngineProperties engine_properties 
)

Definition at line 780 of file flutter_glfw.cc.

References CreateShareWindowForWindow(), flutter::testing::StubFlutterGlfwApi::CreateWindow(), FlutterEngineRunTask(), GetScreenCoordinatesPerInch(), GLFW_FALSE, GLFWAssignEventCallbacks(), GLFWClearCanvas(), GLFWFramebufferSizeCallback(), GLFWWindowRefreshCallback(), FlutterDesktopWindowProperties::height, kSuccess, FlutterDesktopWindowProperties::prevent_resize, RunFlutterEngine(), SetUpCommonEngineState(), state, FlutterDesktopWindowProperties::title, FlutterDesktopWindowProperties::width, and FlutterDesktopWindowControllerState::window.

782  {
783  auto state = std::make_unique<FlutterDesktopWindowControllerState>();
784 
785  // Create the window, and set the state as its user data.
786  if (window_properties.prevent_resize) {
787  glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
788  }
789 #if defined(__linux__)
790  glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
791 #endif
792  state->window = UniqueGLFWwindowPtr(
793  glfwCreateWindow(window_properties.width, window_properties.height,
794  window_properties.title, NULL, NULL),
795  glfwDestroyWindow);
796  glfwDefaultWindowHints();
797  GLFWwindow* window = state->window.get();
798  if (window == nullptr) {
799  return nullptr;
800  }
801  GLFWClearCanvas(window);
802  glfwSetWindowUserPointer(window, state.get());
803 
804  // Create the share window before starting the engine, since it may call
805  // EngineMakeResourceContextCurrent immediately.
806  state->resource_window = CreateShareWindowForWindow(window);
807 
808  state->engine = std::make_unique<FlutterDesktopEngineState>();
809  state->engine->window_controller = state.get();
810 
811  // Create an event loop for the window. It is not running yet.
812  auto event_loop = std::make_unique<flutter::GLFWEventLoop>(
813  std::this_thread::get_id(), // main GLFW thread
814  [engine_state = state->engine.get()](const auto* task) {
815  if (FlutterEngineRunTask(engine_state->flutter_engine, task) !=
816  kSuccess) {
817  std::cerr << "Could not post an engine task." << std::endl;
818  }
819  });
820 
821  // Start the engine.
822  if (!RunFlutterEngine(state->engine.get(), engine_properties,
823  std::move(event_loop))) {
824  return nullptr;
825  }
826  SetUpCommonEngineState(state->engine.get(), window);
827 
828  state->window_wrapper = std::make_unique<FlutterDesktopWindow>();
829  state->window_wrapper->window = window;
830 
831  // Set up the keyboard handlers
832  auto internal_plugin_messenger =
833  state->engine->internal_plugin_registrar->messenger();
834  state->keyboard_hook_handlers.push_back(
835  std::make_unique<flutter::KeyEventHandler>(internal_plugin_messenger));
836  state->keyboard_hook_handlers.push_back(
837  std::make_unique<flutter::TextInputPlugin>(internal_plugin_messenger));
838 
839  // Trigger an initial size callback to send size information to Flutter.
840  state->monitor_screen_coordinates_per_inch = GetScreenCoordinatesPerInch();
841  int width_px, height_px;
842  glfwGetFramebufferSize(window, &width_px, &height_px);
843  GLFWFramebufferSizeCallback(window, width_px, height_px);
844 
845  // Set up GLFW callbacks for the window.
846  glfwSetFramebufferSizeCallback(window, GLFWFramebufferSizeCallback);
847  glfwSetWindowRefreshCallback(window, GLFWWindowRefreshCallback);
848  GLFWAssignEventCallbacks(window);
849 
850  return state.release();
851 }
#define GLFW_FALSE
Definition: flutter_glfw.cc:34
FlutterEngineResult FlutterEngineRunTask(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterTask *task)
Inform the engine to run the specified task. This task has been given to the engine via the FlutterTa...
Definition: embedder.cc:1956
static UniqueGLFWwindowPtr CreateShareWindowForWindow(GLFWwindow *window)
static double GetScreenCoordinatesPerInch()
static void GLFWAssignEventCallbacks(GLFWwindow *window)
std::unique_ptr< GLFWwindow, void(*)(GLFWwindow *)> UniqueGLFWwindowPtr
Definition: flutter_glfw.cc:37
static void GLFWClearCanvas(GLFWwindow *window)
static bool RunFlutterEngine(FlutterDesktopEngineState *engine_state, const FlutterDesktopEngineProperties &engine_properties, std::unique_ptr< flutter::EventLoop > event_loop)
void GLFWWindowRefreshCallback(GLFWwindow *window)
static void SetUpCommonEngineState(FlutterDesktopEngineState *state, GLFWwindow *window)
static void GLFWFramebufferSizeCallback(GLFWwindow *window, int width_px, int height_px)
AtkStateType state

◆ FlutterDesktopDestroyWindow()

void FlutterDesktopDestroyWindow ( FlutterDesktopWindowControllerRef  controller)

Definition at line 853 of file flutter_glfw.cc.

References flutter::testing::StubFlutterGlfwApi::DestroyWindow(), FlutterDesktopPluginRegistrar::destruction_handler, FlutterDesktopWindowControllerState::engine, and FlutterEngineShutdown().

853  {
855  controller->engine->plugin_registrar.get();
856  if (registrar->destruction_handler) {
857  registrar->destruction_handler(registrar);
858  }
859  FlutterEngineShutdown(controller->engine->flutter_engine);
860  delete controller;
861 }
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:1377
std::unique_ptr< FlutterDesktopEngineState > engine
Definition: flutter_glfw.cc:55
FlutterDesktopOnPluginRegistrarDestroyed destruction_handler

◆ FlutterDesktopGetEngine()

FlutterDesktopEngineRef FlutterDesktopGetEngine ( FlutterDesktopWindowControllerRef  controller)

Definition at line 966 of file flutter_glfw.cc.

References FlutterDesktopWindowControllerState::engine.

967  {
968  return controller->engine.get();
969 }
std::unique_ptr< FlutterDesktopEngineState > engine
Definition: flutter_glfw.cc:55

◆ FlutterDesktopGetPluginRegistrar()

FlutterDesktopPluginRegistrarRef FlutterDesktopGetPluginRegistrar ( FlutterDesktopEngineRef  engine,
const char *  plugin_name 
)

Definition at line 971 of file flutter_glfw.cc.

References FlutterDesktopEngineState::plugin_registrar.

973  {
974  // Currently, one registrar acts as the registrar for all plugins, so the
975  // name is ignored. It is part of the API to reduce churn in the future when
976  // aligning more closely with the Flutter registrar system.
977  return engine->plugin_registrar.get();
978 }
std::unique_ptr< FlutterDesktopPluginRegistrar > plugin_registrar

◆ FlutterDesktopGetWindow()

FlutterDesktopWindowRef FlutterDesktopGetWindow ( FlutterDesktopWindowControllerRef  controller)

Definition at line 958 of file flutter_glfw.cc.

References FlutterDesktopWindowControllerState::window_wrapper.

959  {
960  // Currently, one registrar acts as the registrar for all plugins, so the
961  // name is ignored. It is part of the API to reduce churn in the future when
962  // aligning more closely with the Flutter registrar system.
963  return controller->window_wrapper.get();
964 }
std::unique_ptr< FlutterDesktopWindow > window_wrapper
Definition: flutter_glfw.cc:58

◆ FlutterDesktopInit()

bool FlutterDesktopInit ( )

Definition at line 770 of file flutter_glfw.cc.

References GLFWErrorCallback(), and flutter::testing::StubFlutterGlfwApi::Init().

770  {
771  // Before making any GLFW calls, set up a logging error handler.
772  glfwSetErrorCallback(GLFWErrorCallback);
773  return glfwInit();
774 }
static void GLFWErrorCallback(int error_code, const char *description)

◆ FlutterDesktopMessengerSend()

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

Definition at line 1079 of file flutter_glfw.cc.

References FlutterDesktopMessengerSendWithReply().

1082  {
1083  return FlutterDesktopMessengerSendWithReply(messenger, channel, message,
1084  message_size, nullptr, nullptr);
1085 }
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 1087 of file flutter_glfw.cc.

References FlutterDesktopMessenger::engine, and FlutterEngineSendPlatformMessageResponse().

1091  {
1092  FlutterEngineSendPlatformMessageResponse(messenger->engine->flutter_engine,
1093  handle, data, data_length);
1094 }
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:1736
FlutterDesktopEngineState * engine

◆ 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 1044 of file flutter_glfw.cc.

References FlutterDesktopMessenger::engine, FlutterEngineSendPlatformMessage(), FlutterPlatformMessageCreateResponseHandle(), FlutterPlatformMessageReleaseResponseHandle(), kSuccess, and result.

Referenced by FlutterDesktopMessengerSend().

1049  {
1050  FlutterPlatformMessageResponseHandle* response_handle = nullptr;
1051  if (reply != nullptr && user_data != nullptr) {
1053  messenger->engine->flutter_engine, reply, user_data, &response_handle);
1054  if (result != kSuccess) {
1055  std::cout << "Failed to create response handle\n";
1056  return false;
1057  }
1058  }
1059 
1060  FlutterPlatformMessage platform_message = {
1061  sizeof(FlutterPlatformMessage),
1062  channel,
1063  message,
1064  message_size,
1065  response_handle,
1066  };
1067 
1069  messenger->engine->flutter_engine, &platform_message);
1070 
1071  if (response_handle != nullptr) {
1073  messenger->engine->flutter_engine, response_handle);
1074  }
1075 
1076  return message_result == kSuccess;
1077 }
FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterPlatformMessageResponseHandle *response)
Collects the handle created using FlutterPlatformMessageCreateResponseHandle.
Definition: embedder.cc:1722
void * user_data
GAsyncResult * result
FlutterDesktopEngineState * engine
FlutterEngineResult
Definition: embedder.h:65
FlutterEngineResult FlutterEngineSendPlatformMessage(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessage *flutter_message)
Definition: embedder.cc:1636
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:1687

◆ FlutterDesktopMessengerSetCallback()

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

Definition at line 1096 of file flutter_glfw.cc.

References FlutterDesktopMessenger::engine, and FlutterDesktopEngineState::message_dispatcher.

1099  {
1100  messenger->engine->message_dispatcher->SetMessageCallback(channel, callback,
1101  user_data);
1102 }
std::unique_ptr< flutter::IncomingMessageDispatcher > message_dispatcher
void * user_data
FlKeyEvent FlKeyResponderAsyncCallback callback
FlutterDesktopEngineState * engine

◆ FlutterDesktopPluginRegistrarEnableInputBlocking()

void FlutterDesktopPluginRegistrarEnableInputBlocking ( FlutterDesktopPluginRegistrarRef  registrar,
const char *  channel 
)

Definition at line 1017 of file flutter_glfw.cc.

References FlutterDesktopPluginRegistrar::engine, FlutterDesktopEngineState::message_dispatcher, and flutter::testing::StubFlutterGlfwApi::PluginRegistrarEnableInputBlocking().

1019  {
1020  registrar->engine->message_dispatcher->EnableInputBlockingForChannel(channel);
1021 }
std::unique_ptr< flutter::IncomingMessageDispatcher > message_dispatcher
FlutterDesktopEngineState * engine

◆ FlutterDesktopPluginRegistrarGetMessenger()

FlutterDesktopMessengerRef FlutterDesktopPluginRegistrarGetMessenger ( FlutterDesktopPluginRegistrarRef  registrar)

Definition at line 1023 of file flutter_glfw.cc.

References FlutterDesktopPluginRegistrar::engine, and FlutterDesktopEngineState::messenger.

1024  {
1025  return registrar->engine->messenger.get();
1026 }
std::unique_ptr< FlutterDesktopMessenger > messenger
FlutterDesktopEngineState * engine

◆ FlutterDesktopPluginRegistrarGetWindow()

FlutterDesktopWindowRef FlutterDesktopPluginRegistrarGetWindow ( FlutterDesktopPluginRegistrarRef  registrar)

Definition at line 1034 of file flutter_glfw.cc.

References FlutterDesktopPluginRegistrar::engine, FlutterDesktopEngineState::window_controller, and FlutterDesktopWindowControllerState::window_wrapper.

1035  {
1037  registrar->engine->window_controller;
1038  if (!controller) {
1039  return nullptr;
1040  }
1041  return controller->window_wrapper.get();
1042 }
std::unique_ptr< FlutterDesktopWindow > window_wrapper
Definition: flutter_glfw.cc:58
FlutterDesktopWindowControllerState * window_controller
FlutterDesktopEngineState * engine

◆ FlutterDesktopPluginRegistrarSetDestructionHandler()

void FlutterDesktopPluginRegistrarSetDestructionHandler ( FlutterDesktopPluginRegistrarRef  registrar,
FlutterDesktopOnPluginRegistrarDestroyed  callback 
)

Definition at line 1028 of file flutter_glfw.cc.

References callback, and FlutterDesktopPluginRegistrar::destruction_handler.

1030  {
1031  registrar->destruction_handler = callback;
1032 }
FlKeyEvent FlKeyResponderAsyncCallback callback
FlutterDesktopOnPluginRegistrarDestroyed destruction_handler

◆ FlutterDesktopRegistrarGetTextureRegistrar()

FlutterDesktopTextureRegistrarRef FlutterDesktopRegistrarGetTextureRegistrar ( FlutterDesktopPluginRegistrarRef  registrar)

Definition at line 1104 of file flutter_glfw.cc.

1105  {
1106  std::cerr << "GLFW Texture support is not implemented yet." << std::endl;
1107  return nullptr;
1108 }

◆ FlutterDesktopRunEngine()

FlutterDesktopEngineRef FlutterDesktopRunEngine ( const FlutterDesktopEngineProperties properties)

Definition at line 980 of file flutter_glfw.cc.

References FlutterEngineRunTask(), kSuccess, flutter::testing::StubFlutterGlfwApi::RunEngine(), RunFlutterEngine(), SetUpCommonEngineState(), and state.

981  {
982  auto engine_state = std::make_unique<FlutterDesktopEngineState>();
983 
984  auto event_loop = std::make_unique<flutter::HeadlessEventLoop>(
985  std::this_thread::get_id(),
986  [state = engine_state.get()](const auto* task) {
987  if (FlutterEngineRunTask(state->flutter_engine, task) != kSuccess) {
988  std::cerr << "Could not post an engine task." << std::endl;
989  }
990  });
991 
992  if (!RunFlutterEngine(engine_state.get(), properties,
993  std::move(event_loop))) {
994  return nullptr;
995  }
996  SetUpCommonEngineState(engine_state.get(), nullptr);
997 
998  return engine_state.release();
999 }
FlutterEngineResult FlutterEngineRunTask(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterTask *task)
Inform the engine to run the specified task. This task has been given to the engine via the FlutterTa...
Definition: embedder.cc:1956
static bool RunFlutterEngine(FlutterDesktopEngineState *engine_state, const FlutterDesktopEngineProperties &engine_properties, std::unique_ptr< flutter::EventLoop > event_loop)
static void SetUpCommonEngineState(FlutterDesktopEngineState *state, GLFWwindow *window)
AtkStateType state

◆ FlutterDesktopRunEngineEventLoopWithTimeout()

void FlutterDesktopRunEngineEventLoopWithTimeout ( FlutterDesktopEngineRef  engine,
uint32_t  timeout_milliseconds 
)

Definition at line 1001 of file flutter_glfw.cc.

References FlutterDesktopEngineState::event_loop, and flutter::testing::StubFlutterGlfwApi::RunEngineEventLoopWithTimeout().

Referenced by FlutterDesktopRunWindowEventLoopWithTimeout().

1003  {
1004  std::chrono::nanoseconds wait_duration =
1005  timeout_milliseconds == 0
1006  ? std::chrono::nanoseconds::max()
1007  : std::chrono::milliseconds(timeout_milliseconds);
1008  engine->event_loop->WaitForEvents(wait_duration);
1009 }
Definition: ref_ptr.h:252
std::unique_ptr< flutter::EventLoop > event_loop

◆ FlutterDesktopRunWindowEventLoopWithTimeout()

bool FlutterDesktopRunWindowEventLoopWithTimeout ( FlutterDesktopWindowControllerRef  controller,
uint32_t  timeout_milliseconds 
)

Definition at line 950 of file flutter_glfw.cc.

References FlutterDesktopWindowControllerState::engine, FlutterDesktopRunEngineEventLoopWithTimeout(), flutter::testing::StubFlutterGlfwApi::RunWindowEventLoopWithTimeout(), and FlutterDesktopWindowControllerState::window.

952  {
954  timeout_milliseconds);
955  return !glfwWindowShouldClose(controller->window.get());
956 }
std::unique_ptr< FlutterDesktopEngineState > engine
Definition: flutter_glfw.cc:55
void FlutterDesktopRunEngineEventLoopWithTimeout(FlutterDesktopEngineRef engine, uint32_t timeout_milliseconds)

◆ FlutterDesktopShutDownEngine()

bool FlutterDesktopShutDownEngine ( FlutterDesktopEngineRef  engine)

Definition at line 1011 of file flutter_glfw.cc.

References FlutterDesktopWindowControllerState::engine, FlutterEngineShutdown(), kSuccess, result, and flutter::testing::StubFlutterGlfwApi::ShutDownEngine().

1011  {
1012  auto result = FlutterEngineShutdown(engine->flutter_engine);
1013  delete engine;
1014  return (result == kSuccess);
1015 }
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:1377
GAsyncResult * result

◆ FlutterDesktopTerminate()

void FlutterDesktopTerminate ( )

Definition at line 776 of file flutter_glfw.cc.

References flutter::testing::StubFlutterGlfwApi::Terminate().

776  {
777  glfwTerminate();
778 }

◆ FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable()

bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable ( FlutterDesktopTextureRegistrarRef  texture_registrar,
int64_t  texture_id 
)

Definition at line 1124 of file flutter_glfw.cc.

1126  {
1127  std::cerr << "GLFW Texture support is not implemented yet." << std::endl;
1128  return false;
1129 }

◆ FlutterDesktopTextureRegistrarRegisterExternalTexture()

int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture ( FlutterDesktopTextureRegistrarRef  texture_registrar,
const FlutterDesktopTextureInfo texture_info 
)

Definition at line 1110 of file flutter_glfw.cc.

1112  {
1113  std::cerr << "GLFW Texture support is not implemented yet." << std::endl;
1114  return -1;
1115 }

◆ FlutterDesktopTextureRegistrarUnregisterExternalTexture()

bool FlutterDesktopTextureRegistrarUnregisterExternalTexture ( FlutterDesktopTextureRegistrarRef  texture_registrar,
int64_t  texture_id 
)

Definition at line 1117 of file flutter_glfw.cc.

1119  {
1120  std::cerr << "GLFW Texture support is not implemented yet." << std::endl;
1121  return false;
1122 }

◆ FlutterDesktopWindowGetFrame()

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

Definition at line 883 of file flutter_glfw.cc.

References flutter::testing::StubFlutterGlfwApi::GetWindowFrame(), and FlutterDesktopWindow::window.

887  {
888  glfwGetWindowPos(flutter_window->window, x, y);
889  glfwGetWindowSize(flutter_window->window, width, height);
890  // The above gives content area size and position; adjust for the window
891  // decoration to give actual window frame.
892  int frame_left, frame_top, frame_right, frame_bottom;
893  glfwGetWindowFrameSize(flutter_window->window, &frame_left, &frame_top,
894  &frame_right, &frame_bottom);
895  if (x) {
896  *x -= frame_left;
897  }
898  if (y) {
899  *y -= frame_top;
900  }
901  if (width) {
902  *width += frame_left + frame_right;
903  }
904  if (height) {
905  *height += frame_top + frame_bottom;
906  }
907 }
int32_t width
int32_t height
GLFWwindow * window
Definition: flutter_glfw.cc:84

◆ FlutterDesktopWindowGetScaleFactor()

double FlutterDesktopWindowGetScaleFactor ( FlutterDesktopWindowRef  flutter_window)

◆ FlutterDesktopWindowSetFrame()

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

Definition at line 909 of file flutter_glfw.cc.

References flutter::testing::StubFlutterGlfwApi::SetWindowFrame(), and FlutterDesktopWindow::window.

913  {
914  // Get the window decoration sizes to adjust, since the GLFW setters take
915  // content position and size.
916  int frame_left, frame_top, frame_right, frame_bottom;
917  glfwGetWindowFrameSize(flutter_window->window, &frame_left, &frame_top,
918  &frame_right, &frame_bottom);
919  glfwSetWindowPos(flutter_window->window, x + frame_left, y + frame_top);
920  glfwSetWindowSize(flutter_window->window, width - frame_left - frame_right,
921  height - frame_top - frame_bottom);
922 }
int32_t width
int32_t height
GLFWwindow * window
Definition: flutter_glfw.cc:84

◆ FlutterDesktopWindowSetHoverEnabled()

void FlutterDesktopWindowSetHoverEnabled ( FlutterDesktopWindowRef  flutter_window,
bool  enabled 
)

Definition at line 863 of file flutter_glfw.cc.

References FlutterDesktopWindow::hover_tracking_enabled, SetHoverCallbacksEnabled(), flutter::testing::StubFlutterGlfwApi::SetHoverEnabled(), and FlutterDesktopWindow::window.

864  {
865  flutter_window->hover_tracking_enabled = enabled;
866  SetHoverCallbacksEnabled(flutter_window->window, enabled);
867 }
static void SetHoverCallbacksEnabled(GLFWwindow *window, bool enabled)
GLFWwindow * window
Definition: flutter_glfw.cc:84

◆ FlutterDesktopWindowSetIcon()

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

Definition at line 875 of file flutter_glfw.cc.

References height, flutter::testing::StubFlutterGlfwApi::SetWindowIcon(), width, and FlutterDesktopWindow::window.

878  {
879  GLFWimage image = {width, height, static_cast<unsigned char*>(pixel_data)};
880  glfwSetWindowIcon(flutter_window->window, pixel_data ? 1 : 0, &image);
881 }
int32_t width
int32_t height
GLFWwindow * window
Definition: flutter_glfw.cc:84

◆ FlutterDesktopWindowSetPixelRatioOverride()

void FlutterDesktopWindowSetPixelRatioOverride ( FlutterDesktopWindowRef  flutter_window,
double  pixel_ratio 
)

Definition at line 929 of file flutter_glfw.cc.

References GetWindowController(), FlutterDesktopWindow::pixel_ratio_override, SendWindowMetrics(), flutter::testing::StubFlutterGlfwApi::SetPixelRatioOverride(), and FlutterDesktopWindow::window.

931  {
932  flutter_window->pixel_ratio_override = pixel_ratio;
933  // Send a metrics update using the new pixel ratio.
934  int width_px, height_px;
935  glfwGetFramebufferSize(flutter_window->window, &width_px, &height_px);
936  if (width_px > 0 && height_px > 0) {
937  auto* controller = GetWindowController(flutter_window->window);
938  SendWindowMetrics(controller, width_px, height_px);
939  }
940 }
static void SendWindowMetrics(FlutterDesktopWindowControllerState *controller, int width, int height)
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)
GLFWwindow * window
Definition: flutter_glfw.cc:84

◆ FlutterDesktopWindowSetSizeLimits()

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

Definition at line 942 of file flutter_glfw.cc.

References FlutterDesktopSize::height, flutter::testing::StubFlutterGlfwApi::SetSizeLimits(), FlutterDesktopSize::width, and FlutterDesktopWindow::window.

944  {
945  glfwSetWindowSizeLimits(flutter_window->window, minimum_size.width,
946  minimum_size.height, maximum_size.width,
947  maximum_size.height);
948 }
GLFWwindow * window
Definition: flutter_glfw.cc:84

◆ FlutterDesktopWindowSetTitle()

void FlutterDesktopWindowSetTitle ( FlutterDesktopWindowRef  flutter_window,
const char *  title 
)

Definition at line 869 of file flutter_glfw.cc.

References flutter::testing::StubFlutterGlfwApi::SetWindowTitle(), FlutterDesktopWindowControllerState::window, and FlutterDesktopWindow::window.

870  {
871  GLFWwindow* window = flutter_window->window;
872  glfwSetWindowTitle(window, title);
873 }
GLFWwindow * window
Definition: flutter_glfw.cc:84

◆ GetScreenCoordinatesPerInch()

static double GetScreenCoordinatesPerInch ( )
static

Definition at line 191 of file flutter_glfw.cc.

References kDpPerInch.

Referenced by FlutterDesktopCreateWindow().

191  {
192  auto* primary_monitor = glfwGetPrimaryMonitor();
193  if (primary_monitor == nullptr) {
194  return kDpPerInch;
195  }
196  auto* primary_monitor_mode = glfwGetVideoMode(primary_monitor);
197  int primary_monitor_width_mm;
198  glfwGetMonitorPhysicalSize(primary_monitor, &primary_monitor_width_mm,
199  nullptr);
200  if (primary_monitor_width_mm == 0) {
201  return kDpPerInch;
202  }
203  return primary_monitor_mode->width / (primary_monitor_width_mm / 25.4);
204 }
static constexpr double kDpPerInch
Definition: flutter_glfw.cc:43

◆ GetWindowController()

◆ GLFWAssignEventCallbacks()

static void GLFWAssignEventCallbacks ( GLFWwindow *  window)
static

Definition at line 464 of file flutter_glfw.cc.

References GetWindowController(), GLFWCharCallback(), GLFWKeyCallback(), GLFWMouseButtonCallback(), GLFWScrollCallback(), SetHoverCallbacksEnabled(), and FlutterDesktopWindowControllerState::window_wrapper.

Referenced by EngineOnFlutterPlatformMessage(), and FlutterDesktopCreateWindow().

464  {
465  glfwPollEvents();
466  glfwSetKeyCallback(window, GLFWKeyCallback);
467  glfwSetCharCallback(window, GLFWCharCallback);
468  glfwSetMouseButtonCallback(window, GLFWMouseButtonCallback);
469  glfwSetScrollCallback(window, GLFWScrollCallback);
470  if (GetWindowController(window)->window_wrapper->hover_tracking_enabled) {
471  SetHoverCallbacksEnabled(window, true);
472  }
473 }
static void GLFWScrollCallback(GLFWwindow *window, double delta_x, double delta_y)
static void GLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
static void SetHoverCallbacksEnabled(GLFWwindow *window, bool enabled)
static void GLFWCharCallback(GLFWwindow *window, unsigned int code_point)
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)
static void GLFWMouseButtonCallback(GLFWwindow *window, int key, int action, int mods)

◆ GLFWCharCallback()

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

Definition at line 436 of file flutter_glfw.cc.

References GetWindowController(), and FlutterDesktopWindowControllerState::keyboard_hook_handlers.

Referenced by GLFWAssignEventCallbacks().

436  {
437  for (const auto& handler :
438  GetWindowController(window)->keyboard_hook_handlers) {
439  handler->CharHook(window, code_point);
440  }
441 }
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)

◆ GLFWClearCanvas()

static void GLFWClearCanvas ( GLFWwindow *  window)
static

Definition at line 583 of file flutter_glfw.cc.

Referenced by FlutterDesktopCreateWindow().

583  {
584  glfwMakeContextCurrent(window);
585  // This color is Material Blue Grey.
586  glClearColor(236.0f / 255.0f, 239.0f / 255.0f, 241.0f / 255.0f, 0.0f);
587  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
588  glFlush();
589  glfwSwapBuffers(window);
590  glfwMakeContextCurrent(nullptr);
591 }

◆ GLFWClearEventCallbacks()

static void GLFWClearEventCallbacks ( GLFWwindow *  window)
static

Definition at line 476 of file flutter_glfw.cc.

References SetHoverCallbacksEnabled().

Referenced by EngineOnFlutterPlatformMessage().

476  {
477  glfwSetKeyCallback(window, nullptr);
478  glfwSetCharCallback(window, nullptr);
479  glfwSetMouseButtonCallback(window, nullptr);
480  glfwSetScrollCallback(window, nullptr);
481  SetHoverCallbacksEnabled(window, false);
482 }
static void SetHoverCallbacksEnabled(GLFWwindow *window, bool enabled)

◆ GLFWCursorEnterCallback()

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

Definition at line 359 of file flutter_glfw.cc.

References event, kAdd, kRemove, FlutterPointerEvent::phase, SendPointerEventWithData(), and SetEventLocationFromCursorPosition().

Referenced by GLFWMouseButtonCallback(), and SetHoverCallbacksEnabled().

359  {
360  FlutterPointerEvent event = {};
361  event.phase =
365 }
static void SetEventLocationFromCursorPosition(GLFWwindow *window, FlutterPointerEvent *event_data)
static void SendPointerEventWithData(GLFWwindow *window, const FlutterPointerEvent &event_data)
FlKeyEvent * event
Definition: embedder.h:612
FlutterPointerPhase phase
Definition: embedder.h:650

◆ GLFWCursorPositionCallback()

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

Definition at line 368 of file flutter_glfw.cc.

References event, GetWindowController(), SendPointerEventWithData(), SetEventPhaseFromCursorButtonState(), and FlutterPointerEvent::x.

Referenced by GLFWMouseButtonCallback(), and SetHoverCallbacksEnabled().

368  {
369  FlutterPointerEvent event = {};
370  event.x = x;
371  event.y = y;
372  auto* controller = GetWindowController(window);
373  SetEventPhaseFromCursorButtonState(window, &event, controller->buttons);
375 }
static void SendPointerEventWithData(GLFWwindow *window, const FlutterPointerEvent &event_data)
FlKeyEvent * event
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)
double x
The x coordinate of the pointer event in physical pixels.
Definition: embedder.h:656
static void SetEventPhaseFromCursorButtonState(GLFWwindow *window, FlutterPointerEvent *event_data, int64_t buttons)

◆ GLFWErrorCallback()

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

Definition at line 593 of file flutter_glfw.cc.

Referenced by FlutterDesktopInit().

593  {
594  std::cerr << "GLFW error " << error_code << ": " << description << std::endl;
595 }

◆ GLFWFramebufferSizeCallback()

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

Definition at line 250 of file flutter_glfw.cc.

References GetWindowController(), SendWindowMetrics(), and width.

Referenced by FlutterDesktopCreateWindow().

252  {
253  int width;
254  glfwGetWindowSize(window, &width, nullptr);
255  auto* controller = GetWindowController(window);
256  controller->window_wrapper->pixels_per_screen_coordinate =
257  width > 0 ? width_px / width : 1;
258 
259  SendWindowMetrics(controller, width_px, height_px);
260  controller->window_wrapper->skip_next_window_refresh = true;
261 }
static void SendWindowMetrics(FlutterDesktopWindowControllerState *controller, int width, int height)
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)
int32_t width

◆ GLFWKeyCallback()

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

Definition at line 444 of file flutter_glfw.cc.

References GetWindowController(), and FlutterDesktopWindowControllerState::keyboard_hook_handlers.

Referenced by GLFWAssignEventCallbacks().

448  {
449  for (const auto& handler :
450  GetWindowController(window)->keyboard_hook_handlers) {
451  handler->KeyboardHook(window, key, scancode, action, mods);
452  }
453 }
SemanticsAction action
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)

◆ GLFWMouseButtonCallback()

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

Definition at line 378 of file flutter_glfw.cc.

References event, GetWindowController(), GLFWCursorEnterCallback(), GLFWCursorPositionCallback(), kFlutterPointerButtonMousePrimary, kFlutterPointerButtonMouseSecondary, SendPointerEventWithData(), SetEventLocationFromCursorPosition(), SetEventPhaseFromCursorButtonState(), FlutterDesktopWindowControllerState::window, and FlutterDesktopWindowControllerState::window_wrapper.

Referenced by GLFWAssignEventCallbacks().

381  {
382  int64_t button;
383  if (key == GLFW_MOUSE_BUTTON_LEFT) {
385  } else if (key == GLFW_MOUSE_BUTTON_RIGHT) {
387  } else {
388  return;
389  }
390 
391  auto* controller = GetWindowController(window);
392  controller->buttons = (action == GLFW_PRESS) ? controller->buttons | button
393  : controller->buttons & ~button;
394 
396  SetEventPhaseFromCursorButtonState(window, &event, controller->buttons);
399 
400  // If mouse tracking isn't already enabled, turn it on for the duration of
401  // the drag to generate kMove events.
402  bool hover_enabled =
403  GetWindowController(window)->window_wrapper->hover_tracking_enabled;
404  if (!hover_enabled) {
405  glfwSetCursorPosCallback(window, (controller->buttons != 0)
407  : nullptr);
408  }
409  // Disable enter/exit events while the mouse button is down; GLFW will send
410  // an exit event when the mouse button is released, and the pointer should
411  // stay valid until then.
412  if (hover_enabled) {
413  glfwSetCursorEnterCallback(
414  window, (controller->buttons != 0) ? nullptr : GLFWCursorEnterCallback);
415  }
416 }
static void SetEventLocationFromCursorPosition(GLFWwindow *window, FlutterPointerEvent *event_data)
static void SendPointerEventWithData(GLFWwindow *window, const FlutterPointerEvent &event_data)
std::unique_ptr< FlutterDesktopWindow > window_wrapper
Definition: flutter_glfw.cc:58
FlKeyEvent * event
SemanticsAction action
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)
static void GLFWCursorPositionCallback(GLFWwindow *window, double x, double y)
static void GLFWCursorEnterCallback(GLFWwindow *window, int entered)
static void SetEventPhaseFromCursorButtonState(GLFWwindow *window, FlutterPointerEvent *event_data, int64_t buttons)

◆ GLFWScrollCallback()

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

Definition at line 419 of file flutter_glfw.cc.

References event, GetWindowController(), kFlutterPointerSignalKindScroll, SendPointerEventWithData(), SetEventLocationFromCursorPosition(), and SetEventPhaseFromCursorButtonState().

Referenced by GLFWAssignEventCallbacks().

421  {
422  FlutterPointerEvent event = {};
424  auto* controller = GetWindowController(window);
425  SetEventPhaseFromCursorButtonState(window, &event, controller->buttons);
427  // TODO: See if this can be queried from the OS; this value is chosen
428  // arbitrarily to get something that feels reasonable.
429  const int kScrollOffsetMultiplier = 20;
430  event.scroll_delta_x = delta_x * kScrollOffsetMultiplier;
431  event.scroll_delta_y = -delta_y * kScrollOffsetMultiplier;
433 }
static void SetEventLocationFromCursorPosition(GLFWwindow *window, FlutterPointerEvent *event_data)
static void SendPointerEventWithData(GLFWwindow *window, const FlutterPointerEvent &event_data)
FlKeyEvent * event
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)
static void SetEventPhaseFromCursorButtonState(GLFWwindow *window, FlutterPointerEvent *event_data, int64_t buttons)

◆ GLFWWindowRefreshCallback()

void GLFWWindowRefreshCallback ( GLFWwindow *  window)

Definition at line 264 of file flutter_glfw.cc.

References GetWindowController(), and SendWindowMetrics().

Referenced by FlutterDesktopCreateWindow().

264  {
265  auto* controller = GetWindowController(window);
266  if (controller->window_wrapper->skip_next_window_refresh) {
267  controller->window_wrapper->skip_next_window_refresh = false;
268  return;
269  }
270  // There's no engine API to request a redraw explicitly, so instead send a
271  // window metrics event with the current size to trigger it.
272  int width_px, height_px;
273  glfwGetFramebufferSize(window, &width_px, &height_px);
274  if (width_px > 0 && height_px > 0) {
275  SendWindowMetrics(controller, width_px, height_px);
276  }
277 }
static void SendWindowMetrics(FlutterDesktopWindowControllerState *controller, int width, int height)
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)

◆ LoadAotData()

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

Definition at line 599 of file flutter_glfw.cc.

References FlutterEngineAOTDataSource::elf_path, FlutterEngineCreateAOTData(), kFlutterEngineAOTDataSourceTypeElfPath, kSuccess, result, and FlutterEngineAOTDataSource::type.

Referenced by RunFlutterEngine().

599  {
600  if (aot_data_path.empty()) {
601  std::cerr
602  << "Attempted to load AOT data, but no aot_data_path was provided."
603  << std::endl;
604  return nullptr;
605  }
606  if (!std::filesystem::exists(aot_data_path)) {
607  std::cerr << "Can't load AOT data from " << aot_data_path.u8string()
608  << "; no such file." << std::endl;
609  return nullptr;
610  }
611  std::string path_string = aot_data_path.u8string();
612  FlutterEngineAOTDataSource source = {};
614  source.elf_path = path_string.c_str();
615  FlutterEngineAOTData data = nullptr;
616  auto result = FlutterEngineCreateAOTData(&source, &data);
617  if (result != kSuccess) {
618  std::cerr << "Failed to load AOT data from: " << path_string << std::endl;
619  return nullptr;
620  }
621  return UniqueAotDataPtr(data);
622 }
GAsyncResult * result
FlutterEngineAOTDataSourceType type
Definition: embedder.h:1326
const char * elf_path
Absolute path to an ELF library file.
Definition: embedder.h:1329
std::unique_ptr< _FlutterEngineAOTData, AOTDataDeleter > UniqueAotDataPtr
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:748

◆ RunFlutterEngine()

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

Definition at line 631 of file flutter_glfw.cc.

References FlutterDesktopEngineState::aot_data, FlutterProjectArgs::aot_data, FlutterDesktopEngineProperties::aot_library_path, args, FlutterDesktopEngineProperties::assets_path, FlutterProjectArgs::assets_path, FlutterOpenGLRendererConfig::clear_current, FlutterProjectArgs::command_line_argc, FlutterProjectArgs::command_line_argv, ConfigurePlatformTaskRunner(), FlutterProjectArgs::custom_task_runners, FlutterDesktopWindowControllerState::engine, EngineClearContext(), EngineGetActiveFbo(), EngineMakeContextCurrent(), EngineMakeResourceContextCurrent(), EngineOnFlutterPlatformMessage(), EnginePresent(), EngineProcResolver(), FlutterDesktopEngineState::event_loop, FlutterOpenGLRendererConfig::fbo_callback, FLUTTER_ENGINE_VERSION, FlutterEngineRun(), FlutterEngineRunsAOTCompiledDartCode(), flutter::GetExecutableDirectory(), FlutterOpenGLRendererConfig::gl_proc_resolver, FlutterDesktopEngineProperties::icu_data_path, FlutterProjectArgs::icu_data_path, kOpenGL, kSuccess, LoadAotData(), FlutterOpenGLRendererConfig::make_current, FlutterOpenGLRendererConfig::make_resource_current, FlutterRendererConfig::open_gl, flutter::path, FlutterProjectArgs::platform_message_callback, FlutterCustomTaskRunners::platform_task_runner, FlutterOpenGLRendererConfig::present, result, FlutterOpenGLRendererConfig::struct_size, FlutterCustomTaskRunners::struct_size, FlutterProjectArgs::struct_size, FlutterDesktopEngineProperties::switches, FlutterDesktopEngineProperties::switches_count, FlutterRendererConfig::type, and FlutterDesktopEngineState::window_controller.

Referenced by FlutterDesktopCreateWindow(), and FlutterDesktopRunEngine().

634  {
635  // FlutterProjectArgs is expecting a full argv, so when processing it for
636  // flags the first item is treated as the executable and ignored. Add a dummy
637  // value so that all provided arguments are used.
638  std::vector<const char*> argv = {"placeholder"};
639  if (engine_properties.switches_count > 0) {
640  argv.insert(argv.end(), &engine_properties.switches[0],
641  &engine_properties.switches[engine_properties.switches_count]);
642  }
643 
644  std::filesystem::path assets_path =
645  std::filesystem::u8path(engine_properties.assets_path);
646  std::filesystem::path icu_path =
647  std::filesystem::u8path(engine_properties.icu_data_path);
648  std::filesystem::path aot_library_path =
649  std::filesystem::u8path(engine_properties.aot_library_path);
650  if (assets_path.is_relative() || icu_path.is_relative() ||
651  (!aot_library_path.empty() && aot_library_path.is_relative())) {
652  // Treat relative paths as relative to the directory of this executable.
653  std::filesystem::path executable_location =
655  if (executable_location.empty()) {
656  std::cerr << "Unable to find executable location to resolve paths."
657  << std::endl;
658  return false;
659  }
660  assets_path = std::filesystem::path(executable_location) / assets_path;
661  icu_path = std::filesystem::path(executable_location) / icu_path;
662  if (!aot_library_path.empty()) {
663  aot_library_path =
664  std::filesystem::path(executable_location) / aot_library_path;
665  }
666  }
667  std::string assets_path_string = assets_path.u8string();
668  std::string icu_path_string = icu_path.u8string();
669  std::string lib_path_string = aot_library_path.u8string();
670 
671  // Configure a task runner using the event loop.
672  engine_state->event_loop = std::move(event_loop);
673  FlutterTaskRunnerDescription platform_task_runner = {};
674  ConfigurePlatformTaskRunner(&platform_task_runner, engine_state);
675  FlutterCustomTaskRunners task_runners = {};
676  task_runners.struct_size = sizeof(FlutterCustomTaskRunners);
677  task_runners.platform_task_runner = &platform_task_runner;
678 
679  FlutterRendererConfig config = {};
680  config.type = kOpenGL;
681  config.open_gl.struct_size = sizeof(config.open_gl);
684  config.open_gl.present = EnginePresent;
687  // Don't provide a resolver in headless mode, since headless mode should
688  // work even if GLFW initialization failed.
689  if (engine_state->window_controller != nullptr) {
691  }
693  args.struct_size = sizeof(FlutterProjectArgs);
694  args.assets_path = assets_path_string.c_str();
695  args.icu_data_path = icu_path_string.c_str();
696  args.command_line_argc = static_cast<int>(argv.size());
697  args.command_line_argv = &argv[0];
699  args.custom_task_runners = &task_runners;
700 
702  engine_state->aot_data = LoadAotData(lib_path_string);
703  if (!engine_state->aot_data) {
704  std::cerr << "Unable to start engine without AOT data." << std::endl;
705  return false;
706  }
707  args.aot_data = engine_state->aot_data.get();
708  }
709 
711  auto result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &args,
712  engine_state, &engine);
713  if (result != kSuccess || engine == nullptr) {
714  std::cerr << "Failed to start Flutter engine: error " << result
715  << std::endl;
716  return false;
717  }
718  engine_state->flutter_engine = engine;
719  return true;
720 }
static void * EngineProcResolver(void *user_data, const char *name)
G_BEGIN_DECLS FlValue * args
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
struct _FlutterEngine * FLUTTER_API_SYMBOL(FlutterEngine)
Definition: embedder.h:228
static bool EnginePresent(void *user_data)
static uint32_t EngineGetActiveFbo(void *user_data)
static bool EngineMakeResourceContextCurrent(void *user_data)
const char * icu_data_path
Definition: embedder.h:1378
std::filesystem::path GetExecutableDirectory()
Definition: path_utils.cc:16
const FlutterCustomTaskRunners * custom_task_runners
Definition: embedder.h:1493
GAsyncResult * result
FlutterPlatformMessageCallback platform_message_callback
Definition: embedder.h:1402
static bool EngineMakeContextCurrent(void *user_data)
const char *const * command_line_argv
Definition: embedder.h:1396
static void ConfigurePlatformTaskRunner(FlutterTaskRunnerDescription *task_runner, FlutterDesktopEngineState *engine_state)
#define FLUTTER_ENGINE_VERSION
Definition: embedder.h:63
FlutterRendererType type
Definition: embedder.h:555
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:869
size_t struct_size
The size of this struct. Must be sizeof(FlutterOpenGLRendererConfig).
Definition: embedder.h:388
static bool EngineClearContext(void *user_data)
UniqueAotDataPtr aot_data
BoolCallback make_resource_current
Definition: embedder.h:407
BoolCallback clear_current
Definition: embedder.h:390
FlutterDesktopWindowControllerState * window_controller
const char * assets_path
Definition: embedder.h:1354
BoolCallback make_current
Definition: embedder.h:389
FlutterOpenGLRendererConfig open_gl
Definition: embedder.h:557
size_t struct_size
The size of this struct. Must be sizeof(FlutterProjectArgs).
Definition: embedder.h:1350
UniqueAotDataPtr LoadAotData(std::filesystem::path aot_data_path)
std::unique_ptr< flutter::EventLoop > event_loop
UIntCallback fbo_callback
Definition: embedder.h:400
const FlutterTaskRunnerDescription * platform_task_runner
Definition: embedder.h:943
FlutterEngineAOTData aot_data
Definition: embedder.h:1543
static void EngineOnFlutterPlatformMessage(const FlutterPlatformMessage *engine_message, void *user_data)
ProcResolver gl_proc_resolver
Definition: embedder.h:424
size_t struct_size
The size of this struct. Must be sizeof(FlutterCustomTaskRunners).
Definition: embedder.h:938
bool FlutterEngineRunsAOTCompiledDartCode(void)
Returns if the Flutter engine instance will run AOT compiled Dart code. This call has no threading re...
Definition: embedder.cc:2061
int command_line_argc
The command line argument count used to initialize the project.
Definition: embedder.h:1380

◆ SendPointerEventWithData()

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

Definition at line 283 of file flutter_glfw.cc.

References event, FlutterEngineSendPointerEvent(), GetWindowController(), kAdd, kDown, kFlutterPointerDeviceKindMouse, kRemove, kUp, FlutterPointerEvent::phase, FlutterPointerEvent::struct_size, FlutterPointerEvent::x, and FlutterPointerEvent::y.

Referenced by GLFWCursorEnterCallback(), GLFWCursorPositionCallback(), GLFWMouseButtonCallback(), and GLFWScrollCallback().

284  {
285  auto* controller = GetWindowController(window);
286  // If sending anything other than an add, and the pointer isn't already added,
287  // synthesize an add to satisfy Flutter's expectations about events.
288  if (!controller->pointer_currently_added &&
289  event_data.phase != FlutterPointerPhase::kAdd) {
290  FlutterPointerEvent event = {};
292  event.x = event_data.x;
293  event.y = event_data.y;
295  }
296  // Don't double-add (e.g., if events are delivered out of order, so an add has
297  // already been synthesized).
298  if (controller->pointer_currently_added &&
299  event_data.phase == FlutterPointerPhase::kAdd) {
300  return;
301  }
302 
303  FlutterPointerEvent event = event_data;
304  // Set metadata that's always the same regardless of the event.
305  event.struct_size = sizeof(event);
306  event.timestamp =
307  std::chrono::duration_cast<std::chrono::microseconds>(
308  std::chrono::high_resolution_clock::now().time_since_epoch())
309  .count();
311  event.buttons =
312  (event.phase == FlutterPointerPhase::kAdd) ? 0 : controller->buttons;
313 
314  // Convert all screen coordinates to pixel coordinates.
315  double pixels_per_coordinate =
316  controller->window_wrapper->pixels_per_screen_coordinate;
317  event.x *= pixels_per_coordinate;
318  event.y *= pixels_per_coordinate;
319  event.scroll_delta_x *= pixels_per_coordinate;
320  event.scroll_delta_y *= pixels_per_coordinate;
321 
322  FlutterEngineSendPointerEvent(controller->engine->flutter_engine, &event, 1);
323 
324  if (event_data.phase == FlutterPointerPhase::kAdd) {
325  controller->pointer_currently_added = true;
326  } else if (event_data.phase == FlutterPointerPhase::kRemove) {
327  controller->pointer_currently_added = false;
328  } else if (event_data.phase == FlutterPointerPhase::kDown) {
329  controller->pointer_currently_down = true;
330  } else if (event_data.phase == FlutterPointerPhase::kUp) {
331  controller->pointer_currently_down = false;
332  }
333 }
Definition: embedder.h:595
double y
The y coordinate of the pointer event in physical pixels.
Definition: embedder.h:658
static void SendPointerEventWithData(GLFWwindow *window, const FlutterPointerEvent &event_data)
FlKeyEvent * event
size_t struct_size
The size of this struct. Must be sizeof(FlutterPointerEvent).
Definition: embedder.h:649
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)
Definition: embedder.h:612
double x
The x coordinate of the pointer event in physical pixels.
Definition: embedder.h:656
FlutterEngineResult FlutterEngineSendPointerEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPointerEvent *pointers, size_t events_count)
Definition: embedder.cc:1510
FlutterPointerPhase phase
Definition: embedder.h:650

◆ SendWindowMetrics()

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

Definition at line 208 of file flutter_glfw.cc.

References FlutterDesktopWindowControllerState::engine, event, FlutterEngineSendWindowMetricsEvent(), height, kDpPerInch, FlutterDesktopWindowControllerState::monitor_screen_coordinates_per_inch, FlutterWindowMetricsEvent::struct_size, width, and FlutterDesktopWindowControllerState::window_wrapper.

Referenced by FlutterDesktopWindowSetPixelRatioOverride(), GLFWFramebufferSizeCallback(), and GLFWWindowRefreshCallback().

210  {
211  double dpi = controller->window_wrapper->pixels_per_screen_coordinate *
213 
214  FlutterWindowMetricsEvent event = {};
215  event.struct_size = sizeof(event);
216  event.width = width;
217  event.height = height;
218  if (controller->window_wrapper->pixel_ratio_override == 0.0) {
219  // The Flutter pixel_ratio is defined as DPI/dp. Limit the ratio to a
220  // minimum of 1 to avoid rendering a smaller UI on standard resolution
221  // monitors.
222  event.pixel_ratio = std::max(dpi / kDpPerInch, 1.0);
223  } else {
224  event.pixel_ratio = controller->window_wrapper->pixel_ratio_override;
225  }
226  FlutterEngineSendWindowMetricsEvent(controller->engine->flutter_engine,
227  &event);
228 }
std::unique_ptr< FlutterDesktopEngineState > engine
Definition: flutter_glfw.cc:55
std::unique_ptr< FlutterDesktopWindow > window_wrapper
Definition: flutter_glfw.cc:58
FlKeyEvent * event
int32_t width
size_t struct_size
The size of this struct. Must be sizeof(FlutterWindowMetricsEvent).
Definition: embedder.h:565
int32_t height
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterWindowMetricsEvent *flutter_metrics)
Definition: embedder.cc:1388
static constexpr double kDpPerInch
Definition: flutter_glfw.cc:43

◆ SetEventLocationFromCursorPosition()

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

Definition at line 336 of file flutter_glfw.cc.

References FlutterPointerEvent::x, and FlutterPointerEvent::y.

Referenced by GLFWCursorEnterCallback(), GLFWMouseButtonCallback(), and GLFWScrollCallback().

338  {
339  glfwGetCursorPos(window, &event_data->x, &event_data->y);
340 }
double y
The y coordinate of the pointer event in physical pixels.
Definition: embedder.h:658
double x
The x coordinate of the pointer event in physical pixels.
Definition: embedder.h:656

◆ SetEventPhaseFromCursorButtonState()

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

Definition at line 346 of file flutter_glfw.cc.

References GetWindowController(), kDown, kHover, kMove, kUp, and FlutterPointerEvent::phase.

Referenced by GLFWCursorPositionCallback(), GLFWMouseButtonCallback(), and GLFWScrollCallback().

348  {
349  auto* controller = GetWindowController(window);
350  event_data->phase =
351  (buttons == 0)
352  ? (controller->pointer_currently_down ? FlutterPointerPhase::kUp
354  : (controller->pointer_currently_down ? FlutterPointerPhase::kMove
356 }
Definition: embedder.h:595
The pointer moved while up.
Definition: embedder.h:619
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)
FlutterPointerPhase phase
Definition: embedder.h:650

◆ SetHoverCallbacksEnabled()

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

Definition at line 456 of file flutter_glfw.cc.

References GLFWCursorEnterCallback(), and GLFWCursorPositionCallback().

Referenced by FlutterDesktopWindowSetHoverEnabled(), GLFWAssignEventCallbacks(), and GLFWClearEventCallbacks().

456  {
457  glfwSetCursorEnterCallback(window,
458  enabled ? GLFWCursorEnterCallback : nullptr);
459  glfwSetCursorPosCallback(window,
460  enabled ? GLFWCursorPositionCallback : nullptr);
461 }
static void GLFWCursorPositionCallback(GLFWwindow *window, double x, double y)
static void GLFWCursorEnterCallback(GLFWwindow *window, int entered)

◆ SetUpCommonEngineState()

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

Definition at line 748 of file flutter_glfw.cc.

References FlutterDesktopEngineState::internal_plugin_registrar, FlutterDesktopEngineState::message_dispatcher, FlutterDesktopEngineState::messenger, FlutterDesktopEngineState::platform_handler, FlutterDesktopEngineState::plugin_registrar, SetUpLocales(), state, and FlutterDesktopWindowControllerState::window.

Referenced by FlutterDesktopCreateWindow(), and FlutterDesktopRunEngine().

749  {
750  // Messaging.
751  state->messenger = std::make_unique<FlutterDesktopMessenger>();
752  state->messenger->engine = state;
753  state->message_dispatcher =
754  std::make_unique<flutter::IncomingMessageDispatcher>(
755  state->messenger.get());
756 
757  // Plugins.
758  state->plugin_registrar = std::make_unique<FlutterDesktopPluginRegistrar>();
759  state->plugin_registrar->engine = state;
761  std::make_unique<flutter::PluginRegistrar>(state->plugin_registrar.get());
762 
763  // System channel handler.
764  state->platform_handler = std::make_unique<flutter::PlatformHandler>(
765  state->internal_plugin_registrar->messenger(), window);
766 
767  SetUpLocales(state);
768 }
static void SetUpLocales(FlutterDesktopEngineState *state)
std::unique_ptr< flutter::IncomingMessageDispatcher > message_dispatcher
std::unique_ptr< FlutterDesktopMessenger > messenger
std::unique_ptr< flutter::PlatformHandler > platform_handler
std::unique_ptr< flutter::PluginRegistrar > internal_plugin_registrar
std::unique_ptr< FlutterDesktopPluginRegistrar > plugin_registrar
AtkStateType state

◆ SetUpLocales()

static void SetUpLocales ( FlutterDesktopEngineState state)
static

Definition at line 723 of file flutter_glfw.cc.

References flutter::ConvertToFlutterLocale(), FlutterEngineUpdateLocales(), flutter::GetPreferredLanguageInfo(), kSuccess, result, and flutter::transform.

Referenced by SetUpCommonEngineState().

723  {
724  std::vector<flutter::LanguageInfo> languages =
726  std::vector<FlutterLocale> flutter_locales =
728  // Convert the locale list to the locale pointer list that must be provided.
729  std::vector<const FlutterLocale*> flutter_locale_list;
730  flutter_locale_list.reserve(flutter_locales.size());
732  flutter_locales.begin(), flutter_locales.end(),
733  std::back_inserter(flutter_locale_list),
734  [](const auto& arg) -> const auto* { return &arg; });
736  state->flutter_engine, flutter_locale_list.data(),
737  flutter_locale_list.size());
738  if (result != kSuccess) {
739  std::cerr << "Failed to set up Flutter locales." << std::endl;
740  }
741 }
std::vector< FlutterLocale > ConvertToFlutterLocale(const std::vector< LanguageInfo > &languages)
GAsyncResult * result
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:2001
std::vector< LanguageInfo > GetPreferredLanguageInfo()
FlutterEngineResult
Definition: embedder.h:65

Variable Documentation

◆ kDpPerInch

constexpr double kDpPerInch = 160.0
static

Definition at line 43 of file flutter_glfw.cc.

Referenced by GetScreenCoordinatesPerInch(), and SendWindowMetrics().

◆ kFlutterDesktopDontCare

const int kFlutterDesktopDontCare = GLFW_DONT_CARE

Definition at line 41 of file flutter_glfw.cc.