[Windows] Move DWM flush to Windows proc table for mocking (flutter/engine#49398)

The `FlutterWindowsView` uses the `DwmFlush` win32 API to prevent artifacts during window resizing.

Currently, the view used the `FlutterWindow` to allow mocking this win32 API. However, the window is a complex type with lots of other responsibilities. The `WindowsProcTable` is the new preferred type for mocking win32 API.

Part of https://github.com/flutter/flutter/issues/140626

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
Loïc Sharma
2023-12-27 15:41:19 -08:00
committed by GitHub
parent fc7ff0d62b
commit e7b8646416
8 changed files with 18 additions and 14 deletions

View File

@@ -185,12 +185,6 @@ void FlutterWindow::SetFlutterCursor(HCURSOR cursor) {
::SetCursor(current_cursor_);
}
void FlutterWindow::OnWindowResized() {
// Blocking the raster thread until DWM flushes alleviates glitches where
// previous size surface is stretched over current size view.
DwmFlush();
}
void FlutterWindow::OnDpiScale(unsigned int dpi) {};
// When DesktopWindow notifies that a WM_Size message has come in

View File

@@ -170,9 +170,6 @@ class FlutterWindow : public KeyboardManager::WindowDelegate,
// |FlutterWindowBindingHandler|
virtual void SetFlutterCursor(HCURSOR cursor) override;
// |FlutterWindowBindingHandler|
virtual void OnWindowResized() override;
// |FlutterWindowBindingHandler|
virtual bool OnBitmapSurfaceCleared() override;

View File

@@ -613,7 +613,11 @@ bool FlutterWindowsView::SwapBuffers() {
resize_status_ = ResizeState::kDone;
lock.unlock();
resize_cv_.notify_all();
binding_handler_->OnWindowResized();
// Blocking the raster thread until DWM flushes alleviates glitches where
// previous size surface is stretched over current size view.
windows_proc_table_->DwmFlush();
if (!visible) {
swap_buffers_result = engine_->surface_manager()->SwapBuffers();
}

View File

@@ -23,7 +23,6 @@ class MockWindowBindingHandler : public WindowBindingHandler {
MOCK_METHOD(HWND, GetWindowHandle, (), (override));
MOCK_METHOD(float, GetDpiScale, (), (override));
MOCK_METHOD(bool, IsVisible, (), (override));
MOCK_METHOD(void, OnWindowResized, (), (override));
MOCK_METHOD(PhysicalWindowBounds, GetPhysicalWindowBounds, (), (override));
MOCK_METHOD(void,
UpdateFlutterCursor,

View File

@@ -32,6 +32,8 @@ class MockWindowsProcTable : public WindowsProcTable {
MOCK_METHOD(bool, DwmIsCompositionEnabled, (), (const, override));
MOCK_METHOD(HRESULT, DwmFlush, (), (const, override));
private:
FML_DISALLOW_COPY_AND_ASSIGN(MockWindowsProcTable);
};

View File

@@ -57,9 +57,6 @@ class WindowBindingHandler {
// Returns the bounds of the backing window in physical pixels.
virtual PhysicalWindowBounds GetPhysicalWindowBounds() = 0;
// Invoked after the window has been resized.
virtual void OnWindowResized() = 0;
// Sets the cursor that should be used when the mouse is over the Flutter
// content. See mouse_cursor.dart for the values and meanings of cursor_name.
virtual void UpdateFlutterCursor(const std::string& cursor_name) = 0;

View File

@@ -54,4 +54,8 @@ bool WindowsProcTable::DwmIsCompositionEnabled() const {
return true;
}
HRESULT WindowsProcTable::DwmFlush() const {
return ::DwmFlush();
}
} // namespace flutter

View File

@@ -50,6 +50,13 @@ class WindowsProcTable {
// https://learn.microsoft.com/windows/win32/api/dwmapi/nf-dwmapi-dwmiscompositionenabled
virtual bool DwmIsCompositionEnabled() const;
// Issues a flush call that blocks the caller until all of the outstanding
// surface updates have been made.
//
// See:
// https://learn.microsoft.com/windows/win32/api/dwmapi/nf-dwmapi-dwmflush
virtual HRESULT DwmFlush() const;
private:
using GetPointerType_ = BOOL __stdcall(UINT32 pointerId,
POINTER_INPUT_TYPE* pointerType);