From 2d02c70ad55159a33c3d41f6e94385c6a3cf4b59 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Mon, 31 Aug 2020 09:28:05 -0700 Subject: [PATCH] [Windows] Fix unnecessary surface creation/destruction in startup path (#63301) --- .../app/windows.tmpl/runner/flutter_window.cpp | 6 ++++-- .../app/windows.tmpl/runner/win32_window.cpp | 12 ++++++++---- .../templates/app/windows.tmpl/runner/win32_window.h | 3 +++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/flutter_tools/templates/app/windows.tmpl/runner/flutter_window.cpp b/packages/flutter_tools/templates/app/windows.tmpl/runner/flutter_window.cpp index 87823d55c4..6c7fa3d085 100644 --- a/packages/flutter_tools/templates/app/windows.tmpl/runner/flutter_window.cpp +++ b/packages/flutter_tools/templates/app/windows.tmpl/runner/flutter_window.cpp @@ -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(100, 100, project_); + std::make_unique(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; diff --git a/packages/flutter_tools/templates/app/windows.tmpl/runner/win32_window.cpp b/packages/flutter_tools/templates/app/windows.tmpl/runner/win32_window.cpp index 19fb9e05b3..549e7af9ad 100644 --- a/packages/flutter_tools/templates/app/windows.tmpl/runner/win32_window.cpp +++ b/packages/flutter_tools/templates/app/windows.tmpl/runner/win32_window.cpp @@ -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_; } diff --git a/packages/flutter_tools/templates/app/windows.tmpl/runner/win32_window.h b/packages/flutter_tools/templates/app/windows.tmpl/runner/win32_window.h index ea09829ca7..93d2162eea 100644 --- a/packages/flutter_tools/templates/app/windows.tmpl/runner/win32_window.h +++ b/packages/flutter_tools/templates/app/windows.tmpl/runner/win32_window.h @@ -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