forked from ChasBoyd/DisplayHDRTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.h
354 lines (315 loc) · 17.7 KB
/
Game.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
#pragma once
#include "DeviceResources.h"
#include "StepTimer.h"
#include "Basicmath.h"
#include <map>
#include <winrt\Windows.Devices.Display.h>
#include <winrt\Windows.Devices.Display.Core.h>
#include <winrt\Windows.Devices.Enumeration.h>
struct rawOutputDesc
{
float MaxLuminance;
float MaxFullFrameLuminance;
float MinLuminance;
};
// A basic game implementation that creates a D3D11 device and
// provides a game loop.
class Game : public DX::IDeviceNotify
{
private:
enum TestingTier
{
DisplayHDR400 = 0,
DisplayHDR500 = 1,
DisplayHDR600 = 2,
DisplayHDR1000 = 3,
DisplayHDR1400 = 4,
DisplayHDR2000 = 5,
DisplayHDR3000 = 6,
DisplayHDR4000 = 7,
DisplayHDR6000 = 8,
DisplayHDR10000 = 9
};
enum ColorGamut
{
GAMUT_Native = 0,
GAMUT_sRGB = 1,
GAMUT_Adobe = 2,
GAMUT_DCIP3 = 3,
GAMUT_BT2100 = 4,
GAMUT_ACES = 5,
};
#define NUM_WBRACKETS 8
UINT32 WhiteLevelBrackets[NUM_WBRACKETS] = { 50, 100, 200, 250, 300, 500, 700, 1000 };
// Used by any test that loads a custom effect or image from file.
struct TestPatternResources
{
std::wstring testTitle; // Mandatory.
std::wstring imageFilename; // Empty means no image is needed for this test.
std::wstring effectShaderFilename; // Empty means no shader is needed for this test.
GUID effectClsid;
// Members above this point need to be specified at app start.
// ---
// Members below this point are generated dynamically.
Microsoft::WRL::ComPtr<IWICBitmapSource> wicSource; // Generated from WIC.
Microsoft::WRL::ComPtr<ID2D1ImageSourceFromWic> d2dSource; // Generated from D2D.
Microsoft::WRL::ComPtr<ID2D1Effect> d2dEffect; // Generated from D2D.
bool imageIsValid; // false means image file is missing or invalid.
bool effectIsValid; // false means effect file is missing or invalid.
};
public:
Game(PWSTR appTitle);
enum class Checkerboard // Which pattern to use in Checkerboard tests 5.x
{
Cb6x4,
Cb4x3,
Cb4x3not,
};
enum class TestPattern
{
StartOfTest, // Must always be first.
ConnectionProperties,
PanelCharacteristics,
ResetInstructions,
PQLevelsInNits,
WarmUp,
TenPercentPeak, // 1.
TenPercentPeakMAX, // 1. MAX
FlashTest, // 2.
FlashTestMAX, // 2. MAX
LongDurationWhite, // 3.
FullFramePeak, // 3. MAX
DualCornerBox, // 4. Total contrast test for TrueBlack
StaticContrastRatio, // 5. was tunnel
ActiveDimming, // 5.1
ActiveDimmingDark, // 5.2
ActiveDimmingSplit, // 5.3
ColorPatches, // 6. 8-10% OPR
ColorPatchesFull, // 6. Fullscreen 100% OPR
BitDepthPrecision, // 7. Uses custom effect.
RiseFallTime, // 8.
ProfileCurve, // 9. Validate tracking of 2084 profile
LocalDimmingContrast, // v1.2.1
BlackLevelHDRvsSDR, // v1.2.2
BlackLevelCrush, // v1.2.3
SubTitleFlicker, // v1.2.4
XRiteColors, // v1.2.5 cycle through the official Xrite patch colors
EndOfMandatoryTests, //
SharpeningFilter, // Uses custom Sine Sweep effect.
ToneMapSpike, // Uses custom Tone Spike effect
TextQuality, // Uses image.
//PQLevelsInNitsDynamic,
OnePixelLinesBW, // Uses image.
OnePixelLinesRG, // Uses image.
ColorPatches709,
FullFrameSDRWhite,
FullFrameSDRWhiteWithHDR,
CalibrateMaxEffectiveValue, // max value to send that has any effect
CalibrateMaxEffectiveFullFrameValue, // MaxFALL after tone mapping
CalibrateMinEffectiveValue, // minimal value that is still visible by user
StaticGradient,
AnimatedGrayGradient,
AnimatedColorGradient,
BlackLevelHdrCorners, // 4.
BlackLevelSdrTunnel, // 5. Tunnel test Moved here from v1.0. Replaced with StaticContrastRatio in v1.1
ColorPatchesMAX, // 6. MAX
EndOfTest, // Must always be last.
Cooldown,
};
// Initialization and management
void Initialize(HWND window, int width, int height);
// Basic game loop
void Tick();
// IDeviceNotify
virtual void OnDeviceLost() override;
virtual void OnDeviceRestored() override;
// Messages
void OnActivated();
void OnDeactivated();
void OnSuspending();
void OnResuming();
void OnWindowSizeChanged(int width, int height);
void OnDisplayChange();
// Properties
void GetDefaultSize(int& width, int& height) const;
// Test pattern control
void SetTestPattern(TestPattern testPattern);
void ChangeTestPattern(bool increment);
void ChangeSubtest( INT32 increment );
void SetShift( bool shift );
bool GetShift( void );
void ToggleXRitePatchAuto( void );
void ChangeXRitePatchDisplayTime(INT32 increment);
void SelectWhiteLevel(INT32 incrememnt);
void StartTestPattern(void);
void ChangeGradientColor(float deltaR, float deltaG, float deltaB);
void ChangeBackBufferFormat(DXGI_FORMAT fmt);
void ChangeCheckerboard( INT32 increment);
bool PauseAnimation();
bool ToggleSubtitle();
bool ToggleInfoTextVisible();
void SetMetadataNeutral(); // OS defaults
void PrintMetadata( ID2D1DeviceContext2* ctx, bool blackText = false );
void PrintTestingTier(ID2D1DeviceContext2* ctx, bool blackText = false);
private:
void ConstructorInternal();
void Update(DX::StepTimer const& timer);
void UpdateDxgiColorimetryInfo();
void InitEffectiveValues();
void SetMetadata(float max, float avg, ColorGamut gamut);
void Render();
bool CheckHDR_On();
bool CheckForDefaults();
void DrawLogo(ID2D1DeviceContext2 *ctx, float c );
void DrawChecker6x4( ID2D1DeviceContext2* ctx, float colorL, float colorR ); // for displays > 20"
void DrawChecker4x3( ID2D1DeviceContext2* ctx, float colorL, float colorR ); // for smaller panels
void DrawChecker4x3n( ID2D1DeviceContext2* ctx, float colorL, float colorR ); // nverse of above
TestingTier GetTestingTier();
WCHAR *GetTierName(TestingTier tier);
float GetTierLuminance(Game::TestingTier tier);
// float ComputeGamutArea( float2 r, float2 g, float2 b );
// float ComputeGamutCoverage( float2 r1, float2 g1, float2 b1, float2 r2, float2 g2, float2 b2 );
// Drawing code specific for each test pattern.
void GenerateTestPattern_StartOfTest(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_ConnectionProperties(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_PanelCharacteristics(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_ResetInstructions(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_CalibrateMaxEffectiveValue(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_CalibrateMaxFullFrameValue(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_CalibrateMinEffectiveValue(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_PQLevelsInNits(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_WarmUp(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_Cooldown(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_TenPercentPeak(ID2D1DeviceContext2* ctx); // 1
void GenerateTestPattern_TenPercentPeakMAX(ID2D1DeviceContext2* ctx); // 1.0b MAX
void GenerateTestPattern_FlashTest(ID2D1DeviceContext2* ctx); // 2
void GenerateTestPattern_FlashTestMAX(ID2D1DeviceContext2* ctx); // 2. Max
void GenerateTestPattern_LongDurationWhite(ID2D1DeviceContext2* ctx); // 3
void GenerateTestPattern_DualCornerBox(ID2D1DeviceContext2* ctx); // 4
void GenerateTestPattern_StaticContrastRatio(ID2D1DeviceContext2 * ctx); // 5
void GenerateTestPattern_ActiveDimming(ID2D1DeviceContext2 * ctx); // 5.1
void GenerateTestPattern_ActiveDimmingDark(ID2D1DeviceContext2 * ctx); // 5.2
void GenerateTestPattern_ActiveDimmingSplit(ID2D1DeviceContext2 * ctx); // 5.3
void GenerateTestPattern_ColorPatches( ID2D1DeviceContext2* ctx, bool full = false ); // 6
void GenerateTestPattern_ColorPatchesMAX(ID2D1DeviceContext2* ctx, float OPR ); // 6.b MAX legacy
void GenerateTestPattern_BitDepthPrecision(ID2D1DeviceContext2* ctx); // 7
void GenerateTestPattern_RiseFallTime(ID2D1DeviceContext2* ctx); // 8
void GenerateTestPattern_ProfileCurve(ID2D1DeviceContext2* ctx); // 9
void GenerateTestPattern_LocalDimmingContrast(ID2D1DeviceContext2* ctx); // v1.2
void GenerateTestPattern_BlackLevelHDRvsSDR(ID2D1DeviceContext2* ctx); // v1.2
void GenerateTestPattern_BlackLevelCrush(ID2D1DeviceContext2* ctx); // v1.2
void GenerateTestPattern_SubTitleFlicker(ID2D1DeviceContext2* ctx); // v1.2
void GenerateTestPattern_XRiteColors(ID2D1DeviceContext2* ctx); // v1.2
void GenerateTestPattern_EndOfMandatoryTests(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_FullFramePeak(ID2D1DeviceContext2* ctx); // 3.b MAX legacy
void GenerateTestPattern_BlackLevelHdrCorners(ID2D1DeviceContext2* ctx); // 4 legacy
void GenerateTestPattern_SharpeningFilter(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_ToneMapSpike(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_FullFrameSDRWhite(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_FullFrameSDRWhiteWithHDR(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_ColorPatches709(ID2D1DeviceContext2 * ctx);
void GenerateTestPattern_StaticGradient(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_AnimatedGrayGradient(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_AnimatedColorGradient(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_BlackLevelSdrTunnel(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_BlackLevelSdrTunnelTrueBlack(ID2D1DeviceContext2* ctx);
void GenerateTestPattern_EndOfTest(ID2D1DeviceContext2* ctx);
// Generalized routine for all tests that involve loading an image.
void GenerateTestPattern_ImageCommon(ID2D1DeviceContext2* ctx, TestPatternResources resources);
// Common rendering subroutines.
void Clear();
void RenderText(ID2D1DeviceContext2* ctx, IDWriteTextFormat* fmt, std::wstring text, D2D1_RECT_F textPos, bool useBlackText = false);
void CreateDeviceIndependentResources();
void CreateDeviceDependentResources();
void CreateWindowSizeDependentResources();
void LoadTestPatternResources(TestPatternResources* resources);
void LoadImageResources(TestPatternResources* resources);
void LoadEffectResources(TestPatternResources* resources);
// Device resources.
std::unique_ptr<DX::DeviceResources> m_deviceResources;
DXGI_ADAPTER_DESC m_adapterDesc;
winrt::hstring m_monitorName; // friendlier name
winrt::Windows::Devices::Display::DisplayMonitorConnectionKind m_connectionKind; // Internal vs wired
winrt::Windows::Devices::Display::DisplayMonitorPhysicalConnectorKind m_physicalConnectorKind; // HDMI vs DisplayPort
winrt::Windows::Devices::Display::DisplayMonitorDescriptorKind m_connectionDescriptorKind; // EDID vs DisplayID
DXGI_RATIONAL m_verticalSyncRate; // Current mode's max rate
DWORD m_displayFrequency; // from EnumDisplaySettings -not precise
Microsoft::WRL::ComPtr<ID2D1LinearGradientBrush> m_gradientBrush;
Microsoft::WRL::ComPtr<IDWriteTextLayout> m_testTitleLayout;
Microsoft::WRL::ComPtr<IDWriteTextLayout> m_panelInfoTextLayout;
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> m_whiteBrush;
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> m_blackBrush;
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> m_redBrush;
DXGI_OUTPUT_DESC1 m_outputDesc;
rawOutputDesc m_rawOutDesc; // base values from OS before scaling due to brightness setting
// Device independent resources.
Microsoft::WRL::ComPtr<IDWriteTextFormat> m_smallFormat;
Microsoft::WRL::ComPtr<IDWriteTextFormat> m_largeFormat;
Microsoft::WRL::ComPtr<IDWriteTextFormat> m_monospaceFormat;
D2D1_RECT_F m_testTitleRect; // Where to draw each test's title
D2D1_RECT_F m_largeTextRect; // Where to draw large text for the test, if applicable
D2D1_RECT_F m_MetadataTextRect; // where we display the metadata (lower right
D2D1_RECT_F m_TestingTierTextRect; // place to dislay the current tier (upper right)
TestingTier m_testingTier; // what tier we are testing for
TestPattern m_currentTest;
TestPattern m_cachedTest;
bool m_shiftKey; // whether shift key is pressed
INT32 m_currentColor;
INT32 m_currentBlack; // for black crush test
INT32 m_currentProfileTile;
INT32 m_modeWidth; // resolution of current mode (actually native res now)
INT32 m_modeHeight;
float m_snoodDiam; // outside diameter of sensor snood in mm
UINT32 m_maxPQCode; // PQ code of maxLuminance
INT32 m_maxProfileTile; // highest tile worth testing on this panel
float m_flashOn;
Checkerboard m_checkerboard; // for tests 5.x
D2D1_COLOR_F m_gradientColor;
INT32 m_LocalDimmingBars; // v1.2 Local Dimming Contrast Test
INT32 m_subtitleVisible; // v1.4 Subtitle Flicker Test
INT32 m_currentXRiteIndex; // v1.5 XRite Color Patch
bool m_XRitePatchAutoMode; // v1.5 flag for when it auto animates
float m_XRitePatchDisplayTime; // how long to show XRite color patch in auto mode
// float m_XRitePatchTimer; // timer for tracking above
INT32 m_whiteLevelBracket; // what tier/level we should use
INT32 m_XRiteIntensity; // correction to X-Rite levels
float m_gradientAnimationBase;
bool m_bPaused;
bool m_showExplanatoryText;
float m_testTimeRemainingSec;
float m_gamutVolume;
//TODO: these code values could all be INTs
float m_maxEffectivesRGBValue; // Code levels via manual test
float m_maxFullFramesRGBValue;
float m_minEffectivesRGBValue;
float m_maxEffectivePQValue; // PQ is using HDR10 10bit encoding
float m_maxFullFramePQValue;
float m_minEffectivePQValue;
float m_staticContrastPQValue; // for test 5. static contrast
float m_staticContrastsRGBValue;
float m_activeDimming50PQValue; // for tests 5.1, 5.2, 5.3 on Active Dimming
float m_activeDimming05PQValue;
float m_activeDimming50sRGBValue; // probably no active dimming in sRGB mode
float m_activeDimming05sRGBValue; // only in HDR mode
bool m_newTestSelected; // Used for one-time initialization of test variables.
bool m_dxgiColorInfoStale;
DXGI_HDR_METADATA_HDR10 m_Metadata;
ColorGamut m_MetadataGamut;
// TODO: integrate this with the other test resources
std::map<TestPattern, TestPatternResources> m_testPatternResources;
std::wstring m_hideTextString;
// Rendering loop timer.
DX::StepTimer m_timer;
float m_totalTime;
PWSTR m_appTitle;
};