mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-28 22:18:25 +01:00
first
This commit is contained in:
parent
bd62d51ec9
commit
b578433e37
135 changed files with 784842 additions and 0 deletions
99
Brutal.Sdl/CustomStringMarshaller.cs
Normal file
99
Brutal.Sdl/CustomStringMarshaller.cs
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
using System.Runtime.InteropServices.Marshalling;
|
||||
using System.Text;
|
||||
|
||||
namespace Brutal.SdlApi;
|
||||
|
||||
/// <summary>
|
||||
/// Marshaller for UTF-8 strings, used by the generated P/Invoke surface for SDL's <c>const char *</c>
|
||||
/// parameters and returns.
|
||||
/// </summary>
|
||||
[CustomMarshaller(typeof(string), MarshalMode.ManagedToUnmanagedIn, typeof(ManagedToUnmanagedIn))] // string parameter
|
||||
[CustomMarshaller(typeof(string), MarshalMode.ManagedToUnmanagedOut, typeof(ManagedToUnmanagedOut))] // return string
|
||||
public static unsafe class CustomStringMarshaller
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom marshaller to marshal a managed string as a UTF-8 unmanaged string.
|
||||
/// </summary>
|
||||
public ref struct ManagedToUnmanagedIn
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the requested buffer size for optimized marshalling.
|
||||
/// </summary>
|
||||
public static int BufferSize => 0x100;
|
||||
|
||||
private byte* _unmanagedValue;
|
||||
private bool _allocated;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the marshaller with a managed string and requested buffer.
|
||||
/// </summary>
|
||||
/// <param name="managed">The managed string with which to initialize the marshaller.</param>
|
||||
/// <param name="buffer">The request buffer whose size is at least <see cref="BufferSize"/>.</param>
|
||||
public void FromManaged(string? managed, Span<byte> buffer)
|
||||
{
|
||||
_allocated = false;
|
||||
|
||||
if (managed is null)
|
||||
{
|
||||
_unmanagedValue = null;
|
||||
return;
|
||||
}
|
||||
|
||||
const int MaxUtf8BytesPerChar = 3;
|
||||
|
||||
// >= for null terminator
|
||||
// Use the cast to long to avoid the checked operation
|
||||
if ((long)MaxUtf8BytesPerChar * managed.Length >= buffer.Length)
|
||||
{
|
||||
// Calculate accurate byte count when the provided stack-allocated buffer is not sufficient
|
||||
int exactByteCount = checked(Encoding.UTF8.GetByteCount(managed) + 1); // + 1 for null terminator
|
||||
if (exactByteCount > buffer.Length)
|
||||
{
|
||||
buffer = new Span<byte>((byte*)NativeMemory.Alloc((nuint)exactByteCount), exactByteCount);
|
||||
_allocated = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Unsafe.AsPointer is safe since buffer must be pinned
|
||||
_unmanagedValue = (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(buffer));
|
||||
|
||||
int byteCount = Encoding.UTF8.GetBytes(managed, buffer);
|
||||
buffer[byteCount] = 0; // null-terminate
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the current managed string to an unmanaged string.
|
||||
/// </summary>
|
||||
/// <returns>An unmanaged string.</returns>
|
||||
public byte* ToUnmanaged() => _unmanagedValue;
|
||||
|
||||
/// <summary>
|
||||
/// Frees any allocated unmanaged memory.
|
||||
/// </summary>
|
||||
public void Free()
|
||||
{
|
||||
if (_allocated)
|
||||
NativeMemory.Free(_unmanagedValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an unmanaged UTF-8 string returned by SDL back to a managed string.
|
||||
/// </summary>
|
||||
public static class ManagedToUnmanagedOut
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts an unmanaged UTF-8 string to a managed string, preserving a NULL pointer as
|
||||
/// <see langword="null"/>.
|
||||
/// </summary>
|
||||
/// <param name="unmanaged">The unmanaged UTF-8 string, or NULL.</param>
|
||||
/// <returns>The managed string, or <see langword="null"/> if <paramref name="unmanaged"/> is NULL.</returns>
|
||||
public static string? ConvertToManaged(byte* unmanaged)
|
||||
{
|
||||
if (unmanaged == null)
|
||||
return null;
|
||||
|
||||
return Marshal.PtrToStringUTF8((IntPtr)unmanaged);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Brutal.Sdl/Generated/Enums/SdlAppResult.gen.cs
Normal file
13
Brutal.Sdl/Generated/Enums/SdlAppResult.gen.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlAppResult : uint
|
||||
{
|
||||
Continue = 0u,
|
||||
Success = 1u,
|
||||
Failure = 2u,
|
||||
}
|
||||
}
|
||||
17
Brutal.Sdl/Generated/Enums/SdlArrayOrder.gen.cs
Normal file
17
Brutal.Sdl/Generated/Enums/SdlArrayOrder.gen.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlArrayOrder : uint
|
||||
{
|
||||
None = 0u,
|
||||
Rgb = 1u,
|
||||
Rgba = 2u,
|
||||
Argb = 3u,
|
||||
Bgr = 4u,
|
||||
Bgra = 5u,
|
||||
Abgr = 6u,
|
||||
}
|
||||
}
|
||||
15
Brutal.Sdl/Generated/Enums/SdlAssertState.gen.cs
Normal file
15
Brutal.Sdl/Generated/Enums/SdlAssertState.gen.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlAssertState : uint
|
||||
{
|
||||
Retry = 0u,
|
||||
Break = 1u,
|
||||
Abort = 2u,
|
||||
Ignore = 3u,
|
||||
AlwaysIgnore = 4u,
|
||||
}
|
||||
}
|
||||
13
Brutal.Sdl/Generated/Enums/SdlAsyncIOResult.gen.cs
Normal file
13
Brutal.Sdl/Generated/Enums/SdlAsyncIOResult.gen.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlAsyncIOResult : uint
|
||||
{
|
||||
Complete = 0u,
|
||||
Failure = 1u,
|
||||
Canceled = 2u,
|
||||
}
|
||||
}
|
||||
13
Brutal.Sdl/Generated/Enums/SdlAsyncIOTaskType.gen.cs
Normal file
13
Brutal.Sdl/Generated/Enums/SdlAsyncIOTaskType.gen.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlAsyncIOTaskType : uint
|
||||
{
|
||||
Read = 0u,
|
||||
Write = 1u,
|
||||
Close = 2u,
|
||||
}
|
||||
}
|
||||
22
Brutal.Sdl/Generated/Enums/SdlAudioFormat.gen.cs
Normal file
22
Brutal.Sdl/Generated/Enums/SdlAudioFormat.gen.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlAudioFormat : uint
|
||||
{
|
||||
Unknown = 0u,
|
||||
U8 = 8u,
|
||||
S8 = 32776u,
|
||||
S16le = 32784u,
|
||||
S16be = 36880u,
|
||||
S32le = 32800u,
|
||||
S32be = 36896u,
|
||||
F32le = 33056u,
|
||||
F32be = 37152u,
|
||||
S16 = 32784u,
|
||||
S32 = 32800u,
|
||||
F32 = 33056u,
|
||||
}
|
||||
}
|
||||
13
Brutal.Sdl/Generated/Enums/SdlBitmapOrder.gen.cs
Normal file
13
Brutal.Sdl/Generated/Enums/SdlBitmapOrder.gen.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlBitmapOrder : uint
|
||||
{
|
||||
None = 0u,
|
||||
N4321 = 1u,
|
||||
N1234 = 2u,
|
||||
}
|
||||
}
|
||||
20
Brutal.Sdl/Generated/Enums/SdlBlendFactor.gen.cs
Normal file
20
Brutal.Sdl/Generated/Enums/SdlBlendFactor.gen.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlBlendFactor : uint
|
||||
{
|
||||
Zero = 1u,
|
||||
One = 2u,
|
||||
SrcColor = 3u,
|
||||
OneMinusSrcColor = 4u,
|
||||
SrcAlpha = 5u,
|
||||
OneMinusSrcAlpha = 6u,
|
||||
DstColor = 7u,
|
||||
OneMinusDstColor = 8u,
|
||||
DstAlpha = 9u,
|
||||
OneMinusDstAlpha = 10u,
|
||||
}
|
||||
}
|
||||
15
Brutal.Sdl/Generated/Enums/SdlBlendOperation.gen.cs
Normal file
15
Brutal.Sdl/Generated/Enums/SdlBlendOperation.gen.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlBlendOperation : uint
|
||||
{
|
||||
Add = 1u,
|
||||
Subtract = 2u,
|
||||
RevSubtract = 3u,
|
||||
Minimum = 4u,
|
||||
Maximum = 5u,
|
||||
}
|
||||
}
|
||||
13
Brutal.Sdl/Generated/Enums/SdlCameraPermissionState.gen.cs
Normal file
13
Brutal.Sdl/Generated/Enums/SdlCameraPermissionState.gen.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlCameraPermissionState
|
||||
{
|
||||
Denied = -1,
|
||||
Pending = 0,
|
||||
Approved = 1,
|
||||
}
|
||||
}
|
||||
13
Brutal.Sdl/Generated/Enums/SdlCameraPosition.gen.cs
Normal file
13
Brutal.Sdl/Generated/Enums/SdlCameraPosition.gen.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlCameraPosition : uint
|
||||
{
|
||||
Unknown = 0u,
|
||||
FrontFacing = 1u,
|
||||
BackFacing = 2u,
|
||||
}
|
||||
}
|
||||
14
Brutal.Sdl/Generated/Enums/SdlCapitalization.gen.cs
Normal file
14
Brutal.Sdl/Generated/Enums/SdlCapitalization.gen.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlCapitalization : uint
|
||||
{
|
||||
None = 0u,
|
||||
Sentences = 1u,
|
||||
Words = 2u,
|
||||
Letters = 3u,
|
||||
}
|
||||
}
|
||||
14
Brutal.Sdl/Generated/Enums/SdlChromaLocation.gen.cs
Normal file
14
Brutal.Sdl/Generated/Enums/SdlChromaLocation.gen.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlChromaLocation : uint
|
||||
{
|
||||
None = 0u,
|
||||
Left = 1u,
|
||||
Center = 2u,
|
||||
Topleft = 3u,
|
||||
}
|
||||
}
|
||||
24
Brutal.Sdl/Generated/Enums/SdlColorPrimaries.gen.cs
Normal file
24
Brutal.Sdl/Generated/Enums/SdlColorPrimaries.gen.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlColorPrimaries : uint
|
||||
{
|
||||
Unknown = 0u,
|
||||
Bt709 = 1u,
|
||||
Unspecified = 2u,
|
||||
Bt470m = 4u,
|
||||
Bt470bg = 5u,
|
||||
Bt601 = 6u,
|
||||
Smpte240 = 7u,
|
||||
GenericFilm = 8u,
|
||||
Bt2020 = 9u,
|
||||
Xyz = 10u,
|
||||
Smpte431 = 11u,
|
||||
Smpte432 = 12u,
|
||||
Ebu3213 = 22u,
|
||||
Custom = 31u,
|
||||
}
|
||||
}
|
||||
13
Brutal.Sdl/Generated/Enums/SdlColorRange.gen.cs
Normal file
13
Brutal.Sdl/Generated/Enums/SdlColorRange.gen.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlColorRange : uint
|
||||
{
|
||||
Unknown = 0u,
|
||||
Limited = 1u,
|
||||
Full = 2u,
|
||||
}
|
||||
}
|
||||
13
Brutal.Sdl/Generated/Enums/SdlColorType.gen.cs
Normal file
13
Brutal.Sdl/Generated/Enums/SdlColorType.gen.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlColorType : uint
|
||||
{
|
||||
Unknown = 0u,
|
||||
Rgb = 1u,
|
||||
Ycbcr = 2u,
|
||||
}
|
||||
}
|
||||
23
Brutal.Sdl/Generated/Enums/SdlColorspace.gen.cs
Normal file
23
Brutal.Sdl/Generated/Enums/SdlColorspace.gen.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlColorspace : uint
|
||||
{
|
||||
Unknown = 0u,
|
||||
Srgb = 301991328u,
|
||||
SrgbLinear = 301991168u,
|
||||
Hdr10 = 301999616u,
|
||||
Jpeg = 570426566u,
|
||||
Bt601Limited = 554703046u,
|
||||
Bt601Full = 571480262u,
|
||||
Bt709Limited = 554697761u,
|
||||
Bt709Full = 571474977u,
|
||||
Bt2020Limited = 554706441u,
|
||||
Bt2020Full = 571483657u,
|
||||
RgbDefault = 301991328u,
|
||||
YuvDefault = 554703046u,
|
||||
}
|
||||
}
|
||||
13
Brutal.Sdl/Generated/Enums/SdlDateFormat.gen.cs
Normal file
13
Brutal.Sdl/Generated/Enums/SdlDateFormat.gen.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlDateFormat : uint
|
||||
{
|
||||
Yyyymmdd = 0u,
|
||||
Ddmmyyyy = 1u,
|
||||
Mmddyyyy = 2u,
|
||||
}
|
||||
}
|
||||
15
Brutal.Sdl/Generated/Enums/SdlDisplayOrientation.gen.cs
Normal file
15
Brutal.Sdl/Generated/Enums/SdlDisplayOrientation.gen.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// <auto-generated/>
|
||||
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.SdlApi
|
||||
{
|
||||
public enum SdlDisplayOrientation : uint
|
||||
{
|
||||
Unknown = 0u,
|
||||
Landscape = 1u,
|
||||
LandscapeFlipped = 2u,
|
||||
Portrait = 3u,
|
||||
PortraitFlipped = 4u,
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue