Skip to content

Commit

Permalink
perf: [Skia] Remove weak registrations in UIElement constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed May 19, 2021
1 parent 61c4223 commit e84146f
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/Uno.UI/UI/Xaml/UIElement.Skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Uno.UI;
using Uno.UI.Extensions;
using Windows.UI.Xaml.Controls.Primitives;
using Uno.UI.DataBinding;

namespace Windows.UI.Xaml
{
Expand All @@ -22,7 +23,6 @@ public partial class UIElement : DependencyObject
internal Size _unclippedDesiredSize;
internal Point _visualOffset;
private ContainerVisual _visual;
private Visibility _visibilityCache;
internal double _canvasTop;
internal double _canvasLeft;
private Rect _currentFinalRect;
Expand All @@ -37,30 +37,24 @@ public UIElement()
InitializePointers();
InitializeKeyboard();

RegisterPropertyChangedCallback(VisibilityProperty, OnVisibilityPropertyChanged);
RegisterPropertyChangedCallback(Controls.Canvas.LeftProperty, OnCanvasLeftChanged);
RegisterPropertyChangedCallback(Controls.Canvas.TopProperty, OnCanvasTopChanged);
this.RegisterPropertyChangedCallbackStrong(OnPropertyChanged);

UpdateHitTest();
}
partial void InitializeKeyboard();

private void OnCanvasTopChanged(DependencyObject sender, DependencyProperty dp)
private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty property, DependencyPropertyChangedEventArgs args)
{
_canvasTop = (double)this.GetValue(Controls.Canvas.TopProperty);
}

private void OnCanvasLeftChanged(DependencyObject sender, DependencyProperty dp)
{
_canvasLeft = (double)this.GetValue(Controls.Canvas.LeftProperty);
if(property == Controls.Canvas.TopProperty)
{
_canvasTop = (double)args.NewValue;
}
else if (property == Controls.Canvas.LeftProperty)
{
_canvasLeft = (double)args.NewValue;
}
}

private void OnVisibilityPropertyChanged(DependencyObject sender, DependencyProperty dp)
{
UpdateHitTest();

_visibilityCache = (Visibility)GetValue(VisibilityProperty);
}

partial void OnOpacityChanged(DependencyPropertyChangedEventArgs args)
{
Expand Down Expand Up @@ -193,6 +187,7 @@ private void InnerRemoveChild(UIElement child)

protected virtual void OnVisibilityChanged(Visibility oldValue, Visibility newVisibility)
{
UpdateHitTest();
UpdateOpacity();

if (newVisibility == Visibility.Collapsed)
Expand Down

0 comments on commit e84146f

Please sign in to comment.