From 5d491894aa69f7938124f5079442f655a0519abe Mon Sep 17 00:00:00 2001 From: Markus Wenzl Date: Tue, 26 Jul 2022 20:00:28 +0200 Subject: [PATCH] Fixes single responsibility principle --- .../DrmOutputOptions.cs | 27 +++++++++++ .../LinuxDrmOptions.cs | 46 ------------------- .../LinuxFramebufferPlatform.cs | 10 +--- .../Output/DrmOutput.cs | 34 ++++++++------ 4 files changed, 49 insertions(+), 68 deletions(-) create mode 100644 src/Linux/Avalonia.LinuxFramebuffer/DrmOutputOptions.cs delete mode 100644 src/Linux/Avalonia.LinuxFramebuffer/LinuxDrmOptions.cs diff --git a/src/Linux/Avalonia.LinuxFramebuffer/DrmOutputOptions.cs b/src/Linux/Avalonia.LinuxFramebuffer/DrmOutputOptions.cs new file mode 100644 index 0000000000..e92ad02c7a --- /dev/null +++ b/src/Linux/Avalonia.LinuxFramebuffer/DrmOutputOptions.cs @@ -0,0 +1,27 @@ +using Avalonia.LinuxFramebuffer.Output; +using Avalonia.Media; +using JetBrains.Annotations; + +namespace Avalonia.LinuxFramebuffer +{ + public class DrmOutputOptions + { + /// + /// Scaling factor. + /// Default: 1.0 + /// + public double Scaling { get; set; } = 1.0; + + /// + /// If true an two cycle buffer swapping is processed at init. + /// Default: True + /// + public bool EnableInitialBufferSwapping { get; set; } = true; + + /// + /// Color for + /// Default: R0 G0 B0 A0 + /// + public Color InitialBufferSwappingColor { get; set; } = new Color(0, 0, 0, 0); + } +} diff --git a/src/Linux/Avalonia.LinuxFramebuffer/LinuxDrmOptions.cs b/src/Linux/Avalonia.LinuxFramebuffer/LinuxDrmOptions.cs deleted file mode 100644 index a67d6f7d8b..0000000000 --- a/src/Linux/Avalonia.LinuxFramebuffer/LinuxDrmOptions.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Avalonia.LinuxFramebuffer.Output; -using Avalonia.Media; -using JetBrains.Annotations; - -namespace Avalonia.LinuxFramebuffer -{ - public class LinuxDrmOptions - { - /// - /// Path for DrmCard to use, if no is passed. - /// Default: null - /// - [CanBeNull] public string Card { get; set; } - - /// - /// True to call drmModeGetConnector for all available connectors, otherwise drmModeGetConnectorCurrent is called to get the kernel-cached connected connector. - /// Info: since some hardware might have incorrect connector information on startup for some reason, you may need to set this parameter to true. - /// Default: False - /// - public bool DrmConnectorsForceProbe { get; set; } = false; - - /// - /// Scaling factor. - /// Default: 1.0 - /// - public double Scaling { get; set; } = 1.0; - - /// - /// If true an two cycle buffer swapping is processed at init. - /// Default: True - /// - public bool EnableInitialBufferSwapping { get; set; } = true; - - /// - /// Color for - /// Default: R0 G0 B0 A0 - /// - public Color InitialBufferSwappingColor { get; set; } = new Color(0, 0, 0, 0); - - /// - /// IOutputBackend. If Null, a new DrmOutput for with will be created. - /// Default: null - /// - [CanBeNull] public IOutputBackend OutputBackend { get; set; } - } -} diff --git a/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs b/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs index bf29aed1a4..a642766809 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs @@ -140,14 +140,8 @@ public static class LinuxFramebufferPlatformExtensions 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 StartLinuxDrm(this T builder, string[] args, [CanBeNull] LinuxDrmOptions drmOptions) - where T : AppBuilderBase, new() - { - drmOptions ??= new LinuxDrmOptions(); - drmOptions.OutputBackend ??= new DrmOutput(drmOptions) {Scaling = drmOptions.Scaling}; - return StartLinuxDirect(builder, args, drmOptions.OutputBackend); - } + public static int StartLinuxDrm(this T builder, string[] args, string card = null, bool connectorsForceProbe = false, [CanBeNull] DrmOutputOptions options = null) + where T : AppBuilderBase, new() => StartLinuxDirect(builder, args, new DrmOutput(card, connectorsForceProbe, options)); 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 85cf1fba76..509b0cee99 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs @@ -7,6 +7,7 @@ using Avalonia.OpenGL; using Avalonia.OpenGL.Egl; using Avalonia.OpenGL.Surfaces; using Avalonia.Platform.Interop; +using JetBrains.Annotations; using static Avalonia.LinuxFramebuffer.NativeUnsafeMethods; using static Avalonia.LinuxFramebuffer.Output.LibDrm; using static Avalonia.LinuxFramebuffer.Output.LibDrm.GbmColorFormats; @@ -15,27 +16,32 @@ namespace Avalonia.LinuxFramebuffer.Output { public unsafe class DrmOutput : IGlOutputBackend, IGlPlatformSurface { - private LinuxDrmOptions _options; + private DrmOutputOptions _outputOptions = new(); private DrmCard _card; public PixelSize PixelSize => _mode.Resolution; public double Scaling { - get => _options.Scaling; - set => _options.Scaling = value; + get => _outputOptions.Scaling; + set => _outputOptions.Scaling = value; } public IGlContext PrimaryContext => _deferredContext; private EglPlatformOpenGlInterface _platformGl; public IPlatformOpenGlInterface PlatformOpenGlInterface => _platformGl; - public DrmOutput(LinuxDrmOptions drmOptions) + public DrmOutput(DrmCard card, DrmResources resources, DrmConnector connector, DrmModeInfo modeInfo, + DrmOutputOptions? options = null) { - _options = drmOptions; - CreateDrmOutput(_options.Card, _options.DrmConnectorsForceProbe); + if(options != null) + _outputOptions = options; + Init(card, resources, connector, modeInfo); } - public DrmOutput(string path = null) : this(new LinuxDrmOptions() { Card = path }) + public DrmOutput(string path = null, bool connectorsForceProbe = false, [CanBeNull] DrmOutputOptions options = null) { + if(options != null) + _outputOptions = options; + CreateDrmOutput(path, connectorsForceProbe); } private void CreateDrmOutput(string path = null, bool connectorsForceProbe = false) @@ -158,9 +164,9 @@ namespace Avalonia.LinuxFramebuffer.Output using (_deferredContext.MakeCurrent(_eglSurface)) { - _deferredContext.GlInterface.ClearColor(_options.InitialBufferSwappingColor.R, - _options.InitialBufferSwappingColor.G, _options.InitialBufferSwappingColor.B, - _options.InitialBufferSwappingColor.A); + _deferredContext.GlInterface.ClearColor(_outputOptions.InitialBufferSwappingColor.R, + _outputOptions.InitialBufferSwappingColor.G, _outputOptions.InitialBufferSwappingColor.B, + _outputOptions.InitialBufferSwappingColor.A); _deferredContext.GlInterface.Clear(GlConsts.GL_COLOR_BUFFER_BIT | GlConsts.GL_STENCIL_BUFFER_BIT); _eglSurface.SwapBuffers(); } @@ -178,15 +184,15 @@ namespace Avalonia.LinuxFramebuffer.Output _mode = mode; _currentBo = bo; - if (_options.EnableInitialBufferSwapping) + if (_outputOptions.EnableInitialBufferSwapping) { //Go trough two cycles of buffer swapping (there are render artifacts otherwise) for(var c=0;c<2;c++) using (CreateGlRenderTarget().BeginDraw()) { - _deferredContext.GlInterface.ClearColor(_options.InitialBufferSwappingColor.R, - _options.InitialBufferSwappingColor.G, _options.InitialBufferSwappingColor.B, - _options.InitialBufferSwappingColor.A); + _deferredContext.GlInterface.ClearColor(_outputOptions.InitialBufferSwappingColor.R, + _outputOptions.InitialBufferSwappingColor.G, _outputOptions.InitialBufferSwappingColor.B, + _outputOptions.InitialBufferSwappingColor.A); _deferredContext.GlInterface.Clear(GlConsts.GL_COLOR_BUFFER_BIT | GlConsts.GL_STENCIL_BUFFER_BIT); } }