Skip to content

Commit

Permalink
Revert "fix native api loading."
Browse files Browse the repository at this point in the history
This reverts commit b580d3f.
  • Loading branch information
Dan Walmsley committed Jun 30, 2023
1 parent b580d3f commit ae2aee4
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/Skia/Avalonia.Skia/Gpu/Metal/SkiaMetalApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
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;
Expand All @@ -25,23 +24,19 @@ public SkiaMetalApi()
{
// Make sure that skia is loaded
GC.KeepAlive(new SKPaint());

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] <IntPtr, IntPtr, IntPtr, IntPtr>)address;
}

if(NativeLibraryEx.TryGetExport(dll, "gr_backendrendertarget_new_metal", out address))
{
_gr_backendrendertarget_new_metal =
(delegate* unmanaged[Stdcall]<int, int, int, GRMtlTextureInfoNative*, IntPtr>)address;
}


var loader = AvaloniaLocator.Current.GetRequiredService<IDynamicLibraryLoader>();
#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] <IntPtr, IntPtr, IntPtr, IntPtr>)
loader.GetProcAddress(dll, "gr_direct_context_make_metal_with_options", false);
_gr_backendrendertarget_new_metal =
(delegate* unmanaged[Stdcall]<int, int, int, GRMtlTextureInfoNative*, IntPtr>)
loader.GetProcAddress(dll, "gr_backendrendertarget_new_metal", false);

_contextCtor = typeof(GRContext).GetConstructor(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null,
new[] { typeof(IntPtr), typeof(bool) }, null) ?? throw new MissingMemberException("GRContext.ctor(IntPtr,bool)");
Expand Down

0 comments on commit ae2aee4

Please sign in to comment.