From 62bc60bee302d839e9b88774348af57da8fbc500 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Tue, 6 Aug 2019 22:14:22 +0300 Subject: [PATCH] [DirectFB] Added configurable scaling support --- samples/ControlCatalog.NetCore/Program.cs | 14 ++++++++++++-- .../FramebufferToplevelImpl.cs | 2 +- .../LinuxFramebufferPlatform.cs | 9 +++++---- .../Avalonia.LinuxFramebuffer/Output/DrmOutput.cs | 6 ++++-- .../Output/FbdevOutput.cs | 7 +++---- .../Output/IOutputBackend.cs | 1 + 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/samples/ControlCatalog.NetCore/Program.cs b/samples/ControlCatalog.NetCore/Program.cs index de9ca02ed1..09d2612ac3 100644 --- a/samples/ControlCatalog.NetCore/Program.cs +++ b/samples/ControlCatalog.NetCore/Program.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Globalization; using System.Linq; using System.Threading; using Avalonia; @@ -28,15 +29,24 @@ namespace ControlCatalog.NetCore } var builder = BuildAvaloniaApp(); + + double GetScaling() + { + var idx = Array.IndexOf(args, "--scaling"); + if (idx != 0 && args.Length > idx + 1 && + double.TryParse(args[idx + 1], NumberStyles.Any, CultureInfo.InvariantCulture, out var scaling)) + return scaling; + return 1; + } if (args.Contains("--fbdev")) { SilenceConsole(); - return builder.StartLinuxFbDev(args); + return builder.StartLinuxFbDev(args, scaling: GetScaling()); } else if (args.Contains("--drm")) { SilenceConsole(); - return builder.StartLinuxDrm(args); + return builder.StartLinuxDrm(args, scaling: GetScaling()); } else return builder.StartWithClassicDesktopLifetime(args); diff --git a/src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs b/src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs index ebaad81fa1..2dc112f3d3 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs @@ -61,7 +61,7 @@ namespace Avalonia.LinuxFramebuffer public IMouseDevice MouseDevice => new MouseDevice(); public IPopupImpl CreatePopup() => null; - public double Scaling => 1; + public double Scaling => _outputBackend.Scaling; public IEnumerable Surfaces => new object[] {_outputBackend}; public Action Input { get; set; } public Action Paint { get; set; } diff --git a/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs b/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs index 2cc1f65202..8fc555aac2 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs @@ -107,11 +107,12 @@ namespace Avalonia.LinuxFramebuffer public static class LinuxFramebufferPlatformExtensions { - public static int StartLinuxFbDev(this T builder, string[] args, string fbdev = null) - where T : AppBuilderBase, new() => StartLinuxDirect(builder, args, new FbdevOutput(fbdev)); + public static int StartLinuxFbDev(this T builder, string[] args, string fbdev = null, double scaling = 1) + where T : AppBuilderBase, new() => + StartLinuxDirect(builder, args, new FbdevOutput(fbdev) {Scaling = scaling}); - public static int StartLinuxDrm(this T builder, string[] args, string card = null) - where T : AppBuilderBase, new() => StartLinuxDirect(builder, args, new DrmOutput(card)); + public static int StartLinuxDrm(this T builder, string[] args, string card = null, double scaling = 1) + where T : AppBuilderBase, new() => StartLinuxDirect(builder, args, new DrmOutput(card) {Scaling = scaling}); public static int StartLinuxDirect(this T builder, string[] args, IOutputBackend backend) where T : AppBuilderBase, new() diff --git a/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs b/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs index 6a76977352..273265a6dc 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs @@ -14,7 +14,7 @@ namespace Avalonia.LinuxFramebuffer.Output private DrmCard _card; private readonly EglGlPlatformSurface _eglPlatformSurface; public PixelSize PixelSize => _mode.Resolution; - + public double Scaling { get; set; } public DrmOutput(string path = null) { var card = new DrmCard(path); @@ -233,7 +233,7 @@ namespace Avalonia.LinuxFramebuffer.Output public PixelSize Size => _parent._mode.Resolution; - public double Scaling => 1; + public double Scaling => _parent.Scaling; } public IGlPlatformSurfaceRenderingSession BeginDraw() @@ -241,6 +241,8 @@ namespace Avalonia.LinuxFramebuffer.Output _parent._deferredContext.MakeCurrent(_parent._eglSurface); return new RenderSession(_parent); } + + } IGlContext IWindowingPlatformGlFeature.ImmediateContext => _immediateContext; diff --git a/src/Linux/Avalonia.LinuxFramebuffer/Output/FbdevOutput.cs b/src/Linux/Avalonia.LinuxFramebuffer/Output/FbdevOutput.cs index 3021c29015..b83fe6cbe8 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/Output/FbdevOutput.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/Output/FbdevOutput.cs @@ -9,16 +9,15 @@ namespace Avalonia.LinuxFramebuffer { public sealed unsafe class FbdevOutput : IFramebufferPlatformSurface, IDisposable, IOutputBackend { - private readonly Vector _dpi; private int _fd; private fb_fix_screeninfo _fixedInfo; private fb_var_screeninfo _varInfo; private IntPtr _mappedLength; private IntPtr _mappedAddress; + public double Scaling { get; set; } - public FbdevOutput(string fileName = null, Vector? dpi = null) + public FbdevOutput(string fileName = null) { - _dpi = dpi ?? new Vector(96, 96); fileName = fileName ?? Environment.GetEnvironmentVariable("FRAMEBUFFER") ?? "/dev/fb0"; _fd = NativeUnsafeMethods.open(fileName, 2, 0); if (_fd <= 0) @@ -101,7 +100,7 @@ namespace Avalonia.LinuxFramebuffer { if (_fd <= 0) throw new ObjectDisposedException("LinuxFramebuffer"); - return new LockedFramebuffer(_fd, _fixedInfo, _varInfo, _mappedAddress, _dpi); + return new LockedFramebuffer(_fd, _fixedInfo, _varInfo, _mappedAddress, new Vector(96, 96) * Scaling); } diff --git a/src/Linux/Avalonia.LinuxFramebuffer/Output/IOutputBackend.cs b/src/Linux/Avalonia.LinuxFramebuffer/Output/IOutputBackend.cs index 01690f07ac..17a39b0219 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/Output/IOutputBackend.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/Output/IOutputBackend.cs @@ -3,5 +3,6 @@ namespace Avalonia.LinuxFramebuffer.Output public interface IOutputBackend { PixelSize PixelSize { get; } + double Scaling { get; set; } } }