Skip to content

Commit

Permalink
Update to Avalonia@54d18061 (Jun 30 2023)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Jul 12, 2023
1 parent 431ae30 commit 33ae479
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public static class AvaloniaNativePlatformExtensions
{
//public static AppBuilder UseAvaloniaNative(this AppBuilder builder)
//{
// builder.UseWindowingSubsystem(() =>
// builder
// .UseStandardRuntimePlatformSubsystem()
// .UseWindowingSubsystem(() =>
// {
// var platform = AvaloniaNativePlatform.Initialize(
// AvaloniaLocator.Current.GetService<AvaloniaNativePlatformOptions>() ??
Expand All @@ -28,7 +30,7 @@ public static class AvaloniaNativePlatformExtensions

public enum AvaloniaNativeRenderingMode
{
/// </summary>
/// <summary>
/// Avalonia would try to use native OpenGL with GPU rendering.
/// </summary>
OpenGl = 1,
Expand All @@ -43,7 +45,7 @@ public enum AvaloniaNativeRenderingMode
Metal = 3
}

/// <summary>
/// </summary>
/// OSX backend options.
/// </summary>
public class AvaloniaNativePlatformOptions
Expand Down
20 changes: 6 additions & 14 deletions src/Modern.WindowKit/Avalonia.Skia/WriteableBitmapImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading;
using Modern.WindowKit.Media.Imaging;
using Modern.WindowKit.Platform;
using Modern.WindowKit.Platform.Internal;
using Modern.WindowKit.Skia.Helpers;
using SkiaSharp;

Expand Down Expand Up @@ -97,21 +98,12 @@ public WriteableBitmapImpl(PixelSize size, Vector dpi, PixelFormat format, Alpha
SKColorType colorType = format.ToSkColorType();
SKAlphaType alphaType = alphaFormat.ToSkAlphaType();

var runtimePlatform = AvaloniaGlobals.GetService<IRuntimePlatform>();
_bitmap = new SKBitmap();

if (runtimePlatform != null)
{
_bitmap = new SKBitmap();

var nfo = new SKImageInfo(size.Width, size.Height, colorType, alphaType);
var blob = runtimePlatform.AllocBlob(nfo.BytesSize);
var nfo = new SKImageInfo(size.Width, size.Height, colorType, alphaType);
var blob = new UnmanagedBlob(nfo.BytesSize);

_bitmap.InstallPixels(nfo, blob.Address, nfo.RowBytes, s_releaseDelegate, blob);
}
else
{
_bitmap = new SKBitmap(size.Width, size.Height, colorType, alphaType);
}
_bitmap.InstallPixels(nfo, blob.Address, nfo.RowBytes, s_releaseDelegate, blob);

_bitmap.Erase(SKColor.Empty);
}
Expand Down Expand Up @@ -176,7 +168,7 @@ public SKImage GetSnapshot()
/// <param name="ctx">Blob.</param>
private static void ReleaseProc(IntPtr address, object ctx)
{
((IUnmanagedBlob)ctx).Dispose();
((UnmanagedBlob)ctx).Dispose();
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/Modern.WindowKit/Avalonia.Win32/FramebufferManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading;
using Modern.WindowKit.Controls.Platform.Surfaces;
using Modern.WindowKit.Platform;
using Modern.WindowKit.Platform.Internal;
using Modern.WindowKit.Win32.Interop;

namespace Modern.WindowKit.Win32
Expand Down Expand Up @@ -107,8 +108,7 @@ private Vector GetCurrentDpi()

private static FramebufferData AllocateFramebufferData(int width, int height)
{
var service = AvaloniaGlobals.GetRequiredService<IRuntimePlatform>();
var bitmapBlob = service.AllocBlob(width * height * _bytesPerPixel);
var bitmapBlob = new UnmanagedBlob(width * height * _bytesPerPixel);

return new FramebufferData(bitmapBlob, width, height);
}
Expand Down Expand Up @@ -157,15 +157,15 @@ private static bool DrawToWindow(IntPtr hWnd, FramebufferData framebufferData, i

private readonly struct FramebufferData
{
public IUnmanagedBlob Data { get; }
public UnmanagedBlob Data { get; }

public PixelSize Size { get; }

public int RowBytes => Size.Width * _bytesPerPixel;

public UnmanagedMethods.BITMAPINFOHEADER Header { get; }

public FramebufferData(IUnmanagedBlob data, int width, int height)
public FramebufferData(UnmanagedBlob data, int width, int height)
{
Data = data;
Size = new PixelSize(width, height);
Expand Down
10 changes: 6 additions & 4 deletions src/Modern.WindowKit/Avalonia.Win32/Win32Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ namespace Modern.WindowKit
//{
// public static AppBuilder UseWin32(this AppBuilder builder)
// {
// return builder.UseWindowingSubsystem(
// () => Win32.Win32Platform.Initialize(
// AvaloniaLocator.Current.GetService<Win32PlatformOptions>() ?? new Win32PlatformOptions()),
// "Win32");
// return builder
// .UseStandardRuntimePlatformSubsystem()
// .UseWindowingSubsystem(
// () => Win32.Win32Platform.Initialize(
// AvaloniaLocator.Current.GetService<Win32PlatformOptions>() ?? new Win32PlatformOptions()),
// "Win32");
// }
//}
}
Expand Down
102 changes: 0 additions & 102 deletions src/Modern.WindowKit/Avalonia.Win32/WindowFramebuffer.cs

This file was deleted.

10 changes: 5 additions & 5 deletions src/Modern.WindowKit/Avalonia.X11/X11CursorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Modern.WindowKit.Controls.Platform.Surfaces;
using Modern.WindowKit.Input;
using Modern.WindowKit.Platform;
using Modern.WindowKit.Platform.Internal;
//using Modern.WindowKit.SourceGenerator;
using Modern.WindowKit.Utilities;

Expand Down Expand Up @@ -92,18 +93,17 @@ private static IntPtr GetNullCursor(IntPtr display)
//private unsafe class XImageCursor : CursorImpl, IFramebufferPlatformSurface, IPlatformHandle
//{
// private readonly PixelSize _pixelSize;
// private readonly IUnmanagedBlob _blob;
// private readonly UnmanagedBlob _blob;

// public XImageCursor(IntPtr display, IBitmapImpl bitmap, PixelPoint hotSpot)
// {
// var size = Marshal.SizeOf<XcursorImage>() +
// (bitmap.PixelSize.Width * bitmap.PixelSize.Height * 4);
// var runtimePlatform = AvaloniaGlobals.GetRequiredService<IRuntimePlatform>();
// var platformRenderInterface = AvaloniaLocator.Current.GetRequiredService<IPlatformRenderInterface>();

// _pixelSize = bitmap.PixelSize;
// _blob = runtimePlatform.AllocBlob(size);

// _blob = new UnmanagedBlob(size);
// var image = (XcursorImage*)_blob.Address;
// image->version = 1;
// image->size = Marshal.SizeOf<XcursorImage>();
Expand All @@ -117,7 +117,7 @@ private static IntPtr GetNullCursor(IntPtr display)
// using (var renderTarget = cpuContext.CreateRenderTarget(new[] { this }))
// using (var ctx = renderTarget.CreateDrawingContext())
// {
// var r = new Rect(_pixelSize.ToSize(1));
// var r = new Rect(_pixelSize.ToSize(1));
// ctx.DrawBitmap(bitmap, 1, r, r);
// }

Expand Down
5 changes: 3 additions & 2 deletions src/Modern.WindowKit/Avalonia.X11/X11Framebuffer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using Modern.WindowKit.Platform;
using Modern.WindowKit.Platform.Internal;
using SkiaSharp;
using static Modern.WindowKit.X11.XLib;
namespace Modern.WindowKit.X11
Expand All @@ -10,7 +11,7 @@ internal class X11Framebuffer : ILockedFramebuffer
private readonly IntPtr _display;
private readonly IntPtr _xid;
private readonly int _depth;
private IUnmanagedBlob _blob;
private UnmanagedBlob _blob;

public X11Framebuffer(IntPtr display, IntPtr xid, int depth, int width, int height, double factor)
{
Expand All @@ -25,7 +26,7 @@ public X11Framebuffer(IntPtr display, IntPtr xid, int depth, int width, int heig
RowBytes = width * 4;
Dpi = new Vector(96, 96) * factor;
Format = PixelFormat.Bgra8888;
_blob = AvaloniaGlobals.GetRequiredService<IRuntimePlatform>().AllocBlob(RowBytes * height);
_blob = new UnmanagedBlob(RowBytes * height);
Address = _blob.Address;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Modern.WindowKit/Avalonia.X11/X11Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ public static class AvaloniaX11PlatformExtensions
{
//public static AppBuilder UseX11(this AppBuilder builder)
//{
// builder.UseWindowingSubsystem(() =>
// builder
// .UseStandardRuntimePlatformSubsystem()
// .UseWindowingSubsystem(() =>
// new AvaloniaX11Platform().Initialize(AvaloniaLocator.Current.GetService<X11PlatformOptions>() ??
// new X11PlatformOptions()));
// return builder;
Expand All @@ -353,5 +355,4 @@ public static class AvaloniaX11PlatformExtensions
public static void InitializeX11Platform(X11PlatformOptions options = null) =>

Check warning on line 355 in src/Modern.WindowKit/Avalonia.X11/X11Platform.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Cannot convert null literal to non-nullable reference type.
new AvaloniaX11Platform().Initialize(options ?? new X11PlatformOptions());
}

}
16 changes: 2 additions & 14 deletions src/Modern.WindowKit/IRuntimePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,13 @@

namespace Modern.WindowKit.Platform
{
[Unstable]
[PrivateApi]
public interface IRuntimePlatform
{
IDisposable StartSystemTimer(TimeSpan interval, Action tick);
RuntimePlatformInfo GetRuntimeInfo();
IUnmanagedBlob AllocBlob(int size);
}

[Unstable]
public interface IUnmanagedBlob : IDisposable
{
IntPtr Address { get; }
int Size { get; }
bool IsDisposed { get; }

}

[Unstable]
[PrivateApi]
public record struct RuntimePlatformInfo
{
public FormFactorType FormFactor => IsDesktop ? FormFactorType.Desktop :
Expand All @@ -29,7 +18,6 @@ public record struct RuntimePlatformInfo
public bool IsMobile { get; set; }
}

[Unstable]
public enum FormFactorType
{
Unknown,
Expand Down
12 changes: 3 additions & 9 deletions src/Modern.WindowKit/StandardRuntimePlatform.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
using System;
using System.Threading;
using Modern.WindowKit.Compatibility;
using Modern.WindowKit.Metadata;
using Modern.WindowKit.Platform.Internal;

namespace Modern.WindowKit.Platform
{
[PrivateApi]
internal class StandardRuntimePlatform : IRuntimePlatform
{
public IDisposable StartSystemTimer(TimeSpan interval, Action tick)
{
return new Timer(_ => tick(), null, interval, interval);
}

public IUnmanagedBlob AllocBlob(int size) => new UnmanagedBlob(size);

private static readonly RuntimePlatformInfo s_info = new()
{
IsDesktop = OperatingSystemEx.IsWindows() || OperatingSystemEx.IsMacOS() || OperatingSystemEx.IsLinux(),
IsMobile = OperatingSystemEx.IsAndroid() || OperatingSystemEx.IsIOS()
};



public virtual RuntimePlatformInfo GetRuntimeInfo() => s_info;
}
}
2 changes: 1 addition & 1 deletion src/Modern.WindowKit/UnmanagedBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Modern.WindowKit.Platform.Internal;

internal class UnmanagedBlob : IUnmanagedBlob
internal class UnmanagedBlob
{
private IntPtr _address;
private readonly object _lock = new object();
Expand Down

0 comments on commit 33ae479

Please sign in to comment.