From 6d9defbb3e219aeabd0d1ddc49b712b99694b21e Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sun, 4 Oct 2020 20:07:02 -0700 Subject: [PATCH 01/19] Add UWP Target --- BUILD.gn | 5 +- shell/platform/windows/BUILD.gn | 165 ++++++++++++++---- .../platform/windows/client_wrapper/BUILD.gn | 6 +- .../client_wrapper/flutter_view_controller.cc | 2 + .../include/flutter/flutter_view_controller.h | 2 + .../windows/flutter_project_bundle.cc | 2 +- shell/platform/windows/flutter_windows.cc | 24 ++- .../windows/flutter_windows_engine.cc | 8 + .../platform/windows/flutter_windows_engine.h | 12 +- .../platform/windows/flutter_windows_view.cc | 2 + shell/platform/windows/flutter_windows_view.h | 6 +- .../platform/windows/public/flutter_windows.h | 2 + shell/platform/windows/system_utils_winuwp.cc | 35 ++++ tools/gn | 5 + 14 files changed, 236 insertions(+), 40 deletions(-) create mode 100644 shell/platform/windows/system_utils_winuwp.cc diff --git a/BUILD.gn b/BUILD.gn index 82575d2ff3755..08402b37f8daf 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -144,11 +144,14 @@ group("flutter") { public_deps += [ "//flutter/shell/platform/darwin/macos:flutter_desktop_darwin_unittests" ] } - if (is_win) { + if (is_win && target_os != "winuwp") { public_deps += [ "//flutter/shell/platform/windows:flutter_windows_unittests", "//flutter/shell/platform/windows/client_wrapper:client_wrapper_windows_unittests", ] + } else if (is_win) { + # TODO once the UWP implmentation lands, reference future flutter_windows_unittests_winrt + # runner implementation from here } } } diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index 66b578cf0fa49..7b98267ba8676 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -21,6 +21,11 @@ config("relative_flutter_windows_headers") { include_dirs = [ "public" ] } +# When OS target is WinUWP use FLUTTER_WINUWP as the preprocessor flag to conditionalize +config("flutter_windows_winuwp_defs") { + defines = [ "FLUTTER_WINUWP 1" ] +} + # 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") { @@ -29,8 +34,15 @@ source_set("flutter_windows_headers") { public_deps = [ "//flutter/shell/platform/common/cpp:common_cpp_library_headers" ] - configs += - [ "//flutter/shell/platform/common/cpp:desktop_library_implementation" ] + if (target_os == "winuwp") { + configs += [ + "//flutter/shell/platform/common/cpp:desktop_library_implementation", + ":flutter_windows_winuwp_defs", + ] + } else { + configs += + [ "//flutter/shell/platform/common/cpp:desktop_library_implementation" ] + } public_configs = [ "//flutter/shell/platform/common/cpp:relative_flutter_library_headers" ] @@ -100,6 +112,59 @@ source_set("flutter_windows_source") { ] } +source_set("flutter_winuwp_source") { + sources = [ + "angle_surface_manager.cc", + "angle_surface_manager.h", + "cursor_handler.cc", + "cursor_handler.h", + "flutter_project_bundle.cc", + "flutter_project_bundle.h", + "flutter_windows.cc", + "flutter_windows_engine.cc", + "flutter_windows_engine.h", + "flutter_windows_view.cc", + "flutter_windows_view.h", + "key_event_handler.cc", + "key_event_handler.h", + "keyboard_hook_handler.h", + "string_conversion.cc", + "string_conversion.h", + "system_utils.h", + "system_utils_winuwp.cc", + "text_input_plugin.cc", + "text_input_plugin.h", + "window_binding_handler.h", + "window_binding_handler_delegate.h", + "window_state.h", + ] + + configs += [ + "//flutter/shell/platform/common/cpp:desktop_library_implementation", + "//third_party/angle:gl_prototypes", + ":flutter_windows_winuwp_defs", + ] + + public_configs = [ ":relative_angle_headers" ] + + deps = [ + ":flutter_windows_headers", + "//flutter/shell/platform/common/cpp:common_cpp", + "//flutter/shell/platform/common/cpp:common_cpp_input", + "//flutter/shell/platform/common/cpp:common_cpp_switches", + "//flutter/shell/platform/common/cpp/client_wrapper:client_wrapper", + "//flutter/shell/platform/embedder:embedder_as_internal_library", + "//flutter/shell/platform/windows/client_wrapper:client_wrapper_windows", + "//third_party/angle:libEGL_static", # the order of libEGL_static and + # libGLESv2_static is important.. if + # reversed, will cause a linker error + # DllMain already defined in + # LIBCMTD.lib + "//third_party/angle:libGLESv2_static", + "//third_party/rapidjson", + ] +} + copy("publish_headers_windows") { sources = _public_headers outputs = [ "$root_out_dir/{{source_file_part}}" ] @@ -114,36 +179,67 @@ shared_library("flutter_windows") { public_configs = [ "//flutter:config" ] } +shared_library("flutter_windows_winuwp") { + deps = [ ":flutter_winuwp_source" ] + libs = [ "windowsapp.lib" ] + public_configs = [ "//flutter:config" ] +} + test_fixtures("flutter_windows_fixtures") { fixtures = [] } -executable("flutter_windows_unittests") { - testonly = true +if (target_os == "winuwp") { + # disabled until the uwp implementation is present + # executable("flutter_windows_unittests_winrt") { + # testonly = true - sources = [ - "flutter_project_bundle_unittests.cc", - "string_conversion_unittests.cc", - "system_utils_unittests.cc", - "testing/mock_win32_window.cc", - "testing/mock_win32_window.h", - "testing/win32_flutter_window_test.cc", - "testing/win32_flutter_window_test.h", - "win32_dpi_utils_unittests.cc", - "win32_flutter_window_unittests.cc", - "win32_window_proc_delegate_manager_unittests.cc", - "win32_window_unittests.cc", - ] + # sources = [ + # "flutter_project_bundle_unittests.cc", + # "string_conversion_unittests.cc", + # "system_utils_unittests.cc", + # ] - public_configs = [ "//flutter:config" ] + # public_configs = [ "//flutter:config" ] - deps = [ - ":flutter_windows_fixtures", - ":flutter_windows_headers", - ":flutter_windows_source", - "//flutter/testing", - "//third_party/rapidjson", - ] + # libs = [ "windowsapp.lib" ] + + # deps = [ + # ":flutter_windows_fixtures", + # ":flutter_windows_headers", + # ":flutter_windows_source", + # "//flutter/testing", + # "//third_party/rapidjson", + # ] + # } +} else { + executable("flutter_windows_unittests") { + testonly = true + + sources = [ + "flutter_project_bundle_unittests.cc", + "string_conversion_unittests.cc", + "system_utils_unittests.cc", + "testing/mock_win32_window.cc", + "testing/mock_win32_window.h", + "testing/win32_flutter_window_test.cc", + "testing/win32_flutter_window_test.h", + "win32_dpi_utils_unittests.cc", + "win32_flutter_window_unittests.cc", + "win32_window_proc_delegate_manager_unittests.cc", + "win32_window_unittests.cc", + ] + + public_configs = [ "//flutter:config" ] + + deps = [ + ":flutter_windows_fixtures", + ":flutter_windows_headers", + ":flutter_windows_source", + "//flutter/testing", + "//third_party/rapidjson", + ] + } } shared_library("flutter_windows_glfw") { @@ -162,11 +258,20 @@ group("windows_glfw") { } group("windows") { - deps = [ - ":flutter_windows", - ":publish_headers_windows", - "//flutter/shell/platform/windows/client_wrapper:publish_wrapper_windows", - ] + if (target_os == "winuwp") { + deps = [ + ":flutter_windows_winuwp", + ":publish_headers_windows", + "//flutter/shell/platform/windows/client_wrapper:publish_wrapper_windows", + ] + } else { + deps = [ + ":flutter_windows", + ":publish_headers_windows", + "//flutter/shell/platform/windows/client_wrapper:publish_wrapper_windows", + ] + } + if (build_glfw_shell) { deps += [ ":windows_glfw" ] } diff --git a/shell/platform/windows/client_wrapper/BUILD.gn b/shell/platform/windows/client_wrapper/BUILD.gn index fe54c2ba2a484..155d87575e74f 100644 --- a/shell/platform/windows/client_wrapper/BUILD.gn +++ b/shell/platform/windows/client_wrapper/BUILD.gn @@ -39,8 +39,10 @@ source_set("client_wrapper_windows") { "//flutter/shell/platform/windows:flutter_windows_headers", ] - configs += - [ "//flutter/shell/platform/common/cpp:desktop_library_implementation" ] + configs += [ + "//flutter/shell/platform/common/cpp:desktop_library_implementation", + "//flutter/shell/platform/windows:flutter_windows_winuwp_defs", + ] public_configs = [ ":relative_core_wrapper_headers", diff --git a/shell/platform/windows/client_wrapper/flutter_view_controller.cc b/shell/platform/windows/client_wrapper/flutter_view_controller.cc index 5cb9fe98623e1..65817524f8497 100644 --- a/shell/platform/windows/client_wrapper/flutter_view_controller.cc +++ b/shell/platform/windows/client_wrapper/flutter_view_controller.cc @@ -29,6 +29,7 @@ FlutterViewController::~FlutterViewController() { } } +#ifndef FLUTTER_WINUWP std::optional FlutterViewController::HandleTopLevelWindowProc( HWND hwnd, UINT message, @@ -39,5 +40,6 @@ std::optional FlutterViewController::HandleTopLevelWindowProc( controller_, hwnd, message, wparam, lparam, &result); return handled ? result : std::optional(std::nullopt); } +#endif } // namespace flutter diff --git a/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h b/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h index 7231fb790b450..916ee4dfd35cf 100644 --- a/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h +++ b/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h @@ -46,6 +46,7 @@ class FlutterViewController { // Returns the view managed by this controller. FlutterView* view() { return view_.get(); } +#ifndef FLUTTER_WINUWP // Allows the Flutter engine and any interested plugins an opportunity to // handle the given message. // @@ -55,6 +56,7 @@ class FlutterViewController { UINT message, WPARAM wparam, LPARAM lparam); + #endif private: // Handle for interacting with the C API's view controller, if any. diff --git a/shell/platform/windows/flutter_project_bundle.cc b/shell/platform/windows/flutter_project_bundle.cc index 4b2c8dfef69be..833c197875122 100644 --- a/shell/platform/windows/flutter_project_bundle.cc +++ b/shell/platform/windows/flutter_project_bundle.cc @@ -7,7 +7,7 @@ #include #include -#include "flutter/shell/platform/common/cpp/engine_switches.h" +#include "flutter/shell/platform/common/cpp/engine_switches.h" // nogncheck #include "flutter/shell/platform/common/cpp/path_utils.h" namespace flutter { diff --git a/shell/platform/windows/flutter_windows.cc b/shell/platform/windows/flutter_windows.cc index d5963a2122632..29424bfa1c235 100644 --- a/shell/platform/windows/flutter_windows.cc +++ b/shell/platform/windows/flutter_windows.cc @@ -22,9 +22,11 @@ #include "flutter/shell/platform/windows/flutter_project_bundle.h" #include "flutter/shell/platform/windows/flutter_windows_engine.h" #include "flutter/shell/platform/windows/flutter_windows_view.h" -#include "flutter/shell/platform/windows/win32_dpi_utils.h" -#include "flutter/shell/platform/windows/win32_flutter_window.h" -#include "flutter/shell/platform/windows/win32_task_runner.h" +#ifndef FLUTTER_WINUWP +#include "flutter/shell/platform/windows/win32_dpi_utils.h" // nogncheck +#include "flutter/shell/platform/windows/win32_flutter_window.h" // nogncheck +#include "flutter/shell/platform/windows/win32_task_runner.h" // nogncheck +#endif #include "flutter/shell/platform/windows/window_binding_handler.h" #include "flutter/shell/platform/windows/window_state.h" @@ -56,6 +58,7 @@ FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate( int width, int height, FlutterDesktopEngineRef engine) { +#ifndef FLUTTER_WINUWP std::unique_ptr window_wrapper = std::make_unique(width, height); @@ -76,6 +79,9 @@ FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate( // Must happen after engine is running. state->view->SendInitialBounds(); return state.release(); +#else + return nullptr; +#endif } void FlutterDesktopViewControllerDestroy( @@ -93,6 +99,7 @@ FlutterDesktopViewRef FlutterDesktopViewControllerGetView( return HandleForView(controller->view.get()); } +#ifndef FLUTTER_WINUWP bool FlutterDesktopViewControllerHandleTopLevelWindowProc( FlutterDesktopViewControllerRef controller, HWND hwnd, @@ -109,6 +116,7 @@ bool FlutterDesktopViewControllerHandleTopLevelWindowProc( } return delegate_result.has_value(); } +#endif FlutterDesktopEngineRef FlutterDesktopEngineCreate( const FlutterDesktopEngineProperties& engine_properties) { @@ -133,7 +141,11 @@ bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, } uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine) { +#ifndef FLUTTER_WINUWP return EngineFromHandle(engine)->task_runner()->ProcessTasks().count(); +#else + return 0; +#endif } void FlutterDesktopEngineReloadSystemFonts(FlutterDesktopEngineRef engine) { @@ -168,17 +180,22 @@ void FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate( FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopWindowProcCallback delegate, void* user_data) { +#ifndef FLUTTER_WINUWP registrar->engine->window_proc_delegate_manager() ->RegisterTopLevelWindowProcDelegate(delegate, user_data); +#endif } void FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate( FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopWindowProcCallback delegate) { +#ifndef FLUTTER_WINUWP registrar->engine->window_proc_delegate_manager() ->UnregisterTopLevelWindowProcDelegate(delegate); +#endif } +#ifndef FLUTTER_WINUWP UINT FlutterDesktopGetDpiForHWND(HWND hwnd) { return flutter::GetDpiForHWND(hwnd); } @@ -186,6 +203,7 @@ UINT FlutterDesktopGetDpiForHWND(HWND hwnd) { UINT FlutterDesktopGetDpiForMonitor(HMONITOR monitor) { return flutter::GetDpiForMonitor(monitor); } +#endif void FlutterDesktopResyncOutputStreams() { FILE* unused; diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc index d70ca504c1b56..ffd834a70c392 100644 --- a/shell/platform/windows/flutter_windows_engine.cc +++ b/shell/platform/windows/flutter_windows_engine.cc @@ -91,6 +91,7 @@ FlutterLocale CovertToFlutterLocale(const LanguageInfo& info) { FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project) : project_(std::make_unique(project)) { +#ifndef FLUTTER_WINUWP task_runner_ = std::make_unique( GetCurrentThreadId(), [this](const auto* task) { if (!engine_) { @@ -102,6 +103,7 @@ FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project) std::cerr << "Failed to post an engine task." << std::endl; } }); +#endif // Set up the legacy structs backing the API handles. messenger_ = std::make_unique(); @@ -111,8 +113,10 @@ FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project) message_dispatcher_ = std::make_unique(messenger_.get()); +#ifndef FLUTTER_WINUWP window_proc_delegate_manager_ = std::make_unique(); +#endif } FlutterWindowsEngine::~FlutterWindowsEngine() { @@ -143,6 +147,7 @@ bool FlutterWindowsEngine::RunWithEntrypoint(const char* entrypoint) { switches.begin(), switches.end(), std::back_inserter(argv), [](const std::string& arg) -> const char* { return arg.c_str(); }); +#ifndef FLUTTER_WINUWP // Configure task runners. FlutterTaskRunnerDescription platform_task_runner = {}; platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription); @@ -159,6 +164,7 @@ bool FlutterWindowsEngine::RunWithEntrypoint(const char* entrypoint) { FlutterCustomTaskRunners custom_task_runners = {}; custom_task_runners.struct_size = sizeof(FlutterCustomTaskRunners); custom_task_runners.platform_task_runner = &platform_task_runner; +#endif FlutterProjectArgs args = {}; args.struct_size = sizeof(FlutterProjectArgs); @@ -172,7 +178,9 @@ bool FlutterWindowsEngine::RunWithEntrypoint(const char* entrypoint) { auto host = static_cast(user_data); return host->HandlePlatformMessage(engine_message); }; +#ifndef FLUTTER_WINUWP args.custom_task_runners = &custom_task_runners; +#endif if (aot_data_) { args.aot_data = aot_data_.get(); } diff --git a/shell/platform/windows/flutter_windows_engine.h b/shell/platform/windows/flutter_windows_engine.h index 49c0fc7f2a8cf..c8c803dcbe21b 100644 --- a/shell/platform/windows/flutter_windows_engine.h +++ b/shell/platform/windows/flutter_windows_engine.h @@ -13,8 +13,10 @@ #include "flutter/shell/platform/common/cpp/incoming_message_dispatcher.h" #include "flutter/shell/platform/windows/flutter_project_bundle.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" -#include "flutter/shell/platform/windows/win32_task_runner.h" -#include "flutter/shell/platform/windows/win32_window_proc_delegate_manager.h" +#ifndef FLUTTER_WINUWP +#include "flutter/shell/platform/windows/win32_task_runner.h" // nogncheck +#include "flutter/shell/platform/windows/win32_window_proc_delegate_manager.h" // nogncheck +#endif #include "flutter/shell/platform/windows/window_state.h" namespace flutter { @@ -73,11 +75,13 @@ class FlutterWindowsEngine { return message_dispatcher_.get(); } +#ifndef FLUTTER_WINUWP Win32TaskRunner* task_runner() { return task_runner_.get(); } Win32WindowProcDelegateManager* window_proc_delegate_manager() { return window_proc_delegate_manager_.get(); } +#endif // Callback passed to Flutter engine for notifying window of platform // messages. @@ -101,8 +105,10 @@ class FlutterWindowsEngine { // The view displaying the content running in this engine, if any. FlutterWindowsView* view_ = nullptr; +#ifndef FLUTTER_WINUWP // Task runner for tasks posted from the engine. std::unique_ptr task_runner_; +#endif // The plugin messenger handle given to API clients. std::unique_ptr messenger_; @@ -118,8 +124,10 @@ class FlutterWindowsEngine { FlutterDesktopOnPluginRegistrarDestroyed plugin_registrar_destruction_callback_; +#ifndef FLUTTER_WINUWP // The manager for WindowProc delegate registration and callbacks. std::unique_ptr window_proc_delegate_manager_; +#endif }; } // namespace flutter diff --git a/shell/platform/windows/flutter_windows_view.cc b/shell/platform/windows/flutter_windows_view.cc index 415f074a8e99f..db47d27ac6da1 100644 --- a/shell/platform/windows/flutter_windows_view.cc +++ b/shell/platform/windows/flutter_windows_view.cc @@ -39,8 +39,10 @@ void FlutterWindowsView::SetEngine( std::make_unique(internal_plugin_messenger)); keyboard_hook_handlers_.push_back( std::make_unique(internal_plugin_messenger)); +#ifndef FLUTTER_WINUWP platform_handler_ = std::make_unique( internal_plugin_messenger, this); +#endif cursor_handler_ = std::make_unique( internal_plugin_messenger, binding_handler_.get()); diff --git a/shell/platform/windows/flutter_windows_view.h b/shell/platform/windows/flutter_windows_view.h index f4e1186c6e034..c88b8ad2bbe53 100644 --- a/shell/platform/windows/flutter_windows_view.h +++ b/shell/platform/windows/flutter_windows_view.h @@ -20,7 +20,9 @@ #include "flutter/shell/platform/windows/keyboard_hook_handler.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" #include "flutter/shell/platform/windows/text_input_plugin.h" -#include "flutter/shell/platform/windows/win32_platform_handler.h" +#ifndef FLUTTER_WINUWP +#include "flutter/shell/platform/windows/win32_platform_handler.h" // nogncheck +#endif #include "flutter/shell/platform/windows/window_binding_handler.h" #include "flutter/shell/platform/windows/window_binding_handler_delegate.h" #include "flutter/shell/platform/windows/window_state.h" @@ -198,8 +200,10 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate { std::vector> keyboard_hook_handlers_; +#ifndef FLUTTER_WINUWP // Handler for the flutter/platform channel. std::unique_ptr platform_handler_; +#endif // Handler for cursor events. std::unique_ptr cursor_handler_; diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index 25414937e54f6..27e018524834a 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -85,6 +85,7 @@ FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine( FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef controller); + #ifndef FLUTTER_WINUWP // Allows the Flutter engine and any interested plugins an opportunity to // handle the given message. // @@ -97,6 +98,7 @@ FLUTTER_EXPORT bool FlutterDesktopViewControllerHandleTopLevelWindowProc( WPARAM wparam, LPARAM lparam, LRESULT* result); +#endif // ========== Engine ========== diff --git a/shell/platform/windows/system_utils_winuwp.cc b/shell/platform/windows/system_utils_winuwp.cc new file mode 100644 index 0000000000000..4d693def5a758 --- /dev/null +++ b/shell/platform/windows/system_utils_winuwp.cc @@ -0,0 +1,35 @@ +// 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/system_utils.h" + +#include + +#include + +#include "flutter/shell/platform/windows/string_conversion.h" + +namespace flutter { + +std::vector GetPreferredLanguageInfo() { + std::vector languages = GetPreferredLanguages(); + std::vector language_info; + // TODO populate via WinRT + return language_info; +} + +std::vector GetPreferredLanguages() { + std::vector languages; + // TODO populate via WinRT + return languages; +} + +LanguageInfo ParseLanguageName(std::wstring language_name) { + LanguageInfo info; + + // TODO populate via WinRT + return info; +} + +} // namespace flutter diff --git a/tools/gn b/tools/gn index 7514665b2dd6e..1ee74de6e5760 100755 --- a/tools/gn +++ b/tools/gn @@ -139,6 +139,10 @@ def to_gn_args(args): elif args.target_os == 'fuchsia': gn_args['target_os'] = 'fuchsia' gn_args['flutter_enable_legacy_fuchsia_embedder'] = args.fuchsia_legacy + elif args.target_os == 'winuwp': + gn_args['target_os'] = 'winuwp' + # Enabling angle_is_winuwp is dependent on an in-flight patch to https://chromium.googlesource.com/angle/angle to update UWP support + # gn_args['angle_is_winuwp'] = True elif args.target_os is not None: gn_args['target_os'] = args.target_os @@ -316,6 +320,7 @@ def parse_args(args): parser.add_argument('--fuchsia', dest='target_os', action='store_const', const='fuchsia') parser.add_argument('--fuchsia-legacy', default=True, action='store_true') parser.add_argument('--no-fuchsia-legacy', dest='fuchsia_legacy', action='store_false') + parser.add_argument('--winuwp', dest='target_os', action='store_const', const='winuwp') parser.add_argument('--linux-cpu', type=str, choices=['x64', 'x86', 'arm64', 'arm']) parser.add_argument('--fuchsia-cpu', type=str, choices=['x64', 'arm64'], default = 'x64') From df7af06f4c590fb7b47d9a0778bd11cf8e6eba41 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 31 Oct 2020 08:48:21 -0700 Subject: [PATCH 02/19] CR feedback --- BUILD.gn | 18 +-- shell/platform/windows/BUILD.gn | 118 +++++------------- .../client_wrapper/flutter_view_controller.cc | 2 +- .../include/flutter/flutter_view_controller.h | 2 +- shell/platform/windows/flutter_windows.cc | 20 +-- .../windows/flutter_windows_engine.cc | 7 +- .../platform/windows/flutter_windows_engine.h | 8 +- .../platform/windows/flutter_windows_view.cc | 2 +- shell/platform/windows/flutter_windows_view.h | 4 +- .../platform/windows/public/flutter_windows.h | 2 +- 10 files changed, 64 insertions(+), 119 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 4d5a9a51cd47b..8eefbf9b7dcd1 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -145,14 +145,16 @@ group("flutter") { public_deps += [ "//flutter/shell/platform/darwin/macos:flutter_desktop_darwin_unittests" ] } - if (is_win && target_os != "winuwp") { - public_deps += [ - "//flutter/shell/platform/windows:flutter_windows_unittests", - "//flutter/shell/platform/windows/client_wrapper:client_wrapper_windows_unittests", - ] - } else if (is_win) { - # TODO once the UWP implmentation lands, reference future flutter_windows_unittests_winrt - # runner implementation from here + if (is_win) { + if (target_os == "winuwp") { + # TODO once the UWP implmentation lands, reference future flutter_windows_unittests_winrt + # runner implementation from here. + } else { + public_deps += [ + "//flutter/shell/platform/windows:flutter_windows_unittests", + "//flutter/shell/platform/windows/client_wrapper:client_wrapper_windows_unittests", + ] + } } } } diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index 7b98267ba8676..1bf1ac0302947 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -21,9 +21,10 @@ config("relative_flutter_windows_headers") { include_dirs = [ "public" ] } -# When OS target is WinUWP use FLUTTER_WINUWP as the preprocessor flag to conditionalize +# TODO: Move to builtroot build/config/win/BUILD.gn when the UWP compliant change to that project lands. +# When OS target is WinUWP use WINUWP as the preprocessor flag to conditionalize. config("flutter_windows_winuwp_defs") { - defines = [ "FLUTTER_WINUWP 1" ] + defines = [ "WINUWP" ] } # The headers are a separate source set since the client wrapper is allowed @@ -49,6 +50,7 @@ source_set("flutter_windows_headers") { } source_set("flutter_windows_source") { + # Common Windows sources. sources = [ "angle_surface_manager.cc", "angle_surface_manager.h", @@ -67,84 +69,43 @@ source_set("flutter_windows_source") { "string_conversion.cc", "string_conversion.h", "system_utils.h", - "system_utils_win32.cc", "text_input_plugin.cc", "text_input_plugin.h", - "win32_dpi_utils.cc", - "win32_dpi_utils.h", - "win32_flutter_window.cc", - "win32_flutter_window.h", - "win32_platform_handler.cc", - "win32_platform_handler.h", - "win32_task_runner.cc", - "win32_task_runner.h", - "win32_window.cc", - "win32_window.h", - "win32_window_proc_delegate_manager.cc", - "win32_window_proc_delegate_manager.h", "window_binding_handler.h", "window_binding_handler_delegate.h", "window_state.h", ] - configs += [ - "//flutter/shell/platform/common/cpp:desktop_library_implementation", - "//third_party/angle:gl_prototypes", - ] - - public_configs = [ ":relative_angle_headers" ] - - deps = [ - ":flutter_windows_headers", - "//flutter/shell/platform/common/cpp:common_cpp", - "//flutter/shell/platform/common/cpp:common_cpp_input", - "//flutter/shell/platform/common/cpp:common_cpp_switches", - "//flutter/shell/platform/common/cpp/client_wrapper:client_wrapper", - "//flutter/shell/platform/embedder:embedder_as_internal_library", - "//flutter/shell/platform/windows/client_wrapper:client_wrapper_windows", - "//third_party/angle:libEGL_static", # the order of libEGL_static and - # libGLESv2_static is important.. if - # reversed, will cause a linker error - # DllMain already defined in - # LIBCMTD.lib - "//third_party/angle:libGLESv2_static", - "//third_party/rapidjson", - ] -} - -source_set("flutter_winuwp_source") { - sources = [ - "angle_surface_manager.cc", - "angle_surface_manager.h", - "cursor_handler.cc", - "cursor_handler.h", - "flutter_project_bundle.cc", - "flutter_project_bundle.h", - "flutter_windows.cc", - "flutter_windows_engine.cc", - "flutter_windows_engine.h", - "flutter_windows_view.cc", - "flutter_windows_view.h", - "key_event_handler.cc", - "key_event_handler.h", - "keyboard_hook_handler.h", - "string_conversion.cc", - "string_conversion.h", - "system_utils.h", - "system_utils_winuwp.cc", - "text_input_plugin.cc", - "text_input_plugin.h", - "window_binding_handler.h", - "window_binding_handler_delegate.h", - "window_state.h", - ] + # Target-specific sources. + if (target_os == "winuwp") { + sources += [ "system_utils_winuwp.cc" ] + } else { + sources += [ + "system_utils_win32.cc", + "win32_dpi_utils.cc", + "win32_dpi_utils.h", + "win32_flutter_window.cc", + "win32_flutter_window.h", + "win32_platform_handler.cc", + "win32_platform_handler.h", + "win32_task_runner.cc", + "win32_task_runner.h", + "win32_window.cc", + "win32_window.h", + "win32_window_proc_delegate_manager.cc", + "win32_window_proc_delegate_manager.h", + ] + } configs += [ "//flutter/shell/platform/common/cpp:desktop_library_implementation", "//third_party/angle:gl_prototypes", - ":flutter_windows_winuwp_defs", ] + if (target_os == "winuwp") { + configs += [ ":flutter_windows_winuwp_defs" ] + } + public_configs = [ ":relative_angle_headers" ] deps = [ @@ -180,7 +141,7 @@ shared_library("flutter_windows") { } shared_library("flutter_windows_winuwp") { - deps = [ ":flutter_winuwp_source" ] + deps = [ ":flutter_windows_source" ] libs = [ "windowsapp.lib" ] public_configs = [ "//flutter:config" ] } @@ -191,27 +152,6 @@ test_fixtures("flutter_windows_fixtures") { if (target_os == "winuwp") { # disabled until the uwp implementation is present - # executable("flutter_windows_unittests_winrt") { - # testonly = true - - # sources = [ - # "flutter_project_bundle_unittests.cc", - # "string_conversion_unittests.cc", - # "system_utils_unittests.cc", - # ] - - # public_configs = [ "//flutter:config" ] - - # libs = [ "windowsapp.lib" ] - - # deps = [ - # ":flutter_windows_fixtures", - # ":flutter_windows_headers", - # ":flutter_windows_source", - # "//flutter/testing", - # "//third_party/rapidjson", - # ] - # } } else { executable("flutter_windows_unittests") { testonly = true diff --git a/shell/platform/windows/client_wrapper/flutter_view_controller.cc b/shell/platform/windows/client_wrapper/flutter_view_controller.cc index 65817524f8497..2724b27881f22 100644 --- a/shell/platform/windows/client_wrapper/flutter_view_controller.cc +++ b/shell/platform/windows/client_wrapper/flutter_view_controller.cc @@ -29,7 +29,7 @@ FlutterViewController::~FlutterViewController() { } } -#ifndef FLUTTER_WINUWP +#ifndef WINUWP std::optional FlutterViewController::HandleTopLevelWindowProc( HWND hwnd, UINT message, diff --git a/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h b/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h index 916ee4dfd35cf..6a21af0922b81 100644 --- a/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h +++ b/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h @@ -46,7 +46,7 @@ class FlutterViewController { // Returns the view managed by this controller. FlutterView* view() { return view_.get(); } -#ifndef FLUTTER_WINUWP +#ifndef WINUWP // Allows the Flutter engine and any interested plugins an opportunity to // handle the given message. // diff --git a/shell/platform/windows/flutter_windows.cc b/shell/platform/windows/flutter_windows.cc index 29424bfa1c235..49f9cedbbec38 100644 --- a/shell/platform/windows/flutter_windows.cc +++ b/shell/platform/windows/flutter_windows.cc @@ -22,13 +22,14 @@ #include "flutter/shell/platform/windows/flutter_project_bundle.h" #include "flutter/shell/platform/windows/flutter_windows_engine.h" #include "flutter/shell/platform/windows/flutter_windows_view.h" -#ifndef FLUTTER_WINUWP +#include "flutter/shell/platform/windows/window_binding_handler.h" +#include "flutter/shell/platform/windows/window_state.h" + +#ifndef WINUWP #include "flutter/shell/platform/windows/win32_dpi_utils.h" // nogncheck #include "flutter/shell/platform/windows/win32_flutter_window.h" // nogncheck #include "flutter/shell/platform/windows/win32_task_runner.h" // nogncheck #endif -#include "flutter/shell/platform/windows/window_binding_handler.h" -#include "flutter/shell/platform/windows/window_state.h" static_assert(FLUTTER_ENGINE_VERSION == 1, ""); @@ -58,7 +59,7 @@ FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate( int width, int height, FlutterDesktopEngineRef engine) { -#ifndef FLUTTER_WINUWP +#ifndef WINUWP std::unique_ptr window_wrapper = std::make_unique(width, height); @@ -99,7 +100,7 @@ FlutterDesktopViewRef FlutterDesktopViewControllerGetView( return HandleForView(controller->view.get()); } -#ifndef FLUTTER_WINUWP +#ifndef WINUWP bool FlutterDesktopViewControllerHandleTopLevelWindowProc( FlutterDesktopViewControllerRef controller, HWND hwnd, @@ -141,9 +142,10 @@ bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, } uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine) { -#ifndef FLUTTER_WINUWP +#ifndef WINUWP return EngineFromHandle(engine)->task_runner()->ProcessTasks().count(); #else + // TODO add WINUWP implementation. return 0; #endif } @@ -180,7 +182,7 @@ void FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate( FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopWindowProcCallback delegate, void* user_data) { -#ifndef FLUTTER_WINUWP +#ifndef WINUWP registrar->engine->window_proc_delegate_manager() ->RegisterTopLevelWindowProcDelegate(delegate, user_data); #endif @@ -189,13 +191,13 @@ void FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate( void FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate( FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopWindowProcCallback delegate) { -#ifndef FLUTTER_WINUWP +#ifndef WINUWP registrar->engine->window_proc_delegate_manager() ->UnregisterTopLevelWindowProcDelegate(delegate); #endif } -#ifndef FLUTTER_WINUWP +#ifndef WINUWP UINT FlutterDesktopGetDpiForHWND(HWND hwnd) { return flutter::GetDpiForHWND(hwnd); } diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc index c083479dc6eda..d5a6f255526d1 100644 --- a/shell/platform/windows/flutter_windows_engine.cc +++ b/shell/platform/windows/flutter_windows_engine.cc @@ -91,7 +91,7 @@ FlutterLocale CovertToFlutterLocale(const LanguageInfo& info) { FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project) : project_(std::make_unique(project)) { -#ifndef FLUTTER_WINUWP +#ifndef WINUWP task_runner_ = std::make_unique( GetCurrentThreadId(), [this](const auto* task) { if (!engine_) { @@ -113,7 +113,7 @@ FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project) message_dispatcher_ = std::make_unique(messenger_.get()); -#ifndef FLUTTER_WINUWP +#ifndef WINUWP window_proc_delegate_manager_ = std::make_unique(); #endif @@ -155,6 +155,7 @@ bool FlutterWindowsEngine::RunWithEntrypoint(const char* entrypoint) { std::back_inserter(entrypoint_argv), [](const std::string& arg) -> const char* { return arg.c_str(); }); +#ifndef FLUTTER_WINRT // Configure task runners. FlutterTaskRunnerDescription platform_task_runner = {}; platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription); @@ -188,7 +189,7 @@ bool FlutterWindowsEngine::RunWithEntrypoint(const char* entrypoint) { auto host = static_cast(user_data); return host->HandlePlatformMessage(engine_message); }; -#ifndef FLUTTER_WINUWP +#ifndef WINUWP args.custom_task_runners = &custom_task_runners; #endif if (aot_data_) { diff --git a/shell/platform/windows/flutter_windows_engine.h b/shell/platform/windows/flutter_windows_engine.h index c8c803dcbe21b..8696934e8501f 100644 --- a/shell/platform/windows/flutter_windows_engine.h +++ b/shell/platform/windows/flutter_windows_engine.h @@ -13,7 +13,7 @@ #include "flutter/shell/platform/common/cpp/incoming_message_dispatcher.h" #include "flutter/shell/platform/windows/flutter_project_bundle.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" -#ifndef FLUTTER_WINUWP +#ifndef WINUWP #include "flutter/shell/platform/windows/win32_task_runner.h" // nogncheck #include "flutter/shell/platform/windows/win32_window_proc_delegate_manager.h" // nogncheck #endif @@ -75,7 +75,7 @@ class FlutterWindowsEngine { return message_dispatcher_.get(); } -#ifndef FLUTTER_WINUWP +#ifndef WINUWP Win32TaskRunner* task_runner() { return task_runner_.get(); } Win32WindowProcDelegateManager* window_proc_delegate_manager() { @@ -105,7 +105,7 @@ class FlutterWindowsEngine { // The view displaying the content running in this engine, if any. FlutterWindowsView* view_ = nullptr; -#ifndef FLUTTER_WINUWP +#ifndef WINUWP // Task runner for tasks posted from the engine. std::unique_ptr task_runner_; #endif @@ -124,7 +124,7 @@ class FlutterWindowsEngine { FlutterDesktopOnPluginRegistrarDestroyed plugin_registrar_destruction_callback_; -#ifndef FLUTTER_WINUWP +#ifndef WINUWP // The manager for WindowProc delegate registration and callbacks. std::unique_ptr window_proc_delegate_manager_; #endif diff --git a/shell/platform/windows/flutter_windows_view.cc b/shell/platform/windows/flutter_windows_view.cc index db47d27ac6da1..4436fced4890d 100644 --- a/shell/platform/windows/flutter_windows_view.cc +++ b/shell/platform/windows/flutter_windows_view.cc @@ -39,7 +39,7 @@ void FlutterWindowsView::SetEngine( std::make_unique(internal_plugin_messenger)); keyboard_hook_handlers_.push_back( std::make_unique(internal_plugin_messenger)); -#ifndef FLUTTER_WINUWP +#ifndef WINUWP platform_handler_ = std::make_unique( internal_plugin_messenger, this); #endif diff --git a/shell/platform/windows/flutter_windows_view.h b/shell/platform/windows/flutter_windows_view.h index c88b8ad2bbe53..462a2285d0879 100644 --- a/shell/platform/windows/flutter_windows_view.h +++ b/shell/platform/windows/flutter_windows_view.h @@ -20,7 +20,7 @@ #include "flutter/shell/platform/windows/keyboard_hook_handler.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" #include "flutter/shell/platform/windows/text_input_plugin.h" -#ifndef FLUTTER_WINUWP +#ifndef WINUWP #include "flutter/shell/platform/windows/win32_platform_handler.h" // nogncheck #endif #include "flutter/shell/platform/windows/window_binding_handler.h" @@ -200,7 +200,7 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate { std::vector> keyboard_hook_handlers_; -#ifndef FLUTTER_WINUWP +#ifndef WINUWP // Handler for the flutter/platform channel. std::unique_ptr platform_handler_; #endif diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index d03ff9052c2b3..69269ff339665 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -92,7 +92,7 @@ FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine( FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef controller); - #ifndef FLUTTER_WINUWP + #ifndef WINUWP // Allows the Flutter engine and any interested plugins an opportunity to // handle the given message. // From 925c5715204dab9abcf46a0c3019120e1340c38a Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 31 Oct 2020 11:35:51 -0700 Subject: [PATCH 03/19] Update licenses --- ci/licenses_golden/licenses_flutter | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index f13271aa91373..25b78b13efa30 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1412,6 +1412,7 @@ FILE: ../../../flutter/shell/platform/windows/string_conversion_unittests.cc FILE: ../../../flutter/shell/platform/windows/system_utils.h FILE: ../../../flutter/shell/platform/windows/system_utils_unittests.cc FILE: ../../../flutter/shell/platform/windows/system_utils_win32.cc +FILE: ../../../flutter/shell/platform/windows/system_utils_winuwp.cc FILE: ../../../flutter/shell/platform/windows/text_input_plugin.cc FILE: ../../../flutter/shell/platform/windows/text_input_plugin.h FILE: ../../../flutter/shell/platform/windows/win32_dpi_utils.cc From 8ec92beb5965eb830a620901819e56c8b09e920a Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 31 Oct 2020 12:23:20 -0700 Subject: [PATCH 04/19] Move the flutter_windows_winuwp_defs to buildroot --- shell/platform/windows/BUILD.gn | 10 ++-------- shell/platform/windows/client_wrapper/BUILD.gn | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index 1bf1ac0302947..919ccc0296288 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -21,12 +21,6 @@ config("relative_flutter_windows_headers") { include_dirs = [ "public" ] } -# TODO: Move to builtroot build/config/win/BUILD.gn when the UWP compliant change to that project lands. -# When OS target is WinUWP use WINUWP as the preprocessor flag to conditionalize. -config("flutter_windows_winuwp_defs") { - defines = [ "WINUWP" ] -} - # 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") { @@ -38,7 +32,7 @@ source_set("flutter_windows_headers") { if (target_os == "winuwp") { configs += [ "//flutter/shell/platform/common/cpp:desktop_library_implementation", - ":flutter_windows_winuwp_defs", + "//build/config/win:flutter_windows_winuwp_defs", ] } else { configs += @@ -103,7 +97,7 @@ source_set("flutter_windows_source") { ] if (target_os == "winuwp") { - configs += [ ":flutter_windows_winuwp_defs" ] + configs += [ "//build/config/win:flutter_windows_winuwp_defs" ] } public_configs = [ ":relative_angle_headers" ] diff --git a/shell/platform/windows/client_wrapper/BUILD.gn b/shell/platform/windows/client_wrapper/BUILD.gn index 155d87575e74f..1f96788d5c2b1 100644 --- a/shell/platform/windows/client_wrapper/BUILD.gn +++ b/shell/platform/windows/client_wrapper/BUILD.gn @@ -41,7 +41,7 @@ source_set("client_wrapper_windows") { configs += [ "//flutter/shell/platform/common/cpp:desktop_library_implementation", - "//flutter/shell/platform/windows:flutter_windows_winuwp_defs", + "//build/config/win:flutter_windows_winuwp_defs", ] public_configs = [ From 642332dcbecb92262dce31767946c7a25f011386 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Thu, 5 Nov 2020 06:11:59 -0800 Subject: [PATCH 05/19] CR Feedback: UWP ifdef applied automatically by buildroot --- shell/platform/windows/BUILD.gn | 5 ----- shell/platform/windows/client_wrapper/BUILD.gn | 1 - 2 files changed, 6 deletions(-) diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index 919ccc0296288..7070243568d77 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -32,7 +32,6 @@ source_set("flutter_windows_headers") { if (target_os == "winuwp") { configs += [ "//flutter/shell/platform/common/cpp:desktop_library_implementation", - "//build/config/win:flutter_windows_winuwp_defs", ] } else { configs += @@ -96,10 +95,6 @@ source_set("flutter_windows_source") { "//third_party/angle:gl_prototypes", ] - if (target_os == "winuwp") { - configs += [ "//build/config/win:flutter_windows_winuwp_defs" ] - } - public_configs = [ ":relative_angle_headers" ] deps = [ diff --git a/shell/platform/windows/client_wrapper/BUILD.gn b/shell/platform/windows/client_wrapper/BUILD.gn index 1f96788d5c2b1..15fc0d4c16d33 100644 --- a/shell/platform/windows/client_wrapper/BUILD.gn +++ b/shell/platform/windows/client_wrapper/BUILD.gn @@ -41,7 +41,6 @@ source_set("client_wrapper_windows") { configs += [ "//flutter/shell/platform/common/cpp:desktop_library_implementation", - "//build/config/win:flutter_windows_winuwp_defs", ] public_configs = [ From 0607fa02005c0b26f5e0ad028fbca5557d172c62 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Thu, 5 Nov 2020 07:01:57 -0800 Subject: [PATCH 06/19] CR feedback: split flutter_windows.cc --- ci/licenses_golden/licenses_flutter | 2 + shell/platform/windows/BUILD.gn | 2 + shell/platform/windows/flutter_windows.cc | 93 ------------------ .../platform/windows/flutter_windows_win32.cc | 95 +++++++++++++++++++ .../windows/flutter_windows_winuwp.cc | 45 +++++++++ 5 files changed, 144 insertions(+), 93 deletions(-) create mode 100644 shell/platform/windows/flutter_windows_win32.cc create mode 100644 shell/platform/windows/flutter_windows_winuwp.cc diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 25b78b13efa30..a7e9ac9bd0ec2 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1398,6 +1398,8 @@ FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle.cc FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle.h FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle_unittests.cc FILE: ../../../flutter/shell/platform/windows/flutter_windows.cc +FILE: ../../../flutter/shell/platform/windows/flutter_windows_win32.cc +FILE: ../../../flutter/shell/platform/windows/flutter_windows_winuwp.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_view.cc diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index 7070243568d77..cbf24ea03da0d 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -71,9 +71,11 @@ source_set("flutter_windows_source") { # Target-specific sources. if (target_os == "winuwp") { + sources += [ "flutter_windows_winuwp.cc" ] sources += [ "system_utils_winuwp.cc" ] } else { sources += [ + "flutter_windows_win32.cc", "system_utils_win32.cc", "win32_dpi_utils.cc", "win32_dpi_utils.h", diff --git a/shell/platform/windows/flutter_windows.cc b/shell/platform/windows/flutter_windows.cc index 49f9cedbbec38..f15f2bf6636dd 100644 --- a/shell/platform/windows/flutter_windows.cc +++ b/shell/platform/windows/flutter_windows.cc @@ -25,12 +25,6 @@ #include "flutter/shell/platform/windows/window_binding_handler.h" #include "flutter/shell/platform/windows/window_state.h" -#ifndef WINUWP -#include "flutter/shell/platform/windows/win32_dpi_utils.h" // nogncheck -#include "flutter/shell/platform/windows/win32_flutter_window.h" // nogncheck -#include "flutter/shell/platform/windows/win32_task_runner.h" // nogncheck -#endif - static_assert(FLUTTER_ENGINE_VERSION == 1, ""); // Returns the engine corresponding to the given opaque API handle. @@ -55,36 +49,6 @@ static FlutterDesktopViewRef HandleForView(flutter::FlutterWindowsView* view) { return reinterpret_cast(view); } -FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate( - int width, - int height, - FlutterDesktopEngineRef engine) { -#ifndef WINUWP - std::unique_ptr window_wrapper = - std::make_unique(width, height); - - auto state = std::make_unique(); - state->view = - std::make_unique(std::move(window_wrapper)); - state->view->CreateRenderSurface(); - - // Take ownership of the engine, starting it if necessary. - state->view->SetEngine( - std::unique_ptr(EngineFromHandle(engine))); - if (!state->view->GetEngine()->running()) { - if (!state->view->GetEngine()->RunWithEntrypoint(nullptr)) { - return nullptr; - } - } - - // Must happen after engine is running. - state->view->SendInitialBounds(); - return state.release(); -#else - return nullptr; -#endif -} - void FlutterDesktopViewControllerDestroy( FlutterDesktopViewControllerRef controller) { delete controller; @@ -100,25 +64,6 @@ FlutterDesktopViewRef FlutterDesktopViewControllerGetView( return HandleForView(controller->view.get()); } -#ifndef WINUWP -bool FlutterDesktopViewControllerHandleTopLevelWindowProc( - FlutterDesktopViewControllerRef controller, - HWND hwnd, - UINT message, - WPARAM wparam, - LPARAM lparam, - LRESULT* result) { - std::optional delegate_result = - controller->view->GetEngine() - ->window_proc_delegate_manager() - ->OnTopLevelWindowProc(hwnd, message, wparam, lparam); - if (delegate_result) { - *result = *delegate_result; - } - return delegate_result.has_value(); -} -#endif - FlutterDesktopEngineRef FlutterDesktopEngineCreate( const FlutterDesktopEngineProperties& engine_properties) { flutter::FlutterProjectBundle project(engine_properties); @@ -141,15 +86,6 @@ bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, return EngineFromHandle(engine)->RunWithEntrypoint(entry_point); } -uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine) { -#ifndef WINUWP - return EngineFromHandle(engine)->task_runner()->ProcessTasks().count(); -#else - // TODO add WINUWP implementation. - return 0; -#endif -} - void FlutterDesktopEngineReloadSystemFonts(FlutterDesktopEngineRef engine) { FlutterEngineReloadSystemFonts(EngineFromHandle(engine)->engine()); } @@ -178,35 +114,6 @@ FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView( return HandleForView(registrar->engine->view()); } -void FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate( - FlutterDesktopPluginRegistrarRef registrar, - FlutterDesktopWindowProcCallback delegate, - void* user_data) { -#ifndef WINUWP - registrar->engine->window_proc_delegate_manager() - ->RegisterTopLevelWindowProcDelegate(delegate, user_data); -#endif -} - -void FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate( - FlutterDesktopPluginRegistrarRef registrar, - FlutterDesktopWindowProcCallback delegate) { -#ifndef WINUWP - registrar->engine->window_proc_delegate_manager() - ->UnregisterTopLevelWindowProcDelegate(delegate); -#endif -} - -#ifndef WINUWP -UINT FlutterDesktopGetDpiForHWND(HWND hwnd) { - return flutter::GetDpiForHWND(hwnd); -} - -UINT FlutterDesktopGetDpiForMonitor(HMONITOR monitor) { - return flutter::GetDpiForMonitor(monitor); -} -#endif - void FlutterDesktopResyncOutputStreams() { FILE* unused; if (freopen_s(&unused, "CONOUT$", "w", stdout)) { diff --git a/shell/platform/windows/flutter_windows_win32.cc b/shell/platform/windows/flutter_windows_win32.cc new file mode 100644 index 0000000000000..a02ce37720dd8 --- /dev/null +++ b/shell/platform/windows/flutter_windows_win32.cc @@ -0,0 +1,95 @@ +// 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/public/flutter_windows.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "flutter/shell/platform/windows/win32_dpi_utils.h" +#include "flutter/shell/platform/windows/win32_flutter_window.h" + +// Returns the engine corresponding to the given opaque API handle. +static flutter::FlutterWindowsEngine* EngineFromHandle( + FlutterDesktopEngineRef ref) { + return reinterpret_cast(ref); +} + +FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate( + int width, + int height, + FlutterDesktopEngineRef engine) { + std::unique_ptr window_wrapper = + std::make_unique(width, height); + + auto state = std::make_unique(); + state->view = + std::make_unique(std::move(window_wrapper)); + state->view->CreateRenderSurface(); + + // Take ownership of the engine, starting it if necessary. + state->view->SetEngine( + std::unique_ptr(EngineFromHandle(engine))); + if (!state->view->GetEngine()->running()) { + if (!state->view->GetEngine()->RunWithEntrypoint(nullptr)) { + return nullptr; + } + } + + // Must happen after engine is running. + state->view->SendInitialBounds(); + return state.release(); +} + +bool FlutterDesktopViewControllerHandleTopLevelWindowProc( + FlutterDesktopViewControllerRef controller, + HWND hwnd, + UINT message, + WPARAM wparam, + LPARAM lparam, + LRESULT* result) { + std::optional delegate_result = + controller->view->GetEngine() + ->window_proc_delegate_manager() + ->OnTopLevelWindowProc(hwnd, message, wparam, lparam); + if (delegate_result) { + *result = *delegate_result; + } + return delegate_result.has_value(); +} + +uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine) { + return EngineFromHandle(engine)->task_runner()->ProcessTasks().count(); +} + +void FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate( + FlutterDesktopPluginRegistrarRef registrar, + FlutterDesktopWindowProcCallback delegate, + void* user_data) { + registrar->engine->window_proc_delegate_manager() + ->RegisterTopLevelWindowProcDelegate(delegate, user_data); +} + +void FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate( + FlutterDesktopPluginRegistrarRef registrar, + FlutterDesktopWindowProcCallback delegate) { + registrar->engine->window_proc_delegate_manager() + ->UnregisterTopLevelWindowProcDelegate(delegate); +} + +UINT FlutterDesktopGetDpiForHWND(HWND hwnd) { + return flutter::GetDpiForHWND(hwnd); +} + +UINT FlutterDesktopGetDpiForMonitor(HMONITOR monitor) { + return flutter::GetDpiForMonitor(monitor); +} diff --git a/shell/platform/windows/flutter_windows_winuwp.cc b/shell/platform/windows/flutter_windows_winuwp.cc new file mode 100644 index 0000000000000..35cd27e25f661 --- /dev/null +++ b/shell/platform/windows/flutter_windows_winuwp.cc @@ -0,0 +1,45 @@ +// 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/public/flutter_windows.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h" +#include "flutter/shell/platform/common/cpp/incoming_message_dispatcher.h" + +FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate( + int width, + int height, + FlutterDesktopEngineRef engine) { + // TODO add WINUWP implementation. + return nullptr; +} + +uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine) { + // TODO add WINUWP implementation. + return 0; +} + +void FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate( + FlutterDesktopPluginRegistrarRef registrar, + FlutterDesktopWindowProcCallback delegate, + void* user_data) { + // TODO add WINUWP implementation. +} + +void FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate( + FlutterDesktopPluginRegistrarRef registrar, + FlutterDesktopWindowProcCallback delegate) { + // TODO add WINUWP implementation. +} From 28cfc6ac2b7c08468310334befa3fca681aa53f3 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 7 Nov 2020 06:14:33 -0800 Subject: [PATCH 07/19] CR Feedback --- DEPS | 2 +- ci/licenses_golden/licenses_flutter | 3 + shell/platform/windows/BUILD.gn | 14 +++-- .../windows/client_wrapper/flutter_engine.cc | 2 + .../windows/flutter_windows_engine.cc | 23 ++++++-- .../platform/windows/flutter_windows_engine.h | 14 +++-- .../platform/windows/flutter_windows_win32.cc | 6 +- .../platform/windows/public/flutter_windows.h | 2 + shell/platform/windows/task_runner.h | 32 +++++++++++ shell/platform/windows/win32_task_runner.h | 14 +++-- shell/platform/windows/winrt_task_runner.cc | 43 +++++++++++++++ shell/platform/windows/winrt_task_runner.h | 55 +++++++++++++++++++ 12 files changed, 185 insertions(+), 25 deletions(-) create mode 100644 shell/platform/windows/task_runner.h create mode 100644 shell/platform/windows/winrt_task_runner.cc create mode 100644 shell/platform/windows/winrt_task_runner.h diff --git a/DEPS b/DEPS index 5276ad26c2ac9..b21005385a275 100644 --- a/DEPS +++ b/DEPS @@ -105,7 +105,7 @@ allowed_hosts = [ ] deps = { - 'src': 'https://github.com/flutter/buildroot.git' + '@' + '9184ff0695be1b3e4bb20cf64efcfa56daa0a3c0', + 'src': 'https://github.com/flutter/buildroot.git' + '@' + 'e6c83ddcc5a2d1ca9bf727d4aae13c2cf8d9999e', # Fuchsia compatibility # diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index a7e9ac9bd0ec2..0430d0143f358 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1415,6 +1415,7 @@ FILE: ../../../flutter/shell/platform/windows/system_utils.h FILE: ../../../flutter/shell/platform/windows/system_utils_unittests.cc FILE: ../../../flutter/shell/platform/windows/system_utils_win32.cc FILE: ../../../flutter/shell/platform/windows/system_utils_winuwp.cc +FILE: ../../../flutter/shell/platform/windows/task_runner.h FILE: ../../../flutter/shell/platform/windows/text_input_plugin.cc FILE: ../../../flutter/shell/platform/windows/text_input_plugin.h FILE: ../../../flutter/shell/platform/windows/win32_dpi_utils.cc @@ -1436,6 +1437,8 @@ FILE: ../../../flutter/shell/platform/windows/win32_window_unittests.cc FILE: ../../../flutter/shell/platform/windows/window_binding_handler.h FILE: ../../../flutter/shell/platform/windows/window_binding_handler_delegate.h FILE: ../../../flutter/shell/platform/windows/window_state.h +FILE: ../../../flutter/shell/platform/windows/winrt_task_runner.cc +FILE: ../../../flutter/shell/platform/windows/winrt_task_runner.h FILE: ../../../flutter/shell/profiling/sampling_profiler.cc FILE: ../../../flutter/shell/profiling/sampling_profiler.h FILE: ../../../flutter/shell/version/version.cc diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index cbf24ea03da0d..4eab309f4a9ee 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -30,9 +30,8 @@ source_set("flutter_windows_headers") { [ "//flutter/shell/platform/common/cpp:common_cpp_library_headers" ] if (target_os == "winuwp") { - configs += [ - "//flutter/shell/platform/common/cpp:desktop_library_implementation", - ] + configs += + [ "//flutter/shell/platform/common/cpp:desktop_library_implementation" ] } else { configs += [ "//flutter/shell/platform/common/cpp:desktop_library_implementation" ] @@ -62,6 +61,7 @@ source_set("flutter_windows_source") { "string_conversion.cc", "string_conversion.h", "system_utils.h", + "task_runner.h", "text_input_plugin.cc", "text_input_plugin.h", "window_binding_handler.h", @@ -71,8 +71,12 @@ source_set("flutter_windows_source") { # Target-specific sources. if (target_os == "winuwp") { - sources += [ "flutter_windows_winuwp.cc" ] - sources += [ "system_utils_winuwp.cc" ] + sources += [ + "flutter_windows_winuwp.cc", + "system_utils_winuwp.cc", + "winrt_task_runner.cc", + "winrt_task_runner.h", + ] } else { sources += [ "flutter_windows_win32.cc", diff --git a/shell/platform/windows/client_wrapper/flutter_engine.cc b/shell/platform/windows/client_wrapper/flutter_engine.cc index a1fc0c4659066..12ca29743c695 100644 --- a/shell/platform/windows/client_wrapper/flutter_engine.cc +++ b/shell/platform/windows/client_wrapper/flutter_engine.cc @@ -64,9 +64,11 @@ void FlutterEngine::ShutDown() { engine_ = nullptr; } +#ifndef WINUWP std::chrono::nanoseconds FlutterEngine::ProcessMessages() { return std::chrono::nanoseconds(FlutterDesktopEngineProcessMessages(engine_)); } +#endif void FlutterEngine::ReloadSystemFonts() { FlutterDesktopEngineReloadSystemFonts(engine_); diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc index d5a6f255526d1..a62c461a63264 100644 --- a/shell/platform/windows/flutter_windows_engine.cc +++ b/shell/platform/windows/flutter_windows_engine.cc @@ -12,6 +12,7 @@ #include "flutter/shell/platform/windows/flutter_windows_view.h" #include "flutter/shell/platform/windows/string_conversion.h" #include "flutter/shell/platform/windows/system_utils.h" +#include "flutter/shell/platform/windows/task_runner.h" namespace flutter { @@ -103,6 +104,18 @@ FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project) std::cerr << "Failed to post an engine task." << std::endl; } }); +#else + task_runner_ = std::make_unique( + GetCurrentThreadId(), [this](const auto* task) { + if (!engine_) { + std::cerr << "Cannot post an engine task when engine is not running." + << std::endl; + return; + } + if (FlutterEngineRunTask(engine_, task) != kSuccess) { + std::cerr << "Failed to post an engine task." << std::endl; + } + }); #endif // Set up the legacy structs backing the API handles. @@ -155,24 +168,22 @@ bool FlutterWindowsEngine::RunWithEntrypoint(const char* entrypoint) { std::back_inserter(entrypoint_argv), [](const std::string& arg) -> const char* { return arg.c_str(); }); -#ifndef FLUTTER_WINRT // Configure task runners. FlutterTaskRunnerDescription platform_task_runner = {}; platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription); platform_task_runner.user_data = task_runner_.get(); platform_task_runner.runs_task_on_current_thread_callback = [](void* user_data) -> bool { - return static_cast(user_data)->RunsTasksOnCurrentThread(); + return static_cast(user_data)->RunsTasksOnCurrentThread(); }; platform_task_runner.post_task_callback = [](FlutterTask task, uint64_t target_time_nanos, void* user_data) -> void { - static_cast(user_data)->PostTask(task, target_time_nanos); + static_cast(user_data)->PostTask(task, target_time_nanos); }; FlutterCustomTaskRunners custom_task_runners = {}; custom_task_runners.struct_size = sizeof(FlutterCustomTaskRunners); custom_task_runners.platform_task_runner = &platform_task_runner; -#endif FlutterProjectArgs args = {}; args.struct_size = sizeof(FlutterProjectArgs); @@ -189,9 +200,9 @@ bool FlutterWindowsEngine::RunWithEntrypoint(const char* entrypoint) { auto host = static_cast(user_data); return host->HandlePlatformMessage(engine_message); }; -#ifndef WINUWP + args.custom_task_runners = &custom_task_runners; -#endif + if (aot_data_) { args.aot_data = aot_data_.get(); } diff --git a/shell/platform/windows/flutter_windows_engine.h b/shell/platform/windows/flutter_windows_engine.h index 8696934e8501f..03f549e300642 100644 --- a/shell/platform/windows/flutter_windows_engine.h +++ b/shell/platform/windows/flutter_windows_engine.h @@ -13,11 +13,15 @@ #include "flutter/shell/platform/common/cpp/incoming_message_dispatcher.h" #include "flutter/shell/platform/windows/flutter_project_bundle.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" +#include "flutter/shell/platform/windows/task_runner.h" +#include "flutter/shell/platform/windows/window_state.h" + #ifndef WINUWP #include "flutter/shell/platform/windows/win32_task_runner.h" // nogncheck #include "flutter/shell/platform/windows/win32_window_proc_delegate_manager.h" // nogncheck +#else +#include "flutter/shell/platform/windows/winrt_task_runner.h" // nogncheck #endif -#include "flutter/shell/platform/windows/window_state.h" namespace flutter { @@ -75,9 +79,9 @@ class FlutterWindowsEngine { return message_dispatcher_.get(); } -#ifndef WINUWP - Win32TaskRunner* task_runner() { return task_runner_.get(); } + TaskRunner* task_runner() { return task_runner_.get(); } +#ifndef WINUWP Win32WindowProcDelegateManager* window_proc_delegate_manager() { return window_proc_delegate_manager_.get(); } @@ -105,10 +109,8 @@ class FlutterWindowsEngine { // The view displaying the content running in this engine, if any. FlutterWindowsView* view_ = nullptr; -#ifndef WINUWP // Task runner for tasks posted from the engine. - std::unique_ptr task_runner_; -#endif + std::unique_ptr task_runner_; // The plugin messenger handle given to API clients. std::unique_ptr messenger_; diff --git a/shell/platform/windows/flutter_windows_win32.cc b/shell/platform/windows/flutter_windows_win32.cc index a02ce37720dd8..45dcf818413b7 100644 --- a/shell/platform/windows/flutter_windows_win32.cc +++ b/shell/platform/windows/flutter_windows_win32.cc @@ -17,6 +17,7 @@ #include "flutter/shell/platform/windows/win32_dpi_utils.h" #include "flutter/shell/platform/windows/win32_flutter_window.h" +#include "flutter/shell/platform/windows/win32_task_runner.h" // Returns the engine corresponding to the given opaque API handle. static flutter::FlutterWindowsEngine* EngineFromHandle( @@ -68,7 +69,10 @@ bool FlutterDesktopViewControllerHandleTopLevelWindowProc( } uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine) { - return EngineFromHandle(engine)->task_runner()->ProcessTasks().count(); + return static_cast( + EngineFromHandle(engine)->task_runner()) + ->ProcessTasks() + .count(); } void FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate( diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index 69269ff339665..54cb5d905e338 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -134,6 +134,7 @@ FLUTTER_EXPORT bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine); FLUTTER_EXPORT bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, const char* entry_point); +#ifndef WINUWP // Processes any pending events in the Flutter engine, and returns the // number of nanoseconds until the next scheduled event (or max, if none). // @@ -142,6 +143,7 @@ FLUTTER_EXPORT bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, // last return value from this function. FLUTTER_EXPORT uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine); +#endif FLUTTER_EXPORT void FlutterDesktopEngineReloadSystemFonts( FlutterDesktopEngineRef engine); diff --git a/shell/platform/windows/task_runner.h b/shell/platform/windows/task_runner.h new file mode 100644 index 0000000000000..61f33f2361d38 --- /dev/null +++ b/shell/platform/windows/task_runner.h @@ -0,0 +1,32 @@ +// 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_TASK_RUNNER_H_ +#define FLUTTER_SHELL_PLATFORM_WINDOWS_TASK_RUNNER_H_ + +#include + +#include +#include + +#include "flutter/shell/platform/embedder/embedder.h" + +namespace flutter { + +// Abstract custom task runner for scheduling custom tasks. +class TaskRunner { + public: + virtual ~TaskRunner() = default; + + // Returns if the current thread is the UI thread. + virtual bool RunsTasksOnCurrentThread() const = 0; + + // Post a Flutter engine tasks to the event loop for delayed execution. + virtual void PostTask(FlutterTask flutter_task, + uint64_t flutter_target_time_nanos) = 0; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TASK_RUNNER_H_ diff --git a/shell/platform/windows/win32_task_runner.h b/shell/platform/windows/win32_task_runner.h index a35490a8563b1..ddfe3b3d7c2f7 100644 --- a/shell/platform/windows/win32_task_runner.h +++ b/shell/platform/windows/win32_task_runner.h @@ -15,27 +15,29 @@ #include #include "flutter/shell/platform/embedder/embedder.h" +#include "flutter/shell/platform/windows/task_runner.h" namespace flutter { // A custom task runner that integrates with user32 GetMessage semantics so that // host app can own its own message loop and flutter still gets to process // tasks on a timely basis. -class Win32TaskRunner { +class Win32TaskRunner : public TaskRunner { public: using TaskExpiredCallback = std::function; Win32TaskRunner(DWORD main_thread_id, const TaskExpiredCallback& on_task_expired); - ~Win32TaskRunner(); + virtual ~Win32TaskRunner(); - // Returns if the current thread is the thread used by the win32 event loop. - bool RunsTasksOnCurrentThread() const; + // |RunsTasksOnCurrentThread| + bool RunsTasksOnCurrentThread() const override; std::chrono::nanoseconds ProcessTasks(); - // Post a Flutter engine tasks to the event loop for delayed execution. - void PostTask(FlutterTask flutter_task, uint64_t flutter_target_time_nanos); + // |PostTask| + void PostTask(FlutterTask flutter_task, + uint64_t flutter_target_time_nanos) override; private: using TaskTimePoint = std::chrono::steady_clock::time_point; diff --git a/shell/platform/windows/winrt_task_runner.cc b/shell/platform/windows/winrt_task_runner.cc new file mode 100644 index 0000000000000..56374a57cf5a7 --- /dev/null +++ b/shell/platform/windows/winrt_task_runner.cc @@ -0,0 +1,43 @@ +// 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/winrt_task_runner.h" + +#include +#include + +namespace flutter { + +WinrtTaskRunner::WinrtTaskRunner(DWORD main_thread_id, + const TaskExpiredCallback& on_task_expired) + : main_thread_id_(main_thread_id), + on_task_expired_(std::move(on_task_expired)) { + dispatcher_ = + winrt::Windows::UI::Core::CoreWindow::GetForCurrentThread().Dispatcher(); +} + +WinrtTaskRunner::~WinrtTaskRunner() = default; + +bool WinrtTaskRunner::RunsTasksOnCurrentThread() const { + return GetCurrentThreadId() == main_thread_id_; +} + +WinrtTaskRunner::TaskTimePoint WinrtTaskRunner::TimePointFromFlutterTime( + uint64_t flutter_target_time_nanos) { + const auto now = TaskTimePoint::clock::now(); + const auto flutter_duration = + flutter_target_time_nanos - FlutterEngineGetCurrentTime(); + return now + std::chrono::nanoseconds(flutter_duration); +} + +void WinrtTaskRunner::PostTask(FlutterTask flutter_task, + uint64_t flutter_target_time_nanos) { + // TODO: consider waiting on threadpool thread until target time + + dispatcher_.RunAsync( + winrt::Windows::UI::Core::CoreDispatcherPriority::Normal, + [this, flutter_task]() { on_task_expired_(&flutter_task); }); +} + +} // namespace flutter diff --git a/shell/platform/windows/winrt_task_runner.h b/shell/platform/windows/winrt_task_runner.h new file mode 100644 index 0000000000000..79ee79c26d454 --- /dev/null +++ b/shell/platform/windows/winrt_task_runner.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_WINRT_TASK_RUNNER_H_ +#define FLUTTER_SHELL_PLATFORM_WINDOWS_WINRT_TASK_RUNNER_H_ + +#include + +#include + +#include +#include +#include + +#include "flutter/shell/platform/embedder/embedder.h" +#include "flutter/shell/platform/windows/task_runner.h" + +namespace flutter { + +// A custom task runner that uses a CoreDispatcher to schedule +// flutter tasks. +class WinrtTaskRunner : public TaskRunner { + public: + using TaskExpiredCallback = std::function; + WinrtTaskRunner(DWORD main_thread_id, + const TaskExpiredCallback& on_task_expired); + + ~WinrtTaskRunner(); + + // |RunsTasksOnCurrentThread| + bool RunsTasksOnCurrentThread() const override; + + // |PostTask| + void PostTask(FlutterTask flutter_task, + uint64_t flutter_target_time_nanos) override; + + private: + using TaskTimePoint = std::chrono::steady_clock::time_point; + DWORD main_thread_id_; + TaskExpiredCallback on_task_expired_; + + WinrtTaskRunner(const WinrtTaskRunner&) = delete; + + WinrtTaskRunner& operator=(const WinrtTaskRunner&) = delete; + + winrt::Windows::UI::Core::CoreDispatcher dispatcher_{nullptr}; + + static TaskTimePoint TimePointFromFlutterTime( + uint64_t flutter_target_time_nanos); +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_WINRT_TASK_RUNNER_H_ From 287029c8a1364b2de53e5060655827859e708795 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 19 Nov 2020 11:18:30 -0800 Subject: [PATCH 08/19] Rename task runners --- ci/licenses_golden/licenses_flutter | 8 ++++---- shell/platform/windows/BUILD.gn | 8 ++++---- shell/platform/windows/flutter_windows_engine.cc | 12 +++++++++--- shell/platform/windows/flutter_windows_engine.h | 3 --- shell/platform/windows/flutter_windows_win32.cc | 2 +- ...win32_task_runner.cc => task_runner_win32.cc} | 14 +++++++------- .../{win32_task_runner.h => task_runner_win32.h} | 16 ++++++++-------- ...inrt_task_runner.cc => task_runner_winuwp.cc} | 16 ++++++++-------- ...{winrt_task_runner.h => task_runner_winuwp.h} | 12 ++++++------ 9 files changed, 47 insertions(+), 44 deletions(-) rename shell/platform/windows/{win32_task_runner.cc => task_runner_win32.cc} (88%) rename shell/platform/windows/{win32_task_runner.h => task_runner_win32.h} (83%) rename shell/platform/windows/{winrt_task_runner.cc => task_runner_winuwp.cc} (63%) rename shell/platform/windows/{winrt_task_runner.h => task_runner_winuwp.h} (78%) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 8ea36b71304ef..151875d9ecc8b 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1418,6 +1418,10 @@ FILE: ../../../flutter/shell/platform/windows/system_utils_unittests.cc FILE: ../../../flutter/shell/platform/windows/system_utils_win32.cc FILE: ../../../flutter/shell/platform/windows/system_utils_winuwp.cc FILE: ../../../flutter/shell/platform/windows/task_runner.h +FILE: ../../../flutter/shell/platform/windows/task_runner_win32.cc +FILE: ../../../flutter/shell/platform/windows/task_runner_win32.h +FILE: ../../../flutter/shell/platform/windows/task_runner_winuwp.cc +FILE: ../../../flutter/shell/platform/windows/task_runner_winuwp.h FILE: ../../../flutter/shell/platform/windows/text_input_plugin.cc FILE: ../../../flutter/shell/platform/windows/text_input_plugin.h FILE: ../../../flutter/shell/platform/windows/win32_dpi_utils.cc @@ -1428,8 +1432,6 @@ FILE: ../../../flutter/shell/platform/windows/win32_flutter_window.h FILE: ../../../flutter/shell/platform/windows/win32_flutter_window_unittests.cc FILE: ../../../flutter/shell/platform/windows/win32_platform_handler.cc FILE: ../../../flutter/shell/platform/windows/win32_platform_handler.h -FILE: ../../../flutter/shell/platform/windows/win32_task_runner.cc -FILE: ../../../flutter/shell/platform/windows/win32_task_runner.h FILE: ../../../flutter/shell/platform/windows/win32_window.cc FILE: ../../../flutter/shell/platform/windows/win32_window.h FILE: ../../../flutter/shell/platform/windows/win32_window_proc_delegate_manager.cc @@ -1439,8 +1441,6 @@ FILE: ../../../flutter/shell/platform/windows/win32_window_unittests.cc FILE: ../../../flutter/shell/platform/windows/window_binding_handler.h FILE: ../../../flutter/shell/platform/windows/window_binding_handler_delegate.h FILE: ../../../flutter/shell/platform/windows/window_state.h -FILE: ../../../flutter/shell/platform/windows/winrt_task_runner.cc -FILE: ../../../flutter/shell/platform/windows/winrt_task_runner.h FILE: ../../../flutter/shell/profiling/sampling_profiler.cc FILE: ../../../flutter/shell/profiling/sampling_profiler.h FILE: ../../../flutter/shell/version/version.cc diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index 9b39d66571213..98c6f70294cb1 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -74,21 +74,21 @@ source_set("flutter_windows_source") { sources += [ "flutter_windows_winuwp.cc", "system_utils_winuwp.cc", - "winrt_task_runner.cc", - "winrt_task_runner.h", + "task_runner_winuwp.cc", + "task_runner_winuwp.h", ] } else { sources += [ "flutter_windows_win32.cc", "system_utils_win32.cc", + "task_runner_win32.cc", + "task_runner_win32.h", "win32_dpi_utils.cc", "win32_dpi_utils.h", "win32_flutter_window.cc", "win32_flutter_window.h", "win32_platform_handler.cc", "win32_platform_handler.h", - "win32_task_runner.cc", - "win32_task_runner.h", "win32_window.cc", "win32_window.h", "win32_window_proc_delegate_manager.cc", diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc index 0ce3c6d228094..2a53d94a0c3a2 100644 --- a/shell/platform/windows/flutter_windows_engine.cc +++ b/shell/platform/windows/flutter_windows_engine.cc @@ -14,6 +14,12 @@ #include "flutter/shell/platform/windows/system_utils.h" #include "flutter/shell/platform/windows/task_runner.h" +#ifdef WINUWP +#include "flutter/shell/platform/windows/task_runner_winuwp.h" // nogncheck +#else +#include "flutter/shell/platform/windows/task_runner_win32.h" // nogncheck +#endif + namespace flutter { namespace { @@ -95,9 +101,9 @@ FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project) aot_data_(nullptr, nullptr) { embedder_api_.struct_size = sizeof(FlutterEngineProcTable); FlutterEngineGetProcAddresses(&embedder_api_); - + #ifndef WINUWP - task_runner_ = std::make_unique( + task_runner_ = std::make_unique( GetCurrentThreadId(), embedder_api_.GetCurrentTime, [this](const auto* task) { if (!engine_) { @@ -110,7 +116,7 @@ FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project) } }); #else - task_runner_ = std::make_unique( + task_runner_ = std::make_unique( GetCurrentThreadId(), [this](const auto* task) { if (!engine_) { std::cerr << "Cannot post an engine task when engine is not running." diff --git a/shell/platform/windows/flutter_windows_engine.h b/shell/platform/windows/flutter_windows_engine.h index 873c1cd353327..0645389a8fc02 100644 --- a/shell/platform/windows/flutter_windows_engine.h +++ b/shell/platform/windows/flutter_windows_engine.h @@ -18,10 +18,7 @@ #include "flutter/shell/platform/windows/window_state.h" #ifndef WINUWP -#include "flutter/shell/platform/windows/win32_task_runner.h" // nogncheck #include "flutter/shell/platform/windows/win32_window_proc_delegate_manager.h" // nogncheck -#else -#include "flutter/shell/platform/windows/winrt_task_runner.h" // nogncheck #endif namespace flutter { diff --git a/shell/platform/windows/flutter_windows_win32.cc b/shell/platform/windows/flutter_windows_win32.cc index 45dcf818413b7..3ebe73af2f654 100644 --- a/shell/platform/windows/flutter_windows_win32.cc +++ b/shell/platform/windows/flutter_windows_win32.cc @@ -15,9 +15,9 @@ #include #include +#include "flutter/shell/platform/windows/task_runner_win32.h" #include "flutter/shell/platform/windows/win32_dpi_utils.h" #include "flutter/shell/platform/windows/win32_flutter_window.h" -#include "flutter/shell/platform/windows/win32_task_runner.h" // Returns the engine corresponding to the given opaque API handle. static flutter::FlutterWindowsEngine* EngineFromHandle( diff --git a/shell/platform/windows/win32_task_runner.cc b/shell/platform/windows/task_runner_win32.cc similarity index 88% rename from shell/platform/windows/win32_task_runner.cc rename to shell/platform/windows/task_runner_win32.cc index 9f6d26db86b91..3eba0de83eaff 100644 --- a/shell/platform/windows/win32_task_runner.cc +++ b/shell/platform/windows/task_runner_win32.cc @@ -2,7 +2,7 @@ // 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/win32_task_runner.h" +#include "flutter/shell/platform/windows/task_runner_win32.h" #include #include @@ -10,20 +10,20 @@ namespace flutter { -Win32TaskRunner::Win32TaskRunner(DWORD main_thread_id, +TaskRunnerWin32::TaskRunnerWin32(DWORD main_thread_id, CurrentTimeProc get_current_time, const TaskExpiredCallback& on_task_expired) : main_thread_id_(main_thread_id), get_current_time_(get_current_time), on_task_expired_(std::move(on_task_expired)) {} -Win32TaskRunner::~Win32TaskRunner() = default; +TaskRunnerWin32::~TaskRunnerWin32() = default; -bool Win32TaskRunner::RunsTasksOnCurrentThread() const { +bool TaskRunnerWin32::RunsTasksOnCurrentThread() const { return GetCurrentThreadId() == main_thread_id_; } -std::chrono::nanoseconds Win32TaskRunner::ProcessTasks() { +std::chrono::nanoseconds TaskRunnerWin32::ProcessTasks() { const TaskTimePoint now = TaskTimePoint::clock::now(); std::vector expired_tasks; @@ -68,14 +68,14 @@ std::chrono::nanoseconds Win32TaskRunner::ProcessTasks() { } } -Win32TaskRunner::TaskTimePoint Win32TaskRunner::TimePointFromFlutterTime( +TaskRunnerWin32::TaskTimePoint TaskRunnerWin32::TimePointFromFlutterTime( uint64_t flutter_target_time_nanos) const { const auto now = TaskTimePoint::clock::now(); const auto flutter_duration = flutter_target_time_nanos - get_current_time_(); return now + std::chrono::nanoseconds(flutter_duration); } -void Win32TaskRunner::PostTask(FlutterTask flutter_task, +void TaskRunnerWin32::PostTask(FlutterTask flutter_task, uint64_t flutter_target_time_nanos) { static std::atomic_uint64_t sGlobalTaskOrder(0); diff --git a/shell/platform/windows/win32_task_runner.h b/shell/platform/windows/task_runner_win32.h similarity index 83% rename from shell/platform/windows/win32_task_runner.h rename to shell/platform/windows/task_runner_win32.h index 8c9a17f53309c..126ab6e420343 100644 --- a/shell/platform/windows/win32_task_runner.h +++ b/shell/platform/windows/task_runner_win32.h @@ -2,8 +2,8 @@ // 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_WIN32_TASK_RUNNER_H_ -#define FLUTTER_SHELL_PLATFORM_WINDOWS_WIN32_TASK_RUNNER_H_ +#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_TASK_RUNNER_WIN32_H_ +#define FLUTTER_SHELL_PLATFORM_WINDOWS_TASK_RUNNER_WIN32_H_ #include @@ -23,16 +23,16 @@ typedef uint64_t (*CurrentTimeProc)(); // A custom task runner that integrates with user32 GetMessage semantics so that // host app can own its own message loop and flutter still gets to process // tasks on a timely basis. -class Win32TaskRunner : public TaskRunner { +class TaskRunnerWin32 : public TaskRunner { public: using TaskExpiredCallback = std::function; // Creates a new task runner with the given main thread ID, current time // provider, and callback for tasks that are ready to be run. - Win32TaskRunner(DWORD main_thread_id, + TaskRunnerWin32(DWORD main_thread_id, CurrentTimeProc get_current_time, const TaskExpiredCallback& on_task_expired); - virtual ~Win32TaskRunner(); + virtual ~TaskRunnerWin32(); // |RunsTasksOnCurrentThread| bool RunsTasksOnCurrentThread() const override; @@ -70,11 +70,11 @@ class Win32TaskRunner : public TaskRunner { std::mutex task_queue_mutex_; std::priority_queue, Task::Comparer> task_queue_; - Win32TaskRunner(const Win32TaskRunner&) = delete; + TaskRunnerWin32(const TaskRunnerWin32&) = delete; - Win32TaskRunner& operator=(const Win32TaskRunner&) = delete; + TaskRunnerWin32& operator=(const TaskRunnerWin32&) = delete; }; } // namespace flutter -#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_WIN32_TASK_RUNNER_H_ +#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TASK_RUNNER_WIN32_H_ diff --git a/shell/platform/windows/winrt_task_runner.cc b/shell/platform/windows/task_runner_winuwp.cc similarity index 63% rename from shell/platform/windows/winrt_task_runner.cc rename to shell/platform/windows/task_runner_winuwp.cc index 56374a57cf5a7..781fd81ee882b 100644 --- a/shell/platform/windows/winrt_task_runner.cc +++ b/shell/platform/windows/task_runner_winuwp.cc @@ -2,28 +2,28 @@ // 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/winrt_task_runner.h" +#include "flutter/shell/platform/windows/task_runner_winuwp.h" #include #include namespace flutter { -WinrtTaskRunner::WinrtTaskRunner(DWORD main_thread_id, - const TaskExpiredCallback& on_task_expired) +TaskRunnerWinUwp::TaskRunnerWinUwp(DWORD main_thread_id, + const TaskExpiredCallback& on_task_expired) : main_thread_id_(main_thread_id), on_task_expired_(std::move(on_task_expired)) { dispatcher_ = winrt::Windows::UI::Core::CoreWindow::GetForCurrentThread().Dispatcher(); } -WinrtTaskRunner::~WinrtTaskRunner() = default; +TaskRunnerWinUwp::~TaskRunnerWinUwp() = default; -bool WinrtTaskRunner::RunsTasksOnCurrentThread() const { +bool TaskRunnerWinUwp::RunsTasksOnCurrentThread() const { return GetCurrentThreadId() == main_thread_id_; } -WinrtTaskRunner::TaskTimePoint WinrtTaskRunner::TimePointFromFlutterTime( +TaskRunnerWinUwp::TaskTimePoint TaskRunnerWinUwp::TimePointFromFlutterTime( uint64_t flutter_target_time_nanos) { const auto now = TaskTimePoint::clock::now(); const auto flutter_duration = @@ -31,8 +31,8 @@ WinrtTaskRunner::TaskTimePoint WinrtTaskRunner::TimePointFromFlutterTime( return now + std::chrono::nanoseconds(flutter_duration); } -void WinrtTaskRunner::PostTask(FlutterTask flutter_task, - uint64_t flutter_target_time_nanos) { +void TaskRunnerWinUwp::PostTask(FlutterTask flutter_task, + uint64_t flutter_target_time_nanos) { // TODO: consider waiting on threadpool thread until target time dispatcher_.RunAsync( diff --git a/shell/platform/windows/winrt_task_runner.h b/shell/platform/windows/task_runner_winuwp.h similarity index 78% rename from shell/platform/windows/winrt_task_runner.h rename to shell/platform/windows/task_runner_winuwp.h index 79ee79c26d454..0e2e0b2e88bf0 100644 --- a/shell/platform/windows/winrt_task_runner.h +++ b/shell/platform/windows/task_runner_winuwp.h @@ -20,13 +20,13 @@ namespace flutter { // A custom task runner that uses a CoreDispatcher to schedule // flutter tasks. -class WinrtTaskRunner : public TaskRunner { +class TaskRunnerWinUwp : public TaskRunner { public: using TaskExpiredCallback = std::function; - WinrtTaskRunner(DWORD main_thread_id, - const TaskExpiredCallback& on_task_expired); + TaskRunnerWinUwp(DWORD main_thread_id, + const TaskExpiredCallback& on_task_expired); - ~WinrtTaskRunner(); + ~TaskRunnerWinUwp(); // |RunsTasksOnCurrentThread| bool RunsTasksOnCurrentThread() const override; @@ -40,9 +40,9 @@ class WinrtTaskRunner : public TaskRunner { DWORD main_thread_id_; TaskExpiredCallback on_task_expired_; - WinrtTaskRunner(const WinrtTaskRunner&) = delete; + TaskRunnerWinUwp(const TaskRunnerWinUwp&) = delete; - WinrtTaskRunner& operator=(const WinrtTaskRunner&) = delete; + TaskRunnerWinUwp& operator=(const TaskRunnerWinUwp&) = delete; winrt::Windows::UI::Core::CoreDispatcher dispatcher_{nullptr}; From fd8b6907deacaad0fbeaceb88bd62638df1e706a Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 19 Nov 2020 14:52:18 -0800 Subject: [PATCH 09/19] Minor cleanup --- BUILD.gn | 4 ++-- shell/platform/windows/flutter_windows_view.h | 7 ++++--- shell/platform/windows/task_runner_win32.h | 8 ++++---- shell/platform/windows/task_runner_winuwp.cc | 11 ++--------- shell/platform/windows/task_runner_winuwp.h | 15 +++++---------- tools/gn | 2 -- 6 files changed, 17 insertions(+), 30 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 73e525a4babca..a4f3247f15211 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -148,8 +148,8 @@ group("flutter") { if (is_win) { if (target_os == "winuwp") { - # TODO once the UWP implmentation lands, reference future flutter_windows_unittests_winrt - # runner implementation from here. + # TODO: Add winnup variant of the unit tests here; see + # https://github.com/flutter/flutter/issues/70197 } else { public_deps += [ "//flutter/shell/platform/windows:flutter_windows_unittests", diff --git a/shell/platform/windows/flutter_windows_view.h b/shell/platform/windows/flutter_windows_view.h index 462a2285d0879..25cc9b8b1f3ce 100644 --- a/shell/platform/windows/flutter_windows_view.h +++ b/shell/platform/windows/flutter_windows_view.h @@ -20,13 +20,14 @@ #include "flutter/shell/platform/windows/keyboard_hook_handler.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" #include "flutter/shell/platform/windows/text_input_plugin.h" -#ifndef WINUWP -#include "flutter/shell/platform/windows/win32_platform_handler.h" // nogncheck -#endif #include "flutter/shell/platform/windows/window_binding_handler.h" #include "flutter/shell/platform/windows/window_binding_handler_delegate.h" #include "flutter/shell/platform/windows/window_state.h" +#ifndef WINUWP +#include "flutter/shell/platform/windows/win32_platform_handler.h" // nogncheck +#endif + namespace flutter { // An OS-windowing neutral abstration for flutter diff --git a/shell/platform/windows/task_runner_win32.h b/shell/platform/windows/task_runner_win32.h index 126ab6e420343..aa73cd998d134 100644 --- a/shell/platform/windows/task_runner_win32.h +++ b/shell/platform/windows/task_runner_win32.h @@ -34,15 +34,15 @@ class TaskRunnerWin32 : public TaskRunner { virtual ~TaskRunnerWin32(); - // |RunsTasksOnCurrentThread| + // |TaskRunner| bool RunsTasksOnCurrentThread() const override; - std::chrono::nanoseconds ProcessTasks(); - - // |PostTask| + // |TaskRunner| void PostTask(FlutterTask flutter_task, uint64_t flutter_target_time_nanos) override; + std::chrono::nanoseconds ProcessTasks(); + private: using TaskTimePoint = std::chrono::steady_clock::time_point; struct Task { diff --git a/shell/platform/windows/task_runner_winuwp.cc b/shell/platform/windows/task_runner_winuwp.cc index 781fd81ee882b..863cb5eadfdbd 100644 --- a/shell/platform/windows/task_runner_winuwp.cc +++ b/shell/platform/windows/task_runner_winuwp.cc @@ -23,17 +23,10 @@ bool TaskRunnerWinUwp::RunsTasksOnCurrentThread() const { return GetCurrentThreadId() == main_thread_id_; } -TaskRunnerWinUwp::TaskTimePoint TaskRunnerWinUwp::TimePointFromFlutterTime( - uint64_t flutter_target_time_nanos) { - const auto now = TaskTimePoint::clock::now(); - const auto flutter_duration = - flutter_target_time_nanos - FlutterEngineGetCurrentTime(); - return now + std::chrono::nanoseconds(flutter_duration); -} - void TaskRunnerWinUwp::PostTask(FlutterTask flutter_task, uint64_t flutter_target_time_nanos) { - // TODO: consider waiting on threadpool thread until target time + // TODO: Handle the target time. See + // https://github.com/flutter/flutter/issues/70890. dispatcher_.RunAsync( winrt::Windows::UI::Core::CoreDispatcherPriority::Normal, diff --git a/shell/platform/windows/task_runner_winuwp.h b/shell/platform/windows/task_runner_winuwp.h index 0e2e0b2e88bf0..69364dca025c4 100644 --- a/shell/platform/windows/task_runner_winuwp.h +++ b/shell/platform/windows/task_runner_winuwp.h @@ -28,26 +28,21 @@ class TaskRunnerWinUwp : public TaskRunner { ~TaskRunnerWinUwp(); - // |RunsTasksOnCurrentThread| + TaskRunnerWinUwp(const TaskRunnerWinUwp&) = delete; + TaskRunnerWinUwp& operator=(const TaskRunnerWinUwp&) = delete; + + // |TaskRunner| bool RunsTasksOnCurrentThread() const override; - // |PostTask| + // |TaskRunner| void PostTask(FlutterTask flutter_task, uint64_t flutter_target_time_nanos) override; private: - using TaskTimePoint = std::chrono::steady_clock::time_point; DWORD main_thread_id_; TaskExpiredCallback on_task_expired_; - TaskRunnerWinUwp(const TaskRunnerWinUwp&) = delete; - - TaskRunnerWinUwp& operator=(const TaskRunnerWinUwp&) = delete; - winrt::Windows::UI::Core::CoreDispatcher dispatcher_{nullptr}; - - static TaskTimePoint TimePointFromFlutterTime( - uint64_t flutter_target_time_nanos); }; } // namespace flutter diff --git a/tools/gn b/tools/gn index e7ac66ac416fa..1548795331a5f 100755 --- a/tools/gn +++ b/tools/gn @@ -141,8 +141,6 @@ def to_gn_args(args): gn_args['flutter_enable_legacy_fuchsia_embedder'] = args.fuchsia_legacy elif args.target_os == 'winuwp': gn_args['target_os'] = 'winuwp' - # Enabling angle_is_winuwp is dependent on an in-flight patch to https://chromium.googlesource.com/angle/angle to update UWP support - # gn_args['angle_is_winuwp'] = True elif args.target_os is not None: gn_args['target_os'] = args.target_os From b6fa93813c13062980a47633daa9b10cfb61b14e Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 19 Nov 2020 15:09:54 -0800 Subject: [PATCH 10/19] TaskRunner factory --- .../windows/flutter_windows_engine.cc | 22 +------------------ shell/platform/windows/task_runner.h | 11 ++++++++++ shell/platform/windows/task_runner_win32.cc | 9 ++++++++ shell/platform/windows/task_runner_win32.h | 2 -- shell/platform/windows/task_runner_winuwp.cc | 8 +++++++ shell/platform/windows/task_runner_winuwp.h | 1 - 6 files changed, 29 insertions(+), 24 deletions(-) diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc index 2a53d94a0c3a2..24e65e31ec054 100644 --- a/shell/platform/windows/flutter_windows_engine.cc +++ b/shell/platform/windows/flutter_windows_engine.cc @@ -14,12 +14,6 @@ #include "flutter/shell/platform/windows/system_utils.h" #include "flutter/shell/platform/windows/task_runner.h" -#ifdef WINUWP -#include "flutter/shell/platform/windows/task_runner_winuwp.h" // nogncheck -#else -#include "flutter/shell/platform/windows/task_runner_win32.h" // nogncheck -#endif - namespace flutter { namespace { @@ -102,8 +96,7 @@ FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project) embedder_api_.struct_size = sizeof(FlutterEngineProcTable); FlutterEngineGetProcAddresses(&embedder_api_); -#ifndef WINUWP - task_runner_ = std::make_unique( + task_runner_ = TaskRunner::Create( GetCurrentThreadId(), embedder_api_.GetCurrentTime, [this](const auto* task) { if (!engine_) { @@ -115,19 +108,6 @@ FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project) std::cerr << "Failed to post an engine task." << std::endl; } }); -#else - task_runner_ = std::make_unique( - GetCurrentThreadId(), [this](const auto* task) { - if (!engine_) { - std::cerr << "Cannot post an engine task when engine is not running." - << std::endl; - return; - } - if (FlutterEngineRunTask(engine_, task) != kSuccess) { - std::cerr << "Failed to post an engine task." << std::endl; - } - }); -#endif // Set up the legacy structs backing the API handles. messenger_ = std::make_unique(); diff --git a/shell/platform/windows/task_runner.h b/shell/platform/windows/task_runner.h index 61f33f2361d38..9d2c22b9043c0 100644 --- a/shell/platform/windows/task_runner.h +++ b/shell/platform/windows/task_runner.h @@ -14,9 +14,13 @@ namespace flutter { +typedef uint64_t (*CurrentTimeProc)(); + // Abstract custom task runner for scheduling custom tasks. class TaskRunner { public: + using TaskExpiredCallback = std::function; + virtual ~TaskRunner() = default; // Returns if the current thread is the UI thread. @@ -25,6 +29,13 @@ class TaskRunner { // Post a Flutter engine tasks to the event loop for delayed execution. virtual void PostTask(FlutterTask flutter_task, uint64_t flutter_target_time_nanos) = 0; + + // Creates a new task runner with the given main thread ID, current time + // provider, and callback for tasks that are ready to be run. + static std::unique_ptr Create( + DWORD main_thread_id, + CurrentTimeProc get_current_time, + const TaskExpiredCallback& on_task_expired); }; } // namespace flutter diff --git a/shell/platform/windows/task_runner_win32.cc b/shell/platform/windows/task_runner_win32.cc index 3eba0de83eaff..bb1fe147707de 100644 --- a/shell/platform/windows/task_runner_win32.cc +++ b/shell/platform/windows/task_runner_win32.cc @@ -10,6 +10,15 @@ namespace flutter { +// static +std::unique_ptr TaskRunner::Create( + DWORD main_thread_id, + CurrentTimeProc get_current_time, + const TaskExpiredCallback& on_task_expired) { + return std::make_unique(main_thread_id, get_current_time, + on_task_expired); +} + TaskRunnerWin32::TaskRunnerWin32(DWORD main_thread_id, CurrentTimeProc get_current_time, const TaskExpiredCallback& on_task_expired) diff --git a/shell/platform/windows/task_runner_win32.h b/shell/platform/windows/task_runner_win32.h index aa73cd998d134..1ac2f64b861c5 100644 --- a/shell/platform/windows/task_runner_win32.h +++ b/shell/platform/windows/task_runner_win32.h @@ -19,13 +19,11 @@ namespace flutter { -typedef uint64_t (*CurrentTimeProc)(); // A custom task runner that integrates with user32 GetMessage semantics so that // host app can own its own message loop and flutter still gets to process // tasks on a timely basis. class TaskRunnerWin32 : public TaskRunner { public: - using TaskExpiredCallback = std::function; // Creates a new task runner with the given main thread ID, current time // provider, and callback for tasks that are ready to be run. TaskRunnerWin32(DWORD main_thread_id, diff --git a/shell/platform/windows/task_runner_winuwp.cc b/shell/platform/windows/task_runner_winuwp.cc index 863cb5eadfdbd..a2fbe7040c412 100644 --- a/shell/platform/windows/task_runner_winuwp.cc +++ b/shell/platform/windows/task_runner_winuwp.cc @@ -9,6 +9,14 @@ namespace flutter { +// static +std::unique_ptr TaskRunner::Create( + DWORD main_thread_id, + CurrentTimeProc get_current_time, + const TaskExpiredCallback& on_task_expired) { + return std::make_unique(main_thread_id, on_task_expired); +} + TaskRunnerWinUwp::TaskRunnerWinUwp(DWORD main_thread_id, const TaskExpiredCallback& on_task_expired) : main_thread_id_(main_thread_id), diff --git a/shell/platform/windows/task_runner_winuwp.h b/shell/platform/windows/task_runner_winuwp.h index 69364dca025c4..49bdb4da587ce 100644 --- a/shell/platform/windows/task_runner_winuwp.h +++ b/shell/platform/windows/task_runner_winuwp.h @@ -22,7 +22,6 @@ namespace flutter { // flutter tasks. class TaskRunnerWinUwp : public TaskRunner { public: - using TaskExpiredCallback = std::function; TaskRunnerWinUwp(DWORD main_thread_id, const TaskExpiredCallback& on_task_expired); From 9576f5c547f4004d47b7ae801f4108608d25d7b2 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 23 Nov 2020 14:01:08 -0800 Subject: [PATCH 11/19] Abstract PlatformHandler. Minor fixes --- ci/licenses_golden/licenses_flutter | 8 +- shell/platform/windows/BUILD.gn | 8 +- .../platform/windows/flutter_windows_view.cc | 5 +- shell/platform/windows/flutter_windows_view.h | 7 +- .../platform/windows/flutter_windows_win32.cc | 2 +- shell/platform/windows/platform_handler.cc | 62 ++++++++ shell/platform/windows/platform_handler.h | 55 +++++++ ...m_handler.cc => platform_handler_win32.cc} | 148 +++++++----------- .../platform/windows/platform_handler_win32.h | 43 +++++ .../windows/platform_handler_winuwp.cc | 38 +++++ .../windows/platform_handler_winuwp.h | 43 +++++ .../platform/windows/win32_platform_handler.h | 38 ----- 12 files changed, 313 insertions(+), 144 deletions(-) create mode 100644 shell/platform/windows/platform_handler.cc create mode 100644 shell/platform/windows/platform_handler.h rename shell/platform/windows/{win32_platform_handler.cc => platform_handler_win32.cc} (57%) create mode 100644 shell/platform/windows/platform_handler_win32.h create mode 100644 shell/platform/windows/platform_handler_winuwp.cc create mode 100644 shell/platform/windows/platform_handler_winuwp.h delete mode 100644 shell/platform/windows/win32_platform_handler.h diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 151875d9ecc8b..c7018129e1381 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1409,6 +1409,12 @@ FILE: ../../../flutter/shell/platform/windows/flutter_windows_view.h FILE: ../../../flutter/shell/platform/windows/key_event_handler.cc FILE: ../../../flutter/shell/platform/windows/key_event_handler.h FILE: ../../../flutter/shell/platform/windows/keyboard_hook_handler.h +FILE: ../../../flutter/shell/platform/windows/platform_handler.cc +FILE: ../../../flutter/shell/platform/windows/platform_handler.h +FILE: ../../../flutter/shell/platform/windows/platform_handler_win32.cc +FILE: ../../../flutter/shell/platform/windows/platform_handler_win32.h +FILE: ../../../flutter/shell/platform/windows/platform_handler_winuwp.cc +FILE: ../../../flutter/shell/platform/windows/platform_handler_winuwp.h FILE: ../../../flutter/shell/platform/windows/public/flutter_windows.h FILE: ../../../flutter/shell/platform/windows/string_conversion.cc FILE: ../../../flutter/shell/platform/windows/string_conversion.h @@ -1430,8 +1436,6 @@ FILE: ../../../flutter/shell/platform/windows/win32_dpi_utils_unittests.cc FILE: ../../../flutter/shell/platform/windows/win32_flutter_window.cc FILE: ../../../flutter/shell/platform/windows/win32_flutter_window.h FILE: ../../../flutter/shell/platform/windows/win32_flutter_window_unittests.cc -FILE: ../../../flutter/shell/platform/windows/win32_platform_handler.cc -FILE: ../../../flutter/shell/platform/windows/win32_platform_handler.h FILE: ../../../flutter/shell/platform/windows/win32_window.cc FILE: ../../../flutter/shell/platform/windows/win32_window.h FILE: ../../../flutter/shell/platform/windows/win32_window_proc_delegate_manager.cc diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index 98c6f70294cb1..86794d4d1b01e 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -58,6 +58,8 @@ source_set("flutter_windows_source") { "key_event_handler.cc", "key_event_handler.h", "keyboard_hook_handler.h", + "platform_handler.cc", + "platform_handler.h", "string_conversion.cc", "string_conversion.h", "system_utils.h", @@ -73,6 +75,8 @@ source_set("flutter_windows_source") { if (target_os == "winuwp") { sources += [ "flutter_windows_winuwp.cc", + "platform_handler_winuwp.cc", + "platform_handler_winuwp.h", "system_utils_winuwp.cc", "task_runner_winuwp.cc", "task_runner_winuwp.h", @@ -80,6 +84,8 @@ source_set("flutter_windows_source") { } else { sources += [ "flutter_windows_win32.cc", + "platform_handler_win32.cc", + "platform_handler_win32.h", "system_utils_win32.cc", "task_runner_win32.cc", "task_runner_win32.h", @@ -87,8 +93,6 @@ source_set("flutter_windows_source") { "win32_dpi_utils.h", "win32_flutter_window.cc", "win32_flutter_window.h", - "win32_platform_handler.cc", - "win32_platform_handler.h", "win32_window.cc", "win32_window.h", "win32_window_proc_delegate_manager.cc", diff --git a/shell/platform/windows/flutter_windows_view.cc b/shell/platform/windows/flutter_windows_view.cc index 0c2a568d96c56..bcac661aa17fb 100644 --- a/shell/platform/windows/flutter_windows_view.cc +++ b/shell/platform/windows/flutter_windows_view.cc @@ -39,10 +39,7 @@ void FlutterWindowsView::SetEngine( std::make_unique(internal_plugin_messenger)); keyboard_hook_handlers_.push_back( std::make_unique(internal_plugin_messenger)); -#ifndef WINUWP - platform_handler_ = std::make_unique( - internal_plugin_messenger, this); -#endif + platform_handler_ = PlatformHandler::Create(internal_plugin_messenger, this); cursor_handler_ = std::make_unique( internal_plugin_messenger, binding_handler_.get()); diff --git a/shell/platform/windows/flutter_windows_view.h b/shell/platform/windows/flutter_windows_view.h index 25cc9b8b1f3ce..4863ef7b1a30f 100644 --- a/shell/platform/windows/flutter_windows_view.h +++ b/shell/platform/windows/flutter_windows_view.h @@ -18,16 +18,13 @@ #include "flutter/shell/platform/windows/flutter_windows_engine.h" #include "flutter/shell/platform/windows/key_event_handler.h" #include "flutter/shell/platform/windows/keyboard_hook_handler.h" +#include "flutter/shell/platform/windows/platform_handler.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" #include "flutter/shell/platform/windows/text_input_plugin.h" #include "flutter/shell/platform/windows/window_binding_handler.h" #include "flutter/shell/platform/windows/window_binding_handler_delegate.h" #include "flutter/shell/platform/windows/window_state.h" -#ifndef WINUWP -#include "flutter/shell/platform/windows/win32_platform_handler.h" // nogncheck -#endif - namespace flutter { // An OS-windowing neutral abstration for flutter @@ -201,10 +198,8 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate { std::vector> keyboard_hook_handlers_; -#ifndef WINUWP // Handler for the flutter/platform channel. std::unique_ptr platform_handler_; -#endif // Handler for cursor events. std::unique_ptr cursor_handler_; diff --git a/shell/platform/windows/flutter_windows_win32.cc b/shell/platform/windows/flutter_windows_win32.cc index 3ebe73af2f654..4ee427eac5144 100644 --- a/shell/platform/windows/flutter_windows_win32.cc +++ b/shell/platform/windows/flutter_windows_win32.cc @@ -69,7 +69,7 @@ bool FlutterDesktopViewControllerHandleTopLevelWindowProc( } uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine) { - return static_cast( + return static_cast( EngineFromHandle(engine)->task_runner()) ->ProcessTasks() .count(); diff --git a/shell/platform/windows/platform_handler.cc b/shell/platform/windows/platform_handler.cc new file mode 100644 index 0000000000000..6267583a80a7e --- /dev/null +++ b/shell/platform/windows/platform_handler.cc @@ -0,0 +1,62 @@ +// 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_handler.h" + +#include "flutter/shell/platform/common/cpp/json_method_codec.h" + +static constexpr char kChannelName[] = "flutter/platform"; + +static constexpr char kGetClipboardDataMethod[] = "Clipboard.getData"; +static constexpr char kSetClipboardDataMethod[] = "Clipboard.setData"; + +static constexpr char kTextPlainFormat[] = "text/plain"; +static constexpr char kTextKey[] = "text"; + +static constexpr char kUnknownClipboardFormatMessage[] = + "Unknown clipboard format"; + +namespace flutter { + +PlatformHandler::PlatformHandler(BinaryMessenger* messenger) + : channel_(std::make_unique>( + messenger, + kChannelName, + &JsonMethodCodec::GetInstance())) { + channel_->SetMethodCallHandler( + [this](const MethodCall& call, + std::unique_ptr> result) { + HandleMethodCall(call, std::move(result)); + }); +} + +PlatformHandler::~PlatformHandler() = default; + +void PlatformHandler::HandleMethodCall( + const MethodCall& method_call, + std::unique_ptr> result) { + const std::string& method = method_call.method_name(); + if (method.compare(kGetClipboardDataMethod) == 0) { + // Only one string argument is expected. + const rapidjson::Value& format = method_call.arguments()[0]; + + if (strcmp(format.GetString(), kTextPlainFormat) != 0) { + result->Error(kClipboardError, kUnknownClipboardFormatMessage); + return; + } + GetPlainText(std::move(result), kTextKey); + } else if (method.compare(kSetClipboardDataMethod) == 0) { + const rapidjson::Value& document = *method_call.arguments(); + rapidjson::Value::ConstMemberIterator itr = document.FindMember(kTextKey); + if (itr == document.MemberEnd()) { + result->Error(kClipboardError, kUnknownClipboardFormatMessage); + return; + } + SetPlainText(itr->value.GetString(), std::move(result)); + } else { + result->NotImplemented(); + } +} + +} // namespace flutter diff --git a/shell/platform/windows/platform_handler.h b/shell/platform/windows/platform_handler.h new file mode 100644 index 0000000000000..ba5a86ea0d8ed --- /dev/null +++ b/shell/platform/windows/platform_handler.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_HANDLER_H_ +#define FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_HANDLER_H_ + +#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h" +#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_channel.h" +#include "rapidjson/document.h" + +namespace flutter { + +class FlutterWindowsView; + +// Handler for internal system channels. +class PlatformHandler { + public: + explicit PlatformHandler(BinaryMessenger* messenger); + + virtual ~PlatformHandler(); + + // Creates a new platform handler using the given messenger and view. + static std::unique_ptr Create(BinaryMessenger* messenger, + FlutterWindowsView* view); + + protected: + // Gets plain text from the clipboard and provides it to |result| as the + // value in a dictionary with the given |key|. + virtual void GetPlainText( + std::unique_ptr> result, + const char* key) = 0; + + // Sets the clipboard's plain text to |text|, and reports the result (either + // an error, or null for success) to |result|. + virtual void SetPlainText( + const std::string& text, + std::unique_ptr> result) = 0; + + // A error type to use for error responses. + static constexpr char kClipboardError[] = "Clipboard error"; + + private: + // Called when a method is called on |channel_|; + void HandleMethodCall( + const MethodCall& method_call, + std::unique_ptr> result); + + // The MethodChannel used for communication with the Flutter engine. + std::unique_ptr> channel_; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_HANDLER_H_ diff --git a/shell/platform/windows/win32_platform_handler.cc b/shell/platform/windows/platform_handler_win32.cc similarity index 57% rename from shell/platform/windows/win32_platform_handler.cc rename to shell/platform/windows/platform_handler_win32.cc index 63543dfb8de16..f891bd540421a 100644 --- a/shell/platform/windows/win32_platform_handler.cc +++ b/shell/platform/windows/platform_handler_win32.cc @@ -2,7 +2,7 @@ // 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/win32_platform_handler.h" +#include "flutter/shell/platform/windows/platform_handler_win32.h" #include @@ -10,22 +10,9 @@ #include #include -#include "flutter/shell/platform/common/cpp/json_method_codec.h" #include "flutter/shell/platform/windows/flutter_windows_view.h" #include "flutter/shell/platform/windows/string_conversion.h" -static constexpr char kChannelName[] = "flutter/platform"; - -static constexpr char kGetClipboardDataMethod[] = "Clipboard.getData"; -static constexpr char kSetClipboardDataMethod[] = "Clipboard.setData"; - -static constexpr char kTextPlainFormat[] = "text/plain"; -static constexpr char kTextKey[] = "text"; - -static constexpr char kClipboardError[] = "Clipboard error"; -static constexpr char kUnknownClipboardFormatMessage[] = - "Unknown clipboard format"; - namespace flutter { namespace { @@ -198,88 +185,67 @@ bool ScopedClipboard::SetString(const std::wstring string) { } // namespace -PlatformHandler::PlatformHandler(flutter::BinaryMessenger* messenger, - FlutterWindowsView* view) - : channel_(std::make_unique>( - messenger, - kChannelName, - &flutter::JsonMethodCodec::GetInstance())), - view_(view) { - channel_->SetMethodCallHandler( - [this]( - const flutter::MethodCall& call, - std::unique_ptr> result) { - HandleMethodCall(call, std::move(result)); - }); +// static +std::unique_ptr PlatformHandler::Create( + BinaryMessenger* messenger, + FlutterWindowsView* view) { + return std::make_unique(messenger, view); } -void PlatformHandler::HandleMethodCall( - const flutter::MethodCall& method_call, - std::unique_ptr> result) { - const std::string& method = method_call.method_name(); - if (method.compare(kGetClipboardDataMethod) == 0) { - // Only one string argument is expected. - const rapidjson::Value& format = method_call.arguments()[0]; - - if (strcmp(format.GetString(), kTextPlainFormat) != 0) { - result->Error(kClipboardError, kUnknownClipboardFormatMessage); - return; - } - ScopedClipboard clipboard; - if (!clipboard.Open(std::get(*view_->GetRenderTarget()))) { - rapidjson::Document error_code; - error_code.SetInt(::GetLastError()); - result->Error(kClipboardError, "Unable to open clipboard", error_code); - return; - } - if (!clipboard.HasString()) { - result->Success(rapidjson::Document()); - return; - } - std::optional clipboard_string = clipboard.GetString(); - if (!clipboard_string) { - rapidjson::Document error_code; - error_code.SetInt(::GetLastError()); - result->Error(kClipboardError, "Unable to get clipboard data", - error_code); - return; - } - - rapidjson::Document document; - document.SetObject(); - rapidjson::Document::AllocatorType& allocator = document.GetAllocator(); - document.AddMember( - rapidjson::Value(kTextKey, allocator), - rapidjson::Value(Utf8FromUtf16(*clipboard_string), allocator), - allocator); - result->Success(document); - } else if (method.compare(kSetClipboardDataMethod) == 0) { - const rapidjson::Value& document = *method_call.arguments(); - rapidjson::Value::ConstMemberIterator itr = document.FindMember(kTextKey); - if (itr == document.MemberEnd()) { - result->Error(kClipboardError, kUnknownClipboardFormatMessage); - return; - } +PlatformHandlerWin32::PlatformHandlerWin32(BinaryMessenger* messenger, + FlutterWindowsView* view) + : PlatformHandler(messenger), view_(view) {} + +PlatformHandlerWin32::~PlatformHandlerWin32() = default; + +void PlatformHandlerWin32::GetPlainText( + std::unique_ptr> result, + const char* key) { + ScopedClipboard clipboard; + if (!clipboard.Open(std::get(*view_->GetRenderTarget()))) { + rapidjson::Document error_code; + error_code.SetInt(::GetLastError()); + result->Error(kClipboardError, "Unable to open clipboard", error_code); + return; + } + if (!clipboard.HasString()) { + result->Success(rapidjson::Document()); + return; + } + std::optional clipboard_string = clipboard.GetString(); + if (!clipboard_string) { + rapidjson::Document error_code; + error_code.SetInt(::GetLastError()); + result->Error(kClipboardError, "Unable to get clipboard data", error_code); + return; + } - ScopedClipboard clipboard; + rapidjson::Document document; + document.SetObject(); + rapidjson::Document::AllocatorType& allocator = document.GetAllocator(); + document.AddMember( + rapidjson::Value(key, allocator), + rapidjson::Value(Utf8FromUtf16(*clipboard_string), allocator), allocator); + result->Success(document); +} - if (!clipboard.Open(std::get(*view_->GetRenderTarget()))) { - rapidjson::Document error_code; - error_code.SetInt(::GetLastError()); - result->Error(kClipboardError, "Unable to open clipboard", error_code); - return; - } - if (!clipboard.SetString(Utf16FromUtf8(itr->value.GetString()))) { - rapidjson::Document error_code; - error_code.SetInt(::GetLastError()); - result->Error(kClipboardError, "Unable to set clipboard data", - error_code); - return; - } - result->Success(); - } else { - result->NotImplemented(); +void PlatformHandlerWin32::SetPlainText( + const std::string& text, + std::unique_ptr> result) { + ScopedClipboard clipboard; + if (!clipboard.Open(std::get(*view_->GetRenderTarget()))) { + rapidjson::Document error_code; + error_code.SetInt(::GetLastError()); + result->Error(kClipboardError, "Unable to open clipboard", error_code); + return; + } + if (!clipboard.SetString(Utf16FromUtf8(text))) { + rapidjson::Document error_code; + error_code.SetInt(::GetLastError()); + result->Error(kClipboardError, "Unable to set clipboard data", error_code); + return; } + result->Success(); } } // namespace flutter diff --git a/shell/platform/windows/platform_handler_win32.h b/shell/platform/windows/platform_handler_win32.h new file mode 100644 index 0000000000000..c2879a1a4c4fd --- /dev/null +++ b/shell/platform/windows/platform_handler_win32.h @@ -0,0 +1,43 @@ +// 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_HANDLER_WIN32_H_ +#define FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_HANDLER_WIN32_H_ + +#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h" +#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_channel.h" +#include "flutter/shell/platform/windows/flutter_windows_view.h" +#include "flutter/shell/platform/windows/platform_handler.h" +#include "rapidjson/document.h" + +namespace flutter { + +class FlutterWindowsView; + +// Win32 implementation of PlatformHandler. +class PlatformHandlerWin32 : public PlatformHandler { + public: + explicit PlatformHandlerWin32(BinaryMessenger* messenger, + FlutterWindowsView* view); + + virtual ~PlatformHandlerWin32(); + + protected: + // |PlatformHandler| + void GetPlainText(std::unique_ptr> result, + const char* key) override; + + // |PlatformHandler| + void SetPlainText( + const std::string& text, + std::unique_ptr> result) override; + + private: + // A reference to the Flutter view. + FlutterWindowsView* view_; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_HANDLER_WIN32_H_ diff --git a/shell/platform/windows/platform_handler_winuwp.cc b/shell/platform/windows/platform_handler_winuwp.cc new file mode 100644 index 0000000000000..cc3e3094302d4 --- /dev/null +++ b/shell/platform/windows/platform_handler_winuwp.cc @@ -0,0 +1,38 @@ +// 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_handler_winuwp.h" + +#include "flutter/shell/platform/windows/flutter_windows_view.h" + +namespace flutter { + +// static +std::unique_ptr PlatformHandler::Create( + BinaryMessenger* messenger, + FlutterWindowsView* view) { + return std::make_unique(mesenger, view); +} + +PlatformHandlerWinUwp::PlatformHandlerWinUwp(BinaryMessenger* messenger, + FlutterWindowsView* view) + : PlatformHandler(messenger), view_(view) {} + +PlatformHandlerWinUwp::~PlatformHandlerWinUwp() = default; + +void PlatformHandlerWinUwp::GetPlainText( + std::unique_ptr> result, + const char* key) { + // TODO: Implement. See https://github.com/flutter/flutter/issues/70214. + result->NotImplemented(); +} + +void PlatformHandlerWinUwp::SetPlainText( + const std::string& text, + std::unique_ptr> result) { + // TODO: Implement. See https://github.com/flutter/flutter/issues/70214. + result->NotImplemented(); +} + +} // namespace flutter diff --git a/shell/platform/windows/platform_handler_winuwp.h b/shell/platform/windows/platform_handler_winuwp.h new file mode 100644 index 0000000000000..7a8a9ce504c6b --- /dev/null +++ b/shell/platform/windows/platform_handler_winuwp.h @@ -0,0 +1,43 @@ +// 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_HANDLER_WINUWP_H_ +#define FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_HANDLER_WINUWP_H_ + +#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h" +#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_channel.h" +#include "flutter/shell/platform/windows/flutter_windows_view.h" +#include "flutter/shell/platform/windows/platform_handler.h" +#include "rapidjson/document.h" + +namespace flutter { + +class FlutterWindowsView; + +// UWP implementation of PlatformHandler. +class PlatformHandlerWinUwp : public PlatformHandler { + public: + explicit PlatformHandlerWinUwp(BinaryMessenger* messenger, + FlutterWindowsView* view); + + virtual ~PlatformHandlerWinUwp(); + + protected: + // |PlatformHandler| + void GetPlainText(std::unique_ptr> result, + const char* key) override; + + // |PlatformHandler| + void SetPlainText( + const std::string& text, + std::unique_ptr> result) override; + + private: + // A reference to the Flutter view. + FlutterWindowsView* view_; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_HANDLER_WINUWP_H_ diff --git a/shell/platform/windows/win32_platform_handler.h b/shell/platform/windows/win32_platform_handler.h deleted file mode 100644 index bcf939edd4174..0000000000000 --- a/shell/platform/windows/win32_platform_handler.h +++ /dev/null @@ -1,38 +0,0 @@ -// 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_HANDLER_H_ -#define FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_HANDLER_H_ - -#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h" -#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_channel.h" -#include "flutter/shell/platform/windows/public/flutter_windows.h" -#include "rapidjson/document.h" - -namespace flutter { - -class FlutterWindowsView; - -// Handler for internal system channels. -class PlatformHandler { - public: - explicit PlatformHandler(flutter::BinaryMessenger* messenger, - FlutterWindowsView* view); - - private: - // Called when a method is called on |channel_|; - void HandleMethodCall( - const flutter::MethodCall& method_call, - std::unique_ptr> result); - - // The MethodChannel used for communication with the Flutter engine. - std::unique_ptr> channel_; - - // A reference to the win32 window. - FlutterWindowsView* view_; -}; - -} // namespace flutter - -#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_HANDLER_H_ From e4c8484faa954e8d23487e15464030211ae30a44 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 23 Nov 2020 18:05:00 -0800 Subject: [PATCH 12/19] Do some testing backfill on the refactored PlatformHandler --- shell/platform/windows/BUILD.gn | 2 + .../windows/platform_handler_unittests.cc | 155 ++++++++++++++++++ .../windows/testing/test_binary_messenger.h | 80 +++++++++ 3 files changed, 237 insertions(+) create mode 100644 shell/platform/windows/platform_handler_unittests.cc create mode 100644 shell/platform/windows/testing/test_binary_messenger.h diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index 86794d4d1b01e..ceda6261f20be 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -160,6 +160,7 @@ if (target_os == "winuwp") { sources = [ "flutter_project_bundle_unittests.cc", "flutter_windows_engine_unittests.cc", + "platform_handler_unittests.cc", "string_conversion_unittests.cc", "system_utils_unittests.cc", "testing/engine_embedder_api_modifier.h", @@ -179,6 +180,7 @@ if (target_os == "winuwp") { ":flutter_windows_fixtures", ":flutter_windows_headers", ":flutter_windows_source", + "//flutter/shell/platform/common/cpp:common_cpp", "//flutter/shell/platform/embedder:embedder_as_internal_library", "//flutter/shell/platform/embedder:embedder_test_utils", "//flutter/testing", diff --git a/shell/platform/windows/platform_handler_unittests.cc b/shell/platform/windows/platform_handler_unittests.cc new file mode 100644 index 0000000000000..78b348b8a84d0 --- /dev/null +++ b/shell/platform/windows/platform_handler_unittests.cc @@ -0,0 +1,155 @@ +// 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_handler.h" + +#include + +#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h" +#include "flutter/shell/platform/common/cpp/json_method_codec.h" +#include "flutter/shell/platform/windows/testing/test_binary_messenger.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include "rapidjson/document.h" + +namespace flutter { +namespace testing { + +namespace { +using ::testing::_; + +static constexpr char kChannelName[] = "flutter/platform"; + +static constexpr char kGetClipboardDataMethod[] = "Clipboard.getData"; +static constexpr char kSetClipboardDataMethod[] = "Clipboard.setData"; + +static constexpr char kTextPlainFormat[] = "text/plain"; + +// Test implementation of PlatformHandler to allow testing the PlatformHandler +// logic. +class TestPlatformHandler : public PlatformHandler { + public: + explicit TestPlatformHandler(BinaryMessenger* messenger) + : PlatformHandler(messenger) {} + + virtual ~TestPlatformHandler() {} + + // |PlatformHandler| + MOCK_METHOD2(GetPlainText, + void(std::unique_ptr>, + const char*)); + MOCK_METHOD2(SetPlainText, + void(const std::string&, + std::unique_ptr>)); +}; + +// Mock result to inspect results of PlatformHandler calls. +class MockMethodResult : public MethodResult { + public: + MOCK_METHOD1(SuccessInternal, void(const rapidjson::Document*)); + MOCK_METHOD3(ErrorInternal, + void(const std::string&, + const std::string&, + const rapidjson::Document*)); + MOCK_METHOD0(NotImplementedInternal, void()); +}; + +} // namespace + +TEST(PlatformHandler, GettingTextCallsThrough) { + TestBinaryMessenger messenger; + TestPlatformHandler platform_handler(&messenger); + + auto args = std::make_unique(rapidjson::kArrayType); + auto& allocator = args->GetAllocator(); + args->PushBack(kTextPlainFormat, allocator); + auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall( + MethodCall(kGetClipboardDataMethod, + std::move(args))); + + // Set up a handler to call a response on |result| so that it doesn't log + // on destruction about leaking. + ON_CALL(platform_handler, GetPlainText) + .WillByDefault( + [](std::unique_ptr> result, + auto key) { result->NotImplemented(); }); + + EXPECT_CALL(platform_handler, GetPlainText(_, ::testing::StrEq("text"))); + EXPECT_TRUE(messenger.SimulateEngineMessage( + kChannelName, encoded->data(), encoded->size(), + [](const uint8_t* reply, size_t reply_size) {})); +} + +TEST(PlatformHandler, RejectsGettingUnknownTypes) { + TestBinaryMessenger messenger; + TestPlatformHandler platform_handler(&messenger); + + auto args = std::make_unique(rapidjson::kArrayType); + auto& allocator = args->GetAllocator(); + args->PushBack("madeup/contenttype", allocator); + auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall( + MethodCall(kGetClipboardDataMethod, + std::move(args))); + + MockMethodResult result; + // Requsting an unknow content type is an error. + EXPECT_CALL(result, ErrorInternal(_, _, _)); + EXPECT_TRUE(messenger.SimulateEngineMessage( + kChannelName, encoded->data(), encoded->size(), + [&](const uint8_t* reply, size_t reply_size) { + JsonMethodCodec::GetInstance().DecodeAndProcessResponseEnvelope( + reply, reply_size, &result); + })); +} + +TEST(PlatformHandler, SettingTextCallsThrough) { + TestBinaryMessenger messenger; + TestPlatformHandler platform_handler(&messenger); + + auto args = std::make_unique(rapidjson::kObjectType); + auto& allocator = args->GetAllocator(); + args->AddMember("text", "hello", allocator); + auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall( + MethodCall(kSetClipboardDataMethod, + std::move(args))); + + // Set up a handler to call a response on |result| so that it doesn't log + // on destruction about leaking. + ON_CALL(platform_handler, SetPlainText) + .WillByDefault( + [](auto value, + std::unique_ptr> result) { + result->NotImplemented(); + }); + + EXPECT_CALL(platform_handler, SetPlainText(::testing::StrEq("hello"), _)); + EXPECT_TRUE(messenger.SimulateEngineMessage( + kChannelName, encoded->data(), encoded->size(), + [](const uint8_t* reply, size_t reply_size) {})); +} + +TEST(PlatformHandler, RejectsSettingUnknownTypes) { + TestBinaryMessenger messenger; + TestPlatformHandler platform_handler(&messenger); + + auto args = std::make_unique(rapidjson::kObjectType); + auto& allocator = args->GetAllocator(); + args->AddMember("madeuptype", "hello", allocator); + auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall( + MethodCall(kSetClipboardDataMethod, + std::move(args))); + + MockMethodResult result; + // Requsting an unknow content type is an error. + EXPECT_CALL(result, ErrorInternal(_, _, _)); + EXPECT_TRUE(messenger.SimulateEngineMessage( + kChannelName, encoded->data(), encoded->size(), + [&](const uint8_t* reply, size_t reply_size) { + JsonMethodCodec::GetInstance().DecodeAndProcessResponseEnvelope( + reply, reply_size, &result); + })); +} + +} // namespace testing +} // namespace flutter diff --git a/shell/platform/windows/testing/test_binary_messenger.h b/shell/platform/windows/testing/test_binary_messenger.h new file mode 100644 index 0000000000000..157a1e8f1f12d --- /dev/null +++ b/shell/platform/windows/testing/test_binary_messenger.h @@ -0,0 +1,80 @@ +// 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_TEST_BINARY_MESSENGER_H_ +#define FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_TEST_BINARY_MESSENGER_H_ + +#include +#include +#include +#include + +#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h" + +namespace flutter { + +// A trivial BinaryMessenger implementation for use in tests. +class TestBinaryMessenger : public BinaryMessenger { + public: + using SendHandler = std::function; + + // Creates a new messenge that forwards all calls to |send_handler|. + explicit TestBinaryMessenger(SendHandler send_handler = nullptr) + : send_handler_(std::move(send_handler)) {} + + virtual ~TestBinaryMessenger() = default; + + // Prevent copying. + TestBinaryMessenger(TestBinaryMessenger const&) = delete; + TestBinaryMessenger& operator=(TestBinaryMessenger const&) = delete; + + // Simulates a message from the engine on the given channel. + // + // Returns false if no handler is registered on that channel. + bool SimulateEngineMessage(const std::string& channel, + const uint8_t* message, + size_t message_size, + BinaryReply reply) { + auto handler = registered_handlers_.find(channel); + if (handler == registered_handlers_.end()) { + return false; + } + (handler->second)(message, message_size, reply); + return true; + } + + // |flutter::BinaryMessenger| + void Send(const std::string& channel, + const uint8_t* message, + size_t message_size, + BinaryReply reply) const override { + // If something under test sends a message, the test should be handling it. + assert(send_handler_); + send_handler_(channel, message, message_size, reply); + } + + // |flutter::BinaryMessenger| + void SetMessageHandler(const std::string& channel, + BinaryMessageHandler handler) override { + if (handler) { + registered_handlers_[channel] = handler; + } else { + registered_handlers_.erase(channel); + } + } + + private: + // Handler to call for SendMessage. + SendHandler send_handler_; + + // Mapping of channel name to registered handlers. + std::map registered_handlers_; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_TEST_BINARY_MESSENGER_H_ From 895088c8531bf55824518d4b3eac2185701e01e0 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 23 Nov 2020 18:08:05 -0800 Subject: [PATCH 13/19] Formatting --- shell/platform/windows/BUILD.gn | 77 +++++++++++-------- .../platform/windows/client_wrapper/BUILD.gn | 9 ++- .../platform/windows/public/flutter_windows.h | 2 +- 3 files changed, 50 insertions(+), 38 deletions(-) diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index ceda6261f20be..2433913868113 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -26,8 +26,9 @@ config("relative_flutter_windows_headers") { source_set("flutter_windows_headers") { public = _public_headers - public_deps = - [ "//flutter/shell/platform/common/cpp:common_cpp_library_headers" ] + public_deps = [ + "//flutter/shell/platform/common/cpp:common_cpp_library_headers", + ] if (target_os == "winuwp") { configs += @@ -129,20 +130,28 @@ source_set("flutter_windows_source") { copy("publish_headers_windows") { sources = _public_headers - outputs = [ "$root_out_dir/{{source_file_part}}" ] + outputs = [ + "$root_out_dir/{{source_file_part}}", + ] # The Windows header assumes the presence of the common headers. - deps = [ "//flutter/shell/platform/common/cpp:publish_headers" ] + deps = [ + "//flutter/shell/platform/common/cpp:publish_headers", + ] } shared_library("flutter_windows") { - deps = [ ":flutter_windows_source" ] + deps = [ + ":flutter_windows_source", + ] public_configs = [ "//flutter:config" ] } shared_library("flutter_windows_winuwp") { - deps = [ ":flutter_windows_source" ] + deps = [ + ":flutter_windows_source", + ] libs = [ "windowsapp.lib" ] public_configs = [ "//flutter:config" ] } @@ -157,40 +166,42 @@ if (target_os == "winuwp") { executable("flutter_windows_unittests") { testonly = true - sources = [ - "flutter_project_bundle_unittests.cc", - "flutter_windows_engine_unittests.cc", - "platform_handler_unittests.cc", - "string_conversion_unittests.cc", - "system_utils_unittests.cc", - "testing/engine_embedder_api_modifier.h", - "testing/mock_win32_window.cc", - "testing/mock_win32_window.h", - "testing/win32_flutter_window_test.cc", - "testing/win32_flutter_window_test.h", - "win32_dpi_utils_unittests.cc", - "win32_flutter_window_unittests.cc", - "win32_window_proc_delegate_manager_unittests.cc", - "win32_window_unittests.cc", - ] + sources = [ + "flutter_project_bundle_unittests.cc", + "flutter_windows_engine_unittests.cc", + "platform_handler_unittests.cc", + "string_conversion_unittests.cc", + "system_utils_unittests.cc", + "testing/engine_embedder_api_modifier.h", + "testing/mock_win32_window.cc", + "testing/mock_win32_window.h", + "testing/win32_flutter_window_test.cc", + "testing/win32_flutter_window_test.h", + "win32_dpi_utils_unittests.cc", + "win32_flutter_window_unittests.cc", + "win32_window_proc_delegate_manager_unittests.cc", + "win32_window_unittests.cc", + ] public_configs = [ "//flutter:config" ] - deps = [ - ":flutter_windows_fixtures", - ":flutter_windows_headers", - ":flutter_windows_source", - "//flutter/shell/platform/common/cpp:common_cpp", - "//flutter/shell/platform/embedder:embedder_as_internal_library", - "//flutter/shell/platform/embedder:embedder_test_utils", - "//flutter/testing", - "//third_party/rapidjson", - ] + deps = [ + ":flutter_windows_fixtures", + ":flutter_windows_headers", + ":flutter_windows_source", + "//flutter/shell/platform/common/cpp:common_cpp", + "//flutter/shell/platform/embedder:embedder_as_internal_library", + "//flutter/shell/platform/embedder:embedder_test_utils", + "//flutter/testing", + "//third_party/rapidjson", + ] } } shared_library("flutter_windows_glfw") { - deps = [ "//flutter/shell/platform/glfw:flutter_glfw" ] + deps = [ + "//flutter/shell/platform/glfw:flutter_glfw", + ] public_configs = [ "//flutter:config" ] } diff --git a/shell/platform/windows/client_wrapper/BUILD.gn b/shell/platform/windows/client_wrapper/BUILD.gn index 15fc0d4c16d33..50e15613e82a7 100644 --- a/shell/platform/windows/client_wrapper/BUILD.gn +++ b/shell/platform/windows/client_wrapper/BUILD.gn @@ -39,9 +39,8 @@ source_set("client_wrapper_windows") { "//flutter/shell/platform/windows:flutter_windows_headers", ] - configs += [ - "//flutter/shell/platform/common/cpp:desktop_library_implementation", - ] + configs += + [ "//flutter/shell/platform/common/cpp:desktop_library_implementation" ] public_configs = [ ":relative_core_wrapper_headers", @@ -64,7 +63,9 @@ source_set("client_wrapper_library_stubs_windows") { defines = [ "FLUTTER_DESKTOP_LIBRARY" ] - public_deps = [ "//flutter/shell/platform/windows:flutter_windows_headers" ] + public_deps = [ + "//flutter/shell/platform/windows:flutter_windows_headers", + ] } test_fixtures("client_wrapper_windows_fixtures") { diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index 54cb5d905e338..dbcaf8df17035 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -92,7 +92,7 @@ FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine( FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef controller); - #ifndef WINUWP +#ifndef WINUWP // Allows the Flutter engine and any interested plugins an opportunity to // handle the given message. // From 111063c18c936495aa69e1792fcaad7c2b2a3e8b Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 24 Nov 2020 09:36:23 -0800 Subject: [PATCH 14/19] Formatting again, but with the right gn --- shell/platform/windows/BUILD.gn | 25 ++++++------------- .../platform/windows/client_wrapper/BUILD.gn | 4 +-- .../include/flutter/flutter_view_controller.h | 2 +- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index 2433913868113..b1a9dc519f1a9 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -26,9 +26,8 @@ config("relative_flutter_windows_headers") { source_set("flutter_windows_headers") { public = _public_headers - public_deps = [ - "//flutter/shell/platform/common/cpp:common_cpp_library_headers", - ] + public_deps = + [ "//flutter/shell/platform/common/cpp:common_cpp_library_headers" ] if (target_os == "winuwp") { configs += @@ -130,28 +129,20 @@ source_set("flutter_windows_source") { copy("publish_headers_windows") { sources = _public_headers - outputs = [ - "$root_out_dir/{{source_file_part}}", - ] + outputs = [ "$root_out_dir/{{source_file_part}}" ] # The Windows header assumes the presence of the common headers. - deps = [ - "//flutter/shell/platform/common/cpp:publish_headers", - ] + deps = [ "//flutter/shell/platform/common/cpp:publish_headers" ] } shared_library("flutter_windows") { - deps = [ - ":flutter_windows_source", - ] + deps = [ ":flutter_windows_source" ] public_configs = [ "//flutter:config" ] } shared_library("flutter_windows_winuwp") { - deps = [ - ":flutter_windows_source", - ] + deps = [ ":flutter_windows_source" ] libs = [ "windowsapp.lib" ] public_configs = [ "//flutter:config" ] } @@ -199,9 +190,7 @@ if (target_os == "winuwp") { } shared_library("flutter_windows_glfw") { - deps = [ - "//flutter/shell/platform/glfw:flutter_glfw", - ] + deps = [ "//flutter/shell/platform/glfw:flutter_glfw" ] public_configs = [ "//flutter:config" ] } diff --git a/shell/platform/windows/client_wrapper/BUILD.gn b/shell/platform/windows/client_wrapper/BUILD.gn index 50e15613e82a7..fe54c2ba2a484 100644 --- a/shell/platform/windows/client_wrapper/BUILD.gn +++ b/shell/platform/windows/client_wrapper/BUILD.gn @@ -63,9 +63,7 @@ source_set("client_wrapper_library_stubs_windows") { defines = [ "FLUTTER_DESKTOP_LIBRARY" ] - public_deps = [ - "//flutter/shell/platform/windows:flutter_windows_headers", - ] + public_deps = [ "//flutter/shell/platform/windows:flutter_windows_headers" ] } test_fixtures("client_wrapper_windows_fixtures") { diff --git a/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h b/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h index 6a21af0922b81..f39a7e70c980e 100644 --- a/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h +++ b/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h @@ -56,7 +56,7 @@ class FlutterViewController { UINT message, WPARAM wparam, LPARAM lparam); - #endif +#endif private: // Handle for interacting with the C API's view controller, if any. From 26f2b5578041ed8fbee66ba8fa6b1538c21d7880 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 5 Dec 2020 06:23:55 -0800 Subject: [PATCH 15/19] Fix UWP build --- .../platform/windows/platform_handler_winuwp.cc | 2 +- shell/platform/windows/system_utils_winuwp.cc | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/shell/platform/windows/platform_handler_winuwp.cc b/shell/platform/windows/platform_handler_winuwp.cc index cc3e3094302d4..f109c3819713b 100644 --- a/shell/platform/windows/platform_handler_winuwp.cc +++ b/shell/platform/windows/platform_handler_winuwp.cc @@ -12,7 +12,7 @@ namespace flutter { std::unique_ptr PlatformHandler::Create( BinaryMessenger* messenger, FlutterWindowsView* view) { - return std::make_unique(mesenger, view); + return std::make_unique(messenger, view); } PlatformHandlerWinUwp::PlatformHandlerWinUwp(BinaryMessenger* messenger, diff --git a/shell/platform/windows/system_utils_winuwp.cc b/shell/platform/windows/system_utils_winuwp.cc index 4d693def5a758..85278dc0a6dd5 100644 --- a/shell/platform/windows/system_utils_winuwp.cc +++ b/shell/platform/windows/system_utils_winuwp.cc @@ -32,4 +32,20 @@ LanguageInfo ParseLanguageName(std::wstring language_name) { return info; } +std::wstring GetUserTimeFormat() { + // Rather than do the call-allocate-call-free dance, just use a sufficiently + // large buffer to handle any reasonable time format string. + const int kBufferSize = 100; + wchar_t buffer[kBufferSize]; + if (::GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_STIMEFORMAT, buffer, + kBufferSize) == 0) { + return std::wstring(); + } + return std::wstring(buffer, kBufferSize); +} + +bool Prefer24HourTime(std::wstring time_format) { + return time_format.find(L"H") != std::wstring::npos; +} + } // namespace flutter From 59d6d53d1161d257fcd263847c66a0f5f943ebb7 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 5 Dec 2020 07:00:53 -0800 Subject: [PATCH 16/19] Fix the win32 build --- shell/platform/windows/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index b1a9dc519f1a9..873125ad4ebef 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -160,7 +160,6 @@ if (target_os == "winuwp") { sources = [ "flutter_project_bundle_unittests.cc", "flutter_windows_engine_unittests.cc", - "platform_handler_unittests.cc", "string_conversion_unittests.cc", "system_utils_unittests.cc", "testing/engine_embedder_api_modifier.h", From 81b31d7861e3951f910812dedc29d471bcd4f8b2 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 5 Dec 2020 07:14:26 -0800 Subject: [PATCH 17/19] CR feedback --- shell/platform/windows/platform_handler.h | 2 +- shell/platform/windows/platform_handler_win32.cc | 4 ++-- shell/platform/windows/platform_handler_win32.h | 2 +- shell/platform/windows/platform_handler_winuwp.cc | 2 +- shell/platform/windows/platform_handler_winuwp.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/shell/platform/windows/platform_handler.h b/shell/platform/windows/platform_handler.h index ba5a86ea0d8ed..b7268023a8e21 100644 --- a/shell/platform/windows/platform_handler.h +++ b/shell/platform/windows/platform_handler.h @@ -29,7 +29,7 @@ class PlatformHandler { // value in a dictionary with the given |key|. virtual void GetPlainText( std::unique_ptr> result, - const char* key) = 0; + std::string_view key) = 0; // Sets the clipboard's plain text to |text|, and reports the result (either // an error, or null for success) to |result|. diff --git a/shell/platform/windows/platform_handler_win32.cc b/shell/platform/windows/platform_handler_win32.cc index f891bd540421a..b4f0ea351601e 100644 --- a/shell/platform/windows/platform_handler_win32.cc +++ b/shell/platform/windows/platform_handler_win32.cc @@ -200,7 +200,7 @@ PlatformHandlerWin32::~PlatformHandlerWin32() = default; void PlatformHandlerWin32::GetPlainText( std::unique_ptr> result, - const char* key) { + std::string_view key) { ScopedClipboard clipboard; if (!clipboard.Open(std::get(*view_->GetRenderTarget()))) { rapidjson::Document error_code; @@ -224,7 +224,7 @@ void PlatformHandlerWin32::GetPlainText( document.SetObject(); rapidjson::Document::AllocatorType& allocator = document.GetAllocator(); document.AddMember( - rapidjson::Value(key, allocator), + rapidjson::Value(key.data(), allocator), rapidjson::Value(Utf8FromUtf16(*clipboard_string), allocator), allocator); result->Success(document); } diff --git a/shell/platform/windows/platform_handler_win32.h b/shell/platform/windows/platform_handler_win32.h index c2879a1a4c4fd..ad8ec92ed5e37 100644 --- a/shell/platform/windows/platform_handler_win32.h +++ b/shell/platform/windows/platform_handler_win32.h @@ -26,7 +26,7 @@ class PlatformHandlerWin32 : public PlatformHandler { protected: // |PlatformHandler| void GetPlainText(std::unique_ptr> result, - const char* key) override; + std::string_view key) override; // |PlatformHandler| void SetPlainText( diff --git a/shell/platform/windows/platform_handler_winuwp.cc b/shell/platform/windows/platform_handler_winuwp.cc index f109c3819713b..e984d1fc9fd79 100644 --- a/shell/platform/windows/platform_handler_winuwp.cc +++ b/shell/platform/windows/platform_handler_winuwp.cc @@ -23,7 +23,7 @@ PlatformHandlerWinUwp::~PlatformHandlerWinUwp() = default; void PlatformHandlerWinUwp::GetPlainText( std::unique_ptr> result, - const char* key) { + std::string_view key) { // TODO: Implement. See https://github.com/flutter/flutter/issues/70214. result->NotImplemented(); } diff --git a/shell/platform/windows/platform_handler_winuwp.h b/shell/platform/windows/platform_handler_winuwp.h index 7a8a9ce504c6b..f8b2b221e1961 100644 --- a/shell/platform/windows/platform_handler_winuwp.h +++ b/shell/platform/windows/platform_handler_winuwp.h @@ -26,7 +26,7 @@ class PlatformHandlerWinUwp : public PlatformHandler { protected: // |PlatformHandler| void GetPlainText(std::unique_ptr> result, - const char* key) override; + std::string_view key) override; // |PlatformHandler| void SetPlainText( From 15d6fb64816305aaad5044ea3cb218f28170fa47 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 5 Dec 2020 07:48:13 -0800 Subject: [PATCH 18/19] Make licenses happy again --- ci/licenses_golden/licenses_flutter | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index d246a264799f7..c97e31f0ec04e 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1415,6 +1415,7 @@ FILE: ../../../flutter/shell/platform/windows/key_event_handler.h FILE: ../../../flutter/shell/platform/windows/keyboard_hook_handler.h FILE: ../../../flutter/shell/platform/windows/platform_handler.cc FILE: ../../../flutter/shell/platform/windows/platform_handler.h +FILE: ../../../flutter/shell/platform/windows/platform_handler_unittests.cc FILE: ../../../flutter/shell/platform/windows/platform_handler_win32.cc FILE: ../../../flutter/shell/platform/windows/platform_handler_win32.h FILE: ../../../flutter/shell/platform/windows/platform_handler_winuwp.cc From a4a43c6c8f4af1bda83cf7b9e81687f89c12391e Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 5 Dec 2020 08:08:43 -0800 Subject: [PATCH 19/19] Make licenses happy again take 2 --- ci/licenses_golden/licenses_flutter | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index c97e31f0ec04e..e87e78e4dbadd 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1403,13 +1403,13 @@ FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle.cc FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle.h FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle_unittests.cc FILE: ../../../flutter/shell/platform/windows/flutter_windows.cc -FILE: ../../../flutter/shell/platform/windows/flutter_windows_win32.cc -FILE: ../../../flutter/shell/platform/windows/flutter_windows_winuwp.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_engine_unittests.cc FILE: ../../../flutter/shell/platform/windows/flutter_windows_view.cc FILE: ../../../flutter/shell/platform/windows/flutter_windows_view.h +FILE: ../../../flutter/shell/platform/windows/flutter_windows_win32.cc +FILE: ../../../flutter/shell/platform/windows/flutter_windows_winuwp.cc FILE: ../../../flutter/shell/platform/windows/key_event_handler.cc FILE: ../../../flutter/shell/platform/windows/key_event_handler.h FILE: ../../../flutter/shell/platform/windows/keyboard_hook_handler.h