From 500e60cb1bc9fe690657b5f82f9df32c1d278bda Mon Sep 17 00:00:00 2001 From: schectman Date: Thu, 8 Feb 2024 14:20:43 -0500 Subject: [PATCH 01/27] Define structs, class --- shell/platform/windows/BUILD.gn | 2 ++ .../platform/windows/platform_view_manager.cc | 9 ++++++ .../platform/windows/platform_view_manager.h | 31 +++++++++++++++++++ .../platform/windows/public/flutter_windows.h | 15 +++++++++ 4 files changed, 57 insertions(+) create mode 100644 shell/platform/windows/platform_view_manager.cc create mode 100644 shell/platform/windows/platform_view_manager.h diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index 7a30f737b69b6..f8dad4bb1f777 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -98,6 +98,8 @@ source_set("flutter_windows_source") { "keyboard_utils.h", "platform_handler.cc", "platform_handler.h", + "platform_view_manager.cc", + "platform_view_manager.h", "sequential_id_generator.cc", "sequential_id_generator.h", "settings_plugin.cc", diff --git a/shell/platform/windows/platform_view_manager.cc b/shell/platform/windows/platform_view_manager.cc new file mode 100644 index 0000000000000..b5fff47fd340a --- /dev/null +++ b/shell/platform/windows/platform_view_manager.cc @@ -0,0 +1,9 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/windows/platform_view_manager.h" + +namespace flutter { + +} // namespace flutter diff --git a/shell/platform/windows/platform_view_manager.h b/shell/platform/windows/platform_view_manager.h new file mode 100644 index 0000000000000..c36568765b5b7 --- /dev/null +++ b/shell/platform/windows/platform_view_manager.h @@ -0,0 +1,31 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_MANAGER_H_ +#define FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_MANAGER_H_ + +#include +#include + +#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h" +#include "flutter/shell/platform/windows/public/flutter_windows.h" + +namespace flutter { + +class PlatformViewManager { + public: + + private: + std::unique_ptr> channel_; + + std::map platform_view_types_; + + std::map platform_views_; + + std::map pending_platform_views_; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_MANAGER_H_ diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index 70cd60a2eb984..f3a400d61229d 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -203,6 +203,21 @@ FLUTTER_EXPORT void FlutterDesktopEngineSetNextFrameCallback( VoidCallback callback, void* user_data); +typedef struct { + size_t cb_size; + HWND parent_window; + const char* platform_view_type; + void* user_data; + int64_t platform_view_id; +} FlutterPlatformViewCreationParameters; + +typedef HWND (*FlutterPlatformViewFactory)(const FlutterPlatformViewCreationParameters*); + +typedef struct { + FlutterPlatformViewFactory factory; + void* user_data; +} FlutterPlatformViewTypeEntry; + // ========== View ========== // Return backing HWND for manipulation in host application. From 8dd45432fe3c314a4d5a9227a7a065dd346197e0 Mon Sep 17 00:00:00 2001 From: schectman Date: Thu, 8 Feb 2024 14:27:49 -0500 Subject: [PATCH 02/27] Define PV type registration runner API function --- .../client_wrapper/testing/stub_flutter_windows_api.cc | 10 ++++++++++ .../client_wrapper/testing/stub_flutter_windows_api.h | 4 ++++ shell/platform/windows/flutter_windows.cc | 7 +++++++ shell/platform/windows/public/flutter_windows.h | 5 +++++ 4 files changed, 26 insertions(+) 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 da0a8c57712d3..f01f895c728f5 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 @@ -176,6 +176,16 @@ bool FlutterDesktopEngineProcessExternalWindowMessage( return false; } +void FlutterDesktopEngineRegisterPlatformViewType( + FlutterDesktopEngineRef engine, + const char* view_type_name, + FlutterPlatformViewTypeEntry view_type) { + if (s_stub_implementation) { + s_stub_implementation->EngineRegisterPlatformViewType(view_type_name, + view_type); + } +} + FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView( FlutterDesktopPluginRegistrarRef controller) { // The stub ignores this, so just return an arbitrary non-zero value. 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 19671159ea426..c9b44199f4053 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 @@ -72,6 +72,10 @@ class StubFlutterWindowsApi { // Called for FlutterDesktopEngineReloadSystemFonts. virtual void EngineReloadSystemFonts() {} + // Called for FlutterDesktopEngineRegisterPlatformViewType. + virtual void EngineRegisterPlatformViewType( + const char* view_type_name, FlutterPlatformViewTypeEntry view_type) {} + // Called for FlutterDesktopViewGetHWND. virtual HWND ViewGetHWND() { return reinterpret_cast(1); } diff --git a/shell/platform/windows/flutter_windows.cc b/shell/platform/windows/flutter_windows.cc index 0f293c497c670..dc1eeb73d80ec 100644 --- a/shell/platform/windows/flutter_windows.cc +++ b/shell/platform/windows/flutter_windows.cc @@ -246,6 +246,13 @@ bool FlutterDesktopEngineProcessExternalWindowMessage( return lresult.has_value(); } +void FlutterDesktopEngineRegisterPlatformViewType( + FlutterDesktopEngineRef engine, + const char* view_type_name, + FlutterPlatformViewTypeEntry view_type) { + // TODO(schectman): forward to platform view manager +} + FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView( FlutterDesktopPluginRegistrarRef registrar) { return HandleForView(registrar->engine->view()); diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index f3a400d61229d..11fff8fbeb7ce 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -218,6 +218,11 @@ typedef struct { void* user_data; } FlutterPlatformViewTypeEntry; +FLUTTER_EXPORT void FlutterDesktopEngineRegisterPlatformViewType( + FlutterDesktopEngineRef engine, + const char* view_type_name, + FlutterPlatformViewTypeEntry view_type); + // ========== View ========== // Return backing HWND for manipulation in host application. From ae0d0492664da3026e74a853f3087bf5420a2c5a Mon Sep 17 00:00:00 2001 From: schectman Date: Thu, 8 Feb 2024 17:30:40 -0500 Subject: [PATCH 03/27] Bare minimum PlatformViewHandler --- .../platform/windows/platform_view_manager.cc | 24 +++++++++++++++++++ .../platform/windows/platform_view_manager.h | 23 +++++++++++++++++- .../platform/windows/public/flutter_windows.h | 1 + 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/shell/platform/windows/platform_view_manager.cc b/shell/platform/windows/platform_view_manager.cc index b5fff47fd340a..92081210d26d1 100644 --- a/shell/platform/windows/platform_view_manager.cc +++ b/shell/platform/windows/platform_view_manager.cc @@ -4,6 +4,30 @@ #include "flutter/shell/platform/windows/platform_view_manager.h" +#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h" + namespace flutter { +namespace { +constexpr char kChannelName[] = ""; +} + +PlatformViewManager::PlatformViewManager(TaskRunner* task_runner, BinaryMessenger* binary_messenger) : task_runner_(task_runner), channel_(std::make_unique>(binary_messenger, kChannelName, &StandardMethodCodec::GetInstance())) { + channel_->SetMethodCallHandler([](const MethodCall& call, std::unique_ptr> result){ + result->Success(); + }); +} + +void PlatformViewManager::QueuePlatformViewCreation(std::string_view type_name, int64_t id) {} + +void PlatformViewManager::InstantiatePlatformView(int64_t id) {} + +void PlatformViewManager::RegisterPlatformViewType(std::string_view type_name, const FlutterPlatformViewTypeEntry& type) {} + +void PlatformViewManager::FocusPlatformView(int64_t id, FocusChangeDirection direction, bool focus) {} + +std::optional PlatformViewManager::GetNativeHandleForId(int64_t id) const { + return std::nullopt; +} + } // namespace flutter diff --git a/shell/platform/windows/platform_view_manager.h b/shell/platform/windows/platform_view_manager.h index c36568765b5b7..60d9d870a73f8 100644 --- a/shell/platform/windows/platform_view_manager.h +++ b/shell/platform/windows/platform_view_manager.h @@ -5,17 +5,36 @@ #ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_MANAGER_H_ #define FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_MANAGER_H_ +#include #include #include +#include #include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" +#include "flutter/shell/platform/windows/task_runner.h" namespace flutter { +enum class FocusChangeDirection { + kProgrammatic, + kForward, + kBackward +}; + class PlatformViewManager { public: + PlatformViewManager(TaskRunner* task_runner, BinaryMessenger* binary_messenger); + + void QueuePlatformViewCreation(std::string_view type_name, int64_t id); + + void InstantiatePlatformView(int64_t id); + void RegisterPlatformViewType(std::string_view type_name, const FlutterPlatformViewTypeEntry& type); + + void FocusPlatformView(int64_t id, FocusChangeDirection direction, bool focus); + + std::optional GetNativeHandleForId(int64_t id) const; private: std::unique_ptr> channel_; @@ -23,7 +42,9 @@ class PlatformViewManager { std::map platform_views_; - std::map pending_platform_views_; + std::map> pending_platform_views_; + + TaskRunner* task_runner_; }; } // namespace flutter diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index 11fff8fbeb7ce..4d92d07d7f793 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -214,6 +214,7 @@ typedef struct { typedef HWND (*FlutterPlatformViewFactory)(const FlutterPlatformViewCreationParameters*); typedef struct { + size_t cb_size; FlutterPlatformViewFactory factory; void* user_data; } FlutterPlatformViewTypeEntry; From 5f14af0e02f4250bdce68e68552f8858790ac12f Mon Sep 17 00:00:00 2001 From: schectman Date: Thu, 8 Feb 2024 17:38:08 -0500 Subject: [PATCH 04/27] Compositor owns platform view manager --- shell/platform/windows/compositor.h | 8 ++++++++ shell/platform/windows/compositor_opengl.cc | 5 +++-- shell/platform/windows/compositor_opengl.h | 3 ++- .../platform/windows/compositor_opengl_unittests.cc | 12 ++++++------ shell/platform/windows/compositor_software.cc | 5 +++-- shell/platform/windows/compositor_software.h | 3 ++- .../windows/compositor_software_unittests.cc | 8 ++++---- shell/platform/windows/flutter_windows_engine.cc | 5 +++-- 8 files changed, 31 insertions(+), 18 deletions(-) diff --git a/shell/platform/windows/compositor.h b/shell/platform/windows/compositor.h index c7691f53e8510..e94e08f4a6c3d 100644 --- a/shell/platform/windows/compositor.h +++ b/shell/platform/windows/compositor.h @@ -7,6 +7,10 @@ #include "flutter/shell/platform/embedder/embedder.h" +#include + +#include "flutter/shell/platform/windows/platform_view_manager.h" + namespace flutter { // Enables the Flutter engine to render content on Windows. @@ -19,6 +23,7 @@ namespace flutter { // Platform views are not yet supported. class Compositor { public: + Compositor(std::unique_ptr manager) : platform_view_manager_(std::move(manager)) {} virtual ~Compositor() = default; // Creates a backing store used for rendering Flutter content. @@ -32,6 +37,9 @@ class Compositor { // Present Flutter content and platform views onto the view. virtual bool Present(const FlutterLayer** layers, size_t layers_count) = 0; + + protected: + std::unique_ptr platform_view_manager_; }; } // namespace flutter diff --git a/shell/platform/windows/compositor_opengl.cc b/shell/platform/windows/compositor_opengl.cc index b43f888d65191..5c3d6b0c85add 100644 --- a/shell/platform/windows/compositor_opengl.cc +++ b/shell/platform/windows/compositor_opengl.cc @@ -34,9 +34,10 @@ int GetSupportedTextureFormat(const impeller::DescriptionGLES* description) { } // namespace -CompositorOpenGL::CompositorOpenGL(FlutterWindowsEngine* engine, +CompositorOpenGL::CompositorOpenGL(std::unique_ptr manager, + FlutterWindowsEngine* engine, impeller::ProcTableGLES::Resolver resolver) - : engine_(engine), resolver_(resolver) {} + : Compositor(std::move(manager)), engine_(engine), resolver_(resolver) {} bool CompositorOpenGL::CreateBackingStore( const FlutterBackingStoreConfig& config, diff --git a/shell/platform/windows/compositor_opengl.h b/shell/platform/windows/compositor_opengl.h index 06c22202332e2..4c936c6e7d9d2 100644 --- a/shell/platform/windows/compositor_opengl.h +++ b/shell/platform/windows/compositor_opengl.h @@ -17,7 +17,8 @@ namespace flutter { // Enables the Flutter engine to render content on Windows using OpenGL. class CompositorOpenGL : public Compositor { public: - CompositorOpenGL(FlutterWindowsEngine* engine, + CompositorOpenGL(std::unique_ptr manager, + FlutterWindowsEngine* engine, impeller::ProcTableGLES::Resolver resolver); /// |Compositor| diff --git a/shell/platform/windows/compositor_opengl_unittests.cc b/shell/platform/windows/compositor_opengl_unittests.cc index 08fd6dfaf4861..659165e4a2f6a 100644 --- a/shell/platform/windows/compositor_opengl_unittests.cc +++ b/shell/platform/windows/compositor_opengl_unittests.cc @@ -113,7 +113,7 @@ class CompositorOpenGLTest : public WindowsTest { TEST_F(CompositorOpenGLTest, CreateBackingStore) { UseHeadlessEngine(); - auto compositor = CompositorOpenGL{engine(), kMockResolver}; + auto compositor = CompositorOpenGL{nullptr, engine(), kMockResolver}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; @@ -127,7 +127,7 @@ TEST_F(CompositorOpenGLTest, CreateBackingStore) { TEST_F(CompositorOpenGLTest, InitializationFailure) { UseHeadlessEngine(); - auto compositor = CompositorOpenGL{engine(), kMockResolver}; + auto compositor = CompositorOpenGL{nullptr, engine(), kMockResolver}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; @@ -140,7 +140,7 @@ TEST_F(CompositorOpenGLTest, InitializationFailure) { TEST_F(CompositorOpenGLTest, Present) { UseEngineWithView(); - auto compositor = CompositorOpenGL{engine(), kMockResolver}; + auto compositor = CompositorOpenGL{nullptr, engine(), kMockResolver}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; @@ -164,7 +164,7 @@ TEST_F(CompositorOpenGLTest, Present) { TEST_F(CompositorOpenGLTest, PresentEmpty) { UseEngineWithView(); - auto compositor = CompositorOpenGL{engine(), kMockResolver}; + auto compositor = CompositorOpenGL{nullptr, engine(), kMockResolver}; // The context will be bound twice: first to initialize the compositor, second // to clear the surface. @@ -177,7 +177,7 @@ TEST_F(CompositorOpenGLTest, PresentEmpty) { TEST_F(CompositorOpenGLTest, HeadlessPresentIgnored) { UseHeadlessEngine(); - auto compositor = CompositorOpenGL{engine(), kMockResolver}; + auto compositor = CompositorOpenGL{nullptr, engine(), kMockResolver}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; @@ -199,7 +199,7 @@ TEST_F(CompositorOpenGLTest, HeadlessPresentIgnored) { TEST_F(CompositorOpenGLTest, NoSurfaceIgnored) { UseEngineWithView(/*add_surface = */ false); - auto compositor = CompositorOpenGL{engine(), kMockResolver}; + auto compositor = CompositorOpenGL{nullptr, engine(), kMockResolver}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; diff --git a/shell/platform/windows/compositor_software.cc b/shell/platform/windows/compositor_software.cc index 6f6353cbe269c..30da2a640fc23 100644 --- a/shell/platform/windows/compositor_software.cc +++ b/shell/platform/windows/compositor_software.cc @@ -8,8 +8,9 @@ namespace flutter { -CompositorSoftware::CompositorSoftware(FlutterWindowsEngine* engine) - : engine_(engine) {} +CompositorSoftware::CompositorSoftware(std::unique_ptr manager, + FlutterWindowsEngine* engine) + : Compositor(std::move(manager)), engine_(engine) {} bool CompositorSoftware::CreateBackingStore( const FlutterBackingStoreConfig& config, diff --git a/shell/platform/windows/compositor_software.h b/shell/platform/windows/compositor_software.h index c4e39111b3c1f..ae33242f636db 100644 --- a/shell/platform/windows/compositor_software.h +++ b/shell/platform/windows/compositor_software.h @@ -15,7 +15,8 @@ namespace flutter { // rasterization and bitmaps. class CompositorSoftware : public Compositor { public: - CompositorSoftware(FlutterWindowsEngine* engine); + CompositorSoftware(std::unique_ptr manager, + FlutterWindowsEngine* engine); /// |Compositor| bool CreateBackingStore(const FlutterBackingStoreConfig& config, diff --git a/shell/platform/windows/compositor_software_unittests.cc b/shell/platform/windows/compositor_software_unittests.cc index bef9fca3061b7..bb7b30889d637 100644 --- a/shell/platform/windows/compositor_software_unittests.cc +++ b/shell/platform/windows/compositor_software_unittests.cc @@ -76,7 +76,7 @@ class CompositorSoftwareTest : public WindowsTest { TEST_F(CompositorSoftwareTest, CreateBackingStore) { UseHeadlessEngine(); - auto compositor = CompositorSoftware{engine()}; + auto compositor = CompositorSoftware{nullptr, engine()}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; @@ -88,7 +88,7 @@ TEST_F(CompositorSoftwareTest, CreateBackingStore) { TEST_F(CompositorSoftwareTest, Present) { UseEngineWithView(); - auto compositor = CompositorSoftware{engine()}; + auto compositor = CompositorSoftware{nullptr, engine()}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; @@ -109,7 +109,7 @@ TEST_F(CompositorSoftwareTest, Present) { TEST_F(CompositorSoftwareTest, PresentEmpty) { UseEngineWithView(); - auto compositor = CompositorSoftware{engine()}; + auto compositor = CompositorSoftware{nullptr, engine()}; EXPECT_CALL(*view(), ClearSoftwareBitmap).WillOnce(Return(true)); EXPECT_TRUE(compositor.Present(nullptr, 0)); @@ -118,7 +118,7 @@ TEST_F(CompositorSoftwareTest, PresentEmpty) { TEST_F(CompositorSoftwareTest, HeadlessPresentIgnored) { UseHeadlessEngine(); - auto compositor = CompositorSoftware{engine()}; + auto compositor = CompositorSoftware{nullptr, engine()}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc index a5766c16577cd..b0d8875b89d92 100644 --- a/shell/platform/windows/flutter_windows_engine.cc +++ b/shell/platform/windows/flutter_windows_engine.cc @@ -380,14 +380,15 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) { args.custom_task_runners = &custom_task_runners; + auto platform_view_manager = std::make_unique(task_runner_.get(), messenger_wrapper_.get()); if (egl_manager_) { auto resolver = [](const char* name) -> void* { return reinterpret_cast(::eglGetProcAddress(name)); }; - compositor_ = std::make_unique(this, resolver); + compositor_ = std::make_unique(std::move(platform_view_manager), this, resolver); } else { - compositor_ = std::make_unique(this); + compositor_ = std::make_unique(std::move(platform_view_manager), this); } FlutterCompositor compositor = {}; From 200f13a8ba3809ea5adaa865d16a35f114764cf1 Mon Sep 17 00:00:00 2001 From: schectman Date: Thu, 8 Feb 2024 17:56:08 -0500 Subject: [PATCH 05/27] Set up for mocking --- shell/platform/windows/BUILD.gn | 1 + shell/platform/windows/compositor.h | 6 ++--- shell/platform/windows/compositor_opengl.cc | 4 ++-- shell/platform/windows/compositor_opengl.h | 2 +- shell/platform/windows/compositor_software.cc | 4 ++-- shell/platform/windows/compositor_software.h | 2 +- .../windows/flutter_windows_engine.cc | 8 ++++--- .../platform/windows/flutter_windows_engine.h | 4 ++++ .../platform/windows/platform_view_manager.h | 2 +- .../windows/testing/engine_modifier.h | 4 ++++ .../testing/mock_platform_view_manager.h | 24 +++++++++++++++++++ 11 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 shell/platform/windows/testing/mock_platform_view_manager.h diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index f8dad4bb1f777..b6953b393c29d 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -222,6 +222,7 @@ executable("flutter_windows_unittests") { "testing/flutter_windows_engine_builder.cc", "testing/flutter_windows_engine_builder.h", "testing/mock_direct_manipulation.h", + "testing/mock_platform_view_manager.h", "testing/mock_text_input_manager.cc", "testing/mock_text_input_manager.h", "testing/mock_window.cc", diff --git a/shell/platform/windows/compositor.h b/shell/platform/windows/compositor.h index e94e08f4a6c3d..7ecd7dc78e4b2 100644 --- a/shell/platform/windows/compositor.h +++ b/shell/platform/windows/compositor.h @@ -7,8 +7,6 @@ #include "flutter/shell/platform/embedder/embedder.h" -#include - #include "flutter/shell/platform/windows/platform_view_manager.h" namespace flutter { @@ -23,7 +21,7 @@ namespace flutter { // Platform views are not yet supported. class Compositor { public: - Compositor(std::unique_ptr manager) : platform_view_manager_(std::move(manager)) {} + Compositor(PlatformViewManager* manager) : platform_view_manager_(manager) {} virtual ~Compositor() = default; // Creates a backing store used for rendering Flutter content. @@ -39,7 +37,7 @@ class Compositor { virtual bool Present(const FlutterLayer** layers, size_t layers_count) = 0; protected: - std::unique_ptr platform_view_manager_; + PlatformViewManager* platform_view_manager_; }; } // namespace flutter diff --git a/shell/platform/windows/compositor_opengl.cc b/shell/platform/windows/compositor_opengl.cc index 5c3d6b0c85add..d21df04062115 100644 --- a/shell/platform/windows/compositor_opengl.cc +++ b/shell/platform/windows/compositor_opengl.cc @@ -34,10 +34,10 @@ int GetSupportedTextureFormat(const impeller::DescriptionGLES* description) { } // namespace -CompositorOpenGL::CompositorOpenGL(std::unique_ptr manager, +CompositorOpenGL::CompositorOpenGL(PlatformViewManager* manager, FlutterWindowsEngine* engine, impeller::ProcTableGLES::Resolver resolver) - : Compositor(std::move(manager)), engine_(engine), resolver_(resolver) {} + : Compositor(manager), engine_(engine), resolver_(resolver) {} bool CompositorOpenGL::CreateBackingStore( const FlutterBackingStoreConfig& config, diff --git a/shell/platform/windows/compositor_opengl.h b/shell/platform/windows/compositor_opengl.h index 4c936c6e7d9d2..f956199b47811 100644 --- a/shell/platform/windows/compositor_opengl.h +++ b/shell/platform/windows/compositor_opengl.h @@ -17,7 +17,7 @@ namespace flutter { // Enables the Flutter engine to render content on Windows using OpenGL. class CompositorOpenGL : public Compositor { public: - CompositorOpenGL(std::unique_ptr manager, + CompositorOpenGL(PlatformViewManager* manager, FlutterWindowsEngine* engine, impeller::ProcTableGLES::Resolver resolver); diff --git a/shell/platform/windows/compositor_software.cc b/shell/platform/windows/compositor_software.cc index 30da2a640fc23..e7e0e5655e89d 100644 --- a/shell/platform/windows/compositor_software.cc +++ b/shell/platform/windows/compositor_software.cc @@ -8,9 +8,9 @@ namespace flutter { -CompositorSoftware::CompositorSoftware(std::unique_ptr manager, +CompositorSoftware::CompositorSoftware(PlatformViewManager* manager, FlutterWindowsEngine* engine) - : Compositor(std::move(manager)), engine_(engine) {} + : Compositor(manager), engine_(engine) {} bool CompositorSoftware::CreateBackingStore( const FlutterBackingStoreConfig& config, diff --git a/shell/platform/windows/compositor_software.h b/shell/platform/windows/compositor_software.h index ae33242f636db..49c82a002ffa3 100644 --- a/shell/platform/windows/compositor_software.h +++ b/shell/platform/windows/compositor_software.h @@ -15,7 +15,7 @@ namespace flutter { // rasterization and bitmaps. class CompositorSoftware : public Compositor { public: - CompositorSoftware(std::unique_ptr manager, + CompositorSoftware(PlatformViewManager* manager, FlutterWindowsEngine* engine); /// |Compositor| diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc index b0d8875b89d92..784e220ea31aa 100644 --- a/shell/platform/windows/flutter_windows_engine.cc +++ b/shell/platform/windows/flutter_windows_engine.cc @@ -380,15 +380,17 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) { args.custom_task_runners = &custom_task_runners; - auto platform_view_manager = std::make_unique(task_runner_.get(), messenger_wrapper_.get()); + if (!platform_view_manager_) { + platform_view_manager_ = std::make_unique(task_runner_.get(), messenger_wrapper_.get()); + } if (egl_manager_) { auto resolver = [](const char* name) -> void* { return reinterpret_cast(::eglGetProcAddress(name)); }; - compositor_ = std::make_unique(std::move(platform_view_manager), this, resolver); + compositor_ = std::make_unique(platform_view_manager_.get(), this, resolver); } else { - compositor_ = std::make_unique(std::move(platform_view_manager), this); + compositor_ = std::make_unique(platform_view_manager_.get(), this); } FlutterCompositor compositor = {}; diff --git a/shell/platform/windows/flutter_windows_engine.h b/shell/platform/windows/flutter_windows_engine.h index 3914978f9fc1d..d564c1e4a102c 100644 --- a/shell/platform/windows/flutter_windows_engine.h +++ b/shell/platform/windows/flutter_windows_engine.h @@ -137,6 +137,8 @@ class FlutterWindowsEngine { TaskRunner* task_runner() { return task_runner_.get(); } + BinaryMessenger* messenger_wrapper() { return messenger_wrapper_.get(); } + FlutterWindowsTextureRegistrar* texture_registrar() { return texture_registrar_.get(); } @@ -427,6 +429,8 @@ class FlutterWindowsEngine { std::shared_ptr gl_; + std::unique_ptr platform_view_manager_; + FML_DISALLOW_COPY_AND_ASSIGN(FlutterWindowsEngine); }; diff --git a/shell/platform/windows/platform_view_manager.h b/shell/platform/windows/platform_view_manager.h index 60d9d870a73f8..e0339fbbcc83e 100644 --- a/shell/platform/windows/platform_view_manager.h +++ b/shell/platform/windows/platform_view_manager.h @@ -26,7 +26,7 @@ class PlatformViewManager { public: PlatformViewManager(TaskRunner* task_runner, BinaryMessenger* binary_messenger); - void QueuePlatformViewCreation(std::string_view type_name, int64_t id); + virtual void QueuePlatformViewCreation(std::string_view type_name, int64_t id); void InstantiatePlatformView(int64_t id); diff --git a/shell/platform/windows/testing/engine_modifier.h b/shell/platform/windows/testing/engine_modifier.h index e9fd3b8833ec6..2e61ef78e53fe 100644 --- a/shell/platform/windows/testing/engine_modifier.h +++ b/shell/platform/windows/testing/engine_modifier.h @@ -68,6 +68,10 @@ class EngineModifier { engine_->lifecycle_manager_ = std::move(handler); } + void SetPlatformViewManager(std::unique_ptr&& manager) { + engine_->platform_view_manager_ = std::move(manager); + } + private: FlutterWindowsEngine* engine_; diff --git a/shell/platform/windows/testing/mock_platform_view_manager.h b/shell/platform/windows/testing/mock_platform_view_manager.h new file mode 100644 index 0000000000000..1bfab46b4f217 --- /dev/null +++ b/shell/platform/windows/testing/mock_platform_view_manager.h @@ -0,0 +1,24 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_PLATFORM_VIEW_MANAGER_H_ +#define FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_PLATFORM_VIEW_MANAGER_H_ + +#include "flutter/shell/platform/windows/platform_view_manager.h" + +#include "flutter/shell/platform/windows/flutter_windows_engine.h" +#include "gmock/gmock.h" + +namespace flutter { + +class MockPlatformViewManager : public PlatformViewManager { + public: + MockPlatformViewManager(FlutterWindowsEngine* engine) : PlatformViewManager(engine->task_runner(), engine->messenger_wrapper()) {} + + MOCK_METHOD(void, QueuePlatformViewCreation, (std::string_view, const FlutterPlatformViewTypeEntry&)); +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_PLATFORM_VIEW_MANAGER_H_ From ed90810145922d6fecb917ed8bba1383da83d1ea Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 13 Feb 2024 11:25:16 -0500 Subject: [PATCH 06/27] Add unit test --- shell/platform/windows/fixtures/main.dart | 22 ++++++++++++++++- .../flutter_windows_engine_unittests.cc | 24 +++++++++++++++++++ .../platform/windows/platform_view_manager.cc | 12 ++++++++-- .../platform/windows/platform_view_manager.h | 2 ++ .../testing/mock_platform_view_manager.h | 4 +++- 5 files changed, 60 insertions(+), 4 deletions(-) diff --git a/shell/platform/windows/fixtures/main.dart b/shell/platform/windows/fixtures/main.dart index 3e1c25eb6da0e..7e6d750af5fe3 100644 --- a/shell/platform/windows/fixtures/main.dart +++ b/shell/platform/windows/fixtures/main.dart @@ -4,7 +4,7 @@ import 'dart:async'; import 'dart:io' as io; -import 'dart:typed_data' show ByteData, Uint8List; +import 'dart:typed_data' show ByteData, Endian, Uint8List; import 'dart:ui' as ui; import 'dart:convert'; @@ -159,6 +159,26 @@ void enableLifecycleToFrom() async { }); } +@pragma('vm:entry-point') +void sendCreationMethod() async { + final List data = [ + // Method name + 7, 'create'.length, ...utf8.encode('create'), + // Method arguments: {'type': 'type':, 'id': 0} + 13, 2, + 7, 'type'.length, ...utf8.encode('type'), + 7, 'type'.length, ...utf8.encode('type'), + 7, 'id'.length, ...utf8.encode('id'), + 3, 0, 0, 0, 0, + ]; + + final Completer completed = Completer(); + final ByteData bytes = ByteData.sublistView(Uint8List.fromList(data)); + ui.PlatformDispatcher.instance.sendPlatformMessage('flutter/platform_views', bytes, (ByteData? response) { + completed.complete(response); + }); +} + @pragma('vm:entry-point') void customEntrypoint() {} diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index e44a5592dc1be..8403b42121833 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -12,6 +12,7 @@ #include "flutter/shell/platform/windows/testing/egl/mock_manager.h" #include "flutter/shell/platform/windows/testing/engine_modifier.h" #include "flutter/shell/platform/windows/testing/flutter_windows_engine_builder.h" +#include "flutter/shell/platform/windows/testing/mock_platform_view_manager.h" #include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h" #include "flutter/shell/platform/windows/testing/mock_windows_proc_table.h" #include "flutter/shell/platform/windows/testing/test_keyboard.h" @@ -1169,5 +1170,28 @@ TEST_F(FlutterWindowsEngineTest, ChannelListenedTo) { } } +TEST_F(FlutterWindowsEngineTest, ReceivePlatformViewMessage) { + FlutterWindowsEngineBuilder builder{GetContext()}; + builder.SetDartEntrypoint("sendCreationMethod"); + auto engine = builder.Build(); + + EngineModifier modifier(engine.get()); + modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; }; + + bool received_call = false; + + auto manager = std::make_unique(engine.get()); + EXPECT_CALL(*manager, QueuePlatformViewCreation).WillRepeatedly([&](std::string_view type_name, int64_t id){ + received_call = true; + }); + modifier.SetPlatformViewManager(std::move(manager)); + + engine->Run(); + + while (!received_call) { + engine->task_runner()->ProcessTasks(); + } +} + } // namespace testing } // namespace flutter diff --git a/shell/platform/windows/platform_view_manager.cc b/shell/platform/windows/platform_view_manager.cc index 92081210d26d1..9333676515b87 100644 --- a/shell/platform/windows/platform_view_manager.cc +++ b/shell/platform/windows/platform_view_manager.cc @@ -9,15 +9,23 @@ namespace flutter { namespace { -constexpr char kChannelName[] = ""; +constexpr char kChannelName[] = "flutter/platform_views"; } PlatformViewManager::PlatformViewManager(TaskRunner* task_runner, BinaryMessenger* binary_messenger) : task_runner_(task_runner), channel_(std::make_unique>(binary_messenger, kChannelName, &StandardMethodCodec::GetInstance())) { - channel_->SetMethodCallHandler([](const MethodCall& call, std::unique_ptr> result){ + channel_->SetMethodCallHandler([this](const MethodCall& call, std::unique_ptr> result){ + const auto& args = std::get(*call.arguments()); + if (call.method_name() == "create") { + const auto& type = std::get(args.find(EncodableValue("type"))->second); + const auto& id = std::get(args.find(EncodableValue("id"))->second); + QueuePlatformViewCreation(type, id); + } result->Success(); }); } +PlatformViewManager::~PlatformViewManager() {} + void PlatformViewManager::QueuePlatformViewCreation(std::string_view type_name, int64_t id) {} void PlatformViewManager::InstantiatePlatformView(int64_t id) {} diff --git a/shell/platform/windows/platform_view_manager.h b/shell/platform/windows/platform_view_manager.h index e0339fbbcc83e..802518ca9fc9f 100644 --- a/shell/platform/windows/platform_view_manager.h +++ b/shell/platform/windows/platform_view_manager.h @@ -26,6 +26,8 @@ class PlatformViewManager { public: PlatformViewManager(TaskRunner* task_runner, BinaryMessenger* binary_messenger); + virtual ~PlatformViewManager(); + virtual void QueuePlatformViewCreation(std::string_view type_name, int64_t id); void InstantiatePlatformView(int64_t id); diff --git a/shell/platform/windows/testing/mock_platform_view_manager.h b/shell/platform/windows/testing/mock_platform_view_manager.h index 1bfab46b4f217..a1eec36a19193 100644 --- a/shell/platform/windows/testing/mock_platform_view_manager.h +++ b/shell/platform/windows/testing/mock_platform_view_manager.h @@ -16,7 +16,9 @@ class MockPlatformViewManager : public PlatformViewManager { public: MockPlatformViewManager(FlutterWindowsEngine* engine) : PlatformViewManager(engine->task_runner(), engine->messenger_wrapper()) {} - MOCK_METHOD(void, QueuePlatformViewCreation, (std::string_view, const FlutterPlatformViewTypeEntry&)); + ~MockPlatformViewManager() {} + + MOCK_METHOD(void, QueuePlatformViewCreation, (std::string_view, int64_t id)); }; } // namespace flutter From 5d410ff79517c0b6f84c9802cb333dc47c607457 Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 13 Feb 2024 11:58:17 -0500 Subject: [PATCH 07/27] Formatting --- .../testing/stub_flutter_windows_api.h | 3 +- .../windows/flutter_windows_engine.cc | 9 ++-- .../flutter_windows_engine_unittests.cc | 7 +-- .../platform/windows/platform_view_manager.cc | 44 +++++++++++++------ .../platform/windows/platform_view_manager.h | 20 +++++---- .../platform/windows/public/flutter_windows.h | 15 ++++--- .../testing/mock_platform_view_manager.h | 4 +- 7 files changed, 64 insertions(+), 38 deletions(-) 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 c9b44199f4053..548d0ee93e61c 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 @@ -74,7 +74,8 @@ class StubFlutterWindowsApi { // Called for FlutterDesktopEngineRegisterPlatformViewType. virtual void EngineRegisterPlatformViewType( - const char* view_type_name, FlutterPlatformViewTypeEntry view_type) {} + const char* view_type_name, + FlutterPlatformViewTypeEntry view_type) {} // Called for FlutterDesktopViewGetHWND. virtual HWND ViewGetHWND() { return reinterpret_cast(1); } diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc index 784e220ea31aa..c46372cb00c2e 100644 --- a/shell/platform/windows/flutter_windows_engine.cc +++ b/shell/platform/windows/flutter_windows_engine.cc @@ -381,16 +381,19 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) { args.custom_task_runners = &custom_task_runners; if (!platform_view_manager_) { - platform_view_manager_ = std::make_unique(task_runner_.get(), messenger_wrapper_.get()); + platform_view_manager_ = std::make_unique( + task_runner_.get(), messenger_wrapper_.get()); } if (egl_manager_) { auto resolver = [](const char* name) -> void* { return reinterpret_cast(::eglGetProcAddress(name)); }; - compositor_ = std::make_unique(platform_view_manager_.get(), this, resolver); + compositor_ = std::make_unique( + platform_view_manager_.get(), this, resolver); } else { - compositor_ = std::make_unique(platform_view_manager_.get(), this); + compositor_ = std::make_unique( + platform_view_manager_.get(), this); } FlutterCompositor compositor = {}; diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index 8403b42121833..7f2b2aa5bfcd7 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -1181,9 +1181,10 @@ TEST_F(FlutterWindowsEngineTest, ReceivePlatformViewMessage) { bool received_call = false; auto manager = std::make_unique(engine.get()); - EXPECT_CALL(*manager, QueuePlatformViewCreation).WillRepeatedly([&](std::string_view type_name, int64_t id){ - received_call = true; - }); + EXPECT_CALL(*manager, QueuePlatformViewCreation) + .WillRepeatedly([&](std::string_view type_name, int64_t id) { + received_call = true; + }); modifier.SetPlatformViewManager(std::move(manager)); engine->Run(); diff --git a/shell/platform/windows/platform_view_manager.cc b/shell/platform/windows/platform_view_manager.cc index 9333676515b87..de2d7012af03f 100644 --- a/shell/platform/windows/platform_view_manager.cc +++ b/shell/platform/windows/platform_view_manager.cc @@ -12,29 +12,45 @@ namespace { constexpr char kChannelName[] = "flutter/platform_views"; } -PlatformViewManager::PlatformViewManager(TaskRunner* task_runner, BinaryMessenger* binary_messenger) : task_runner_(task_runner), channel_(std::make_unique>(binary_messenger, kChannelName, &StandardMethodCodec::GetInstance())) { - channel_->SetMethodCallHandler([this](const MethodCall& call, std::unique_ptr> result){ - const auto& args = std::get(*call.arguments()); - if (call.method_name() == "create") { - const auto& type = std::get(args.find(EncodableValue("type"))->second); - const auto& id = std::get(args.find(EncodableValue("id"))->second); - QueuePlatformViewCreation(type, id); - } - result->Success(); - }); +PlatformViewManager::PlatformViewManager(TaskRunner* task_runner, + BinaryMessenger* binary_messenger) + : task_runner_(task_runner), + channel_(std::make_unique>( + binary_messenger, + kChannelName, + &StandardMethodCodec::GetInstance())) { + channel_->SetMethodCallHandler( + [this](const MethodCall& call, + std::unique_ptr> result) { + const auto& args = std::get(*call.arguments()); + if (call.method_name() == "create") { + const auto& type = + std::get(args.find(EncodableValue("type"))->second); + const auto& id = + std::get(args.find(EncodableValue("id"))->second); + QueuePlatformViewCreation(type, id); + } + result->Success(); + }); } PlatformViewManager::~PlatformViewManager() {} -void PlatformViewManager::QueuePlatformViewCreation(std::string_view type_name, int64_t id) {} +void PlatformViewManager::QueuePlatformViewCreation(std::string_view type_name, + int64_t id) {} void PlatformViewManager::InstantiatePlatformView(int64_t id) {} -void PlatformViewManager::RegisterPlatformViewType(std::string_view type_name, const FlutterPlatformViewTypeEntry& type) {} +void PlatformViewManager::RegisterPlatformViewType( + std::string_view type_name, + const FlutterPlatformViewTypeEntry& type) {} -void PlatformViewManager::FocusPlatformView(int64_t id, FocusChangeDirection direction, bool focus) {} +void PlatformViewManager::FocusPlatformView(int64_t id, + FocusChangeDirection direction, + bool focus) {} -std::optional PlatformViewManager::GetNativeHandleForId(int64_t id) const { +std::optional PlatformViewManager::GetNativeHandleForId( + int64_t id) const { return std::nullopt; } diff --git a/shell/platform/windows/platform_view_manager.h b/shell/platform/windows/platform_view_manager.h index 802518ca9fc9f..9afd791683de3 100644 --- a/shell/platform/windows/platform_view_manager.h +++ b/shell/platform/windows/platform_view_manager.h @@ -16,27 +16,29 @@ namespace flutter { -enum class FocusChangeDirection { - kProgrammatic, - kForward, - kBackward -}; +enum class FocusChangeDirection { kProgrammatic, kForward, kBackward }; class PlatformViewManager { public: - PlatformViewManager(TaskRunner* task_runner, BinaryMessenger* binary_messenger); + PlatformViewManager(TaskRunner* task_runner, + BinaryMessenger* binary_messenger); virtual ~PlatformViewManager(); - virtual void QueuePlatformViewCreation(std::string_view type_name, int64_t id); + virtual void QueuePlatformViewCreation(std::string_view type_name, + int64_t id); void InstantiatePlatformView(int64_t id); - void RegisterPlatformViewType(std::string_view type_name, const FlutterPlatformViewTypeEntry& type); + void RegisterPlatformViewType(std::string_view type_name, + const FlutterPlatformViewTypeEntry& type); - void FocusPlatformView(int64_t id, FocusChangeDirection direction, bool focus); + void FocusPlatformView(int64_t id, + FocusChangeDirection direction, + bool focus); std::optional GetNativeHandleForId(int64_t id) const; + private: std::unique_ptr> channel_; diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index 4d92d07d7f793..ce8cb6e026a18 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -104,8 +104,8 @@ FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine( FlutterDesktopViewControllerRef controller); // Returns the view managed by the given controller. -FLUTTER_EXPORT FlutterDesktopViewRef -FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef controller); +FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopViewControllerGetView( + FlutterDesktopViewControllerRef controller); // Requests new frame from the engine and repaints the view. FLUTTER_EXPORT void FlutterDesktopViewControllerForceRedraw( @@ -167,8 +167,8 @@ FLUTTER_EXPORT bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, // This should be called on every run of the application-level runloop, and // a wait for native events in the runloop should never be longer than the // last return value from this function. -FLUTTER_EXPORT uint64_t -FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine); +FLUTTER_EXPORT uint64_t FlutterDesktopEngineProcessMessages( + FlutterDesktopEngineRef engine); FLUTTER_EXPORT void FlutterDesktopEngineReloadSystemFonts( FlutterDesktopEngineRef engine); @@ -187,8 +187,8 @@ FlutterDesktopEngineGetPluginRegistrar(FlutterDesktopEngineRef engine, // // Callers should use |FlutterDesktopMessengerAddRef| if the returned pointer // will potentially outlive 'engine', such as when passing it to another thread. -FLUTTER_EXPORT FlutterDesktopMessengerRef -FlutterDesktopEngineGetMessenger(FlutterDesktopEngineRef engine); +FLUTTER_EXPORT FlutterDesktopMessengerRef FlutterDesktopEngineGetMessenger( + FlutterDesktopEngineRef engine); // Returns the texture registrar associated with the engine. FLUTTER_EXPORT FlutterDesktopTextureRegistrarRef @@ -211,7 +211,8 @@ typedef struct { int64_t platform_view_id; } FlutterPlatformViewCreationParameters; -typedef HWND (*FlutterPlatformViewFactory)(const FlutterPlatformViewCreationParameters*); +typedef HWND (*FlutterPlatformViewFactory)( + const FlutterPlatformViewCreationParameters*); typedef struct { size_t cb_size; diff --git a/shell/platform/windows/testing/mock_platform_view_manager.h b/shell/platform/windows/testing/mock_platform_view_manager.h index a1eec36a19193..2ada72c7d8268 100644 --- a/shell/platform/windows/testing/mock_platform_view_manager.h +++ b/shell/platform/windows/testing/mock_platform_view_manager.h @@ -14,7 +14,9 @@ namespace flutter { class MockPlatformViewManager : public PlatformViewManager { public: - MockPlatformViewManager(FlutterWindowsEngine* engine) : PlatformViewManager(engine->task_runner(), engine->messenger_wrapper()) {} + MockPlatformViewManager(FlutterWindowsEngine* engine) + : PlatformViewManager(engine->task_runner(), + engine->messenger_wrapper()) {} ~MockPlatformViewManager() {} From 484c8c1d80cad36ee73c275c8fc69cbb39d19fcc Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 13 Feb 2024 13:45:14 -0500 Subject: [PATCH 08/27] License fix, await future --- ci/licenses_golden/licenses_flutter | 4 ++++ shell/platform/windows/fixtures/main.dart | 1 + 2 files changed, 5 insertions(+) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 26dfb762b3930..34b0f49b05ddd 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -7290,6 +7290,8 @@ ORIGIN: ../../../flutter/shell/platform/windows/keyboard_utils.cc + ../../../flu ORIGIN: ../../../flutter/shell/platform/windows/keyboard_utils.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/platform_handler.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/platform_handler.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/windows/platform_view_manager.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/windows/platform_view_manager.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/public/flutter_windows.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/sequential_id_generator.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/sequential_id_generator.h + ../../../flutter/LICENSE @@ -10177,6 +10179,8 @@ FILE: ../../../flutter/shell/platform/windows/keyboard_utils.cc FILE: ../../../flutter/shell/platform/windows/keyboard_utils.h FILE: ../../../flutter/shell/platform/windows/platform_handler.cc FILE: ../../../flutter/shell/platform/windows/platform_handler.h +FILE: ../../../flutter/shell/platform/windows/platform_view_manager.cc +FILE: ../../../flutter/shell/platform/windows/platform_view_manager.h FILE: ../../../flutter/shell/platform/windows/public/flutter_windows.h FILE: ../../../flutter/shell/platform/windows/sequential_id_generator.cc FILE: ../../../flutter/shell/platform/windows/sequential_id_generator.h diff --git a/shell/platform/windows/fixtures/main.dart b/shell/platform/windows/fixtures/main.dart index 7e6d750af5fe3..3eba41cc634b6 100644 --- a/shell/platform/windows/fixtures/main.dart +++ b/shell/platform/windows/fixtures/main.dart @@ -177,6 +177,7 @@ void sendCreationMethod() async { ui.PlatformDispatcher.instance.sendPlatformMessage('flutter/platform_views', bytes, (ByteData? response) { completed.complete(response); }); + await completed.future; } @pragma('vm:entry-point') From b8fadd7e9a440c38b8cb392a50ab79a725c4cd35 Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 13 Feb 2024 17:09:16 -0500 Subject: [PATCH 09/27] PR Feedback --- shell/platform/windows/compositor.h | 1 + shell/platform/windows/fixtures/main.dart | 3 ++ .../platform/windows/platform_view_manager.cc | 8 ++--- .../platform/windows/platform_view_manager.h | 36 ++++++++++++++----- .../platform/windows/public/flutter_windows.h | 12 ++++--- 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/shell/platform/windows/compositor.h b/shell/platform/windows/compositor.h index 7ecd7dc78e4b2..dcf8f327951a9 100644 --- a/shell/platform/windows/compositor.h +++ b/shell/platform/windows/compositor.h @@ -37,6 +37,7 @@ class Compositor { virtual bool Present(const FlutterLayer** layers, size_t layers_count) = 0; protected: + // Pointer to the platform view manager owned by the engine. PlatformViewManager* platform_view_manager_; }; diff --git a/shell/platform/windows/fixtures/main.dart b/shell/platform/windows/fixtures/main.dart index 3eba41cc634b6..d9eb23b3b9a4f 100644 --- a/shell/platform/windows/fixtures/main.dart +++ b/shell/platform/windows/fixtures/main.dart @@ -161,6 +161,9 @@ void enableLifecycleToFrom() async { @pragma('vm:entry-point') void sendCreationMethod() async { + // The platform view method channel uses the standard method codec. + // See https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/services/message_codecs.dart#L262 + // for the implementation of the encoding and magic number identifiers. final List data = [ // Method name 7, 'create'.length, ...utf8.encode('create'), diff --git a/shell/platform/windows/platform_view_manager.cc b/shell/platform/windows/platform_view_manager.cc index de2d7012af03f..9892f1bd00cd9 100644 --- a/shell/platform/windows/platform_view_manager.cc +++ b/shell/platform/windows/platform_view_manager.cc @@ -37,20 +37,20 @@ PlatformViewManager::PlatformViewManager(TaskRunner* task_runner, PlatformViewManager::~PlatformViewManager() {} void PlatformViewManager::QueuePlatformViewCreation(std::string_view type_name, - int64_t id) {} + PlatformViewId id) {} -void PlatformViewManager::InstantiatePlatformView(int64_t id) {} +void PlatformViewManager::InstantiatePlatformView(PlatformViewId id) {} void PlatformViewManager::RegisterPlatformViewType( std::string_view type_name, const FlutterPlatformViewTypeEntry& type) {} -void PlatformViewManager::FocusPlatformView(int64_t id, +void PlatformViewManager::FocusPlatformView(PlatformViewId id, FocusChangeDirection direction, bool focus) {} std::optional PlatformViewManager::GetNativeHandleForId( - int64_t id) const { + PlatformViewId id) const { return std::nullopt; } diff --git a/shell/platform/windows/platform_view_manager.h b/shell/platform/windows/platform_view_manager.h index 9afd791683de3..532833c40bb67 100644 --- a/shell/platform/windows/platform_view_manager.h +++ b/shell/platform/windows/platform_view_manager.h @@ -16,8 +16,16 @@ namespace flutter { -enum class FocusChangeDirection { kProgrammatic, kForward, kBackward }; +// Possible reasons for change of keyboard foucs. +enum class FocusChangeDirection { + kProgrammatic, // Un-directed focus change. + kForward, // Keyboard focus moves forwards, e.g. TAB-key. + kBackward // Keyboard focus moves backwards, e.g. Shift+TAB. +}; +// Keeps track of registered platform view types and platform view instances, +// and is responsible for processing and responding to platform view related +// method invokations from the framework. class PlatformViewManager { public: PlatformViewManager(TaskRunner* task_runner, @@ -25,29 +33,41 @@ class PlatformViewManager { virtual ~PlatformViewManager(); + // Add a new platform view instance to be lazily instantiated when it is next + // composited. virtual void QueuePlatformViewCreation(std::string_view type_name, - int64_t id); + PlatformViewId id); - void InstantiatePlatformView(int64_t id); + // Create a queued platform view instance. + void InstantiatePlatformView(PlatformViewId id); + // The runner-facing API calls this method to register a window type + // corresponding to a platform view identifier supplied to the widget tree. void RegisterPlatformViewType(std::string_view type_name, const FlutterPlatformViewTypeEntry& type); - void FocusPlatformView(int64_t id, + // The framework may invoke this method when keyboard focus must be given to + // the platform view. + void FocusPlatformView(PlatformViewId id, FocusChangeDirection direction, bool focus); - std::optional GetNativeHandleForId(int64_t id) const; + // Find the HWND corresponding to a platform view id. Returns null if the id + // has no associated platform view. + std::optional GetNativeHandleForId(PlatformViewId id) const; private: std::unique_ptr> channel_; - std::map platform_view_types_; + std::unordered_map + platform_view_types_; - std::map platform_views_; + std::unordered_map platform_views_; - std::map> pending_platform_views_; + std::unordered_map> + pending_platform_views_; + // Pointer to the task runner of the associated engine. TaskRunner* task_runner_; }; diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index ce8cb6e026a18..4819a02d6f757 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -203,21 +203,25 @@ FLUTTER_EXPORT void FlutterDesktopEngineSetNextFrameCallback( VoidCallback callback, void* user_data); +typedef int64_t PlatformViewId; + typedef struct { - size_t cb_size; + size_t struct_size; HWND parent_window; const char* platform_view_type; + // user_data may hold any necessary additional information for creating a new + // platform view. For example, an instance of FlutterWindow. void* user_data; - int64_t platform_view_id; + PlatformViewId platform_view_id; } FlutterPlatformViewCreationParameters; typedef HWND (*FlutterPlatformViewFactory)( const FlutterPlatformViewCreationParameters*); typedef struct { - size_t cb_size; + size_t struct_size; FlutterPlatformViewFactory factory; - void* user_data; + void* user_data; // Arbitrary user data supplied to the cretaion struct. } FlutterPlatformViewTypeEntry; FLUTTER_EXPORT void FlutterDesktopEngineRegisterPlatformViewType( From 1d203f4b8902cf5fc2e242ef00ce60588a2e2318 Mon Sep 17 00:00:00 2001 From: schectman Date: Wed, 14 Feb 2024 13:16:48 -0500 Subject: [PATCH 10/27] _internal header file --- shell/platform/windows/BUILD.gn | 1 + .../windows/flutter_windows_internal.h | 26 +++++++++++++++++++ .../platform/windows/public/flutter_windows.h | 5 ---- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 shell/platform/windows/flutter_windows_internal.h diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index b6953b393c29d..810e720e01259 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -80,6 +80,7 @@ source_set("flutter_windows_source") { "flutter_windows.cc", "flutter_windows_engine.cc", "flutter_windows_engine.h", + "flutter_windows_internal.h", "flutter_windows_texture_registrar.cc", "flutter_windows_texture_registrar.h", "flutter_windows_view.cc", diff --git a/shell/platform/windows/flutter_windows_internal.h b/shell/platform/windows/flutter_windows_internal.h new file mode 100644 index 0000000000000..a0eb5ff533703 --- /dev/null +++ b/shell/platform/windows/flutter_windows_internal.h @@ -0,0 +1,26 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_WINDOWS_INTERNAL_H_ +#define FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_WINDOWS_INTERNAL_H_ + +#include "flutter/shell/platform/windows/public/flutter_windows.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +// Declare functions that are currently in-progress and shall be exposed to the +// public facing API upon completion. + +FLUTTER_EXPORT void FlutterDesktopEngineRegisterPlatformViewType( + FlutterDesktopEngineRef engine, + const char* view_type_name, + FlutterPlatformViewTypeEntry view_type); + +#if defined(__cplusplus) +} +#endif + +#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_WINDOWS_INTERNAL_H_ diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index 4819a02d6f757..47c3262cd18d4 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -224,11 +224,6 @@ typedef struct { void* user_data; // Arbitrary user data supplied to the cretaion struct. } FlutterPlatformViewTypeEntry; -FLUTTER_EXPORT void FlutterDesktopEngineRegisterPlatformViewType( - FlutterDesktopEngineRef engine, - const char* view_type_name, - FlutterPlatformViewTypeEntry view_type); - // ========== View ========== // Return backing HWND for manipulation in host application. From b9acc1aa99394c2d2a37de4d00623cc8054fa2a9 Mon Sep 17 00:00:00 2001 From: schectman Date: Wed, 14 Feb 2024 13:26:14 -0500 Subject: [PATCH 11/27] Wait to add manager to compositors --- shell/platform/windows/compositor.h | 7 ------- shell/platform/windows/compositor_opengl.cc | 5 ++--- shell/platform/windows/compositor_opengl.h | 3 +-- .../platform/windows/compositor_opengl_unittests.cc | 12 ++++++------ shell/platform/windows/compositor_software.cc | 5 ++--- shell/platform/windows/compositor_software.h | 3 +-- .../windows/compositor_software_unittests.cc | 8 ++++---- shell/platform/windows/flutter_windows.cc | 3 ++- shell/platform/windows/flutter_windows_engine.cc | 6 ++++-- shell/platform/windows/flutter_windows_engine.h | 1 + 10 files changed, 23 insertions(+), 30 deletions(-) diff --git a/shell/platform/windows/compositor.h b/shell/platform/windows/compositor.h index dcf8f327951a9..c7691f53e8510 100644 --- a/shell/platform/windows/compositor.h +++ b/shell/platform/windows/compositor.h @@ -7,8 +7,6 @@ #include "flutter/shell/platform/embedder/embedder.h" -#include "flutter/shell/platform/windows/platform_view_manager.h" - namespace flutter { // Enables the Flutter engine to render content on Windows. @@ -21,7 +19,6 @@ namespace flutter { // Platform views are not yet supported. class Compositor { public: - Compositor(PlatformViewManager* manager) : platform_view_manager_(manager) {} virtual ~Compositor() = default; // Creates a backing store used for rendering Flutter content. @@ -35,10 +32,6 @@ class Compositor { // Present Flutter content and platform views onto the view. virtual bool Present(const FlutterLayer** layers, size_t layers_count) = 0; - - protected: - // Pointer to the platform view manager owned by the engine. - PlatformViewManager* platform_view_manager_; }; } // namespace flutter diff --git a/shell/platform/windows/compositor_opengl.cc b/shell/platform/windows/compositor_opengl.cc index d21df04062115..b43f888d65191 100644 --- a/shell/platform/windows/compositor_opengl.cc +++ b/shell/platform/windows/compositor_opengl.cc @@ -34,10 +34,9 @@ int GetSupportedTextureFormat(const impeller::DescriptionGLES* description) { } // namespace -CompositorOpenGL::CompositorOpenGL(PlatformViewManager* manager, - FlutterWindowsEngine* engine, +CompositorOpenGL::CompositorOpenGL(FlutterWindowsEngine* engine, impeller::ProcTableGLES::Resolver resolver) - : Compositor(manager), engine_(engine), resolver_(resolver) {} + : engine_(engine), resolver_(resolver) {} bool CompositorOpenGL::CreateBackingStore( const FlutterBackingStoreConfig& config, diff --git a/shell/platform/windows/compositor_opengl.h b/shell/platform/windows/compositor_opengl.h index f956199b47811..06c22202332e2 100644 --- a/shell/platform/windows/compositor_opengl.h +++ b/shell/platform/windows/compositor_opengl.h @@ -17,8 +17,7 @@ namespace flutter { // Enables the Flutter engine to render content on Windows using OpenGL. class CompositorOpenGL : public Compositor { public: - CompositorOpenGL(PlatformViewManager* manager, - FlutterWindowsEngine* engine, + CompositorOpenGL(FlutterWindowsEngine* engine, impeller::ProcTableGLES::Resolver resolver); /// |Compositor| diff --git a/shell/platform/windows/compositor_opengl_unittests.cc b/shell/platform/windows/compositor_opengl_unittests.cc index 659165e4a2f6a..08fd6dfaf4861 100644 --- a/shell/platform/windows/compositor_opengl_unittests.cc +++ b/shell/platform/windows/compositor_opengl_unittests.cc @@ -113,7 +113,7 @@ class CompositorOpenGLTest : public WindowsTest { TEST_F(CompositorOpenGLTest, CreateBackingStore) { UseHeadlessEngine(); - auto compositor = CompositorOpenGL{nullptr, engine(), kMockResolver}; + auto compositor = CompositorOpenGL{engine(), kMockResolver}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; @@ -127,7 +127,7 @@ TEST_F(CompositorOpenGLTest, CreateBackingStore) { TEST_F(CompositorOpenGLTest, InitializationFailure) { UseHeadlessEngine(); - auto compositor = CompositorOpenGL{nullptr, engine(), kMockResolver}; + auto compositor = CompositorOpenGL{engine(), kMockResolver}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; @@ -140,7 +140,7 @@ TEST_F(CompositorOpenGLTest, InitializationFailure) { TEST_F(CompositorOpenGLTest, Present) { UseEngineWithView(); - auto compositor = CompositorOpenGL{nullptr, engine(), kMockResolver}; + auto compositor = CompositorOpenGL{engine(), kMockResolver}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; @@ -164,7 +164,7 @@ TEST_F(CompositorOpenGLTest, Present) { TEST_F(CompositorOpenGLTest, PresentEmpty) { UseEngineWithView(); - auto compositor = CompositorOpenGL{nullptr, engine(), kMockResolver}; + auto compositor = CompositorOpenGL{engine(), kMockResolver}; // The context will be bound twice: first to initialize the compositor, second // to clear the surface. @@ -177,7 +177,7 @@ TEST_F(CompositorOpenGLTest, PresentEmpty) { TEST_F(CompositorOpenGLTest, HeadlessPresentIgnored) { UseHeadlessEngine(); - auto compositor = CompositorOpenGL{nullptr, engine(), kMockResolver}; + auto compositor = CompositorOpenGL{engine(), kMockResolver}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; @@ -199,7 +199,7 @@ TEST_F(CompositorOpenGLTest, HeadlessPresentIgnored) { TEST_F(CompositorOpenGLTest, NoSurfaceIgnored) { UseEngineWithView(/*add_surface = */ false); - auto compositor = CompositorOpenGL{nullptr, engine(), kMockResolver}; + auto compositor = CompositorOpenGL{engine(), kMockResolver}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; diff --git a/shell/platform/windows/compositor_software.cc b/shell/platform/windows/compositor_software.cc index e7e0e5655e89d..6f6353cbe269c 100644 --- a/shell/platform/windows/compositor_software.cc +++ b/shell/platform/windows/compositor_software.cc @@ -8,9 +8,8 @@ namespace flutter { -CompositorSoftware::CompositorSoftware(PlatformViewManager* manager, - FlutterWindowsEngine* engine) - : Compositor(manager), engine_(engine) {} +CompositorSoftware::CompositorSoftware(FlutterWindowsEngine* engine) + : engine_(engine) {} bool CompositorSoftware::CreateBackingStore( const FlutterBackingStoreConfig& config, diff --git a/shell/platform/windows/compositor_software.h b/shell/platform/windows/compositor_software.h index 49c82a002ffa3..c4e39111b3c1f 100644 --- a/shell/platform/windows/compositor_software.h +++ b/shell/platform/windows/compositor_software.h @@ -15,8 +15,7 @@ namespace flutter { // rasterization and bitmaps. class CompositorSoftware : public Compositor { public: - CompositorSoftware(PlatformViewManager* manager, - FlutterWindowsEngine* engine); + CompositorSoftware(FlutterWindowsEngine* engine); /// |Compositor| bool CreateBackingStore(const FlutterBackingStoreConfig& config, diff --git a/shell/platform/windows/compositor_software_unittests.cc b/shell/platform/windows/compositor_software_unittests.cc index bb7b30889d637..bef9fca3061b7 100644 --- a/shell/platform/windows/compositor_software_unittests.cc +++ b/shell/platform/windows/compositor_software_unittests.cc @@ -76,7 +76,7 @@ class CompositorSoftwareTest : public WindowsTest { TEST_F(CompositorSoftwareTest, CreateBackingStore) { UseHeadlessEngine(); - auto compositor = CompositorSoftware{nullptr, engine()}; + auto compositor = CompositorSoftware{engine()}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; @@ -88,7 +88,7 @@ TEST_F(CompositorSoftwareTest, CreateBackingStore) { TEST_F(CompositorSoftwareTest, Present) { UseEngineWithView(); - auto compositor = CompositorSoftware{nullptr, engine()}; + auto compositor = CompositorSoftware{engine()}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; @@ -109,7 +109,7 @@ TEST_F(CompositorSoftwareTest, Present) { TEST_F(CompositorSoftwareTest, PresentEmpty) { UseEngineWithView(); - auto compositor = CompositorSoftware{nullptr, engine()}; + auto compositor = CompositorSoftware{engine()}; EXPECT_CALL(*view(), ClearSoftwareBitmap).WillOnce(Return(true)); EXPECT_TRUE(compositor.Present(nullptr, 0)); @@ -118,7 +118,7 @@ TEST_F(CompositorSoftwareTest, PresentEmpty) { TEST_F(CompositorSoftwareTest, HeadlessPresentIgnored) { UseHeadlessEngine(); - auto compositor = CompositorSoftware{nullptr, engine()}; + auto compositor = CompositorSoftware{engine()}; FlutterBackingStoreConfig config = {}; FlutterBackingStore backing_store = {}; diff --git a/shell/platform/windows/flutter_windows.cc b/shell/platform/windows/flutter_windows.cc index dc1eeb73d80ec..e06c303701112 100644 --- a/shell/platform/windows/flutter_windows.cc +++ b/shell/platform/windows/flutter_windows.cc @@ -250,7 +250,8 @@ void FlutterDesktopEngineRegisterPlatformViewType( FlutterDesktopEngineRef engine, const char* view_type_name, FlutterPlatformViewTypeEntry view_type) { - // TODO(schectman): forward to platform view manager + // TODO(schectman): forward to platform view manager. + // https://github.com/flutter/flutter/issues/143375 } FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView( diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc index c46372cb00c2e..f86993808a03c 100644 --- a/shell/platform/windows/flutter_windows_engine.cc +++ b/shell/platform/windows/flutter_windows_engine.cc @@ -389,11 +389,13 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) { return reinterpret_cast(::eglGetProcAddress(name)); }; + // TODO(schectman) Pass the platform view manager to the compositor + // constructors: https://github.com/flutter/flutter/issues/143375 compositor_ = std::make_unique( - platform_view_manager_.get(), this, resolver); + this, resolver); } else { compositor_ = std::make_unique( - platform_view_manager_.get(), this); + this); } FlutterCompositor compositor = {}; diff --git a/shell/platform/windows/flutter_windows_engine.h b/shell/platform/windows/flutter_windows_engine.h index d564c1e4a102c..fc2bae6b1a7c8 100644 --- a/shell/platform/windows/flutter_windows_engine.h +++ b/shell/platform/windows/flutter_windows_engine.h @@ -32,6 +32,7 @@ #include "flutter/shell/platform/windows/keyboard_handler_base.h" #include "flutter/shell/platform/windows/keyboard_key_embedder_handler.h" #include "flutter/shell/platform/windows/platform_handler.h" +#include "flutter/shell/platform/windows/platform_view_manager.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" #include "flutter/shell/platform/windows/settings_plugin.h" #include "flutter/shell/platform/windows/task_runner.h" From 35eb6887607a42481ac668dcda8268826188d7e2 Mon Sep 17 00:00:00 2001 From: schectman Date: Wed, 14 Feb 2024 13:26:58 -0500 Subject: [PATCH 12/27] Rename fixture function --- shell/platform/windows/fixtures/main.dart | 2 +- shell/platform/windows/flutter_windows_engine_unittests.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/windows/fixtures/main.dart b/shell/platform/windows/fixtures/main.dart index d9eb23b3b9a4f..f0613bbbcd472 100644 --- a/shell/platform/windows/fixtures/main.dart +++ b/shell/platform/windows/fixtures/main.dart @@ -160,7 +160,7 @@ void enableLifecycleToFrom() async { } @pragma('vm:entry-point') -void sendCreationMethod() async { +void sendCreatePlatformViewMethod() async { // The platform view method channel uses the standard method codec. // See https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/services/message_codecs.dart#L262 // for the implementation of the encoding and magic number identifiers. diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index 7f2b2aa5bfcd7..67cdd7ea73855 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -1172,7 +1172,7 @@ TEST_F(FlutterWindowsEngineTest, ChannelListenedTo) { TEST_F(FlutterWindowsEngineTest, ReceivePlatformViewMessage) { FlutterWindowsEngineBuilder builder{GetContext()}; - builder.SetDartEntrypoint("sendCreationMethod"); + builder.SetDartEntrypoint("sendCreatePlatformViewMethod"); auto engine = builder.Build(); EngineModifier modifier(engine.get()); From 659ebd60a77014aaf7e1cb190f3b61e630959956 Mon Sep 17 00:00:00 2001 From: schectman Date: Wed, 14 Feb 2024 13:28:35 -0500 Subject: [PATCH 13/27] Reorder parameters --- shell/platform/windows/platform_view_manager.cc | 6 +++--- shell/platform/windows/platform_view_manager.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/platform/windows/platform_view_manager.cc b/shell/platform/windows/platform_view_manager.cc index 9892f1bd00cd9..3954daf7ad441 100644 --- a/shell/platform/windows/platform_view_manager.cc +++ b/shell/platform/windows/platform_view_manager.cc @@ -28,7 +28,7 @@ PlatformViewManager::PlatformViewManager(TaskRunner* task_runner, std::get(args.find(EncodableValue("type"))->second); const auto& id = std::get(args.find(EncodableValue("id"))->second); - QueuePlatformViewCreation(type, id); + QueuePlatformViewCreation(id, type); } result->Success(); }); @@ -36,8 +36,8 @@ PlatformViewManager::PlatformViewManager(TaskRunner* task_runner, PlatformViewManager::~PlatformViewManager() {} -void PlatformViewManager::QueuePlatformViewCreation(std::string_view type_name, - PlatformViewId id) {} +void PlatformViewManager::QueuePlatformViewCreation(PlatformViewId id, + std::string_view type_name) {} void PlatformViewManager::InstantiatePlatformView(PlatformViewId id) {} diff --git a/shell/platform/windows/platform_view_manager.h b/shell/platform/windows/platform_view_manager.h index 532833c40bb67..a714cb5931674 100644 --- a/shell/platform/windows/platform_view_manager.h +++ b/shell/platform/windows/platform_view_manager.h @@ -35,8 +35,8 @@ class PlatformViewManager { // Add a new platform view instance to be lazily instantiated when it is next // composited. - virtual void QueuePlatformViewCreation(std::string_view type_name, - PlatformViewId id); + virtual void QueuePlatformViewCreation(PlatformViewId id, + std::string_view type_name); // Create a queued platform view instance. void InstantiatePlatformView(PlatformViewId id); From db2851b8fea9c83b73bc4dc1ea48c594ed50df3d Mon Sep 17 00:00:00 2001 From: schectman Date: Wed, 14 Feb 2024 13:32:29 -0500 Subject: [PATCH 14/27] Use constants --- shell/platform/windows/fixtures/main.dart | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/shell/platform/windows/fixtures/main.dart b/shell/platform/windows/fixtures/main.dart index f0613bbbcd472..bae5b7932cc56 100644 --- a/shell/platform/windows/fixtures/main.dart +++ b/shell/platform/windows/fixtures/main.dart @@ -164,15 +164,18 @@ void sendCreatePlatformViewMethod() async { // The platform view method channel uses the standard method codec. // See https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/services/message_codecs.dart#L262 // for the implementation of the encoding and magic number identifiers. + const int valueString = 7; + const int valueMap = 13; + const int valueInt32 = 3; final List data = [ // Method name - 7, 'create'.length, ...utf8.encode('create'), + valueString, 'create'.length, ...utf8.encode('create'), // Method arguments: {'type': 'type':, 'id': 0} - 13, 2, - 7, 'type'.length, ...utf8.encode('type'), - 7, 'type'.length, ...utf8.encode('type'), - 7, 'id'.length, ...utf8.encode('id'), - 3, 0, 0, 0, 0, + valueMap, 2, + valueString, 'type'.length, ...utf8.encode('type'), + valueString, 'type'.length, ...utf8.encode('type'), + valueString, 'id'.length, ...utf8.encode('id'), + valueInt32, 0, 0, 0, 0, ]; final Completer completed = Completer(); From db48ddde54b2f7fe047468bb5b67add2fe52a004 Mon Sep 17 00:00:00 2001 From: schectman Date: Wed, 14 Feb 2024 13:37:53 -0500 Subject: [PATCH 15/27] Reorder params in test --- shell/platform/windows/flutter_windows_engine_unittests.cc | 2 +- shell/platform/windows/testing/mock_platform_view_manager.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index 67cdd7ea73855..fbb5074fcff3b 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -1182,7 +1182,7 @@ TEST_F(FlutterWindowsEngineTest, ReceivePlatformViewMessage) { auto manager = std::make_unique(engine.get()); EXPECT_CALL(*manager, QueuePlatformViewCreation) - .WillRepeatedly([&](std::string_view type_name, int64_t id) { + .WillRepeatedly([&](PlatformViewId id, std::string_view type_name) { received_call = true; }); modifier.SetPlatformViewManager(std::move(manager)); diff --git a/shell/platform/windows/testing/mock_platform_view_manager.h b/shell/platform/windows/testing/mock_platform_view_manager.h index 2ada72c7d8268..d8774a59a9c78 100644 --- a/shell/platform/windows/testing/mock_platform_view_manager.h +++ b/shell/platform/windows/testing/mock_platform_view_manager.h @@ -20,7 +20,7 @@ class MockPlatformViewManager : public PlatformViewManager { ~MockPlatformViewManager() {} - MOCK_METHOD(void, QueuePlatformViewCreation, (std::string_view, int64_t id)); + MOCK_METHOD(void, QueuePlatformViewCreation, (PlatformViewId id, std::string_view)); }; } // namespace flutter From f87ed964682a36cbf83e3d4d2102f012f300607f Mon Sep 17 00:00:00 2001 From: schectman Date: Wed, 14 Feb 2024 13:39:19 -0500 Subject: [PATCH 16/27] Format --- shell/platform/windows/flutter_windows_engine.cc | 6 ++---- shell/platform/windows/platform_view_manager.cc | 5 +++-- shell/platform/windows/testing/mock_platform_view_manager.h | 4 +++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc index f86993808a03c..8626f0ff237b6 100644 --- a/shell/platform/windows/flutter_windows_engine.cc +++ b/shell/platform/windows/flutter_windows_engine.cc @@ -391,11 +391,9 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) { // TODO(schectman) Pass the platform view manager to the compositor // constructors: https://github.com/flutter/flutter/issues/143375 - compositor_ = std::make_unique( - this, resolver); + compositor_ = std::make_unique(this, resolver); } else { - compositor_ = std::make_unique( - this); + compositor_ = std::make_unique(this); } FlutterCompositor compositor = {}; diff --git a/shell/platform/windows/platform_view_manager.cc b/shell/platform/windows/platform_view_manager.cc index 3954daf7ad441..1526a4d7d7289 100644 --- a/shell/platform/windows/platform_view_manager.cc +++ b/shell/platform/windows/platform_view_manager.cc @@ -36,8 +36,9 @@ PlatformViewManager::PlatformViewManager(TaskRunner* task_runner, PlatformViewManager::~PlatformViewManager() {} -void PlatformViewManager::QueuePlatformViewCreation(PlatformViewId id, - std::string_view type_name) {} +void PlatformViewManager::QueuePlatformViewCreation( + PlatformViewId id, + std::string_view type_name) {} void PlatformViewManager::InstantiatePlatformView(PlatformViewId id) {} diff --git a/shell/platform/windows/testing/mock_platform_view_manager.h b/shell/platform/windows/testing/mock_platform_view_manager.h index d8774a59a9c78..cd6f435620903 100644 --- a/shell/platform/windows/testing/mock_platform_view_manager.h +++ b/shell/platform/windows/testing/mock_platform_view_manager.h @@ -20,7 +20,9 @@ class MockPlatformViewManager : public PlatformViewManager { ~MockPlatformViewManager() {} - MOCK_METHOD(void, QueuePlatformViewCreation, (PlatformViewId id, std::string_view)); + MOCK_METHOD(void, + QueuePlatformViewCreation, + (PlatformViewId id, std::string_view)); }; } // namespace flutter From 42f976e1a7fded9f0d2b1fbc22b524906c7c2b0e Mon Sep 17 00:00:00 2001 From: schectman Date: Wed, 14 Feb 2024 14:28:19 -0500 Subject: [PATCH 17/27] License --- ci/licenses_golden/licenses_flutter | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 34b0f49b05ddd..185dc221c3685 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -7272,6 +7272,7 @@ ORIGIN: ../../../flutter/shell/platform/windows/flutter_window.h + ../../../flut ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_engine.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_engine.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_internal.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_texture_registrar.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_texture_registrar.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_view.cc + ../../../flutter/LICENSE @@ -10161,6 +10162,7 @@ FILE: ../../../flutter/shell/platform/windows/flutter_window.h FILE: ../../../flutter/shell/platform/windows/flutter_windows.cc FILE: ../../../flutter/shell/platform/windows/flutter_windows_engine.cc FILE: ../../../flutter/shell/platform/windows/flutter_windows_engine.h +FILE: ../../../flutter/shell/platform/windows/flutter_windows_internal.h FILE: ../../../flutter/shell/platform/windows/flutter_windows_texture_registrar.cc FILE: ../../../flutter/shell/platform/windows/flutter_windows_texture_registrar.h FILE: ../../../flutter/shell/platform/windows/flutter_windows_view.cc From 284b309bb9234c0fd258a161d127d0e8ae06fe67 Mon Sep 17 00:00:00 2001 From: schectman Date: Fri, 16 Feb 2024 12:15:13 -0500 Subject: [PATCH 18/27] Break up PlatformViewManager --- shell/platform/windows/BUILD.gn | 2 + .../windows/flutter_windows_engine.cc | 6 +- .../platform/windows/flutter_windows_engine.h | 4 +- .../flutter_windows_engine_unittests.cc | 5 +- .../platform/windows/platform_view_manager.cc | 47 ++++++++-------- .../platform/windows/platform_view_manager.h | 36 ++---------- .../platform/windows/platform_view_plugin.cc | 29 ++++++++++ shell/platform/windows/platform_view_plugin.h | 55 +++++++++++++++++++ .../windows/testing/engine_modifier.h | 4 +- .../testing/mock_platform_view_manager.h | 11 ++-- 10 files changed, 128 insertions(+), 71 deletions(-) create mode 100644 shell/platform/windows/platform_view_plugin.cc create mode 100644 shell/platform/windows/platform_view_plugin.h diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index 810e720e01259..8b5ed885e97c7 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -101,6 +101,8 @@ source_set("flutter_windows_source") { "platform_handler.h", "platform_view_manager.cc", "platform_view_manager.h", + "platform_view_plugin.cc", + "platform_view_plugin.h", "sequential_id_generator.cc", "sequential_id_generator.h", "settings_plugin.cc", diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc index 8626f0ff237b6..282b7c2482c2c 100644 --- a/shell/platform/windows/flutter_windows_engine.cc +++ b/shell/platform/windows/flutter_windows_engine.cc @@ -380,9 +380,9 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) { args.custom_task_runners = &custom_task_runners; - if (!platform_view_manager_) { - platform_view_manager_ = std::make_unique( - task_runner_.get(), messenger_wrapper_.get()); + if (!platform_view_plugin_) { + platform_view_plugin_ = std::make_unique( + messenger_wrapper_.get(), task_runner_.get()); } if (egl_manager_) { auto resolver = [](const char* name) -> void* { diff --git a/shell/platform/windows/flutter_windows_engine.h b/shell/platform/windows/flutter_windows_engine.h index fc2bae6b1a7c8..df9dde3074121 100644 --- a/shell/platform/windows/flutter_windows_engine.h +++ b/shell/platform/windows/flutter_windows_engine.h @@ -32,7 +32,7 @@ #include "flutter/shell/platform/windows/keyboard_handler_base.h" #include "flutter/shell/platform/windows/keyboard_key_embedder_handler.h" #include "flutter/shell/platform/windows/platform_handler.h" -#include "flutter/shell/platform/windows/platform_view_manager.h" +#include "flutter/shell/platform/windows/platform_view_plugin.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" #include "flutter/shell/platform/windows/settings_plugin.h" #include "flutter/shell/platform/windows/task_runner.h" @@ -430,7 +430,7 @@ class FlutterWindowsEngine { std::shared_ptr gl_; - std::unique_ptr platform_view_manager_; + std::unique_ptr platform_view_plugin_; FML_DISALLOW_COPY_AND_ASSIGN(FlutterWindowsEngine); }; diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index fbb5074fcff3b..3510560cd7b0c 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -1181,11 +1181,12 @@ TEST_F(FlutterWindowsEngineTest, ReceivePlatformViewMessage) { bool received_call = false; auto manager = std::make_unique(engine.get()); - EXPECT_CALL(*manager, QueuePlatformViewCreation) + EXPECT_CALL(*manager, AddPlatformView) .WillRepeatedly([&](PlatformViewId id, std::string_view type_name) { received_call = true; + return true; }); - modifier.SetPlatformViewManager(std::move(manager)); + modifier.SetPlatformViewPlugin(std::move(manager)); engine->Run(); diff --git a/shell/platform/windows/platform_view_manager.cc b/shell/platform/windows/platform_view_manager.cc index 1526a4d7d7289..aef30e03d2339 100644 --- a/shell/platform/windows/platform_view_manager.cc +++ b/shell/platform/windows/platform_view_manager.cc @@ -12,10 +12,8 @@ namespace { constexpr char kChannelName[] = "flutter/platform_views"; } -PlatformViewManager::PlatformViewManager(TaskRunner* task_runner, - BinaryMessenger* binary_messenger) - : task_runner_(task_runner), - channel_(std::make_unique>( +PlatformViewManager::PlatformViewManager(BinaryMessenger* binary_messenger) + : channel_(std::make_unique>( binary_messenger, kChannelName, &StandardMethodCodec::GetInstance())) { @@ -28,31 +26,30 @@ PlatformViewManager::PlatformViewManager(TaskRunner* task_runner, std::get(args.find(EncodableValue("type"))->second); const auto& id = std::get(args.find(EncodableValue("id"))->second); - QueuePlatformViewCreation(id, type); + if (AddPlatformView(id, type)) { + result->Success(); + } else { + result->Error("AddPlatformView", "Failed to add platform view"); + } + return; + } else if (call.method_name() == "focus") { + const auto& id = + std::get(args.find(EncodableValue("id"))->second); + const auto& direction = + std::get(args.find(EncodableValue("direction"))->second); + const auto& focus = + std::get(args.find(EncodableValue("focus"))->second); + if (FocusPlatformView(id, static_cast(direction), focus)) { + result->Success(); + } else { + result->Error("FocusPlatformView", "Failed to focus platform view"); + } + return; } - result->Success(); + result->NotImplemented(); }); } PlatformViewManager::~PlatformViewManager() {} -void PlatformViewManager::QueuePlatformViewCreation( - PlatformViewId id, - std::string_view type_name) {} - -void PlatformViewManager::InstantiatePlatformView(PlatformViewId id) {} - -void PlatformViewManager::RegisterPlatformViewType( - std::string_view type_name, - const FlutterPlatformViewTypeEntry& type) {} - -void PlatformViewManager::FocusPlatformView(PlatformViewId id, - FocusChangeDirection direction, - bool focus) {} - -std::optional PlatformViewManager::GetNativeHandleForId( - PlatformViewId id) const { - return std::nullopt; -} - } // namespace flutter diff --git a/shell/platform/windows/platform_view_manager.h b/shell/platform/windows/platform_view_manager.h index a714cb5931674..bff397a08f60c 100644 --- a/shell/platform/windows/platform_view_manager.h +++ b/shell/platform/windows/platform_view_manager.h @@ -5,10 +5,7 @@ #ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_MANAGER_H_ #define FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_MANAGER_H_ -#include -#include #include -#include #include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" @@ -28,47 +25,24 @@ enum class FocusChangeDirection { // method invokations from the framework. class PlatformViewManager { public: - PlatformViewManager(TaskRunner* task_runner, - BinaryMessenger* binary_messenger); + PlatformViewManager(BinaryMessenger* binary_messenger); virtual ~PlatformViewManager(); // Add a new platform view instance to be lazily instantiated when it is next // composited. - virtual void QueuePlatformViewCreation(PlatformViewId id, - std::string_view type_name); - - // Create a queued platform view instance. - void InstantiatePlatformView(PlatformViewId id); - - // The runner-facing API calls this method to register a window type - // corresponding to a platform view identifier supplied to the widget tree. - void RegisterPlatformViewType(std::string_view type_name, - const FlutterPlatformViewTypeEntry& type); + virtual bool AddPlatformView(PlatformViewId id, + std::string_view type_name) = 0; // The framework may invoke this method when keyboard focus must be given to // the platform view. - void FocusPlatformView(PlatformViewId id, + virtual bool FocusPlatformView(PlatformViewId id, FocusChangeDirection direction, - bool focus); - - // Find the HWND corresponding to a platform view id. Returns null if the id - // has no associated platform view. - std::optional GetNativeHandleForId(PlatformViewId id) const; + bool focus) = 0; private: std::unique_ptr> channel_; - std::unordered_map - platform_view_types_; - - std::unordered_map platform_views_; - - std::unordered_map> - pending_platform_views_; - - // Pointer to the task runner of the associated engine. - TaskRunner* task_runner_; }; } // namespace flutter diff --git a/shell/platform/windows/platform_view_plugin.cc b/shell/platform/windows/platform_view_plugin.cc new file mode 100644 index 0000000000000..dc5787a64514f --- /dev/null +++ b/shell/platform/windows/platform_view_plugin.cc @@ -0,0 +1,29 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/windows/platform_view_plugin.h" + +namespace flutter { + +PlatformViewPlugin::PlatformViewPlugin(BinaryMessenger* messenger, TaskRunner* task_runner) : PlatformViewManager(messenger), task_runner_(task_runner) {} + +PlatformViewPlugin::~PlatformViewPlugin() {} + +std::optional PlatformViewPlugin::GetNativeHandleForId(PlatformViewId id) const { + return std::nullopt; +} + +void PlatformViewPlugin::RegisterPlatformViewType(std::string_view type_name, const FlutterPlatformViewTypeEntry& type) {} + +void PlatformViewPlugin::InstantiatePlatformView(PlatformViewId id) {} + +bool PlatformViewPlugin::AddPlatformView(PlatformViewId id, std::string_view type_name) { + return true; +} + +bool PlatformViewPlugin::FocusPlatformView(PlatformViewId id, FocusChangeDirection direction, bool focus) { + return true; +} + +} // namespace flutter diff --git a/shell/platform/windows/platform_view_plugin.h b/shell/platform/windows/platform_view_plugin.h new file mode 100644 index 0000000000000..cc579c80d1b1b --- /dev/null +++ b/shell/platform/windows/platform_view_plugin.h @@ -0,0 +1,55 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_PLUGIN_H_ +#define FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_PLUGIN_H_ + +#include "flutter/shell/platform/windows/platform_view_manager.h" + +#include +#include +#include + +namespace flutter { + +class PlatformViewPlugin : public PlatformViewManager { + public: + PlatformViewPlugin(BinaryMessenger* messenger, TaskRunner* task_runner); + + ~PlatformViewPlugin(); + + // Find the HWND corresponding to a platform view id. Returns null if the id + // has no associated platform view. + std::optional GetNativeHandleForId(PlatformViewId id) const; + + // Create a queued platform view instance. + void InstantiatePlatformView(PlatformViewId id); + + // The runner-facing API calls this method to register a window type + // corresponding to a platform view identifier supplied to the widget tree. + void RegisterPlatformViewType(std::string_view type_name, + const FlutterPlatformViewTypeEntry& type); + + // | PlatformViewManager | + bool AddPlatformView(PlatformViewId id, std::string_view type_name) override; + + // | PlatformViewManager | + bool FocusPlatformView(PlatformViewId id, FocusChangeDirection direction, bool focus) override; + + private: + std::unordered_map + platform_view_types_; + + std::unordered_map platform_views_; + + std::unordered_map> + pending_platform_views_; + + // Pointer to the task runner of the associated engine. + TaskRunner* task_runner_; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_PLUGIN_H_ diff --git a/shell/platform/windows/testing/engine_modifier.h b/shell/platform/windows/testing/engine_modifier.h index 2e61ef78e53fe..f33b66afb0676 100644 --- a/shell/platform/windows/testing/engine_modifier.h +++ b/shell/platform/windows/testing/engine_modifier.h @@ -68,8 +68,8 @@ class EngineModifier { engine_->lifecycle_manager_ = std::move(handler); } - void SetPlatformViewManager(std::unique_ptr&& manager) { - engine_->platform_view_manager_ = std::move(manager); + void SetPlatformViewPlugin(std::unique_ptr&& manager) { + engine_->platform_view_plugin_ = std::move(manager); } private: diff --git a/shell/platform/windows/testing/mock_platform_view_manager.h b/shell/platform/windows/testing/mock_platform_view_manager.h index cd6f435620903..90df8bfcbd906 100644 --- a/shell/platform/windows/testing/mock_platform_view_manager.h +++ b/shell/platform/windows/testing/mock_platform_view_manager.h @@ -5,23 +5,22 @@ #ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_PLATFORM_VIEW_MANAGER_H_ #define FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_PLATFORM_VIEW_MANAGER_H_ -#include "flutter/shell/platform/windows/platform_view_manager.h" +#include "flutter/shell/platform/windows/platform_view_plugin.h" #include "flutter/shell/platform/windows/flutter_windows_engine.h" #include "gmock/gmock.h" namespace flutter { -class MockPlatformViewManager : public PlatformViewManager { +class MockPlatformViewManager : public PlatformViewPlugin { public: MockPlatformViewManager(FlutterWindowsEngine* engine) - : PlatformViewManager(engine->task_runner(), - engine->messenger_wrapper()) {} + : PlatformViewPlugin(engine->messenger_wrapper(), engine->task_runner()) {} ~MockPlatformViewManager() {} - MOCK_METHOD(void, - QueuePlatformViewCreation, + MOCK_METHOD(bool, + AddPlatformView, (PlatformViewId id, std::string_view)); }; From e000930bf65d3a359341b0674069a49f1cdc724d Mon Sep 17 00:00:00 2001 From: schectman Date: Fri, 16 Feb 2024 12:21:07 -0500 Subject: [PATCH 19/27] PR Feedback --- ci/licenses_golden/licenses_flutter | 4 ++++ .../platform/windows/platform_view_manager.h | 19 +++++++++++-------- shell/platform/windows/platform_view_plugin.h | 16 +++++++++++++--- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 185dc221c3685..9467def74913f 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -7293,6 +7293,8 @@ ORIGIN: ../../../flutter/shell/platform/windows/platform_handler.cc + ../../../f ORIGIN: ../../../flutter/shell/platform/windows/platform_handler.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/platform_view_manager.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/platform_view_manager.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/windows/platform_view_plugin.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/windows/platform_view_plugin.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/public/flutter_windows.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/sequential_id_generator.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/sequential_id_generator.h + ../../../flutter/LICENSE @@ -10183,6 +10185,8 @@ FILE: ../../../flutter/shell/platform/windows/platform_handler.cc FILE: ../../../flutter/shell/platform/windows/platform_handler.h FILE: ../../../flutter/shell/platform/windows/platform_view_manager.cc FILE: ../../../flutter/shell/platform/windows/platform_view_manager.h +FILE: ../../../flutter/shell/platform/windows/platform_view_plugin.cc +FILE: ../../../flutter/shell/platform/windows/platform_view_plugin.h FILE: ../../../flutter/shell/platform/windows/public/flutter_windows.h FILE: ../../../flutter/shell/platform/windows/sequential_id_generator.cc FILE: ../../../flutter/shell/platform/windows/sequential_id_generator.h diff --git a/shell/platform/windows/platform_view_manager.h b/shell/platform/windows/platform_view_manager.h index bff397a08f60c..7528e01eb9b8b 100644 --- a/shell/platform/windows/platform_view_manager.h +++ b/shell/platform/windows/platform_view_manager.h @@ -20,9 +20,10 @@ enum class FocusChangeDirection { kBackward // Keyboard focus moves backwards, e.g. Shift+TAB. }; -// Keeps track of registered platform view types and platform view instances, -// and is responsible for processing and responding to platform view related -// method invokations from the framework. +// The platform method handler for platform view related communication between +// the engine and the framework. This base class is derived by a concrete class +// (i.e. PlatformViewPlugin) to provide implementation of its abstract virtual +// methods. class PlatformViewManager { public: PlatformViewManager(BinaryMessenger* binary_messenger); @@ -30,15 +31,17 @@ class PlatformViewManager { virtual ~PlatformViewManager(); // Add a new platform view instance to be lazily instantiated when it is next - // composited. + // composited. The manager will invoke Success when this method returns true, + // and invoke Error otherwise. virtual bool AddPlatformView(PlatformViewId id, - std::string_view type_name) = 0; + std::string_view type_name) = 0; // The framework may invoke this method when keyboard focus must be given to - // the platform view. + // the platform view. The manager will invoke Success when this method returns + // true, and invoke Error otherwise. virtual bool FocusPlatformView(PlatformViewId id, - FocusChangeDirection direction, - bool focus) = 0; + FocusChangeDirection direction, + bool focus) = 0; private: std::unique_ptr> channel_; diff --git a/shell/platform/windows/platform_view_plugin.h b/shell/platform/windows/platform_view_plugin.h index cc579c80d1b1b..f3d035b64589a 100644 --- a/shell/platform/windows/platform_view_plugin.h +++ b/shell/platform/windows/platform_view_plugin.h @@ -13,6 +13,8 @@ namespace flutter { +// The concrete implementation of PlatformViewManager that keeps track of +// existing platform view types and instances, and handles their instantiation. class PlatformViewPlugin : public PlatformViewManager { public: PlatformViewPlugin(BinaryMessenger* messenger, TaskRunner* task_runner); @@ -23,18 +25,26 @@ class PlatformViewPlugin : public PlatformViewManager { // has no associated platform view. std::optional GetNativeHandleForId(PlatformViewId id) const; - // Create a queued platform view instance. - void InstantiatePlatformView(PlatformViewId id); - // The runner-facing API calls this method to register a window type // corresponding to a platform view identifier supplied to the widget tree. void RegisterPlatformViewType(std::string_view type_name, const FlutterPlatformViewTypeEntry& type); + // Create a queued platform view instance after it has been added. + // id must correspond to an identifier that has already been added with + // AddPlatformView. + // This method will create the platform view within a task queued to the + // engine's TaskRunner, which will run on the UI thread. + void InstantiatePlatformView(PlatformViewId id); + // | PlatformViewManager | + // type_name must correspond to a string that has already been registered + // with RegisterPlatformViewType. bool AddPlatformView(PlatformViewId id, std::string_view type_name) override; // | PlatformViewManager | + // id must correspond to an identifier that has already been added with + // AddPlatformView. bool FocusPlatformView(PlatformViewId id, FocusChangeDirection direction, bool focus) override; private: From 676868fd441f1abfdd6095ea78d0f90f867f10d6 Mon Sep 17 00:00:00 2001 From: schectman Date: Fri, 16 Feb 2024 12:22:05 -0500 Subject: [PATCH 20/27] Formatting --- .../platform/windows/platform_view_manager.cc | 7 ++++--- shell/platform/windows/platform_view_manager.h | 1 - shell/platform/windows/platform_view_plugin.cc | 18 +++++++++++++----- shell/platform/windows/platform_view_plugin.h | 4 +++- .../testing/mock_platform_view_manager.h | 7 +++---- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/shell/platform/windows/platform_view_manager.cc b/shell/platform/windows/platform_view_manager.cc index aef30e03d2339..8de30fdeb81f0 100644 --- a/shell/platform/windows/platform_view_manager.cc +++ b/shell/platform/windows/platform_view_manager.cc @@ -35,11 +35,12 @@ PlatformViewManager::PlatformViewManager(BinaryMessenger* binary_messenger) } else if (call.method_name() == "focus") { const auto& id = std::get(args.find(EncodableValue("id"))->second); - const auto& direction = - std::get(args.find(EncodableValue("direction"))->second); + const auto& direction = std::get( + args.find(EncodableValue("direction"))->second); const auto& focus = std::get(args.find(EncodableValue("focus"))->second); - if (FocusPlatformView(id, static_cast(direction), focus)) { + if (FocusPlatformView( + id, static_cast(direction), focus)) { result->Success(); } else { result->Error("FocusPlatformView", "Failed to focus platform view"); diff --git a/shell/platform/windows/platform_view_manager.h b/shell/platform/windows/platform_view_manager.h index 7528e01eb9b8b..7cbe25ce8d9e7 100644 --- a/shell/platform/windows/platform_view_manager.h +++ b/shell/platform/windows/platform_view_manager.h @@ -45,7 +45,6 @@ class PlatformViewManager { private: std::unique_ptr> channel_; - }; } // namespace flutter diff --git a/shell/platform/windows/platform_view_plugin.cc b/shell/platform/windows/platform_view_plugin.cc index dc5787a64514f..bad994dfa05af 100644 --- a/shell/platform/windows/platform_view_plugin.cc +++ b/shell/platform/windows/platform_view_plugin.cc @@ -6,23 +6,31 @@ namespace flutter { -PlatformViewPlugin::PlatformViewPlugin(BinaryMessenger* messenger, TaskRunner* task_runner) : PlatformViewManager(messenger), task_runner_(task_runner) {} +PlatformViewPlugin::PlatformViewPlugin(BinaryMessenger* messenger, + TaskRunner* task_runner) + : PlatformViewManager(messenger), task_runner_(task_runner) {} PlatformViewPlugin::~PlatformViewPlugin() {} -std::optional PlatformViewPlugin::GetNativeHandleForId(PlatformViewId id) const { +std::optional PlatformViewPlugin::GetNativeHandleForId( + PlatformViewId id) const { return std::nullopt; } -void PlatformViewPlugin::RegisterPlatformViewType(std::string_view type_name, const FlutterPlatformViewTypeEntry& type) {} +void PlatformViewPlugin::RegisterPlatformViewType( + std::string_view type_name, + const FlutterPlatformViewTypeEntry& type) {} void PlatformViewPlugin::InstantiatePlatformView(PlatformViewId id) {} -bool PlatformViewPlugin::AddPlatformView(PlatformViewId id, std::string_view type_name) { +bool PlatformViewPlugin::AddPlatformView(PlatformViewId id, + std::string_view type_name) { return true; } -bool PlatformViewPlugin::FocusPlatformView(PlatformViewId id, FocusChangeDirection direction, bool focus) { +bool PlatformViewPlugin::FocusPlatformView(PlatformViewId id, + FocusChangeDirection direction, + bool focus) { return true; } diff --git a/shell/platform/windows/platform_view_plugin.h b/shell/platform/windows/platform_view_plugin.h index f3d035b64589a..928b691f58cd1 100644 --- a/shell/platform/windows/platform_view_plugin.h +++ b/shell/platform/windows/platform_view_plugin.h @@ -45,7 +45,9 @@ class PlatformViewPlugin : public PlatformViewManager { // | PlatformViewManager | // id must correspond to an identifier that has already been added with // AddPlatformView. - bool FocusPlatformView(PlatformViewId id, FocusChangeDirection direction, bool focus) override; + bool FocusPlatformView(PlatformViewId id, + FocusChangeDirection direction, + bool focus) override; private: std::unordered_map diff --git a/shell/platform/windows/testing/mock_platform_view_manager.h b/shell/platform/windows/testing/mock_platform_view_manager.h index 90df8bfcbd906..a3c6922269932 100644 --- a/shell/platform/windows/testing/mock_platform_view_manager.h +++ b/shell/platform/windows/testing/mock_platform_view_manager.h @@ -15,13 +15,12 @@ namespace flutter { class MockPlatformViewManager : public PlatformViewPlugin { public: MockPlatformViewManager(FlutterWindowsEngine* engine) - : PlatformViewPlugin(engine->messenger_wrapper(), engine->task_runner()) {} + : PlatformViewPlugin(engine->messenger_wrapper(), engine->task_runner()) { + } ~MockPlatformViewManager() {} - MOCK_METHOD(bool, - AddPlatformView, - (PlatformViewId id, std::string_view)); + MOCK_METHOD(bool, AddPlatformView, (PlatformViewId id, std::string_view)); }; } // namespace flutter From 6e6ef7ebabd2a9d719f0c1b003cbbf7613b8b5bc Mon Sep 17 00:00:00 2001 From: schectman Date: Fri, 16 Feb 2024 13:51:16 -0500 Subject: [PATCH 21/27] PR Feedback --- shell/platform/windows/fixtures/main.dart | 12 +++-- .../platform/windows/platform_view_manager.cc | 54 ++++++++++++++----- .../platform/windows/platform_view_manager.h | 2 +- .../platform/windows/platform_view_plugin.cc | 10 ++++ 4 files changed, 60 insertions(+), 18 deletions(-) diff --git a/shell/platform/windows/fixtures/main.dart b/shell/platform/windows/fixtures/main.dart index bae5b7932cc56..4512c58e93b22 100644 --- a/shell/platform/windows/fixtures/main.dart +++ b/shell/platform/windows/fixtures/main.dart @@ -167,14 +167,18 @@ void sendCreatePlatformViewMethod() async { const int valueString = 7; const int valueMap = 13; const int valueInt32 = 3; + const String method = 'create'; + const String typeKey = 'viewType'; + const String typeValue = 'type'; + const String idKey = 'id'; final List data = [ // Method name - valueString, 'create'.length, ...utf8.encode('create'), + valueString, method.length, ...utf8.encode(method), // Method arguments: {'type': 'type':, 'id': 0} valueMap, 2, - valueString, 'type'.length, ...utf8.encode('type'), - valueString, 'type'.length, ...utf8.encode('type'), - valueString, 'id'.length, ...utf8.encode('id'), + valueString, typeKey.length, ...utf8.encode(typeKey), + valueString, typeValue.length, ...utf8.encode(typeValue), + valueString, idKey.length, ...utf8.encode(idKey), valueInt32, 0, 0, 0, 0, ]; diff --git a/shell/platform/windows/platform_view_manager.cc b/shell/platform/windows/platform_view_manager.cc index 8de30fdeb81f0..cb403673597b6 100644 --- a/shell/platform/windows/platform_view_manager.cc +++ b/shell/platform/windows/platform_view_manager.cc @@ -10,7 +10,13 @@ namespace flutter { namespace { constexpr char kChannelName[] = "flutter/platform_views"; -} +constexpr char kCreateMethod[] = "create"; +constexpr char kFocusMethod[] = "focus"; +constexpr char kViewTypeParameter[] = "viewType"; +constexpr char kIdParameter[] = "id"; +constexpr char kDirectionParameter[] = "direction"; +constexpr char kFocusParameter[] = "focus"; +} // namespace PlatformViewManager::PlatformViewManager(BinaryMessenger* binary_messenger) : channel_(std::make_unique>( @@ -21,24 +27,46 @@ PlatformViewManager::PlatformViewManager(BinaryMessenger* binary_messenger) [this](const MethodCall& call, std::unique_ptr> result) { const auto& args = std::get(*call.arguments()); - if (call.method_name() == "create") { - const auto& type = - std::get(args.find(EncodableValue("type"))->second); - const auto& id = - std::get(args.find(EncodableValue("id"))->second); + if (call.method_name() == kCreateMethod) { + const auto& type_itr = args.find(EncodableValue(kViewTypeParameter)); + const auto& id_itr = args.find(EncodableValue(kIdParameter)); + if (type_itr == args.end()) { + result->Error("AddPlatformView", "Parameter viewType is required"); + return; + } + if (id_itr == args.end()) { + result->Error("AddPlatformView", "Parameter id is required"); + return; + } + const auto& type = std::get(type_itr->second); + const auto& id = std::get(id_itr->second); if (AddPlatformView(id, type)) { result->Success(); } else { result->Error("AddPlatformView", "Failed to add platform view"); } return; - } else if (call.method_name() == "focus") { - const auto& id = - std::get(args.find(EncodableValue("id"))->second); - const auto& direction = std::get( - args.find(EncodableValue("direction"))->second); - const auto& focus = - std::get(args.find(EncodableValue("focus"))->second); + } else if (call.method_name() == kFocusMethod) { + const auto& id_itr = args.find(EncodableValue(kIdParameter)); + const auto& direction_itr = + args.find(EncodableValue(kDirectionParameter)); + const auto& focus_itr = args.find(EncodableValue(kFocusParameter)); + if (id_itr == args.end()) { + result->Error("FocusPlatformView", "Parameter id is required"); + return; + } + if (direction_itr == args.end()) { + result->Error("FocusPlatformView", + "Parameter direction is required"); + return; + } + if (focus_itr == args.end()) { + result->Error("FocusPlatformView", "Parameter focus is required"); + return; + } + const auto& id = std::get(id_itr->second); + const auto& direction = std::get(direction_itr->second); + const auto& focus = std::get(focus_itr->second); if (FocusPlatformView( id, static_cast(direction), focus)) { result->Success(); diff --git a/shell/platform/windows/platform_view_manager.h b/shell/platform/windows/platform_view_manager.h index 7cbe25ce8d9e7..49c645e659b0d 100644 --- a/shell/platform/windows/platform_view_manager.h +++ b/shell/platform/windows/platform_view_manager.h @@ -16,7 +16,7 @@ namespace flutter { // Possible reasons for change of keyboard foucs. enum class FocusChangeDirection { kProgrammatic, // Un-directed focus change. - kForward, // Keyboard focus moves forwards, e.g. TAB-key. + kForward, // Keyboard focus moves forwards, e.g. TAB key. kBackward // Keyboard focus moves backwards, e.g. Shift+TAB. }; diff --git a/shell/platform/windows/platform_view_plugin.cc b/shell/platform/windows/platform_view_plugin.cc index bad994dfa05af..a54ebfebf1a64 100644 --- a/shell/platform/windows/platform_view_plugin.cc +++ b/shell/platform/windows/platform_view_plugin.cc @@ -12,22 +12,32 @@ PlatformViewPlugin::PlatformViewPlugin(BinaryMessenger* messenger, PlatformViewPlugin::~PlatformViewPlugin() {} +// TODO(schectman): Impelement platform view lookup. +// https://github.com/flutter/flutter/issues/143375 std::optional PlatformViewPlugin::GetNativeHandleForId( PlatformViewId id) const { return std::nullopt; } +// TODO(schectman): Impelement platform view type registration. +// https://github.com/flutter/flutter/issues/143375 void PlatformViewPlugin::RegisterPlatformViewType( std::string_view type_name, const FlutterPlatformViewTypeEntry& type) {} +// TODO(schectman): Impelement platform view instantiation. +// https://github.com/flutter/flutter/issues/143375 void PlatformViewPlugin::InstantiatePlatformView(PlatformViewId id) {} +// TODO(schectman): Impelement platform view addition. +// https://github.com/flutter/flutter/issues/143375 bool PlatformViewPlugin::AddPlatformView(PlatformViewId id, std::string_view type_name) { return true; } +// TODO(schectman): Impelement platform view focus request. +// https://github.com/flutter/flutter/issues/143375 bool PlatformViewPlugin::FocusPlatformView(PlatformViewId id, FocusChangeDirection direction, bool focus) { From 22a9e4605911e5b70de115017c3fb3430e672307 Mon Sep 17 00:00:00 2001 From: yaakovschectman <109111084+yaakovschectman@users.noreply.github.com> Date: Wed, 21 Feb 2024 06:46:46 -0500 Subject: [PATCH 22/27] Update shell/platform/windows/flutter_windows_engine_unittests.cc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com> --- shell/platform/windows/flutter_windows_engine_unittests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index 3510560cd7b0c..d7aad7abc77b1 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -1175,7 +1175,7 @@ TEST_F(FlutterWindowsEngineTest, ReceivePlatformViewMessage) { builder.SetDartEntrypoint("sendCreatePlatformViewMethod"); auto engine = builder.Build(); - EngineModifier modifier(engine.get()); + EngineModifier modifier{engine.get()}; modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; }; bool received_call = false; From 95a849819fdf4e9c013139bfd8047edcb194dc84 Mon Sep 17 00:00:00 2001 From: yaakovschectman <109111084+yaakovschectman@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:51:46 -0500 Subject: [PATCH 23/27] Update shell/platform/windows/platform_view_manager.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com> --- shell/platform/windows/platform_view_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/windows/platform_view_manager.h b/shell/platform/windows/platform_view_manager.h index 49c645e659b0d..43b13250f2dd9 100644 --- a/shell/platform/windows/platform_view_manager.h +++ b/shell/platform/windows/platform_view_manager.h @@ -13,7 +13,7 @@ namespace flutter { -// Possible reasons for change of keyboard foucs. +// Possible reasons for change of keyboard focus. enum class FocusChangeDirection { kProgrammatic, // Un-directed focus change. kForward, // Keyboard focus moves forwards, e.g. TAB key. From 1fa97f3a43fba8dcb3776a9e48357ce497d9192f Mon Sep 17 00:00:00 2001 From: yaakovschectman <109111084+yaakovschectman@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:51:54 -0500 Subject: [PATCH 24/27] Update shell/platform/windows/public/flutter_windows.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com> --- shell/platform/windows/public/flutter_windows.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index 47c3262cd18d4..1d6168b95449a 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -221,7 +221,7 @@ typedef HWND (*FlutterPlatformViewFactory)( typedef struct { size_t struct_size; FlutterPlatformViewFactory factory; - void* user_data; // Arbitrary user data supplied to the cretaion struct. + void* user_data; // Arbitrary user data supplied to the creation struct. } FlutterPlatformViewTypeEntry; // ========== View ========== From 5453b290a3d2b17874aeec989225dd3c14a68bb6 Mon Sep 17 00:00:00 2001 From: yaakovschectman <109111084+yaakovschectman@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:52:25 -0500 Subject: [PATCH 25/27] Update shell/platform/windows/flutter_windows_engine_unittests.cc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com> --- shell/platform/windows/flutter_windows_engine_unittests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index d7aad7abc77b1..5650d25336677 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -1182,7 +1182,7 @@ TEST_F(FlutterWindowsEngineTest, ReceivePlatformViewMessage) { auto manager = std::make_unique(engine.get()); EXPECT_CALL(*manager, AddPlatformView) - .WillRepeatedly([&](PlatformViewId id, std::string_view type_name) { + .WillOnce([&](PlatformViewId id, std::string_view type_name) { received_call = true; return true; }); From dfa6b73bf0892d6b0f5f61e96770139a364cf8e4 Mon Sep 17 00:00:00 2001 From: schectman Date: Wed, 21 Feb 2024 14:59:45 -0500 Subject: [PATCH 26/27] PR Feedback --- .../testing/stub_flutter_windows_api.h | 1 + .../windows/flutter_windows_internal.h | 21 +++++++++++++++++++ .../platform/windows/platform_view_manager.h | 2 +- shell/platform/windows/platform_view_plugin.h | 10 ++++----- .../platform/windows/public/flutter_windows.h | 21 ------------------- 5 files changed, 28 insertions(+), 27 deletions(-) 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 548d0ee93e61c..43eaa50074132 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 @@ -7,6 +7,7 @@ #include +#include "flutter/shell/platform/windows/flutter_windows_internal.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" namespace flutter { diff --git a/shell/platform/windows/flutter_windows_internal.h b/shell/platform/windows/flutter_windows_internal.h index a0eb5ff533703..47b98e983a48a 100644 --- a/shell/platform/windows/flutter_windows_internal.h +++ b/shell/platform/windows/flutter_windows_internal.h @@ -14,6 +14,27 @@ extern "C" { // Declare functions that are currently in-progress and shall be exposed to the // public facing API upon completion. +typedef int64_t PlatformViewId; + +typedef struct { + size_t struct_size; + HWND parent_window; + const char* platform_view_type; + // user_data may hold any necessary additional information for creating a new + // platform view. For example, an instance of FlutterWindow. + void* user_data; + PlatformViewId platform_view_id; +} FlutterPlatformViewCreationParameters; + +typedef HWND (*FlutterPlatformViewFactory)( + const FlutterPlatformViewCreationParameters*); + +typedef struct { + size_t struct_size; + FlutterPlatformViewFactory factory; + void* user_data; // Arbitrary user data supplied to the creation struct. +} FlutterPlatformViewTypeEntry; + FLUTTER_EXPORT void FlutterDesktopEngineRegisterPlatformViewType( FlutterDesktopEngineRef engine, const char* view_type_name, diff --git a/shell/platform/windows/platform_view_manager.h b/shell/platform/windows/platform_view_manager.h index 43b13250f2dd9..d4b736f9602fc 100644 --- a/shell/platform/windows/platform_view_manager.h +++ b/shell/platform/windows/platform_view_manager.h @@ -8,7 +8,7 @@ #include #include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h" -#include "flutter/shell/platform/windows/public/flutter_windows.h" +#include "flutter/shell/platform/windows/flutter_windows_internal.h" #include "flutter/shell/platform/windows/task_runner.h" namespace flutter { diff --git a/shell/platform/windows/platform_view_plugin.h b/shell/platform/windows/platform_view_plugin.h index 928b691f58cd1..490d21a8e0ba2 100644 --- a/shell/platform/windows/platform_view_plugin.h +++ b/shell/platform/windows/platform_view_plugin.h @@ -30,6 +30,11 @@ class PlatformViewPlugin : public PlatformViewManager { void RegisterPlatformViewType(std::string_view type_name, const FlutterPlatformViewTypeEntry& type); + // | PlatformViewManager | + // type_name must correspond to a string that has already been registered + // with RegisterPlatformViewType. + bool AddPlatformView(PlatformViewId id, std::string_view type_name) override; + // Create a queued platform view instance after it has been added. // id must correspond to an identifier that has already been added with // AddPlatformView. @@ -37,11 +42,6 @@ class PlatformViewPlugin : public PlatformViewManager { // engine's TaskRunner, which will run on the UI thread. void InstantiatePlatformView(PlatformViewId id); - // | PlatformViewManager | - // type_name must correspond to a string that has already been registered - // with RegisterPlatformViewType. - bool AddPlatformView(PlatformViewId id, std::string_view type_name) override; - // | PlatformViewManager | // id must correspond to an identifier that has already been added with // AddPlatformView. diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index 1d6168b95449a..a9f7f973fb987 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -203,27 +203,6 @@ FLUTTER_EXPORT void FlutterDesktopEngineSetNextFrameCallback( VoidCallback callback, void* user_data); -typedef int64_t PlatformViewId; - -typedef struct { - size_t struct_size; - HWND parent_window; - const char* platform_view_type; - // user_data may hold any necessary additional information for creating a new - // platform view. For example, an instance of FlutterWindow. - void* user_data; - PlatformViewId platform_view_id; -} FlutterPlatformViewCreationParameters; - -typedef HWND (*FlutterPlatformViewFactory)( - const FlutterPlatformViewCreationParameters*); - -typedef struct { - size_t struct_size; - FlutterPlatformViewFactory factory; - void* user_data; // Arbitrary user data supplied to the creation struct. -} FlutterPlatformViewTypeEntry; - // ========== View ========== // Return backing HWND for manipulation in host application. From 585ca1110fd9db885a6afe2b3414da0af6ebb733 Mon Sep 17 00:00:00 2001 From: schectman Date: Thu, 22 Feb 2024 16:17:35 -0500 Subject: [PATCH 27/27] Include internal header --- shell/platform/windows/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index a91224d0c5b99..fe72e926d48dd 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -8,6 +8,7 @@ import("//flutter/shell/platform/glfw/config.gni") import("//flutter/testing/testing.gni") _public_headers = [ "public/flutter_windows.h" ] +_internal_headers = [ "flutter_windows_internal.h" ] config("relative_angle_headers") { include_dirs = [ "//third_party/angle/include" ] @@ -24,7 +25,7 @@ config("relative_flutter_windows_headers") { # The headers are a separate source set since the client wrapper is allowed # to depend on the public headers, but none of the rest of the code. source_set("flutter_windows_headers") { - public = _public_headers + public = _public_headers + _internal_headers public_deps = [ "//flutter/shell/platform/common:common_cpp_library_headers" ] @@ -80,7 +81,6 @@ source_set("flutter_windows_source") { "flutter_windows.cc", "flutter_windows_engine.cc", "flutter_windows_engine.h", - "flutter_windows_internal.h", "flutter_windows_texture_registrar.cc", "flutter_windows_texture_registrar.h", "flutter_windows_view.cc",