From e9543eaf17bef4fb8a02711b5b2abd584920d329 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Fri, 12 Feb 2021 19:10:09 -0800 Subject: [PATCH] Windows: linker compatibility with AppContainer for winuwp target (flutter/engine#24318) * Update Windows linker settings to be compatible with AppContainer when target==winuwp --- .../flutter/shell/platform/embedder/BUILD.gn | 3 +++ .../flutter/shell/platform/windows/BUILD.gn | 5 ++++- .../platform/windows/key_event_handler.cc | 19 +++++++++++++++++++ .../platform/windows/key_event_handler.h | 11 +++++++++++ engine/src/flutter/shell/testing/BUILD.gn | 8 ++++++++ engine/src/flutter/tools/gn | 2 ++ 6 files changed, 47 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/embedder/BUILD.gn b/engine/src/flutter/shell/platform/embedder/BUILD.gn index 7cbba62bbc5..f545de9691e 100644 --- a/engine/src/flutter/shell/platform/embedder/BUILD.gn +++ b/engine/src/flutter/shell/platform/embedder/BUILD.gn @@ -245,6 +245,9 @@ if (enable_unittests) { sources = [ "tests/embedder_unittests_proctable.cc" ] defines = [ "FLUTTER_ENGINE_NO_PROTOTYPES" ] + if (is_win) { + libs = [ "psapi.lib" ] + } deps = [ ":embedder", diff --git a/engine/src/flutter/shell/platform/windows/BUILD.gn b/engine/src/flutter/shell/platform/windows/BUILD.gn index 8881c7d13b1..0468c04fc2b 100644 --- a/engine/src/flutter/shell/platform/windows/BUILD.gn +++ b/engine/src/flutter/shell/platform/windows/BUILD.gn @@ -170,7 +170,10 @@ 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/engine/src/flutter/shell/platform/windows/key_event_handler.cc b/engine/src/flutter/shell/platform/windows/key_event_handler.cc index 3d6b488bc4b..de607b917d2 100644 --- a/engine/src/flutter/shell/platform/windows/key_event_handler.cc +++ b/engine/src/flutter/shell/platform/windows/key_event_handler.cc @@ -122,7 +122,12 @@ 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 } KeyEventHandler::~KeyEventHandler() = default; @@ -190,6 +195,15 @@ 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; input_event.ki = *key_event; @@ -199,6 +213,7 @@ void KeyEventHandler::HandleResponse(bool handled, "with scancode " << scancode << " (character " << character << ")" << std::endl; } +#endif } } @@ -225,6 +240,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/engine/src/flutter/shell/platform/windows/key_event_handler.h b/engine/src/flutter/shell/platform/windows/key_event_handler.h index 06ae709a912..7c4df0f038f 100644 --- a/engine/src/flutter/shell/platform/windows/key_event_handler.h +++ b/engine/src/flutter/shell/platform/windows/key_event_handler.h @@ -27,8 +27,19 @@ 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); +#else explicit KeyEventHandler(flutter::BinaryMessenger* messenger, SendInputDelegate delegate = SendInput); +#endif virtual ~KeyEventHandler(); diff --git a/engine/src/flutter/shell/testing/BUILD.gn b/engine/src/flutter/shell/testing/BUILD.gn index 459e7e9886d..f82f481326f 100644 --- a/engine/src/flutter/shell/testing/BUILD.gn +++ b/engine/src/flutter/shell/testing/BUILD.gn @@ -13,6 +13,14 @@ executable("testing") { ] sources = [ "tester_main.cc" ] + if (is_win) { + libs = [ + "psapi.lib", + "user32.lib", + "FontSub.lib", + "shlwapi.lib", + ] + } deps = [ "//flutter/assets", diff --git a/engine/src/flutter/tools/gn b/engine/src/flutter/tools/gn index e6f8c218d77..ea19ec069cc 100755 --- a/engine/src/flutter/tools/gn +++ b/engine/src/flutter/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