diff options
author | Theun de Bruijn <theun@theundebruijn.com> | 2023-09-26 07:40:16 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-25 23:40:16 +0200 |
commit | eca8808649b7d763dd6b528bd26d43b7bd839cd2 (patch) | |
tree | 24d110eea8e3cdf3158a7c54400e11168cc5c649 /src/Ryujinx.Headless.SDL2/WindowBase.cs | |
parent | f6c3f1cdfdb9145634be3bfc54400f0d408f36dd (diff) |
Headless: Add support for Scaling Filters, Anti-aliasing and Exclusive Fullscreen (#5412)1.1.1025
* Headless: Added support for fullscreen option
* Headless: cleanup of fullscreen support
* Headless: fullscreen support : implemented proposed changes
* Headless: fullscreen support: cleanup
* Headless: exclusive fullscreen support: wip
* Headless: exclusive fullscreen support: add. windows scale interop
* Headless: exclusive fullscreen support: cleanup
* Headless: exclusive fullscreen support: cleanup
* Headless: fullscreen support: fix for OpenGL scaling
* Headless: fullscreen support: cleanup
* Headless: fullscreen support: cleanup
* Headless: fullscreen support: add. Vulkan fix
* Headless: fullscreen support: add. macOS fullscreen fix
* Headless: fullscreen support: cleanup
* Headless: fullscreen support: cleanup
* Headless: fullscreen support: cleanup
* Headless: exclusive fullscreen support: add. display selection logic
* Headless: exclusive fullscreen support: add. anti-aliasing + scaling-filter logic
* Headless: exclusive fullscreen support: upd. options to be case-insensitive
* Headless: exclusive fullscreen support: force default values for scaling + anti-aliasing options
* Headless: upd. OpenGL --fullscreen window size logic
* Headless: upd. fullscreen logic
* Headless: cleanup
* Headless: refac. DisplayId option naming
* Headless: refac. scaling + anti-aliasing option handling
* Headless: refac. namespace handling
* Headless: upd. imports ordering
* Apply suggestions from code review
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
---------
Co-authored-by: Ac_K <Acoustik666@gmail.com>
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
Diffstat (limited to 'src/Ryujinx.Headless.SDL2/WindowBase.cs')
-rw-r--r-- | src/Ryujinx.Headless.SDL2/WindowBase.cs | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/src/Ryujinx.Headless.SDL2/WindowBase.cs b/src/Ryujinx.Headless.SDL2/WindowBase.cs index 0b91da5c..1b955605 100644 --- a/src/Ryujinx.Headless.SDL2/WindowBase.cs +++ b/src/Ryujinx.Headless.SDL2/WindowBase.cs @@ -20,6 +20,8 @@ using System.IO; using System.Runtime.InteropServices; using System.Threading; using static SDL2.SDL; +using AntiAliasing = Ryujinx.Common.Configuration.AntiAliasing; +using ScalingFilter = Ryujinx.Common.Configuration.ScalingFilter; using Switch = Ryujinx.HLE.Switch; namespace Ryujinx.Headless.SDL2 @@ -28,8 +30,9 @@ namespace Ryujinx.Headless.SDL2 { protected const int DefaultWidth = 1280; protected const int DefaultHeight = 720; - private const SDL_WindowFlags DefaultFlags = SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI | SDL_WindowFlags.SDL_WINDOW_RESIZABLE | SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS | SDL_WindowFlags.SDL_WINDOW_SHOWN; private const int TargetFps = 60; + private SDL_WindowFlags DefaultFlags = SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI | SDL_WindowFlags.SDL_WINDOW_RESIZABLE | SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS | SDL_WindowFlags.SDL_WINDOW_SHOWN; + private SDL_WindowFlags FullscreenFlag = 0; private static readonly ConcurrentQueue<Action> _mainThreadActions = new(); @@ -54,7 +57,14 @@ namespace Ryujinx.Headless.SDL2 public IHostUiTheme HostUiTheme { get; } public int Width { get; private set; } public int Height { get; private set; } + public int DisplayId { get; set; } public bool IsFullscreen { get; set; } + public bool IsExclusiveFullscreen { get; set; } + public int ExclusiveFullscreenWidth { get; set; } + public int ExclusiveFullscreenHeight { get; set; } + public AntiAliasing AntiAliasing { get; set; } + public ScalingFilter ScalingFilter { get; set; } + public int ScalingFilterLevel { get; set; } protected SDL2MouseDriver MouseDriver; private readonly InputManager _inputManager; @@ -158,9 +168,24 @@ namespace Ryujinx.Headless.SDL2 string titleIdSection = string.IsNullOrWhiteSpace(activeProcess.ProgramIdText) ? string.Empty : $" ({activeProcess.ProgramIdText.ToUpper()})"; string titleArchSection = activeProcess.Is64Bit ? " (64-bit)" : " (32-bit)"; - SDL_WindowFlags fullscreenFlag = IsFullscreen ? SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP : 0; + Width = DefaultWidth; + Height = DefaultHeight; + + if (IsExclusiveFullscreen) + { + Width = ExclusiveFullscreenWidth; + Height = ExclusiveFullscreenHeight; + + DefaultFlags = SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI; + FullscreenFlag = SDL_WindowFlags.SDL_WINDOW_FULLSCREEN; + } + else if (IsFullscreen) + { + DefaultFlags = SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI; + FullscreenFlag = SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP; + } - WindowHandle = SDL_CreateWindow($"Ryujinx {Program.Version}{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, DefaultWidth, DefaultHeight, DefaultFlags | fullscreenFlag | GetWindowFlags()); + WindowHandle = SDL_CreateWindow($"Ryujinx {Program.Version}{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}", SDL_WINDOWPOS_CENTERED_DISPLAY(DisplayId), SDL_WINDOWPOS_CENTERED_DISPLAY(DisplayId), Width, Height, DefaultFlags | FullscreenFlag | GetWindowFlags()); if (WindowHandle == IntPtr.Zero) { @@ -175,9 +200,6 @@ namespace Ryujinx.Headless.SDL2 _windowId = SDL_GetWindowID(WindowHandle); SDL2Driver.Instance.RegisterWindow(_windowId, HandleWindowEvent); - - Width = DefaultWidth; - Height = DefaultHeight; } private void HandleWindowEvent(SDL_Event evnt) @@ -189,8 +211,8 @@ namespace Ryujinx.Headless.SDL2 case SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED: // Unlike on Windows, this event fires on macOS when triggering fullscreen mode. // And promptly crashes the process because `Renderer?.window.SetSize` is undefined. - // As we don't need this to fire in either case we can test for isFullscreen. - if (!IsFullscreen) + // As we don't need this to fire in either case we can test for fullscreen. + if (!IsFullscreen && !IsExclusiveFullscreen) { Width = evnt.window.data1; Height = evnt.window.data2; @@ -225,6 +247,17 @@ namespace Ryujinx.Headless.SDL2 return Renderer.GetHardwareInfo().GpuVendor; } + private void SetAntiAliasing() + { + Renderer?.Window.SetAntiAliasing((Graphics.GAL.AntiAliasing)AntiAliasing); + } + + private void SetScalingFilter() + { + Renderer?.Window.SetScalingFilter((Graphics.GAL.ScalingFilter)ScalingFilter); + Renderer?.Window.SetScalingFilterLevel(ScalingFilterLevel); + } + public void Render() { InitializeWindowRenderer(); @@ -233,6 +266,10 @@ namespace Ryujinx.Headless.SDL2 InitializeRenderer(); + SetAntiAliasing(); + + SetScalingFilter(); + _gpuVendorName = GetGpuVendorName(); Device.Gpu.Renderer.RunLoop(() => |