mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-25 15:35:28 +00:00
Changed IDisplayDeviceDriver.RestoreResolution method to IDisplayDeviceDriver.TryRestoreResolution.
DisplayDevice now correctly reports original resolution.
This commit is contained in:
parent
55dd09a450
commit
58ae48833c
|
@ -25,7 +25,7 @@ namespace OpenTK.Graphics
|
||||||
// TODO: Does not detect changes to primary device.
|
// TODO: Does not detect changes to primary device.
|
||||||
// TODO: Mono does not support System.Windows.Forms.Screen.BitsPerPixel -- find workaround!
|
// TODO: Mono does not support System.Windows.Forms.Screen.BitsPerPixel -- find workaround!
|
||||||
|
|
||||||
DisplayResolution current_resolution;
|
DisplayResolution current_resolution, original_resolution;
|
||||||
List<DisplayResolution> available_resolutions = new List<DisplayResolution>();
|
List<DisplayResolution> available_resolutions = new List<DisplayResolution>();
|
||||||
bool primary;
|
bool primary;
|
||||||
|
|
||||||
|
@ -183,18 +183,21 @@ namespace OpenTK.Graphics
|
||||||
/// <param name="height">The new height of the DisplayDevice.</param>
|
/// <param name="height">The new height of the DisplayDevice.</param>
|
||||||
/// <param name="bitsPerPixel">The new bits per pixel of the DisplayDevice.</param>
|
/// <param name="bitsPerPixel">The new bits per pixel of the DisplayDevice.</param>
|
||||||
/// <param name="refreshRate">The new refresh rate of the DisplayDevice.</param>
|
/// <param name="refreshRate">The new refresh rate of the DisplayDevice.</param>
|
||||||
/// <exception cref="GraphicsModeException">Thrown if the requested resolution change failed.</exception>
|
/// <exception cref="GraphicsModeException">Thrown if the requested resolution could not be set.</exception>
|
||||||
public void ChangeResolution(DisplayResolution resolution)
|
public void ChangeResolution(DisplayResolution resolution)
|
||||||
{
|
{
|
||||||
if (resolution == null)
|
if (resolution == null)
|
||||||
throw new ArgumentNullException("resulotion", "Must be a valid resolution.");
|
throw new ArgumentNullException("resulotion", "Must be a valid resolution.");
|
||||||
|
if (resolution == current_resolution)
|
||||||
|
return;
|
||||||
|
|
||||||
if (implementation.TryChangeResolution(this, resolution))
|
if (implementation.TryChangeResolution(this, resolution))
|
||||||
{
|
{
|
||||||
|
if (original_resolution == null)
|
||||||
|
original_resolution = current_resolution;
|
||||||
current_resolution = resolution;
|
current_resolution = resolution;
|
||||||
}
|
}
|
||||||
else
|
else throw new GraphicsModeException(String.Format("Device {0}: Failed to change resolution to {1}.",
|
||||||
throw new GraphicsModeException(String.Format("Device {0}: Failed to change resolution to {1}.",
|
|
||||||
this, resolution));
|
this, resolution));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,9 +205,14 @@ namespace OpenTK.Graphics
|
||||||
|
|
||||||
#region public void RestoreResolution()
|
#region public void RestoreResolution()
|
||||||
|
|
||||||
|
/// <summary>Restores the original resolution of the DisplayDevice.</summary>
|
||||||
|
/// <exception cref="GraphicsModeException">Thrown if the original resolution could not be restored.</exception>
|
||||||
public void RestoreResolution()
|
public void RestoreResolution()
|
||||||
{
|
{
|
||||||
implementation.RestoreResolution(this);
|
if (original_resolution != null)
|
||||||
|
if (implementation.TryRestoreResolution(this))
|
||||||
|
current_resolution = original_resolution;
|
||||||
|
else throw new GraphicsModeException(String.Format("Device {0}: Failed to restore resolution.", this));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace OpenTK.Graphics
|
||||||
internal interface IDisplayDeviceDriver
|
internal interface IDisplayDeviceDriver
|
||||||
{
|
{
|
||||||
bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution);
|
bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution);
|
||||||
void RestoreResolution(DisplayDevice device);
|
bool TryRestoreResolution(DisplayDevice device);
|
||||||
//DisplayDevice[] AvailableDevices { get; }
|
//DisplayDevice[] AvailableDevices { get; }
|
||||||
//DisplayResolution[]
|
//DisplayResolution[]
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,30 +95,31 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
public bool TryChangeResolution(OpenTK.Graphics.DisplayDevice device, DisplayResolution resolution)
|
public bool TryChangeResolution(OpenTK.Graphics.DisplayDevice device, DisplayResolution resolution)
|
||||||
{
|
{
|
||||||
DeviceMode mode = new DeviceMode();
|
DeviceMode mode = null;
|
||||||
mode.PelsWidth = resolution.Width;
|
if (resolution != null)
|
||||||
mode.PelsHeight = resolution.Height;
|
{
|
||||||
mode.BitsPerPel = resolution.BitsPerPixel;
|
mode = new DeviceMode();
|
||||||
mode.DisplayFrequency = (int)resolution.RefreshRate;
|
mode.PelsWidth = resolution.Width;
|
||||||
mode.Fields = Constants.DM_BITSPERPEL
|
mode.PelsHeight = resolution.Height;
|
||||||
| Constants.DM_PELSWIDTH
|
mode.BitsPerPel = resolution.BitsPerPixel;
|
||||||
| Constants.DM_PELSHEIGHT
|
mode.DisplayFrequency = (int)resolution.RefreshRate;
|
||||||
| Constants.DM_DISPLAYFREQUENCY;
|
mode.Fields = Constants.DM_BITSPERPEL
|
||||||
|
| Constants.DM_PELSWIDTH
|
||||||
|
| Constants.DM_PELSHEIGHT
|
||||||
|
| Constants.DM_DISPLAYFREQUENCY;
|
||||||
|
}
|
||||||
|
|
||||||
//return Functions.ChangeDisplaySettings(settings, ChangeDisplaySettingsEnum.Fullscreen) ==
|
return Constants.DISP_CHANGE_SUCCESSFUL ==
|
||||||
// Constants.DISP_CHANGE_SUCCESSFUL;
|
Functions.ChangeDisplaySettingsEx(available_device_names[device], mode, IntPtr.Zero, 0, IntPtr.Zero);
|
||||||
return Functions.ChangeDisplaySettingsEx(available_device_names[device], mode, IntPtr.Zero, 0, IntPtr.Zero) ==
|
|
||||||
Constants.DISP_CHANGE_SUCCESSFUL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region public void RestoreResolution(OpenTK.Graphics.DisplayDevice device)
|
#region public TryRestoreResolution TryRestoreResolution(OpenTK.Graphics.DisplayDevice device)
|
||||||
|
|
||||||
public void RestoreResolution(OpenTK.Graphics.DisplayDevice device)
|
public bool TryRestoreResolution(OpenTK.Graphics.DisplayDevice device)
|
||||||
{
|
{
|
||||||
//Functions.ChangeDisplaySettings(null, (ChangeDisplaySettingsEnum)0);
|
return TryChangeResolution(device, null);
|
||||||
Functions.ChangeDisplaySettingsEx(available_device_names[device], null, IntPtr.Zero, 0, IntPtr.Zero);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -165,9 +165,9 @@ namespace OpenTK.Platform.X11
|
||||||
current_rotation, (short)(resolution != null ? resolution.RefreshRate : 0), lastConfigUpdate[screen]);
|
current_rotation, (short)(resolution != null ? resolution.RefreshRate : 0), lastConfigUpdate[screen]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RestoreResolution(DisplayDevice device)
|
public bool TryRestoreResolution(DisplayDevice device)
|
||||||
{
|
{
|
||||||
TryChangeResolution(device, null);
|
return TryChangeResolution(device, null);
|
||||||
//System.Diagnostics.Process.Start("xrandr", "-s -0").WaitForExit(); // Hack, but works ;)
|
//System.Diagnostics.Process.Start("xrandr", "-s -0").WaitForExit(); // Hack, but works ;)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue