Core - Made graphics context providable by UI

Windows - Implemented Vulkan graphics context
Splash screen - Tweaked design
This commit is contained in:
Robert committed 2022-05-06 18:19:02 +02:00
1 parent b2987b5190
commit 34407aaeec
18 files changed
+346 -25

No files matched your search

+1
View File
@@ -232,6 +232,7 @@ namespace Artemis.Core.Services
_pluginManagementService.CopyBuiltInPlugins();
_pluginManagementService.LoadPlugins(StartupArguments, IsElevated);
_rgbService.ApplyPreferredGraphicsContext(StartupArguments.Contains("--force-software-render"));
_rgbService.SetRenderPaused(false);
OnInitialized();
}
@@ -0,0 +1,10 @@
using System.Collections.Generic;
using Artemis.Core.SkiaSharp;
namespace Artemis.Core.Services;
public interface IGraphicsContextProvider
{
IReadOnlyCollection<string> GraphicsContextNames { get; }
IManagedGraphicsContext? GetGraphicsContext(string name);
}
@@ -40,7 +40,7 @@ namespace Artemis.Core.Services
/// Gets a boolean indicating whether the render pipeline is open
/// </summary>
bool RenderOpen { get; }
/// <summary>
/// Gets or sets a boolean indicating whether to flush the RGB.NET LEDs during next update
/// </summary>
@@ -56,6 +56,12 @@ namespace Artemis.Core.Services
/// </summary>
void CloseRender();
/// <summary>
/// Applies the current value of the <c>Core.PreferredGraphicsContext</c> setting to the graphics context.
/// </summary>
/// <param name="forceSoftware">A boolean to indicate whether or not to force the graphics context to software mode.</param>
void ApplyPreferredGraphicsContext(bool forceSoftware);
/// <summary>
/// Updates the graphics context to the provided <paramref name="managedGraphicsContext"></paramref>.
/// <para>Note: The old graphics context will be used until the next frame starts rendering and is disposed afterwards.</para>
@@ -139,10 +145,10 @@ namespace Artemis.Core.Services
void DisableDevice(ArtemisDevice device);
/// <summary>
/// Pauses or resumes rendering, method won't return until the current frame finished rendering
/// Pauses or resumes rendering, method won't return until the current frame finished rendering
/// </summary>
/// <param name="paused"></param>
/// <returns><see langword="true"/> if the pause state was changed; otherwise <see langword="false"/>.</returns>
/// <returns><see langword="true" /> if the pause state was changed; otherwise <see langword="false" />.</returns>
bool SetRenderPaused(bool paused);
/// <summary>
+51 -2
View File
@@ -8,6 +8,7 @@ using Artemis.Core.Services.Models;
using Artemis.Core.SkiaSharp;
using Artemis.Storage.Entities.Surface;
using Artemis.Storage.Repositories.Interfaces;
using Ninject;
using RGB.NET.Core;
using Serilog;
@@ -22,21 +23,27 @@ namespace Artemis.Core.Services
private readonly List<ArtemisDevice> _devices;
private readonly List<ArtemisDevice> _enabledDevices;
private readonly ILogger _logger;
private readonly IKernel _kernel;
private readonly ISettingsService _settingsService;
private readonly IPluginManagementService _pluginManagementService;
private readonly PluginSetting<double> _renderScaleSetting;
private readonly PluginSetting<int> _targetFrameRateSetting;
private readonly PluginSetting<string> _preferredGraphicsContext;
private readonly SKTextureBrush _textureBrush = new(null) {CalculationMode = RenderMode.Absolute};
private Dictionary<Led, ArtemisLed> _ledMap;
private ListLedGroup? _surfaceLedGroup;
private SKTexture? _texture;
public RgbService(ILogger logger, ISettingsService settingsService, IPluginManagementService pluginManagementService, IDeviceRepository deviceRepository)
public RgbService(ILogger logger, IKernel kernel, ISettingsService settingsService, IPluginManagementService pluginManagementService, IDeviceRepository deviceRepository)
{
_logger = logger;
_kernel = kernel;
_settingsService = settingsService;
_pluginManagementService = pluginManagementService;
_deviceRepository = deviceRepository;
_targetFrameRateSetting = settingsService.GetSetting("Core.TargetFrameRate", 30);
_renderScaleSetting = settingsService.GetSetting("Core.RenderScale", 0.25);
_preferredGraphicsContext = _settingsService.GetSetting("Core.PreferredGraphicsContext", "Vulkan");
Surface = new RGBSurface();
Utilities.RenderScaleMultiplier = (int) (1 / _renderScaleSetting.Value);
@@ -46,6 +53,7 @@ namespace Artemis.Core.Services
Surface.SurfaceLayoutChanged += SurfaceOnLayoutChanged;
_targetFrameRateSetting.SettingChanged += TargetFrameRateSettingOnSettingChanged;
_renderScaleSetting.SettingChanged += RenderScaleSettingOnSettingChanged;
_preferredGraphicsContext.SettingChanged += PreferredGraphicsContextOnSettingChanged;
_enabledDevices = new List<ArtemisDevice>();
_devices = new List<ArtemisDevice>();
_ledMap = new Dictionary<Led, ArtemisLed>();
@@ -61,6 +69,7 @@ namespace Artemis.Core.Services
Utilities.ShutdownRequested += UtilitiesOnShutdownRequested;
}
public TimerUpdateTrigger UpdateTrigger { get; }
protected virtual void OnDeviceRemoved(DeviceEventArgs e)
@@ -135,13 +144,18 @@ namespace Artemis.Core.Services
private void RenderScaleSettingOnSettingChanged(object? sender, EventArgs e)
{
Utilities.RenderScaleMultiplier = (int) (1 / _renderScaleSetting.Value);
_texture?.Invalidate();
foreach (ArtemisDevice artemisDevice in Devices)
artemisDevice.CalculateRenderProperties();
OnLedsChanged();
}
private void PreferredGraphicsContextOnSettingChanged(object? sender, EventArgs e)
{
ApplyPreferredGraphicsContext(false);
}
public IReadOnlyCollection<ArtemisDevice> EnabledDevices { get; }
public IReadOnlyCollection<ArtemisDevice> Devices { get; }
public IReadOnlyDictionary<Led, ArtemisLed> LedMap { get; private set; }
@@ -271,6 +285,7 @@ namespace Artemis.Core.Services
private IManagedGraphicsContext? _newGraphicsContext;
public SKTexture OpenRender()
{
if (RenderOpen)
@@ -333,6 +348,40 @@ namespace Artemis.Core.Services
}
}
public void ApplyPreferredGraphicsContext(bool forceSoftware)
{
if (forceSoftware)
{
_logger.Warning("Startup argument '--force-software-render' is applied, forcing software rendering");
UpdateGraphicsContext(null);
return;
}
if (_preferredGraphicsContext.Value == "Software")
{
UpdateGraphicsContext(null);
return;
}
IGraphicsContextProvider? provider = _kernel.TryGet<IGraphicsContextProvider>();
if (provider == null)
{
_logger.Warning("No graphics context provider found, defaulting to software rendering");
UpdateGraphicsContext(null);
return;
}
IManagedGraphicsContext? context = provider.GetGraphicsContext(_preferredGraphicsContext.Value);
if (context == null)
{
_logger.Warning("No graphics context named '{Context}' found, defaulting to software rendering", _preferredGraphicsContext.Value);
UpdateGraphicsContext(null);
return;
}
UpdateGraphicsContext(context);
}
public void UpdateGraphicsContext(IManagedGraphicsContext? managedGraphicsContext)
{
if (ReferenceEquals(managedGraphicsContext, Constants.ManagedGraphicsContext))