Skip to content

Commit b9db102

Browse files
committed
before refreshrate overhaul
1 parent b8d64c7 commit b9db102

File tree

8 files changed

+4031
-50
lines changed

8 files changed

+4031
-50
lines changed

ColorControl/MainForm.cs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -351,38 +351,6 @@ private void MainForm_ResizeEnd(object sender, EventArgs e)
351351

352352
private async void MainForm_Click(object sender, EventArgs e)
353353
{
354-
//_powerEventDispatcher.SendEvent(PowerEventDispatcher.Event_Shutdown);
355-
//PipeUtils.SendMessage(SvcMessageType.RestartAfterUpdate);
356-
//Program.Restart();
357-
//Environment.Exit(0);
358-
//InstallUpdate("");
359-
//await Test();
360-
361-
//var dm = DisplayManager.Create(DisplayManagerOptions.None);
362-
363-
//var targets = dm.GetCurrentTargets();
364-
365-
//var monitor = targets.First().TryGetMonitor();
366-
367-
//var result = dm.TryReadCurrentStateForAllTargets();
368-
//var state = result.State;
369-
370-
//var res2 = state.TryFunctionalize(DisplayStateFunctionalizeOptions.None);
371-
372-
////var path = state.ConnectTarget(targets.First());
373-
//var path = state.GetPathForTarget(targets.First());
374-
375-
//var res3 = state.TryApply(DisplayStateApplyOptions.None);
376-
377-
//path.IsInterlaced = false;
378-
//path.Scaling = DisplayPathScaling.Identity;
379-
//path.SourcePixelFormat = Windows.Graphics.DirectX.DirectXPixelFormat.R8G8B8A8UIntNormalized;
380-
//path.PresentationRate = null;
381-
//path.Properties.Clear();
382-
//path.WireFormat = null;
383-
384-
//var modes = path.FindModes(DisplayModeQueryOptions.None);
385-
386354
_serviceManager.NvService?.TestResolution();
387355
}
388356

ColorControl/Services/Common/GraphicsService.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using ColorControl.Shared.Common;
2+
using ColorControl.Shared.Contracts;
23
using ColorControl.Shared.Native;
34
using NWin32;
45
using NWin32.NativeTypes;
6+
using Shared.Native;
57
using System;
68
using System.Collections.Generic;
79
using System.Diagnostics;
@@ -99,6 +101,18 @@ protected List<uint> GetAvailableRefreshRatesInternal(string displayName, bool p
99101
return list;
100102
}
101103

104+
protected List<Rational> GetAvailableRefreshRatesV2(string displayName, bool portrait, int horizontal, int vertical)
105+
{
106+
var dxWrapper = new DXWrapper();
107+
108+
var modes = dxWrapper.GetModes(displayName, (uint)horizontal, (uint)vertical);
109+
110+
var refreshRates = modes.Select(m => m.RefreshRate).DistinctBy(r => r.ToString())
111+
.Select(r => new Rational(r.Numerator, r.Denominator));
112+
113+
return refreshRates.ToList();
114+
}
115+
102116
protected uint GetCurrentRefreshRate(string displayName)
103117
{
104118
DEVMODEA devMode;

ColorControl/Services/LG/LgPanel.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using ColorControl.Shared.EventDispatcher;
77
using ColorControl.Shared.Forms;
88
using ColorControl.Shared.Native;
9-
using ColorControl.Shared.Services;
109
using LgTv;
1110
using NLog;
1211
using NStandard;
@@ -811,7 +810,12 @@ private void mnuLgExpert_Opening(object sender, CancelEventArgs e)
811810
mnuLgOLEDMotionPro.Visible = visible;
812811
miLgEnableMotionPro.Visible = enableVisible;
813812

814-
var svcMenuFlagVisible = new[] { "A2", "B2", "C2", "G2", "A3", "B3", "C3", "G3", "CS3" }.Any(m => device?.ModelName?.Contains(m) == true);
813+
var svcMenuFlagVisible = new[]
814+
{
815+
"A2", "B2", "C2", "G2", "CS2",
816+
"A3", "B3", "C3", "G3", "CS3",
817+
"C4", "G4", "M4", "CS4"
818+
}.Any(m => device?.ModelName?.Contains(m) == true);
815819

816820
mnuLgSetSvcMenuFlag.Visible = svcMenuFlagVisible;
817821

ColorControl/Services/NVIDIA/NvPanel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ private void BuildNvRefreshRateResolutionMenu(NvPreset preset)
547547
if (mnuRefreshRate.DropDownItems.Count == 1)
548548
{
549549
var refreshRates = _nvService.GetAvailableRefreshRates(preset);
550+
551+
//var v2 = _nvService.GetAvailableRefreshRatesV2(preset);
552+
550553
_lastDisplayRefreshRates = displayName;
551554

552555
foreach (var refreshRate in refreshRates)

ColorControl/Services/NVIDIA/NvService.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,25 @@ public List<uint> GetAvailableRefreshRates(NvPreset preset = null)
10811081
return GetAvailableRefreshRatesInternal(display.Name, portrait, desktopRect.Width, desktopRect.Height);
10821082
}
10831083

1084+
public List<Rational> GetAvailableRefreshRatesV2(NvPreset preset = null)
1085+
{
1086+
if (preset != null)
1087+
{
1088+
SetCurrentDisplay(preset);
1089+
}
1090+
1091+
var display = GetCurrentDisplay();
1092+
if (display == null)
1093+
{
1094+
return [];
1095+
}
1096+
1097+
var portrait = IsDisplayInPortraitMode(display);
1098+
var desktopRect = GetDesktopRect(display);
1099+
1100+
return GetAvailableRefreshRatesV2(display.Name, portrait, desktopRect.Width, desktopRect.Height);
1101+
}
1102+
10841103
private Rectangle GetDesktopRect(Display display)
10851104
{
10861105
try
@@ -1296,6 +1315,12 @@ public void SetColorProfile(Display display, string name)
12961315

12971316
public void TestResolution()
12981317
{
1318+
//CCD.SetDisplayConfig();
1319+
1320+
//var dxWrapper = new DXWrapper();
1321+
1322+
//dxWrapper.Test();
1323+
12991324
//var display = GetCurrentDisplay();
13001325

13011326
//var configs = DisplayApi.GetDisplayConfig();

Shared/Contracts/Rational.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace ColorControl.Shared.Contracts;
2+
3+
public class Rational
4+
{
5+
public uint Numerator { get; }
6+
public uint Denominator { get; }
7+
8+
public Rational(uint numerator, uint denominator)
9+
{
10+
Numerator = numerator;
11+
Denominator = denominator;
12+
}
13+
14+
public override string ToString()
15+
{
16+
var value = Numerator / (double)Denominator;
17+
18+
return $"{value:0.000}";
19+
}
20+
}

Shared/Native/CCD.cs

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,27 @@ public static void GetAllPaths()
7777
var result = NativeMethods.QueryDisplayConfig(QueryDisplayFlags.AllPaths, ref numPathArrayElements, pathArray, ref numModeInfoArrayElements, modeArray, out Unsafe.NullRef<DisplayConfigTopologyId>());
7878
}
7979

80+
public static void SetDisplayConfig()
81+
{
82+
uint numPathArrayElements;
83+
uint numModeInfoArrayElements;
84+
85+
NativeMethods.GetDisplayConfigBufferSizes(QueryDisplayFlags.AllPaths, out numPathArrayElements, out numModeInfoArrayElements);
86+
87+
var pathArray = new DisplayConfigPathInfo[numPathArrayElements];
88+
var modeArray = new DisplayConfigModeInfo[numModeInfoArrayElements];
89+
90+
var result = NativeMethods.QueryDisplayConfig(QueryDisplayFlags.AllPaths, ref numPathArrayElements, pathArray, ref numModeInfoArrayElements, modeArray, out Unsafe.NullRef<DisplayConfigTopologyId>());
91+
92+
var sourceIndex = pathArray[0].sourceInfo.modeInfoIdx;
93+
var targetIndex = pathArray[0].targetInfo.modeInfoIdx;
94+
95+
modeArray[targetIndex].targetMode.targetVideoSignalInfo.vSyncFreq = new DisplayConfigRational { denominator = 1000, numerator = 145000 };
96+
97+
result = NativeMethods.SetDisplayConfig(1, pathArray, 2, modeArray, SdcFlags.Apply | SdcFlags.UseSuppliedDisplayConfig | SdcFlags.AllowChanges);
98+
}
99+
100+
80101
public static LUID GetAdapterId(string displayName = null)
81102
{
82103
return ExecuteForModeConfig((modeInfo) =>
@@ -786,8 +807,8 @@ enum DisplayConfigScaling : uint
786807
[StructLayout(LayoutKind.Sequential)]
787808
struct DisplayConfigRational
788809
{
789-
uint numerator;
790-
uint denominator;
810+
public uint numerator;
811+
public uint denominator;
791812
}
792813

793814
[Flags]
@@ -886,36 +907,36 @@ enum D3DmdtVideoSignalStandard : uint
886907
[StructLayout(LayoutKind.Sequential)]
887908
struct DisplayConfigVideoSignalInfo
888909
{
889-
long pixelRate;
890-
DisplayConfigRational hSyncFreq;
891-
DisplayConfigRational vSyncFreq;
892-
DisplayConfig2DRegion activeSize;
893-
DisplayConfig2DRegion totalSize;
910+
public long pixelRate;
911+
public DisplayConfigRational hSyncFreq;
912+
public DisplayConfigRational vSyncFreq;
913+
public DisplayConfig2DRegion activeSize;
914+
public DisplayConfig2DRegion totalSize;
894915

895-
D3DmdtVideoSignalStandard videoStandard;
896-
DisplayConfigScanLineOrdering ScanLineOrdering;
916+
public D3DmdtVideoSignalStandard videoStandard;
917+
public DisplayConfigScanLineOrdering ScanLineOrdering;
897918
}
898919

899920
[StructLayout(LayoutKind.Sequential)]
900921
struct DisplayConfigTargetMode
901922
{
902-
DisplayConfigVideoSignalInfo targetVideoSignalInfo;
923+
public DisplayConfigVideoSignalInfo targetVideoSignalInfo;
903924
}
904925

905926
[StructLayout(LayoutKind.Sequential)]
906927
struct PointL
907928
{
908-
int x;
909-
int y;
929+
public int x;
930+
public int y;
910931
}
911932

912933
[StructLayout(LayoutKind.Sequential)]
913934
struct DisplayConfigSourceMode
914935
{
915-
uint width;
916-
uint height;
917-
DisplayConfigPixelFormat pixelFormat;
918-
PointL position;
936+
public uint width;
937+
public uint height;
938+
public DisplayConfigPixelFormat pixelFormat;
939+
public PointL position;
919940
}
920941

921942
[StructLayout(LayoutKind.Sequential)]

0 commit comments

Comments
 (0)