[Windows] Fix unnecessary surface creation/destruction in startup path (#63301)
This commit is contained in:
@@ -15,9 +15,11 @@ bool FlutterWindow::OnCreate() {
|
||||
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_ =
|
||||
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.
|
||||
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
|
||||
return false;
|
||||
|
||||
@@ -174,8 +174,7 @@ Win32Window::MessageHandler(HWND hwnd,
|
||||
return 0;
|
||||
}
|
||||
case WM_SIZE:
|
||||
RECT rect;
|
||||
GetClientRect(hwnd, &rect);
|
||||
RECT rect = GetClientArea();
|
||||
if (child_content_ != nullptr) {
|
||||
// Size and position the child window.
|
||||
MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
|
||||
@@ -218,8 +217,7 @@ Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept {
|
||||
void Win32Window::SetChildContent(HWND content) {
|
||||
child_content_ = content;
|
||||
SetParent(content, window_handle_);
|
||||
RECT frame;
|
||||
GetClientRect(window_handle_, &frame);
|
||||
RECT frame = GetClientArea();
|
||||
|
||||
MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
|
||||
frame.bottom - frame.top, true);
|
||||
@@ -227,6 +225,12 @@ void Win32Window::SetChildContent(HWND content) {
|
||||
SetFocus(child_content_);
|
||||
}
|
||||
|
||||
RECT Win32Window::GetClientArea() {
|
||||
RECT frame;
|
||||
GetClientRect(window_handle_, &frame);
|
||||
return frame;
|
||||
}
|
||||
|
||||
HWND Win32Window::GetHandle() {
|
||||
return window_handle_;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,9 @@ class Win32Window {
|
||||
// If true, closing this window will quit the application.
|
||||
void SetQuitOnClose(bool quit_on_close);
|
||||
|
||||
// Return a RECT representing the bounds of the current client area.
|
||||
RECT GetClientArea();
|
||||
|
||||
protected:
|
||||
// Processes and route salient window messages for mouse handling,
|
||||
// size change and DPI. Delegates handling of these to member overloads that
|
||||
|
||||
Reference in New Issue
Block a user