Unverified Commit 2d02c70a authored by James Clarke's avatar James Clarke Committed by GitHub

[Windows] Fix unnecessary surface creation/destruction in startup path (#63301)

parent 6d1242dd
...@@ -15,9 +15,11 @@ bool FlutterWindow::OnCreate() { ...@@ -15,9 +15,11 @@ bool FlutterWindow::OnCreate() {
return false; return false;
} }
// The size here is arbitrary since SetChildContent will resize it. RECT frame = GetClientArea();
// The size here must match the window dimensions to avoid unnecessary surface creation / destruction in the startup path.
flutter_controller_ = flutter_controller_ =
std::make_unique<flutter::FlutterViewController>(100, 100, project_); std::make_unique<flutter::FlutterViewController>(frame.right - frame.left, frame.bottom - frame.top, project_);
// Ensure that basic setup of the controller was successful. // Ensure that basic setup of the controller was successful.
if (!flutter_controller_->engine() || !flutter_controller_->view()) { if (!flutter_controller_->engine() || !flutter_controller_->view()) {
return false; return false;
......
...@@ -174,8 +174,7 @@ Win32Window::MessageHandler(HWND hwnd, ...@@ -174,8 +174,7 @@ Win32Window::MessageHandler(HWND hwnd,
return 0; return 0;
} }
case WM_SIZE: case WM_SIZE:
RECT rect; RECT rect = GetClientArea();
GetClientRect(hwnd, &rect);
if (child_content_ != nullptr) { if (child_content_ != nullptr) {
// Size and position the child window. // Size and position the child window.
MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
...@@ -218,8 +217,7 @@ Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { ...@@ -218,8 +217,7 @@ Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept {
void Win32Window::SetChildContent(HWND content) { void Win32Window::SetChildContent(HWND content) {
child_content_ = content; child_content_ = content;
SetParent(content, window_handle_); SetParent(content, window_handle_);
RECT frame; RECT frame = GetClientArea();
GetClientRect(window_handle_, &frame);
MoveWindow(content, frame.left, frame.top, frame.right - frame.left, MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
frame.bottom - frame.top, true); frame.bottom - frame.top, true);
...@@ -227,6 +225,12 @@ void Win32Window::SetChildContent(HWND content) { ...@@ -227,6 +225,12 @@ void Win32Window::SetChildContent(HWND content) {
SetFocus(child_content_); SetFocus(child_content_);
} }
RECT Win32Window::GetClientArea() {
RECT frame;
GetClientRect(window_handle_, &frame);
return frame;
}
HWND Win32Window::GetHandle() { HWND Win32Window::GetHandle() {
return window_handle_; return window_handle_;
} }
......
...@@ -52,6 +52,9 @@ class Win32Window { ...@@ -52,6 +52,9 @@ class Win32Window {
// If true, closing this window will quit the application. // If true, closing this window will quit the application.
void SetQuitOnClose(bool quit_on_close); void SetQuitOnClose(bool quit_on_close);
// Return a RECT representing the bounds of the current client area.
RECT GetClientArea();
protected: protected:
// Processes and route salient window messages for mouse handling, // Processes and route salient window messages for mouse handling,
// size change and DPI. Delegates handling of these to member overloads that // size change and DPI. Delegates handling of these to member overloads that
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment