Skip to content

Commit c74ff5a

Browse files
committed
perf: Reuse radii arrays
1 parent a5ce5f3 commit c74ff5a

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/Uno.UI/UI/Xaml/Controls/Border/BorderLayerRenderer.skia.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ namespace Windows.UI.Xaml.Shapes
1818
{
1919
partial class BorderLayerRenderer
2020
{
21+
private static SKPoint[] _outerRadiiStore = new SKPoint[4];
22+
private static SKPoint[] _innerRadiiStore = new SKPoint[4];
23+
2124
private LayoutState _currentState;
2225

2326
private SerialDisposable _layerDisposable = new SerialDisposable();
@@ -120,16 +123,17 @@ private static IDisposable InnerCreateLayer(UIElement owner, LayoutState state)
120123
.DisposeWith(disposables);
121124
}
122125

123-
var outerRadii = cornerRadius.GetRadii(new Size(area.Width, area.Height), borderThickness, true);
124-
var innerRadii = cornerRadius.GetRadii(new Size(area.Width, area.Height), borderThickness, false);
126+
// This needs to be adjusted if multiple UI threads are used in the future for multi-window
127+
cornerRadius.GetRadii(ref _outerRadiiStore, new Size(area.Width, area.Height), borderThickness, true);
128+
cornerRadius.GetRadii(ref _innerRadiiStore, new Size(area.Width, area.Height), borderThickness, false);
125129

126-
var borderPath = GetRoundedRect(outerRadii, innerRadii, borderThickness, area, adjustedArea);
130+
var borderPath = GetRoundedRect(_outerRadiiStore, _innerRadiiStore, borderThickness, area, adjustedArea);
127131

128132
var backgroundPath = state.BackgroundSizing == BackgroundSizing.InnerBorderEdge ?
129-
GetRoundedPath(adjustedArea.ToSKRect(), innerRadii) :
130-
GetRoundedPath(adjustedArea.ToSKRect(), outerRadii);
133+
GetRoundedPath(adjustedArea.ToSKRect(), _innerRadiiStore) :
134+
GetRoundedPath(adjustedArea.ToSKRect(), _outerRadiiStore);
131135

132-
var outerPath = GetRoundedPath(area.ToSKRect(), outerRadii);
136+
var outerPath = GetRoundedPath(area.ToSKRect(), _outerRadiiStore);
133137

134138
backgroundShape.Geometry = compositor.CreatePathGeometry(backgroundPath);
135139
borderShape.Geometry = compositor.CreatePathGeometry(borderPath);
@@ -319,8 +323,6 @@ private static CompositionPath GetRoundedPath(SKRect area, SKPoint[] radii, Skia
319323
geometrySource ??= new SkiaGeometrySource2D();
320324
var geometry = geometrySource.Geometry;
321325

322-
// How ArcTo works:
323-
// http://www.twistedape.me.uk/blog/2013/09/23/what-arctopointdoes/
324326
var roundRect = new SKRoundRect();
325327
roundRect.SetRectRadii(area, radii);
326328
geometry.AddRoundRect(roundRect);

src/Uno.UI/UI/Xaml/CornerRadius.skia.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ partial struct CornerRadius
1313
/// <param name="borderThickness">Border thickness.</param>
1414
/// <param name="outer">True to return outer corner radii, false for inner.</param>
1515
/// <returns>Radii.</returns>
16-
internal SKPoint[] GetRadii(Size elementSize, Thickness borderThickness, bool outer)
16+
internal void GetRadii(ref SKPoint[] radii, Size elementSize, Thickness borderThickness, bool outer)
1717
{
1818
var halfLeft = borderThickness.Left * 0.5;
1919
var halfTop = borderThickness.Top * 0.5;
@@ -94,12 +94,9 @@ internal SKPoint[] GetRadii(Size elementSize, Thickness borderThickness, bool ou
9494
topLeft = elementSize.Height - bottomLeft;
9595
}
9696

97-
return new SKPoint[]
98-
{
99-
new((float)leftTop, (float)topLeft),
100-
new((float)rightTop, (float)topRight),
101-
new((float)rightBottom, (float)bottomRight),
102-
new((float)leftBottom, (float)bottomLeft),
103-
};
97+
radii[0] = new((float)leftTop, (float)topLeft);
98+
radii[1] = new((float)rightTop, (float)topRight);
99+
radii[2] = new((float)rightBottom, (float)bottomRight);
100+
radii[3] = new((float)leftBottom, (float)bottomLeft);
104101
}
105102
}

0 commit comments

Comments
 (0)