Ejemplo n.º 1
0
 private void SetCurrentDisplay(NvPreset preset)
 {
     if (preset.primaryDisplay)
     {
         var displayId = DisplayDevice.GetGDIPrimaryDisplayDevice().DisplayId;
         _currentDisplay = Display.GetDisplays().FirstOrDefault(x => x.DisplayDevice.DisplayId == displayId);
     }
     else
     {
         _currentDisplay = Display.GetDisplays().FirstOrDefault(x => x.Name.Equals(preset.displayName));
     }
 }
Ejemplo n.º 2
0
        public List <uint> GetAvailableRefreshRates(NvPreset preset = null)
        {
            if (preset != null)
            {
                SetCurrentDisplay(preset);
            }

            var display = GetCurrentDisplay();
            var portrait = new[] { Rotate.Degree90, Rotate.Degree270 }.Contains(display.DisplayDevice.ScanOutInformation.SourceToTargetRotation);
            var timing = display.DisplayDevice.CurrentTiming;

            return(GetAvailableRefreshRatesInternal(display.Name, portrait, timing.HorizontalVisible, timing.VerticalVisible));
        }
Ejemplo n.º 3
0
        public NvPreset(NvPreset preset) : this()
        {
            id = GetNewId();

            primaryDisplay = preset.primaryDisplay;
            displayName    = preset.displayName;

            var colorData = preset.colorData;

            this.colorData = new ColorData(colorData.ColorFormat, dynamicRange: colorData.DynamicRange, colorDepth: colorData.ColorDepth, colorSelectionPolicy: colorData.SelectionPolicy);
            applyColorData = preset.applyColorData;

            applyHDR         = preset.applyHDR;
            HDREnabled       = preset.HDREnabled;
            toggleHDR        = preset.toggleHDR;
            applyDithering   = preset.applyDithering;
            ditheringEnabled = preset.ditheringEnabled;
            applyRefreshRate = preset.applyRefreshRate;
            refreshRate      = preset.refreshRate;
        }
Ejemplo n.º 4
0
        public bool SetDithering(bool enabled, uint bits = 1, uint mode = 4, NvPreset preset = null)
        {
            var result = true;

            var ptr = NvAPI64_QueryInterface(0xDF0DFCDD);

            if (ptr != IntPtr.Zero)
            {
                var delegateValue = Marshal.GetDelegateForFunctionPointer(ptr, typeof(NvAPI_Disp_SetDitherControl)) as NvAPI_Disp_SetDitherControl;

                var displayDevice = GetCurrentDisplay().DisplayDevice;

                var gpuHandle = displayDevice.PhysicalGPU.Handle;
                var displayId = displayDevice.DisplayId;

                if (preset != null)
                {
                    bits = preset.ditheringBits;
                    mode = preset.ditheringMode;
                }

                var resultValue = delegateValue(gpuHandle, displayId, (uint)(enabled ? 1 : 2), bits, mode);
                if (resultValue != 0)
                {
                    Logger.Error($"Could not set dithering because NvAPI_Disp_SetDitherControl returned a non-zero return code: {resultValue}");
                    result = false;
                }
            }
            else
            {
                Logger.Error($"Could not set dithering because the function NvAPI_Disp_SetDitherControl could not be found");
                result = false;
            }

            return(result);
        }
Ejemplo n.º 5
0
        public bool ApplyPreset(NvPreset preset, Config config)
        {
            var result = true;

            if (!HasDisplaysAttached())
            {
                return(false);
            }

            SetCurrentDisplay(preset);

            var hdrEnabled = IsHDREnabled();

            var newHdrEnabled = preset.applyHDR && (preset.HDREnabled || (preset.toggleHDR && !hdrEnabled));
            var applyHdr      = preset.applyHDR && (preset.toggleHDR || preset.HDREnabled != hdrEnabled);

            if (preset.applyColorData && (ColorDataDiffers(preset.colorData) || (!newHdrEnabled && preset.applyColorData && preset.colorData.Colorimetry != ColorDataColorimetry.Auto)))
            {
                var display = GetCurrentDisplay();
                if (hdrEnabled)
                {
                    SetHDRState(display, false);

                    applyHdr = false;
                }

                try
                {
                    display.DisplayDevice.SetColorData(preset.colorData);
                }
                catch (Exception ex)
                {
                    Logger.Error($"SetColorData threw an exception: {ex.Message}");
                    result = false;
                }

                if (hdrEnabled && newHdrEnabled)
                {
                    SetHDRState(display, true);

                    applyHdr = false;
                }
            }

            if (applyHdr)
            {
                var display = GetCurrentDisplay();

                var colorData = preset.applyColorData ? preset.colorData : display.DisplayDevice.CurrentColorData;

                SetHDRState(display, newHdrEnabled, colorData);
            }

            if (preset.applyRefreshRate)
            {
                if (!SetRefreshRate(preset.refreshRate))
                {
                    result = false;
                }
            }

            if (preset.applyDithering)
            {
                if (!SetDithering(preset.ditheringEnabled, preset: preset))
                {
                    result = false;
                }
            }

            _lastAppliedPreset = preset;

            return(result);
        }
Ejemplo n.º 6
0
        public NvPreset Clone()
        {
            var preset = new NvPreset(this);

            return(preset);
        }