2008-01-24 09:14:08 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Licensed under the MIT/X11 license.
|
|
|
|
|
* Copyright (c) 2006-2008 the OpenTK team.
|
|
|
|
|
* This notice may not be removed.
|
|
|
|
|
* See license.txt for licensing detailed licensing details.
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
namespace OpenTK.Platform.Windows
|
|
|
|
|
{
|
|
|
|
|
internal class WinDisplayDeviceDriver : IDisplayDeviceDriver
|
|
|
|
|
{
|
|
|
|
|
static object display_lock = new object();
|
2008-01-24 10:50:39 +00:00
|
|
|
|
static Dictionary<OpenTK.Graphics.DisplayDevice, string> available_device_names =
|
|
|
|
|
new Dictionary<OpenTK.Graphics.DisplayDevice, string>(); // Needed for ChangeDisplaySettingsEx
|
2008-01-24 09:14:08 +00:00
|
|
|
|
|
|
|
|
|
#region --- Constructors ---
|
|
|
|
|
|
|
|
|
|
static WinDisplayDeviceDriver()
|
|
|
|
|
{
|
|
|
|
|
lock (display_lock)
|
|
|
|
|
{
|
|
|
|
|
// To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice
|
|
|
|
|
// we only allow settings to be set through its constructor.
|
|
|
|
|
// Thus, we save all necessary parameters in temporary variables
|
|
|
|
|
// and construct the device when every needed detail is available.
|
|
|
|
|
OpenTK.Graphics.DisplayDevice opentk_dev;
|
|
|
|
|
DisplayResolution opentk_dev_current_res = null;
|
|
|
|
|
List<DisplayResolution> opentk_dev_available_res = new List<DisplayResolution>();
|
|
|
|
|
bool opentk_dev_primary = false;
|
|
|
|
|
int device_count = 0, mode_count = 0;
|
|
|
|
|
|
|
|
|
|
// Get available video adapters and enumerate all monitors
|
|
|
|
|
DisplayDevice dev1 = new DisplayDevice(), dev2 = new DisplayDevice();
|
|
|
|
|
while (Functions.EnumDisplayDevices(null, device_count++, dev1, 0))
|
|
|
|
|
{
|
2008-01-24 09:30:49 +00:00
|
|
|
|
if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.None)
|
2008-01-24 09:14:08 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
DeviceMode monitor_mode = new DeviceMode();
|
|
|
|
|
|
|
|
|
|
// The second function should only be executed when the first one fails
|
|
|
|
|
// (e.g. when the monitor is disabled)
|
|
|
|
|
if (Functions.EnumDisplaySettings(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.CurrentSettings, monitor_mode) ||
|
|
|
|
|
Functions.EnumDisplaySettings(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.RegistrySettings, monitor_mode))
|
|
|
|
|
{
|
|
|
|
|
opentk_dev_current_res = new DisplayResolution(monitor_mode.PelsWidth, monitor_mode.PelsHeight,
|
|
|
|
|
monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);
|
|
|
|
|
opentk_dev_primary =
|
|
|
|
|
(dev1.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opentk_dev_available_res.Clear();
|
|
|
|
|
mode_count = 0;
|
|
|
|
|
while (Functions.EnumDisplaySettings(dev1.DeviceName.ToString(), mode_count++, monitor_mode))
|
|
|
|
|
{
|
|
|
|
|
DisplayResolution res = new DisplayResolution(
|
|
|
|
|
monitor_mode.PelsWidth, monitor_mode.PelsHeight,
|
|
|
|
|
monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);
|
|
|
|
|
|
|
|
|
|
opentk_dev_available_res.Add(res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Construct the OpenTK DisplayDevice through the accumulated parameters.
|
|
|
|
|
opentk_dev = new OpenTK.Graphics.DisplayDevice(opentk_dev_current_res, opentk_dev_primary,
|
|
|
|
|
opentk_dev_available_res);
|
2008-01-24 10:50:39 +00:00
|
|
|
|
|
|
|
|
|
available_device_names.Add(opentk_dev, dev1.DeviceName);
|
2008-01-24 09:14:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public WinDisplayDeviceDriver()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- IDisplayDeviceDriver Members ---
|
|
|
|
|
|
2008-01-24 10:50:39 +00:00
|
|
|
|
#region public bool TryChangeResolution(OpenTK.Graphics.DisplayDevice device, DisplayResolution resolution)
|
2008-01-24 09:14:08 +00:00
|
|
|
|
|
2008-01-24 10:50:39 +00:00
|
|
|
|
public bool TryChangeResolution(OpenTK.Graphics.DisplayDevice device, DisplayResolution resolution)
|
2008-01-24 09:14:08 +00:00
|
|
|
|
{
|
2008-01-24 10:50:39 +00:00
|
|
|
|
DeviceMode mode = new DeviceMode();
|
|
|
|
|
mode.PelsWidth = resolution.Width;
|
|
|
|
|
mode.PelsHeight = resolution.Height;
|
|
|
|
|
mode.BitsPerPel = resolution.BitsPerPixel;
|
|
|
|
|
mode.DisplayFrequency = (int)resolution.RefreshRate;
|
|
|
|
|
mode.Fields = Constants.DM_BITSPERPEL
|
2008-01-24 09:14:08 +00:00
|
|
|
|
| Constants.DM_PELSWIDTH
|
2008-01-24 10:50:39 +00:00
|
|
|
|
| Constants.DM_PELSHEIGHT
|
|
|
|
|
| Constants.DM_DISPLAYFREQUENCY;
|
2008-01-24 09:14:08 +00:00
|
|
|
|
|
2008-01-24 10:50:39 +00:00
|
|
|
|
//return Functions.ChangeDisplaySettings(settings, ChangeDisplaySettingsEnum.Fullscreen) ==
|
|
|
|
|
// Constants.DISP_CHANGE_SUCCESSFUL;
|
|
|
|
|
return Functions.ChangeDisplaySettingsEx(available_device_names[device], mode, IntPtr.Zero, 0, IntPtr.Zero) ==
|
2008-01-24 09:14:08 +00:00
|
|
|
|
Constants.DISP_CHANGE_SUCCESSFUL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-24 10:50:39 +00:00
|
|
|
|
#region public void RestoreResolution(OpenTK.Graphics.DisplayDevice device)
|
2008-01-24 09:14:08 +00:00
|
|
|
|
|
2008-01-24 10:50:39 +00:00
|
|
|
|
public void RestoreResolution(OpenTK.Graphics.DisplayDevice device)
|
2008-01-24 09:14:08 +00:00
|
|
|
|
{
|
2008-01-24 10:50:39 +00:00
|
|
|
|
//Functions.ChangeDisplaySettings(null, (ChangeDisplaySettingsEnum)0);
|
|
|
|
|
Functions.ChangeDisplaySettingsEx(available_device_names[device], null, IntPtr.Zero, 0, IntPtr.Zero);
|
2008-01-24 09:14:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public DisplayDevice[] AvailableDevices
|
|
|
|
|
|
|
|
|
|
public OpenTK.Graphics.DisplayDevice[] AvailableDevices
|
|
|
|
|
{
|
|
|
|
|
get { return null; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|