Skip to content

Commit 2231ce1

Browse files
authored
Revert "Code cleanup on destructors (flutter#16481)"
This reverts commit 8f2cbb3.
1 parent 70cbea8 commit 2231ce1

File tree

7 files changed

+31
-10
lines changed

7 files changed

+31
-10
lines changed

shell/platform/windows/testing/win32_flutter_window_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "flutter/shell/platform/windows/testing/win32_flutter_window_test.h"
2+
#include <iostream>
23

34
namespace flutter {
45
namespace testing {

shell/platform/windows/testing/win32_flutter_window_test.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Win32FlutterWindowTest : public Win32FlutterWindow {
1414
public:
1515
Win32FlutterWindowTest(int width, int height);
1616

17-
virtual ~Win32FlutterWindowTest();
17+
~Win32FlutterWindowTest();
1818

1919
// |Win32Window|
2020
void OnFontChange() override;

shell/platform/windows/win32_flutter_window.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace flutter {
66

7-
// The Windows DPI system is based on this
7+
// the Windows DPI system is based on this
88
// constant for machines running at 100% scaling.
99
constexpr int base_dpi = 96;
1010

@@ -15,6 +15,7 @@ Win32FlutterWindow::Win32FlutterWindow(int width, int height) {
1515

1616
Win32FlutterWindow::~Win32FlutterWindow() {
1717
DestroyRenderSurface();
18+
Win32Window::Destroy();
1819
}
1920

2021
FlutterDesktopViewControllerRef Win32FlutterWindow::CreateWin32FlutterWindow(
@@ -176,6 +177,10 @@ void Win32FlutterWindow::OnScroll(double delta_x, double delta_y) {
176177
}
177178
}
178179

180+
void Win32FlutterWindow::OnClose() {
181+
messageloop_running_ = false;
182+
}
183+
179184
void Win32FlutterWindow::OnFontChange() {
180185
if (engine_ == nullptr) {
181186
return;
@@ -353,4 +358,5 @@ void Win32FlutterWindow::DestroyRenderSurface() {
353358
}
354359
render_surface = EGL_NO_SURFACE;
355360
}
361+
356362
} // namespace flutter

shell/platform/windows/win32_flutter_window.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Win32FlutterWindow : public Win32Window {
3333
// Create flutter Window for use as child window
3434
Win32FlutterWindow(int width, int height);
3535

36-
virtual ~Win32FlutterWindow();
36+
~Win32FlutterWindow();
3737

3838
static FlutterDesktopViewControllerRef CreateWin32FlutterWindow(int width,
3939
int height);
@@ -65,6 +65,9 @@ class Win32FlutterWindow : public Win32Window {
6565
// |Win32Window|
6666
void OnScroll(double delta_x, double delta_y) override;
6767

68+
// |Win32Window|
69+
void OnClose() override;
70+
6871
// |Win32Window|
6972
void OnFontChange() override;
7073

@@ -82,6 +85,9 @@ class Win32FlutterWindow : public Win32Window {
8285
// Create a surface for Flutter engine to render into.
8386
void CreateRenderSurface();
8487

88+
// Destroy current rendering surface if one has been allocated.
89+
void DestroyRenderSurface();
90+
8591
// Callbacks for clearing context, settings context and swapping buffers.
8692
bool ClearContext();
8793
bool MakeCurrent();
@@ -93,9 +99,6 @@ class Win32FlutterWindow : public Win32Window {
9399
void SendWindowMetrics();
94100

95101
private:
96-
// Destroy current rendering surface if one has been allocated.
97-
void DestroyRenderSurface();
98-
99102
// Reports a mouse movement to Flutter engine.
100103
void SendPointerMove(double x, double y);
101104

@@ -171,6 +174,9 @@ class Win32FlutterWindow : public Win32Window {
171174

172175
// should we forword input messages or not
173176
bool process_events_ = false;
177+
178+
// flag indicating if the message loop should be running
179+
bool messageloop_running_ = false;
174180
};
175181

176182
} // namespace flutter

shell/platform/windows/win32_window.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ Win32Window::MessageHandler(HWND hwnd,
112112
case kWmDpiChangedBeforeParent:
113113
return HandleDpiChange(window_handle_, wparam, lparam, false);
114114
break;
115+
case WM_DESTROY:
116+
window->OnClose();
117+
return 0;
118+
break;
115119
case WM_SIZE:
116120
width = LOWORD(lparam);
117121
height = HIWORD(lparam);

shell/platform/windows/win32_window.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct MouseState {
3737
class Win32Window {
3838
public:
3939
Win32Window();
40-
virtual ~Win32Window();
40+
~Win32Window();
4141

4242
// Initializes as a child window with size using |width| and |height| and
4343
// |title| to identify the windowclass. Does not show window, window must be
@@ -46,6 +46,9 @@ class Win32Window {
4646
unsigned int width,
4747
unsigned int height);
4848

49+
// Release OS resources asociated with window.
50+
virtual void Destroy();
51+
4952
HWND GetWindowHandle();
5053

5154
protected:
@@ -113,6 +116,9 @@ class Win32Window {
113116
// Called when mouse scrollwheel input occurs.
114117
virtual void OnScroll(double delta_x, double delta_y) = 0;
115118

119+
// Called when the user closes the Windows.
120+
virtual void OnClose() = 0;
121+
116122
// Called when the system font change.
117123
virtual void OnFontChange() = 0;
118124

@@ -144,9 +150,6 @@ class Win32Window {
144150
void SetMouseButtons(uint64_t buttons) { mouse_state_.buttons = buttons; }
145151

146152
private:
147-
// Release OS resources asociated with window.
148-
void Destroy();
149-
150153
// Activates tracking for a "mouse leave" event.
151154
void TrackMouseLeaveEvent(HWND hwnd);
152155

shell/platform/windows/win32_window_unittests.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ TEST(Win32FlutterWindowTest, CanFontChange) {
1515
LRESULT result = SendMessage(hwnd, WM_FONTCHANGE, NULL, NULL);
1616
ASSERT_EQ(result, 0);
1717
ASSERT_TRUE(window.OnFontChangeWasCalled());
18+
ASSERT_TRUE(TRUE);
1819
}
1920

2021
} // namespace testing

0 commit comments

Comments
 (0)