mirror of
https://github.com/ZuneDev/MicrosoftIris.git
synced 2026-07-27 13:13:29 -07:00
[WIP] Fix net48 build
This commit is contained in:
@@ -8,9 +8,6 @@ using System.Security.Permissions;
|
||||
|
||||
namespace Microsoft.Iris.OS.CLR
|
||||
{
|
||||
#if WINDOWS
|
||||
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
|
||||
#endif
|
||||
internal static class NativeMethods
|
||||
{
|
||||
public const int S_OK = 0;
|
||||
|
||||
@@ -13,9 +13,6 @@ using System.Security.Permissions;
|
||||
namespace Microsoft.Iris.OS.CLR
|
||||
{
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
#if WINDOWS
|
||||
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
|
||||
#endif
|
||||
internal static class UnsafeNativeMethods
|
||||
{
|
||||
[DllImport("Ole32.dll")]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#if NETCOREAPP
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Iris.Interop;
|
||||
@@ -215,3 +217,5 @@ public static unsafe class EngineApi
|
||||
release(pUnknown);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#if NETCOREAPP
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -148,3 +150,5 @@ internal sealed class LoadedSound(IntPtr samples) : IDisposable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,7 @@ internal static class WaveParser
|
||||
{
|
||||
private const ushort WAVE_FORMAT_PCM = 1;
|
||||
|
||||
#if NETCOREAPP
|
||||
public static bool TryParse(ReadOnlySpan<byte> source, out SoundHeader header, out byte[] samples)
|
||||
{
|
||||
header = default;
|
||||
@@ -57,6 +58,61 @@ internal static class WaveParser
|
||||
offset = body + (int)chunkSize + ((chunkSize & 1) != 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
// Only uncompressed PCM is representable through this surface -- the managed side
|
||||
// declares WAVE_FORMAT_PCM as its sole format constant, so anything else would be
|
||||
// silently misinterpreted downstream rather than merely unsupported.
|
||||
return haveFormat && samples.Length > 0 && header.formatTag == WAVE_FORMAT_PCM;
|
||||
}
|
||||
#endif
|
||||
|
||||
public static bool TryParse(byte[] source, out SoundHeader header, out byte[] samples)
|
||||
{
|
||||
header = default;
|
||||
samples = Array.Empty<byte>();
|
||||
|
||||
// "RIFF" <size> "WAVE" then a chunk list.
|
||||
if (source.Length < 12 ||
|
||||
!(source[0] == 'R' && source[1] == 'I' && source[2] == 'F' && source[3] == 'F') ||
|
||||
!(source[8] == 'W' && source[9] == 'A' && source[10] == 'V' && source[11] == 'E'))
|
||||
return false;
|
||||
|
||||
bool haveFormat = false;
|
||||
int offset = 12;
|
||||
|
||||
while (offset + 8 <= source.Length)
|
||||
{
|
||||
string chunkId = System.Text.Encoding.UTF8.GetString(source, offset, 4);
|
||||
int body = offset + 8;
|
||||
|
||||
var chunkSizeOffset = offset + 4;
|
||||
//uint chunkSize = source[chunkSizeOffset] | source[chunkSizeOffset + 1];
|
||||
uint chunkSize = BinaryPrimitives.ReadUInt32LittleEndian(source.Slice(offset + 4, 4));
|
||||
|
||||
if (body + chunkSize > source.Length)
|
||||
chunkSize = (uint)(source.Length - body);
|
||||
|
||||
if (chunkId == "fmt " && chunkSize >= 16)
|
||||
{
|
||||
ReadOnlySpan<byte> fmt = source.Slice(body, (int)chunkSize);
|
||||
header.formatTag = BinaryPrimitives.ReadUInt16LittleEndian(fmt[..2]);
|
||||
header.channels = BinaryPrimitives.ReadUInt16LittleEndian(fmt.Slice(2, 2));
|
||||
header.samplesPerSec = BinaryPrimitives.ReadUInt32LittleEndian(fmt.Slice(4, 4));
|
||||
header.avgBytesPerSec = BinaryPrimitives.ReadUInt32LittleEndian(fmt.Slice(8, 4));
|
||||
header.blockAlign = BinaryPrimitives.ReadUInt16LittleEndian(fmt.Slice(12, 2));
|
||||
header.bitsPerSample = BinaryPrimitives.ReadUInt16LittleEndian(fmt.Slice(14, 2));
|
||||
header.cbExtraData = chunkSize >= 18 ? BinaryPrimitives.ReadUInt16LittleEndian(fmt.Slice(16, 2)) : (ushort)0;
|
||||
haveFormat = true;
|
||||
}
|
||||
else if (chunkId == "data")
|
||||
{
|
||||
samples = source.Slice(body, (int)chunkSize).ToArray();
|
||||
header.cbDataSize = chunkSize;
|
||||
}
|
||||
|
||||
// Chunks are word-aligned: an odd-sized chunk is followed by a pad byte.
|
||||
offset = body + (int)chunkSize + ((chunkSize & 1) != 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
// Only uncompressed PCM is representable through this surface -- the managed side
|
||||
// declares WAVE_FORMAT_PCM as its sole format constant, so anything else would be
|
||||
// silently misinterpreted downstream rather than merely unsupported.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#if NETCOREAPP
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
@@ -610,3 +612,5 @@ public static unsafe class SchemaApi
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -29,7 +29,11 @@ internal sealed class TypeSchema
|
||||
// from assemblies loaded at runtime via SpLoadDll -- that is the entire point of this
|
||||
// subsystem. Annotating the parameter keeps every member of anything that reaches
|
||||
// here rooted, instead of silently trimming the properties/methods markup binds to.
|
||||
public TypeSchema([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, uint id)
|
||||
public TypeSchema(
|
||||
#if NETCOREAPP
|
||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
|
||||
#endif
|
||||
Type type, uint id)
|
||||
{
|
||||
Type = type;
|
||||
ID = id;
|
||||
@@ -74,7 +78,13 @@ internal sealed class EnumSchema
|
||||
// at runtime, which can genuinely fail under NativeAOT -- and this project
|
||||
// publishes AOT. The underlying-type overload returns a boxed primitive array, no
|
||||
// dynamic array construction involved.
|
||||
Array underlying = Enum.GetValuesAsUnderlyingType(type);
|
||||
Array underlying =
|
||||
#if NETCOREAPP
|
||||
Enum.GetValuesAsUnderlyingType(type);
|
||||
#else
|
||||
Enum.GetValues(type);
|
||||
#endif
|
||||
|
||||
Values = new int[underlying.Length];
|
||||
for (int i = 0; i < underlying.Length; i++)
|
||||
Values[i] = Convert.ToInt32(underlying.GetValue(i));
|
||||
@@ -102,7 +112,11 @@ internal sealed class SchemaRegistration
|
||||
public IReadOnlyList<TypeSchema> Types => _types;
|
||||
public IReadOnlyList<EnumSchema> Enums => _enums;
|
||||
|
||||
public void Add([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
|
||||
public void Add(
|
||||
#if NETCOREAPP
|
||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
|
||||
#endif
|
||||
Type type)
|
||||
{
|
||||
if (type.IsEnum)
|
||||
_enums.Add(new EnumSchema(type, (uint)_enums.Count));
|
||||
@@ -110,6 +124,7 @@ internal sealed class SchemaRegistration
|
||||
_types.Add(new TypeSchema(type, (uint)_types.Count));
|
||||
}
|
||||
|
||||
#if NETCOREAPP
|
||||
// Unavoidably trim-unsafe by design, and suppressed rather than left to warn so a real
|
||||
// future warning isn't lost in the noise: this projects types out of an assembly the
|
||||
// host chose at *runtime* (SpLoadDll), which the trimmer cannot see into by
|
||||
@@ -118,6 +133,7 @@ internal sealed class SchemaRegistration
|
||||
// assembly), not by static analysis of UIXrender.
|
||||
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Types come from assemblies loaded at runtime via SpLoadDll; the host must root them. See comment above.")]
|
||||
[UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Types come from assemblies loaded at runtime via SpLoadDll; the host must root them. See comment above.")]
|
||||
#endif
|
||||
public static SchemaRegistration FromAssembly(Assembly assembly)
|
||||
{
|
||||
var registration = new SchemaRegistration();
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#if NETCOREAPP
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Iris.Interop;
|
||||
@@ -341,3 +343,5 @@ public static unsafe class RichTextApi
|
||||
return HRESULT.S_OK;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#if NETCOREAPP
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Iris.Interop;
|
||||
@@ -90,3 +92,5 @@ public static unsafe class SimpleTextApi
|
||||
return HRESULT.S_OK;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#if NETCOREAPP
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Iris.Interop;
|
||||
|
||||
@@ -23,3 +25,5 @@ public static unsafe class TracingApi
|
||||
public static void SpLogTrace(char* categoryName, char* message, int indentLevel) =>
|
||||
TracingState.LogTrace(NativeString.UniToString(categoryName), NativeString.UniToString(message), indentLevel);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#if NETCOREAPP
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
@@ -183,3 +185,5 @@ public static unsafe class XmlLiteApi
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,19 +22,25 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Pure-managed, cross-platform, NativeAOT-safe image decoder. Chosen over
|
||||
<!-- Pure-managed, cross-platform, NativeAOT-safe image decoder. Chosen over
|
||||
System.Drawing (Windows-only since .NET 6, and a graphics API this project's
|
||||
dependency policy excludes) so SpBitmapLoad* is real logic on every platform.
|
||||
See logs/UIXrender/FullSurface.md, decision 3. -->
|
||||
<PackageReference Include="StbImageSharp" Version="2.30.15" />
|
||||
<PackageReference Include="StbTrueTypeSharp" Version="1.26.12" />
|
||||
<PackageReference Include="StbImageSharp" Version="2.30.15" />
|
||||
<PackageReference Include="StbTrueTypeSharp" Version="1.26.12" />
|
||||
|
||||
<PackageReference Include="System.ValueTuple" Version="4.6.2" />
|
||||
<PackageReference Include="PolySharp" Version="1.16.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- The subsystem models (RichTextObject, UIXList, TextMetrics, WaveParser,
|
||||
<!-- The subsystem models (RichTextObject, UIXList, TextMetrics, WaveParser,
|
||||
XmlLiteReader, SchemaRegistration) are internal, and the exports that wrap them
|
||||
are [UnmanagedCallersOnly] and so uncallable from C#. This lets the managed
|
||||
test harness exercise the real logic directly. -->
|
||||
<InternalsVisibleTo Include="UIXrender.Engine.Tests" />
|
||||
<InternalsVisibleTo Include="UIXrender.Engine.Tests" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user