diff --git a/engine/src/flutter/shell/platform/windows/flutter_window_win32.cc b/engine/src/flutter/shell/platform/windows/flutter_window_win32.cc index aa75f30ac0..a6fd8bd05b 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_window_win32.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_window_win32.cc @@ -89,6 +89,10 @@ float FlutterWindowWin32::GetDpiScale() { return static_cast(GetCurrentDPI()) / static_cast(base_dpi); } +bool FlutterWindowWin32::IsVisible() { + return IsWindowVisible(GetWindowHandle()); +} + PhysicalWindowBounds FlutterWindowWin32::GetPhysicalWindowBounds() { return {GetCurrentWidth(), GetCurrentHeight()}; } diff --git a/engine/src/flutter/shell/platform/windows/flutter_window_win32.h b/engine/src/flutter/shell/platform/windows/flutter_window_win32.h index d4fe0f5623..4279b7afba 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_window_win32.h +++ b/engine/src/flutter/shell/platform/windows/flutter_window_win32.h @@ -92,6 +92,9 @@ class FlutterWindowWin32 : public WindowWin32, public WindowBindingHandler { // |FlutterWindowBindingHandler| float GetDpiScale() override; + // |FlutterWindowBindingHandler| + bool IsVisible() override; + // |FlutterWindowBindingHandler| PhysicalWindowBounds GetPhysicalWindowBounds() override; diff --git a/engine/src/flutter/shell/platform/windows/flutter_window_win32_unittests.cc b/engine/src/flutter/shell/platform/windows/flutter_window_win32_unittests.cc index 6841700508..f5f6f93527 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_window_win32_unittests.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_window_win32_unittests.cc @@ -156,6 +156,7 @@ class MockFlutterWindowWin32 : public FlutterWindowWin32 { MOCK_METHOD2(OnScroll, void(double, double)); MOCK_METHOD4(DefaultWindowProc, LRESULT(HWND, UINT, WPARAM, LPARAM)); MOCK_METHOD0(GetDpiScale, float()); + MOCK_METHOD0(IsVisible, bool()); MOCK_METHOD1(UpdateCursorRect, void(const Rect&)); }; diff --git a/engine/src/flutter/shell/platform/windows/flutter_window_winuwp.cc b/engine/src/flutter/shell/platform/windows/flutter_window_winuwp.cc index bace4d7529..bda55263c3 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_window_winuwp.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_window_winuwp.cc @@ -117,6 +117,10 @@ float FlutterWindowWinUWP::GetDpiScale() { return display_helper_->GetDpiScale(); } +bool FlutterWindowWinUWP::IsVisible() { + return window_.Visible(); +} + void FlutterWindowWinUWP::OnDpiChanged( winrt::Windows::Graphics::Display::DisplayInformation const& args, winrt::Windows::Foundation::IInspectable const&) { diff --git a/engine/src/flutter/shell/platform/windows/flutter_window_winuwp.h b/engine/src/flutter/shell/platform/windows/flutter_window_winuwp.h index 8cb4455568..6ac054ee7b 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_window_winuwp.h +++ b/engine/src/flutter/shell/platform/windows/flutter_window_winuwp.h @@ -43,6 +43,9 @@ class FlutterWindowWinUWP : public WindowBindingHandler { // |WindowBindingHandler| float GetDpiScale() override; + // |FlutterWindowBindingHandler| + bool IsVisible() override; + // |WindowBindingHandler| PhysicalWindowBounds GetPhysicalWindowBounds() override; diff --git a/engine/src/flutter/shell/platform/windows/flutter_windows_view.cc b/engine/src/flutter/shell/platform/windows/flutter_windows_view.cc index ecb2e580c0..1d5d9b230a 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_windows_view.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_windows_view.cc @@ -449,11 +449,22 @@ bool FlutterWindowsView::SwapBuffers() { case ResizeState::kResizeStarted: return false; case ResizeState::kFrameGenerated: { - bool swap_buffers_result = engine_->surface_manager()->SwapBuffers(); + bool visible = binding_handler_->IsVisible(); + bool swap_buffers_result; + // For visible windows swap the buffers while resize handler is waiting. + // For invisible windows unblock the handler first and then swap buffers. + // SwapBuffers waits for vsync and there's no point doing that for + // invisible windows. + if (visible) { + swap_buffers_result = engine_->surface_manager()->SwapBuffers(); + } resize_status_ = ResizeState::kDone; lock.unlock(); resize_cv_.notify_all(); binding_handler_->OnWindowResized(); + if (!visible) { + swap_buffers_result = engine_->surface_manager()->SwapBuffers(); + } return swap_buffers_result; } case ResizeState::kDone: diff --git a/engine/src/flutter/shell/platform/windows/testing/mock_window_binding_handler.h b/engine/src/flutter/shell/platform/windows/testing/mock_window_binding_handler.h index d3619df55c..c6be8e18c8 100644 --- a/engine/src/flutter/shell/platform/windows/testing/mock_window_binding_handler.h +++ b/engine/src/flutter/shell/platform/windows/testing/mock_window_binding_handler.h @@ -27,6 +27,7 @@ class MockWindowBindingHandler : public WindowBindingHandler { MOCK_METHOD0(GetRenderTarget, WindowsRenderTarget()); MOCK_METHOD0(GetPlatformWindow, PlatformWindow()); MOCK_METHOD0(GetDpiScale, float()); + MOCK_METHOD0(IsVisible, bool()); MOCK_METHOD0(OnWindowResized, void()); MOCK_METHOD0(GetPhysicalWindowBounds, PhysicalWindowBounds()); MOCK_METHOD1(UpdateFlutterCursor, void(const std::string& cursor_name)); diff --git a/engine/src/flutter/shell/platform/windows/window_binding_handler.h b/engine/src/flutter/shell/platform/windows/window_binding_handler.h index f699bda24f..60f93ca8ae 100644 --- a/engine/src/flutter/shell/platform/windows/window_binding_handler.h +++ b/engine/src/flutter/shell/platform/windows/window_binding_handler.h @@ -68,6 +68,9 @@ class WindowBindingHandler { // Returns the scale factor for the backing window. virtual float GetDpiScale() = 0; + // Returns whether the PlatformWindow is currently visible. + virtual bool IsVisible() = 0; + // Returns the bounds of the backing window in physical pixels. virtual PhysicalWindowBounds GetPhysicalWindowBounds() = 0;