Introduce some metal consistency (#1615)
* Use the shortened Mtl in the construcion type names because that is what we have done in the past :'( * Use the longer Metal in the views layer :') * Use GRMtlBackendContext as that is coming soon, so might as well get ahead
This commit is contained in:
Родитель
bb8ae1071f
Коммит
0e4f6fedd4
|
@ -45,7 +45,7 @@ namespace SkiaSharp
|
|||
|
||||
#if __IOS__ || __MACOS__
|
||||
|
||||
public GRBackendRenderTarget (int width, int height, int sampleCount, GRMetalTextureInfo mtlInfo)
|
||||
public GRBackendRenderTarget (int width, int height, int sampleCount, GRMtlTextureInfo mtlInfo)
|
||||
: this (IntPtr.Zero, true)
|
||||
{
|
||||
var info = mtlInfo.ToNative ();
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace SkiaSharp
|
|||
|
||||
#if __IOS__ || __MACOS__
|
||||
|
||||
public GRBackendTexture (int width, int height, bool mipmapped, GRMetalTextureInfo mtlInfo)
|
||||
public GRBackendTexture (int width, int height, bool mipmapped, GRMtlTextureInfo mtlInfo)
|
||||
: this (IntPtr.Zero, true)
|
||||
{
|
||||
var info = mtlInfo.ToNative ();
|
||||
|
|
|
@ -96,15 +96,16 @@ namespace SkiaSharp
|
|||
|
||||
// CreateMetal
|
||||
|
||||
public static GRContext CreateMetal (Metal.IMTLDevice device, Metal.IMTLCommandQueue queue) =>
|
||||
CreateMetal (device, queue, null);
|
||||
public static GRContext CreateMetal (GRMtlBackendContext backendContext) =>
|
||||
CreateMetal (backendContext, null);
|
||||
|
||||
public static GRContext CreateMetal (Metal.IMTLDevice device, Metal.IMTLCommandQueue queue, GRContextOptions options)
|
||||
public static GRContext CreateMetal (GRMtlBackendContext backendContext, GRContextOptions options)
|
||||
{
|
||||
if (device == null)
|
||||
throw new ArgumentNullException (nameof (device));
|
||||
if (queue == null)
|
||||
throw new ArgumentNullException (nameof (queue));
|
||||
if (backendContext == null)
|
||||
throw new ArgumentNullException (nameof (backendContext));
|
||||
|
||||
var device = backendContext.Device;
|
||||
var queue = backendContext.Queue;
|
||||
|
||||
if (options == null) {
|
||||
return GetObject (SkiaApi.gr_context_make_metal ((void*)device.Handle, (void*)queue.Handle));
|
||||
|
|
|
@ -112,30 +112,30 @@ namespace SkiaSharp
|
|||
|
||||
#if __IOS__ || __MACOS__
|
||||
|
||||
public unsafe partial struct GRMetalTextureInfo
|
||||
public unsafe partial struct GRMtlTextureInfo
|
||||
{
|
||||
public GRMetalTextureInfo (Metal.IMTLTexture texture)
|
||||
public GRMtlTextureInfo (Metal.IMTLTexture texture)
|
||||
{
|
||||
Texture = texture;
|
||||
}
|
||||
|
||||
public Metal.IMTLTexture Texture { get; set; }
|
||||
|
||||
internal GRMetalTextureInfoNative ToNative () =>
|
||||
new GRMetalTextureInfoNative {
|
||||
internal GRMtlTextureInfoNative ToNative () =>
|
||||
new GRMtlTextureInfoNative {
|
||||
fTexture = (void*)Texture.Handle
|
||||
};
|
||||
|
||||
public readonly bool Equals (GRMetalTextureInfo obj) =>
|
||||
public readonly bool Equals (GRMtlTextureInfo obj) =>
|
||||
Texture == obj.Texture;
|
||||
|
||||
public readonly override bool Equals (object obj) =>
|
||||
obj is GRMetalTextureInfo f && Equals (f);
|
||||
obj is GRMtlTextureInfo f && Equals (f);
|
||||
|
||||
public static bool operator == (GRMetalTextureInfo left, GRMetalTextureInfo right) =>
|
||||
public static bool operator == (GRMtlTextureInfo left, GRMtlTextureInfo right) =>
|
||||
left.Equals (right);
|
||||
|
||||
public static bool operator != (GRMetalTextureInfo left, GRMetalTextureInfo right) =>
|
||||
public static bool operator != (GRMtlTextureInfo left, GRMtlTextureInfo right) =>
|
||||
!left.Equals (right);
|
||||
|
||||
public readonly override int GetHashCode ()
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
#if __IOS__ || __MACOS__
|
||||
using System;
|
||||
using Metal;
|
||||
|
||||
namespace SkiaSharp
|
||||
{
|
||||
public class GRMtlBackendContext : IDisposable
|
||||
{
|
||||
public IMTLDevice Device { get; set; }
|
||||
|
||||
public IMTLCommandQueue Queue { get; set; }
|
||||
|
||||
protected virtual void Dispose (bool disposing)
|
||||
{
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
Dispose (disposing: true);
|
||||
GC.SuppressFinalize (this);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -224,14 +224,14 @@ namespace SkiaSharp
|
|||
// gr_backendrendertarget_t* gr_backendrendertarget_new_metal(int width, int height, int samples, const gr_mtl_textureinfo_t* mtlInfo)
|
||||
#if !USE_DELEGATES
|
||||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern gr_backendrendertarget_t gr_backendrendertarget_new_metal (Int32 width, Int32 height, Int32 samples, GRMetalTextureInfoNative* mtlInfo);
|
||||
internal static extern gr_backendrendertarget_t gr_backendrendertarget_new_metal (Int32 width, Int32 height, Int32 samples, GRMtlTextureInfoNative* mtlInfo);
|
||||
#else
|
||||
private partial class Delegates {
|
||||
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
|
||||
internal delegate gr_backendrendertarget_t gr_backendrendertarget_new_metal (Int32 width, Int32 height, Int32 samples, GRMetalTextureInfoNative* mtlInfo);
|
||||
internal delegate gr_backendrendertarget_t gr_backendrendertarget_new_metal (Int32 width, Int32 height, Int32 samples, GRMtlTextureInfoNative* mtlInfo);
|
||||
}
|
||||
private static Delegates.gr_backendrendertarget_new_metal gr_backendrendertarget_new_metal_delegate;
|
||||
internal static gr_backendrendertarget_t gr_backendrendertarget_new_metal (Int32 width, Int32 height, Int32 samples, GRMetalTextureInfoNative* mtlInfo) =>
|
||||
internal static gr_backendrendertarget_t gr_backendrendertarget_new_metal (Int32 width, Int32 height, Int32 samples, GRMtlTextureInfoNative* mtlInfo) =>
|
||||
(gr_backendrendertarget_new_metal_delegate ??= GetSymbol<Delegates.gr_backendrendertarget_new_metal> ("gr_backendrendertarget_new_metal")).Invoke (width, height, samples, mtlInfo);
|
||||
#endif
|
||||
|
||||
|
@ -370,14 +370,14 @@ namespace SkiaSharp
|
|||
// gr_backendtexture_t* gr_backendtexture_new_metal(int width, int height, bool mipmapped, const gr_mtl_textureinfo_t* mtlInfo)
|
||||
#if !USE_DELEGATES
|
||||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern gr_backendtexture_t gr_backendtexture_new_metal (Int32 width, Int32 height, [MarshalAs (UnmanagedType.I1)] bool mipmapped, GRMetalTextureInfoNative* mtlInfo);
|
||||
internal static extern gr_backendtexture_t gr_backendtexture_new_metal (Int32 width, Int32 height, [MarshalAs (UnmanagedType.I1)] bool mipmapped, GRMtlTextureInfoNative* mtlInfo);
|
||||
#else
|
||||
private partial class Delegates {
|
||||
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
|
||||
internal delegate gr_backendtexture_t gr_backendtexture_new_metal (Int32 width, Int32 height, [MarshalAs (UnmanagedType.I1)] bool mipmapped, GRMetalTextureInfoNative* mtlInfo);
|
||||
internal delegate gr_backendtexture_t gr_backendtexture_new_metal (Int32 width, Int32 height, [MarshalAs (UnmanagedType.I1)] bool mipmapped, GRMtlTextureInfoNative* mtlInfo);
|
||||
}
|
||||
private static Delegates.gr_backendtexture_new_metal gr_backendtexture_new_metal_delegate;
|
||||
internal static gr_backendtexture_t gr_backendtexture_new_metal (Int32 width, Int32 height, [MarshalAs (UnmanagedType.I1)] bool mipmapped, GRMetalTextureInfoNative* mtlInfo) =>
|
||||
internal static gr_backendtexture_t gr_backendtexture_new_metal (Int32 width, Int32 height, [MarshalAs (UnmanagedType.I1)] bool mipmapped, GRMtlTextureInfoNative* mtlInfo) =>
|
||||
(gr_backendtexture_new_metal_delegate ??= GetSymbol<Delegates.gr_backendtexture_new_metal> ("gr_backendtexture_new_metal")).Invoke (width, height, mipmapped, mtlInfo);
|
||||
#endif
|
||||
|
||||
|
@ -13423,20 +13423,20 @@ namespace SkiaSharp
|
|||
|
||||
// gr_mtl_textureinfo_t
|
||||
[StructLayout (LayoutKind.Sequential)]
|
||||
internal unsafe partial struct GRMetalTextureInfoNative : IEquatable<GRMetalTextureInfoNative> {
|
||||
internal unsafe partial struct GRMtlTextureInfoNative : IEquatable<GRMtlTextureInfoNative> {
|
||||
// public const void* fTexture
|
||||
public void* fTexture;
|
||||
|
||||
public readonly bool Equals (GRMetalTextureInfoNative obj) =>
|
||||
public readonly bool Equals (GRMtlTextureInfoNative obj) =>
|
||||
fTexture == obj.fTexture;
|
||||
|
||||
public readonly override bool Equals (object obj) =>
|
||||
obj is GRMetalTextureInfoNative f && Equals (f);
|
||||
obj is GRMtlTextureInfoNative f && Equals (f);
|
||||
|
||||
public static bool operator == (GRMetalTextureInfoNative left, GRMetalTextureInfoNative right) =>
|
||||
public static bool operator == (GRMtlTextureInfoNative left, GRMtlTextureInfoNative right) =>
|
||||
left.Equals (right);
|
||||
|
||||
public static bool operator != (GRMetalTextureInfoNative left, GRMetalTextureInfoNative right) =>
|
||||
public static bool operator != (GRMtlTextureInfoNative left, GRMtlTextureInfoNative right) =>
|
||||
!left.Equals (right);
|
||||
|
||||
public readonly override int GetHashCode ()
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
"internal": true
|
||||
},
|
||||
"gr_mtl_textureinfo_t": {
|
||||
"cs": "GRMetalTextureInfoNative",
|
||||
"cs": "GRMtlTextureInfoNative",
|
||||
"internal": true
|
||||
},
|
||||
"gr_context_options_t": {
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace SkiaSharp.Views.Mac
|
|||
|
||||
private bool designMode;
|
||||
|
||||
private IMTLCommandQueue commandQueue;
|
||||
private GRMtlBackendContext backendContext;
|
||||
private GRContext context;
|
||||
|
||||
// created in code
|
||||
|
@ -84,9 +84,13 @@ namespace SkiaSharp.Views.Mac
|
|||
DepthStencilPixelFormat = MTLPixelFormat.Depth32Float_Stencil8;
|
||||
SampleCount = 1;
|
||||
Device = device;
|
||||
commandQueue = device.CreateCommandQueue();
|
||||
backendContext = new GRMtlBackendContext
|
||||
{
|
||||
Device = device,
|
||||
Queue = device.CreateCommandQueue(),
|
||||
};
|
||||
|
||||
// hook up the drawing
|
||||
// hook up the drawing
|
||||
Delegate = this;
|
||||
}
|
||||
|
||||
|
@ -111,7 +115,7 @@ namespace SkiaSharp.Views.Mac
|
|||
if (designMode)
|
||||
return;
|
||||
|
||||
if (Device == null || commandQueue == null || CurrentDrawable?.Texture == null)
|
||||
if (backendContext.Device == null || backendContext.Queue == null || CurrentDrawable?.Texture == null)
|
||||
return;
|
||||
|
||||
CanvasSize = DrawableSize.ToSKSize();
|
||||
|
@ -120,13 +124,13 @@ namespace SkiaSharp.Views.Mac
|
|||
return;
|
||||
|
||||
// create the contexts if not done already
|
||||
context ??= GRContext.CreateMetal(Device, commandQueue);
|
||||
context ??= GRContext.CreateMetal(backendContext);
|
||||
|
||||
const SKColorType colorType = SKColorType.Bgra8888;
|
||||
const GRSurfaceOrigin surfaceOrigin = GRSurfaceOrigin.TopLeft;
|
||||
|
||||
// create the render target
|
||||
var metalInfo = new GRMetalTextureInfo(CurrentDrawable.Texture);
|
||||
var metalInfo = new GRMtlTextureInfo(CurrentDrawable.Texture);
|
||||
using var renderTarget = new GRBackendRenderTarget((int)CanvasSize.Width, (int)CanvasSize.Height, (int)SampleCount, metalInfo);
|
||||
|
||||
// create the surface
|
||||
|
@ -143,7 +147,7 @@ namespace SkiaSharp.Views.Mac
|
|||
context.Flush();
|
||||
|
||||
// present
|
||||
using var commandBuffer = commandQueue.CommandBuffer();
|
||||
using var commandBuffer = backendContext.Queue.CommandBuffer();
|
||||
commandBuffer.PresentDrawable(CurrentDrawable);
|
||||
commandBuffer.Commit();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче