1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-10-01 12:30:00 +02:00

gui/gpu: Implement setting and toggle for Aspect Ratio (#1777)

* gui/gpu: Implement setting and toggle for Aspect Ratio

* address gdkchan feedback and add 16:10

* fix config.json file

* Fix rebase

* Address gdkchan feedback

* Address rip feedback

* Fix aspectWidth
This commit is contained in:
Ac_K 2020-12-16 03:19:07 +01:00 committed by GitHub
parent 808380690c
commit 11222516c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 264 additions and 57 deletions

View file

@ -0,0 +1,59 @@
namespace Ryujinx.Common.Configuration
{
public enum AspectRatio
{
Fixed4x3,
Fixed16x9,
Fixed16x10,
Fixed21x9,
Fixed32x9,
Stretched
}
public static class AspectRatioExtensions
{
public static float ToFloat(this AspectRatio aspectRatio)
{
return aspectRatio.ToFloatX() / aspectRatio.ToFloatY();
}
public static float ToFloatX(this AspectRatio aspectRatio)
{
return aspectRatio switch
{
AspectRatio.Fixed4x3 => 4.0f,
AspectRatio.Fixed16x9 => 16.0f,
AspectRatio.Fixed16x10 => 16.0f,
AspectRatio.Fixed21x9 => 21.0f,
AspectRatio.Fixed32x9 => 32.0f,
_ => 16.0f
};
}
public static float ToFloatY(this AspectRatio aspectRatio)
{
return aspectRatio switch
{
AspectRatio.Fixed4x3 => 3.0f,
AspectRatio.Fixed16x9 => 9.0f,
AspectRatio.Fixed16x10 => 10.0f,
AspectRatio.Fixed21x9 => 9.0f,
AspectRatio.Fixed32x9 => 9.0f,
_ => 9.0f
};
}
public static string ToText(this AspectRatio aspectRatio)
{
return aspectRatio switch
{
AspectRatio.Fixed4x3 => "4:3",
AspectRatio.Fixed16x9 => "16:9",
AspectRatio.Fixed16x10 => "16:10",
AspectRatio.Fixed21x9 => "21:9",
AspectRatio.Fixed32x9 => "32:9",
_ => "Stretched"
};
}
}
}

View file

@ -14,7 +14,7 @@ namespace Ryujinx.Configuration
/// <summary>
/// The current version of the file format
/// </summary>
public const int CurrentVersion = 17;
public const int CurrentVersion = 18;
public int Version { get; set; }
@ -33,6 +33,11 @@ namespace Ryujinx.Configuration
/// </summary>
public float MaxAnisotropy { get; set; }
/// <summary>
/// Aspect Ratio applied to the renderer window.
/// </summary>
public AspectRatio AspectRatio { get; set; }
/// <summary>
/// Dumps shaders in this local directory
/// </summary>

View file

@ -278,6 +278,11 @@ namespace Ryujinx.Configuration
/// </summary>
public ReactiveObject<float> MaxAnisotropy { get; private set; }
/// <summary>
/// Aspect Ratio applied to the renderer window.
/// </summary>
public ReactiveObject<AspectRatio> AspectRatio { get; private set; }
/// <summary>
/// Resolution Scale. An integer scale applied to applicable render targets. Values 1-4, or -1 to use a custom floating point scale instead.
/// </summary>
@ -308,6 +313,7 @@ namespace Ryujinx.Configuration
ResScale = new ReactiveObject<int>();
ResScaleCustom = new ReactiveObject<float>();
MaxAnisotropy = new ReactiveObject<float>();
AspectRatio = new ReactiveObject<AspectRatio>();
ShadersDumpPath = new ReactiveObject<string>();
EnableVsync = new ReactiveObject<bool>();
EnableShaderCache = new ReactiveObject<bool>();
@ -388,6 +394,7 @@ namespace Ryujinx.Configuration
ResScale = Graphics.ResScale,
ResScaleCustom = Graphics.ResScaleCustom,
MaxAnisotropy = Graphics.MaxAnisotropy,
AspectRatio = Graphics.AspectRatio,
GraphicsShadersDumpPath = Graphics.ShadersDumpPath,
LoggingEnableDebug = Logger.EnableDebug,
LoggingEnableStub = Logger.EnableStub,
@ -449,6 +456,7 @@ namespace Ryujinx.Configuration
Graphics.ResScale.Value = 1;
Graphics.ResScaleCustom.Value = 1.0f;
Graphics.MaxAnisotropy.Value = -1.0f;
Graphics.AspectRatio.Value = AspectRatio.Fixed16x9;
Graphics.ShadersDumpPath.Value = "";
Logger.EnableDebug.Value = false;
Logger.EnableStub.Value = true;
@ -457,7 +465,7 @@ namespace Ryujinx.Configuration
Logger.EnableError.Value = true;
Logger.EnableGuest.Value = true;
Logger.EnableFsAccessLog.Value = false;
Logger.FilteredClasses.Value = new LogClass[] { };
Logger.FilteredClasses.Value = Array.Empty<LogClass>();
Logger.GraphicsDebugLevel.Value = GraphicsDebugLevel.None;
Logger.EnableFileLog.Value = true;
System.Language.Value = Language.AmericanEnglish;
@ -753,6 +761,15 @@ namespace Ryujinx.Configuration
configurationFileUpdated = true;
}
if (configurationFileFormat.Version < 18)
{
Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 18.");
configurationFileFormat.AspectRatio = AspectRatio.Fixed16x9;
configurationFileUpdated = true;
}
List<InputConfig> inputConfig = new List<InputConfig>();
inputConfig.AddRange(configurationFileFormat.ControllerConfig);
inputConfig.AddRange(configurationFileFormat.KeyboardConfig);
@ -760,6 +777,7 @@ namespace Ryujinx.Configuration
Graphics.ResScale.Value = configurationFileFormat.ResScale;
Graphics.ResScaleCustom.Value = configurationFileFormat.ResScaleCustom;
Graphics.MaxAnisotropy.Value = configurationFileFormat.MaxAnisotropy;
Graphics.AspectRatio.Value = configurationFileFormat.AspectRatio;
Graphics.ShadersDumpPath.Value = configurationFileFormat.GraphicsShadersDumpPath;
Logger.EnableDebug.Value = configurationFileFormat.LoggingEnableDebug;
Logger.EnableStub.Value = configurationFileFormat.LoggingEnableStub;

View file

@ -8,6 +8,9 @@ namespace Ryujinx.Graphics.GAL
public int Bottom { get; }
public bool FlipX { get; }
public bool FlipY { get; }
public bool IsStretched { get; }
public float AspectRatioX { get; }
public float AspectRatioY { get; }
public ImageCrop(
int left,
@ -15,7 +18,11 @@ namespace Ryujinx.Graphics.GAL
int top,
int bottom,
bool flipX,
bool flipY)
bool flipY,
bool isStretched,
float aspectRatioX,
float aspectRatioY
)
{
Left = left;
Right = right;
@ -23,6 +30,9 @@ namespace Ryujinx.Graphics.GAL
Bottom = bottom;
FlipX = flipX;
FlipY = flipY;
IsStretched = isStretched;
AspectRatioX = aspectRatioX;
AspectRatioY = aspectRatioY;
}
}
}

View file

@ -1,7 +1,5 @@
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Platform;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.OpenGL.Image;
using System;
@ -10,9 +8,6 @@ namespace Ryujinx.Graphics.OpenGL
{
class Window : IWindow, IDisposable
{
private const int NativeWidth = 1280;
private const int NativeHeight = 720;
private readonly Renderer _renderer;
private int _width;
@ -25,9 +20,6 @@ namespace Ryujinx.Graphics.OpenGL
public Window(Renderer renderer)
{
_renderer = renderer;
_width = NativeWidth;
_height = NativeHeight;
}
public void Present(ITexture texture, ImageCrop crop)
@ -104,8 +96,8 @@ namespace Ryujinx.Graphics.OpenGL
srcY1 = (int)Math.Ceiling(srcY1 * scale);
}
float ratioX = MathF.Min(1f, (_height * (float)NativeWidth) / ((float)NativeHeight * _width));
float ratioY = MathF.Min(1f, (_width * (float)NativeHeight) / ((float)NativeWidth * _height));
float ratioX = crop.IsStretched ? 1.0f : MathF.Min(1.0f, _height * crop.AspectRatioX / (_width * crop.AspectRatioY));
float ratioY = crop.IsStretched ? 1.0f : MathF.Min(1.0f, _width * crop.AspectRatioY / (_height * crop.AspectRatioX));
int dstWidth = (int)(_width * ratioX);
int dstHeight = (int)(_height * ratioY);

View file

@ -1,4 +1,6 @@
using Ryujinx.Common.Logging;
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging;
using Ryujinx.Configuration;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu;
using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap;
@ -277,13 +279,19 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
bool flipX = item.Transform.HasFlag(NativeWindowTransform.FlipX);
bool flipY = item.Transform.HasFlag(NativeWindowTransform.FlipY);
AspectRatio aspectRatio = ConfigurationState.Instance.Graphics.AspectRatio.Value;
bool isStretched = aspectRatio == AspectRatio.Stretched;
ImageCrop crop = new ImageCrop(
cropRect.Left,
cropRect.Right,
cropRect.Top,
cropRect.Bottom,
flipX,
flipY);
flipY,
isStretched,
aspectRatio.ToFloatX(),
aspectRatio.ToFloatY());
TextureCallbackInformation textureCallbackInformation = new TextureCallbackInformation
{

View file

@ -1,8 +1,9 @@
{
"version": 17,
"version": 18,
"res_scale": 1,
"res_scale_custom": 1,
"max_anisotropy": -1,
"aspect_ratio": "Fixed16x9",
"graphics_shaders_dump_path": "",
"logging_enable_debug": false,
"logging_enable_stub": true,

View file

@ -5,16 +5,16 @@ using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Input;
using Ryujinx.Configuration;
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Configuration.Hid;
using Ryujinx.Configuration;
using Ryujinx.Graphics.OpenGL;
using Ryujinx.HLE;
using Ryujinx.HLE.HOS.Services.Hid;
using Ryujinx.Motion;
using System;
using System.Collections.Generic;
using System.Threading;
using Ryujinx.Motion;
namespace Ryujinx.Ui
{
@ -219,7 +219,6 @@ namespace Ryujinx.Ui
{
parent.Present();
string titleNameSection = string.IsNullOrWhiteSpace(_device.Application.TitleName) ? string.Empty
: $" - {_device.Application.TitleName}";
@ -419,6 +418,7 @@ namespace Ryujinx.Ui
StatusUpdatedEvent?.Invoke(this, new StatusUpdatedEventArgs(
_device.EnableDeviceVsync,
dockedMode,
ConfigurationState.Instance.Graphics.AspectRatio.Value.ToText(),
$"Game: {_device.Statistics.GetGameFrameRate():00.00} FPS",
$"FIFO: {_device.Statistics.GetFifoPercent():0.00} %",
$"GPU: {_renderer.GpuVendor}"));
@ -632,16 +632,18 @@ namespace Ryujinx.Ui
// OpenTK always captures mouse events, even if out of focus, so check if window is focused.
if (_isFocused && _mousePressed)
{
float aspectWidth = SwitchPanelHeight * ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat();
int screenWidth = AllocatedWidth;
int screenHeight = AllocatedHeight;
if (AllocatedWidth > (AllocatedHeight * SwitchPanelWidth) / SwitchPanelHeight)
if (AllocatedWidth > AllocatedHeight * aspectWidth / SwitchPanelHeight)
{
screenWidth = (AllocatedHeight * SwitchPanelWidth) / SwitchPanelHeight;
screenWidth = (int)(AllocatedHeight * aspectWidth) / SwitchPanelHeight;
}
else
{
screenHeight = (AllocatedWidth * SwitchPanelHeight) / SwitchPanelWidth;
screenHeight = (AllocatedWidth * SwitchPanelHeight) / (int)aspectWidth;
}
int startX = (AllocatedWidth - screenWidth) >> 1;
@ -659,7 +661,7 @@ namespace Ryujinx.Ui
int screenMouseX = (int)_mouseX - startX;
int screenMouseY = (int)_mouseY - startY;
int mX = (screenMouseX * SwitchPanelWidth) / screenWidth;
int mX = (screenMouseX * (int)aspectWidth) / screenWidth;
int mY = (screenMouseY * SwitchPanelHeight) / screenHeight;
TouchPoint currentPoint = new TouchPoint

View file

@ -72,6 +72,7 @@ namespace Ryujinx.Ui
[GUI] CheckMenuItem _pathToggle;
[GUI] CheckMenuItem _fileSizeToggle;
[GUI] Label _dockedMode;
[GUI] Label _aspectRatio;
[GUI] Label _gameStatus;
[GUI] TreeView _gameTable;
[GUI] TreeSelection _gameTableSelection;
@ -668,6 +669,7 @@ namespace Ryujinx.Ui
{
int resScale = ConfigurationState.Instance.Graphics.ResScale;
float resScaleCustom = ConfigurationState.Instance.Graphics.ResScaleCustom;
Graphics.Gpu.GraphicsConfig.ResScale = (resScale == -1) ? resScaleCustom : resScale;
Graphics.Gpu.GraphicsConfig.MaxAnisotropy = ConfigurationState.Instance.Graphics.MaxAnisotropy;
Graphics.Gpu.GraphicsConfig.ShadersDumpPath = ConfigurationState.Instance.Graphics.ShadersDumpPath;
@ -810,6 +812,7 @@ namespace Ryujinx.Ui
_fifoStatus.Text = args.FifoStatus;
_gpuName.Text = args.GpuName;
_dockedMode.Text = args.DockedMode;
_aspectRatio.Text = args.AspectRatio;
if (args.VSyncEnabled)
{
@ -868,6 +871,13 @@ namespace Ryujinx.Ui
ConfigurationState.Instance.System.EnableDockedMode.Value = !ConfigurationState.Instance.System.EnableDockedMode.Value;
}
private void AspectRatio_Clicked(object sender, ButtonReleaseEventArgs args)
{
AspectRatio aspectRatio = ConfigurationState.Instance.Graphics.AspectRatio.Value;
ConfigurationState.Instance.Graphics.AspectRatio.Value = ((int)aspectRatio + 1) > Enum.GetNames(typeof(AspectRatio)).Length - 1 ? AspectRatio.Fixed4x3 : aspectRatio + 1;
}
private void Row_Clicked(object sender, ButtonReleaseEventArgs args)
{
if (args.Event.Button != 3) return;

View file

@ -562,13 +562,21 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="_gameStatus">
<object class="GtkEventBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">0</property>
<signal name="button-release-event" handler="AspectRatio_Clicked" swapped="no"/>
<child>
<object class="GtkLabel" id="_aspectRatio">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
@ -587,7 +595,7 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="_fifoStatus">
<object class="GtkLabel" id="_gameStatus">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
@ -611,6 +619,31 @@
<property name="position">7</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="_fifoStatus">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">8</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">9</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="_gpuName">
<property name="visible">True</property>
@ -621,7 +654,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">8</property>
<property name="position">10</property>
</packing>
</child>
</object>

View file

@ -71,6 +71,7 @@ namespace Ryujinx.Ui
[GUI] Entry _addGameDirBox;
[GUI] Entry _graphicsShadersDumpPath;
[GUI] ComboBoxText _anisotropy;
[GUI] ComboBoxText _aspectRatio;
[GUI] ComboBoxText _resScaleCombo;
[GUI] Entry _resScaleText;
[GUI] ToggleButton _configureController1;
@ -249,6 +250,7 @@ namespace Ryujinx.Ui
_systemRegionSelect.SetActiveId(ConfigurationState.Instance.System.Region.Value.ToString());
_resScaleCombo.SetActiveId(ConfigurationState.Instance.Graphics.ResScale.Value.ToString());
_anisotropy.SetActiveId(ConfigurationState.Instance.Graphics.MaxAnisotropy.Value.ToString());
_aspectRatio.SetActiveId(((int)ConfigurationState.Instance.Graphics.AspectRatio.Value).ToString());
_custThemePath.Buffer.Text = ConfigurationState.Instance.Ui.CustomThemePath;
_resScaleText.Buffer.Text = ConfigurationState.Instance.Graphics.ResScaleCustom.Value.ToString();
@ -408,6 +410,7 @@ namespace Ryujinx.Ui
ConfigurationState.Instance.Ui.GameDirs.Value = gameDirs;
ConfigurationState.Instance.System.FsGlobalAccessLogMode.Value = (int)_fsLogSpinAdjustment.Value;
ConfigurationState.Instance.Graphics.MaxAnisotropy.Value = float.Parse(_anisotropy.ActiveId, CultureInfo.InvariantCulture);
ConfigurationState.Instance.Graphics.AspectRatio.Value = Enum.Parse<AspectRatio>(_aspectRatio.ActiveId);
ConfigurationState.Instance.Graphics.ResScale.Value = int.Parse(_resScaleCombo.ActiveId);
ConfigurationState.Instance.Graphics.ResScaleCustom.Value = resScaleCustom;
@ -422,7 +425,7 @@ namespace Ryujinx.Ui
}
//Events
private void TimeZoneEntry_FocusOut(Object sender, FocusOutEventArgs e)
private void TimeZoneEntry_FocusOut(object sender, FocusOutEventArgs e)
{
if (!_validTzRegions.Contains(_systemTimeZoneEntry.Text))
{
@ -439,7 +442,7 @@ namespace Ryujinx.Ui
((string)compl.Model.GetValue(iter, 0)).Substring(3).StartsWith(key); // offset
}
private void SystemTimeSpin_ValueChanged(Object sender, EventArgs e)
private void SystemTimeSpin_ValueChanged(object sender, EventArgs e)
{
int year = _systemTimeYearSpin.ValueAsInt;
int month = _systemTimeMonthSpin.ValueAsInt;

View file

@ -1811,6 +1811,55 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Aspect Ratio applied to the renderer window.</property>
<property name="label" translatable="yes">Aspect Ratio:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="_aspectRatio">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Aspect Ratio applied to the renderer window.</property>
<property name="active-id">1</property>
<items>
<item id="0" translatable="yes">4:3</item>
<item id="1" translatable="yes">16:9</item>
<item id="2" translatable="yes">16:10</item>
<item id="3" translatable="yes">21:9</item>
<item id="4" translatable="yes">32:9</item>
<item id="5" translatable="yes">Stretch to Fit Window</item>
</items>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>

View file

@ -6,14 +6,16 @@ namespace Ryujinx.Ui
{
public bool VSyncEnabled;
public string DockedMode;
public string AspectRatio;
public string GameStatus;
public string FifoStatus;
public string GpuName;
public StatusUpdatedEventArgs(bool vSyncEnabled, string dockedMode, string gameStatus, string fifoStatus, string gpuName)
public StatusUpdatedEventArgs(bool vSyncEnabled, string dockedMode, string aspectRatio, string gameStatus, string fifoStatus, string gpuName)
{
VSyncEnabled = vSyncEnabled;
DockedMode = dockedMode;
AspectRatio = aspectRatio;
GameStatus = gameStatus;
FifoStatus = fifoStatus;
GpuName = gpuName;

View file

@ -941,6 +941,21 @@
16
]
},
"aspect_ratio": {
"$id": "#/properties/aspect_ratio",
"type": "string",
"title": "Aspect Ratio applied to the renderer window.",
"description": "Aspect Ratio applied to the renderer window.",
"default": "Fixed16x9",
"examples": [
"Fixed4x3",
"Fixed16x9",
"Fixed16x10",
"Fixed21x9",
"Fixed32x9",
"Stretched"
]
},
"graphics_shaders_dump_path": {
"$id": "#/properties/graphics_shaders_dump_path",
"type": "string",