mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-15 03:20:30 +00:00
Add required CoreGraphics/Accelerate interops
This commit is contained in:
@@ -342,6 +342,7 @@
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=API/@EntryIndexedValue">API</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ARGB/@EntryIndexedValue">ARGB</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BPM/@EntryIndexedValue">BPM</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CG/@EntryIndexedValue">CG</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FBO/@EntryIndexedValue">FBO</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CCL/@EntryIndexedValue">CCL</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GC/@EntryIndexedValue">GC</s:String>
|
||||
|
||||
19
osu.Framework/Platform/Apple/Native/Accelerate/vImage.cs
Normal file
19
osu.Framework/Platform/Apple/Native/Accelerate/vImage.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native.Accelerate
|
||||
{
|
||||
internal static unsafe partial class vImage
|
||||
{
|
||||
[LibraryImport(Interop.LIB_ACCELERATE, EntryPoint = "vImageBuffer_Init")]
|
||||
internal static partial vImage_Error Init(vImage_Buffer* buf, uint height, uint width, uint pixelBits, vImage_Flags flags);
|
||||
|
||||
[LibraryImport(Interop.LIB_ACCELERATE, EntryPoint = "vImageBuffer_InitWithCGImage")]
|
||||
internal static partial vImage_Error InitWithCGImage(vImage_Buffer* buf, vImage_CGImageFormat* format, double* backgroundColour, IntPtr image, vImage_Flags flags);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native.Accelerate
|
||||
{
|
||||
internal unsafe struct vImage_Buffer
|
||||
{
|
||||
public byte* Data;
|
||||
public nuint Height;
|
||||
public nuint Width;
|
||||
public nuint BytesPerRow;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native.Accelerate
|
||||
{
|
||||
internal unsafe struct vImage_CGImageFormat
|
||||
{
|
||||
public uint BitsPerComponent;
|
||||
public uint BitsPerPixel;
|
||||
public CGColorSpace ColorSpace;
|
||||
public CGBitmapInfo BitmapInfo;
|
||||
public uint Version;
|
||||
public double* Decode;
|
||||
public CGColorRenderingIntent RenderingIntent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native.Accelerate
|
||||
{
|
||||
internal enum vImage_Error : long
|
||||
{
|
||||
OutOfPlaceOperationRequired = -21780,
|
||||
ColorSyncIsAbsent = -21779,
|
||||
InvalidImageFormat = -21778,
|
||||
InvalidRowBytes = -21777,
|
||||
InternalError = -21776,
|
||||
UnknownFlagsBit = -21775,
|
||||
BufferSizeMismatch = -21774,
|
||||
InvalidParameter = -21773,
|
||||
NullPointerArgument = -21772,
|
||||
MemoryAllocationError = -21771,
|
||||
InvalidOffsetY = -21770,
|
||||
InvalidOffsetX = -21769,
|
||||
InvalidEdgeStyle = -21768,
|
||||
InvalidKernelSize = -21767,
|
||||
RoiLargerThanInputBuffer = -21766,
|
||||
NoError = 0,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native.Accelerate
|
||||
{
|
||||
internal enum vImage_Flags : uint
|
||||
{
|
||||
NoFlags = 0,
|
||||
LeaveAlphaUnchanged = 1,
|
||||
CopyInPlace = 2,
|
||||
BackgroundColorFill = 4,
|
||||
EdgeExtend = 8,
|
||||
DoNotTile = 16,
|
||||
HighQualityResampling = 32,
|
||||
TruncateKernel = 64,
|
||||
GetTempBufferSize = 128,
|
||||
PrintDiagnosticsToConsole = 256,
|
||||
NoAllocate = 512,
|
||||
}
|
||||
}
|
||||
24
osu.Framework/Platform/Apple/Native/CGBitmapContext.cs
Normal file
24
osu.Framework/Platform/Apple/Native/CGBitmapContext.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native
|
||||
{
|
||||
internal readonly partial struct CGBitmapContext
|
||||
{
|
||||
internal IntPtr Handle { get; }
|
||||
|
||||
internal CGBitmapContext(IntPtr handle)
|
||||
{
|
||||
Handle = handle;
|
||||
}
|
||||
|
||||
[LibraryImport(Interop.LIB_CORE_GRAPHICS, EntryPoint = "CGBitmapContextCreate")]
|
||||
public static partial CGBitmapContext Create(IntPtr data, nuint width, nuint height, nuint bitsPerComponent, nuint bytesPerRow, CGColorSpace colorSpace, CGBitmapInfo bitmapInfo);
|
||||
|
||||
[LibraryImport(Interop.LIB_CORE_GRAPHICS, EntryPoint = "CGContextDrawImage")]
|
||||
public static partial void DrawImage(CGBitmapContext context, CGRect rect, CGImage image);
|
||||
}
|
||||
}
|
||||
26
osu.Framework/Platform/Apple/Native/CGBitmapInfo.cs
Normal file
26
osu.Framework/Platform/Apple/Native/CGBitmapInfo.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native
|
||||
{
|
||||
public enum CGBitmapInfo : uint
|
||||
{
|
||||
None,
|
||||
PremultipliedLast,
|
||||
PremultipliedFirst,
|
||||
Last,
|
||||
First,
|
||||
NoneSkipLast,
|
||||
NoneSkipFirst,
|
||||
Only,
|
||||
AlphaInfoMask = 31,
|
||||
FloatInfoMask = 3840,
|
||||
FloatComponents = 256,
|
||||
ByteOrderMask = 28672,
|
||||
ByteOrderDefault = 0,
|
||||
ByteOrder16Little = 4096,
|
||||
ByteOrder32Little = 8192,
|
||||
ByteOrder16Big = 12288,
|
||||
ByteOrder32Big = 16384,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native
|
||||
{
|
||||
public enum CGColorRenderingIntent
|
||||
{
|
||||
Default,
|
||||
AbsoluteColorimetric,
|
||||
RelativeColorimetric,
|
||||
Perceptual,
|
||||
Saturation,
|
||||
}
|
||||
}
|
||||
21
osu.Framework/Platform/Apple/Native/CGColorSpace.cs
Normal file
21
osu.Framework/Platform/Apple/Native/CGColorSpace.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native
|
||||
{
|
||||
public readonly partial struct CGColorSpace
|
||||
{
|
||||
internal IntPtr Handle { get; }
|
||||
|
||||
internal CGColorSpace(IntPtr handle)
|
||||
{
|
||||
Handle = handle;
|
||||
}
|
||||
|
||||
[LibraryImport(Interop.LIB_CORE_GRAPHICS, EntryPoint = "CGColorSpaceCreateDeviceRGB")]
|
||||
internal static partial CGColorSpace CreateDeviceRGB();
|
||||
}
|
||||
}
|
||||
33
osu.Framework/Platform/Apple/Native/CGImage.cs
Normal file
33
osu.Framework/Platform/Apple/Native/CGImage.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native
|
||||
{
|
||||
internal readonly partial struct CGImage
|
||||
{
|
||||
internal IntPtr Handle { get; }
|
||||
|
||||
public CGImage(IntPtr handle)
|
||||
{
|
||||
Handle = handle;
|
||||
}
|
||||
|
||||
internal nuint Width => GetWidth(this);
|
||||
internal nuint Height => GetHeight(this);
|
||||
|
||||
[LibraryImport(Interop.LIB_CORE_GRAPHICS, EntryPoint = "CGImageGetWidth")]
|
||||
internal static partial nuint GetWidth(CGImage image);
|
||||
|
||||
[LibraryImport(Interop.LIB_CORE_GRAPHICS, EntryPoint = "CGImageGetHeight")]
|
||||
internal static partial nuint GetHeight(CGImage image);
|
||||
|
||||
[LibraryImport(Interop.LIB_CORE_GRAPHICS, EntryPoint = "CGImageRelease")]
|
||||
internal static partial void Release(CGImage image);
|
||||
|
||||
[LibraryImport("/System/Library/Frameworks/CoreFoundation.framework/Versions/Current/CoreFoundation", EntryPoint = "CFGetRetainCount")]
|
||||
internal static partial int GetRetainCount(CGImage image);
|
||||
}
|
||||
}
|
||||
17
osu.Framework/Platform/Apple/Native/CGImageAlphaInfo.cs
Normal file
17
osu.Framework/Platform/Apple/Native/CGImageAlphaInfo.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native
|
||||
{
|
||||
internal enum CGImageAlphaInfo : uint
|
||||
{
|
||||
None,
|
||||
PremultipliedLast,
|
||||
PremultipliedFirst,
|
||||
Last,
|
||||
First,
|
||||
NoneSkipLast,
|
||||
NoneSkipFirst,
|
||||
Only,
|
||||
}
|
||||
}
|
||||
11
osu.Framework/Platform/Apple/Native/CGPoint.cs
Normal file
11
osu.Framework/Platform/Apple/Native/CGPoint.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native
|
||||
{
|
||||
internal struct CGPoint
|
||||
{
|
||||
internal double X;
|
||||
internal double Y;
|
||||
}
|
||||
}
|
||||
11
osu.Framework/Platform/Apple/Native/CGRect.cs
Normal file
11
osu.Framework/Platform/Apple/Native/CGRect.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native
|
||||
{
|
||||
internal struct CGRect
|
||||
{
|
||||
internal CGPoint Origin;
|
||||
internal CGSize Size;
|
||||
}
|
||||
}
|
||||
11
osu.Framework/Platform/Apple/Native/CGSize.cs
Normal file
11
osu.Framework/Platform/Apple/Native/CGSize.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native
|
||||
{
|
||||
internal struct CGSize
|
||||
{
|
||||
internal double Width;
|
||||
internal double Height;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ namespace osu.Framework.Platform.Apple.Native
|
||||
Handle = handle;
|
||||
}
|
||||
|
||||
public static implicit operator NSData(NSMutableData data) => new NSData(data.Handle);
|
||||
|
||||
internal byte[] ToBytes()
|
||||
{
|
||||
IntPtr pointer = Interop.SendIntPtr(Handle, sel_bytes);
|
||||
|
||||
39
osu.Framework/Platform/Apple/Native/NSMutableData.cs
Normal file
39
osu.Framework/Platform/Apple/Native/NSMutableData.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Platform.MacOS.Native;
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native
|
||||
{
|
||||
internal readonly struct NSMutableData : IDisposable
|
||||
{
|
||||
internal IntPtr Handle { get; }
|
||||
|
||||
private static readonly IntPtr class_pointer = Class.Get("NSMutableData");
|
||||
private static readonly IntPtr sel_release = Selector.Get("release");
|
||||
private static readonly IntPtr sel_data_with_length = Selector.Get("dataWithLength:");
|
||||
private static readonly IntPtr sel_mutable_bytes = Selector.Get("mutableBytes");
|
||||
|
||||
internal NSMutableData(IntPtr handle)
|
||||
{
|
||||
Handle = handle;
|
||||
}
|
||||
|
||||
internal unsafe byte* MutableBytes => (byte*)Interop.SendIntPtr(Handle, sel_mutable_bytes);
|
||||
|
||||
internal void Release() => Interop.SendVoid(Handle, sel_release);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Handle != IntPtr.Zero)
|
||||
Release();
|
||||
}
|
||||
|
||||
internal static NSMutableData FromLength(int length)
|
||||
{
|
||||
IntPtr handle = Interop.SendIntPtr(class_pointer, sel_data_with_length, length);
|
||||
return new NSMutableData(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,9 @@ namespace osu.Framework.Platform.MacOS.Native
|
||||
private static readonly IntPtr sel_release = Selector.Get("release");
|
||||
private static readonly IntPtr sel_init_with_data = Selector.Get("initWithData:");
|
||||
private static readonly IntPtr sel_tiff_representation = Selector.Get("TIFFRepresentation");
|
||||
private static readonly IntPtr sel_cg_image_for_proposed_rect = Selector.Get("CGImageForProposedRect:context:hints:");
|
||||
|
||||
internal CGImage CGImage => new CGImage(Interop.SendIntPtr(Handle, sel_cg_image_for_proposed_rect, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero));
|
||||
|
||||
internal NSData TiffRepresentation => new NSData(Interop.SendIntPtr(Handle, sel_tiff_representation));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user