From 5f6c8e654c583b377dd67f8d61f4e157f835f1d4 Mon Sep 17 00:00:00 2001 From: cwassall Date: Sun, 19 Jan 2014 19:44:12 +0000 Subject: [PATCH 1/2] Remember DisplayDevice original resolutions When refreshing the AvailableDevices list, it is important to set the original resolution on any DisplayDevices that were previously available to allow the RestoreResolution() method to work correctly. --- Source/OpenTK/DisplayDevice.cs | 3 ++- Source/OpenTK/Platform/Windows/WinDisplayDevice.cs | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/OpenTK/DisplayDevice.cs b/Source/OpenTK/DisplayDevice.cs index b90a3273..d6bf0837 100644 --- a/Source/OpenTK/DisplayDevice.cs +++ b/Source/OpenTK/DisplayDevice.cs @@ -47,7 +47,8 @@ namespace OpenTK bool primary; Rectangle bounds; - DisplayResolution current_resolution = new DisplayResolution(), original_resolution; + DisplayResolution current_resolution = new DisplayResolution(); + internal DisplayResolution original_resolution; List available_resolutions = new List(); IList available_resolutions_readonly; diff --git a/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs b/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs index 2ff578f7..56da3668 100644 --- a/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs +++ b/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs @@ -96,6 +96,10 @@ namespace OpenTK.Platform.Windows { lock (display_lock) { + // Store an array of the current available DisplayDevice objects. + // This is needed to preserve the original_resolution. + DisplayDevice[] previousDevices = AvailableDevices.ToArray(); + AvailableDevices.Clear(); // We save all necessary parameters in temporary variables @@ -159,6 +163,11 @@ namespace OpenTK.Platform.Windows opentk_dev_current_res.Bounds, dev1.DeviceName); + // Set the original_resolution if the DisplayDevice was previously available. + foreach (DisplayDevice existingDevice in previousDevices) + if ((string)existingDevice.Id == (string)opentk_dev.Id) + opentk_dev.original_resolution = existingDevice.original_resolution; + AvailableDevices.Add(opentk_dev); if (opentk_dev_primary) From 7b591962e888f18cc4f098d0c369867cbd56aff7 Mon Sep 17 00:00:00 2001 From: cwassall Date: Mon, 20 Jan 2014 12:51:55 +0000 Subject: [PATCH 2/2] Change original_resolution field to a property As the original_resolution field needs to be accessed from outside the module, it should be an internal property as opposed to an internal field --- Source/OpenTK/DisplayDevice.cs | 19 ++++++++++++++++++- .../Platform/Windows/WinDisplayDevice.cs | 6 +++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Source/OpenTK/DisplayDevice.cs b/Source/OpenTK/DisplayDevice.cs index d6bf0837..4e8c7a3d 100644 --- a/Source/OpenTK/DisplayDevice.cs +++ b/Source/OpenTK/DisplayDevice.cs @@ -48,7 +48,7 @@ namespace OpenTK bool primary; Rectangle bounds; DisplayResolution current_resolution = new DisplayResolution(); - internal DisplayResolution original_resolution; + DisplayResolution original_resolution; List available_resolutions = new List(); IList available_resolutions_readonly; @@ -336,6 +336,23 @@ namespace OpenTK #endregion + #region --- Internal Methods --- + + #region internal DisplayResolution OriginalResolution + + /// + /// Gets the original resolution of this instance. + /// + internal DisplayResolution OriginalResolution + { + get { return original_resolution; } + set { original_resolution = value; } + } + + #endregion + + #endregion + #region --- Private Methods --- #region DisplayResolution FindResolution(int width, int height, int bitsPerPixel, float refreshRate) diff --git a/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs b/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs index 56da3668..fc594b63 100644 --- a/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs +++ b/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs @@ -97,7 +97,7 @@ namespace OpenTK.Platform.Windows lock (display_lock) { // Store an array of the current available DisplayDevice objects. - // This is needed to preserve the original_resolution. + // This is needed to preserve the original resolution. DisplayDevice[] previousDevices = AvailableDevices.ToArray(); AvailableDevices.Clear(); @@ -163,10 +163,10 @@ namespace OpenTK.Platform.Windows opentk_dev_current_res.Bounds, dev1.DeviceName); - // Set the original_resolution if the DisplayDevice was previously available. + // Set the original resolution if the DisplayDevice was previously available. foreach (DisplayDevice existingDevice in previousDevices) if ((string)existingDevice.Id == (string)opentk_dev.Id) - opentk_dev.original_resolution = existingDevice.original_resolution; + opentk_dev.OriginalResolution = existingDevice.OriginalResolution; AvailableDevices.Add(opentk_dev);