Windows: Resize synchronization shouldn't wait for vsync if window is hidden (flutter/engine#26857)
* Resize synchronization shouldn't wait for vsync if window is hidden
This commit is contained in:
@@ -89,6 +89,10 @@ float FlutterWindowWin32::GetDpiScale() {
|
||||
return static_cast<float>(GetCurrentDPI()) / static_cast<float>(base_dpi);
|
||||
}
|
||||
|
||||
bool FlutterWindowWin32::IsVisible() {
|
||||
return IsWindowVisible(GetWindowHandle());
|
||||
}
|
||||
|
||||
PhysicalWindowBounds FlutterWindowWin32::GetPhysicalWindowBounds() {
|
||||
return {GetCurrentWidth(), GetCurrentHeight()};
|
||||
}
|
||||
|
||||
@@ -92,6 +92,9 @@ class FlutterWindowWin32 : public WindowWin32, public WindowBindingHandler {
|
||||
// |FlutterWindowBindingHandler|
|
||||
float GetDpiScale() override;
|
||||
|
||||
// |FlutterWindowBindingHandler|
|
||||
bool IsVisible() override;
|
||||
|
||||
// |FlutterWindowBindingHandler|
|
||||
PhysicalWindowBounds GetPhysicalWindowBounds() override;
|
||||
|
||||
|
||||
@@ -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&));
|
||||
};
|
||||
|
||||
|
||||
@@ -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&) {
|
||||
|
||||
@@ -43,6 +43,9 @@ class FlutterWindowWinUWP : public WindowBindingHandler {
|
||||
// |WindowBindingHandler|
|
||||
float GetDpiScale() override;
|
||||
|
||||
// |FlutterWindowBindingHandler|
|
||||
bool IsVisible() override;
|
||||
|
||||
// |WindowBindingHandler|
|
||||
PhysicalWindowBounds GetPhysicalWindowBounds() override;
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user