diff --git a/shell/platform/windows/client_wrapper/flutter_view_controller.cc b/shell/platform/windows/client_wrapper/flutter_view_controller.cc index e6f39247cba1f..3f59964f2dc1b 100644 --- a/shell/platform/windows/client_wrapper/flutter_view_controller.cc +++ b/shell/platform/windows/client_wrapper/flutter_view_controller.cc @@ -29,6 +29,12 @@ FlutterViewController::~FlutterViewController() { } } +FlutterViewId FlutterViewController::view_id() const { + auto view_id = FlutterDesktopViewControllerGetViewId(controller_); + + return static_cast(view_id); +} + void FlutterViewController::ForceRedraw() { FlutterDesktopViewControllerForceRedraw(controller_); } 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 5b5a019d5f654..837c2e13e583d 100644 --- a/shell/platform/windows/client_wrapper/flutter_view_controller_unittests.cc +++ b/shell/platform/windows/client_wrapper/flutter_view_controller_unittests.cc @@ -70,6 +70,15 @@ TEST(FlutterViewControllerTest, CreateDestroy) { EXPECT_FALSE(test_api->engine_destroyed()); } +TEST(FlutterViewControllerTest, GetViewId) { + 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); + EXPECT_EQ(controller.view_id(), 1); +} + TEST(FlutterViewControllerTest, GetEngine) { DartProject project(L"data"); testing::ScopedStubFlutterWindowsApi scoped_api_stub( diff --git a/shell/platform/windows/client_wrapper/include/flutter/flutter_view.h b/shell/platform/windows/client_wrapper/include/flutter/flutter_view.h index c5cc649be024e..8f1752a9f58a3 100644 --- a/shell/platform/windows/client_wrapper/include/flutter/flutter_view.h +++ b/shell/platform/windows/client_wrapper/include/flutter/flutter_view.h @@ -9,6 +9,9 @@ namespace flutter { +// The unique identifier for a view. +typedef int64_t FlutterViewId; + // A view displaying Flutter content. class FlutterView { public: 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 7a2ce191973be..4c658f479967a 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 @@ -38,11 +38,14 @@ class FlutterViewController { FlutterViewController(FlutterViewController const&) = delete; FlutterViewController& operator=(FlutterViewController const&) = delete; + // Returns the view controller's view ID. + FlutterViewId view_id() const; + // Returns the engine running Flutter content in this view. - FlutterEngine* engine() { return engine_.get(); } + FlutterEngine* engine() const { return engine_.get(); } // Returns the view managed by this controller. - FlutterView* view() { return view_.get(); } + FlutterView* view() const { return view_.get(); } // Requests new frame from the engine and repaints the view. void ForceRedraw(); 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 f01f895c728f5..384e0c3cfae31 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 @@ -52,6 +52,12 @@ void FlutterDesktopViewControllerDestroy( } } +FlutterDesktopViewId FlutterDesktopViewControllerGetViewId( + FlutterDesktopViewControllerRef controller) { + // The stub ignores this, so just return an arbitrary non-zero value. + return static_cast(1); +} + FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine( FlutterDesktopViewControllerRef controller) { // The stub ignores this, so just return an arbitrary non-zero value. diff --git a/shell/platform/windows/flutter_windows.cc b/shell/platform/windows/flutter_windows.cc index dfe9767f53529..df25772582c91 100644 --- a/shell/platform/windows/flutter_windows.cc +++ b/shell/platform/windows/flutter_windows.cc @@ -110,6 +110,12 @@ void FlutterDesktopViewControllerDestroy(FlutterDesktopViewControllerRef ref) { delete controller; } +FlutterDesktopViewId FlutterDesktopViewControllerGetViewId( + FlutterDesktopViewControllerRef ref) { + auto controller = ViewControllerFromHandle(ref); + return static_cast(controller->view()->view_id()); +} + FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine( FlutterDesktopViewControllerRef ref) { auto controller = ViewControllerFromHandle(ref); diff --git a/shell/platform/windows/flutter_windows_unittests.cc b/shell/platform/windows/flutter_windows_unittests.cc index a35bfae0f6cea..55e5b65a2fc24 100644 --- a/shell/platform/windows/flutter_windows_unittests.cc +++ b/shell/platform/windows/flutter_windows_unittests.cc @@ -307,6 +307,18 @@ TEST_F(WindowsTest, NextFrameCallback) { captures.frame_drawn_latch.Wait(); } +// Implicit view has the implicit view ID. +TEST_F(WindowsTest, GetViewId) { + auto& context = GetContext(); + WindowsConfigBuilder builder(context); + ViewControllerPtr controller{builder.Run()}; + ASSERT_NE(controller, nullptr); + FlutterDesktopViewId view_id = + FlutterDesktopViewControllerGetViewId(controller.get()); + + ASSERT_EQ(view_id, static_cast(kImplicitViewId)); +} + TEST_F(WindowsTest, GetGraphicsAdapter) { auto& context = GetContext(); WindowsConfigBuilder builder(context); diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index a9f7f973fb987..aa74241fdbe28 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -32,6 +32,9 @@ typedef struct FlutterDesktopView* FlutterDesktopViewRef; struct FlutterDesktopEngine; typedef struct FlutterDesktopEngine* FlutterDesktopEngineRef; +// The unique identifier for a view. +typedef int64_t FlutterDesktopViewId; + // Properties for configuring a Flutter engine instance. typedef struct { // The path to the flutter_assets folder for the application to be run. @@ -97,13 +100,17 @@ FlutterDesktopViewControllerCreate(int width, FLUTTER_EXPORT void FlutterDesktopViewControllerDestroy( FlutterDesktopViewControllerRef controller); +// Returns the view controller's view ID. +FLUTTER_EXPORT FlutterDesktopViewId FlutterDesktopViewControllerGetViewId( + FlutterDesktopViewControllerRef view_controller); + // Returns the handle for the engine running in FlutterDesktopViewControllerRef. // // Its lifetime is the same as the |controller|'s. FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine( FlutterDesktopViewControllerRef controller); -// Returns the view managed by the given controller. +// Returns the view managed by the given controller. FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopViewControllerGetView( FlutterDesktopViewControllerRef controller); @@ -205,7 +212,7 @@ FLUTTER_EXPORT void FlutterDesktopEngineSetNextFrameCallback( // ========== View ========== -// Return backing HWND for manipulation in host application. +// Returns the backing HWND for manipulation in host application. FLUTTER_EXPORT HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view); // Returns the DXGI adapter used for rendering or nullptr in case of error.