Skip to content

Commit 6d16f8a

Browse files
committed
perf: Specialized binding for UIElement.AdjustCornerRadius()
1 parent 0adc2ea commit 6d16f8a

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package Uno.UI;
2+
3+
import android.graphics.*;
4+
5+
public final class UIElementNative
6+
{
7+
private UIElementNative() {
8+
}
9+
10+
public static void adjustCornerRadius(Canvas canvas, float[] radii)
11+
{
12+
Path clipPath = new Path();
13+
14+
clipPath.addRoundRect(new RectF(canvas.getClipBounds()), radii, Path.Direction.CW);
15+
16+
canvas.clipPath(clipPath);
17+
}
18+
}

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using Android.Graphics;
33
using Uno.UI;
44
using Uno.UI.Controls;
@@ -9,10 +9,9 @@ partial struct CornerRadius
99
{
1010
internal Path GetOutlinePath(RectF rect)
1111
{
12-
var radii = GetRadii();
13-
1412
var path = new Path();
15-
path.AddRoundRect(rect, radii, Path.Direction.Cw);
13+
14+
path.AddRoundRect(rect, GetRadii(), Path.Direction.Cw);
1615

1716
return path;
1817
}
@@ -29,16 +28,21 @@ internal Path GetInnerOutlinePath(RectF rect, Thickness borderThickness)
2928

3029
internal float[] GetRadii()
3130
{
31+
var topLeft = ViewHelper.LogicalToPhysicalPixels(TopLeft);
32+
var topRight = ViewHelper.LogicalToPhysicalPixels(TopRight);
33+
var bottomRight = ViewHelper.LogicalToPhysicalPixels(BottomRight);
34+
var bottomLeft = ViewHelper.LogicalToPhysicalPixels(BottomLeft);
35+
3236
return new float[]
3337
{
34-
ViewHelper.LogicalToPhysicalPixels(TopLeft),
35-
ViewHelper.LogicalToPhysicalPixels(TopLeft),
36-
ViewHelper.LogicalToPhysicalPixels(TopRight),
37-
ViewHelper.LogicalToPhysicalPixels(TopRight),
38-
ViewHelper.LogicalToPhysicalPixels(BottomRight),
39-
ViewHelper.LogicalToPhysicalPixels(BottomRight),
40-
ViewHelper.LogicalToPhysicalPixels(BottomLeft),
41-
ViewHelper.LogicalToPhysicalPixels(BottomLeft)
38+
topLeft,
39+
topLeft,
40+
topRight,
41+
topRight,
42+
bottomRight,
43+
bottomRight,
44+
bottomLeft,
45+
bottomLeft
4246
};
4347
}
4448

src/Uno.UI/UI/Xaml/UIElement.Android.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Uno.UI;
1+
using Uno.UI;
22
using Uno.UI.Controls;
33
using Uno.UI.Extensions;
44
using Uno.UI.Xaml.Input;
@@ -180,9 +180,7 @@ private protected void AdjustCornerRadius(Android.Graphics.Canvas canvas, Corner
180180
{
181181
if (cornerRadius != CornerRadius.None)
182182
{
183-
var rect = new RectF(canvas.ClipBounds);
184-
var clipPath = cornerRadius.GetOutlinePath(rect);
185-
canvas.ClipPath(clipPath);
183+
UIElementNative.AdjustCornerRadius(canvas, cornerRadius.GetRadii());
186184
}
187185
}
188186

0 commit comments

Comments
 (0)