Flutter Windows Embedder
flutter_windows.h File Reference
#include <dxgi.h>
#include <stddef.h>
#include <stdint.h>
#include <windows.h>
#include "flutter_export.h"
#include "flutter_messenger.h"
#include "flutter_plugin_registrar.h"

Go to the source code of this file.

Classes

struct  FlutterDesktopEngineProperties
 

Typedefs

typedef void(* VoidCallback) (void *)
 
typedef struct FlutterDesktopViewController * FlutterDesktopViewControllerRef
 
typedef struct FlutterDesktopView * FlutterDesktopViewRef
 
typedef struct FlutterDesktopEngine * FlutterDesktopEngineRef
 
typedef int64_t FlutterDesktopViewId
 
typedef bool(* FlutterDesktopWindowProcCallback) (HWND, UINT, WPARAM, LPARAM, void *, LRESULT *result)
 

Functions

FLUTTER_EXPORT FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate (int width, int height, FlutterDesktopEngineRef engine)
 
FLUTTER_EXPORT void FlutterDesktopViewControllerDestroy (FlutterDesktopViewControllerRef controller)
 
FLUTTER_EXPORT FlutterDesktopViewId FlutterDesktopViewControllerGetViewId (FlutterDesktopViewControllerRef view_controller)
 
FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine (FlutterDesktopViewControllerRef controller)
 
FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopViewControllerGetView (FlutterDesktopViewControllerRef controller)
 
FLUTTER_EXPORT void FlutterDesktopViewControllerForceRedraw (FlutterDesktopViewControllerRef controller)
 
FLUTTER_EXPORT bool FlutterDesktopViewControllerHandleTopLevelWindowProc (FlutterDesktopViewControllerRef controller, HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT *result)
 
FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopEngineCreate (const FlutterDesktopEngineProperties *engine_properties)
 
FLUTTER_EXPORT bool FlutterDesktopEngineDestroy (FlutterDesktopEngineRef engine)
 
FLUTTER_EXPORT bool FlutterDesktopEngineRun (FlutterDesktopEngineRef engine, const char *entry_point)
 
FLUTTER_EXPORT uint64_t FlutterDesktopEngineProcessMessages (FlutterDesktopEngineRef engine)
 
FLUTTER_EXPORT void FlutterDesktopEngineReloadSystemFonts (FlutterDesktopEngineRef engine)
 
FLUTTER_EXPORT FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar (FlutterDesktopEngineRef engine, const char *plugin_name)
 
FLUTTER_EXPORT FlutterDesktopMessengerRef FlutterDesktopEngineGetMessenger (FlutterDesktopEngineRef engine)
 
FLUTTER_EXPORT FlutterDesktopTextureRegistrarRef FlutterDesktopEngineGetTextureRegistrar (FlutterDesktopEngineRef engine)
 
FLUTTER_EXPORT void FlutterDesktopEngineSetNextFrameCallback (FlutterDesktopEngineRef engine, VoidCallback callback, void *user_data)
 
FLUTTER_EXPORT HWND FlutterDesktopViewGetHWND (FlutterDesktopViewRef view)
 
FLUTTER_EXPORT IDXGIAdapter * FlutterDesktopViewGetGraphicsAdapter (FlutterDesktopViewRef view)
 
FLUTTER_EXPORT bool FlutterDesktopEngineProcessExternalWindowMessage (FlutterDesktopEngineRef engine, HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT *result)
 
FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView (FlutterDesktopPluginRegistrarRef registrar)
 
FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetViewById (FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopViewId view_id)
 
FLUTTER_EXPORT void FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate (FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopWindowProcCallback delegate, void *user_data)
 
FLUTTER_EXPORT void FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate (FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopWindowProcCallback delegate)
 
FLUTTER_EXPORT UINT FlutterDesktopGetDpiForHWND (HWND hwnd)
 
FLUTTER_EXPORT UINT FlutterDesktopGetDpiForMonitor (HMONITOR monitor)
 
FLUTTER_EXPORT void FlutterDesktopResyncOutputStreams ()
 

Typedef Documentation

◆ FlutterDesktopEngineRef

typedef struct FlutterDesktopEngine* FlutterDesktopEngineRef

Definition at line 33 of file flutter_windows.h.

◆ FlutterDesktopViewControllerRef

typedef struct FlutterDesktopViewController* FlutterDesktopViewControllerRef

Definition at line 25 of file flutter_windows.h.

◆ FlutterDesktopViewId

typedef int64_t FlutterDesktopViewId

Definition at line 36 of file flutter_windows.h.

◆ FlutterDesktopViewRef

typedef struct FlutterDesktopView* FlutterDesktopViewRef

Definition at line 29 of file flutter_windows.h.

◆ FlutterDesktopWindowProcCallback

typedef bool(* FlutterDesktopWindowProcCallback) (HWND, UINT, WPARAM, LPARAM, void *, LRESULT *result)

Definition at line 245 of file flutter_windows.h.

◆ VoidCallback

typedef void(* VoidCallback) (void *)

Definition at line 21 of file flutter_windows.h.

Function Documentation

◆ FlutterDesktopEngineCreate()

FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopEngineCreate ( const FlutterDesktopEngineProperties engine_properties)

Definition at line 183 of file flutter_windows.cc.

184  {
185  flutter::FlutterProjectBundle project(*engine_properties);
186  auto engine = std::make_unique<flutter::FlutterWindowsEngine>(project);
187  return HandleForEngine(engine.release());
188 }

References HandleForEngine().

Referenced by flutter::FlutterEngine::FlutterEngine(), and flutter::testing::TEST().

◆ FlutterDesktopEngineDestroy()

FLUTTER_EXPORT bool FlutterDesktopEngineDestroy ( FlutterDesktopEngineRef  engine)

Definition at line 190 of file flutter_windows.cc.

190  {
191  flutter::FlutterWindowsEngine* engine = EngineFromHandle(engine_ref);
192  bool result = true;
193  if (engine->running()) {
194  result = engine->Stop();
195  }
196  delete engine;
197  return result;
198 }

References EngineFromHandle(), flutter::FlutterWindowsEngine::running(), and flutter::FlutterWindowsEngine::Stop().

Referenced by flutter::FlutterEngine::ShutDown(), and flutter::testing::TEST().

◆ FlutterDesktopEngineGetMessenger()

FLUTTER_EXPORT FlutterDesktopMessengerRef FlutterDesktopEngineGetMessenger ( FlutterDesktopEngineRef  engine)

Definition at line 228 of file flutter_windows.cc.

229  {
230  return EngineFromHandle(engine)->messenger();
231 }

References EngineFromHandle(), and flutter::FlutterWindowsEngine::messenger().

Referenced by flutter::FlutterEngine::FlutterEngine().

◆ FlutterDesktopEngineGetPluginRegistrar()

FLUTTER_EXPORT FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar ( FlutterDesktopEngineRef  engine,
const char *  plugin_name 
)

Definition at line 218 of file flutter_windows.cc.

220  {
221  // Currently, one registrar acts as the registrar for all plugins, so the
222  // name is ignored. It is part of the API to reduce churn in the future when
223  // aligning more closely with the Flutter registrar system.
224 
225  return EngineFromHandle(engine)->GetRegistrar();
226 }

References EngineFromHandle(), and flutter::FlutterWindowsEngine::GetRegistrar().

Referenced by flutter::FlutterEngine::GetRegistrarForPlugin(), and flutter::testing::TEST_F().

◆ FlutterDesktopEngineGetTextureRegistrar()

FLUTTER_EXPORT FlutterDesktopTextureRegistrarRef FlutterDesktopEngineGetTextureRegistrar ( FlutterDesktopEngineRef  engine)

Definition at line 233 of file flutter_windows.cc.

234  {
236  EngineFromHandle(engine)->texture_registrar());
237 }

References EngineFromHandle(), and HandleForTextureRegistrar().

Referenced by flutter::testing::TEST().

◆ FlutterDesktopEngineProcessExternalWindowMessage()

FLUTTER_EXPORT bool FlutterDesktopEngineProcessExternalWindowMessage ( FlutterDesktopEngineRef  engine,
HWND  hwnd,
UINT  message,
WPARAM  wparam,
LPARAM  lparam,
LRESULT *  result 
)

Definition at line 266 of file flutter_windows.cc.

272  {
273  std::optional<LRESULT> lresult =
275  wparam, lparam);
276  if (result && lresult.has_value()) {
277  *result = lresult.value();
278  }
279  return lresult.has_value();
280 }

References EngineFromHandle(), message, and flutter::FlutterWindowsEngine::ProcessExternalWindowMessage().

Referenced by flutter::FlutterEngine::ProcessExternalWindowMessage().

◆ FlutterDesktopEngineProcessMessages()

FLUTTER_EXPORT uint64_t FlutterDesktopEngineProcessMessages ( FlutterDesktopEngineRef  engine)

Definition at line 210 of file flutter_windows.cc.

210  {
211  return std::chrono::nanoseconds::max().count();
212 }

Referenced by flutter::FlutterEngine::ProcessMessages().

◆ FlutterDesktopEngineReloadSystemFonts()

FLUTTER_EXPORT void FlutterDesktopEngineReloadSystemFonts ( FlutterDesktopEngineRef  engine)

◆ FlutterDesktopEngineRun()

FLUTTER_EXPORT bool FlutterDesktopEngineRun ( FlutterDesktopEngineRef  engine,
const char *  entry_point 
)

Definition at line 200 of file flutter_windows.cc.

201  {
202  std::string_view entry_point_view{""};
203  if (entry_point != nullptr) {
204  entry_point_view = entry_point;
205  }
206 
207  return EngineFromHandle(engine)->Run(entry_point_view);
208 }

References EngineFromHandle(), and flutter::FlutterWindowsEngine::Run().

Referenced by flutter::FlutterEngine::Run(), and flutter::testing::TEST_F().

◆ FlutterDesktopEngineSetNextFrameCallback()

FLUTTER_EXPORT void FlutterDesktopEngineSetNextFrameCallback ( FlutterDesktopEngineRef  engine,
VoidCallback  callback,
void *  user_data 
)

◆ FlutterDesktopGetDpiForHWND()

FLUTTER_EXPORT UINT FlutterDesktopGetDpiForHWND ( HWND  hwnd)

Definition at line 316 of file flutter_windows.cc.

316  {
317  return flutter::GetDpiForHWND(hwnd);
318 }

References flutter::GetDpiForHWND().

◆ FlutterDesktopGetDpiForMonitor()

FLUTTER_EXPORT UINT FlutterDesktopGetDpiForMonitor ( HMONITOR  monitor)

Definition at line 320 of file flutter_windows.cc.

320  {
321  return flutter::GetDpiForMonitor(monitor);
322 }

References flutter::GetDpiForMonitor().

◆ FlutterDesktopPluginRegistrarGetView()

◆ FlutterDesktopPluginRegistrarGetViewById()

FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetViewById ( FlutterDesktopPluginRegistrarRef  registrar,
FlutterDesktopViewId  view_id 
)

◆ FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate()

◆ FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate()

◆ FlutterDesktopResyncOutputStreams()

FLUTTER_EXPORT void FlutterDesktopResyncOutputStreams ( )

Definition at line 324 of file flutter_windows.cc.

324  {
325  FILE* unused;
326  if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
327  _dup2(_fileno(stdout), 1);
328  }
329  if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
330  _dup2(_fileno(stdout), 2);
331  }
332  std::ios::sync_with_stdio();
333 }

◆ FlutterDesktopViewControllerCreate()

FLUTTER_EXPORT FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate ( int  width,
int  height,
FlutterDesktopEngineRef  engine 
)

Definition at line 121 of file flutter_windows.cc.

124  {
125  return CreateViewController(engine, width, height, /*owns_engine=*/true);
126 }

References CreateViewController().

Referenced by flutter::FlutterViewController::FlutterViewController(), and flutter::testing::TEST_F().

◆ FlutterDesktopViewControllerDestroy()

FLUTTER_EXPORT void FlutterDesktopViewControllerDestroy ( FlutterDesktopViewControllerRef  controller)

Definition at line 135 of file flutter_windows.cc.

135  {
136  auto controller = ViewControllerFromHandle(ref);
137  controller->Destroy();
138  delete controller;
139 }

References ViewControllerFromHandle().

Referenced by flutter::FlutterViewController::~FlutterViewController().

◆ FlutterDesktopViewControllerForceRedraw()

FLUTTER_EXPORT void FlutterDesktopViewControllerForceRedraw ( FlutterDesktopViewControllerRef  controller)

Definition at line 159 of file flutter_windows.cc.

160  {
161  auto controller = ViewControllerFromHandle(ref);
162  controller->view()->ForceRedraw();
163 }

References ViewControllerFromHandle().

Referenced by flutter::FlutterViewController::ForceRedraw().

◆ FlutterDesktopViewControllerGetEngine()

FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine ( FlutterDesktopViewControllerRef  controller)

Definition at line 147 of file flutter_windows.cc.

148  {
149  auto controller = ViewControllerFromHandle(ref);
150  return HandleForEngine(controller->engine());
151 }

References HandleForEngine(), and ViewControllerFromHandle().

Referenced by flutter::testing::TEST_F().

◆ FlutterDesktopViewControllerGetView()

FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopViewControllerGetView ( FlutterDesktopViewControllerRef  controller)

Definition at line 153 of file flutter_windows.cc.

154  {
155  auto controller = ViewControllerFromHandle(ref);
156  return HandleForView(controller->view());
157 }

References HandleForView(), and ViewControllerFromHandle().

Referenced by flutter::FlutterViewController::FlutterViewController(), and flutter::testing::TEST_F().

◆ FlutterDesktopViewControllerGetViewId()

FLUTTER_EXPORT FlutterDesktopViewId FlutterDesktopViewControllerGetViewId ( FlutterDesktopViewControllerRef  view_controller)

Definition at line 141 of file flutter_windows.cc.

142  {
143  auto controller = ViewControllerFromHandle(ref);
144  return static_cast<FlutterDesktopViewId>(controller->view()->view_id());
145 }

References ViewControllerFromHandle().

Referenced by flutter::testing::TEST_F(), and flutter::FlutterViewController::view_id().

◆ FlutterDesktopViewControllerHandleTopLevelWindowProc()

FLUTTER_EXPORT bool FlutterDesktopViewControllerHandleTopLevelWindowProc ( FlutterDesktopViewControllerRef  controller,
HWND  hwnd,
UINT  message,
WPARAM  wparam,
LPARAM  lparam,
LRESULT *  result 
)

Definition at line 165 of file flutter_windows.cc.

171  {
172  auto controller = ViewControllerFromHandle(ref);
173  std::optional<LRESULT> delegate_result =
174  controller->engine()
175  ->window_proc_delegate_manager()
176  ->OnTopLevelWindowProc(hwnd, message, wparam, lparam);
177  if (delegate_result) {
178  *result = *delegate_result;
179  }
180  return delegate_result.has_value();
181 }

References message, and ViewControllerFromHandle().

Referenced by flutter::FlutterViewController::HandleTopLevelWindowProc().

◆ FlutterDesktopViewGetGraphicsAdapter()

FLUTTER_EXPORT IDXGIAdapter* FlutterDesktopViewGetGraphicsAdapter ( FlutterDesktopViewRef  view)

Definition at line 250 of file flutter_windows.cc.

250  {
251  auto egl_manager = ViewFromHandle(view)->GetEngine()->egl_manager();
252  if (egl_manager) {
253  Microsoft::WRL::ComPtr<ID3D11Device> d3d_device;
254  Microsoft::WRL::ComPtr<IDXGIDevice> dxgi_device;
255  if (egl_manager->GetDevice(d3d_device.GetAddressOf()) &&
256  SUCCEEDED(d3d_device.As(&dxgi_device))) {
257  IDXGIAdapter* adapter;
258  if (SUCCEEDED(dxgi_device->GetAdapter(&adapter))) {
259  return adapter;
260  }
261  }
262  }
263  return nullptr;
264 }

References flutter::FlutterWindowsEngine::egl_manager(), flutter::FlutterWindowsView::GetEngine(), and ViewFromHandle().

Referenced by flutter::FlutterView::GetGraphicsAdapter(), and flutter::testing::TEST_F().

◆ FlutterDesktopViewGetHWND()

FLUTTER_EXPORT HWND FlutterDesktopViewGetHWND ( FlutterDesktopViewRef  view)
flutter::kImplicitViewId
constexpr FlutterViewId kImplicitViewId
Definition: flutter_windows_engine.h:55
flutter::FlutterWindowsEngine::GetRegistrar
FlutterDesktopPluginRegistrarRef GetRegistrar()
Definition: flutter_windows_engine.cc:668
flutter::FlutterProjectBundle
Definition: flutter_project_bundle.h:21
flutter::FlutterWindowsEngine::view
FlutterWindowsView * view(FlutterViewId view_id) const
Definition: flutter_windows_engine.cc:656
HandleForView
static FlutterDesktopViewRef HandleForView(flutter::FlutterWindowsView *view)
Definition: flutter_windows.cc:59
CreateViewController
static FlutterDesktopViewControllerRef CreateViewController(FlutterDesktopEngineRef engine_ref, int width, int height, bool owns_engine)
Definition: flutter_windows.cc:79
FlutterDesktopViewId
int64_t FlutterDesktopViewId
Definition: flutter_windows.h:36
HandleForTextureRegistrar
static FlutterDesktopTextureRegistrarRef HandleForTextureRegistrar(flutter::FlutterWindowsTextureRegistrar *registrar)
Definition: flutter_windows.cc:70
flutter::FlutterWindowsEngine::SetNextFrameCallback
void SetNextFrameCallback(fml::closure callback)
Definition: flutter_windows_engine.cc:762
flutter::GetDpiForMonitor
UINT GetDpiForMonitor(HMONITOR monitor)
Definition: dpi_utils.cc:134
user_data
void * user_data
Definition: flutter_windows_view_unittests.cc:53
flutter::FlutterWindowsEngine
Definition: flutter_windows_engine.h:90
flutter::FlutterWindowsEngine::window_proc_delegate_manager
WindowProcDelegateManager * window_proc_delegate_manager()
Definition: flutter_windows_engine.h:167
flutter::FlutterWindowsEngine::running
virtual bool running() const
Definition: flutter_windows_engine.h:117
flutter::GetDpiForHWND
UINT GetDpiForHWND(HWND hwnd)
Definition: dpi_utils.cc:130
EngineFromHandle
static flutter::FlutterWindowsEngine * EngineFromHandle(FlutterDesktopEngineRef ref)
Definition: flutter_windows.cc:32
flutter::FlutterWindowsView::GetWindowHandle
virtual HWND GetWindowHandle() const
Definition: flutter_windows_view.cc:758
flutter::FlutterWindowsEngine::Stop
virtual bool Stop()
Definition: flutter_windows_engine.cc:482
flutter::FlutterWindowsEngine::messenger
FlutterDesktopMessengerRef messenger()
Definition: flutter_windows_engine.h:149
flutter::FlutterWindowsEngine::ProcessExternalWindowMessage
std::optional< LRESULT > ProcessExternalWindowMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
Definition: flutter_windows_engine.cc:966
FlutterDesktopPluginRegistrar::engine
flutter::FlutterWindowsEngine * engine
Definition: window_state.h:25
flutter::WindowProcDelegateManager::UnregisterTopLevelWindowProcDelegate
void UnregisterTopLevelWindowProcDelegate(FlutterDesktopWindowProcCallback callback)
Definition: window_proc_delegate_manager.cc:27
flutter::FlutterWindowsView::GetEngine
FlutterWindowsEngine * GetEngine() const
Definition: flutter_windows_view.cc:762
HandleForEngine
static FlutterDesktopEngineRef HandleForEngine(flutter::FlutterWindowsEngine *engine)
Definition: flutter_windows.cc:38
ViewFromHandle
static flutter::FlutterWindowsView * ViewFromHandle(FlutterDesktopViewRef ref)
Definition: flutter_windows.cc:54
ViewControllerFromHandle
static flutter::FlutterWindowsViewController * ViewControllerFromHandle(FlutterDesktopViewControllerRef ref)
Definition: flutter_windows.cc:43
message
Win32Message message
Definition: keyboard_unittests.cc:137
flutter::FlutterWindowsEngine::egl_manager
egl::Manager * egl_manager() const
Definition: flutter_windows_engine.h:165
flutter::FlutterWindowsEngine::Run
bool Run()
Definition: flutter_windows_engine.cc:239
flutter::WindowProcDelegateManager::RegisterTopLevelWindowProcDelegate
void RegisterTopLevelWindowProcDelegate(FlutterDesktopWindowProcCallback callback, void *user_data)
Definition: window_proc_delegate_manager.cc:16
flutter::FlutterWindowsEngine::ReloadSystemFonts
void ReloadSystemFonts()
Definition: flutter_windows_engine.cc:754
callback
FlutterDesktopBinaryReply callback
Definition: flutter_windows_view_unittests.cc:52