Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question (here and below) -- if these headers are included by end-user applications, how do we know they've got WINUWP defined (or not)? Are we setting it as defined in our build template?

Should we be creating a UWP subclass here? I think the answer is that long-term, yes. We can deal with this in the short term by using a version check against the template like we did back when the the win32/macos templates were changing more frequently. I'll dig up the code for that -- that change will be in the template, not here, so nothing to do on this commit.

// Returns the backing HWND for the view.
HWND GetNativeWindow() { return FlutterDesktopViewGetHWND(view_); }
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/windows/flutter_window_win32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/windows/flutter_window_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class FlutterWindowWin32 : public WindowWin32, public WindowBindingHandler {
// |FlutterWindowBindingHandler|
WindowsRenderTarget GetRenderTarget() override;

// |FlutterWindowBindingHandler|
PlatformWindow GetPlatformWindow() override;

// |FlutterWindowBindingHandler|
float GetDpiScale() override;

Expand Down
15 changes: 11 additions & 4 deletions shell/platform/windows/flutter_window_winuwp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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.
Expand Down
23 changes: 16 additions & 7 deletions shell/platform/windows/flutter_window_winuwp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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();

Expand All @@ -35,6 +37,9 @@ class FlutterWindowWinUWP : public WindowBindingHandler {
// |WindowBindingHandler|
WindowsRenderTarget GetRenderTarget() override;

// |FlutterWindowBindingHandler|
PlatformWindow GetPlatformWindow() override;

// |WindowBindingHandler|
float GetDpiScale() override;

Expand Down Expand Up @@ -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_;
Expand Down
13 changes: 12 additions & 1 deletion shell/platform/windows/flutter_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,20 @@ FlutterDesktopTextureRegistrarRef FlutterDesktopEngineGetTextureRegistrar(
EngineFromHandle(engine)->texture_registrar());
}

#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 std::get<HWND>(*ViewFromHandle(view)->GetRenderTarget());
return ViewFromHandle(view)->GetPlatformWindow();
}
#endif

FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView(
FlutterDesktopPluginRegistrarRef registrar) {
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/windows/flutter_windows_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/windows/flutter_windows_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions shell/platform/windows/flutter_windows_winuwp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
15 changes: 10 additions & 5 deletions shell/platform/windows/public/flutter_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
19 changes: 17 additions & 2 deletions shell/platform/windows/window_binding_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand All @@ -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;

Expand Down