コード例 #1
0
            new Dictionary<DisplayDevice, string>();    // Needed for ChangeDisplaySettingsEx
        #region --- Constructors ---

        /// <summary>Queries available display devices and display resolutions.</summary>
        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.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                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
                WindowsDisplayDevice dev1 = new WindowsDisplayDevice(), dev2 = new WindowsDisplayDevice();
                while (Functions.EnumDisplayDevices(null, device_count++, dev1, 0))
                {
                    if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.None)
                        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.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.CurrentSettings, monitor_mode, 0) ||
                        Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.RegistrySettings, monitor_mode, 0))
                    {
                        opentk_dev_current_res = new DisplayResolution(
                            monitor_mode.Position.X, monitor_mode.Position.Y,
                            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.Position.X, monitor_mode.Position.Y,
                            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.
                    // The constructor will automatically add the DisplayDevice to the list
                    // of available devices.
                    opentk_dev = new DisplayDevice(
                        opentk_dev_current_res,
                        opentk_dev_primary,
                        opentk_dev_available_res,
                        opentk_dev_current_res.Bounds);
                    available_device_names.Add(opentk_dev, dev1.DeviceName);
                }
            }
        }
コード例 #2
0
        public bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
        {
            DeviceMode mode = null;

            if (resolution != null)
            {
                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 | Constants.DM_PELSWIDTH
                                        | Constants.DM_PELSHEIGHT | Constants.DM_DISPLAYFREQUENCY;
            }

            return(Constants.DISP_CHANGE_SUCCESSFUL ==
                   API.ChangeDisplaySettingsEx(available_device_names[device], mode, IntPtr.Zero,
                                               ChangeDisplaySettingsEnum.Fullscreen, IntPtr.Zero));
        }
コード例 #3
0
        public bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
        {
            IntPtr display = displayMap[device];
            IntPtr currentModePtr = CG.DisplayCurrentMode(display);

            if (storedModes.ContainsKey(display) == false)
            {
                storedModes.Add(display, currentModePtr);        
            }

            IntPtr displayModesPtr = CG.DisplayAvailableModes(display);
            CFArray displayModes = new CFArray(displayModesPtr);

            for (int j = 0; j < displayModes.Count; j++)
            {
                CFDictionary dict = new CFDictionary(displayModes[j]);

                int width = (int)dict.GetNumberValue("Width");
                int height = (int)dict.GetNumberValue("Height");
                int bpp = (int)dict.GetNumberValue("BitsPerPixel");
                double freq = dict.GetNumberValue("RefreshRate");

                if (width == resolution.Width &&
                    height == resolution.Height &&
                    bpp == resolution.BitsPerPixel &&
                    System.Math.Abs(freq - resolution.RefreshRate) < 1e-6)
                {
                    if (displaysCaptured.Contains(display) == false)
                    {
                        CG.DisplayCapture(display);
                    }

                    Debug.Print("Changing resolution to {0}x{1}x{2}@{3}.", width, height, bpp, freq);

                    CG.DisplaySwitchToMode(display, displayModes[j]);

                    return true;
                }

            }
            return false;
        }
コード例 #4
0
        private unsafe void AddDisplay(LinuxDisplay display)
        {
            DisplayResolution[] modes = new DisplayResolution[display.pConnector->count_modes];
            DisplayResolution   current;

            GetModes(display, modes, out current);

            bool          is_primary = AvailableDevices.Count == 0;
            DisplayDevice device     = new DisplayDevice(current, is_primary,
                                                         modes, GetBounds(current), display);

            if (is_primary)
            {
                Primary = device;
            }

            UpdateDisplayIndices(display, device);

            Debug.Print("[KMS] Added DisplayDevice {0}", device);
        }
コード例 #5
0
        /// <summary>
        /// Converts the given resolution value to a user-friendly display string.
        /// </summary>
        /// <param name="resolution">The resolution to convert.</param>
        /// <returns>The display string.</returns>
        public static string ToDisplayString(this DisplayResolution resolution)
        {
            var displayString = string.Empty;

            switch (resolution)
            {
            case DisplayResolution.Resolution320x200x8bpp:
                displayString = "320x200, 8 bit";
                break;

            case DisplayResolution.Resolution640x480x8bpp:
                displayString = "640x480, 8 bit";
                break;

            case DisplayResolution.Resolution1024x768x8bpp:
                displayString = "1024x768, 8 bit";
                break;

            case DisplayResolution.Resolution1680x1050x8bpp:
                displayString = "1680x1050, 8 bit";
                break;

            case DisplayResolution.Resolution800x400x16bpp:
                displayString = "800x400, 16 bit";
                break;

            case DisplayResolution.Resolution1600x1200x32bpp:
                displayString = "1600x1200, 32 bit";
                break;

            case DisplayResolution.Resolution3280x1200x32bpp:
                displayString = "3280x1200, 32 bit";
                break;

            case DisplayResolution.Resolution320x240x16bpp:
            default:
                displayString = "320x240, 16 bit";
                break;
            }
            return(displayString);
        }
コード例 #6
0
        public Sdl2DisplayDeviceDriver()
        {
            int displays = SDL.GetNumVideoDisplays();

            for (int d = 0; d < displays; d++)
            {
                Rect bounds;
                SDL.GetDisplayBounds(d, out bounds);

                DisplayMode current_mode;
                SDL.GetCurrentDisplayMode(d, out current_mode);

                var mode_list = new List <DisplayResolution>();
                int num_modes = SDL.GetNumDisplayModes(d);
                for (int m = 0; m < num_modes; m++)
                {
                    DisplayMode sdl_mode;
                    SDL.GetDisplayMode(d, m, out sdl_mode);
                    mode_list.Add(new DisplayResolution(
                                      bounds.X, bounds.Y,
                                      sdl_mode.Width, sdl_mode.Height,
                                      TranslateFormat(sdl_mode.Format),
                                      sdl_mode.RefreshRate));
                }

                var current_resolution = new DisplayResolution(
                    bounds.X, bounds.Y,
                    current_mode.Width, current_mode.Height,
                    TranslateFormat(current_mode.Format),
                    current_mode.RefreshRate);

                var device = new DisplayDevice(
                    current_resolution, d == 0, mode_list, TranslateBounds(bounds), d);

                AvailableDevices.Add(device);
                if (d == 0)
                {
                    Primary = device;
                }
            }
        }
コード例 #7
0
        public sealed override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
        {
            DeviceMode mode = null;

            if (resolution != null)
            {
                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
                    | Constants.DM_PELSWIDTH
                    | Constants.DM_PELSHEIGHT
                    | Constants.DM_DISPLAYFREQUENCY;
            }

            return Constants.DISP_CHANGE_SUCCESSFUL == 
                Functions.ChangeDisplaySettingsEx((string)device.Id, mode, IntPtr.Zero,
                    ChangeDisplaySettingsEnum.Fullscreen, IntPtr.Zero);
        }
コード例 #8
0
        public override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
        {
            var display        = HandleTo(device);
            var currentModePtr = CG.DisplayCurrentMode(display);

            if (storedModes.ContainsKey(display) == false)
            {
                storedModes.Add(display, currentModePtr);
            }

            var displayModesPtr = CG.DisplayAvailableModes(display);
            var displayModes    = new CFArray(displayModesPtr);

            for (var j = 0; j < displayModes.Count; j++)
            {
                var dict = new CFDictionary(displayModes[j]);

                var width  = (int)dict.GetNumberValue("Width");
                var height = (int)dict.GetNumberValue("Height");
                var bpp    = (int)dict.GetNumberValue("BitsPerPixel");
                var freq   = dict.GetNumberValue("RefreshRate");

                if (width == resolution.Width && height == resolution.Height && bpp == resolution.BitsPerPixel &&
                    Math.Abs(freq - resolution.RefreshRate) < 1e-6)
                {
//                    if (displaysCaptured.Contains(display) == false)
//                    {
//                        CG.DisplayCapture(display);
//                    }

                    Debug.Print("Changing resolution to {0}x{1}x{2}@{3}.", width, height, bpp, freq);

                    CG.DisplaySwitchToMode(display, displayModes[j]);

                    return(true);
                }
            }

            return(false);
        }
コード例 #9
0
        public Sdl2DisplayDeviceDriver()
        {
            int displays = SDL.GetNumVideoDisplays();
            for (int d = 0; d < displays; d++)
            {
                Rect bounds;
                SDL.GetDisplayBounds(d, out bounds);

                DisplayMode current_mode;
                SDL.GetCurrentDisplayMode(d, out current_mode);

                var mode_list = new List<DisplayResolution>();
                int num_modes = SDL.GetNumDisplayModes(d);
                for (int m = 0; m < num_modes; m++)
                {
                    DisplayMode sdl_mode;
                    SDL.GetDisplayMode(d, m, out sdl_mode);
                    mode_list.Add(new DisplayResolution(
                        bounds.X, bounds.Y,
                        sdl_mode.Width, sdl_mode.Height,
                        TranslateFormat(sdl_mode.Format),
                        sdl_mode.RefreshRate));
                }

                var current_resolution = new DisplayResolution(
                    bounds.X, bounds.Y,
                    current_mode.Width, current_mode.Height,
                    TranslateFormat(current_mode.Format),
                    current_mode.RefreshRate);

                var device = new DisplayDevice(
                    current_resolution, d == 0, mode_list, TranslateBounds(bounds), d);

                AvailableDevices.Add(device);
                if (d == 0)
                    Primary = device;
            }
        }
コード例 #10
0
 public void RefreshDisplayDevices()
 {
     lock (this.display_lock)
     {
         this.AvailableDevices.Clear();
         DisplayResolution        local_1 = (DisplayResolution)null;
         List <DisplayResolution> local_2 = new List <DisplayResolution>();
         bool local_3 = false;
         int  local_4 = 0;
         WindowsDisplayDevice local_6 = new WindowsDisplayDevice();
         WindowsDisplayDevice temp_10 = new WindowsDisplayDevice();
         while (Functions.EnumDisplayDevices((string)null, local_4++, local_6, 0))
         {
             if ((local_6.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) != DisplayDeviceStateFlags.None)
             {
                 DeviceMode local_7 = new DeviceMode();
                 if (Functions.EnumDisplaySettingsEx(((object)local_6.DeviceName).ToString(), DisplayModeSettingsEnum.CurrentSettings, local_7, 0) || Functions.EnumDisplaySettingsEx(((object)local_6.DeviceName).ToString(), DisplayModeSettingsEnum.RegistrySettings, local_7, 0))
                 {
                     local_1 = new DisplayResolution(local_7.Position.X, local_7.Position.Y, local_7.PelsWidth, local_7.PelsHeight, local_7.BitsPerPel, (float)local_7.DisplayFrequency);
                     local_3 = (local_6.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None;
                 }
                 local_2.Clear();
                 int local_5_1 = 0;
                 while (Functions.EnumDisplaySettings(((object)local_6.DeviceName).ToString(), local_5_1++, local_7))
                 {
                     DisplayResolution local_8 = new DisplayResolution(local_7.Position.X, local_7.Position.Y, local_7.PelsWidth, local_7.PelsHeight, local_7.BitsPerPel, (float)local_7.DisplayFrequency);
                     local_2.Add(local_8);
                 }
                 DisplayDevice local_0 = new DisplayDevice(local_1, local_3, (IEnumerable <DisplayResolution>)local_2, local_1.Bounds, (object)local_6.DeviceName);
                 this.AvailableDevices.Add(local_0);
                 if (local_3)
                 {
                     this.Primary = local_0;
                 }
             }
         }
     }
 }
コード例 #11
0
ファイル: Settings.cs プロジェクト: joecons97/Voxel.Net
        public void ApplyWindowSettings(DisplayResolution res, bool fullscreen)
        {
            Fullscreen   = fullscreen;
            WindowWidth  = res.Width;
            WindowHeight = res.Height;
            RefreshRate  = res.RefreshRate;
            BitsPerPixel = res.BitsPerPixel;

            Program.Window.ClientSize      = new System.Drawing.Size(WindowWidth, WindowHeight);
            Program.Window.ClientRectangle = new System.Drawing.Rectangle(0, 0, WindowWidth, WindowHeight);

            if (Fullscreen)
            {
                DisplayDevice.GetDisplay(DisplayIndex.Default).ChangeResolution(res);
            }
            else
            {
                DisplayDevice.GetDisplay(DisplayIndex.Default).RestoreResolution();
            }

            Program.Window.WindowState = Fullscreen ? OpenTK.WindowState.Fullscreen : OpenTK.WindowState.Normal;

            Save();
        }
コード例 #12
0
        internal unsafe static void Init()
        {
            // 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.
            // The main DisplayDevice constructor adds the newly constructed device
            // to the list of available devices.
            const int maxDisplayCount = 20;

            IntPtr[] displays = new IntPtr[maxDisplayCount];
            int      displayCount;

            fixed(IntPtr *displayPtr = displays)
            {
                CG.CGGetActiveDisplayList(maxDisplayCount, displayPtr, out displayCount);
            }

            Debug.Print("CoreGraphics reported {0} display(s).", displayCount);

            for (int i = 0; i < displayCount; i++)
            {
                IntPtr curDisplay = displays[i];

                // according to docs, first element in the array is always the main display.
                bool primary = (i == 0);
                if (primary)
                {
                    mainDisplay = curDisplay;
                }

                // gets current settings
                int currentWidth  = CG.CGDisplayPixelsWide(curDisplay);
                int currentHeight = CG.CGDisplayPixelsHigh(curDisplay);
                Debug.Print("Display {0} is at  {1}x{2}", i, currentWidth, currentHeight);

                IntPtr  displayModesPtr = CG.CGDisplayAvailableModes(curDisplay);
                CFArray displayModes    = new CFArray(displayModesPtr);
                Debug.Print("Supports {0} display modes.", displayModes.Count);

                DisplayResolution opentk_dev_current_res = null;
                IntPtr            currentModePtr         = CG.CGDisplayCurrentMode(curDisplay);
                CFDictionary      currentMode            = new CFDictionary(currentModePtr);

                for (int j = 0; j < displayModes.Count; j++)
                {
                    CFDictionary dict = new CFDictionary(displayModes[j]);

                    int    width   = (int)dict.GetNumberValue("Width");
                    int    height  = (int)dict.GetNumberValue("Height");
                    int    bpp     = (int)dict.GetNumberValue("BitsPerPixel");
                    double freq    = dict.GetNumberValue("RefreshRate");
                    bool   current = currentMode.DictRef == dict.DictRef;

                    if (current)
                    {
                        opentk_dev_current_res = new DisplayResolution(width, height, bpp, (float)freq);
                    }
                }

                HIRect    bounds  = CG.CGDisplayBounds(curDisplay);
                Rectangle newRect = new Rectangle(
                    (int)bounds.Origin.X, (int)bounds.Origin.Y, (int)bounds.Size.X, (int)bounds.Size.Y);

                Debug.Print("Display {0} bounds: {1}", i, newRect);

                DisplayDevice opentk_dev = new DisplayDevice(opentk_dev_current_res, primary);
                opentk_dev.Bounds   = newRect;
                opentk_dev.Metadata = curDisplay;
            }
        }
コード例 #13
0
            new Dictionary <DisplayDevice, string>();            // Needed for ChangeDisplaySettingsEx

        /// <summary>Queries available display devices and display resolutions.</summary>
        static WinDisplayDeviceDriver()
        {
            // 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.
            // The main DisplayDevice constructor adds the newly constructed device
            // to the list of available devices.
            DisplayResolution        currentRes   = null;
            List <DisplayResolution> availableRes = new List <DisplayResolution>();
            bool devPrimary = false;
            int  deviceNum  = 0;

            // Get available video adapters and enumerate all monitors
            WindowsDisplayDevice winDev = new WindowsDisplayDevice();

            while (API.EnumDisplayDevices(null, deviceNum++, winDev, 0))
            {
                if ((winDev.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == 0)
                {
                    continue;
                }

                DeviceMode mode = new DeviceMode();

                // The second function should only be executed when the first one fails (e.g. when the monitor is disabled)
                if (API.EnumDisplaySettings(winDev.DeviceName, (int)DisplayModeSettings.Current, mode) ||
                    API.EnumDisplaySettings(winDev.DeviceName, (int)DisplayModeSettings.Registry, mode))
                {
                    if (mode.BitsPerPel > 0)
                    {
                        currentRes = new DisplayResolution(
                            mode.Position.X, mode.Position.Y,
                            mode.PelsWidth, mode.PelsHeight,
                            mode.BitsPerPel, mode.DisplayFrequency);
                        devPrimary = (winDev.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != 0;
                    }
                }

                availableRes.Clear();
                int i = 0;
                while (API.EnumDisplaySettings(winDev.DeviceName, i++, mode))
                {
                    // For example, the device \.\DISPLAYV1 returns a single resolution with bits per pixel of 0
                    // We must skip these resolutions
                    if (mode.BitsPerPel <= 0)
                    {
                        continue;
                    }

                    availableRes.Add(new DisplayResolution(
                                         mode.Position.X, mode.Position.Y,
                                         mode.PelsWidth, mode.PelsHeight,
                                         mode.BitsPerPel, mode.DisplayFrequency));
                }

                // This device has no valid resolutions, ignore it
                if (availableRes.Count == 0 || currentRes == null)
                {
                    continue;
                }

                // Construct the OpenTK DisplayDevice through the accumulated parameters.
                // The constructor automatically adds the DisplayDevice to the list of available devices.
                DisplayDevice device = new DisplayDevice(currentRes, devPrimary, availableRes, currentRes.Bounds);
                available_device_names.Add(device, winDev.DeviceName);
                currentRes = null;
            }
        }
コード例 #14
0
            new Dictionary <DisplayDevice, string>();    // Needed for ChangeDisplaySettingsEx

        #region --- Constructors ---

        /// <summary>Queries available display devices and display resolutions.</summary>
        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.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                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
                WindowsDisplayDevice dev1 = new WindowsDisplayDevice(), dev2 = new WindowsDisplayDevice();
                while (Functions.EnumDisplayDevices(null, device_count++, dev1, 0))
                {
                    if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.None)
                    {
                        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.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.CurrentSettings, monitor_mode, 0) ||
                        Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.RegistrySettings, monitor_mode, 0))
                    {
                        opentk_dev_current_res = new DisplayResolution(
                            monitor_mode.Position.X, monitor_mode.Position.Y,
                            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.Position.X, monitor_mode.Position.Y,
                            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.
                    // The constructor will automatically add the DisplayDevice to the list
                    // of available devices.
                    opentk_dev = new DisplayDevice(
                        opentk_dev_current_res,
                        opentk_dev_primary,
                        opentk_dev_available_res);

                    available_device_names.Add(opentk_dev, dev1.DeviceName);
                }
            }
        }
コード例 #15
0
        public QuartzDisplayDeviceDriver()
        {
            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.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                const int maxDisplayCount = 20;
                IntPtr[]  displays        = new IntPtr[maxDisplayCount];
                int       displayCount;

                unsafe
                {
                    fixed(IntPtr *displayPtr = displays)
                    {
                        CG.GetActiveDisplayList(maxDisplayCount, displayPtr, out displayCount);
                    }
                }

                Debug.Print("CoreGraphics reported {0} display(s).", displayCount);
                Debug.Indent();

                for (int i = 0; i < displayCount; i++)
                {
                    IntPtr currentDisplay = displays[i];

                    // according to docs, first element in the array is always the
                    // main display.
                    bool primary = (i == 0);

                    // gets current settings
                    int currentWidth  = CG.DisplayPixelsWide(currentDisplay);
                    int currentHeight = CG.DisplayPixelsHigh(currentDisplay);
                    Debug.Print("Display {0} is at  {1}x{2}", i, currentWidth, currentHeight);

                    IntPtr  displayModesPtr = CG.DisplayAvailableModes(currentDisplay);
                    CFArray displayModes    = new CFArray(displayModesPtr);
                    Debug.Print("Supports {0} display modes.", displayModes.Count);

                    DisplayResolution        opentk_dev_current_res   = null;
                    List <DisplayResolution> opentk_dev_available_res = new List <DisplayResolution>();
                    IntPtr       currentModePtr = CG.DisplayCurrentMode(currentDisplay);
                    CFDictionary currentMode    = new CFDictionary(currentModePtr);

                    for (int j = 0; j < displayModes.Count; j++)
                    {
                        CFDictionary dict = new CFDictionary(displayModes[j]);

                        int    width   = (int)dict.GetNumberValue("Width");
                        int    height  = (int)dict.GetNumberValue("Height");
                        int    bpp     = (int)dict.GetNumberValue("BitsPerPixel");
                        double freq    = dict.GetNumberValue("RefreshRate");
                        bool   current = currentMode.Ref == dict.Ref;

                        //if (current) Debug.Write("  * ");
                        //else Debug.Write("    ");

                        //Debug.Print("Mode {0} is {1}x{2}x{3} @ {4}.", j, width, height, bpp, freq);

                        DisplayResolution thisRes = new DisplayResolution(0, 0, width, height, bpp, (float)freq);
                        opentk_dev_available_res.Add(thisRes);

                        if (current)
                        {
                            opentk_dev_current_res = thisRes;
                        }
                    }

                    HIRect    bounds  = CG.DisplayBounds(currentDisplay);
                    Rectangle newRect = new Rectangle((int)bounds.Origin.X, (int)bounds.Origin.Y, (int)bounds.Size.Width, (int)bounds.Size.Height);

                    Debug.Print("Display {0} bounds: {1}", i, newRect);

                    DisplayDevice opentk_dev = new DisplayDevice(opentk_dev_current_res,
                                                                 primary, opentk_dev_available_res, newRect, currentDisplay);

                    AvailableDevices.Add(opentk_dev);

                    if (primary)
                    {
                        Primary = opentk_dev;
                    }
                }

                Debug.Unindent();
            }
        }
コード例 #16
0
 public bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution) => false;
コード例 #17
0
        static bool ChangeResolutionXRandR(DisplayDevice device, DisplayResolution resolution)
        {
            using (new XLock(API.DefaultDisplay))
            {
                int screen = deviceToScreen[device];
                IntPtr root = Functions.XRootWindow(API.DefaultDisplay, screen);
                IntPtr screen_config = Functions.XRRGetScreenInfo(API.DefaultDisplay, root);

                ushort current_rotation;
                int current_resolution_index = Functions.XRRConfigCurrentConfiguration(screen_config, out current_rotation);
                int new_resolution_index;
                if (resolution != null)
                    new_resolution_index = screenResolutionToIndex[screen]
                        [new DisplayResolution(0, 0, resolution.Width, resolution.Height, resolution.BitsPerPixel, 0)];
                else
                    new_resolution_index = deviceToDefaultResolution[device];

                Debug.Print("Changing size of screen {0} from {1} to {2}",
                    screen, current_resolution_index, new_resolution_index);

                return 0 == Functions.XRRSetScreenConfigAndRate(API.DefaultDisplay, screen_config, root, new_resolution_index,
                    current_rotation, (short)(resolution != null ? resolution.RefreshRate : 0), lastConfigUpdate[screen]);
            }
        }
コード例 #18
0
        public QuartzDisplayDeviceDriver()
        {
            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.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                const int maxDisplayCount = 20;
                var       displays        = new IntPtr[maxDisplayCount];
                int       displayCount;

                unsafe
                {
                    fixed(IntPtr *displayPtr = displays)
                    {
                        CG.GetActiveDisplayList(maxDisplayCount, displayPtr, out displayCount);
                    }
                }

                Debug.Print("CoreGraphics reported {0} display(s).", displayCount);
                Debug.Indent();

                for (var i = 0; i < displayCount; i++)
                {
                    var currentDisplay = displays[i];

                    // according to docs, first element in the array is always the
                    // main display.
                    var primary = i == 0;

                    // gets current settings
                    var currentWidth  = CG.DisplayPixelsWide(currentDisplay);
                    var currentHeight = CG.DisplayPixelsHigh(currentDisplay);
                    Debug.Print("Display {0} is at  {1}x{2}", i, currentWidth, currentHeight);

                    var displayModesPtr = CG.DisplayAvailableModes(currentDisplay);
                    var displayModes    = new CFArray(displayModesPtr);
                    Debug.Print("Supports {0} display modes.", displayModes.Count);

                    DisplayResolution opentk_dev_current_res = null;
                    var opentk_dev_available_res             = new List <DisplayResolution>();
                    var currentModePtr = CG.DisplayCurrentMode(currentDisplay);
                    var currentMode    = new CFDictionary(currentModePtr);

                    for (var j = 0; j < displayModes.Count; j++)
                    {
                        var dict = new CFDictionary(displayModes[j]);

                        var width   = (int)dict.GetNumberValue("Width");
                        var height  = (int)dict.GetNumberValue("Height");
                        var bpp     = (int)dict.GetNumberValue("BitsPerPixel");
                        var freq    = dict.GetNumberValue("RefreshRate");
                        var current = currentMode.Ref == dict.Ref;

                        if (freq <= 0)
                        {
                            IntPtr displayLink;
                            CV.DisplayLinkCreateWithCGDisplay(currentDisplay, out displayLink);

                            var t = CV.DisplayLinkGetNominalOutputVideoRefreshPeriod(displayLink);
                            if ((t.flags & (int)CV.TimeFlags.TimeIsIndefinite) != (int)CV.TimeFlags.TimeIsIndefinite)
                            {
                                freq = (double)t.timeScale / t.timeValue;
                            }

                            CV.DisplayLinkRelease(displayLink);
                        }

                        //if (current) Debug.Write("  * ");
                        //else Debug.Write("    ");

                        //Debug.Print("Mode {0} is {1}x{2}x{3} @ {4}.", j, width, height, bpp, freq);

                        var thisRes = new DisplayResolution(0, 0, width, height, bpp, (float)freq);
                        opentk_dev_available_res.Add(thisRes);

                        if (current)
                        {
                            opentk_dev_current_res = thisRes;
                        }
                    }

                    var bounds  = CG.DisplayBounds(currentDisplay);
                    var newRect = new Rectangle((int)bounds.Location.X, (int)bounds.Location.Y,
                                                (int)bounds.Size.Width, (int)bounds.Size.Height);

                    Debug.Print("Display {0} bounds: {1}", i, newRect);

                    var opentk_dev = new DisplayDevice(opentk_dev_current_res,
                                                       primary, opentk_dev_available_res, newRect, currentDisplay);

                    AvailableDevices.Add(opentk_dev);

                    if (primary)
                    {
                        Primary = opentk_dev;
                    }
                }

                Debug.Unindent();
            }
        }
コード例 #19
0
        private unsafe static void GetModes(LinuxDisplay display, DisplayResolution[] modes, out DisplayResolution current)
        {
            int mode_count = display.pConnector->count_modes;

            Debug.Print("[KMS] Display supports {0} mode(s)", mode_count);
            for (int i = 0; i < mode_count; i++)
            {
                ModeInfo *mode = display.pConnector->modes + i;
                if (mode != null)
                {
                    Debug.Print("Mode {0}: {1}x{2} @{3}", i,
                                mode->hdisplay, mode->vdisplay, mode->vrefresh);
                    DisplayResolution res = GetDisplayResolution(mode);
                    modes[i] = res;
                }
            }

            if (display.pCrtc->mode_valid != 0)
            {
                ModeInfo cmode = display.pCrtc->mode;
                current = GetDisplayResolution(&cmode);
            }
            else
            {
                current = GetDisplayResolution(display.pConnector->modes);
            }
            Debug.Print("Current mode: {0}", current.ToString());
        }
コード例 #20
0
        public void RefreshDisplayDevices()
        {
            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
                // and construct the device when every needed detail is available.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                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
                WindowsDisplayDevice dev1 = new WindowsDisplayDevice();
                while (Functions.EnumDisplayDevices(null, device_count++, dev1, 0))
                {
                    if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.None)
                        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.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.CurrentSettings, monitor_mode, 0) ||
                        Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.RegistrySettings, monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        float scale = GetScale(ref monitor_mode);
                        opentk_dev_current_res = new DisplayResolution(
                            (int)(monitor_mode.Position.X / scale), (int)(monitor_mode.Position.Y / scale),
                            (int)(monitor_mode.PelsWidth / scale), (int)(monitor_mode.PelsHeight / scale),
                            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.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), mode_count++, monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        float scale = GetScale(ref monitor_mode);
                        DisplayResolution res = new DisplayResolution(
                            (int)(monitor_mode.Position.X / scale), (int)(monitor_mode.Position.Y / scale),
                            (int)(monitor_mode.PelsWidth / scale), (int)(monitor_mode.PelsHeight / scale),
                            monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);

                        opentk_dev_available_res.Add(res);
                    }

                    // Construct the OpenTK DisplayDevice through the accumulated parameters.
                    // The constructor will automatically add the DisplayDevice to the list
                    // of available devices.
                    #pragma warning disable 612,618
                    opentk_dev = new DisplayDevice(
                        opentk_dev_current_res,
                        opentk_dev_primary,
                        opentk_dev_available_res,
                        opentk_dev_current_res.Bounds,
                        dev1.DeviceName);
                    #pragma warning restore 612,618

                    // 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.OriginalResolution = existingDevice.OriginalResolution;

                    AvailableDevices.Add(opentk_dev);

                    if (opentk_dev_primary)
                        Primary = opentk_dev;

                    Debug.Print("DisplayDevice {0} ({1}) supports {2} resolutions.",
                        device_count, opentk_dev.IsPrimary ? "primary" : "secondary", opentk_dev.AvailableResolutions.Count);
                }
            }
        }
コード例 #21
0
        public void RefreshDisplayDevices()
        {
            lock (display_lock)
            {
                AvailableDevices.Clear();

                // We save all necessary parameters in temporary variables
                // and construct the device when every needed detail is available.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                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
                WindowsDisplayDevice dev1 = new WindowsDisplayDevice(), dev2 = new WindowsDisplayDevice();
                while (Functions.EnumDisplayDevices(null, device_count++, dev1, 0))
                {
                    if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.None)
                    {
                        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.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.CurrentSettings, monitor_mode, 0) ||
                        Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.RegistrySettings, monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        float scale = GetScale(ref monitor_mode);
                        opentk_dev_current_res = new DisplayResolution(
                            (int)(monitor_mode.Position.X / scale), (int)(monitor_mode.Position.Y / scale),
                            (int)(monitor_mode.PelsWidth / scale), (int)(monitor_mode.PelsHeight / scale),
                            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.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), mode_count++, monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        float             scale = GetScale(ref monitor_mode);
                        DisplayResolution res   = new DisplayResolution(
                            (int)(monitor_mode.Position.X / scale), (int)(monitor_mode.Position.Y / scale),
                            (int)(monitor_mode.PelsWidth / scale), (int)(monitor_mode.PelsHeight / scale),
                            monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);

                        opentk_dev_available_res.Add(res);
                    }

                    // Construct the OpenTK DisplayDevice through the accumulated parameters.
                    // The constructor will automatically add the DisplayDevice to the list
                    // of available devices.
                    opentk_dev = new DisplayDevice(
                        opentk_dev_current_res,
                        opentk_dev_primary,
                        opentk_dev_available_res,
                        opentk_dev_current_res.Bounds,
                        dev1.DeviceName);

                    AvailableDevices.Add(opentk_dev);

                    if (opentk_dev_primary)
                    {
                        Primary = opentk_dev;
                    }

                    Debug.Print("DisplayDevice {0} ({1}) supports {2} resolutions.",
                                device_count, opentk_dev.IsPrimary ? "primary" : "secondary", opentk_dev.AvailableResolutions.Count);
                }
            }
        }
コード例 #22
0
 public abstract bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution);
コード例 #23
0
		public sealed override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
        {
            // In SDL2, the resolution is automagically handled by the window.
			return true;
        }
コード例 #24
0
        public bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
        {
            // If resolution is null, restore the default resolution (new_resolution_index = 0).

            if (xrandr_supported)
            {
                return ChangeResolutionXRandR(device, resolution);
            }
            else if (xf86_supported)
            {
                return ChangeResolutionXF86(device, resolution);
            }
            else
            {
                return false;
            }
        }
コード例 #25
0
        static bool QueryXRandR(List<DisplayDevice> devices)
        {
            // Get available resolutions. Then, for each resolution get all available rates.
            foreach (DisplayDevice dev in devices)
            {
                int screen = deviceToScreen[dev];

                IntPtr timestamp_of_last_update;
                Functions.XRRTimes(API.DefaultDisplay, screen, out timestamp_of_last_update);
                lastConfigUpdate.Add(timestamp_of_last_update);

                List<DisplayResolution> available_res = new List<DisplayResolution>();

                // Add info for a new screen.
                screenResolutionToIndex.Add(new Dictionary<DisplayResolution, int>());

                int[] depths = FindAvailableDepths(screen);

                int resolution_count = 0;
                foreach (XRRScreenSize size in FindAvailableResolutions(screen))
                {
                    if (size.Width == 0 || size.Height == 0)
                    {
                        Debug.Print("[Warning] XRandR returned an invalid resolution ({0}) for display device {1}", size, screen);
                        continue;
                    }
                    short[] rates = null;
                    rates = Functions.XRRRates(API.DefaultDisplay, screen, resolution_count);

                    // It seems that XRRRates returns 0 for modes that are larger than the screen
                    // can support, as well as for all supported modes. On Ubuntu 7.10 the tool
                    // "Screens and Graphics" does report these modes, though.
                    foreach (short rate in rates)
                    {
                        // Note: some X servers (like Xming on Windows) do not report any rates other than 0.
                        // If we only have 1 rate, add it even if it is 0.
                        if (rate != 0 || rates.Length == 1)
                            foreach (int depth in depths)
                                available_res.Add(new DisplayResolution(0, 0, size.Width, size.Height, depth, (float)rate));
                    }
                    // Keep the index of this resolution - we will need it for resolution changes later.
                    foreach (int depth in depths)
                    {
                        // Note that Xinerama may return multiple devices for a single screen. XRandR will
                        // not distinguish between the two as far as resolutions are supported (since XRandR
                        // operates on X screens, not display devices) - we need to be careful not to add the
                        // same resolution twice!
                        DisplayResolution res = new DisplayResolution(0, 0, size.Width, size.Height, depth, 0);
                        if (!screenResolutionToIndex[screen].ContainsKey(res))
                            screenResolutionToIndex[screen].Add(res, resolution_count);
                    }

                    ++resolution_count;
                }


                // The resolution of the current DisplayDevice is discovered through XRRConfigCurrentConfiguration.
                // Its refresh rate is discovered by the FindCurrentRefreshRate call.
                // Its depth is discovered by the FindCurrentDepth call.
                float current_refresh_rate = FindCurrentRefreshRate(screen);
                int current_depth = FindCurrentDepth(screen);
                IntPtr screen_config = Functions.XRRGetScreenInfo(API.DefaultDisplay, Functions.XRootWindow(API.DefaultDisplay, screen));
                ushort current_rotation;  // Not needed.
                int current_resolution_index = Functions.XRRConfigCurrentConfiguration(screen_config, out current_rotation);

                if (dev.Bounds == Rectangle.Empty)
                    dev.Bounds = new Rectangle(0, 0, available_res[current_resolution_index].Width, available_res[current_resolution_index].Height);
                dev.BitsPerPixel = current_depth;
                dev.RefreshRate = current_refresh_rate;
                dev.AvailableResolutions = available_res;

                deviceToDefaultResolution.Add(dev, current_resolution_index);
            }

            return true;
        }
 public sealed override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
 {
     IntPtr display = HandleTo(device);
     IntPtr currentModePtr = CG.DisplayCurrentMode(display);
     
     if (storedModes.ContainsKey(display) == false)
     {
         storedModes.Add(display, currentModePtr);
     }
     
     IntPtr displayModesPtr = CG.DisplayAvailableModes(display);
     CFArray displayModes = new CFArray(displayModesPtr);
     
     for (int j = 0; j < displayModes.Count; j++)
     {
         CFDictionary dict = new CFDictionary(displayModes[j]);
         
         int width = (int)dict.GetNumberValue("Width");
         int height = (int)dict.GetNumberValue("Height");
         int bpp = (int)dict.GetNumberValue("BitsPerPixel");
         double freq = dict.GetNumberValue("RefreshRate");
         
         if (width == resolution.Width && height == resolution.Height && bpp == resolution.BitsPerPixel && System.Math.Abs(freq - resolution.RefreshRate) < 1e-6)
         {
             if (displaysCaptured.Contains(display) == false)
             {
                 CG.DisplayCapture(display);
             }
             
             Debug.Print("Changing resolution to {0}x{1}x{2}@{3}.", width, height, bpp, freq);
             
             CG.DisplaySwitchToMode(display, displayModes[j]);
             
             return true;
         }
         
     }
     return false;
 }
コード例 #27
0
 static bool ChangeResolutionXF86(DisplayDevice device, DisplayResolution resolution)
 {
     return false;
 }
コード例 #28
0
ファイル: X11DisplayDevice.cs プロジェクト: hultqvist/opentk
        bool ChangeResolutionXRandR(DisplayDevice device, DisplayResolution resolution)
        {
            using (new XLock(API.DefaultDisplay))
            {
                int screen = deviceToScreen[device];
                IntPtr root = Functions.XRootWindow(API.DefaultDisplay, screen);
                IntPtr screen_config = Functions.XRRGetScreenInfo(API.DefaultDisplay, root);

                ushort current_rotation;
                int current_resolution_index = Functions.XRRConfigCurrentConfiguration(screen_config, out current_rotation);
                int new_resolution_index;
                if (resolution != null)
                    new_resolution_index = screenResolutionToIndex[screen]
                        [new DisplayResolution(0, 0, resolution.Width, resolution.Height, resolution.BitsPerPixel, 0)];
                else
                    new_resolution_index = deviceToDefaultResolution[device];

                Debug.Print("Changing size of screen {0} from {1} to {2}",
                    screen, current_resolution_index, new_resolution_index);

                int ret = 0;
                short refresh_rate = (short)(resolution != null ? resolution.RefreshRate : 0);
                if (refresh_rate > 0)
                {
                    ret = Functions.XRRSetScreenConfigAndRate(API.DefaultDisplay,
                    screen_config, root, new_resolution_index, current_rotation,
                    refresh_rate, IntPtr.Zero);
                }
                else
                {
                    ret = Functions.XRRSetScreenConfig(API.DefaultDisplay,
                    screen_config, root, new_resolution_index, current_rotation,
                    IntPtr.Zero);
                }

                if (ret != 0)
                {
                    Debug.Print("[Error] Change to resolution {0} failed with error {1}.",
                        resolution, (ErrorCode)ret);
                }

                return ret == 0;
            }
        }
コード例 #29
0
 /// <summary>
 /// Converts an osuTK <see cref="DisplayResolution"/> to a <see cref="DisplayMode"/> structure.
 /// It is not possible to retrieve the pixel format from <see cref="DisplayResolution"/>.
 /// </summary>
 /// <param name="resolution">The <see cref="DisplayResolution"/> to convert.</param>
 /// <returns>A <see cref="DisplayMode"/> structure populated with the corresponding properties.</returns>
 internal static DisplayMode ToDisplayMode(this DisplayResolution resolution) =>
 new DisplayMode(null, new Size(resolution.Width, resolution.Height), resolution.BitsPerPixel, (int)Math.Round(resolution.RefreshRate), 0, 0);
コード例 #30
0
 /// <summary>
 /// Initializes a new instance of the type.
 /// </summary>
 /// <param name="resolution">The value to represent.</param>
 public DisplayResolutionViewModel(DisplayResolution resolution)
 {
     Resolution        = resolution;
     DisplayResolution = resolution.ToDisplayString();
 }
        public QuartzDisplayDeviceDriver()
        {
            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.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                const int maxDisplayCount = 20;
                IntPtr[] displays = new IntPtr[maxDisplayCount];
                int displayCount;
                
                unsafe
                {
                    fixed (IntPtr* displayPtr = displays)
                    {
                        CG.GetActiveDisplayList(maxDisplayCount, displayPtr, out displayCount);
                    }
                }
                
                Debug.Print("CoreGraphics reported {0} display(s).", displayCount);
                Debug.Indent();
                
                for (int i = 0; i < displayCount; i++)
                {
                    IntPtr currentDisplay = displays[i];
                    
                    // according to docs, first element in the array is always the
                    // main display.
                    bool primary = (i == 0);
                    
                    // gets current settings
                    int currentWidth = CG.DisplayPixelsWide(currentDisplay);
                    int currentHeight = CG.DisplayPixelsHigh(currentDisplay);
                    Debug.Print("Display {0} is at  {1}x{2}", i, currentWidth, currentHeight);
                    
                    IntPtr displayModesPtr = CG.DisplayAvailableModes(currentDisplay);
                    CFArray displayModes = new CFArray(displayModesPtr);
                    Debug.Print("Supports {0} display modes.", displayModes.Count);
                    
                    DisplayResolution opentk_dev_current_res = null;
                    List<DisplayResolution> opentk_dev_available_res = new List<DisplayResolution>();
                    IntPtr currentModePtr = CG.DisplayCurrentMode(currentDisplay);
                    CFDictionary currentMode = new CFDictionary(currentModePtr);
                    
                    for (int j = 0; j < displayModes.Count; j++)
                    {
                        CFDictionary dict = new CFDictionary(displayModes[j]);
                        
                        int width = (int)dict.GetNumberValue("Width");
                        int height = (int)dict.GetNumberValue("Height");
                        int bpp = (int)dict.GetNumberValue("BitsPerPixel");
                        double freq = dict.GetNumberValue("RefreshRate");
                        bool current = currentMode.Ref == dict.Ref;
                        
                        //if (current) Debug.Write("  * ");
                        //else Debug.Write("    ");
                        
                        //Debug.Print("Mode {0} is {1}x{2}x{3} @ {4}.", j, width, height, bpp, freq);
                        
                        DisplayResolution thisRes = new DisplayResolution(0, 0, width, height, bpp, (float)freq);
                        opentk_dev_available_res.Add(thisRes);
                        
                        if (current)
                            opentk_dev_current_res = thisRes;
                        
                    }
                    
                    HIRect bounds = CG.DisplayBounds(currentDisplay);
                    Rectangle newRect = new Rectangle((int)bounds.Origin.X, (int)bounds.Origin.Y, (int)bounds.Size.Width, (int)bounds.Size.Height);
                    
                    Debug.Print("Display {0} bounds: {1}", i, newRect);
                    
                    DisplayDevice opentk_dev = new DisplayDevice(opentk_dev_current_res,
                        primary, opentk_dev_available_res, newRect, currentDisplay);

                    AvailableDevices.Add(opentk_dev);

                    if (primary)
                        Primary = opentk_dev;
                }
                
                Debug.Unindent();
            }
        }
コード例 #32
0
        static X11XrandrDisplayDevice()
        {
            using (new XLock(API.DefaultDisplay))
            {
                List<DisplayDevice> devices = new List<DisplayDevice>();
                bool xinerama_supported = false;
                try
                {
                    // Try to use Xinerama to obtain the geometry of all output devices.
                    int event_base, error_base;
                    if (NativeMethods.XineramaQueryExtension(API.DefaultDisplay, out event_base, out error_base) &&
                        NativeMethods.XineramaIsActive(API.DefaultDisplay))
                    {
                        IList<XineramaScreenInfo> screens = NativeMethods.XineramaQueryScreens(API.DefaultDisplay);
                        bool first = true;
                        foreach (XineramaScreenInfo screen in screens)
                        {
                            DisplayDevice dev = new DisplayDevice();
                            dev.Bounds = new Rectangle(screen.X, screen.Y, screen.Width, screen.Height);
                            if (first)
                            {
                                // We consider the first device returned by Xinerama as the primary one.
                                // Makes sense conceptually, but is there a way to verify this?
                                dev.IsPrimary = true;
                                first = false;
                            }
                            devices.Add(dev);
                            // It seems that all X screens are equal to 0 is Xinerama is enabled, at least on Nvidia (verify?)
                            deviceToScreen.Add(dev, 0 /*screen.ScreenNumber*/);
                            xinerama_supported = true;
                        }
                    }
                }
                catch { Debug.Print("Xinerama query failed."); }

                if (!xinerama_supported)
                {
                    // We assume that devices are equivalent to the number of available screens.
                    // Note: this won't work correctly in the case of distinct X servers.
                    for (int i = 0; i < API.ScreenCount; i++)
                    {
                        DisplayDevice dev = new DisplayDevice();
                        dev.IsPrimary = i == Functions.XDefaultScreen(API.DefaultDisplay);
                        devices.Add(dev);
                        deviceToScreen.Add(dev, i);
                    }
                }

                // Get available resolutions. Then, for each resolution get all available rates.
                foreach (DisplayDevice dev in devices)
                {
                    int screen = deviceToScreen[dev];

                    IntPtr timestamp_of_last_update;
                    Functions.XRRTimes(API.DefaultDisplay, screen, out timestamp_of_last_update);
                    lastConfigUpdate.Add(timestamp_of_last_update);

                    List<DisplayResolution> available_res = new List<DisplayResolution>();

                    // Add info for a new screen.
                    screenResolutionToIndex.Add(new Dictionary<DisplayResolution, int>());

                    int[] depths = FindAvailableDepths(screen);

                    int resolution_count = 0;
                    foreach (XRRScreenSize size in FindAvailableResolutions(screen))
                    {
                        if (size.Width == 0 || size.Height == 0)
                        {
                            Debug.Print("[Warning] XRandR returned an invalid resolution ({0}) for display device {1}", size, screen);
                            continue;
                        }
                        short[] rates = null;
                        rates = Functions.XRRRates(API.DefaultDisplay, screen, resolution_count);

                        // It seems that XRRRates returns 0 for modes that are larger than the screen
                        // can support, as well as for all supported modes. On Ubuntu 7.10 the tool
                        // "Screens and Graphics" does report these modes, though.
                        foreach (short rate in rates)
                        {
                            // Note: some X servers (like Xming on Windows) do not report any rates other than 0.
                            // If we only have 1 rate, add it even if it is 0.
                            if (rate != 0 || rates.Length == 1)
                                foreach (int depth in depths)
                                    available_res.Add(new DisplayResolution(0, 0, size.Width, size.Height, depth, (float)rate));
                        }
                        // Keep the index of this resolution - we will need it for resolution changes later.
                        foreach (int depth in depths)
                        {
                            // Note that Xinerama may return multiple devices for a single screen. XRandR will
                            // not distinguish between the two as far as resolutions are supported (since XRandR
                            // operates on X screens, not display devices) - we need to be careful not to add the
                            // same resolution twice!
                            DisplayResolution res = new DisplayResolution(0, 0, size.Width, size.Height, depth, 0);
                            if (!screenResolutionToIndex[screen].ContainsKey(res))
                                screenResolutionToIndex[screen].Add(res, resolution_count);
                        }

                        ++resolution_count;
                    }


                    // The resolution of the current DisplayDevice is discovered through XRRConfigCurrentConfiguration.
                    // Its refresh rate is discovered by the FindCurrentRefreshRate call.
                    // Its depth is discovered by the FindCurrentDepth call.
                    float current_refresh_rate = FindCurrentRefreshRate(screen);
                    int current_depth = FindCurrentDepth(screen);
                    IntPtr screen_config = Functions.XRRGetScreenInfo(API.DefaultDisplay, Functions.XRootWindow(API.DefaultDisplay, screen));
                    ushort current_rotation;  // Not needed.
                    int current_resolution_index = Functions.XRRConfigCurrentConfiguration(screen_config, out current_rotation);

                    if (dev.Bounds == Rectangle.Empty)
                        dev.Bounds = new Rectangle(0, 0, available_res[current_resolution_index].Width, available_res[current_resolution_index].Height);
                    dev.BitsPerPixel = current_depth;
                    dev.RefreshRate = current_refresh_rate;
                    dev.AvailableResolutions = available_res;

                    deviceToDefaultResolution.Add(dev, current_resolution_index);
                }
            }
        }
コード例 #33
0
 private void UpdateDisplayResolution(DisplayResolution displayResolution)
 {
     JzIntvDisplaySize = displayResolution.ToLongCommandLineArgumentString();
     Properties.Settings.Default.DisplaySize = displayResolution.ToLongCommandLineArgumentString();
 }
コード例 #34
0
        public void RefreshDisplayDevices()
        {
            lock (display_lock)
            {
                // Store an array of the current available DisplayDevice objects.
                // This is needed to preserve the original resolution.
                var previousDevices = AvailableDevices.ToArray();

                AvailableDevices.Clear();

                // We save all necessary parameters in temporary variables
                // and construct the device when every needed detail is available.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                DisplayDevice     opentk_dev;
                DisplayResolution opentk_dev_current_res = null;
                var  opentk_dev_available_res            = new List <DisplayResolution>();
                bool opentk_dev_primary = false;
                uint device_count = 0, mode_count = 0;

                // Get available video adapters and enumerate all monitors
                while (User32.DeviceContext.EnumDisplayDevices(null, device_count++, out var dev1, 0))
                {
                    if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == 0)
                    {
                        continue;
                    }

                    // The second function should only be executed when the first one fails
                    // (e.g. when the monitor is disabled)
                    if (User32.DeviceContext.EnumDisplaySettingsEx(dev1.DeviceName, DisplayModeSetting.CurrentSettings,
                                                                   out DeviceMode monitor_mode, 0) ||
                        User32.DeviceContext.EnumDisplaySettingsEx(dev1.DeviceName, DisplayModeSetting.RegistrySettings,
                                                                   out monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        var scale = GetScale(ref monitor_mode);
                        opentk_dev_current_res = new DisplayResolution(
                            (int)(monitor_mode.DisplayOptions.Position.X / scale),
                            (int)(monitor_mode.DisplayOptions.Position.Y / scale),
                            (int)(monitor_mode.WidthInPixels / scale),
                            (int)(monitor_mode.HeightInPixels / scale),
                            (int)monitor_mode.BitsPerPixel,
                            monitor_mode.DisplayFrequency
                            );

                        opentk_dev_primary = (dev1.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != 0;
                    }

                    opentk_dev_available_res.Clear();
                    mode_count = 0;
                    while (User32.DeviceContext.EnumDisplaySettingsEx(dev1.DeviceName, (DisplayModeSetting)mode_count++, out monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        var scale = GetScale(ref monitor_mode);
                        var res   = new DisplayResolution(
                            (int)(monitor_mode.DisplayOptions.Position.X / scale),
                            (int)(monitor_mode.DisplayOptions.Position.Y / scale),
                            (int)(monitor_mode.WidthInPixels / scale),
                            (int)(monitor_mode.HeightInPixels / scale),
                            (int)monitor_mode.BitsPerPixel,
                            monitor_mode.DisplayFrequency
                            );

                        opentk_dev_available_res.Add(res);
                    }

                    // Construct the OpenTK DisplayDevice through the accumulated parameters.
                    // The constructor will automatically add the DisplayDevice to the list
                    // of available devices.
#pragma warning disable 612,618
                    opentk_dev = new DisplayDevice(
                        opentk_dev_current_res,
                        opentk_dev_primary,
                        opentk_dev_available_res,
                        opentk_dev_current_res.Bounds,
                        dev1.DeviceName
                        );
#pragma warning restore 612,618

                    // Set the original resolution if the DisplayDevice was previously available.
                    foreach (var existingDevice in previousDevices)
                    {
                        if ((string)existingDevice.Id == (string)opentk_dev.Id)
                        {
                            opentk_dev.OriginalResolution = existingDevice.OriginalResolution;
                        }
                    }

                    AvailableDevices.Add(opentk_dev);

                    if (opentk_dev_primary)
                    {
                        Primary = opentk_dev;
                    }

                    Debug.Print("DisplayDevice {0} ({1}) supports {2} resolutions.",
                                device_count, opentk_dev.IsPrimary ? "primary" : "secondary",
                                opentk_dev.AvailableResolutions.Count);
                }
            }
        }
コード例 #35
0
ファイル: MainControler.cs プロジェクト: ntj/GravurGIS
        ////////////////
        // Methods
        ////////////////
        private void CheckEnvironment()
        {
            // display
            int resolutionWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            int resolutionHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
            if (resolutionHeight >= 640 && resolutionWidth >= 480) this.displayResolution = DisplayResolution.VGA;
            else this.displayResolution = DisplayResolution.QVGA;

            SetUpAppLink();
        }
コード例 #36
0
ファイル: X11DisplayDevice.cs プロジェクト: conankzhang/fez
 private static bool ChangeResolutionXF86(DisplayDevice device, DisplayResolution resolution)
 {
     return(false);
 }
コード例 #37
0
        public override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
        {
            // Todo: we need a temporary window to change resolutions, most probably
            Trace.WriteLine("SDL2 driver does not implement TryChangeResolution");
            return true;

            //SDL2.SDL_DisplayMode desired, closest;
            //desired.w = resolution.Width;
            //desired.h = resolution.Height;
            //desired.format = SDL.SDL_PIXELFORMAT_BGRA8888;

            //SDL2.SDL_GetClosestDisplayMode((int)device.Id, ref desired, out closest);
            //SDL2.SDL_SetWindowDisplayMode(IntPtr.Zero, ref closest);
        }
コード例 #38
0
        public void RefreshDisplayDevices()
        {
            lock (display_lock)
            {
                AvailableDevices.Clear();

                // We save all necessary parameters in temporary variables
                // and construct the device when every needed detail is available.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                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
                WindowsDisplayDevice dev1 = new WindowsDisplayDevice(), dev2 = new WindowsDisplayDevice();
                while (Functions.EnumDisplayDevices(null, device_count++, dev1, 0))
                {
                    if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.None)
                        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.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.CurrentSettings, monitor_mode, 0) ||
                        Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.RegistrySettings, monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        opentk_dev_current_res = new DisplayResolution(
                            monitor_mode.Position.X, monitor_mode.Position.Y,
                            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.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), mode_count++, monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        DisplayResolution res = new DisplayResolution(
                            monitor_mode.Position.X, monitor_mode.Position.Y,
                            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.
                    // The constructor will automatically add the DisplayDevice to the list
                    // of available devices.
                    opentk_dev = new DisplayDevice(
                        opentk_dev_current_res,
                        opentk_dev_primary,
                        opentk_dev_available_res,
                        opentk_dev_current_res.Bounds,
                        dev1.DeviceName);

                    AvailableDevices.Add(opentk_dev);

                    if (opentk_dev_primary)
                        Primary = opentk_dev;

                    Debug.Print("DisplayDevice {0} ({1}) supports {2} resolutions.",
                        device_count, opentk_dev.IsPrimary ? "primary" : "secondary", opentk_dev.AvailableResolutions.Count);
                }
            }
        }
コード例 #39
0
ファイル: X11DisplayDevice.cs プロジェクト: valera6285/opentk
        bool QueryXRandR(List <DisplayDevice> devices)
        {
            // Get available resolutions. Then, for each resolution get all available rates.
            foreach (DisplayDevice dev in devices)
            {
                int screen = deviceToScreen[dev];

                IntPtr timestamp_of_last_update;
                Functions.XRRTimes(API.DefaultDisplay, screen, out timestamp_of_last_update);
                lastConfigUpdate.Add(timestamp_of_last_update);

                List <DisplayResolution> available_res = new List <DisplayResolution>();

                // Add info for a new screen.
                screenResolutionToIndex.Add(new Dictionary <DisplayResolution, int>());

                int[] depths = FindAvailableDepths(screen);

                int resolution_count = 0;
                foreach (XRRScreenSize size in FindAvailableResolutions(screen))
                {
                    if (size.Width == 0 || size.Height == 0)
                    {
                        Debug.Print("[Warning] XRandR returned an invalid resolution ({0}) for display device {1}", size, screen);
                        continue;
                    }
                    short[] rates = null;
                    rates = Functions.XRRRates(API.DefaultDisplay, screen, resolution_count);

                    // It seems that XRRRates returns 0 for modes that are larger than the screen
                    // can support, as well as for all supported modes. On Ubuntu 7.10 the tool
                    // "Screens and Graphics" does report these modes, though.
                    foreach (short rate in rates)
                    {
                        // Note: some X servers (like Xming on Windows) do not report any rates other than 0.
                        // If we only have 1 rate, add it even if it is 0.
                        if (rate != 0 || rates.Length == 1)
                        {
                            foreach (int depth in depths)
                            {
                                available_res.Add(new DisplayResolution(0, 0, size.Width, size.Height, depth, (float)rate));
                            }
                        }
                    }
                    // Keep the index of this resolution - we will need it for resolution changes later.
                    foreach (int depth in depths)
                    {
                        // Note that Xinerama may return multiple devices for a single screen. XRandR will
                        // not distinguish between the two as far as resolutions are supported (since XRandR
                        // operates on X screens, not display devices) - we need to be careful not to add the
                        // same resolution twice!
                        DisplayResolution res = new DisplayResolution(0, 0, size.Width, size.Height, depth, 0);
                        if (!screenResolutionToIndex[screen].ContainsKey(res))
                        {
                            screenResolutionToIndex[screen].Add(res, resolution_count);
                        }
                    }

                    ++resolution_count;
                }


                // The resolution of the current DisplayDevice is discovered through XRRConfigCurrentConfiguration.
                // Its refresh rate is discovered by the FindCurrentRefreshRate call.
                // Its depth is discovered by the FindCurrentDepth call.
                float  current_refresh_rate = FindCurrentRefreshRate(screen);
                int    current_depth        = FindCurrentDepth(screen);
                IntPtr screen_config        = Functions.XRRGetScreenInfo(API.DefaultDisplay, Functions.XRootWindow(API.DefaultDisplay, screen));
                ushort current_rotation;  // Not needed.
                int    current_resolution_index = Functions.XRRConfigCurrentConfiguration(screen_config, out current_rotation);

                if (dev.Bounds == Rectangle.Empty)
                {
                    // We have added depths.Length copies of each resolution
                    // Adjust the return value of XRRGetScreenInfo to retrieve the correct resolution
                    int index = current_resolution_index * depths.Length;

                    // Make sure we are within the bounds of the available_res array
                    if (index >= available_res.Count)
                    {
                        // If not, use the return value of XRRGetScreenInfo directly
                        index = current_resolution_index;
                    }
                    DisplayResolution current_resolution = available_res[index];
                    dev.Bounds = new Rectangle(0, 0, current_resolution.Width, current_resolution.Height);
                }
                dev.BitsPerPixel         = current_depth;
                dev.RefreshRate          = current_refresh_rate;
                dev.AvailableResolutions = available_res;

                deviceToDefaultResolution.Add(dev, current_resolution_index);
            }

            return(true);
        }
コード例 #40
0
        public void RefreshDisplayDevices()
        {
            lock (this.display_lock)
            {
                // Store an array of the current available DisplayDevice objects.
                // This is needed to preserve the original resolution.
                DisplayDevice[] previousDevices = this.AvailableDevices.ToArray();

                this.AvailableDevices.Clear();

                // We save all necessary parameters in temporary variables
                // and construct the device when every needed detail is available.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                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
                WindowsDisplayDevice dev1 = new WindowsDisplayDevice();
                while (Functions.EnumDisplayDevices(null, device_count++, dev1, 0))
                {
                    if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.None) // NOTE: AttachedToDesktop is identical to Active
                    {
                        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.EnumDisplaySettingsEx(dev1.DeviceName, DisplayModeSettingsEnum.CurrentSettings, monitor_mode, 0) ||
                        Functions.EnumDisplaySettingsEx(dev1.DeviceName, DisplayModeSettingsEnum.RegistrySettings, monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        float scale  = this.GetScale(ref monitor_mode);
                        var   x      = (int)(monitor_mode.Position.X / scale);
                        var   y      = (int)(monitor_mode.Position.Y / scale);
                        var   width  = (int)(monitor_mode.PelsWidth / scale);
                        var   height = (int)(monitor_mode.PelsHeight / scale);

                        try
                        {
                            opentk_dev_current_res = new DisplayResolution(x, y, width, height, monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);
                        }
                        catch (ArgumentOutOfRangeException e)
                        {
                            Debug.Print("[OpenTK] Invaild display mode on {0}: {1}, ({2},{3},{4},{5},{6},{7})", dev1.DeviceName, e.Message, x, y, width, height, monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);

                            // ingnore this output device -> continue with EnumDisplayDevices
                            continue;
                        }

                        opentk_dev_primary =
                            (dev1.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None;
                    }

                    opentk_dev_available_res.Clear();
                    mode_count = 0;
                    while (Functions.EnumDisplaySettingsEx(dev1.DeviceName, mode_count++, monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        float scale  = this.GetScale(ref monitor_mode);
                        var   x      = (int)(monitor_mode.Position.X / scale);
                        var   y      = (int)(monitor_mode.Position.Y / scale);
                        var   width  = (int)(monitor_mode.PelsWidth / scale);
                        var   height = (int)(monitor_mode.PelsHeight / scale);

                        try
                        {
                            var res = new DisplayResolution(x, y, width, height, monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);

                            opentk_dev_available_res.Add(res);
                        }
                        catch (ArgumentOutOfRangeException e)
                        {
                            Debug.Print("[OpenTK] Invaild display mode on {0}: {1}, ({2},{3},{4},{5},{6},{7})", dev1.DeviceName, e.Message, x, y, width, height, monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);

                            // ingnore this mode for list of available modes -> continue with EnumDisplaySettingsEx
                            continue;
                        }
                    }

                    // Construct the OpenTK DisplayDevice through the accumulated parameters.
                    // The constructor will automatically add the DisplayDevice to the list
                    // of available devices.
                    #pragma warning disable 612,618
                    opentk_dev = new DisplayDevice(
                        opentk_dev_current_res,
                        opentk_dev_primary,
                        opentk_dev_available_res,
                        opentk_dev_current_res.Bounds,
                        dev1.DeviceName);
                    #pragma warning restore 612,618

                    // 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.OriginalResolution = existingDevice.OriginalResolution;
                        }
                    }

                    this.AvailableDevices.Add(opentk_dev);

                    if (opentk_dev_primary)
                    {
                        this.Primary = opentk_dev;
                    }

                    Debug.Print("DisplayDevice {0} ({1}) supports {2} resolutions.",
                                device_count, opentk_dev.IsPrimary ? "primary" : "secondary", opentk_dev.AvailableResolutions.Count);
                }
            }
        }
コード例 #41
0
 public bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
 {
     return(false);
 }
コード例 #42
0
 /// <summary>
 /// Convert the given resolution to a short command line string.
 /// </summary>
 /// <param name="resolution">The resolution to convert.</param>
 /// <returns>The short command line argument string, which is just a number.</returns>
 public static string ToShortCommandLineArgumentString(this DisplayResolution resolution)
 {
     return(((int)resolution).ToString());
 }
コード例 #43
0
 public override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
 {
     Sdl2Factory.UseFullscreenDesktop = false;
     return(true);
 }
コード例 #44
0
 public abstract bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution);
コード例 #45
0
 public override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
 {
     Sdl2Factory.UseFullscreenDesktop = false;
     return true;
 }
コード例 #46
0
        static bool QueryXRandR(List <DisplayDevice> devices)
        {
            // Get available resolutions. Then, for each resolution get all available rates.
            foreach (DisplayDevice dev in devices)
            {
                int screen = deviceToScreen[dev];

                IntPtr lastUpdateTimestamp;
                API.XRRTimes(API.DefaultDisplay, screen, out lastUpdateTimestamp);
                lastConfigUpdate.Add(lastUpdateTimestamp);
                List <DisplayResolution> available_res = new List <DisplayResolution>();

                // Add info for a new screen.
                screenResolutionToIndex.Add(new Dictionary <DisplayResolution, int>());
                int[] depths = API.XListDepths(API.DefaultDisplay, screen);

                int resolution_count = 0;
                foreach (XRRScreenSize size in FindAvailableResolutions(screen))
                {
                    if (size.Width == 0 || size.Height == 0)
                    {
                        Debug.Print("[Warning] XRandR returned an invalid resolution ({0}) for display device {1}", size, screen);
                        continue;
                    }
                    short[] rates = API.XRRRates(API.DefaultDisplay, screen, resolution_count);

                    // It seems that XRRRates returns 0 for modes that are larger than the screen
                    // can support, as well as for all supported modes. On Ubuntu 7.10 the tool
                    // "Screens and Graphics" does report these modes, though.
                    foreach (short rate in rates)
                    {
                        // Note: some X servers (like Xming on Windows) do not report any rates other than 0.
                        // If we only have 1 rate, add it even if it is 0.
                        if (rate != 0 || rates.Length == 1)
                        {
                            foreach (int depth in depths)
                            {
                                available_res.Add(new DisplayResolution(0, 0, size.Width, size.Height, depth, rate));
                            }
                        }
                    }
                    // Keep the index of this resolution - we will need it for resolution changes later.
                    foreach (int depth in depths)
                    {
                        // Note that Xinerama may return multiple devices for a single screen. XRandR will
                        // not distinguish between the two as far as resolutions are supported (since XRandR
                        // operates on X screens, not display devices) - we need to be careful not to add the
                        // same resolution twice!
                        DisplayResolution res = new DisplayResolution(0, 0, size.Width, size.Height, depth, 0);
                        if (!screenResolutionToIndex[screen].ContainsKey(res))
                        {
                            screenResolutionToIndex[screen].Add(res, resolution_count);
                        }
                    }
                    ++resolution_count;
                }

                IntPtr screenConfig = API.XRRGetScreenInfo(API.DefaultDisplay, API.XRootWindow(API.DefaultDisplay, screen));
                ushort curRotation;
                int    curResolutionIndex = API.XRRConfigCurrentConfiguration(screenConfig, out curRotation);
                float  curRefreshRate     = API.XRRConfigCurrentRate(screenConfig);
                int    curDepth           = API.XDefaultDepth(API.DefaultDisplay, screen);
                API.XRRFreeScreenConfigInfo(screenConfig);

                if (dev.Bounds == Rectangle.Empty)
                {
                    dev.Bounds = new Rectangle(0, 0, available_res[curResolutionIndex].Width, available_res[curResolutionIndex].Height);
                }
                dev.BitsPerPixel         = curDepth;
                dev.RefreshRate          = curRefreshRate;
                dev.AvailableResolutions = available_res;

                deviceToDefaultResolution.Add(dev, curResolutionIndex);
            }
            return(true);
        }