Skip to content

Commit

Permalink
feat: Adjust WASM to use XamlRoot.RasterizationScale
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Apr 22, 2024
1 parent 54e20dd commit 841a0e3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.wasm.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -10,8 +13,16 @@ internal partial class NativeWindowWrapper : NativeWindowWrapperBase
{
private static readonly Lazy<NativeWindowWrapper> _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()
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 841a0e3

Please sign in to comment.