Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 04a4681

Browse files
committed
Add flutter_windows_view and window_binding_handler
Switch input handling infra to FlutterWindowsView win32_flutter_window implement WindowBindingHandler Strip unneeded functionality from win32flutterwindow Fulfill WindowBindingHandler interface in Win32FlutterWindow Add implementations for missing input handling in Win32FlutterWindow Cleanup dead code Correctly hook up rendering again Fix resizing clang-format Fix clipboard Cleanup Rename Add comments cleanup
1 parent dbb57f1 commit 04a4681

23 files changed

+860
-520
lines changed

shell/platform/windows/BUILD.gn

+8-5
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,23 @@ source_set("flutter_windows_source") {
4141
sources = [
4242
"angle_surface_manager.cc",
4343
"angle_surface_manager.h",
44-
"dpi_utils.cc",
45-
"dpi_utils.h",
4644
"flutter_windows.cc",
45+
"flutter_windows_view.cc",
46+
"flutter_windows_view.h",
4747
"key_event_handler.cc",
4848
"key_event_handler.h",
4949
"keyboard_hook_handler.h",
50-
"platform_handler.cc",
51-
"platform_handler.h",
5250
"string_conversion.cc",
5351
"string_conversion.h",
5452
"text_input_plugin.cc",
5553
"text_input_plugin.h",
54+
"window_binding_handler.h",
55+
"win32_dpi_utils.cc",
56+
"win32_dpi_utils.h",
5657
"win32_flutter_window.cc",
5758
"win32_flutter_window.h",
59+
"win32_platform_handler.cc",
60+
"win32_platform_handler.h",
5861
"win32_task_runner.cc",
5962
"win32_task_runner.h",
6063
"win32_window.cc",
@@ -110,12 +113,12 @@ executable("flutter_windows_unittests") {
110113
testonly = true
111114

112115
sources = [
113-
"dpi_utils_unittests.cc",
114116
"string_conversion_unittests.cc",
115117
"testing/win32_flutter_window_test.cc",
116118
"testing/win32_flutter_window_test.h",
117119
"testing/win32_window_test.cc",
118120
"testing/win32_window_test.h",
121+
"win32_dpi_utils_unittests.cc",
119122
"win32_flutter_window_unittests.cc",
120123
"win32_window_unittests.cc",
121124
]

shell/platform/windows/angle_surface_manager.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ void AngleSurfaceManager::CleanUp() {
165165
}
166166
}
167167

168-
EGLSurface AngleSurfaceManager::CreateSurface(HWND window) {
169-
if (!window || !initialize_succeeded_) {
168+
EGLSurface AngleSurfaceManager::CreateSurface(WindowsRenderTarget* render_target) {
169+
if (!render_target || !initialize_succeeded_) {
170170
return EGL_NO_SURFACE;
171171
}
172172

@@ -175,7 +175,7 @@ EGLSurface AngleSurfaceManager::CreateSurface(HWND window) {
175175
const EGLint surfaceAttributes[] = {EGL_NONE};
176176

177177
surface = eglCreateWindowSurface(egl_display_, egl_config_,
178-
static_cast<EGLNativeWindowType>(window),
178+
static_cast<EGLNativeWindowType>(render_target->GetWindowHandle()),
179179
surfaceAttributes);
180180
if (surface == EGL_NO_SURFACE) {
181181
OutputDebugString(L"Surface creation failed.");

shell/platform/windows/angle_surface_manager.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// Windows platform specific includes
1616
#include <windows.h>
1717

18+
#include "window_binding_handler.h"
19+
1820
namespace flutter {
1921

2022
// An manager for inializing ANGLE correctly and using it to create and
@@ -29,9 +31,9 @@ class AngleSurfaceManager {
2931
AngleSurfaceManager& operator=(const AngleSurfaceManager&) = delete;
3032

3133
// Creates and returns an EGLSurface wrapper and backing DirectX 11 SwapChain
32-
// asociated with window, in the appropriate format for display in a
33-
// HWND-backed window.
34-
EGLSurface CreateSurface(HWND window);
34+
// asociated with window, in the appropriate format for display.
35+
// Target represents the visual entity to bind to.
36+
EGLSurface CreateSurface(WindowsRenderTarget* render_target);
3537

3638
// queries EGL for the dimensions of surface in physical
3739
// pixels returning width and height as out params.

shell/platform/windows/flutter_windows.cc

+20-14
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
#include "flutter/shell/platform/common/cpp/incoming_message_dispatcher.h"
2020
#include "flutter/shell/platform/common/cpp/path_utils.h"
2121
#include "flutter/shell/platform/embedder/embedder.h"
22-
#include "flutter/shell/platform/windows/dpi_utils.h"
22+
#include "flutter/shell/platform/windows/flutter_windows_view.h"
2323
#include "flutter/shell/platform/windows/key_event_handler.h"
2424
#include "flutter/shell/platform/windows/keyboard_hook_handler.h"
25-
#include "flutter/shell/platform/windows/platform_handler.h"
2625
#include "flutter/shell/platform/windows/text_input_plugin.h"
26+
#include "flutter/shell/platform/windows/win32_dpi_utils.h"
2727
#include "flutter/shell/platform/windows/win32_flutter_window.h"
28+
#include "flutter/shell/platform/windows/win32_platform_handler.h"
2829
#include "flutter/shell/platform/windows/win32_task_runner.h"
30+
#include "flutter/shell/platform/windows/window_binding_handler.h"
2931
#include "flutter/shell/platform/windows/window_state.h"
3032

3133
static_assert(FLUTTER_ENGINE_VERSION == 1, "");
@@ -66,7 +68,7 @@ UniqueAotDataPtr LoadAotData(std::filesystem::path aot_data_path) {
6668
// Returns the state object for the engine, or null on failure to start the
6769
// engine.
6870
static std::unique_ptr<FlutterDesktopEngineState> RunFlutterEngine(
69-
flutter::Win32FlutterWindow* window,
71+
flutter::FlutterWindowsView* view,
7072
const FlutterDesktopEngineProperties& engine_properties) {
7173
auto state = std::make_unique<FlutterDesktopEngineState>();
7274

@@ -79,22 +81,22 @@ static std::unique_ptr<FlutterDesktopEngineState> RunFlutterEngine(
7981
&engine_properties.switches[engine_properties.switches_count]);
8082
}
8183

82-
window->CreateRenderSurface();
84+
view->CreateRenderSurface();
8385

8486
// Provide the necessary callbacks for rendering within a win32 child window.
8587
FlutterRendererConfig config = {};
8688
config.type = kOpenGL;
8789
config.open_gl.struct_size = sizeof(config.open_gl);
8890
config.open_gl.make_current = [](void* user_data) -> bool {
89-
auto host = static_cast<flutter::Win32FlutterWindow*>(user_data);
91+
auto host = static_cast<flutter::FlutterWindowsView*>(user_data);
9092
return host->MakeCurrent();
9193
};
9294
config.open_gl.clear_current = [](void* user_data) -> bool {
93-
auto host = static_cast<flutter::Win32FlutterWindow*>(user_data);
95+
auto host = static_cast<flutter::FlutterWindowsView*>(user_data);
9496
return host->ClearContext();
9597
};
9698
config.open_gl.present = [](void* user_data) -> bool {
97-
auto host = static_cast<flutter::Win32FlutterWindow*>(user_data);
99+
auto host = static_cast<flutter::FlutterWindowsView*>(user_data);
98100
return host->SwapBuffers();
99101
};
100102
config.open_gl.fbo_callback = [](void* user_data) -> uint32_t { return 0; };
@@ -103,7 +105,7 @@ static std::unique_ptr<FlutterDesktopEngineState> RunFlutterEngine(
103105
return reinterpret_cast<void*>(eglGetProcAddress(what));
104106
};
105107
config.open_gl.make_resource_current = [](void* user_data) -> bool {
106-
auto host = static_cast<flutter::Win32FlutterWindow*>(user_data);
108+
auto host = static_cast<flutter::FlutterWindowsView*>(user_data);
107109
return host->MakeResourceCurrent();
108110
};
109111

@@ -178,7 +180,7 @@ static std::unique_ptr<FlutterDesktopEngineState> RunFlutterEngine(
178180
args.platform_message_callback =
179181
[](const FlutterPlatformMessage* engine_message,
180182
void* user_data) -> void {
181-
auto window = reinterpret_cast<flutter::Win32FlutterWindow*>(user_data);
183+
auto window = reinterpret_cast<flutter::FlutterWindowsView*>(user_data);
182184
return window->HandlePlatformMessage(engine_message);
183185
};
184186
args.custom_task_runners = &custom_task_runners;
@@ -188,7 +190,7 @@ static std::unique_ptr<FlutterDesktopEngineState> RunFlutterEngine(
188190

189191
FLUTTER_API_SYMBOL(FlutterEngine) engine = nullptr;
190192
auto result =
191-
FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &args, window, &engine);
193+
FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &args, view, &engine);
192194
if (result != kSuccess || engine == nullptr) {
193195
std::cerr << "Failed to start Flutter engine: error " << result
194196
<< std::endl;
@@ -202,8 +204,12 @@ FlutterDesktopViewControllerRef FlutterDesktopCreateViewController(
202204
int width,
203205
int height,
204206
const FlutterDesktopEngineProperties& engine_properties) {
207+
std::unique_ptr<flutter::FlutterWindowBindingHandler> window_wrapper =
208+
std::make_unique<flutter::Win32FlutterWindow>(width, height);
209+
205210
FlutterDesktopViewControllerRef state =
206-
flutter::Win32FlutterWindow::CreateWin32FlutterWindow(width, height);
211+
flutter::FlutterWindowsView::CreateFlutterWindowsView(
212+
std::move(window_wrapper));
207213

208214
auto engine_state = RunFlutterEngine(state->view.get(), engine_properties);
209215

@@ -261,8 +267,8 @@ FlutterDesktopViewRef FlutterDesktopGetView(
261267
return controller->view_wrapper.get();
262268
}
263269

264-
HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view) {
265-
return view->window->GetWindowHandle();
270+
HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view_ref) {
271+
return view_ref->view->GetRenderTarget()->GetWindowHandle();
266272
}
267273

268274
UINT FlutterDesktopGetDpiForHWND(HWND hwnd) {
@@ -316,7 +322,7 @@ void FlutterDesktopRegistrarSetDestructionHandler(
316322

317323
FlutterDesktopViewRef FlutterDesktopRegistrarGetView(
318324
FlutterDesktopPluginRegistrarRef registrar) {
319-
return registrar->window;
325+
return registrar->view;
320326
}
321327

322328
bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger,

0 commit comments

Comments
 (0)