5#include "flutter/shell/platform/windows/public/flutter_windows.h"
16#include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h"
17#include "flutter/shell/platform/common/incoming_message_dispatcher.h"
18#include "flutter/shell/platform/common/path_utils.h"
19#include "flutter/shell/platform/embedder/embedder.h"
20#include "flutter/shell/platform/windows/dpi_utils.h"
21#include "flutter/shell/platform/windows/flutter_project_bundle.h"
22#include "flutter/shell/platform/windows/flutter_window.h"
23#include "flutter/shell/platform/windows/flutter_windows_engine.h"
24#include "flutter/shell/platform/windows/flutter_windows_view.h"
25#include "flutter/shell/platform/windows/flutter_windows_view_controller.h"
26#include "flutter/shell/platform/windows/window_binding_handler.h"
27#include "flutter/shell/platform/windows/window_state.h"
85 std::unique_ptr<flutter::WindowBindingHandler> window_wrapper =
86 std::make_unique<flutter::FlutterWindow>(
89 std::unique_ptr<flutter::FlutterWindowsEngine>
engine;
91 engine = std::unique_ptr<flutter::FlutterWindowsEngine>(engine_ptr);
94 std::unique_ptr<flutter::FlutterWindowsView> view =
95 engine_ptr->
CreateView(std::move(window_wrapper));
100 auto controller = std::make_unique<flutter::FlutterWindowsViewController>(
101 std::move(
engine), std::move(view));
104 if (!controller->engine()->running()) {
105 if (!controller->engine()->Run()) {
111 controller->view()->SendInitialBounds();
116 controller->engine()->UpdateAccessibilityFeatures();
137 controller->Destroy();
162 controller->view()->ForceRedraw();
173 std::optional<LRESULT> delegate_result =
175 ->window_proc_delegate_manager()
176 ->OnTopLevelWindowProc(hwnd,
message, wparam, lparam);
177 if (delegate_result) {
178 *
result = *delegate_result;
180 return delegate_result.has_value();
186 auto engine = std::make_unique<flutter::FlutterWindowsEngine>(project);
201 const char* entry_point) {
202 std::string_view entry_point_view{
""};
203 if (entry_point !=
nullptr) {
204 entry_point_view = entry_point;
220 const char* plugin_name) {
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))) {
273 std::optional<LRESULT> lresult =
276 if (
result && lresult.has_value()) {
277 *
result = lresult.value();
279 return lresult.has_value();
284 const char* view_type_name,
305 registrar->
engine->window_proc_delegate_manager()
306 ->RegisterTopLevelWindowProcDelegate(delegate,
user_data);
312 registrar->
engine->window_proc_delegate_manager()
313 ->UnregisterTopLevelWindowProcDelegate(delegate);
326 if (freopen_s(&
unused,
"CONOUT$",
"w", stdout)) {
327 _dup2(_fileno(stdout), 1);
329 if (freopen_s(&
unused,
"CONOUT$",
"w", stderr)) {
330 _dup2(_fileno(stdout), 2);
332 std::ios::sync_with_stdio();
345 registrar->
engine->AddPluginRegistrarDestructionCallback(
callback, registrar);
351 const size_t message_size,
355 <<
"Messenger must reference a running engine to send a message";
365 const size_t message_size) {
367 message_size,
nullptr,
nullptr);
374 size_t data_length) {
376 <<
"Messenger must reference a running engine to send a response";
388 <<
"Messenger must reference a running engine to set a callback";
441 registrar->UnregisterTexture(
FlutterDesktopMessengerRef ToRef()
Convert to FlutterDesktopMessengerRef.
flutter::FlutterWindowsEngine * GetEngine() const
Getter for the engine field.
static FlutterDesktopMessenger * FromRef(FlutterDesktopMessengerRef ref)
Convert from FlutterDesktopMessengerRef.
FlutterDesktopMessenger * AddRef()
FlutterDesktopMessengerRef messenger()
bool SendPlatformMessage(const char *channel, const uint8_t *message, const size_t message_size, const FlutterDesktopBinaryReply reply, void *user_data)
std::optional< LRESULT > ProcessExternalWindowMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
std::shared_ptr< WindowsProcTable > windows_proc_table()
IncomingMessageDispatcher * message_dispatcher()
void SendPlatformMessageResponse(const FlutterDesktopMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
egl::Manager * egl_manager() const
std::unique_ptr< FlutterWindowsView > CreateView(std::unique_ptr< WindowBindingHandler > window)
void SetNextFrameCallback(fml::closure callback)
FlutterDesktopPluginRegistrarRef GetRegistrar()
int64_t RegisterTexture(const FlutterDesktopTextureInfo *texture_info)
bool MarkTextureFrameAvailable(int64_t texture_id)
Controls a view that displays Flutter content.
FlutterWindowsEngine * GetEngine() const
virtual HWND GetWindowHandle() const
void SetMessageCallback(const std::string &channel, FlutterDesktopMessageCallback callback, void *user_data)
#define FLUTTER_ENGINE_VERSION
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
void(* FlutterDesktopBinaryReply)(const uint8_t *data, size_t data_size, void *user_data)
void(* FlutterDesktopMessageCallback)(FlutterDesktopMessengerRef, const FlutterDesktopMessage *, void *)
void(* FlutterDesktopOnPluginRegistrarDestroyed)(FlutterDesktopPluginRegistrarRef)
struct FlutterDesktopTextureRegistrar * FlutterDesktopTextureRegistrarRef
void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger, const char *channel, FlutterDesktopMessageCallback callback, void *user_data)
UINT FlutterDesktopGetDpiForHWND(HWND hwnd)
void FlutterDesktopViewControllerForceRedraw(FlutterDesktopViewControllerRef ref)
static FlutterDesktopTextureRegistrarRef HandleForTextureRegistrar(flutter::FlutterWindowsTextureRegistrar *registrar)
FlutterDesktopEngineRef FlutterDesktopEngineCreate(const FlutterDesktopEngineProperties *engine_properties)
void FlutterDesktopEngineReloadSystemFonts(FlutterDesktopEngineRef engine)
bool FlutterDesktopEngineProcessExternalWindowMessage(FlutterDesktopEngineRef engine, HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT *result)
static flutter::FlutterWindowsEngine * EngineFromHandle(FlutterDesktopEngineRef ref)
void FlutterDesktopResyncOutputStreams()
void FlutterDesktopEngineRegisterPlatformViewType(FlutterDesktopEngineRef engine, const char *view_type_name, FlutterPlatformViewTypeEntry view_type)
static FlutterDesktopViewRef HandleForView(flutter::FlutterWindowsView *view)
static FlutterDesktopViewControllerRef CreateViewController(FlutterDesktopEngineRef engine_ref, int width, int height, bool owns_engine)
void FlutterDesktopMessengerSendResponse(FlutterDesktopMessengerRef messenger, const FlutterDesktopMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetViewById(FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopViewId view_id)
static FlutterDesktopEngineRef HandleForEngine(flutter::FlutterWindowsEngine *engine)
bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size, const FlutterDesktopBinaryReply reply, void *user_data)
void FlutterDesktopPluginRegistrarSetDestructionHandler(FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopOnPluginRegistrarDestroyed callback)
FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar(FlutterDesktopEngineRef engine, const char *plugin_name)
int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture(FlutterDesktopTextureRegistrarRef texture_registrar, const FlutterDesktopTextureInfo *texture_info)
static FlutterDesktopViewControllerRef HandleForViewController(flutter::FlutterWindowsViewController *view_controller)
bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable(FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id)
FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate(int width, int height, FlutterDesktopEngineRef engine)
FlutterDesktopMessengerRef FlutterDesktopMessengerLock(FlutterDesktopMessengerRef messenger)
void FlutterDesktopTextureRegistrarUnregisterExternalTexture(FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id, void(*callback)(void *user_data), void *user_data)
bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine_ref)
UINT FlutterDesktopGetDpiForMonitor(HMONITOR monitor)
bool FlutterDesktopMessengerIsAvailable(FlutterDesktopMessengerRef messenger)
bool FlutterDesktopMessengerSend(FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size)
FlutterDesktopTextureRegistrarRef FlutterDesktopEngineGetTextureRegistrar(FlutterDesktopEngineRef engine)
void FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate(FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopWindowProcCallback delegate)
bool FlutterDesktopViewControllerHandleTopLevelWindowProc(FlutterDesktopViewControllerRef ref, HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT *result)
static flutter::FlutterWindowsTextureRegistrar * TextureRegistrarFromHandle(FlutterDesktopTextureRegistrarRef ref)
uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine)
static flutter::FlutterWindowsView * ViewFromHandle(FlutterDesktopViewRef ref)
void FlutterDesktopMessengerUnlock(FlutterDesktopMessengerRef messenger)
void FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate(FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopWindowProcCallback delegate, void *user_data)
static flutter::FlutterWindowsViewController * ViewControllerFromHandle(FlutterDesktopViewControllerRef ref)
FlutterDesktopMessengerRef FlutterDesktopEngineGetMessenger(FlutterDesktopEngineRef engine)
IDXGIAdapter * FlutterDesktopViewGetGraphicsAdapter(FlutterDesktopViewRef view)
FlutterDesktopViewId FlutterDesktopViewControllerGetViewId(FlutterDesktopViewControllerRef ref)
FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine(FlutterDesktopViewControllerRef ref)
FlutterDesktopTextureRegistrarRef FlutterDesktopRegistrarGetTextureRegistrar(FlutterDesktopPluginRegistrarRef registrar)
FlutterDesktopMessengerRef FlutterDesktopPluginRegistrarGetMessenger(FlutterDesktopPluginRegistrarRef registrar)
void FlutterDesktopEngineSetNextFrameCallback(FlutterDesktopEngineRef engine, VoidCallback callback, void *user_data)
HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view)
void FlutterDesktopMessengerRelease(FlutterDesktopMessengerRef messenger)
FlutterDesktopViewRef FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef ref)
FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView(FlutterDesktopPluginRegistrarRef registrar)
FlutterDesktopMessengerRef FlutterDesktopMessengerAddRef(FlutterDesktopMessengerRef messenger)
FlutterDesktopViewControllerRef FlutterDesktopEngineCreateViewController(FlutterDesktopEngineRef engine, const FlutterDesktopViewControllerProperties *properties)
void FlutterDesktopViewControllerDestroy(FlutterDesktopViewControllerRef ref)
bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, const char *entry_point)
struct FlutterDesktopViewController * FlutterDesktopViewControllerRef
bool(* FlutterDesktopWindowProcCallback)(HWND, UINT, WPARAM, LPARAM, void *, LRESULT *result)
int64_t FlutterDesktopViewId
struct FlutterDesktopView * FlutterDesktopViewRef
#define FML_DCHECK(condition)
static float max(float r, float g, float b)
G_BEGIN_DECLS FlTextureRegistrar * texture_registrar
UINT GetDpiForHWND(HWND hwnd)
UINT GetDpiForMonitor(HMONITOR monitor)
constexpr FlutterViewId kImplicitViewId
FlutterDesktopMessengerReferenceOwner messenger
FlutterDesktopEngineState * engine
std::shared_ptr< const fml::Mapping > data