From 841a0e359de2ed95bebd654a884b2febb65e4415 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Thu, 28 Mar 2024 14:18:22 +0100 Subject: [PATCH] feat: Adjust WASM to use XamlRoot.RasterizationScale --- .../Factory/NativeWindowFactory.singlewindow.cs | 6 +++++- .../Window/Native/NativeWindowWrapper.wasm.cs | 17 +++++++++++++++++ .../Window/Native/NativeWindowWrapperBase.cs | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Uno.UI/UI/Xaml/Window/Native/Factory/NativeWindowFactory.singlewindow.cs b/src/Uno.UI/UI/Xaml/Window/Native/Factory/NativeWindowFactory.singlewindow.cs index 3716bce041fc..f39066d4aae8 100644 --- a/src/Uno.UI/UI/Xaml/Window/Native/Factory/NativeWindowFactory.singlewindow.cs +++ b/src/Uno.UI/UI/Xaml/Window/Native/Factory/NativeWindowFactory.singlewindow.cs @@ -11,6 +11,10 @@ partial class NativeWindowFactory { public static bool SupportsMultipleWindows => false; - private static INativeWindowWrapper? CreateWindowPlatform(Microsoft.UI.Xaml.Window window, XamlRoot xamlRoot) => NativeWindowWrapper.Instance; + private static INativeWindowWrapper? CreateWindowPlatform(Microsoft.UI.Xaml.Window window, XamlRoot xamlRoot) + { + NativeWindowWrapper.Instance.SetXamlRoot(xamlRoot); + return NativeWindowWrapper.Instance; + } } #endif diff --git a/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.wasm.cs b/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.wasm.cs index 23dedf3464e3..1c98f02ffe78 100644 --- a/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.wasm.cs +++ b/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.wasm.cs @@ -1,6 +1,9 @@ using System; +using System.Runtime.InteropServices.JavaScript; using Uno.Disposables; +using Uno.Foundation.Logging; using Windows.Foundation; +using Windows.Graphics.Display; using Windows.UI.Core; using static __Uno.UI.Xaml.Controls.NativeWindowWrapper; @@ -10,8 +13,16 @@ internal partial class NativeWindowWrapper : NativeWindowWrapperBase { private static readonly Lazy _instance = new(() => new NativeWindowWrapper()); + private readonly DisplayInformation _displayInformation; + internal static NativeWindowWrapper Instance => _instance.Value; + public NativeWindowWrapper() + { + _displayInformation = DisplayInformation.GetForCurrentViewSafe() ?? throw new InvalidOperationException("DisplayInformation must be available when the window is initialized"); + _displayInformation.DpiChanged += (s, e) => DispatchDpiChanged(); + } + public override object NativeWindow => null; public override void Activate() @@ -22,6 +33,12 @@ public override void Close() { } + private void DispatchDpiChanged() + { + this.Log().LogError("Setting RasterizationScale to {0}", _displayInformation.RawPixelsPerViewPixel); + RasterizationScale = (float)_displayInformation.RawPixelsPerViewPixel; + } + internal void OnNativeClosed() => RaiseClosed(); internal void OnNativeActivated(CoreWindowActivationState state) => ActivationState = state; diff --git a/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapperBase.cs b/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapperBase.cs index 1ea8eb7b01d6..d05fbd914027 100644 --- a/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapperBase.cs +++ b/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapperBase.cs @@ -35,7 +35,7 @@ protected NativeWindowWrapperBase() protected XamlRoot? XamlRoot => _xamlRoot; - protected void SetXamlRoot(XamlRoot xamlRoot) + internal void SetXamlRoot(XamlRoot xamlRoot) { _xamlRoot = xamlRoot; xamlRoot.VisualTree.ContentRoot.SetContentIsland(_contentIsland);