Skip to content

Commit

Permalink
fix(skia): Hide Visuals for zero arrange, reduce refresh load
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Oct 5, 2020
1 parent c36b60f commit f8818db
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/Uno.UI/UI/Xaml/UIElement.Layout.netstd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,16 @@ public void Arrange(Rect finalRect)
return;
}

if (Visibility == Visibility.Collapsed)
if (Visibility == Visibility.Collapsed || finalRect == default)
{
LayoutSlot = finalRect;
Visual.IsVisible = false;
return;
}

if (!_isArrangeValid || finalRect != LayoutSlot)
{
Visual.IsVisible = true;
ArrangeCore(finalRect);
LayoutSlot = finalRect;
_isArrangeValid = true;
Expand Down
15 changes: 10 additions & 5 deletions src/Uno.UWP/UI/Composition/Compositor.Skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public partial class Compositor
{
private readonly Stack<float> _opacityStack = new Stack<float>();
private float _currentOpacity = 1.0f;
private bool _isDirty = false;

private OpacityDisposable PushOpacity(float opacity)
{
Expand Down Expand Up @@ -44,7 +45,8 @@ public void Dispose()

internal void Render(SKSurface surface, SKImageInfo info)
{
var sw = Stopwatch.StartNew();
_isDirty = false;
// var sw = Stopwatch.StartNew();

if (RootVisual != null)
{
Expand All @@ -54,14 +56,13 @@ internal void Render(SKSurface surface, SKImageInfo info)
}
}

sw.Stop();

// sw.Stop();
// global::System.Console.WriteLine($"Render time {sw.Elapsed}");
}

private void RenderVisual(SKSurface surface, SKImageInfo info, Visual visual)
{
if (visual.Opacity != 0)
if (visual.Opacity != 0 && visual.IsVisible)
{
surface.Canvas.Save();

Expand Down Expand Up @@ -148,7 +149,11 @@ private static void ApplyClip(SKSurface surface, Visual visual)

partial void InvalidateRenderPartial()
{
CoreWindow.QueueInvalidateRender();
if (!_isDirty)
{
_isDirty = true;
CoreWindow.QueueInvalidateRender();
}
}
}
}
2 changes: 1 addition & 1 deletion src/Uno.UWP/UI/Composition/Visual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class Visual : global::Windows.UI.Composition.CompositionObject
private float _rotationAngleInDegrees;
private Vector3 _rotationAxis = new Vector3(0, 0, 1);
private Matrix4x4 transformMatrix = Matrix4x4.Identity;
private bool isVisible;
private bool isVisible = true;
private float opacity = 1.0f;

internal Visual(Compositor compositor) : base(compositor)
Expand Down

0 comments on commit f8818db

Please sign in to comment.