From 75f0bbc101f65ffd96768e701a2a58cff5b9257c Mon Sep 17 00:00:00 2001 From: Elie Bariche <33458222+ebariche@users.noreply.github.com> Date: Tue, 4 Apr 2023 09:22:19 -0400 Subject: [PATCH] perf: Add CreateInstance binding --- .../RenderingLoopAnimator.Interop.wasm.cs | 16 ++++++++++++++++ .../Animators/RenderingLoopAnimator.wasm.cs | 9 +++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.Interop.wasm.cs diff --git a/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.Interop.wasm.cs b/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.Interop.wasm.cs new file mode 100644 index 000000000000..f87d369a2e36 --- /dev/null +++ b/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.Interop.wasm.cs @@ -0,0 +1,16 @@ +#if NET7_0_OR_GREATER +using System; +using System.Runtime.InteropServices.JavaScript; + +namespace __Windows.UI.Xaml.Media.Animation +{ + internal partial class RenderingLoopAnimator + { + internal static partial class NativeMethods + { + [JSImport("globalThis.Windows.UI.Xaml.Media.Animation.RenderingLoopAnimator.createInstance")] + internal static partial void CreateInstance(IntPtr managedHandle, double id); + } + } +} +#endif diff --git a/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.wasm.cs b/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.wasm.cs index 3c8256b64892..0d64235966c6 100644 --- a/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.wasm.cs +++ b/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.wasm.cs @@ -5,6 +5,10 @@ using Uno.Foundation.Interop; using Uno.Foundation.Logging; +#if NET7_0_OR_GREATER +using NativeMethods = __Windows.UI.Xaml.Media.Animation.RenderingLoopAnimator.NativeMethods; +#endif + namespace Windows.UI.Xaml.Media.Animation { internal abstract class RenderingLoopAnimator : CPUBoundAnimator, IJSObject where T : struct @@ -94,7 +98,12 @@ private Metadata() { } public long CreateNativeInstance(IntPtr managedHandle) { var id = RenderingLoopAnimatorMetadataIdProvider.Next(); + +#if NET7_0_OR_GREATER + NativeMethods.CreateInstance(managedHandle, id); +#else WebAssemblyRuntime.InvokeJS($"Windows.UI.Xaml.Media.Animation.RenderingLoopAnimator.createInstance(\"{managedHandle}\", \"{id}\")"); +#endif return id; }