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

Commit 38b9f3f

Browse files
authored
[Windows] Remove PlatformWindow and RenderTarget abstractions (#49312)
The Windows embedder has three ways to get an `HWND`: 1. `GetWindowHandle` which returns the `HWND` 2. `GetPlatformWindow` which returns the `HWND` wrapped as a `PlatformWindow` 3. `GetRenderTarget` which returns the `HWND` wrapped as a `RenderTarget` These abstractions are no longer useful now that we removed the UWP embedder. This change removes `PlatformWindow` and `RenderTarget` and uses `HWND` directly. This change is a refactoring with no semantic changes.
1 parent bdf261b commit 38b9f3f

18 files changed

+44
-95
lines changed

shell/platform/windows/angle_surface_manager.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ void AngleSurfaceManager::CleanUp() {
229229
}
230230
}
231231

232-
bool AngleSurfaceManager::CreateSurface(WindowsRenderTarget* render_target,
232+
bool AngleSurfaceManager::CreateSurface(HWND hwnd,
233233
EGLint width,
234234
EGLint height) {
235-
if (!render_target || !initialize_succeeded_) {
235+
if (!hwnd || !initialize_succeeded_) {
236236
return false;
237237
}
238238

@@ -245,10 +245,9 @@ bool AngleSurfaceManager::CreateSurface(WindowsRenderTarget* render_target,
245245
EGL_FIXED_SIZE_ANGLE, EGL_TRUE, EGL_WIDTH, width,
246246
EGL_HEIGHT, height, EGL_NONE};
247247

248-
surface = eglCreateWindowSurface(
249-
egl_display_, egl_config_,
250-
static_cast<EGLNativeWindowType>(std::get<HWND>(*render_target)),
251-
surfaceAttributes);
248+
surface = eglCreateWindowSurface(egl_display_, egl_config_,
249+
static_cast<EGLNativeWindowType>(hwnd),
250+
surfaceAttributes);
252251
if (surface == EGL_NO_SURFACE) {
253252
LogEglError("Surface creation failed.");
254253
return false;
@@ -260,7 +259,7 @@ bool AngleSurfaceManager::CreateSurface(WindowsRenderTarget* render_target,
260259
return true;
261260
}
262261

263-
void AngleSurfaceManager::ResizeSurface(WindowsRenderTarget* render_target,
262+
void AngleSurfaceManager::ResizeSurface(HWND hwnd,
264263
EGLint width,
265264
EGLint height,
266265
bool vsync_enabled) {
@@ -275,7 +274,7 @@ void AngleSurfaceManager::ResizeSurface(WindowsRenderTarget* render_target,
275274
// See: https://github.com/flutter/flutter/issues/79427
276275
ClearContext();
277276
DestroySurface();
278-
if (!CreateSurface(render_target, width, height)) {
277+
if (!CreateSurface(hwnd, width, height)) {
279278
FML_LOG(ERROR)
280279
<< "AngleSurfaceManager::ResizeSurface failed to create surface";
281280
}

shell/platform/windows/angle_surface_manager.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,20 @@ class AngleSurfaceManager {
3333

3434
// Creates an EGLSurface wrapper and backing DirectX 11 SwapChain
3535
// associated with window, in the appropriate format for display.
36-
// Target represents the visual entity to bind to. Width and
37-
// height represent dimensions surface is created at.
36+
// HWND is the window backing the surface. Width and height represent
37+
// dimensions surface is created at.
3838
//
3939
// After the surface is created, |SetVSyncEnabled| should be called on a
4040
// thread that can bind the |egl_context_|.
41-
virtual bool CreateSurface(WindowsRenderTarget* render_target,
42-
EGLint width,
43-
EGLint height);
41+
virtual bool CreateSurface(HWND hwnd, EGLint width, EGLint height);
4442

4543
// Resizes backing surface from current size to newly requested size
4644
// based on width and height for the specific case when width and height do
4745
// not match current surface dimensions. Target represents the visual entity
4846
// to bind to.
4947
//
5048
// This binds |egl_context_| to the current thread.
51-
virtual void ResizeSurface(WindowsRenderTarget* render_target,
49+
virtual void ResizeSurface(HWND hwnd,
5250
EGLint width,
5351
EGLint height,
5452
bool enable_vsync);

shell/platform/windows/compositor_opengl_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class CompositorOpenGLTest : public WindowsTest {
104104

105105
auto window = std::make_unique<MockWindowBindingHandler>();
106106
EXPECT_CALL(*window.get(), SetView).Times(1);
107-
EXPECT_CALL(*window.get(), GetRenderTarget).WillRepeatedly(Return(nullptr));
107+
EXPECT_CALL(*window.get(), GetWindowHandle).WillRepeatedly(Return(nullptr));
108108

109109
view_ = std::make_unique<MockFlutterWindowsView>(std::move(window));
110110

shell/platform/windows/compositor_software_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class CompositorSoftwareTest : public WindowsTest {
5656

5757
auto window = std::make_unique<MockWindowBindingHandler>();
5858
EXPECT_CALL(*window.get(), SetView).Times(1);
59-
EXPECT_CALL(*window.get(), GetRenderTarget).WillRepeatedly(Return(nullptr));
59+
EXPECT_CALL(*window.get(), GetWindowHandle).WillRepeatedly(Return(nullptr));
6060

6161
engine_ = builder.Build();
6262
view_ = std::make_unique<MockFlutterWindowsView>(std::move(window));

shell/platform/windows/cursor_handler_unittests.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class CursorHandlerTest : public WindowsTest {
7676

7777
window_ = window.get();
7878
EXPECT_CALL(*window_, SetView).Times(1);
79-
EXPECT_CALL(*window_, GetRenderTarget).WillOnce(Return(nullptr));
8079

8180
engine_ = builder.Build();
8281
view_ = std::make_unique<FlutterWindowsView>(std::move(window));

shell/platform/windows/flutter_platform_node_delegate_windows.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ gfx::Rect FlutterPlatformNodeDelegateWindows::GetBoundsRect(
8787
coordinate_system, clipping_behavior, offscreen_result);
8888
POINT origin{bounds.x(), bounds.y()};
8989
POINT extent{bounds.x() + bounds.width(), bounds.y() + bounds.height()};
90-
ClientToScreen(view_->GetPlatformWindow(), &origin);
91-
ClientToScreen(view_->GetPlatformWindow(), &extent);
90+
ClientToScreen(view_->GetWindowHandle(), &origin);
91+
ClientToScreen(view_->GetWindowHandle(), &extent);
9292
return gfx::Rect(origin.x, origin.y, extent.x - origin.x,
9393
extent.y - origin.y);
9494
}
@@ -107,7 +107,7 @@ void FlutterPlatformNodeDelegateWindows::SetFocus() {
107107

108108
gfx::AcceleratedWidget
109109
FlutterPlatformNodeDelegateWindows::GetTargetForNativeAccessibilityEvent() {
110-
return view_->GetPlatformWindow();
110+
return view_->GetWindowHandle();
111111
}
112112

113113
ui::AXPlatformNode* FlutterPlatformNodeDelegateWindows::GetPlatformNode()

shell/platform/windows/flutter_window.cc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,6 @@ void FlutterWindow::SetView(WindowBindingHandlerDelegate* window) {
164164
}
165165
}
166166

167-
WindowsRenderTarget FlutterWindow::GetRenderTarget() {
168-
return WindowsRenderTarget(GetWindowHandle());
169-
}
170-
171-
PlatformWindow FlutterWindow::GetPlatformWindow() {
172-
return GetWindowHandle();
173-
}
174-
175167
float FlutterWindow::GetDpiScale() {
176168
return static_cast<float>(GetCurrentDPI()) / static_cast<float>(base_dpi);
177169
}
@@ -408,7 +400,7 @@ void FlutterWindow::OnWindowStateEvent(WindowStateEvent event) {
408400
focused_ = false;
409401
break;
410402
}
411-
HWND hwnd = GetPlatformWindow();
403+
HWND hwnd = GetWindowHandle();
412404
if (hwnd && binding_handler_delegate_) {
413405
binding_handler_delegate_->OnWindowStateEvent(hwnd, event);
414406
}

shell/platform/windows/flutter_window.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class FlutterWindow : public KeyboardManager::WindowDelegate,
5050
unsigned int width,
5151
unsigned int height);
5252

53-
HWND GetWindowHandle();
54-
5553
// |KeyboardManager::WindowDelegate|
5654
virtual BOOL Win32PeekMessage(LPMSG lpMsg,
5755
UINT wMsgFilterMin,
@@ -155,10 +153,7 @@ class FlutterWindow : public KeyboardManager::WindowDelegate,
155153
virtual void SetView(WindowBindingHandlerDelegate* view) override;
156154

157155
// |FlutterWindowBindingHandler|
158-
virtual WindowsRenderTarget GetRenderTarget() override;
159-
160-
// |FlutterWindowBindingHandler|
161-
virtual PlatformWindow GetPlatformWindow() override;
156+
virtual HWND GetWindowHandle() override;
162157

163158
// |FlutterWindowBindingHandler|
164159
virtual float GetDpiScale() override;

shell/platform/windows/flutter_window_unittests.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class MockFlutterWindow : public FlutterWindow {
7272
MOCK_METHOD(UINT, Win32DispatchMessage, (UINT, WPARAM, LPARAM), (override));
7373
MOCK_METHOD(BOOL, Win32PeekMessage, (LPMSG, UINT, UINT, UINT), (override));
7474
MOCK_METHOD(uint32_t, Win32MapVkToChar, (uint32_t), (override));
75-
MOCK_METHOD(HWND, GetPlatformWindow, (), (override));
75+
MOCK_METHOD(HWND, GetWindowHandle, (), (override));
7676
MOCK_METHOD(ui::AXFragmentRootDelegateWin*,
7777
GetAxFragmentRootDelegate,
7878
(),
@@ -341,7 +341,7 @@ TEST(FlutterWindowTest, AlertNode) {
341341

342342
TEST(FlutterWindowTest, LifecycleFocusMessages) {
343343
MockFlutterWindow win32window;
344-
EXPECT_CALL(win32window, GetPlatformWindow)
344+
EXPECT_CALL(win32window, GetWindowHandle)
345345
.WillRepeatedly(Return(reinterpret_cast<HWND>(1)));
346346
MockWindowBindingHandlerDelegate delegate;
347347

@@ -373,7 +373,7 @@ TEST(FlutterWindowTest, LifecycleFocusMessages) {
373373

374374
TEST(FlutterWindowTest, CachedLifecycleMessage) {
375375
MockFlutterWindow win32window;
376-
EXPECT_CALL(win32window, GetPlatformWindow)
376+
EXPECT_CALL(win32window, GetWindowHandle)
377377
.WillRepeatedly(Return(reinterpret_cast<HWND>(1)));
378378
EXPECT_CALL(win32window, OnWindowStateEvent)
379379
.WillRepeatedly([&](WindowStateEvent event) {
@@ -413,8 +413,8 @@ TEST(FlutterWindowTest, PosthumousWindowMessage) {
413413

414414
{
415415
MockFlutterWindow win32window(false);
416-
EXPECT_CALL(win32window, GetPlatformWindow).WillRepeatedly([&]() {
417-
return win32window.FlutterWindow::GetPlatformWindow();
416+
EXPECT_CALL(win32window, GetWindowHandle).WillRepeatedly([&]() {
417+
return win32window.FlutterWindow::GetWindowHandle();
418418
});
419419
EXPECT_CALL(win32window, OnWindowStateEvent)
420420
.WillRepeatedly([&](WindowStateEvent event) {
@@ -423,7 +423,7 @@ TEST(FlutterWindowTest, PosthumousWindowMessage) {
423423
EXPECT_CALL(win32window, OnResize).Times(AnyNumber());
424424
win32window.SetView(&delegate);
425425
win32window.InitializeChild("Title", 1, 1);
426-
hwnd = win32window.GetPlatformWindow();
426+
hwnd = win32window.GetWindowHandle();
427427
SendMessage(hwnd, WM_SIZE, 0, MAKEWORD(1, 1));
428428
SendMessage(hwnd, WM_SETFOCUS, 0, 0);
429429

shell/platform/windows/flutter_windows.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void FlutterDesktopEngineSetNextFrameCallback(FlutterDesktopEngineRef engine,
211211
}
212212

213213
HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view) {
214-
return ViewFromHandle(view)->GetPlatformWindow();
214+
return ViewFromHandle(view)->GetWindowHandle();
215215
}
216216

217217
IDXGIAdapter* FlutterDesktopViewGetGraphicsAdapter(FlutterDesktopViewRef view) {

0 commit comments

Comments
 (0)