From 6515f6a9af5de17c0adfc195ac330719893c6f22 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sun, 31 Jan 2021 08:39:13 -0800 Subject: [PATCH 1/4] Update Windows linker settings to be compatible with AppContainer when target==winuwp --- shell/platform/embedder/BUILD.gn | 2 ++ shell/platform/windows/BUILD.gn | 2 +- shell/platform/windows/key_event_handler.cc | 8 ++++++++ shell/platform/windows/key_event_handler.h | 5 +++++ shell/testing/BUILD.gn | 2 ++ tools/gn | 2 ++ 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/shell/platform/embedder/BUILD.gn b/shell/platform/embedder/BUILD.gn index 7cbba62bbc5c5..800a543fe0568 100644 --- a/shell/platform/embedder/BUILD.gn +++ b/shell/platform/embedder/BUILD.gn @@ -246,6 +246,8 @@ if (enable_unittests) { defines = [ "FLUTTER_ENGINE_NO_PROTOTYPES" ] + libs = [ "psapi.lib" ] + deps = [ ":embedder", ":embedder_gpu_configuration", diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index 8881c7d13b170..aea28beedcbd8 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -170,7 +170,7 @@ executable("flutter_windows_unittests") { testonly = true if (target_os == "winuwp") { - libs = [ "windowsapp.lib" ] + libs = [ "windowsapp.lib", "user32.lib" ] } # Common Windows test sources. diff --git a/shell/platform/windows/key_event_handler.cc b/shell/platform/windows/key_event_handler.cc index 3d6b488bc4b82..34e96be2d8dd3 100644 --- a/shell/platform/windows/key_event_handler.cc +++ b/shell/platform/windows/key_event_handler.cc @@ -122,7 +122,9 @@ KeyEventHandler::KeyEventHandler(flutter::BinaryMessenger* messenger, kChannelName, &flutter::JsonMessageCodec::GetInstance())), send_input_(send_input) { +#ifndef WINUWP assert(send_input != nullptr); +#endif } KeyEventHandler::~KeyEventHandler() = default; @@ -190,6 +192,7 @@ void KeyEventHandler::HandleResponse(bool handled, std::cerr << "Unable to find event " << id << " in pending events queue."; return; } +#ifndef WINUWP INPUT input_event; input_event.type = INPUT_KEYBOARD; input_event.ki = *key_event; @@ -199,6 +202,7 @@ void KeyEventHandler::HandleResponse(bool handled, "with scancode " << scancode << " (character " << character << ")" << std::endl; } +#endif } } @@ -225,6 +229,10 @@ bool KeyEventHandler::KeyboardHook(FlutterWindowsView* view, event.AddMember(kKeyMapKey, kWindowsKeyMap, allocator); #ifndef WINUWP event.AddMember(kModifiersKey, GetModsForKeyState(), allocator); +#else + // TODO: Implement modifiers in UWP codepath + // TODO: https://github.com/flutter/flutter/issues/70202 + event.AddMember(kModifiersKey, 0, allocator); #endif switch (action) { diff --git a/shell/platform/windows/key_event_handler.h b/shell/platform/windows/key_event_handler.h index 06ae709a91231..ad50219185235 100644 --- a/shell/platform/windows/key_event_handler.h +++ b/shell/platform/windows/key_event_handler.h @@ -27,8 +27,13 @@ class KeyEventHandler : public KeyboardHookHandler { using SendInputDelegate = std::function; +#ifdef WINUWP + explicit KeyEventHandler(flutter::BinaryMessenger* messenger, + SendInputDelegate delegate = nullptr); +#else explicit KeyEventHandler(flutter::BinaryMessenger* messenger, SendInputDelegate delegate = SendInput); +#endif virtual ~KeyEventHandler(); diff --git a/shell/testing/BUILD.gn b/shell/testing/BUILD.gn index 459e7e9886db6..927d0eea96ef8 100644 --- a/shell/testing/BUILD.gn +++ b/shell/testing/BUILD.gn @@ -14,6 +14,8 @@ executable("testing") { sources = [ "tester_main.cc" ] + libs = [ "psapi.lib", "user32.lib", "FontSub.lib", "shlwapi.lib"] + deps = [ "//flutter/assets", "//flutter/common", diff --git a/tools/gn b/tools/gn index e6f8c218d779f..ea19ec069cc88 100755 --- a/tools/gn +++ b/tools/gn @@ -105,6 +105,8 @@ def to_gn_args(args): gn_args['skia_use_fontconfig'] = args.enable_fontconfig gn_args['flutter_use_fontconfig'] = args.enable_fontconfig gn_args['flutter_enable_skshaper'] = args.enable_skshaper + if args.target_os == 'winuwp': + gn_args['skia_enable_winuwp'] = True if args.enable_skshaper: gn_args['skia_use_icu'] = True gn_args['skia_enable_icu_ubrk_safeclone'] = True From 83ec9c1d5f943c6a113e487a46b156bd044c6e62 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Thu, 11 Feb 2021 17:17:25 -0800 Subject: [PATCH 2/4] Formatting, fix linux and mac builds --- shell/platform/windows/BUILD.gn | 5 ++++- shell/testing/BUILD.gn | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index aea28beedcbd8..0468c04fc2bdc 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -170,7 +170,10 @@ executable("flutter_windows_unittests") { testonly = true if (target_os == "winuwp") { - libs = [ "windowsapp.lib", "user32.lib" ] + libs = [ + "windowsapp.lib", + "user32.lib", + ] } # Common Windows test sources. diff --git a/shell/testing/BUILD.gn b/shell/testing/BUILD.gn index 927d0eea96ef8..f82f481326fc7 100644 --- a/shell/testing/BUILD.gn +++ b/shell/testing/BUILD.gn @@ -13,8 +13,14 @@ executable("testing") { ] sources = [ "tester_main.cc" ] - - libs = [ "psapi.lib", "user32.lib", "FontSub.lib", "shlwapi.lib"] + if (is_win) { + libs = [ + "psapi.lib", + "user32.lib", + "FontSub.lib", + "shlwapi.lib", + ] + } deps = [ "//flutter/assets", From e22ba8797b2a741464f3551d0a0e2ded849db842 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Thu, 11 Feb 2021 17:21:30 -0800 Subject: [PATCH 3/4] try again --- shell/platform/embedder/BUILD.gn | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shell/platform/embedder/BUILD.gn b/shell/platform/embedder/BUILD.gn index 800a543fe0568..f545de9691ef8 100644 --- a/shell/platform/embedder/BUILD.gn +++ b/shell/platform/embedder/BUILD.gn @@ -245,8 +245,9 @@ if (enable_unittests) { sources = [ "tests/embedder_unittests_proctable.cc" ] defines = [ "FLUTTER_ENGINE_NO_PROTOTYPES" ] - - libs = [ "psapi.lib" ] + if (is_win) { + libs = [ "psapi.lib" ] + } deps = [ ":embedder", From 2d6f617e6381aed61fbbeffeaeefbfc6366ec95e Mon Sep 17 00:00:00 2001 From: James Clarke Date: Fri, 12 Feb 2021 18:11:42 -0800 Subject: [PATCH 4/4] Fix CR feedback --- shell/platform/windows/key_event_handler.cc | 11 +++++++++++ shell/platform/windows/key_event_handler.h | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/shell/platform/windows/key_event_handler.cc b/shell/platform/windows/key_event_handler.cc index 34e96be2d8dd3..de607b917d21e 100644 --- a/shell/platform/windows/key_event_handler.cc +++ b/shell/platform/windows/key_event_handler.cc @@ -122,6 +122,9 @@ KeyEventHandler::KeyEventHandler(flutter::BinaryMessenger* messenger, kChannelName, &flutter::JsonMessageCodec::GetInstance())), send_input_(send_input) { +// As described in the header, UWP doesn't support the SendInput API hence we +// only need to assert that the delegate is null in the non-UWP case since it is +// expected to be null in the UWP case. #ifndef WINUWP assert(send_input != nullptr); #endif @@ -192,6 +195,14 @@ void KeyEventHandler::HandleResponse(bool handled, std::cerr << "Unable to find event " << id << " in pending events queue."; return; } + +// As described in the header, the user32 SendInput function is not supported in +// UWP appcontainer and there is no WinRT equivalent hence we pass null for +// SendInputDelegate param. Since this handler is one of last resort, it is +// only applicable for platformview scenarios where the host view can handle +// input events in the event the Flutter view does not choose to handle them. +// Since platformview is currently not support for desktop, there is no +// functional gap caused by this currently. #ifndef WINUWP INPUT input_event; input_event.type = INPUT_KEYBOARD; diff --git a/shell/platform/windows/key_event_handler.h b/shell/platform/windows/key_event_handler.h index ad50219185235..7c4df0f038fc6 100644 --- a/shell/platform/windows/key_event_handler.h +++ b/shell/platform/windows/key_event_handler.h @@ -27,6 +27,12 @@ class KeyEventHandler : public KeyboardHookHandler { using SendInputDelegate = std::function; +// the user32 SendInput function is not supported in UWP appcontainer and there +// is no WinRT equivalent hence we pass null for SendInputDelegate param. Since +// this handler is one of last resort, it is only applicable for platformview +// scenarios where the host view can handle input events in the event the +// Flutter view does not choose to handle them. Since platformview is currently +// not support for desktop, there is no functional gap caused by this currently. #ifdef WINUWP explicit KeyEventHandler(flutter::BinaryMessenger* messenger, SendInputDelegate delegate = nullptr);