-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (50 loc) · 1.42 KB
/
Copy pathmain.cpp
File metadata and controls
57 lines (50 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "hdr_controller.h"
#include "nv_digital_vibrance.h"
#include <chrono>
#include <string>
#include <thread>
namespace
{
constexpr int kHdrOnVibrance = 60;
constexpr int kHdrOffVibrance = 50;
bool SetDvcWithRetry(const std::wstring& deviceName, int level,
DigitalVibranceState& state, std::wstring& error)
{
for (int attempt = 0; attempt < 8; ++attempt)
{
if (NvDigitalVibrance::Set(deviceName, level, state, error))
{
return true;
}
std::this_thread::sleep_for(std::chrono::milliseconds(300));
}
return false;
}
} // namespace
int main()
{
HdrDisplayState before{};
std::wstring error;
if (!HdrController::QueryPrimaryDisplay(before, error) ||
!before.hdrSupported)
{
return 1;
}
const bool enableHdr = !before.hdrEnabled;
HdrDisplayState after{};
if (!HdrController::SetEnabled(before, enableHdr, after, error))
{
return 2;
}
std::this_thread::sleep_for(std::chrono::milliseconds(450));
const std::wstring deviceName = after.gdiDeviceName.empty()
? before.gdiDeviceName
: after.gdiDeviceName;
const int targetDvc = enableHdr ? kHdrOnVibrance : kHdrOffVibrance;
DigitalVibranceState dvc{};
if (!SetDvcWithRetry(deviceName, targetDvc, dvc, error))
{
return 3;
}
return 0;
}