From afd351982d485a88d080adecdefe3287079dfeac Mon Sep 17 00:00:00 2001 From: rmbagme Date: Thu, 2 Mar 2023 17:33:42 +0800 Subject: [PATCH] avalonia 11.0.0-preview5 --- .../ClassicDesktopStyleApplicationLifetime.cs | 2 +- .../IFontManagerImpl2.cs | 6 ++--- .../ImmutableBitmap.cs | 22 +++++++++++++++---- .../PlatformRenderInterface.cs | 4 ++-- src/Avalonia.Skia.Internals/SkiaPlatform2.cs | 3 +-- .../SkiaSharpHelpers.cs | 1 - .../Helpers/NotifyIconHelper.cs | 1 - src/BD.WTTS.Client.Avalonia.App/UI/App.axaml | 1 - src/ImplicitUsings.Avalonia.cs | 2 -- 9 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/Avalonia.Skia.Internals/ClassicDesktopStyleApplicationLifetime.cs b/src/Avalonia.Skia.Internals/ClassicDesktopStyleApplicationLifetime.cs index c817d0176..1a14b1da9 100644 --- a/src/Avalonia.Skia.Internals/ClassicDesktopStyleApplicationLifetime.cs +++ b/src/Avalonia.Skia.Internals/ClassicDesktopStyleApplicationLifetime.cs @@ -200,7 +200,7 @@ namespace Avalonia { public static int StartWithClassicDesktopLifetime2( this T builder, string[] args, ShutdownMode shutdownMode = ShutdownMode.OnLastWindowClose) - where T : AppBuilderBase, new() + where T : AppBuilder, new() { var lifetime = new ClassicDesktopStyleApplicationLifetime2() { diff --git a/src/Avalonia.Skia.Internals/IFontManagerImpl2.cs b/src/Avalonia.Skia.Internals/IFontManagerImpl2.cs index c1f4d8384..59a9855df 100644 --- a/src/Avalonia.Skia.Internals/IFontManagerImpl2.cs +++ b/src/Avalonia.Skia.Internals/IFontManagerImpl2.cs @@ -22,12 +22,12 @@ public interface IFontManagerImpl2 : IFontManagerImpl return Impl.GetInstalledFontFamilyNames(checkForUpdates); } - bool IFontManagerImpl.TryMatchCharacter(int codepoint, FontStyle fontStyle, FontWeight fontWeight, FontFamily fontFamily, CultureInfo culture, out Typeface typeface) + bool IFontManagerImpl.TryMatchCharacter(int codepoint, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch, FontFamily fontFamily, CultureInfo culture, out Typeface typeface) { - return Impl.TryMatchCharacter(codepoint, fontStyle, fontWeight, fontFamily, culture, out typeface); + return Impl.TryMatchCharacter(codepoint, fontStyle, fontWeight, fontStretch, fontFamily, culture, out typeface); } - IGlyphTypefaceImpl IFontManagerImpl.CreateGlyphTypeface(Typeface typeface) + IGlyphTypeface IFontManagerImpl.CreateGlyphTypeface(Typeface typeface) { typeface = OnCreateGlyphTypeface(typeface); return Impl.CreateGlyphTypeface(typeface); diff --git a/src/Avalonia.Skia.Internals/ImmutableBitmap.cs b/src/Avalonia.Skia.Internals/ImmutableBitmap.cs index f1150a34d..4a0d47f15 100644 --- a/src/Avalonia.Skia.Internals/ImmutableBitmap.cs +++ b/src/Avalonia.Skia.Internals/ImmutableBitmap.cs @@ -2,11 +2,12 @@ extern alias AvaloniaSkia; using Avalonia.Platform; using AvaloniaSkia::Avalonia.Skia.Helpers; -using Avalonia.Visuals.Media.Imaging; using SkiaSharp; using AvaloniaSkia::Avalonia.Skia; using DrawingContextImpl = AvaloniaSkia::Avalonia.Skia.DrawingContextImpl; using IDrawableBitmapImpl = AvaloniaSkia::Avalonia.Skia.IDrawableBitmapImpl; +using Avalonia.Media.Imaging; +using System.Drawing; // https://github.com/AvaloniaUI/Avalonia/blob/0.10.13/src/Skia/Avalonia.Skia/ImmutableBitmap.cs @@ -15,9 +16,10 @@ namespace Avalonia.Skia; /// /// Immutable Skia bitmap. /// -internal class ImmutableBitmap : IDrawableBitmapImpl +internal class ImmutableBitmap : IDrawableBitmapImpl, IReadableBitmapImpl { private readonly SKImage _image; + private readonly SKBitmap? _bitmap; public ImmutableBitmap(SKImage image) { @@ -165,13 +167,13 @@ internal class ImmutableBitmap : IDrawableBitmapImpl } /// - public void Save(string fileName) + public void Save(string fileName, int? quality = null) { ImageSavingHelper.SaveImage(_image, fileName); } /// - public void Save(Stream stream) + public void Save(Stream stream, int? quality = null) { ImageSavingHelper.SaveImage(_image, stream); } @@ -181,4 +183,16 @@ internal class ImmutableBitmap : IDrawableBitmapImpl { context.Canvas.DrawImage(_image, sourceRect, destRect, paint); } + + public PixelFormat? Format => _bitmap?.ColorType.ToAvalonia(); + public ILockedFramebuffer Lock() + { + if (_bitmap is null) + throw new NotSupportedException("A bitmap is needed for locking"); + + if (_bitmap.ColorType.ToAvalonia() is not { } format) + throw new NotSupportedException($"Unsupported format {_bitmap.ColorType}"); + + return new LockedFramebuffer(_bitmap.GetPixels(), PixelSize, _bitmap.RowBytes, Dpi, format, null); + } } \ No newline at end of file diff --git a/src/Avalonia.Skia.Internals/PlatformRenderInterface.cs b/src/Avalonia.Skia.Internals/PlatformRenderInterface.cs index 51e0ef0fb..5772298ab 100644 --- a/src/Avalonia.Skia.Internals/PlatformRenderInterface.cs +++ b/src/Avalonia.Skia.Internals/PlatformRenderInterface.cs @@ -1,7 +1,7 @@ extern alias AvaloniaSkia; +using Avalonia.Media.Imaging; using Avalonia.Platform; -using Avalonia.Visuals.Media.Imaging; using ISkiaGpu = AvaloniaSkia::Avalonia.Skia.ISkiaGpu; using @this = AvaloniaSkia::Avalonia.Skia.PlatformRenderInterface; @@ -11,7 +11,7 @@ namespace Avalonia.Skia; sealed class PlatformRenderInterface : @this, IPlatformRenderInterface { - public PlatformRenderInterface(ISkiaGpu? skiaGpu, long? maxResourceBytes = null) : base(skiaGpu, maxResourceBytes) + public PlatformRenderInterface(long? maxResourceBytes = null) : base(maxResourceBytes) { } diff --git a/src/Avalonia.Skia.Internals/SkiaPlatform2.cs b/src/Avalonia.Skia.Internals/SkiaPlatform2.cs index d78b17f1c..09e90333f 100644 --- a/src/Avalonia.Skia.Internals/SkiaPlatform2.cs +++ b/src/Avalonia.Skia.Internals/SkiaPlatform2.cs @@ -14,8 +14,7 @@ public static class SkiaPlatform2 static IPlatformRenderInterface GetPlatformRenderInterface() { var options = AvaloniaLocator.Current.GetService() ?? new(); - var customGpu = options.CustomGpuFactory?.Invoke(); - var renderInterface = new PlatformRenderInterface(customGpu, options.MaxGpuResourceSizeBytes); + var renderInterface = new PlatformRenderInterface(options.MaxGpuResourceSizeBytes); return renderInterface; } } diff --git a/src/Avalonia.Skia.Internals/SkiaSharpHelpers.cs b/src/Avalonia.Skia.Internals/SkiaSharpHelpers.cs index e8d00ab5b..ea1b52a0a 100644 --- a/src/Avalonia.Skia.Internals/SkiaSharpHelpers.cs +++ b/src/Avalonia.Skia.Internals/SkiaSharpHelpers.cs @@ -3,7 +3,6 @@ extern alias AvaloniaSkia; using SkiaSharp; using Avalonia.Media.Imaging; using Avalonia.Utilities; -using Avalonia.Visuals.Media.Imaging; namespace Avalonia.Skia; diff --git a/src/BD.WTTS.Client.Avalonia.App/Helpers/NotifyIconHelper.cs b/src/BD.WTTS.Client.Avalonia.App/Helpers/NotifyIconHelper.cs index 5736a33a8..29698dc33 100644 --- a/src/BD.WTTS.Client.Avalonia.App/Helpers/NotifyIconHelper.cs +++ b/src/BD.WTTS.Client.Avalonia.App/Helpers/NotifyIconHelper.cs @@ -1,4 +1,3 @@ -using Avalonia.Shared.PlatformSupport; #if WINDOWS using System.Windows; #endif diff --git a/src/BD.WTTS.Client.Avalonia.App/UI/App.axaml b/src/BD.WTTS.Client.Avalonia.App/UI/App.axaml index 464b37281..9507e8c06 100644 --- a/src/BD.WTTS.Client.Avalonia.App/UI/App.axaml +++ b/src/BD.WTTS.Client.Avalonia.App/UI/App.axaml @@ -3,6 +3,5 @@ xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> - diff --git a/src/ImplicitUsings.Avalonia.cs b/src/ImplicitUsings.Avalonia.cs index 56134f241..66c7d1e35 100644 --- a/src/ImplicitUsings.Avalonia.cs +++ b/src/ImplicitUsings.Avalonia.cs @@ -26,8 +26,6 @@ global using Avalonia.Media.Imaging; global using Avalonia.Media.Immutable; global using Avalonia.Threading; global using Avalonia.Visuals; -global using Avalonia.Visuals.Media; -global using Avalonia.Visuals.Media.Imaging; global using Avalonia.Styling; global using Avalonia.Input; #if _IMPORT_AVALONIA_GIF__