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/cpp/client_wrapper/include/flutter/plugin_registrar.h"
#include "flutter/shell/platform/common/cpp/incoming_message_dispatcher.h"
#include "flutter/shell/platform/common/cpp/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/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)
 
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 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)
 

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

Referenced by CreateShareWindowForWindow(), and FlutterDesktopCreateWindow().

◆ GLFW_TRUE

#define GLFW_TRUE   1

Definition at line 30 of file flutter_glfw.cc.

Referenced by GLFWKeyCallback(), and main().

Typedef Documentation

◆ UniqueAotDataPtr

Definition at line 101 of file flutter_glfw.cc.

◆ UniqueGLFWwindowPtr

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

Definition at line 36 of file flutter_glfw.cc.

Function Documentation

◆ ConfigurePlatformTaskRunner()

static void ConfigurePlatformTaskRunner ( FlutterTaskRunnerDescription task_runner,
FlutterDesktopEngineState engine_state 
)
static

Definition at line 225 of file flutter_glfw.cc.

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

Referenced by RunFlutterEngine().

227  {
228  task_runner->struct_size = sizeof(FlutterTaskRunnerDescription);
229  task_runner->user_data = engine_state;
230  task_runner->runs_task_on_current_thread_callback = [](void* state) -> bool {
231  return reinterpret_cast<FlutterDesktopEngineState*>(state)
232  ->event_loop->RunsTasksOnCurrentThread();
233  };
234  task_runner->post_task_callback =
235  [](FlutterTask task, uint64_t target_time_nanos, void* state) -> void {
236  reinterpret_cast<FlutterDesktopEngineState*>(state)->event_loop->PostTask(
237  task, target_time_nanos);
238  };
239 }
size_t struct_size
The size of this struct. Must be sizeof(FlutterTaskRunnerDescription).
Definition: embedder.h:718
FlutterTaskRunnerPostTaskCallback post_task_callback
Definition: embedder.h:735
BoolCallback runs_task_on_current_thread_callback
Definition: embedder.h:724

◆ ConvertToDesktopMessage()

static FlutterDesktopMessage ConvertToDesktopMessage ( const FlutterPlatformMessage engine_message)
static

Definition at line 170 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().

171  {
172  FlutterDesktopMessage message = {};
173  message.struct_size = sizeof(message);
174  message.channel = engine_message.channel;
175  message.message = engine_message.message;
176  message.message_size = engine_message.message_size;
177  message.response_handle = engine_message.response_handle;
178  return message;
179 }
const char * channel
Definition: embedder.h:563
const FlutterPlatformMessageResponseHandle * response_handle
Definition: embedder.h:572
const FlutterDesktopMessageResponseHandle * response_handle
const uint8_t * message
Definition: embedder.h:564
const uint8_t * message

◆ CreateShareWindowForWindow()

static UniqueGLFWwindowPtr CreateShareWindowForWindow ( GLFWwindow *  window)
static

Definition at line 158 of file flutter_glfw.cc.

References GLFW_FALSE.

Referenced by FlutterDesktopCreateWindow().

158  {
159  glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
160  glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
161 #if defined(__linux__)
162  glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
163 #endif
164  GLFWwindow* share_window = glfwCreateWindow(1, 1, "", NULL, window);
165  glfwDefaultWindowHints();
166  return UniqueGLFWwindowPtr(share_window, glfwDestroyWindow);
167 }
#define GLFW_FALSE
Definition: flutter_glfw.cc:33
std::unique_ptr< GLFWwindow, void(*)(GLFWwindow *)> UniqueGLFWwindowPtr
Definition: flutter_glfw.cc:36

◆ EngineClearContext()

static bool EngineClearContext ( void *  user_data)
static

Definition at line 512 of file flutter_glfw.cc.

References user_data, and FlutterDesktopEngineState::window_controller.

Referenced by RunFlutterEngine().

512  {
513  FlutterDesktopEngineState* engine_state =
514  static_cast<FlutterDesktopEngineState*>(user_data);
515  FlutterDesktopWindowControllerState* window_controller =
516  engine_state->window_controller;
517  if (!window_controller) {
518  return false;
519  }
520  glfwMakeContextCurrent(nullptr);
521  return true;
522 }
G_BEGIN_DECLS FlMethodCall gpointer user_data
FlutterDesktopWindowControllerState * window_controller

◆ EngineGetActiveFbo()

static uint32_t EngineGetActiveFbo ( void *  user_data)
static

Definition at line 536 of file flutter_glfw.cc.

Referenced by RunFlutterEngine().

536  {
537  return 0;
538 }

◆ EngineMakeContextCurrent()

static bool EngineMakeContextCurrent ( void *  user_data)
static

Definition at line 488 of file flutter_glfw.cc.

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

Referenced by RunFlutterEngine().

488  {
489  FlutterDesktopEngineState* engine_state =
490  static_cast<FlutterDesktopEngineState*>(user_data);
491  FlutterDesktopWindowControllerState* window_controller =
492  engine_state->window_controller;
493  if (!window_controller) {
494  return false;
495  }
496  glfwMakeContextCurrent(window_controller->window.get());
497  return true;
498 }
G_BEGIN_DECLS FlMethodCall gpointer user_data
FlutterDesktopWindowControllerState * window_controller

◆ EngineMakeResourceContextCurrent()

static bool EngineMakeResourceContextCurrent ( void *  user_data)
static

Definition at line 500 of file flutter_glfw.cc.

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

Referenced by RunFlutterEngine().

500  {
501  FlutterDesktopEngineState* engine_state =
502  static_cast<FlutterDesktopEngineState*>(user_data);
503  FlutterDesktopWindowControllerState* window_controller =
504  engine_state->window_controller;
505  if (!window_controller) {
506  return false;
507  }
508  glfwMakeContextCurrent(window_controller->resource_window.get());
509  return true;
510 }
UniqueGLFWwindowPtr resource_window
Definition: flutter_glfw.cc:50
G_BEGIN_DECLS FlMethodCall gpointer user_data
FlutterDesktopWindowControllerState * window_controller

◆ EngineOnFlutterPlatformMessage()

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

Definition at line 457 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().

459  {
460  if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) {
461  std::cerr << "Invalid message size received. Expected: "
462  << sizeof(FlutterPlatformMessage) << " but received "
463  << engine_message->struct_size << std::endl;
464  return;
465  }
466 
467  FlutterDesktopEngineState* engine_state =
468  static_cast<FlutterDesktopEngineState*>(user_data);
469  GLFWwindow* window = engine_state->window_controller == nullptr
470  ? nullptr
471  : engine_state->window_controller->window.get();
472 
473  auto message = ConvertToDesktopMessage(*engine_message);
474  engine_state->message_dispatcher->HandleMessage(
475  message,
476  [window] {
477  if (window) {
478  GLFWClearEventCallbacks(window);
479  }
480  },
481  [window] {
482  if (window) {
483  GLFWAssignEventCallbacks(window);
484  }
485  });
486 }
static void GLFWClearEventCallbacks(GLFWwindow *window)
std::unique_ptr< flutter::IncomingMessageDispatcher > message_dispatcher
static void GLFWAssignEventCallbacks(GLFWwindow *window)
static FlutterDesktopMessage ConvertToDesktopMessage(const FlutterPlatformMessage &engine_message)
G_BEGIN_DECLS FlMethodCall gpointer user_data
FlutterDesktopWindowControllerState * window_controller
size_t struct_size
The size of this struct. Must be sizeof(FlutterPlatformMessage).
Definition: embedder.h:562

◆ EnginePresent()

static bool EnginePresent ( void *  user_data)
static

Definition at line 524 of file flutter_glfw.cc.

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

Referenced by RunFlutterEngine().

524  {
525  FlutterDesktopEngineState* engine_state =
526  static_cast<FlutterDesktopEngineState*>(user_data);
527  FlutterDesktopWindowControllerState* window_controller =
528  engine_state->window_controller;
529  if (!window_controller) {
530  return false;
531  }
532  glfwSwapBuffers(window_controller->window.get());
533  return true;
534 }
G_BEGIN_DECLS FlMethodCall gpointer user_data
FlutterDesktopWindowControllerState * window_controller

◆ EngineProcResolver()

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

Definition at line 542 of file flutter_glfw.cc.

Referenced by RunFlutterEngine().

542  {
543  return reinterpret_cast<void*>(glfwGetProcAddress(name));
544 }
const char * name
Definition: fuchsia.cc:50

◆ FlutterDesktopCreateWindow()

FlutterDesktopWindowControllerRef FlutterDesktopCreateWindow ( const FlutterDesktopWindowProperties window_properties,
const FlutterDesktopEngineProperties engine_properties 
)

Definition at line 728 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(), FlutterDesktopWindowProperties::title, FlutterDesktopWindowProperties::width, and FlutterDesktopWindowControllerState::window.

730  {
731  auto state = std::make_unique<FlutterDesktopWindowControllerState>();
732 
733  // Create the window, and set the state as its user data.
734  if (window_properties.prevent_resize) {
735  glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
736  }
737 #if defined(__linux__)
738  glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
739 #endif
740  state->window = UniqueGLFWwindowPtr(
741  glfwCreateWindow(window_properties.width, window_properties.height,
742  window_properties.title, NULL, NULL),
743  glfwDestroyWindow);
744  glfwDefaultWindowHints();
745  GLFWwindow* window = state->window.get();
746  if (window == nullptr) {
747  return nullptr;
748  }
749  GLFWClearCanvas(window);
750  glfwSetWindowUserPointer(window, state.get());
751 
752  // Create the share window before starting the engine, since it may call
753  // EngineMakeResourceContextCurrent immediately.
754  state->resource_window = CreateShareWindowForWindow(window);
755 
756  state->engine = std::make_unique<FlutterDesktopEngineState>();
757  state->engine->window_controller = state.get();
758 
759  // Create an event loop for the window. It is not running yet.
760  auto event_loop = std::make_unique<flutter::GLFWEventLoop>(
761  std::this_thread::get_id(), // main GLFW thread
762  [engine_state = state->engine.get()](const auto* task) {
763  if (FlutterEngineRunTask(engine_state->flutter_engine, task) !=
764  kSuccess) {
765  std::cerr << "Could not post an engine task." << std::endl;
766  }
767  });
768 
769  // Start the engine.
770  if (!RunFlutterEngine(state->engine.get(), engine_properties,
771  std::move(event_loop))) {
772  return nullptr;
773  }
774  SetUpCommonEngineState(state->engine.get(), window);
775 
776  state->window_wrapper = std::make_unique<FlutterDesktopWindow>();
777  state->window_wrapper->window = window;
778 
779  // Set up the keyboard handlers
780  auto internal_plugin_messenger =
781  state->engine->internal_plugin_registrar->messenger();
782  state->keyboard_hook_handlers.push_back(
783  std::make_unique<flutter::KeyEventHandler>(internal_plugin_messenger));
784  state->keyboard_hook_handlers.push_back(
785  std::make_unique<flutter::TextInputPlugin>(internal_plugin_messenger));
786 
787  // Trigger an initial size callback to send size information to Flutter.
788  state->monitor_screen_coordinates_per_inch = GetScreenCoordinatesPerInch();
789  int width_px, height_px;
790  glfwGetFramebufferSize(window, &width_px, &height_px);
791  GLFWFramebufferSizeCallback(window, width_px, height_px);
792 
793  // Set up GLFW callbacks for the window.
794  glfwSetFramebufferSizeCallback(window, GLFWFramebufferSizeCallback);
795  glfwSetWindowRefreshCallback(window, GLFWWindowRefreshCallback);
796  GLFWAssignEventCallbacks(window);
797 
798  return state.release();
799 }
#define GLFW_FALSE
Definition: flutter_glfw.cc:33
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:1716
static UniqueGLFWwindowPtr CreateShareWindowForWindow(GLFWwindow *window)
static double GetScreenCoordinatesPerInch()
static void GLFWAssignEventCallbacks(GLFWwindow *window)
std::unique_ptr< GLFWwindow, void(*)(GLFWwindow *)> UniqueGLFWwindowPtr
Definition: flutter_glfw.cc:36
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)

◆ FlutterDesktopDestroyWindow()

void FlutterDesktopDestroyWindow ( FlutterDesktopWindowControllerRef  controller)

Definition at line 801 of file flutter_glfw.cc.

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

801  {
803  controller->engine->plugin_registrar.get();
804  if (registrar->destruction_handler) {
805  registrar->destruction_handler(registrar);
806  }
807  FlutterEngineShutdown(controller->engine->flutter_engine);
808  delete controller;
809 }
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:1217
std::unique_ptr< FlutterDesktopEngineState > engine
Definition: flutter_glfw.cc:54
FlutterDesktopOnPluginRegistrarDestroyed destruction_handler

◆ FlutterDesktopGetEngine()

FlutterDesktopEngineRef FlutterDesktopGetEngine ( FlutterDesktopWindowControllerRef  controller)

Definition at line 914 of file flutter_glfw.cc.

References FlutterDesktopWindowControllerState::engine.

915  {
916  return controller->engine.get();
917 }
std::unique_ptr< FlutterDesktopEngineState > engine
Definition: flutter_glfw.cc:54

◆ FlutterDesktopGetPluginRegistrar()

FlutterDesktopPluginRegistrarRef FlutterDesktopGetPluginRegistrar ( FlutterDesktopEngineRef  engine,
const char *  plugin_name 
)

Definition at line 919 of file flutter_glfw.cc.

References FlutterDesktopEngineState::plugin_registrar.

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

◆ FlutterDesktopGetWindow()

FlutterDesktopWindowRef FlutterDesktopGetWindow ( FlutterDesktopWindowControllerRef  controller)

Definition at line 906 of file flutter_glfw.cc.

References FlutterDesktopWindowControllerState::window_wrapper.

907  {
908  // Currently, one registrar acts as the registrar for all plugins, so the
909  // name is ignored. It is part of the API to reduce churn in the future when
910  // aligning more closely with the Flutter registrar system.
911  return controller->window_wrapper.get();
912 }
std::unique_ptr< FlutterDesktopWindow > window_wrapper
Definition: flutter_glfw.cc:57

◆ FlutterDesktopInit()

bool FlutterDesktopInit ( )

Definition at line 718 of file flutter_glfw.cc.

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

718  {
719  // Before making any GLFW calls, set up a logging error handler.
720  glfwSetErrorCallback(GLFWErrorCallback);
721  return glfwInit();
722 }
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 1027 of file flutter_glfw.cc.

References FlutterDesktopMessengerSendWithReply().

1030  {
1031  return FlutterDesktopMessengerSendWithReply(messenger, channel, message,
1032  message_size, nullptr, nullptr);
1033 }
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 1035 of file flutter_glfw.cc.

References FlutterDesktopMessenger::engine, and FlutterEngineSendPlatformMessageResponse().

1039  {
1040  FlutterEngineSendPlatformMessageResponse(messenger->engine->flutter_engine,
1041  handle, data, data_length);
1042 }
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:1496
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 992 of file flutter_glfw.cc.

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

Referenced by FlutterDesktopMessengerSend().

997  {
998  FlutterPlatformMessageResponseHandle* response_handle = nullptr;
999  if (reply != nullptr && user_data != nullptr) {
1001  messenger->engine->flutter_engine, reply, user_data, &response_handle);
1002  if (result != kSuccess) {
1003  std::cout << "Failed to create response handle\n";
1004  return false;
1005  }
1006  }
1007 
1008  FlutterPlatformMessage platform_message = {
1009  sizeof(FlutterPlatformMessage),
1010  channel,
1011  message,
1012  message_size,
1013  response_handle,
1014  };
1015 
1017  messenger->engine->flutter_engine, &platform_message);
1018 
1019  if (response_handle != nullptr) {
1021  messenger->engine->flutter_engine, response_handle);
1022  }
1023 
1024  return message_result == kSuccess;
1025 }
FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterPlatformMessageResponseHandle *response)
Collects the handle created using FlutterPlatformMessageCreateResponseHandle.
Definition: embedder.cc:1482
FlutterDesktopEngineState * engine
G_BEGIN_DECLS FlMethodCall gpointer user_data
FlutterEngineResult
Definition: embedder.h:65
FlutterEngineResult FlutterEngineSendPlatformMessage(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessage *flutter_message)
Definition: embedder.cc:1395
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:1447

◆ FlutterDesktopMessengerSetCallback()

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

Definition at line 1044 of file flutter_glfw.cc.

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

1047  {
1048  messenger->engine->message_dispatcher->SetMessageCallback(channel, callback,
1049  user_data);
1050 }
std::unique_ptr< flutter::IncomingMessageDispatcher > message_dispatcher
FlutterDesktopEngineState * engine
G_BEGIN_DECLS FlMethodCall gpointer user_data

◆ FlutterDesktopPluginRegistrarEnableInputBlocking()

void FlutterDesktopPluginRegistrarEnableInputBlocking ( FlutterDesktopPluginRegistrarRef  registrar,
const char *  channel 
)

Definition at line 965 of file flutter_glfw.cc.

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

967  {
968  registrar->engine->message_dispatcher->EnableInputBlockingForChannel(channel);
969 }
std::unique_ptr< flutter::IncomingMessageDispatcher > message_dispatcher
FlutterDesktopEngineState * engine

◆ FlutterDesktopPluginRegistrarGetMessenger()

FlutterDesktopMessengerRef FlutterDesktopPluginRegistrarGetMessenger ( FlutterDesktopPluginRegistrarRef  registrar)

Definition at line 971 of file flutter_glfw.cc.

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

972  {
973  return registrar->engine->messenger.get();
974 }
std::unique_ptr< FlutterDesktopMessenger > messenger
FlutterDesktopEngineState * engine

◆ FlutterDesktopPluginRegistrarGetWindow()

FlutterDesktopWindowRef FlutterDesktopPluginRegistrarGetWindow ( FlutterDesktopPluginRegistrarRef  registrar)

Definition at line 982 of file flutter_glfw.cc.

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

983  {
985  registrar->engine->window_controller;
986  if (!controller) {
987  return nullptr;
988  }
989  return controller->window_wrapper.get();
990 }
std::unique_ptr< FlutterDesktopWindow > window_wrapper
Definition: flutter_glfw.cc:57
FlutterDesktopWindowControllerState * window_controller
FlutterDesktopEngineState * engine

◆ FlutterDesktopPluginRegistrarSetDestructionHandler()

void FlutterDesktopPluginRegistrarSetDestructionHandler ( FlutterDesktopPluginRegistrarRef  registrar,
FlutterDesktopOnPluginRegistrarDestroyed  callback 
)

Definition at line 976 of file flutter_glfw.cc.

References FlutterDesktopPluginRegistrar::destruction_handler.

978  {
979  registrar->destruction_handler = callback;
980 }
FlutterDesktopOnPluginRegistrarDestroyed destruction_handler

◆ FlutterDesktopRunEngine()

FlutterDesktopEngineRef FlutterDesktopRunEngine ( const FlutterDesktopEngineProperties properties)

Definition at line 928 of file flutter_glfw.cc.

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

929  {
930  auto engine_state = std::make_unique<FlutterDesktopEngineState>();
931 
932  auto event_loop = std::make_unique<flutter::HeadlessEventLoop>(
933  std::this_thread::get_id(),
934  [state = engine_state.get()](const auto* task) {
935  if (FlutterEngineRunTask(state->flutter_engine, task) != kSuccess) {
936  std::cerr << "Could not post an engine task." << std::endl;
937  }
938  });
939 
940  if (!RunFlutterEngine(engine_state.get(), properties,
941  std::move(event_loop))) {
942  return nullptr;
943  }
944  SetUpCommonEngineState(engine_state.get(), nullptr);
945 
946  return engine_state.release();
947 }
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:1716
static bool RunFlutterEngine(FlutterDesktopEngineState *engine_state, const FlutterDesktopEngineProperties &engine_properties, std::unique_ptr< flutter::EventLoop > event_loop)
static void SetUpCommonEngineState(FlutterDesktopEngineState *state, GLFWwindow *window)

◆ FlutterDesktopRunEngineEventLoopWithTimeout()

void FlutterDesktopRunEngineEventLoopWithTimeout ( FlutterDesktopEngineRef  engine,
uint32_t  timeout_milliseconds 
)

Definition at line 949 of file flutter_glfw.cc.

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

Referenced by FlutterDesktopRunWindowEventLoopWithTimeout().

951  {
952  std::chrono::nanoseconds wait_duration =
953  timeout_milliseconds == 0
954  ? std::chrono::nanoseconds::max()
955  : std::chrono::milliseconds(timeout_milliseconds);
956  engine->event_loop->WaitForEvents(wait_duration);
957 }
Definition: ref_ptr.h:252
std::unique_ptr< flutter::EventLoop > event_loop

◆ FlutterDesktopRunWindowEventLoopWithTimeout()

bool FlutterDesktopRunWindowEventLoopWithTimeout ( FlutterDesktopWindowControllerRef  controller,
uint32_t  timeout_milliseconds 
)

Definition at line 898 of file flutter_glfw.cc.

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

900  {
902  timeout_milliseconds);
903  return !glfwWindowShouldClose(controller->window.get());
904 }
std::unique_ptr< FlutterDesktopEngineState > engine
Definition: flutter_glfw.cc:54
void FlutterDesktopRunEngineEventLoopWithTimeout(FlutterDesktopEngineRef engine, uint32_t timeout_milliseconds)

◆ FlutterDesktopShutDownEngine()

bool FlutterDesktopShutDownEngine ( FlutterDesktopEngineRef  engine)

Definition at line 959 of file flutter_glfw.cc.

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

959  {
960  auto result = FlutterEngineShutdown(engine->flutter_engine);
961  delete engine;
962  return (result == kSuccess);
963 }
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:1217

◆ FlutterDesktopTerminate()

void FlutterDesktopTerminate ( )

Definition at line 724 of file flutter_glfw.cc.

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

724  {
725  glfwTerminate();
726 }

◆ FlutterDesktopWindowGetFrame()

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

Definition at line 831 of file flutter_glfw.cc.

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

835  {
836  glfwGetWindowPos(flutter_window->window, x, y);
837  glfwGetWindowSize(flutter_window->window, width, height);
838  // The above gives content area size and position; adjust for the window
839  // decoration to give actual window frame.
840  int frame_left, frame_top, frame_right, frame_bottom;
841  glfwGetWindowFrameSize(flutter_window->window, &frame_left, &frame_top,
842  &frame_right, &frame_bottom);
843  if (x) {
844  *x -= frame_left;
845  }
846  if (y) {
847  *y -= frame_top;
848  }
849  if (width) {
850  *width += frame_left + frame_right;
851  }
852  if (height) {
853  *height += frame_top + frame_bottom;
854  }
855 }
int32_t height
int32_t width
GLFWwindow * window
Definition: flutter_glfw.cc:77

◆ FlutterDesktopWindowGetScaleFactor()

double FlutterDesktopWindowGetScaleFactor ( FlutterDesktopWindowRef  flutter_window)

◆ FlutterDesktopWindowSetFrame()

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

Definition at line 857 of file flutter_glfw.cc.

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

861  {
862  // Get the window decoration sizes to adjust, since the GLFW setters take
863  // content position and size.
864  int frame_left, frame_top, frame_right, frame_bottom;
865  glfwGetWindowFrameSize(flutter_window->window, &frame_left, &frame_top,
866  &frame_right, &frame_bottom);
867  glfwSetWindowPos(flutter_window->window, x + frame_left, y + frame_top);
868  glfwSetWindowSize(flutter_window->window, width - frame_left - frame_right,
869  height - frame_top - frame_bottom);
870 }
int32_t height
int32_t width
GLFWwindow * window
Definition: flutter_glfw.cc:77

◆ FlutterDesktopWindowSetHoverEnabled()

void FlutterDesktopWindowSetHoverEnabled ( FlutterDesktopWindowRef  flutter_window,
bool  enabled 
)

Definition at line 811 of file flutter_glfw.cc.

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

812  {
813  flutter_window->hover_tracking_enabled = enabled;
814  SetHoverCallbacksEnabled(flutter_window->window, enabled);
815 }
static void SetHoverCallbacksEnabled(GLFWwindow *window, bool enabled)
GLFWwindow * window
Definition: flutter_glfw.cc:77

◆ FlutterDesktopWindowSetIcon()

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

Definition at line 823 of file flutter_glfw.cc.

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

826  {
827  GLFWimage image = {width, height, static_cast<unsigned char*>(pixel_data)};
828  glfwSetWindowIcon(flutter_window->window, pixel_data ? 1 : 0, &image);
829 }
int32_t height
int32_t width
GLFWwindow * window
Definition: flutter_glfw.cc:77

◆ FlutterDesktopWindowSetPixelRatioOverride()

void FlutterDesktopWindowSetPixelRatioOverride ( FlutterDesktopWindowRef  flutter_window,
double  pixel_ratio 
)

Definition at line 877 of file flutter_glfw.cc.

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

879  {
880  flutter_window->pixel_ratio_override = pixel_ratio;
881  // Send a metrics update using the new pixel ratio.
882  int width_px, height_px;
883  glfwGetFramebufferSize(flutter_window->window, &width_px, &height_px);
884  if (width_px > 0 && height_px > 0) {
885  auto* controller = GetWindowController(flutter_window->window);
886  SendWindowMetrics(controller, width_px, height_px);
887  }
888 }
static void SendWindowMetrics(FlutterDesktopWindowControllerState *controller, int width, int height)
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)
GLFWwindow * window
Definition: flutter_glfw.cc:77

◆ FlutterDesktopWindowSetSizeLimits()

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

Definition at line 890 of file flutter_glfw.cc.

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

892  {
893  glfwSetWindowSizeLimits(flutter_window->window, minimum_size.width,
894  minimum_size.height, maximum_size.width,
895  maximum_size.height);
896 }
GLFWwindow * window
Definition: flutter_glfw.cc:77

◆ FlutterDesktopWindowSetTitle()

void FlutterDesktopWindowSetTitle ( FlutterDesktopWindowRef  flutter_window,
const char *  title 
)

Definition at line 817 of file flutter_glfw.cc.

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

818  {
819  GLFWwindow* window = flutter_window->window;
820  glfwSetWindowTitle(window, title);
821 }
GLFWwindow * window
Definition: flutter_glfw.cc:77

◆ GetScreenCoordinatesPerInch()

static double GetScreenCoordinatesPerInch ( )
static

Definition at line 184 of file flutter_glfw.cc.

References kDpPerInch.

Referenced by FlutterDesktopCreateWindow().

184  {
185  auto* primary_monitor = glfwGetPrimaryMonitor();
186  if (primary_monitor == nullptr) {
187  return kDpPerInch;
188  }
189  auto* primary_monitor_mode = glfwGetVideoMode(primary_monitor);
190  int primary_monitor_width_mm;
191  glfwGetMonitorPhysicalSize(primary_monitor, &primary_monitor_width_mm,
192  nullptr);
193  if (primary_monitor_width_mm == 0) {
194  return kDpPerInch;
195  }
196  return primary_monitor_mode->width / (primary_monitor_width_mm / 25.4);
197 }
static constexpr double kDpPerInch
Definition: flutter_glfw.cc:42

◆ GetWindowController()

◆ GLFWAssignEventCallbacks()

static void GLFWAssignEventCallbacks ( GLFWwindow *  window)
static

Definition at line 435 of file flutter_glfw.cc.

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

Referenced by EngineOnFlutterPlatformMessage(), and FlutterDesktopCreateWindow().

435  {
436  glfwPollEvents();
437  glfwSetKeyCallback(window, GLFWKeyCallback);
438  glfwSetCharCallback(window, GLFWCharCallback);
439  glfwSetMouseButtonCallback(window, GLFWMouseButtonCallback);
440  glfwSetScrollCallback(window, GLFWScrollCallback);
441  if (GetWindowController(window)->window_wrapper->hover_tracking_enabled) {
442  SetHoverCallbacksEnabled(window, true);
443  }
444 }
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 407 of file flutter_glfw.cc.

References GetWindowController(), and FlutterDesktopWindowControllerState::keyboard_hook_handlers.

Referenced by GLFWAssignEventCallbacks().

407  {
408  for (const auto& handler :
409  GetWindowController(window)->keyboard_hook_handlers) {
410  handler->CharHook(window, code_point);
411  }
412 }
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)

◆ GLFWClearCanvas()

static void GLFWClearCanvas ( GLFWwindow *  window)
static

Definition at line 554 of file flutter_glfw.cc.

Referenced by FlutterDesktopCreateWindow().

554  {
555  glfwMakeContextCurrent(window);
556  // This color is Material Blue Grey.
557  glClearColor(236.0f / 255.0f, 239.0f / 255.0f, 241.0f / 255.0f, 0.0f);
558  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
559  glFlush();
560  glfwSwapBuffers(window);
561  glfwMakeContextCurrent(nullptr);
562 }

◆ GLFWClearEventCallbacks()

static void GLFWClearEventCallbacks ( GLFWwindow *  window)
static

Definition at line 447 of file flutter_glfw.cc.

References SetHoverCallbacksEnabled().

Referenced by EngineOnFlutterPlatformMessage().

447  {
448  glfwSetKeyCallback(window, nullptr);
449  glfwSetCharCallback(window, nullptr);
450  glfwSetMouseButtonCallback(window, nullptr);
451  glfwSetScrollCallback(window, nullptr);
452  SetHoverCallbacksEnabled(window, false);
453 }
static void SetHoverCallbacksEnabled(GLFWwindow *window, bool enabled)

◆ GLFWCursorEnterCallback()

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

Definition at line 339 of file flutter_glfw.cc.

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

Referenced by GLFWMouseButtonCallback(), and SetHoverCallbacksEnabled().

339  {
340  FlutterPointerEvent event = {};
341  event.phase =
345 }
static void SetEventLocationFromCursorPosition(GLFWwindow *window, FlutterPointerEvent *event_data)
static void SendPointerEventWithData(GLFWwindow *window, const FlutterPointerEvent &event_data)
Definition: embedder.h:492
GdkEventButton * event
Definition: fl_view.cc:62
FlutterPointerPhase phase
Definition: embedder.h:529

◆ GLFWCursorPositionCallback()

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

Definition at line 348 of file flutter_glfw.cc.

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

Referenced by GLFWMouseButtonCallback(), and SetHoverCallbacksEnabled().

348  {
349  FlutterPointerEvent event = {};
350  event.x = x;
351  event.y = y;
354 }
static void SetEventPhaseFromCursorButtonState(GLFWwindow *window, FlutterPointerEvent *event_data)
static void SendPointerEventWithData(GLFWwindow *window, const FlutterPointerEvent &event_data)
double x
The x coordinate of the pointer event in physical pixels.
Definition: embedder.h:535
GdkEventButton * event
Definition: fl_view.cc:62

◆ GLFWErrorCallback()

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

Definition at line 564 of file flutter_glfw.cc.

Referenced by FlutterDesktopInit().

564  {
565  std::cerr << "GLFW error " << error_code << ": " << description << std::endl;
566 }

◆ GLFWFramebufferSizeCallback()

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

Definition at line 243 of file flutter_glfw.cc.

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

Referenced by FlutterDesktopCreateWindow().

245  {
246  int width;
247  glfwGetWindowSize(window, &width, nullptr);
248  auto* controller = GetWindowController(window);
249  controller->window_wrapper->pixels_per_screen_coordinate =
250  width > 0 ? width_px / width : 1;
251 
252  SendWindowMetrics(controller, width_px, height_px);
253  controller->window_wrapper->skip_next_window_refresh = true;
254 }
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 415 of file flutter_glfw.cc.

References GetWindowController(), and FlutterDesktopWindowControllerState::keyboard_hook_handlers.

Referenced by GLFWAssignEventCallbacks().

419  {
420  for (const auto& handler :
421  GetWindowController(window)->keyboard_hook_handlers) {
422  handler->KeyboardHook(window, key, scancode, action, mods);
423  }
424 }
SemanticsAction action
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)

◆ GLFWMouseButtonCallback()

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

Definition at line 357 of file flutter_glfw.cc.

References event, GetWindowController(), GLFWCursorEnterCallback(), GLFWCursorPositionCallback(), kDown, kUp, FlutterPointerEvent::phase, SendPointerEventWithData(), SetEventLocationFromCursorPosition(), and FlutterDesktopWindowControllerState::window_wrapper.

Referenced by GLFWAssignEventCallbacks().

360  {
361  // Flutter currently doesn't understand other buttons, so ignore anything
362  // other than left.
363  if (key != GLFW_MOUSE_BUTTON_LEFT) {
364  return;
365  }
366 
367  FlutterPointerEvent event = {};
368  event.phase = (action == GLFW_PRESS) ? FlutterPointerPhase::kDown
372 
373  // If mouse tracking isn't already enabled, turn it on for the duration of
374  // the drag to generate kMove events.
375  bool hover_enabled =
376  GetWindowController(window)->window_wrapper->hover_tracking_enabled;
377  if (!hover_enabled) {
378  glfwSetCursorPosCallback(
379  window, (action == GLFW_PRESS) ? GLFWCursorPositionCallback : nullptr);
380  }
381  // Disable enter/exit events while the mouse button is down; GLFW will send
382  // an exit event when the mouse button is released, and the pointer should
383  // stay valid until then.
384  if (hover_enabled) {
385  glfwSetCursorEnterCallback(
386  window, (action == GLFW_PRESS) ? nullptr : GLFWCursorEnterCallback);
387  }
388 }
Definition: embedder.h:475
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:57
SemanticsAction action
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)
GdkEventButton * event
Definition: fl_view.cc:62
static void GLFWCursorPositionCallback(GLFWwindow *window, double x, double y)
static void GLFWCursorEnterCallback(GLFWwindow *window, int entered)
FlutterPointerPhase phase
Definition: embedder.h:529

◆ GLFWScrollCallback()

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

Definition at line 391 of file flutter_glfw.cc.

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

Referenced by GLFWAssignEventCallbacks().

393  {
394  FlutterPointerEvent event = {};
398  // TODO: See if this can be queried from the OS; this value is chosen
399  // arbitrarily to get something that feels reasonable.
400  const int kScrollOffsetMultiplier = 20;
401  event.scroll_delta_x = delta_x * kScrollOffsetMultiplier;
402  event.scroll_delta_y = -delta_y * kScrollOffsetMultiplier;
404 }
static void SetEventLocationFromCursorPosition(GLFWwindow *window, FlutterPointerEvent *event_data)
static void SetEventPhaseFromCursorButtonState(GLFWwindow *window, FlutterPointerEvent *event_data)
static void SendPointerEventWithData(GLFWwindow *window, const FlutterPointerEvent &event_data)
GdkEventButton * event
Definition: fl_view.cc:62

◆ GLFWWindowRefreshCallback()

void GLFWWindowRefreshCallback ( GLFWwindow *  window)

Definition at line 257 of file flutter_glfw.cc.

References GetWindowController(), and SendWindowMetrics().

Referenced by FlutterDesktopCreateWindow().

257  {
258  auto* controller = GetWindowController(window);
259  if (controller->window_wrapper->skip_next_window_refresh) {
260  controller->window_wrapper->skip_next_window_refresh = false;
261  return;
262  }
263  // There's no engine API to request a redraw explicitly, so instead send a
264  // window metrics event with the current size to trigger it.
265  int width_px, height_px;
266  glfwGetFramebufferSize(window, &width_px, &height_px);
267  if (width_px > 0 && height_px > 0) {
268  SendWindowMetrics(controller, width_px, height_px);
269  }
270 }
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 570 of file flutter_glfw.cc.

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

Referenced by flutter::FlutterProjectBundle::icu_path(), and RunFlutterEngine().

570  {
571  if (aot_data_path.empty()) {
572  std::cerr
573  << "Attempted to load AOT data, but no aot_data_path was provided."
574  << std::endl;
575  return nullptr;
576  }
577  if (!std::filesystem::exists(aot_data_path)) {
578  std::cerr << "Can't load AOT data from " << aot_data_path.u8string()
579  << "; no such file." << std::endl;
580  return nullptr;
581  }
582  std::string path_string = aot_data_path.u8string();
583  FlutterEngineAOTDataSource source = {};
585  source.elf_path = path_string.c_str();
586  FlutterEngineAOTData data = nullptr;
587  auto result = FlutterEngineCreateAOTData(&source, &data);
588  if (result != kSuccess) {
589  std::cerr << "Failed to load AOT data from: " << path_string << std::endl;
590  return nullptr;
591  }
592  return UniqueAotDataPtr(data);
593 }
FlutterEngineAOTDataSourceType type
Definition: embedder.h:1122
const char * elf_path
Absolute path to an ELF library file.
Definition: embedder.h:1125
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:597

◆ RunFlutterEngine()

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

Definition at line 602 of file flutter_glfw.cc.

References FlutterDesktopEngineState::aot_data, FlutterProjectArgs::aot_data, FlutterDesktopEngineProperties::aot_library_path, 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, 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().

605  {
606  // FlutterProjectArgs is expecting a full argv, so when processing it for
607  // flags the first item is treated as the executable and ignored. Add a dummy
608  // value so that all provided arguments are used.
609  std::vector<const char*> argv = {"placeholder"};
610  if (engine_properties.switches_count > 0) {
611  argv.insert(argv.end(), &engine_properties.switches[0],
612  &engine_properties.switches[engine_properties.switches_count]);
613  }
614 
615  std::filesystem::path assets_path =
616  std::filesystem::u8path(engine_properties.assets_path);
617  std::filesystem::path icu_path =
618  std::filesystem::u8path(engine_properties.icu_data_path);
619  std::filesystem::path aot_library_path =
620  std::filesystem::u8path(engine_properties.aot_library_path);
621  if (assets_path.is_relative() || icu_path.is_relative() ||
622  (!aot_library_path.empty() && aot_library_path.is_relative())) {
623  // Treat relative paths as relative to the directory of this executable.
624  std::filesystem::path executable_location =
626  if (executable_location.empty()) {
627  std::cerr << "Unable to find executable location to resolve paths."
628  << std::endl;
629  return false;
630  }
631  assets_path = std::filesystem::path(executable_location) / assets_path;
632  icu_path = std::filesystem::path(executable_location) / icu_path;
633  if (!aot_library_path.empty()) {
634  aot_library_path =
635  std::filesystem::path(executable_location) / aot_library_path;
636  }
637  }
638  std::string assets_path_string = assets_path.u8string();
639  std::string icu_path_string = icu_path.u8string();
640  std::string lib_path_string = aot_library_path.u8string();
641 
642  // Configure a task runner using the event loop.
643  engine_state->event_loop = std::move(event_loop);
644  FlutterTaskRunnerDescription platform_task_runner = {};
645  ConfigurePlatformTaskRunner(&platform_task_runner, engine_state);
646  FlutterCustomTaskRunners task_runners = {};
647  task_runners.struct_size = sizeof(FlutterCustomTaskRunners);
648  task_runners.platform_task_runner = &platform_task_runner;
649 
650  FlutterRendererConfig config = {};
651  config.type = kOpenGL;
652  config.open_gl.struct_size = sizeof(config.open_gl);
655  config.open_gl.present = EnginePresent;
658  // Don't provide a resolver in headless mode, since headless mode should
659  // work even if GLFW initialization failed.
660  if (engine_state->window_controller != nullptr) {
662  }
663  FlutterProjectArgs args = {};
664  args.struct_size = sizeof(FlutterProjectArgs);
665  args.assets_path = assets_path_string.c_str();
666  args.icu_data_path = icu_path_string.c_str();
667  args.command_line_argc = static_cast<int>(argv.size());
668  args.command_line_argv = &argv[0];
670  args.custom_task_runners = &task_runners;
671 
673  engine_state->aot_data = LoadAotData(lib_path_string);
674  if (!engine_state->aot_data) {
675  std::cerr << "Unable to start engine without AOT data." << std::endl;
676  return false;
677  }
678  args.aot_data = engine_state->aot_data.get();
679  }
680 
682  auto result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &args,
683  engine_state, &engine);
684  if (result != kSuccess || engine == nullptr) {
685  std::cerr << "Failed to start Flutter engine: error " << result
686  << std::endl;
687  return false;
688  }
689  engine_state->flutter_engine = engine;
690  return true;
691 }
static void * EngineProcResolver(void *user_data, const char *name)
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
struct _FlutterEngine * FLUTTER_API_SYMBOL(FlutterEngine)
Definition: embedder.h:220
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:1195
std::filesystem::path GetExecutableDirectory()
Definition: path_utils.cc:16
const FlutterCustomTaskRunners * custom_task_runners
Definition: embedder.h:1309
FlutterPlatformMessageCallback platform_message_callback
Definition: embedder.h:1218
static bool EngineMakeContextCurrent(void *user_data)
const char *const * command_line_argv
Definition: embedder.h:1213
static void ConfigurePlatformTaskRunner(FlutterTaskRunnerDescription *task_runner, FlutterDesktopEngineState *engine_state)
#define FLUTTER_ENGINE_VERSION
Definition: embedder.h:63
FlutterRendererType type
Definition: embedder.h:448
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:717
size_t struct_size
The size of this struct. Must be sizeof(FlutterOpenGLRendererConfig).
Definition: embedder.h:379
static bool EngineClearContext(void *user_data)
UniqueAotDataPtr aot_data
BoolCallback make_resource_current
Definition: embedder.h:398
BoolCallback clear_current
Definition: embedder.h:381
FlutterDesktopWindowControllerState * window_controller
const char * assets_path
Definition: embedder.h:1171
BoolCallback make_current
Definition: embedder.h:380
FlutterOpenGLRendererConfig open_gl
Definition: embedder.h:450
size_t struct_size
The size of this struct. Must be sizeof(FlutterProjectArgs).
Definition: embedder.h:1167
UniqueAotDataPtr LoadAotData(std::filesystem::path aot_data_path)
std::unique_ptr< flutter::EventLoop > event_loop
UIntCallback fbo_callback
Definition: embedder.h:391
const FlutterTaskRunnerDescription * platform_task_runner
Definition: embedder.h:748
FlutterEngineAOTData aot_data
Definition: embedder.h:1359
static void EngineOnFlutterPlatformMessage(const FlutterPlatformMessage *engine_message, void *user_data)
ProcResolver gl_proc_resolver
Definition: embedder.h:415
size_t struct_size
The size of this struct. Must be sizeof(FlutterCustomTaskRunners).
Definition: embedder.h:743
bool FlutterEngineRunsAOTCompiledDartCode(void)
Returns if the Flutter engine instance will run AOT compiled Dart code. This call has no threading re...
Definition: embedder.cc:1820
int command_line_argc
The command line argument count used to initialize the project.
Definition: embedder.h:1197

◆ SendPointerEventWithData()

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

Definition at line 276 of file flutter_glfw.cc.

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

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

277  {
278  auto* controller = GetWindowController(window);
279  // If sending anything other than an add, and the pointer isn't already added,
280  // synthesize an add to satisfy Flutter's expectations about events.
281  if (!controller->pointer_currently_added &&
282  event_data.phase != FlutterPointerPhase::kAdd) {
283  FlutterPointerEvent event = {};
285  event.x = event_data.x;
286  event.y = event_data.y;
288  }
289  // Don't double-add (e.g., if events are delivered out of order, so an add has
290  // already been synthesized).
291  if (controller->pointer_currently_added &&
292  event_data.phase == FlutterPointerPhase::kAdd) {
293  return;
294  }
295 
296  FlutterPointerEvent event = event_data;
297  // Set metadata that's always the same regardless of the event.
298  event.struct_size = sizeof(event);
299  event.timestamp =
300  std::chrono::duration_cast<std::chrono::microseconds>(
301  std::chrono::high_resolution_clock::now().time_since_epoch())
302  .count();
303  // Convert all screen coordinates to pixel coordinates.
304  double pixels_per_coordinate =
305  controller->window_wrapper->pixels_per_screen_coordinate;
306  event.x *= pixels_per_coordinate;
307  event.y *= pixels_per_coordinate;
308  event.scroll_delta_x *= pixels_per_coordinate;
309  event.scroll_delta_y *= pixels_per_coordinate;
310 
311  FlutterEngineSendPointerEvent(controller->engine->flutter_engine, &event, 1);
312 
313  if (event_data.phase == FlutterPointerPhase::kAdd) {
314  controller->pointer_currently_added = true;
315  } else if (event_data.phase == FlutterPointerPhase::kRemove) {
316  controller->pointer_currently_added = false;
317  }
318 }
double y
The y coordinate of the pointer event in physical pixels.
Definition: embedder.h:537
static void SendPointerEventWithData(GLFWwindow *window, const FlutterPointerEvent &event_data)
size_t struct_size
The size of this struct. Must be sizeof(FlutterPointerEvent).
Definition: embedder.h:528
static FlutterDesktopWindowControllerState * GetWindowController(GLFWwindow *window)
Definition: embedder.h:492
double x
The x coordinate of the pointer event in physical pixels.
Definition: embedder.h:535
GdkEventButton * event
Definition: fl_view.cc:62
FlutterEngineResult FlutterEngineSendPointerEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPointerEvent *pointers, size_t events_count)
Definition: embedder.cc:1322
FlutterPointerPhase phase
Definition: embedder.h:529

◆ SendWindowMetrics()

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

Definition at line 201 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().

203  {
204  double dpi = controller->window_wrapper->pixels_per_screen_coordinate *
206 
207  FlutterWindowMetricsEvent event = {};
208  event.struct_size = sizeof(event);
209  event.width = width;
210  event.height = height;
211  if (controller->window_wrapper->pixel_ratio_override == 0.0) {
212  // The Flutter pixel_ratio is defined as DPI/dp. Limit the ratio to a
213  // minimum of 1 to avoid rendering a smaller UI on standard resolution
214  // monitors.
215  event.pixel_ratio = std::max(dpi / kDpPerInch, 1.0);
216  } else {
217  event.pixel_ratio = controller->window_wrapper->pixel_ratio_override;
218  }
219  FlutterEngineSendWindowMetricsEvent(controller->engine->flutter_engine,
220  &event);
221 }
std::unique_ptr< FlutterDesktopEngineState > engine
Definition: flutter_glfw.cc:54
std::unique_ptr< FlutterDesktopWindow > window_wrapper
Definition: flutter_glfw.cc:57
int32_t height
int32_t width
size_t struct_size
The size of this struct. Must be sizeof(FlutterWindowMetricsEvent).
Definition: embedder.h:457
GdkEventButton * event
Definition: fl_view.cc:62
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterWindowMetricsEvent *flutter_metrics)
Definition: embedder.cc:1228
static constexpr double kDpPerInch
Definition: flutter_glfw.cc:42

◆ SetEventLocationFromCursorPosition()

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

Definition at line 321 of file flutter_glfw.cc.

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

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

323  {
324  glfwGetCursorPos(window, &event_data->x, &event_data->y);
325 }
double y
The y coordinate of the pointer event in physical pixels.
Definition: embedder.h:537
double x
The x coordinate of the pointer event in physical pixels.
Definition: embedder.h:535

◆ SetEventPhaseFromCursorButtonState()

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

Definition at line 329 of file flutter_glfw.cc.

References kHover, kMove, and FlutterPointerEvent::phase.

Referenced by GLFWCursorPositionCallback(), and GLFWScrollCallback().

331  {
332  event_data->phase =
333  glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS
336 }
The pointer moved while up.
Definition: embedder.h:499
FlutterPointerPhase phase
Definition: embedder.h:529

◆ SetHoverCallbacksEnabled()

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

Definition at line 427 of file flutter_glfw.cc.

References GLFWCursorEnterCallback(), and GLFWCursorPositionCallback().

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

427  {
428  glfwSetCursorEnterCallback(window,
429  enabled ? GLFWCursorEnterCallback : nullptr);
430  glfwSetCursorPosCallback(window,
431  enabled ? GLFWCursorPositionCallback : nullptr);
432 }
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 698 of file flutter_glfw.cc.

References FlutterDesktopEngineState::internal_plugin_registrar, FlutterDesktopEngineState::message_dispatcher, FlutterDesktopEngineState::messenger, FlutterDesktopEngineState::platform_handler, FlutterDesktopEngineState::plugin_registrar, and FlutterDesktopWindowControllerState::window.

Referenced by FlutterDesktopCreateWindow(), and FlutterDesktopRunEngine().

699  {
700  // Messaging.
701  state->messenger = std::make_unique<FlutterDesktopMessenger>();
702  state->messenger->engine = state;
703  state->message_dispatcher =
704  std::make_unique<flutter::IncomingMessageDispatcher>(
705  state->messenger.get());
706 
707  // Plugins.
708  state->plugin_registrar = std::make_unique<FlutterDesktopPluginRegistrar>();
709  state->plugin_registrar->engine = state;
711  std::make_unique<flutter::PluginRegistrar>(state->plugin_registrar.get());
712 
713  // System channel handler.
714  state->platform_handler = std::make_unique<flutter::PlatformHandler>(
715  state->internal_plugin_registrar->messenger(), window);
716 }
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

Variable Documentation

◆ kDpPerInch

constexpr double kDpPerInch = 160.0
static

Definition at line 42 of file flutter_glfw.cc.

Referenced by GetScreenCoordinatesPerInch(), and SendWindowMetrics().

◆ kFlutterDesktopDontCare

const int kFlutterDesktopDontCare = GLFW_DONT_CARE

Definition at line 40 of file flutter_glfw.cc.