Browse Source

Revert "fix native api loading."

This reverts commit b580d3f986.
pull/11930/head
Dan Walmsley 3 years ago
parent
commit
ae2aee402d
  1. 31
      src/Skia/Avalonia.Skia/Gpu/Metal/SkiaMetalApi.cs

31
src/Skia/Avalonia.Skia/Gpu/Metal/SkiaMetalApi.cs

@ -2,7 +2,6 @@ using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Avalonia.Compatibility;
using Avalonia.Platform.Interop; using Avalonia.Platform.Interop;
using SkiaSharp; using SkiaSharp;
using BindingFlags = System.Reflection.BindingFlags; using BindingFlags = System.Reflection.BindingFlags;
@ -25,23 +24,19 @@ internal unsafe class SkiaMetalApi
{ {
// Make sure that skia is loaded // Make sure that skia is loaded
GC.KeepAlive(new SKPaint()); GC.KeepAlive(new SKPaint());
var dll = NativeLibraryEx.Load("libSkiaSharp"); var loader = AvaloniaLocator.Current.GetRequiredService<IDynamicLibraryLoader>();
#if NET6_0_OR_GREATER
IntPtr address; var dll = NativeLibrary.Load("libSkiaSharp", typeof(SKPaint).Assembly, null);
#else
if (NativeLibraryEx.TryGetExport(dll, "gr_direct_context_make_metal_with_options", out address)) var dll = loader.LoadLibrary("libSkiaSharp");
{ #endif
_gr_direct_context_make_metal_with_options = _gr_direct_context_make_metal_with_options = (delegate* unmanaged[Stdcall] <IntPtr, IntPtr, IntPtr, IntPtr>)
(delegate* unmanaged[Stdcall] <IntPtr, IntPtr, IntPtr, IntPtr>)address; loader.GetProcAddress(dll, "gr_direct_context_make_metal_with_options", false);
} _gr_backendrendertarget_new_metal =
(delegate* unmanaged[Stdcall]<int, int, int, GRMtlTextureInfoNative*, IntPtr>)
if(NativeLibraryEx.TryGetExport(dll, "gr_backendrendertarget_new_metal", out address)) loader.GetProcAddress(dll, "gr_backendrendertarget_new_metal", false);
{
_gr_backendrendertarget_new_metal =
(delegate* unmanaged[Stdcall]<int, int, int, GRMtlTextureInfoNative*, IntPtr>)address;
}
_contextCtor = typeof(GRContext).GetConstructor( _contextCtor = typeof(GRContext).GetConstructor(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null,
new[] { typeof(IntPtr), typeof(bool) }, null) ?? throw new MissingMemberException("GRContext.ctor(IntPtr,bool)"); new[] { typeof(IntPtr), typeof(bool) }, null) ?? throw new MissingMemberException("GRContext.ctor(IntPtr,bool)");

Loading…
Cancel
Save