Skip to content

Commit

Permalink
perf(WindowManager): Add GetNaturalImageSizeAsync binding
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed May 19, 2023
1 parent ec977f6 commit 223c0e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
14 changes: 0 additions & 14 deletions src/Uno.UI/UI/Xaml/Media/ImageBrush.Interop.wasm.cs

This file was deleted.

8 changes: 2 additions & 6 deletions src/Uno.UI/UI/Xaml/Media/ImageBrush.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
using System.Globalization;
using System.Collections.Generic;
using Uno.Extensions;
using Uno.UI.Xaml;
using Uno.UI.Xaml.Media;
using Uno.Foundation.Logging;
using System.Collections.Concurrent;

#if NET7_0_OR_GREATER
using NativeMethods = __Windows.UI.Xaml.Media.ImageBrush.NativeMethods;
#endif

namespace Windows.UI.Xaml.Media
{
partial class ImageBrush
Expand Down Expand Up @@ -223,8 +220,7 @@ private async void SetNaturalImageSize(UIElement pattern, FrameworkElement targe

if (!_naturalSizeCache.TryGetValue(_imageUri, out var naturalSize))
{
var command = "Uno.UI.WindowManager.current.getNaturalImageSize(\"" + _imageUri + "\");";
var naturalSizeResponse = await Uno.Foundation.WebAssemblyRuntime.InvokeAsync(command);
var naturalSizeResponse = await WindowManagerInterop.GetNaturalImageSizeAsync(_imageUri);

if (!TryParseNaturalSize(naturalSizeResponse, out naturalSize))
{
Expand Down
12 changes: 12 additions & 0 deletions src/Uno.UI/UI/Xaml/WindowManagerInterop.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,14 @@ private struct WindowManagerResetElementBackgroundParams
}
#endregion

internal static Task<string> GetNaturalImageSizeAsync(string imageUri)
=>
#if NET7_0_OR_GREATER
NativeMethods.GetNaturalImageSizeAsync(imageUri);
#else
WebAssemblyRuntime.InvokeAsync($"Uno.UI.WindowManager.current.getNaturalImageSize(\"{imageUri}\")");
#endif

internal static string RawPixelsToBase64EncodeImage(IntPtr data, int width, int height)
=>
#if NET7_0_OR_GREATER
Expand All @@ -1217,6 +1225,7 @@ internal static void SetImageAsMonochrome(IntPtr htmlId, string url, string colo
#else
WebAssemblyRuntime.InvokeJS($"Uno.UI.WindowManager.current.setImageAsMonochrome({htmlId}, \"{url}\", \"{color}\");");
#endif

internal static void SetRootElement(IntPtr htmlId)
{
#if NET7_0_OR_GREATER
Expand Down Expand Up @@ -1293,6 +1302,9 @@ internal static partial void ArrangeElement(
[JSImport("globalThis.Uno.UI.WindowManager.getBootTime")]
internal static partial double GetBootTime();

[JSImport("globalThis.Uno.UI.WindowManager.current.getNaturalImageSize")]
internal static partial Task<string> GetNaturalImageSizeAsync(string imageUri);

[JSImport("globalThis.Uno.UI.WindowManager.current.focusView")]
internal static partial void FocusView(IntPtr htmlId);

Expand Down

0 comments on commit 223c0e6

Please sign in to comment.