Browse Source

Merge pull request #11572 from almightyju/vnc-colour

Fix headless vnc colour format
pull/11583/head
Max Katz 3 years ago
committed by GitHub
parent
commit
9ee73d1c5a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/Headless/Avalonia.Headless.Vnc/HeadlessVncPlatformExtensions.cs
  2. 12
      src/Headless/Avalonia.Headless/AvaloniaHeadlessPlatform.cs
  3. 6
      src/Headless/Avalonia.Headless/HeadlessWindowImpl.cs

4
src/Headless/Avalonia.Headless.Vnc/HeadlessVncPlatformExtensions.cs

@ -5,6 +5,7 @@ using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Headless;
using Avalonia.Headless.Vnc;
using Avalonia.Platform;
using RemoteViewing.Vnc;
using RemoteViewing.Vnc.Server;
@ -22,7 +23,8 @@ namespace Avalonia
return builder
.UseHeadless(new AvaloniaHeadlessPlatformOptions
{
UseHeadlessDrawing = false
UseHeadlessDrawing = false,
FrameBufferFormat = PixelFormat.Bgra8888
})
.AfterSetup(_ =>
{

12
src/Headless/Avalonia.Headless/AvaloniaHeadlessPlatform.cs

@ -51,11 +51,16 @@ namespace Avalonia.Headless
private class HeadlessWindowingPlatform : IWindowingPlatform
{
public IWindowImpl CreateWindow() => new HeadlessWindowImpl(false);
readonly PixelFormat _frameBufferFormat;
public HeadlessWindowingPlatform(PixelFormat frameBufferFormat)
{
_frameBufferFormat = frameBufferFormat;
}
public IWindowImpl CreateWindow() => new HeadlessWindowImpl(false, _frameBufferFormat);
public IWindowImpl CreateEmbeddableWindow() => throw new PlatformNotSupportedException();
public IPopupImpl CreatePopup() => new HeadlessWindowImpl(true);
public IPopupImpl CreatePopup() => new HeadlessWindowImpl(true, _frameBufferFormat);
public ITrayIconImpl? CreateTrayIcon() => null;
}
@ -70,7 +75,7 @@ namespace Avalonia.Headless
.Bind<IPlatformIconLoader>().ToSingleton<HeadlessIconLoaderStub>()
.Bind<IKeyboardDevice>().ToConstant(new KeyboardDevice())
.Bind<IRenderTimer>().ToConstant(new RenderTimer(60))
.Bind<IWindowingPlatform>().ToConstant(new HeadlessWindowingPlatform())
.Bind<IWindowingPlatform>().ToConstant(new HeadlessWindowingPlatform(opts.FrameBufferFormat))
.Bind<PlatformHotkeyConfiguration>().ToSingleton<PlatformHotkeyConfiguration>();
Compositor = new Compositor( null);
}
@ -92,6 +97,7 @@ namespace Avalonia.Headless
public class AvaloniaHeadlessPlatformOptions
{
public bool UseHeadlessDrawing { get; set; } = true;
public PixelFormat FrameBufferFormat { get; set; } = PixelFormat.Rgba8888;
}
public static class AvaloniaHeadlessPlatformExtensions

6
src/Headless/Avalonia.Headless/HeadlessWindowImpl.cs

@ -24,9 +24,10 @@ namespace Avalonia.Headless
private readonly Pointer _mousePointer;
private WriteableBitmap? _lastRenderedFrame;
private readonly object _sync = new object();
private readonly PixelFormat _frameBufferFormat;
public bool IsPopup { get; }
public HeadlessWindowImpl(bool isPopup)
public HeadlessWindowImpl(bool isPopup, PixelFormat frameBufferFormat)
{
IsPopup = isPopup;
Surfaces = new object[] { this };
@ -34,6 +35,7 @@ namespace Avalonia.Headless
_mousePointer = new Pointer(Pointer.GetNextFreeId(), PointerType.Mouse, true);
MouseDevice = new MouseDevice(_mousePointer);
ClientSize = new Size(1024, 768);
_frameBufferFormat = frameBufferFormat;
}
public void Dispose()
@ -201,7 +203,7 @@ namespace Avalonia.Headless
public ILockedFramebuffer Lock()
{
var bmp = new WriteableBitmap(PixelSize.FromSize(ClientSize, RenderScaling), new Vector(96, 96) * RenderScaling, PixelFormat.Rgba8888, AlphaFormat.Premul);
var bmp = new WriteableBitmap(PixelSize.FromSize(ClientSize, RenderScaling), new Vector(96, 96) * RenderScaling, _frameBufferFormat, AlphaFormat.Premul);
var fb = bmp.Lock();
return new FramebufferProxy(fb, () =>
{

Loading…
Cancel
Save