before refreshrate overhaul

This commit is contained in:
Vincent Maas committed 2024-04-06 13:29:02 +02:00
1 parent b8d64c7322
commit b9db10262b
8 files changed
+4031 -50

No files matched your search

-32
View File
@@ -351,38 +351,6 @@ namespace ColorControl
private async void MainForm_Click(object sender, EventArgs e)
{
//_powerEventDispatcher.SendEvent(PowerEventDispatcher.Event_Shutdown);
//PipeUtils.SendMessage(SvcMessageType.RestartAfterUpdate);
//Program.Restart();
//Environment.Exit(0);
//InstallUpdate("");
//await Test();
//var dm = DisplayManager.Create(DisplayManagerOptions.None);
//var targets = dm.GetCurrentTargets();
//var monitor = targets.First().TryGetMonitor();
//var result = dm.TryReadCurrentStateForAllTargets();
//var state = result.State;
//var res2 = state.TryFunctionalize(DisplayStateFunctionalizeOptions.None);
////var path = state.ConnectTarget(targets.First());
//var path = state.GetPathForTarget(targets.First());
//var res3 = state.TryApply(DisplayStateApplyOptions.None);
//path.IsInterlaced = false;
//path.Scaling = DisplayPathScaling.Identity;
//path.SourcePixelFormat = Windows.Graphics.DirectX.DirectXPixelFormat.R8G8B8A8UIntNormalized;
//path.PresentationRate = null;
//path.Properties.Clear();
//path.WireFormat = null;
//var modes = path.FindModes(DisplayModeQueryOptions.None);
_serviceManager.NvService?.TestResolution();
}
@@ -1,7 +1,9 @@
using ColorControl.Shared.Common;
using ColorControl.Shared.Contracts;
using ColorControl.Shared.Native;
using NWin32;
using NWin32.NativeTypes;
using Shared.Native;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -99,6 +101,18 @@ namespace ColorControl.Services.Common
return list;
}
protected List<Rational> GetAvailableRefreshRatesV2(string displayName, bool portrait, int horizontal, int vertical)
{
var dxWrapper = new DXWrapper();
var modes = dxWrapper.GetModes(displayName, (uint)horizontal, (uint)vertical);
var refreshRates = modes.Select(m => m.RefreshRate).DistinctBy(r => r.ToString())
.Select(r => new Rational(r.Numerator, r.Denominator));
return refreshRates.ToList();
}
protected uint GetCurrentRefreshRate(string displayName)
{
DEVMODEA devMode;
+6 -2
View File
@@ -6,7 +6,6 @@ using ColorControl.Shared.Contracts;
using ColorControl.Shared.EventDispatcher;
using ColorControl.Shared.Forms;
using ColorControl.Shared.Native;
using ColorControl.Shared.Services;
using LgTv;
using NLog;
using NStandard;
@@ -811,7 +810,12 @@ Do you want to continue?"
mnuLgOLEDMotionPro.Visible = visible;
miLgEnableMotionPro.Visible = enableVisible;
var svcMenuFlagVisible = new[] { "A2", "B2", "C2", "G2", "A3", "B3", "C3", "G3", "CS3" }.Any(m => device?.ModelName?.Contains(m) == true);
var svcMenuFlagVisible = new[]
{
"A2", "B2", "C2", "G2", "CS2",
"A3", "B3", "C3", "G3", "CS3",
"C4", "G4", "M4", "CS4"
}.Any(m => device?.ModelName?.Contains(m) == true);
mnuLgSetSvcMenuFlag.Visible = svcMenuFlagVisible;
+3
View File
@@ -547,6 +547,9 @@ namespace ColorControl.Services.NVIDIA
if (mnuRefreshRate.DropDownItems.Count == 1)
{
var refreshRates = _nvService.GetAvailableRefreshRates(preset);
//var v2 = _nvService.GetAvailableRefreshRatesV2(preset);
_lastDisplayRefreshRates = displayName;
foreach (var refreshRate in refreshRates)
+25
View File
@@ -1081,6 +1081,25 @@ namespace ColorControl.Services.NVIDIA
return GetAvailableRefreshRatesInternal(display.Name, portrait, desktopRect.Width, desktopRect.Height);
}
public List<Rational> GetAvailableRefreshRatesV2(NvPreset preset = null)
{
if (preset != null)
{
SetCurrentDisplay(preset);
}
var display = GetCurrentDisplay();
if (display == null)
{
return [];
}
var portrait = IsDisplayInPortraitMode(display);
var desktopRect = GetDesktopRect(display);
return GetAvailableRefreshRatesV2(display.Name, portrait, desktopRect.Width, desktopRect.Height);
}
private Rectangle GetDesktopRect(Display display)
{
try
@@ -1296,6 +1315,12 @@ namespace ColorControl.Services.NVIDIA
public void TestResolution()
{
//CCD.SetDisplayConfig();
//var dxWrapper = new DXWrapper();
//dxWrapper.Test();
//var display = GetCurrentDisplay();
//var configs = DisplayApi.GetDisplayConfig();
+20
View File
@@ -0,0 +1,20 @@
namespace ColorControl.Shared.Contracts;
public class Rational
{
public uint Numerator { get; }
public uint Denominator { get; }
public Rational(uint numerator, uint denominator)
{
Numerator = numerator;
Denominator = denominator;
}
public override string ToString()
{
var value = Numerator / (double)Denominator;
return $"{value:0.000}";
}
}
+37 -16
View File
@@ -77,6 +77,27 @@ namespace ColorControl.Shared.Native
var result = NativeMethods.QueryDisplayConfig(QueryDisplayFlags.AllPaths, ref numPathArrayElements, pathArray, ref numModeInfoArrayElements, modeArray, out Unsafe.NullRef<DisplayConfigTopologyId>());
}
public static void SetDisplayConfig()
{
uint numPathArrayElements;
uint numModeInfoArrayElements;
NativeMethods.GetDisplayConfigBufferSizes(QueryDisplayFlags.AllPaths, out numPathArrayElements, out numModeInfoArrayElements);
var pathArray = new DisplayConfigPathInfo[numPathArrayElements];
var modeArray = new DisplayConfigModeInfo[numModeInfoArrayElements];
var result = NativeMethods.QueryDisplayConfig(QueryDisplayFlags.AllPaths, ref numPathArrayElements, pathArray, ref numModeInfoArrayElements, modeArray, out Unsafe.NullRef<DisplayConfigTopologyId>());
var sourceIndex = pathArray[0].sourceInfo.modeInfoIdx;
var targetIndex = pathArray[0].targetInfo.modeInfoIdx;
modeArray[targetIndex].targetMode.targetVideoSignalInfo.vSyncFreq = new DisplayConfigRational { denominator = 1000, numerator = 145000 };
result = NativeMethods.SetDisplayConfig(1, pathArray, 2, modeArray, SdcFlags.Apply | SdcFlags.UseSuppliedDisplayConfig | SdcFlags.AllowChanges);
}
public static LUID GetAdapterId(string displayName = null)
{
return ExecuteForModeConfig((modeInfo) =>
@@ -786,8 +807,8 @@ namespace ColorControl.Shared.Native
[StructLayout(LayoutKind.Sequential)]
struct DisplayConfigRational
{
uint numerator;
uint denominator;
public uint numerator;
public uint denominator;
}
[Flags]
@@ -886,36 +907,36 @@ namespace ColorControl.Shared.Native
[StructLayout(LayoutKind.Sequential)]
struct DisplayConfigVideoSignalInfo
{
long pixelRate;
DisplayConfigRational hSyncFreq;
DisplayConfigRational vSyncFreq;
DisplayConfig2DRegion activeSize;
DisplayConfig2DRegion totalSize;
public long pixelRate;
public DisplayConfigRational hSyncFreq;
public DisplayConfigRational vSyncFreq;
public DisplayConfig2DRegion activeSize;
public DisplayConfig2DRegion totalSize;
D3DmdtVideoSignalStandard videoStandard;
DisplayConfigScanLineOrdering ScanLineOrdering;
public D3DmdtVideoSignalStandard videoStandard;
public DisplayConfigScanLineOrdering ScanLineOrdering;
}
[StructLayout(LayoutKind.Sequential)]
struct DisplayConfigTargetMode
{
DisplayConfigVideoSignalInfo targetVideoSignalInfo;
public DisplayConfigVideoSignalInfo targetVideoSignalInfo;
}
[StructLayout(LayoutKind.Sequential)]
struct PointL
{
int x;
int y;
public int x;
public int y;
}
[StructLayout(LayoutKind.Sequential)]
struct DisplayConfigSourceMode
{
uint width;
uint height;
DisplayConfigPixelFormat pixelFormat;
PointL position;
public uint width;
public uint height;
public DisplayConfigPixelFormat pixelFormat;
public PointL position;
}
[StructLayout(LayoutKind.Sequential)]
File diff suppressed because it is too large. Load diff