コード例 #1
0
        public bool SetRefreshRate(double refreshRate)
        {
            if (!_initialized)
            {
                return(false);
            }

            // Set proper numerator and denominator for refresh rate
            UInt32 newRefreshRate = (uint)(refreshRate * 1000);
            UInt32 numerator;
            UInt32 denominator;
            UInt32 scanLineOrdering;

            switch (newRefreshRate)
            {
            case 23976:
                numerator        = 24000;
                denominator      = 1001;
                scanLineOrdering = DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE;
                break;

            case 24000:
                numerator        = 24000;
                denominator      = 1000;
                scanLineOrdering = DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE;
                break;

            case 25000:
                numerator        = 25000;
                denominator      = 1000;
                scanLineOrdering = DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE;
                break;

            case 29970:
                numerator        = 30000;
                denominator      = 1001;
                scanLineOrdering = DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE;
                break;

            case 30000:
                numerator        = 30000;
                denominator      = 1000;
                scanLineOrdering = DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE;
                break;

            case 50000:
                numerator        = 50000;
                denominator      = 1000;
                scanLineOrdering = DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE;
                break;

            case 59940:
                numerator        = 60000;
                denominator      = 1001;
                scanLineOrdering = DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE;
                break;

            case 60000:
                numerator        = 60000;
                denominator      = 1000;
                scanLineOrdering = DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE;
                break;

            default:
                numerator        = newRefreshRate / 1000;
                denominator      = 1;
                scanLineOrdering = DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE;
                break;
            }

            // Set refresh rate parameters in display config
            Marshal.WriteInt32(_pModeArray, _offset + 32, (int)numerator);
            Marshal.WriteInt32(_pModeArray, _offset + 36, (int)denominator);
            Marshal.WriteInt32(_pModeArray, _offset + 56, (int)scanLineOrdering);

            // Validate new refresh rate
            UInt32 flags  = SDC_VALIDATE | SDC_USE_SUPPLIED_DISPLAY_CONFIG;
            long   result = SetDisplayConfig(_numPathArrayElements, _pPathArray, _numModeArrayElements, _pModeArray, flags);

            // Adding SDC_ALLOW_CHANGES to flags if validation failed
            if (result != 0)
            {
                ServiceRegistration.Get <ILogger>().Debug("RefreshRateChanger.SetDisplayConfig(...): SDC_VALIDATE of {0}/{1} failed", numerator, denominator);
                flags = SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_ALLOW_CHANGES;
            }
            else
            {
                ServiceRegistration.Get <ILogger>().Debug("RefreshRateChanger.SetDisplayConfig(...): SDC_VALIDATE of {0}/{1} succesful", numerator, denominator);
                flags = SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG;
            }

            // Configuring display
            result = SetDisplayConfig(_numPathArrayElements, _pPathArray, _numModeArrayElements, _pModeArray, flags);

            if (result != 0)
            {
                ServiceRegistration.Get <ILogger>().Warn("RefreshRateChanger.SetDisplayConfig(...): SDC_APPLY returned {0}", result);
                return(false);
            }
            ServiceRegistration.Get <ILogger>().Debug("RefreshRateChanger.SetDisplayConfig(...): Successfully switched to {0}/{1}", numerator, denominator);
            Windows7DwmFix.FixDwm();
            _rateChanged = true;
            return(true);
        }
コード例 #2
0
        public bool SetRefreshRate(double refreshRate)
        {
            if (!_initialized)
            {
                return(false);
            }

            // Set proper numerator and denominator for refresh rate
            UInt32 newRefreshRate = (uint)(refreshRate * 1000);
            UInt32 numerator;
            UInt32 denominator;

            CCDWrapper.DisplayConfigScanLineOrdering scanLineOrdering;
            switch (newRefreshRate)
            {
            case 23976:
                numerator        = 24000;
                denominator      = 1001;
                scanLineOrdering = CCDWrapper.DisplayConfigScanLineOrdering.Progressive;
                break;

            case 24000:
                numerator        = 24000;
                denominator      = 1000;
                scanLineOrdering = CCDWrapper.DisplayConfigScanLineOrdering.Progressive;
                break;

            case 25000:
                numerator        = 25000;
                denominator      = 1000;
                scanLineOrdering = CCDWrapper.DisplayConfigScanLineOrdering.Progressive;
                break;

            case 29970:
                numerator        = 30000;
                denominator      = 1001;
                scanLineOrdering = CCDWrapper.DisplayConfigScanLineOrdering.Progressive;
                break;

            case 30000:
                numerator        = 30000;
                denominator      = 1000;
                scanLineOrdering = CCDWrapper.DisplayConfigScanLineOrdering.Progressive;
                break;

            case 50000:
                numerator        = 50000;
                denominator      = 1000;
                scanLineOrdering = CCDWrapper.DisplayConfigScanLineOrdering.Progressive;
                break;

            case 59940:
                numerator        = 60000;
                denominator      = 1001;
                scanLineOrdering = CCDWrapper.DisplayConfigScanLineOrdering.Progressive;
                break;

            case 60000:
                numerator        = 60000;
                denominator      = 1000;
                scanLineOrdering = CCDWrapper.DisplayConfigScanLineOrdering.Progressive;
                break;

            default:
                numerator        = newRefreshRate / 1000;
                denominator      = 1;
                scanLineOrdering = CCDWrapper.DisplayConfigScanLineOrdering.Progressive;
                break;
            }

            // Set refresh rate parameters in display config
            var modeIndex = _displayIndex * 2; // Array always contains "Source" and "Target" per display

            _modeInfoArray[modeIndex].TargetMode.TargetVideoSignalInfo.VerticalSyncFreq.Numerator   = numerator;
            _modeInfoArray[modeIndex].TargetMode.TargetVideoSignalInfo.VerticalSyncFreq.Denominator = denominator;
            _modeInfoArray[modeIndex].TargetMode.TargetVideoSignalInfo.ScanLineOrdering             = scanLineOrdering;

            // Validate new refresh rate
            CCDWrapper.SdcFlags flags = CCDWrapper.SdcFlags.Validate | CCDWrapper.SdcFlags.UseSuppliedDisplayConfig;
            long result = CCDWrapper.SetDisplayConfig(_numPathArrayElements, _pathInfoArray, _numModeInfoArrayElements, _modeInfoArray, flags);

            // Adding SDC_ALLOW_CHANGES to flags if validation failed
            if (result != 0)
            {
                ServiceRegistration.Get <ILogger>().Debug("RefreshRateChanger.SetDisplayConfig(...): SDC_VALIDATE of {0}/{1} failed", numerator, denominator);
                flags = CCDWrapper.SdcFlags.Apply | CCDWrapper.SdcFlags.UseSuppliedDisplayConfig | CCDWrapper.SdcFlags.AllowChanges;
            }
            else
            {
                ServiceRegistration.Get <ILogger>().Debug("RefreshRateChanger.SetDisplayConfig(...): SDC_VALIDATE of {0}/{1} succesful", numerator, denominator);
                flags = CCDWrapper.SdcFlags.Apply | CCDWrapper.SdcFlags.UseSuppliedDisplayConfig;
            }

            // Configuring display
            result = CCDWrapper.SetDisplayConfig(_numPathArrayElements, _pathInfoArray, _numModeInfoArrayElements, _modeInfoArray, flags);

            if (result != 0)
            {
                ServiceRegistration.Get <ILogger>().Warn("RefreshRateChanger.SetDisplayConfig(...): SDC_APPLY returned {0}", result);
                return(false);
            }
            ServiceRegistration.Get <ILogger>().Debug("RefreshRateChanger.SetDisplayConfig(...): Successfully switched to {0}/{1}", numerator, denominator);
            Windows7DwmFix.FixDwm();
            _rateChanged = true;
            return(true);
        }