From b30894cb5c1e2403b70e72853ffbd0176ad7c6dd Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Tue, 21 May 2024 05:57:47 +0200 Subject: [PATCH] Warning fixes: spring wave (#15747) * Fix duplicated trimming attributes warning in Markup.Xaml.Loader * Fix nullability warnings * Update ImageSharp to 2.1.8 * Removed obsolete attributes on ValueStore * Ignore CA1815 on private API RenderTargetProperties * Fix switch expression warnings * Fix warnings in Vulkan project * Only include PThread for WasmEnableThreads * Rename pollfd to PollFd to fix CS8981 * Fix incompatible packages being used in ControlCatalog.Desktop --------- Co-authored-by: Max Katz --- build/Base.props | 3 --- build/ImageSharp.props | 2 +- build/SampleApp.props | 13 +++++++++++-- samples/ControlCatalog.Desktop/Program.cs | 5 ++--- .../Pages/OpenGl/OpenGlContent.cs | 4 ++-- .../Pages/OpenGl/OpenGlLeasePage.xaml.cs | 8 ++++---- samples/ControlCatalog/Pages/OpenGlPage.xaml.cs | 2 +- samples/GpuInterop/VulkanDemo/VulkanImage.cs | 3 ++- .../AssemblyLoadContextH.cs | 11 +++++++---- .../MainWindow.axaml.cs | 17 +++++++++-------- .../UnloadableAssemblyLoadContext/PlugTool.cs | 10 +++++----- .../UnloadableAssemblyLoadContext.csproj | 15 +++------------ .../Program.cs | 9 --------- .../Window1.axaml | 1 - .../Window1.axaml.cs | 5 +---- .../Compatibility/TrimmingAttributes.cs | 4 +++- .../Platform/RenderTargetProperties.cs | 5 ++++- src/Avalonia.Base/PropertyStore/ValueStore.cs | 2 -- .../Composition/Server/DrawingContextProxy.cs | 3 --- src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs | 4 ++-- src/Avalonia.Vulkan/Avalonia.Vulkan.csproj | 5 +++++ src/Avalonia.Vulkan/VulkanImageInfo.cs | 6 ++---- src/Avalonia.X11/Vulkan/VulkanSupport.cs | 4 +++- src/Avalonia.X11/X11FramebufferSurface.cs | 4 +++- .../Avalonia.Browser/Rendering/RenderWorker.cs | 4 +++- .../build/Avalonia.Browser.targets | 2 +- .../Input/LibInput/LibInputBackend.cs | 2 +- .../NativeUnsafeMethods.cs | 4 ++-- .../Output/DrmOutput.cs | 2 +- .../Output/FbDevBackBuffer.cs | 4 +++- .../Output/FbDevOutputOptions.cs | 6 +++++- .../IncludeXamlIlSre.props | 9 +-------- .../Avalonia.Designer.HostApp.csproj | 3 +++ .../CrossTestBase.cs | 2 +- .../CrossUI.Wpf.cs | 6 ++++-- .../CrossTests/CrossGeometryTests.cs | 2 +- .../CrossUI/CrossUI.Avalonia.cs | 3 ++- tests/Avalonia.RenderTests/CrossUI/CrossUI.cs | 14 ++++++++------ .../Avalonia.Skia.RenderTests/CrossTestBase.cs | 6 +++++- 39 files changed, 111 insertions(+), 103 deletions(-) delete mode 100644 samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContextPlug/Program.cs diff --git a/build/Base.props b/build/Base.props index 2d50a7eae0c..6b7ae5d6775 100644 --- a/build/Base.props +++ b/build/Base.props @@ -1,9 +1,6 @@  - - - diff --git a/build/ImageSharp.props b/build/ImageSharp.props index c1eee25ce56..c15d4f862a4 100644 --- a/build/ImageSharp.props +++ b/build/ImageSharp.props @@ -1,5 +1,5 @@ - + diff --git a/build/SampleApp.props b/build/SampleApp.props index 285f880129e..8ecbe902ab4 100644 --- a/build/SampleApp.props +++ b/build/SampleApp.props @@ -1,13 +1,22 @@ + WinExe - - + + + + + + + + + + diff --git a/samples/ControlCatalog.Desktop/Program.cs b/samples/ControlCatalog.Desktop/Program.cs index d555ce13996..533ee8308a0 100644 --- a/samples/ControlCatalog.Desktop/Program.cs +++ b/samples/ControlCatalog.Desktop/Program.cs @@ -1,7 +1,5 @@ using System; -using System.Linq; using Avalonia; -using Avalonia.Controls; using Avalonia.Platform; using ControlCatalog.NetCore; using ControlCatalog.Pages; @@ -29,7 +27,8 @@ public static AppBuilder BuildAvaloniaApp() EmbedSample.Implementation = new EmbedSampleWin(); }) - .UsePlatformDetect(); + .UseWin32() + .UseSkia(); private static void ConfigureAssetAssembly(AppBuilder builder) { diff --git a/samples/ControlCatalog/Pages/OpenGl/OpenGlContent.cs b/samples/ControlCatalog/Pages/OpenGl/OpenGlContent.cs index c975ca1e85b..913b0abfeb8 100644 --- a/samples/ControlCatalog/Pages/OpenGl/OpenGlContent.cs +++ b/samples/ControlCatalog/Pages/OpenGl/OpenGlContent.cs @@ -183,7 +183,7 @@ private static void CheckError(GlInterface gl) Console.WriteLine(err); } - public string Info { get; private set; } + public string Info { get; private set; } = string.Empty; public unsafe void Init(GlInterface GL, GlVersion version) { @@ -308,4 +308,4 @@ public void Deinit(GlInterface GL) CheckError(GL); } -} \ No newline at end of file +} diff --git a/samples/ControlCatalog/Pages/OpenGl/OpenGlLeasePage.xaml.cs b/samples/ControlCatalog/Pages/OpenGl/OpenGlLeasePage.xaml.cs index 91c4ce0dbe9..a8c45297ee0 100644 --- a/samples/ControlCatalog/Pages/OpenGl/OpenGlLeasePage.xaml.cs +++ b/samples/ControlCatalog/Pages/OpenGl/OpenGlLeasePage.xaml.cs @@ -169,7 +169,7 @@ public OpenGlLeasePage() _knobs.PropertyChanged += KnobsPropertyChanged; } - private void KnobsPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs change) + private void KnobsPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs change) { if (change.Property == GlPageKnobs.YawProperty || change.Property == GlPageKnobs.RollProperty @@ -183,7 +183,7 @@ Parameters GetParameters() => new() Yaw = _knobs!.Yaw, Pitch = _knobs.Pitch, Roll = _knobs.Roll, Disco = _knobs.Disco }; - private void ViewportAttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs e) + private void ViewportAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e) { var visual = ElementComposition.GetElementVisual(_viewport!); if(visual == null) @@ -206,11 +206,11 @@ protected override Size ArrangeOverride(Size finalSize) return size; } - private void ViewportDetachedFromVisualTree(object sender, VisualTreeAttachmentEventArgs e) + private void ViewportDetachedFromVisualTree(object? sender, VisualTreeAttachmentEventArgs e) { _visual?.SendHandlerMessage(new DisposeMessage()); _visual = null; ElementComposition.SetElementChildVisual(_viewport, null); base.OnDetachedFromVisualTree(e); } -} \ No newline at end of file +} diff --git a/samples/ControlCatalog/Pages/OpenGlPage.xaml.cs b/samples/ControlCatalog/Pages/OpenGlPage.xaml.cs index 494a672b947..28f4d7e073e 100644 --- a/samples/ControlCatalog/Pages/OpenGlPage.xaml.cs +++ b/samples/ControlCatalog/Pages/OpenGlPage.xaml.cs @@ -30,7 +30,7 @@ public void Init(GlPageKnobs knobs) _knobs.PropertyChanged += KnobsPropertyChanged; } - private void KnobsPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs change) + private void KnobsPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs change) { if (change.Property == GlPageKnobs.YawProperty || change.Property == GlPageKnobs.RollProperty diff --git a/samples/GpuInterop/VulkanDemo/VulkanImage.cs b/samples/GpuInterop/VulkanDemo/VulkanImage.cs index ea434412432..0c5c2e3511a 100644 --- a/samples/GpuInterop/VulkanDemo/VulkanImage.cs +++ b/samples/GpuInterop/VulkanDemo/VulkanImage.cs @@ -117,7 +117,8 @@ public unsafe class VulkanImage : IDisposable ImportMemoryWin32HandleInfoKHR handleImport = default; if (handleType == ExternalMemoryHandleTypeFlags.D3D11TextureBit && exportable) { - _d3dTexture2D = D3DMemoryHelper.CreateMemoryHandle(vk.D3DDevice, size, Format); + var d3dDevice = vk.D3DDevice ?? throw new NotSupportedException("Vulkan D3DDevice wasn't created"); + _d3dTexture2D = D3DMemoryHelper.CreateMemoryHandle(d3dDevice, size, Format); using var dxgi = _d3dTexture2D.QueryInterface(); handleImport = new ImportMemoryWin32HandleInfoKHR diff --git a/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/AssemblyLoadContextH.cs b/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/AssemblyLoadContextH.cs index 780be4d4b8c..607ec49b12a 100644 --- a/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/AssemblyLoadContextH.cs +++ b/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/AssemblyLoadContextH.cs @@ -22,13 +22,16 @@ public AssemblyLoadContextH(string pluginPath, string name) : base(isCollectible Unloading += (sender) => { AvaloniaPropertyRegistry.Instance.UnregisterByModule(sender.Assemblies.First().DefinedTypes); - Application.Current.Styles.Remove(MainWindow.Style); - AssetLoader.InvalidateAssemblyCache(sender.Assemblies.First().GetName().Name); - MainWindow.Style= null; + + if (MainWindow.Style is { } style) + Application.Current?.Styles.Remove(style); + + AssetLoader.InvalidateAssemblyCache(sender.Assemblies.First().GetName().Name!); + MainWindow.Style = null; }; } - protected override Assembly Load(AssemblyName assemblyName) + protected override Assembly? Load(AssemblyName assemblyName) { var assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName); if (assemblyPath != null) diff --git a/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/MainWindow.axaml.cs b/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/MainWindow.axaml.cs index 959740da59c..aee3a60a01e 100644 --- a/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/MainWindow.axaml.cs +++ b/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/MainWindow.axaml.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Reflection; using System.Threading; @@ -33,11 +34,11 @@ private void InitializeComponent() this.AttachDevTools(); } } - private PlugTool _plugTool; + private PlugTool? _plugTool; protected override void OnOpened(EventArgs e) { base.OnOpened(e); - test(); + Test(); //Content = _plugTool.FindControl("UnloadableAssemblyLoadContextPlug.TestControl"); @@ -75,7 +76,7 @@ protected override void OnClosed(EventArgs e) Thread.CurrentThread.IsBackground = false; - var weakReference = _plugTool.Unload(); + var weakReference = _plugTool!.Unload(); while (weakReference.IsAlive) { GC.Collect(); @@ -88,8 +89,9 @@ protected override void OnClosed(EventArgs e) } - public static IStyle Style; - public void test(){ + public static IStyle? Style; + + public void Test() { //Notice : 你可以删除UnloadableAssemblyLoadContextPlug.dll所在文件夹中有关Avalonia的所有Dll,但这不是必须的 //Notice : You can delete all Dlls about Avalonia in the folder where UnloadableAssemblyLoadContextPlug.dll is located, but this is not necessary @@ -97,7 +99,6 @@ protected override void OnClosed(EventArgs e) var AssemblyLoadContextH = new AssemblyLoadContextH(fileInfo.FullName,"test"); var assembly = AssemblyLoadContextH.LoadFromAssemblyPath(fileInfo.FullName); - var assemblyDescriptorResolver = _plugTool=new PlugTool(); _plugTool.AssemblyLoadContextH = AssemblyLoadContextH; @@ -106,13 +107,13 @@ protected override void OnClosed(EventArgs e) styleInclude.Source=new Uri("ControlStyle.axaml", UriKind.Relative); styles.Add(styleInclude); Style = styles; - Application.Current.Styles.Add(styles); + Application.Current!.Styles.Add(styles); foreach (var type in assembly.GetTypes()) { if (type.FullName=="AvaloniaPlug.Window1") { //创建type实例 - Window instance = (Window)type.GetConstructor( new Type[0]).Invoke(null); + Window? instance = (Window)type.GetConstructor([])!.Invoke(null); Dispatcher.UIThread.InvokeAsync(() => { diff --git a/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/PlugTool.cs b/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/PlugTool.cs index fb5cc282654..2b240e3a912 100644 --- a/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/PlugTool.cs +++ b/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/PlugTool.cs @@ -6,23 +6,23 @@ namespace UnloadableAssemblyLoadContext; public class PlugTool { - public AssemblyLoadContextH AssemblyLoadContextH; + public AssemblyLoadContextH? AssemblyLoadContextH; public WeakReference Unload() { var weakReference = new WeakReference(AssemblyLoadContextH); - AssemblyLoadContextH.Unload(); + AssemblyLoadContextH?.Unload(); AssemblyLoadContextH = null; return weakReference; } public Control? FindControl(string type) { - var type1 = AssemblyLoadContextH.Assemblies. + var type1 = AssemblyLoadContextH!.Assemblies. FirstOrDefault(x => x.GetName().Name == "UnloadableAssemblyLoadContextPlug")?. GetType(type); - if (type1.IsSubclassOf(typeof(Control))) + if (type1 is not null && type1.IsSubclassOf(typeof(Control))) { - var constructorInfo = type1.GetConstructor( Type.EmptyTypes).Invoke(null) as Control; + var constructorInfo = type1.GetConstructor([])!.Invoke(null) as Control; return constructorInfo; } diff --git a/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext.csproj b/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext.csproj index e39a35a2940..9ad92d3e62d 100644 --- a/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext.csproj +++ b/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext.csproj @@ -10,19 +10,10 @@ - - %(Filename) - - - Designer - - - - - - - + + + diff --git a/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContextPlug/Program.cs b/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContextPlug/Program.cs deleted file mode 100644 index 60c37ec32f7..00000000000 --- a/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContextPlug/Program.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace AvaloniaPlug; - -class Program -{ - // Initialization code. Don't use any Avalonia, third-party APIs or any - // SynchronizationContext-reliant code before AppMain is called: things aren't initialized - // yet and stuff might break. - private static string test = "23"; -} \ No newline at end of file diff --git a/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContextPlug/Window1.axaml b/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContextPlug/Window1.axaml index 83a389f31e9..b9724f2c51a 100644 --- a/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContextPlug/Window1.axaml +++ b/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContextPlug/Window1.axaml @@ -2,7 +2,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:avaloniaPlug="clr-namespace:AvaloniaPlug" xmlns:unloadableAssemblyLoadContextPlug="clr-namespace:UnloadableAssemblyLoadContextPlug" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="UnloadableAssemblyLoadContextPlug.Window1" diff --git a/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContextPlug/Window1.axaml.cs b/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContextPlug/Window1.axaml.cs index 8236d1a3385..e4f9c619cdb 100644 --- a/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContextPlug/Window1.axaml.cs +++ b/samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContextPlug/Window1.axaml.cs @@ -1,8 +1,5 @@ -using System.Diagnostics; -using Avalonia; -using Avalonia.Controls; +using Avalonia.Controls; using Avalonia.Markup.Xaml; -using AvaloniaPlug; namespace UnloadableAssemblyLoadContextPlug; diff --git a/src/Avalonia.Base/Compatibility/TrimmingAttributes.cs b/src/Avalonia.Base/Compatibility/TrimmingAttributes.cs index 8adc6f66648..0341d86b65a 100644 --- a/src/Avalonia.Base/Compatibility/TrimmingAttributes.cs +++ b/src/Avalonia.Base/Compatibility/TrimmingAttributes.cs @@ -1,4 +1,6 @@ -#pragma warning disable MA0048 // File name must match type name +#nullable enable + +#pragma warning disable MA0048 // File name must match type name // https://github.com/dotnet/runtime/tree/main/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis // Licensed to the .NET Foundation under one or more agreements. diff --git a/src/Avalonia.Base/Platform/RenderTargetProperties.cs b/src/Avalonia.Base/Platform/RenderTargetProperties.cs index 33b117ff1e6..c4a09481801 100644 --- a/src/Avalonia.Base/Platform/RenderTargetProperties.cs +++ b/src/Avalonia.Base/Platform/RenderTargetProperties.cs @@ -1,8 +1,10 @@ +using System.Diagnostics.CodeAnalysis; using Avalonia.Metadata; namespace Avalonia.Platform; [PrivateApi] +[SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Private API, not meant to be compared")] public struct RenderTargetProperties { /// @@ -21,10 +23,11 @@ public struct RenderTargetProperties } [PrivateApi] +[SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Private API, not meant to be compared")] public struct RenderTargetDrawingContextProperties { /// /// Indicates that the drawing context targets a surface that preserved its contents since the previous frame /// public bool PreviousFrameIsRetained { get; init; } -} \ No newline at end of file +} diff --git a/src/Avalonia.Base/PropertyStore/ValueStore.cs b/src/Avalonia.Base/PropertyStore/ValueStore.cs index e443a11781d..67d176eceac 100644 --- a/src/Avalonia.Base/PropertyStore/ValueStore.cs +++ b/src/Avalonia.Base/PropertyStore/ValueStore.cs @@ -468,7 +468,6 @@ public void SetInheritanceParent(AvaloniaObject? newParent) /// /// The binding entry. /// The priority of binding which produced a new value. - [Obsolete("TODO: Remove?")] public void OnBindingValueChanged( IValueEntry entry, BindingPriority priority) @@ -592,7 +591,6 @@ public void OnInheritedEffectiveValueDisposed(StyledProperty property, T o /// /// The previously bound property. /// The observer. - [Obsolete("TODO: Remove?")] public void OnLocalValueBindingCompleted(AvaloniaProperty property, IDisposable observer) { if (_localValueBindings is not null && diff --git a/src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs b/src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs index 75dc13b1e0c..f4124c22f07 100644 --- a/src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs +++ b/src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs @@ -10,9 +10,6 @@ namespace Avalonia.Rendering.Composition.Server; -/// - -/// internal partial class CompositorDrawingContextProxy : IDrawingContextImpl, IDrawingContextWithAcrylicLikeSupport, IDrawingContextImplWithEffects { diff --git a/src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs b/src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs index e6af805b4f3..f7e95b83d08 100644 --- a/src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs +++ b/src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs @@ -21,7 +21,7 @@ internal class DBusTrayIconImpl : ITrayIconImpl private readonly OrgFreedesktopDBus? _dBus; private IDisposable? _serviceWatchDisposable; - private StatusNotifierItemDbusObj? _statusNotifierItemDbusObj; + private readonly StatusNotifierItemDbusObj? _statusNotifierItemDbusObj; private OrgKdeStatusNotifierWatcher? _statusNotifierWatcher; private (int, int, byte[]) _icon; @@ -115,7 +115,7 @@ private async void CreateTrayIcon() await _dBus!.RequestNameAsync(_sysTrayServiceName, 0); await _statusNotifierWatcher.RegisterStatusNotifierItemAsync(_sysTrayServiceName); - _statusNotifierItemDbusObj.SetTitleAndTooltip(_tooltipText); + _statusNotifierItemDbusObj!.SetTitleAndTooltip(_tooltipText); _statusNotifierItemDbusObj.SetIcon(_icon); _statusNotifierItemDbusObj.ActivationDelegate += OnClicked; } diff --git a/src/Avalonia.Vulkan/Avalonia.Vulkan.csproj b/src/Avalonia.Vulkan/Avalonia.Vulkan.csproj index 94f6e5eebda..59b8e62708d 100644 --- a/src/Avalonia.Vulkan/Avalonia.Vulkan.csproj +++ b/src/Avalonia.Vulkan/Avalonia.Vulkan.csproj @@ -14,4 +14,9 @@ + + + + + diff --git a/src/Avalonia.Vulkan/VulkanImageInfo.cs b/src/Avalonia.Vulkan/VulkanImageInfo.cs index 5dbbecd5728..171ee65a6bb 100644 --- a/src/Avalonia.Vulkan/VulkanImageInfo.cs +++ b/src/Avalonia.Vulkan/VulkanImageInfo.cs @@ -1,8 +1,6 @@ -using System; - namespace Avalonia.Vulkan; -public struct VulkanImageInfo +public record struct VulkanImageInfo { public uint Format { get; set; } public PixelSize PixelSize { get; set; } @@ -16,4 +14,4 @@ public struct VulkanImageInfo public ulong ViewHandle { get; set; } public ulong MemorySize { get; set; } public bool IsProtected { get; set; } -} \ No newline at end of file +} diff --git a/src/Avalonia.X11/Vulkan/VulkanSupport.cs b/src/Avalonia.X11/Vulkan/VulkanSupport.cs index 860e9139543..5139d78880f 100644 --- a/src/Avalonia.X11/Vulkan/VulkanSupport.cs +++ b/src/Avalonia.X11/Vulkan/VulkanSupport.cs @@ -1,3 +1,5 @@ +#nullable enable + using System; using System.Collections.Generic; using System.Runtime.InteropServices; @@ -13,7 +15,7 @@ internal class VulkanSupport [DllImport("libvulkan.so.1")] private static extern IntPtr vkGetInstanceProcAddr(IntPtr instance, string name); - public static VulkanPlatformGraphics? TryInitialize(X11Info info, VulkanOptions options) + public static VulkanPlatformGraphics? TryInitialize(X11Info info, VulkanOptions? options) { s_offscreenWindow = XLib.XCreateSimpleWindow(info.DeferredDisplay, XLib.XDefaultRootWindow(info.DeferredDisplay), 0, 0, 1, diff --git a/src/Avalonia.X11/X11FramebufferSurface.cs b/src/Avalonia.X11/X11FramebufferSurface.cs index 5b878673d4f..f3cfc2ae908 100644 --- a/src/Avalonia.X11/X11FramebufferSurface.cs +++ b/src/Avalonia.X11/X11FramebufferSurface.cs @@ -1,3 +1,5 @@ +#nullable enable + using System; using Avalonia.Controls.Platform.Surfaces; using Avalonia.Platform; @@ -65,7 +67,7 @@ public ILockedFramebuffer Lock(out FramebufferLockProperties properties) } properties = new FramebufferLockProperties(framebufferValid); - return _fb.Lock(new Vector(96, 96), Blit); + return _fb!.Lock(new Vector(96, 96), Blit); } public IFramebufferRenderTarget CreateFramebufferRenderTarget() diff --git a/src/Browser/Avalonia.Browser/Rendering/RenderWorker.cs b/src/Browser/Avalonia.Browser/Rendering/RenderWorker.cs index 0a46b37ec14..4ddd1b90884 100644 --- a/src/Browser/Avalonia.Browser/Rendering/RenderWorker.cs +++ b/src/Browser/Avalonia.Browser/Rendering/RenderWorker.cs @@ -101,7 +101,9 @@ public static Task RunAsync(Func run) Name = "Manual JS worker" }; _setExtLoop.Invoke(null, [th]); +#pragma warning disable CA1416 th.Start(); +#pragma warning restore CA1416 return tcs.Task; } @@ -137,4 +139,4 @@ static JSWebWorkerWrapper() public static Func, Task> RunAsync { get; set; } } -} \ No newline at end of file +} diff --git a/src/Browser/Avalonia.Browser/build/Avalonia.Browser.targets b/src/Browser/Avalonia.Browser/build/Avalonia.Browser.targets index fe66c02dd86..4ada399979c 100644 --- a/src/Browser/Avalonia.Browser/build/Avalonia.Browser.targets +++ b/src/Browser/Avalonia.Browser/build/Avalonia.Browser.targets @@ -6,7 +6,7 @@ - + diff --git a/src/Linux/Avalonia.LinuxFramebuffer/Input/LibInput/LibInputBackend.cs b/src/Linux/Avalonia.LinuxFramebuffer/Input/LibInput/LibInputBackend.cs index 91e33526d0c..d21f4f436e1 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/Input/LibInput/LibInputBackend.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/Input/LibInput/LibInputBackend.cs @@ -51,7 +51,7 @@ private unsafe void InputThread(IntPtr ctx, LibInputBackendOptions options) libinput_dispatch(ctx); } - pollfd pfd = new pollfd { fd = fd, events = 1 }; + var pfd = new PollFd { fd = fd, events = 1 }; NativeUnsafeMethods.poll(&pfd, new IntPtr(1), 10); } } diff --git a/src/Linux/Avalonia.LinuxFramebuffer/NativeUnsafeMethods.cs b/src/Linux/Avalonia.LinuxFramebuffer/NativeUnsafeMethods.cs index f71d4e97539..f6aeb3e6f4d 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/NativeUnsafeMethods.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/NativeUnsafeMethods.cs @@ -35,7 +35,7 @@ unsafe class NativeUnsafeMethods [DllImport("libc", EntryPoint = "poll", SetLastError = true)] - public static extern int poll(pollfd* fds, IntPtr nfds, int timeout); + public static extern int poll(PollFd* fds, IntPtr nfds, int timeout); [DllImport("libevdev.so.2", EntryPoint = "libevdev_new_from_fd", SetLastError = true)] public static extern int libevdev_new_from_fd(int fd, out IntPtr dev); @@ -66,7 +66,7 @@ unsafe class NativeUnsafeMethods } [StructLayout(LayoutKind.Sequential)] - struct pollfd { + struct PollFd { public int fd; /* file descriptor */ public short events; /* requested events */ public short revents; /* returned events */ diff --git a/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs b/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs index 72036fcabce..1cf3e41099f 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs @@ -311,7 +311,7 @@ public void Dispose() }; while (waitingForFlip) { - var pfd = new pollfd {events = 1, fd = _parent._card.Fd}; + var pfd = new PollFd {events = 1, fd = _parent._card.Fd}; poll(&pfd, new IntPtr(1), -1); drmHandleEvent(_parent._card.Fd, &ctx); } diff --git a/src/Linux/Avalonia.LinuxFramebuffer/Output/FbDevBackBuffer.cs b/src/Linux/Avalonia.LinuxFramebuffer/Output/FbDevBackBuffer.cs index e3729ddb8ba..b1e125f247d 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/Output/FbDevBackBuffer.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/Output/FbDevBackBuffer.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.Runtime.InteropServices; using System.Threading; using Avalonia.Platform; diff --git a/src/Linux/Avalonia.LinuxFramebuffer/Output/FbDevOutputOptions.cs b/src/Linux/Avalonia.LinuxFramebuffer/Output/FbDevOutputOptions.cs index cdf39614d16..8336362213e 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/Output/FbDevOutputOptions.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/Output/FbDevOutputOptions.cs @@ -1,3 +1,5 @@ +#nullable enable + using Avalonia.Platform; namespace Avalonia.LinuxFramebuffer.Output; @@ -9,12 +11,14 @@ public class FbDevOutputOptions /// Defaults to the value in environment variable FRAMEBUFFER or /dev/fb0 when FRAMEBUFFER is not set /// public string? FileName { get; set; } + /// /// The required pixel format for the frame buffer. /// A null value will leave the frame buffer in the current pixel format. /// Otherwise sets the frame buffer to the required format /// public PixelFormat? PixelFormat { get; set; } + /// /// If set to true, double-buffering will be disabled and scene will be composed directly into mmap-ed memory region /// While this mode saves a blit, you need to check if it won't cause rendering artifacts your particular device. @@ -25,4 +29,4 @@ public class FbDevOutputOptions /// The initial scale factor to use /// public double Scaling { get; set; } = 1; -} \ No newline at end of file +} diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/IncludeXamlIlSre.props b/src/Markup/Avalonia.Markup.Xaml.Loader/IncludeXamlIlSre.props index 173af923cbf..2b841545530 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/IncludeXamlIlSre.props +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/IncludeXamlIlSre.props @@ -9,15 +9,8 @@ + - - - - - - - - diff --git a/src/tools/Avalonia.Designer.HostApp/Avalonia.Designer.HostApp.csproj b/src/tools/Avalonia.Designer.HostApp/Avalonia.Designer.HostApp.csproj index e68eddc7fd6..c0daef63a08 100644 --- a/src/tools/Avalonia.Designer.HostApp/Avalonia.Designer.HostApp.csproj +++ b/src/tools/Avalonia.Designer.HostApp/Avalonia.Designer.HostApp.csproj @@ -14,6 +14,9 @@ + + + diff --git a/tests/Avalonia.RenderTests.WpfCompare/CrossTestBase.cs b/tests/Avalonia.RenderTests.WpfCompare/CrossTestBase.cs index e7d6b27213f..eefc4f1bd5e 100644 --- a/tests/Avalonia.RenderTests.WpfCompare/CrossTestBase.cs +++ b/tests/Avalonia.RenderTests.WpfCompare/CrossTestBase.cs @@ -44,7 +44,7 @@ static string GetTestsDirectory() while (path.Length > 0 && Path.GetFileName(path) != "tests") { - path = Path.GetDirectoryName(path); + path = Path.GetDirectoryName(path)!; } return path; diff --git a/tests/Avalonia.RenderTests.WpfCompare/CrossUI.Wpf.cs b/tests/Avalonia.RenderTests.WpfCompare/CrossUI.Wpf.cs index 302f7f695c2..3ed994ca8ee 100644 --- a/tests/Avalonia.RenderTests.WpfCompare/CrossUI.Wpf.cs +++ b/tests/Avalonia.RenderTests.WpfCompare/CrossUI.Wpf.cs @@ -266,13 +266,15 @@ static Brush SyncGradient(GradientBrush dst, CrossGradientBrush src) { PenLineCap.Flat => WPenLineCap.Flat, PenLineCap.Round => WPenLineCap.Round, - PenLineCap.Square => WPenLineCap.Square + PenLineCap.Square => WPenLineCap.Square, + _ => throw new InvalidOperationException() }; var join = pen.LineJoin switch { PenLineJoin.Bevel => WPenLineJoin.Bevel, PenLineJoin.Miter => WPenLineJoin.Miter, - PenLineJoin.Round => WPenLineJoin.Round + PenLineJoin.Round => WPenLineJoin.Round, + _ => throw new InvalidOperationException() }; return new Pen(ConvertBrush(pen.Brush), pen.Thickness) diff --git a/tests/Avalonia.RenderTests/CrossTests/CrossGeometryTests.cs b/tests/Avalonia.RenderTests/CrossTests/CrossGeometryTests.cs index a5492328e6f..0fdd2fc0d90 100644 --- a/tests/Avalonia.RenderTests/CrossTests/CrossGeometryTests.cs +++ b/tests/Avalonia.RenderTests/CrossTests/CrossGeometryTests.cs @@ -120,7 +120,6 @@ public void Should_Render_Geometry_With_Strokeless_Lines() InlineData(PenLineCap.Round, PenLineJoin.Bevel), InlineData(PenLineCap.Round, PenLineJoin.Miter), ] -#endif public void Should_Properly_CloseFigure(PenLineCap lineCap, PenLineJoin lineJoin) { var geometry = new CrossPathGeometry(); @@ -156,4 +155,5 @@ public void Should_Properly_CloseFigure(PenLineCap lineCap, PenLineJoin lineJoin RenderAndCompare(control, $"{nameof(Should_Properly_CloseFigure)}_{lineCap}_{lineJoin}"); } +#endif } diff --git a/tests/Avalonia.RenderTests/CrossUI/CrossUI.Avalonia.cs b/tests/Avalonia.RenderTests/CrossUI/CrossUI.Avalonia.cs index 8ac89dc220c..168aeeb096e 100644 --- a/tests/Avalonia.RenderTests/CrossUI/CrossUI.Avalonia.cs +++ b/tests/Avalonia.RenderTests/CrossUI/CrossUI.Avalonia.cs @@ -200,7 +200,8 @@ s switch Point1 = q.Point1, Point2 = q.Point2, IsStroked = q.IsStroked - } + }, + _ => throw new InvalidOperationException() })) })) }; diff --git a/tests/Avalonia.RenderTests/CrossUI/CrossUI.cs b/tests/Avalonia.RenderTests/CrossUI/CrossUI.cs index 3710123eaf6..13a3a3029c4 100644 --- a/tests/Avalonia.RenderTests/CrossUI/CrossUI.cs +++ b/tests/Avalonia.RenderTests/CrossUI/CrossUI.cs @@ -162,13 +162,13 @@ public record QuadraticBezier(Point Point1, Point Point2, bool IsStroked) : Cros public class CrossDrawingBrush : CrossTileBrush { - public CrossDrawing Drawing; + public required CrossDrawing Drawing { get; set; } } public class CrossPen { - public CrossBrush Brush; - public double Thickness = 1; + public required CrossBrush Brush { get; set; } + public double Thickness { get; set; } = 1; public PenLineJoin LineJoin { get; set; } = PenLineJoin.Miter; public PenLineCap LineCap { get; set; } = PenLineCap.Flat; } @@ -212,7 +212,7 @@ public CrossBitmapImage(string path) public class CrossDrawingImage : CrossImage { - public CrossDrawing Drawing; + public required CrossDrawing Drawing { get; set; } } @@ -251,12 +251,14 @@ public override void Render(ICrossDrawingContext ctx) public class CrossImageControl : CrossControl { - public CrossImage Image; + public required CrossImage Image { get; set; } + public override void Render(ICrossDrawingContext ctx) { base.Render(ctx); var rc = new Rect(Bounds.Size); - ctx.DrawImage(Image, rc); + var image = Image; + ctx.DrawImage(image, rc); } } diff --git a/tests/Avalonia.Skia.RenderTests/CrossTestBase.cs b/tests/Avalonia.Skia.RenderTests/CrossTestBase.cs index a94736b0c79..776fe36b520 100644 --- a/tests/Avalonia.Skia.RenderTests/CrossTestBase.cs +++ b/tests/Avalonia.Skia.RenderTests/CrossTestBase.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.IO; using System.Runtime.CompilerServices; using Avalonia.Skia.RenderTests; @@ -35,6 +37,8 @@ public CrossTestBase(string groupName) protected void RenderAndCompare(CrossControl root, [CallerMemberName] string? testName = null, double dpi = 96) { + ArgumentException.ThrowIfNullOrEmpty(testName, nameof(testName)); + var dir = Path.Combine(TestRenderHelper.GetTestsDirectory(), "TestFiles", "CrossTests", _groupName); if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);