Windows: UWP ViewController accepts a CoreApplicationView and exposes to plugins (flutter/engine#25879)
This commit is contained in:
@@ -11,12 +11,12 @@ namespace flutter {
|
||||
|
||||
#ifdef WINUWP
|
||||
FlutterViewController::FlutterViewController(
|
||||
ABI::Windows::UI::Core::CoreWindow* window,
|
||||
ABI::Windows::ApplicationModel::Core::CoreApplicationView* applicationview,
|
||||
ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs* args,
|
||||
const DartProject& project) {
|
||||
engine_ = std::make_unique<FlutterEngine>(project);
|
||||
controller_ = FlutterDesktopViewControllerCreateFromCoreWindow(
|
||||
window, args, engine_->RelinquishEngine());
|
||||
controller_ = FlutterDesktopViewControllerCreateFromCoreApplicationView(
|
||||
applicationview, args, engine_->RelinquishEngine());
|
||||
if (!controller_) {
|
||||
std::cerr << "Failed to create view controller." << std::endl;
|
||||
return;
|
||||
|
||||
@@ -20,7 +20,12 @@ class FlutterView {
|
||||
FlutterView(FlutterView const&) = delete;
|
||||
FlutterView& operator=(FlutterView const&) = delete;
|
||||
|
||||
#ifndef WINUWP
|
||||
#ifdef WINUWP
|
||||
// Returns the backing CoreApplicationView for the view.
|
||||
ABI::Windows::ApplicationModel::Core::CoreApplicationView* GetNativeWindow() {
|
||||
return FlutterDesktopViewGetCoreApplicationView(view_);
|
||||
}
|
||||
#else
|
||||
// Returns the backing HWND for the view.
|
||||
HWND GetNativeWindow() { return FlutterDesktopViewGetHWND(view_); }
|
||||
#endif
|
||||
|
||||
@@ -47,7 +47,8 @@ class FlutterViewController {
|
||||
// |IActivatedEventArgs| will be used to configure the engine switches. Can
|
||||
// be set to nullptr.
|
||||
explicit FlutterViewController(
|
||||
ABI::Windows::UI::Core::CoreWindow* window,
|
||||
ABI::Windows::ApplicationModel::Core::CoreApplicationView*
|
||||
applicationview,
|
||||
ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs* args,
|
||||
const DartProject& project);
|
||||
#endif
|
||||
|
||||
@@ -81,6 +81,10 @@ WindowsRenderTarget FlutterWindowWin32::GetRenderTarget() {
|
||||
return WindowsRenderTarget(GetWindowHandle());
|
||||
}
|
||||
|
||||
PlatformWindow FlutterWindowWin32::GetPlatformWindow() {
|
||||
return GetWindowHandle();
|
||||
}
|
||||
|
||||
float FlutterWindowWin32::GetDpiScale() {
|
||||
return static_cast<float>(GetCurrentDPI()) / static_cast<float>(base_dpi);
|
||||
}
|
||||
|
||||
@@ -86,6 +86,9 @@ class FlutterWindowWin32 : public WindowWin32, public WindowBindingHandler {
|
||||
// |FlutterWindowBindingHandler|
|
||||
WindowsRenderTarget GetRenderTarget() override;
|
||||
|
||||
// |FlutterWindowBindingHandler|
|
||||
PlatformWindow GetPlatformWindow() override;
|
||||
|
||||
// |FlutterWindowBindingHandler|
|
||||
float GetDpiScale() override;
|
||||
|
||||
|
||||
@@ -10,10 +10,13 @@ namespace flutter {
|
||||
static constexpr double kControllerScrollMultiplier = 3;
|
||||
|
||||
FlutterWindowWinUWP::FlutterWindowWinUWP(
|
||||
ABI::Windows::UI::Core::CoreWindow* window) {
|
||||
winrt::Windows::UI::Core::CoreWindow cw{nullptr};
|
||||
winrt::copy_from_abi(cw, window);
|
||||
window_ = cw;
|
||||
ABI::Windows::ApplicationModel::Core::CoreApplicationView*
|
||||
applicationview) {
|
||||
winrt::Windows::ApplicationModel::Core::CoreApplicationView cav{nullptr};
|
||||
winrt::copy_from_abi(cav, applicationview);
|
||||
|
||||
application_view_ = cav;
|
||||
window_ = application_view_.CoreWindow();
|
||||
|
||||
SetEventHandlers();
|
||||
|
||||
@@ -46,6 +49,10 @@ WindowsRenderTarget FlutterWindowWinUWP::GetRenderTarget() {
|
||||
#endif
|
||||
}
|
||||
|
||||
PlatformWindow FlutterWindowWinUWP::GetPlatformWindow() {
|
||||
return application_view_;
|
||||
}
|
||||
|
||||
void FlutterWindowWinUWP::ApplyInverseDpiScalingTransform() {
|
||||
// Apply inverse transform to negate built in DPI scaling in order to render
|
||||
// at native scale.
|
||||
|
||||
@@ -5,12 +5,13 @@
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_UWP_FLUTTER_WINDOW_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_WINDOWS_UWP_FLUTTER_WINDOW_H_
|
||||
|
||||
#include <winrt/Windows.Devices.Input.h>
|
||||
#include <winrt/Windows.UI.Composition.h>
|
||||
#include <winrt/Windows.UI.Input.h>
|
||||
#include <winrt/Windows.UI.Text.Core.h>
|
||||
#include <winrt/Windows.UI.ViewManagement.Core.h>
|
||||
#include <winrt/Windows.UI.ViewManagement.h>
|
||||
#include <third_party/cppwinrt/generated/winrt/Windows.ApplicationModel.Core.h>
|
||||
#include <third_party/cppwinrt/generated/winrt/Windows.Devices.Input.h>
|
||||
#include <third_party/cppwinrt/generated/winrt/Windows.UI.Composition.h>
|
||||
#include <third_party/cppwinrt/generated/winrt/Windows.UI.Input.h>
|
||||
#include <third_party/cppwinrt/generated/winrt/Windows.UI.Text.Core.h>
|
||||
#include <third_party/cppwinrt/generated/winrt/Windows.UI.ViewManagement.Core.h>
|
||||
#include <third_party/cppwinrt/generated/winrt/Windows.UI.ViewManagement.h>
|
||||
|
||||
#include "flutter/shell/platform/embedder/embedder.h"
|
||||
#include "flutter/shell/platform/windows/display_helper_winuwp.h"
|
||||
@@ -25,7 +26,8 @@ namespace flutter {
|
||||
// Specifically handles window events within windows.
|
||||
class FlutterWindowWinUWP : public WindowBindingHandler {
|
||||
public:
|
||||
explicit FlutterWindowWinUWP(ABI::Windows::UI::Core::CoreWindow* window);
|
||||
explicit FlutterWindowWinUWP(
|
||||
ABI::Windows::ApplicationModel::Core::CoreApplicationView* window);
|
||||
|
||||
virtual ~FlutterWindowWinUWP();
|
||||
|
||||
@@ -35,6 +37,9 @@ class FlutterWindowWinUWP : public WindowBindingHandler {
|
||||
// |WindowBindingHandler|
|
||||
WindowsRenderTarget GetRenderTarget() override;
|
||||
|
||||
// |FlutterWindowBindingHandler|
|
||||
PlatformWindow GetPlatformWindow() override;
|
||||
|
||||
// |WindowBindingHandler|
|
||||
float GetDpiScale() override;
|
||||
|
||||
@@ -119,6 +124,10 @@ class FlutterWindowWinUWP : public WindowBindingHandler {
|
||||
// Backing CoreWindow. nullptr if not set.
|
||||
winrt::Windows::UI::Core::CoreWindow window_{nullptr};
|
||||
|
||||
// CoreApplicationView that owns window_. nullptr if not set.
|
||||
winrt::Windows::ApplicationModel::Core::CoreApplicationView application_view_{
|
||||
nullptr};
|
||||
|
||||
// Pointer to a FlutterWindowsView that can be
|
||||
// used to update engine windowing and input state.
|
||||
WindowBindingHandlerDelegate* binding_handler_delegate_;
|
||||
|
||||
@@ -128,9 +128,20 @@ FlutterDesktopTextureRegistrarRef FlutterDesktopEngineGetTextureRegistrar(
|
||||
EngineFromHandle(engine)->texture_registrar());
|
||||
}
|
||||
|
||||
HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view) {
|
||||
return std::get<HWND>(*ViewFromHandle(view)->GetRenderTarget());
|
||||
#ifdef WINUWP
|
||||
ABI::Windows::ApplicationModel::Core::CoreApplicationView*
|
||||
FlutterDesktopViewGetCoreApplicationView(FlutterDesktopViewRef view) {
|
||||
return static_cast<
|
||||
ABI::Windows::ApplicationModel::Core::CoreApplicationView*>(
|
||||
winrt::get_abi(ViewFromHandle(view)->GetPlatformWindow()));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef WINUWP
|
||||
HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view) {
|
||||
return ViewFromHandle(view)->GetPlatformWindow();
|
||||
}
|
||||
#endif
|
||||
|
||||
FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView(
|
||||
FlutterDesktopPluginRegistrarRef registrar) {
|
||||
|
||||
@@ -487,6 +487,10 @@ WindowsRenderTarget* FlutterWindowsView::GetRenderTarget() const {
|
||||
return render_target_.get();
|
||||
}
|
||||
|
||||
PlatformWindow FlutterWindowsView::GetPlatformWindow() const {
|
||||
return binding_handler_->GetPlatformWindow();
|
||||
}
|
||||
|
||||
FlutterWindowsEngine* FlutterWindowsView::GetEngine() {
|
||||
return engine_.get();
|
||||
}
|
||||
|
||||
@@ -59,6 +59,9 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate,
|
||||
// Return the currently configured WindowsRenderTarget.
|
||||
WindowsRenderTarget* GetRenderTarget() const;
|
||||
|
||||
// Return the currently configured PlatformWindow.
|
||||
PlatformWindow GetPlatformWindow() const;
|
||||
|
||||
// Returns the engine backing this view.
|
||||
FlutterWindowsEngine* GetEngine();
|
||||
|
||||
|
||||
@@ -41,12 +41,12 @@ std::vector<std::string> SplitCommaSeparatedString(const std::string& s) {
|
||||
}
|
||||
|
||||
FlutterDesktopViewControllerRef
|
||||
FlutterDesktopViewControllerCreateFromCoreWindow(
|
||||
ABI::Windows::UI::Core::CoreWindow* window,
|
||||
FlutterDesktopViewControllerCreateFromCoreApplicationView(
|
||||
ABI::Windows::ApplicationModel::Core::CoreApplicationView* application_view,
|
||||
ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs* args,
|
||||
FlutterDesktopEngineRef engine) {
|
||||
std::unique_ptr<flutter::WindowBindingHandler> window_wrapper =
|
||||
std::make_unique<flutter::FlutterWindowWinUWP>(window);
|
||||
std::make_unique<flutter::FlutterWindowWinUWP>(application_view);
|
||||
|
||||
auto state = std::make_unique<FlutterDesktopViewControllerState>();
|
||||
state->view =
|
||||
|
||||
@@ -77,11 +77,11 @@ typedef struct {
|
||||
// FlutterDesktopViewControllerDestroy. Returns a null pointer in the event of
|
||||
// an error.
|
||||
#ifdef WINUWP
|
||||
// The CoreWindow implementation accepts a pointer to the host CoreWindow
|
||||
// and view hookup is performed in the construction path.
|
||||
// The CoreApplicationView implementation accepts a pointer to the host
|
||||
// CoreApplicationView and view hookup is performed in the construction path.
|
||||
FLUTTER_EXPORT FlutterDesktopViewControllerRef
|
||||
FlutterDesktopViewControllerCreateFromCoreWindow(
|
||||
ABI::Windows::UI::Core::CoreWindow* window,
|
||||
FlutterDesktopViewControllerCreateFromCoreApplicationView(
|
||||
ABI::Windows::ApplicationModel::Core::CoreApplicationView* window,
|
||||
ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs* args,
|
||||
FlutterDesktopEngineRef engine);
|
||||
#else //! WINUWP
|
||||
@@ -192,7 +192,12 @@ FlutterDesktopEngineGetTextureRegistrar(
|
||||
|
||||
// ========== View ==========
|
||||
|
||||
#ifndef WINUWP
|
||||
#ifdef WINUWP
|
||||
// Return backing CoreApplicationView for manipulation of CoreWindow and
|
||||
// CoreTitleBar in host application.
|
||||
FLUTTER_EXPORT ABI::Windows::ApplicationModel::Core::CoreApplicationView*
|
||||
FlutterDesktopViewGetCoreApplicationView(FlutterDesktopViewRef view);
|
||||
#else
|
||||
// Return backing HWND for manipulation in host application.
|
||||
FLUTTER_EXPORT HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view);
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,7 @@ class MockWindowBindingHandler : public WindowBindingHandler {
|
||||
|
||||
MOCK_METHOD1(SetView, void(WindowBindingHandlerDelegate* view));
|
||||
MOCK_METHOD0(GetRenderTarget, WindowsRenderTarget());
|
||||
MOCK_METHOD0(GetPlatformWindow, PlatformWindow());
|
||||
MOCK_METHOD0(GetDpiScale, float());
|
||||
MOCK_METHOD0(OnWindowResized, void());
|
||||
MOCK_METHOD0(GetPhysicalWindowBounds, PhysicalWindowBounds());
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "flutter/shell/platform/windows/window_binding_handler_delegate.h"
|
||||
|
||||
#ifdef WINUWP
|
||||
#include <third_party/cppwinrt/generated/winrt/Windows.ApplicationModel.Activation.h>
|
||||
#include <third_party/cppwinrt/generated/winrt/Windows.UI.Composition.h>
|
||||
#endif
|
||||
|
||||
@@ -28,6 +29,16 @@ struct PhysicalWindowBounds {
|
||||
size_t height;
|
||||
};
|
||||
|
||||
// Type representing an underlying platform window.
|
||||
#ifdef WINUWP
|
||||
using PlatformWindow =
|
||||
winrt::Windows::ApplicationModel::Core::CoreApplicationView;
|
||||
#else
|
||||
using PlatformWindow = HWND;
|
||||
#endif
|
||||
|
||||
// Type representing a platform object that can be accepted by the Angle
|
||||
// rendering layer to bind to and render pixels into.
|
||||
#ifdef WINUWP
|
||||
using WindowsRenderTarget =
|
||||
std::variant<winrt::Windows::UI::Composition::SpriteVisual,
|
||||
@@ -46,10 +57,14 @@ class WindowBindingHandler {
|
||||
// such as key presses, mouse position updates etc.
|
||||
virtual void SetView(WindowBindingHandlerDelegate* view) = 0;
|
||||
|
||||
// Returns a valid WindowsRenderTarget representing the backing
|
||||
// window.
|
||||
// Returns a valid WindowsRenderTarget representing the platform object that
|
||||
// rendering can be bound to by ANGLE rendering backend.
|
||||
virtual WindowsRenderTarget GetRenderTarget() = 0;
|
||||
|
||||
// Returns a valid PlatformWindow representing the backing
|
||||
// window.
|
||||
virtual PlatformWindow GetPlatformWindow() = 0;
|
||||
|
||||
// Returns the scale factor for the backing window.
|
||||
virtual float GetDpiScale() = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user