Skip to content

Commit e88f972

Browse files
authored
Merge branch 'master' into fixes/controlCodepoint
2 parents e35eb1a + d7040e2 commit e88f972

File tree

16 files changed

+57
-30
lines changed

16 files changed

+57
-30
lines changed

build/TrimmingEnable.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@
1919
<WarningsAsErrors Condition="'$(IsAotCompatible)' == 'true'">$(WarningsAsErrors);IL3050;IL3051;IL3052;IL3053;IL3054;IL3055;IL3056</WarningsAsErrors>
2020
</PropertyGroup>
2121

22+
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0')) AND '$(EnableRuntimeMarshalling)' != 'true'">
23+
<WarningsAsErrors>$(WarningsAsErrors);CA1420;CA1421</WarningsAsErrors>
24+
</PropertyGroup>
25+
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0')) AND '$(EnableRuntimeMarshalling)' != 'true'">
26+
<AssemblyAttribute Include="System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute" />
27+
</ItemGroup>
2228
</Project>

packages/Avalonia/AvaloniaBuildTasks.targets

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@
174174
<_AvaloniaXamlCompiledSymbols Include="@(_DebugSymbolsIntermediatePath->Metadata('AvaloniaCompileOutput'))"/>
175175
<_DebugSymbolsIntermediatePath Remove="@(_DebugSymbolsIntermediatePath)"/>
176176
<_DebugSymbolsIntermediatePath Include="@(_AvaloniaXamlCompiledSymbols)"/>
177+
178+
<!-- ClickOnce takes a copy of @(IntermediateAssembly) during the evaluation phase -->
179+
<_DeploymentManifestEntryPoint Remove="@(_DeploymentManifestEntryPoint)" />
180+
<_DeploymentManifestEntryPoint Include="@(_AvaloniaXamlCompiledAssembly)">
181+
<TargetPath>$(TargetFileName)</TargetPath>
182+
</_DeploymentManifestEntryPoint>
177183
</ItemGroup>
178184
</Target>
179185

src/Android/Avalonia.Android/Avalonia.Android.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<SupportedOSPlatformVersion>$(AvsMinSupportedAndroidVersion)</SupportedOSPlatformVersion>
55
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
66
<AndroidResgenNamespace>Avalonia.Android.Internal</AndroidResgenNamespace>
7+
<EnableRuntimeMarshalling>true</EnableRuntimeMarshalling>
78
</PropertyGroup>
89
<ItemGroup>
910
<ProjectReference Include="..\..\..\packages\Avalonia\Avalonia.csproj" />

src/Android/Avalonia.Android/Platform/SkiaPlatform/AndroidFramebuffer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Avalonia.Android.Platform.SkiaPlatform
88
{
9-
class AndroidFramebuffer : ILockedFramebuffer
9+
unsafe class AndroidFramebuffer : ILockedFramebuffer
1010
{
1111
private IntPtr _window;
1212

@@ -24,7 +24,7 @@ public AndroidFramebuffer(Surface surface, double scaling)
2424
bottom = ANativeWindow_getHeight(_window)
2525
};
2626
Size = new PixelSize(rc.right, rc.bottom);
27-
ANativeWindow_lock(_window, out buffer, ref rc);
27+
ANativeWindow_lock(_window, &buffer, &rc);
2828

2929
Format = buffer.format == AndroidPixelFormat.WINDOW_FORMAT_RGB_565
3030
? PixelFormat.Rgb565 : PixelFormat.Rgba8888;
@@ -61,7 +61,7 @@ public void Dispose()
6161
internal static extern void ANativeWindow_unlockAndPost(IntPtr window);
6262

6363
[DllImport("android")]
64-
internal static extern int ANativeWindow_lock(IntPtr window, out ANativeWindow_Buffer outBuffer, ref ARect inOutDirtyBounds);
64+
internal static extern int ANativeWindow_lock(IntPtr window, ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds);
6565
public enum AndroidPixelFormat
6666
{
6767
WINDOW_FORMAT_RGBA_8888 = 1,

src/Android/Avalonia.Android/Platform/Vulkan/VulkanSupport.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
namespace Avalonia.Android.Platform.Vulkan
88
{
9-
internal class VulkanSupport
9+
internal partial class VulkanSupport
1010
{
11-
[DllImport("libvulkan.so")]
12-
private static extern IntPtr vkGetInstanceProcAddr(IntPtr instance, string name);
11+
[LibraryImport("libvulkan.so", StringMarshalling = StringMarshalling.Utf8)]
12+
private static partial IntPtr vkGetInstanceProcAddr(IntPtr instance, string name);
1313

1414
public static VulkanPlatformGraphics? TryInitialize(VulkanOptions options) =>
1515
VulkanPlatformGraphics.TryCreate(options ?? new(), new VulkanPlatformSpecificOptions

src/Avalonia.Base/Avalonia.Base.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
66
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
77
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>
8-
<IsTrimmable>true</IsTrimmable>
98
</PropertyGroup>
109
<ItemGroup>
1110
<EmbeddedResource Include="Assets\*.trie" />

src/Avalonia.Base/Media/Imaging/PixelFormatTranscoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void Transcode(
1818
AlphaFormat destAlphaFormat)
1919
{
2020
var pixelCount = srcSize.Width * srcSize.Height;
21-
var bufferSize = pixelCount * Marshal.SizeOf<Rgba8888Pixel>();
21+
var bufferSize = pixelCount * sizeof(Rgba8888Pixel);
2222
using var blob = new UnmanagedBlob(bufferSize);
2323

2424
var pixels = new Span<Rgba8888Pixel>((void*)blob.Address, pixelCount);

src/Avalonia.Base/Platform/Internal/UnmanagedBlob.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Runtime.CompilerServices;
44
using System.Runtime.InteropServices;
55
using System.Threading;
6+
using Avalonia.Compatibility;
67

78
namespace Avalonia.Platform.Internal;
89

@@ -108,21 +109,15 @@ public void Dispose()
108109
public int Size { get; private set; }
109110
public bool IsDisposed { get; private set; }
110111

111-
[DllImport("libc", SetLastError = true)]
112+
[DllImport("libc")]
112113
private static extern IntPtr mmap(IntPtr addr, IntPtr length, int prot, int flags, int fd, IntPtr offset);
113-
[DllImport("libc", SetLastError = true)]
114+
[DllImport("libc")]
114115
private static extern int munmap(IntPtr addr, IntPtr length);
115-
[DllImport("libc", SetLastError = true)]
116-
private static extern long sysconf(int name);
117-
118-
private bool? _useMmap;
119-
private bool UseMmap
120-
=> _useMmap ?? ((_useMmap = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)).Value);
121116

122117
// Could be replaced with https://github.com/dotnet/runtime/issues/40892 when it will be available.
123118
private IntPtr Alloc(int size)
124119
{
125-
if (!UseMmap)
120+
if (!OperatingSystemEx.IsLinux())
126121
{
127122
return Marshal.AllocHGlobal(size);
128123
}
@@ -131,25 +126,33 @@ private IntPtr Alloc(int size)
131126
var rv = mmap(IntPtr.Zero, new IntPtr(size), 3, 0x22, -1, IntPtr.Zero);
132127
if (rv.ToInt64() == -1 || (ulong)rv.ToInt64() == 0xffffffff)
133128
{
134-
var errno = Marshal.GetLastWin32Error();
129+
#if NET6_0_OR_GREATER
130+
var errno = Marshal.GetLastSystemError();
135131
throw new Exception("Unable to allocate memory: " + errno);
132+
#else
133+
throw new Exception("Unable to allocate memory");
134+
#endif
136135
}
137136
return rv;
138137
}
139138
}
140139

141140
private void Free(IntPtr ptr, int len)
142141
{
143-
if (!UseMmap)
142+
if (!OperatingSystemEx.IsLinux())
144143
{
145144
Marshal.FreeHGlobal(ptr);
146145
}
147146
else
148147
{
149148
if (munmap(ptr, new IntPtr(len)) == -1)
150149
{
151-
var errno = Marshal.GetLastWin32Error();
150+
#if NET6_0_OR_GREATER
151+
var errno = Marshal.GetLastSystemError();
152152
throw new Exception("Unable to free memory: " + errno);
153+
#else
154+
throw new Exception("Unable to free memory");
155+
#endif
153156
}
154157
}
155158
}

src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>$(AvsCurrentTargetFramework);$(AvsLegacyTargetFrameworks);netstandard2.0</TargetFrameworks>
55
<Nullable>enable</Nullable>
6+
<EnableRuntimeMarshalling>true</EnableRuntimeMarshalling>
67
</PropertyGroup>
78

89
<Import Project="../../build/TrimmingEnable.props" />

src/Avalonia.OpenGL/Avalonia.OpenGL.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>$(AvsCurrentTargetFramework);$(AvsLegacyTargetFrameworks);netstandard2.0</TargetFrameworks>
55
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
6+
<EnableRuntimeMarshalling>true</EnableRuntimeMarshalling>
67
</PropertyGroup>
78

89
<ItemGroup>

src/Avalonia.Vulkan/Avalonia.Vulkan.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>$(AvsCurrentTargetFramework);$(AvsLegacyTargetFrameworks);netstandard2.0</TargetFrameworks>
55
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
6+
<EnableRuntimeMarshalling>true</EnableRuntimeMarshalling>
67
</PropertyGroup>
78

89
<ItemGroup>

src/Avalonia.X11/Avalonia.X11.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<PropertyGroup>
33
<TargetFrameworks>$(AvsCurrentTargetFramework);$(AvsLegacyTargetFrameworks);netstandard2.0</TargetFrameworks>
44
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
5+
<EnableRuntimeMarshalling>true</EnableRuntimeMarshalling>
56
</PropertyGroup>
67

78
<ItemGroup>

src/Browser/Avalonia.Browser/Rendering/BrowserWebGlRenderTarget.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ partial class WebGlContext : IGlContext, Avalonia.Skia.IGlSkiaSpecificOptionsFea
9696
[JSImport("WebGlRenderTarget.makeContextCurrent", AvaloniaModule.MainModuleName)]
9797
private static partial bool MakeContextCurrent(int context);
9898

99-
[DllImport("libSkiaSharp", EntryPoint = "eglGetProcAddress")]
100-
private static extern IntPtr eglGetProcAddress(string name);
99+
[LibraryImport("libSkiaSharp", EntryPoint = "eglGetProcAddress", StringMarshalling = StringMarshalling.Utf8)]
100+
private static partial IntPtr eglGetProcAddress(string name);
101101

102102
private int _contextId;
103103
private readonly Thread _thread;
@@ -177,4 +177,4 @@ public void Dispose()
177177
throw new NotSupportedException();
178178

179179
public bool UseNativeSkiaGrGlInterface => true;
180-
}
180+
}

src/Linux/Avalonia.LinuxFramebuffer/Avalonia.LinuxFramebuffer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<PropertyGroup>
33
<TargetFrameworks>$(AvsCurrentTargetFramework);$(AvsLegacyTargetFrameworks);netstandard2.0</TargetFrameworks>
44
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
5+
<EnableRuntimeMarshalling>true</EnableRuntimeMarshalling>
56
</PropertyGroup>
67
<ItemGroup>
78
<ProjectReference Include="..\..\..\packages\Avalonia\Avalonia.csproj" />

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics.CodeAnalysis;
33
using System.Reflection;
4+
using System.Runtime.CompilerServices;
45
using System.Runtime.InteropServices;
56
using Avalonia.Compatibility;
67
using Avalonia.Platform.Interop;
@@ -77,13 +78,18 @@ public GRContext CreateContext(IntPtr device, IntPtr queue, GRContextOptions? op
7778
{
7879
options ??= new();
7980
var nativeOptions = _contextOptionsToNative.Invoke(options, null)!;
80-
var pOptions = Marshal.AllocHGlobal(Marshal.SizeOf(nativeOptions));
81-
Marshal.StructureToPtr(nativeOptions, pOptions, false);
82-
var context = _gr_direct_context_make_metal_with_options(device, queue, pOptions);
83-
Marshal.FreeHGlobal(pOptions);
84-
if (context == IntPtr.Zero)
85-
throw new InvalidOperationException("Unable to create GRContext from Metal device.");
86-
return (GRContext)_contextCtor.Invoke(new object[] { context, true });
81+
var gcHandle = GCHandle.Alloc(nativeOptions, GCHandleType.Pinned);
82+
try
83+
{
84+
var context = _gr_direct_context_make_metal_with_options(device, queue, gcHandle.AddrOfPinnedObject());
85+
if (context == IntPtr.Zero)
86+
throw new InvalidOperationException("Unable to create GRContext from Metal device.");
87+
return (GRContext)_contextCtor.Invoke(new object[] { context, true });
88+
}
89+
finally
90+
{
91+
gcHandle.Free();
92+
}
8793
}
8894

8995
internal struct GRMtlTextureInfoNative

src/Windows/Avalonia.Win32/Avalonia.Win32.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<PropertyGroup>
33
<TargetFrameworks>$(AvsCurrentTargetFramework);$(AvsLegacyTargetFrameworks);netstandard2.0</TargetFrameworks>
44
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
5+
<EnableRuntimeMarshalling>true</EnableRuntimeMarshalling>
56
<!-- We still keep BinaryFormatter for WinForms compatibility. -->
67
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
78
</PropertyGroup>

0 commit comments

Comments
 (0)