diff --git a/src/Skia/Avalonia.Skia/Gpu/Metal/SkiaMetalApi.cs b/src/Skia/Avalonia.Skia/Gpu/Metal/SkiaMetalApi.cs index 9475d96fc02..bfd486c60a2 100644 --- a/src/Skia/Avalonia.Skia/Gpu/Metal/SkiaMetalApi.cs +++ b/src/Skia/Avalonia.Skia/Gpu/Metal/SkiaMetalApi.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.InteropServices; +using Avalonia.Compatibility; using Avalonia.Platform.Interop; using SkiaSharp; using BindingFlags = System.Reflection.BindingFlags; @@ -24,19 +25,23 @@ public SkiaMetalApi() { // Make sure that skia is loaded GC.KeepAlive(new SKPaint()); - - var loader = AvaloniaLocator.Current.GetRequiredService(); -#if NET6_0_OR_GREATER - var dll = NativeLibrary.Load("libSkiaSharp", typeof(SKPaint).Assembly, null); -#else - var dll = loader.LoadLibrary("libSkiaSharp"); -#endif - _gr_direct_context_make_metal_with_options = (delegate* unmanaged[Stdcall] ) - loader.GetProcAddress(dll, "gr_direct_context_make_metal_with_options", false); - _gr_backendrendertarget_new_metal = - (delegate* unmanaged[Stdcall]) - loader.GetProcAddress(dll, "gr_backendrendertarget_new_metal", false); - + + var dll = NativeLibraryEx.Load("libSkiaSharp"); + + IntPtr address; + + if (NativeLibraryEx.TryGetExport(dll, "gr_direct_context_make_metal_with_options", out address)) + { + _gr_direct_context_make_metal_with_options = + (delegate* unmanaged[Stdcall] )address; + } + + if(NativeLibraryEx.TryGetExport(dll, "gr_backendrendertarget_new_metal", out address)) + { + _gr_backendrendertarget_new_metal = + (delegate* unmanaged[Stdcall])address; + } + _contextCtor = typeof(GRContext).GetConstructor( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new[] { typeof(IntPtr), typeof(bool) }, null) ?? throw new MissingMemberException("GRContext.ctor(IntPtr,bool)");