Skip to content

Commit

Permalink
chore: Avoid creating XamlRoot too early
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Jan 24, 2025
1 parent 5baf543 commit 1bca109
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/Uno.UI/UI/Xaml/Internal/Scaling/RootScale.mux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ private void ApplyScale(bool scaleChanged)

if (scaleChanged)
{
// TODO Uno: This should not be done here
VisualTree.ContentRoot.CompositionTarget.OnRasterizationScaleChanged(GetEffectiveRasterizationScale());

// TODO Uno: Reload images on scale change!
//foreach (var displayListener in _displayListeners)
//{
Expand Down
16 changes: 5 additions & 11 deletions src/Uno.UI/UI/Xaml/Media/CompositionTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ namespace Microsoft.UI.Xaml.Media;
public partial class CompositionTarget : ICompositionTarget
{
private Visual _root;
private double _rasterizationScale;
private double? _rasterizationScale;
private EventHandler _rasterizationScaleChanged;

internal CompositionTarget(ContentRoot contentRoot)
{
ContentRoot = contentRoot;
var xamlRoot = contentRoot.GetOrCreateXamlRoot();
_rasterizationScale = xamlRoot.RasterizationScale;
xamlRoot.Changed += XamlRoot_Changed;
}

event EventHandler ICompositionTarget.RasterizationScaleChanged
Expand All @@ -39,7 +36,7 @@ internal Visual Root
}
}

double ICompositionTarget.RasterizationScale => _rasterizationScale;
double ICompositionTarget.RasterizationScale => _rasterizationScale ?? 1.0;

public static Compositor GetCompositorForCurrentThread() => Compositor.GetSharedCompositor();

Expand All @@ -50,12 +47,9 @@ void ICompositionTarget.TryRedirectForManipulation(PointerPoint pointerPoint, In
#endif
}

private void XamlRoot_Changed(XamlRoot sender, XamlRootChangedEventArgs args)
internal void OnRasterizationScaleChanged(double rasterizationScale)
{
if (ContentRoot.XamlRoot.RasterizationScale != _rasterizationScale)
{
_rasterizationScale = ContentRoot.XamlRoot.RasterizationScale;
_rasterizationScaleChanged?.Invoke(this, EventArgs.Empty);
}
_rasterizationScale = rasterizationScale;
_rasterizationScaleChanged?.Invoke(this, EventArgs.Empty);
}
}

0 comments on commit 1bca109

Please sign in to comment.