Skip to content

Commit 58bd823

Browse files
committed
perf(WindowManager): Add MeasureViewNativeFast binding
1 parent 553f390 commit 58bd823

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/Uno.UI/UI/Xaml/WindowManagerInterop.wasm.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
using Windows.UI;
1414
using Windows.UI.Xaml;
1515

16+
#if NET7_0_OR_GREATER
17+
using System.Runtime.InteropServices.JavaScript;
18+
#endif
19+
1620
namespace Uno.UI.Xaml
1721
{
1822
/// <summary>
@@ -268,6 +272,15 @@ internal static Size MeasureView(IntPtr htmlId, Size availableSize, bool measure
268272
}
269273
else
270274
{
275+
#if NET7_0_OR_GREATER
276+
using var pReturn = TSInteropMarshaller.AllocateBlittableStructure(typeof(WindowManagerMeasureViewReturn));
277+
278+
NativeMethods.MeasureView(htmlId, availableSize.Width, availableSize.Height, measureContent, pReturn);
279+
280+
var result = TSInteropMarshaller.UnmarshalStructure<WindowManagerMeasureViewReturn>(pReturn);
281+
282+
return new Size(result.DesiredWidth, result.DesiredHeight);
283+
#else
271284
var parms = new WindowManagerMeasureViewParams
272285
{
273286
HtmlId = htmlId,
@@ -279,6 +292,7 @@ internal static Size MeasureView(IntPtr htmlId, Size availableSize, bool measure
279292
var ret = (WindowManagerMeasureViewReturn)TSInteropMarshaller.InvokeJS("Uno:measureViewNative", parms, typeof(WindowManagerMeasureViewReturn));
280293

281294
return new Size(ret.DesiredWidth, ret.DesiredHeight);
295+
#endif
282296
}
283297
}
284298

@@ -1462,5 +1476,13 @@ internal enum HtmlPointerButtonUpdate
14621476
Eraser = 5
14631477
}
14641478
#endregion
1479+
1480+
#if NET7_0_OR_GREATER
1481+
internal static partial class NativeMethods
1482+
{
1483+
[JSImport("globalThis.Uno.UI.WindowManager.current.measureViewNativeFast")]
1484+
internal static partial void MeasureView(IntPtr htmlId, double availableWidth, double availableHeight, bool measureContent, IntPtr pReturn);
1485+
}
1486+
#endif
14651487
}
14661488
}

src/Uno.UI/ts/WindowManager.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,17 @@ namespace Uno.UI {
13281328
return true;
13291329
}
13301330

1331+
public measureViewNativeFast(htmlId: number, availableWidth: number, availableHeight: number, measureContent: boolean, pReturn: number) {
1332+
1333+
const result = this.measureViewInternal(htmlId, availableWidth, availableHeight, measureContent);
1334+
1335+
const desiredSize = new WindowManagerMeasureViewReturn();
1336+
desiredSize.DesiredWidth = result[0];
1337+
desiredSize.DesiredHeight = result[1];
1338+
1339+
desiredSize.marshal(pReturn);
1340+
}
1341+
13311342
private static MAX_WIDTH = `${Number.MAX_SAFE_INTEGER}vw`;
13321343
private static MAX_HEIGHT = `${Number.MAX_SAFE_INTEGER}vh`;
13331344

0 commit comments

Comments
 (0)