From 19c8f51bd7dda933ee6aa803477810f282c680ca Mon Sep 17 00:00:00 2001 From: Loic Sharma Date: Mon, 15 May 2023 16:01:17 -0700 Subject: [PATCH 1/2] [Windows] Add force redraw to C++ client wrapper --- .../client_wrapper/flutter_view_controller.cc | 4 ++++ .../flutter_view_controller_unittests.cc | 18 ++++++++++++++++++ .../include/flutter/flutter_view_controller.h | 3 +++ .../testing/stub_flutter_windows_api.cc | 6 +++++- .../testing/stub_flutter_windows_api.h | 3 +++ .../platform/windows/public/flutter_windows.h | 2 +- 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/shell/platform/windows/client_wrapper/flutter_view_controller.cc b/shell/platform/windows/client_wrapper/flutter_view_controller.cc index 5cb9fe98623e1..e6f39247cba1f 100644 --- a/shell/platform/windows/client_wrapper/flutter_view_controller.cc +++ b/shell/platform/windows/client_wrapper/flutter_view_controller.cc @@ -29,6 +29,10 @@ FlutterViewController::~FlutterViewController() { } } +void FlutterViewController::ForceRedraw() { + FlutterDesktopViewControllerForceRedraw(controller_); +} + std::optional FlutterViewController::HandleTopLevelWindowProc( HWND hwnd, UINT message, diff --git a/shell/platform/windows/client_wrapper/flutter_view_controller_unittests.cc b/shell/platform/windows/client_wrapper/flutter_view_controller_unittests.cc index 264a998c29138..08d860d44e984 100644 --- a/shell/platform/windows/client_wrapper/flutter_view_controller_unittests.cc +++ b/shell/platform/windows/client_wrapper/flutter_view_controller_unittests.cc @@ -27,6 +27,11 @@ class TestWindowsApi : public testing::StubFlutterWindowsApi { // |flutter::testing::StubFlutterWindowsApi| void ViewControllerDestroy() override { view_controller_destroyed_ = true; } + // |flutter::testing::StubFlutterWindowsApi| + void ViewControllerForceRedraw() override { + view_controller_force_redrawed_ = true; + } + // |flutter::testing::StubFlutterWindowsApi| FlutterDesktopEngineRef EngineCreate( const FlutterDesktopEngineProperties& engine_properties) override { @@ -41,10 +46,12 @@ class TestWindowsApi : public testing::StubFlutterWindowsApi { bool engine_destroyed() { return engine_destroyed_; } bool view_controller_destroyed() { return view_controller_destroyed_; } + bool view_controller_force_redrawed() { return view_controller_force_redrawed_; } private: bool engine_destroyed_ = false; bool view_controller_destroyed_ = false; + bool view_controller_force_redrawed_ = false; }; } // namespace @@ -79,4 +86,15 @@ TEST(FlutterViewControllerTest, GetView) { EXPECT_NE(controller.view(), nullptr); } +TEST(FlutterViewControllerTest, ForceRedraw) { + DartProject project(L"data"); + testing::ScopedStubFlutterWindowsApi scoped_api_stub( + std::make_unique()); + auto test_api = static_cast(scoped_api_stub.stub()); + FlutterViewController controller(100, 100, project); + + controller.ForceRedraw(); + EXPECT_TRUE(test_api->view_controller_force_redrawed()); +} + } // namespace flutter diff --git a/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h b/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h index 9b08d03f6504d..7a2ce191973be 100644 --- a/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h +++ b/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h @@ -44,6 +44,9 @@ class FlutterViewController { // Returns the view managed by this controller. FlutterView* view() { return view_.get(); } + // Requests new frame from the engine and repaints the view. + void ForceRedraw(); + // Allows the Flutter engine and any interested plugins an opportunity to // handle the given message. // diff --git a/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.cc b/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.cc index 8028bbb78e398..ed9f9d3bcb2ff 100644 --- a/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.cc +++ b/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.cc @@ -65,7 +65,11 @@ FlutterDesktopViewRef FlutterDesktopViewControllerGetView( } void FlutterDesktopViewControllerForceRedraw( - FlutterDesktopViewControllerRef controller) {} + FlutterDesktopViewControllerRef controller) { + if (s_stub_implementation) { + s_stub_implementation->ViewControllerForceRedraw(); + } +} bool FlutterDesktopViewControllerHandleTopLevelWindowProc( FlutterDesktopViewControllerRef controller, diff --git a/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.h b/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.h index 247255c5668e9..a1864d4f07720 100644 --- a/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.h +++ b/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.h @@ -38,6 +38,9 @@ class StubFlutterWindowsApi { // Called for FlutterDesktopViewControllerDestroy. virtual void ViewControllerDestroy() {} + // Called for FlutterDesktopViewControllerForceRedraw. + virtual void ViewControllerForceRedraw() {} + // Called for FlutterDesktopViewControllerHandleTopLevelWindowProc. virtual bool ViewControllerHandleTopLevelWindowProc(HWND hwnd, UINT message, diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index 1498906fe1d90..767c3468d45d3 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -107,7 +107,7 @@ FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine( FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef controller); -// Requests new frame from engine and repaints the view +// Requests new frame from the engine and repaints the view. FLUTTER_EXPORT void FlutterDesktopViewControllerForceRedraw( FlutterDesktopViewControllerRef controller); From 5f06422b84ae4b363abeea2b672c493403aa2f89 Mon Sep 17 00:00:00 2001 From: Loic Sharma Date: Mon, 15 May 2023 16:17:23 -0700 Subject: [PATCH 2/2] Format --- .../client_wrapper/flutter_view_controller_unittests.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shell/platform/windows/client_wrapper/flutter_view_controller_unittests.cc b/shell/platform/windows/client_wrapper/flutter_view_controller_unittests.cc index 08d860d44e984..5b5a019d5f654 100644 --- a/shell/platform/windows/client_wrapper/flutter_view_controller_unittests.cc +++ b/shell/platform/windows/client_wrapper/flutter_view_controller_unittests.cc @@ -46,7 +46,9 @@ class TestWindowsApi : public testing::StubFlutterWindowsApi { bool engine_destroyed() { return engine_destroyed_; } bool view_controller_destroyed() { return view_controller_destroyed_; } - bool view_controller_force_redrawed() { return view_controller_force_redrawed_; } + bool view_controller_force_redrawed() { + return view_controller_force_redrawed_; + } private: bool engine_destroyed_ = false;