2222#include < uuids.h>
2323#include < Mferror.h>
2424#include < Mfidl.h>
25- #include < dwmapi.h>
2625#include < optional>
2726#include " Helper.h"
2827#include " Times.h"
@@ -472,20 +471,16 @@ CDX11VideoProcessor::~CDX11VideoProcessor()
472471 MH_RemoveHook (SetWindowLongA);
473472}
474473
475- HRESULT CDX11VideoProcessor::Init ( const HWND hwnd, const bool displayHdrChanged, bool * pChangeDevice /* = nullptr */ )
474+ void CDX11VideoProcessor::FillDisplayParams ( )
476475{
477- DLog (L" CDX11VideoProcessor::Init()" );
478-
479- const bool bWindowChanged = displayHdrChanged || (m_hWnd != hwnd);
480- g_hWnd = m_hWnd = hwnd;
481476 m_bHdrPassthroughSupport = false ;
482477 m_bHdrDisplayModeEnabled = false ;
483478 m_DisplayBitsPerChannel = 8 ;
484479
485480 m_bACMEnabled = false ;
486481
487482 MONITORINFOEXW mi = { sizeof (mi) };
488- GetMonitorInfoW (MonitorFromWindow (m_hWnd, MONITOR_DEFAULTTOPRIMARY), (MONITORINFO*) &mi);
483+ GetMonitorInfoW (MonitorFromWindow (m_hWnd, MONITOR_DEFAULTTOPRIMARY), reinterpret_cast <LPMONITORINFO>( &mi) );
489484 DisplayConfig_t displayConfig = {};
490485
491486 if (GetDisplayConfig (mi.szDevice , displayConfig)) {
@@ -494,7 +489,64 @@ HRESULT CDX11VideoProcessor::Init(const HWND hwnd, const bool displayHdrChanged,
494489 m_DisplayBitsPerChannel = displayConfig.bitsPerChannel ;
495490
496491 m_bACMEnabled = !m_bHdrDisplayModeEnabled && displayConfig.ACMEnabled ();
492+
493+ #ifdef _DEBUG
494+ auto displayDesc = std::format (L" \n Display: {} {}" , mi.szDevice , DisplayConfigToString (displayConfig));
495+ if (displayConfig.bitsPerChannel ) {
496+ auto colenc = ColorEncodingToString (displayConfig.colorEncoding );
497+ if (colenc) {
498+ displayDesc.append (std::format (L" \n Color: {} {}-bit" , colenc, displayConfig.bitsPerChannel ));
499+ if (displayConfig.HDRSupported ()) {
500+ displayDesc.append (L" , HDR10: " );
501+ displayDesc.append (displayConfig.HDREnabled () ? L" on" : L" off" );
502+
503+ if (IsWindows11_24H2OrGreater ()) {
504+ auto ColorModeToStr = [](DISPLAYCONFIG_ADVANCED_COLOR_MODE ColorMode) {
505+ std::wstring str;
506+ #define UNPACK_VALUE (VALUE ) case VALUE: str = L" " #VALUE; break ;
507+ switch (ColorMode) {
508+ UNPACK_VALUE (DISPLAYCONFIG_ADVANCED_COLOR_MODE_SDR);
509+ UNPACK_VALUE (DISPLAYCONFIG_ADVANCED_COLOR_MODE_WCG);
510+ UNPACK_VALUE (DISPLAYCONFIG_ADVANCED_COLOR_MODE_HDR);
511+ default :
512+ str = std::to_wstring (static_cast <int >(ColorMode));
513+ };
514+ #undef UNPACK_VALUE
515+
516+ return str;
517+ };
518+
519+ const auto & colors = displayConfig.windows1124H2Colors ;
520+ displayDesc.append (std::format (L" \n Advanced Color: Supported: {}, Active: {}, Limited by OS policy: {}, HDR is supported: {}" ,
521+ colors.advancedColorSupported , colors.advancedColorActive ,
522+ colors.advancedColorLimitedByPolicy , colors.highDynamicRangeSupported ));
523+ displayDesc.append (std::format (L" \n HDR enabled: {}, Wide supported: {}, Wide enabled: {}" ,
524+ colors.highDynamicRangeUserEnabled , colors.wideColorSupported ,
525+ colors.wideColorUserEnabled ));
526+ displayDesc.append (std::format (L" \n Display color mode: {}" , ColorModeToStr (colors.activeColorMode )));
527+ } else {
528+ const auto & colors = displayConfig.advancedColor ;
529+ displayDesc.append (std::format (L" \n Advanced Color: Supported: {}, Enabled: {}, Wide forced: {}, Force disabled: {}" ,
530+ colors.advancedColorSupported , colors.advancedColorEnabled ,
531+ colors.wideColorEnforced , colors.advancedColorForceDisabled ));
532+ }
533+ }
534+ }
535+ }
536+
537+ DLog (L" CDX11VideoProcessor::FillDisplayParams():{}" , displayDesc);
538+ #endif
497539 }
540+ }
541+
542+ HRESULT CDX11VideoProcessor::Init (const HWND hwnd, const bool displayHdrChanged, bool * pChangeDevice/* = nullptr*/ )
543+ {
544+ DLog (L" CDX11VideoProcessor::Init()" );
545+
546+ const bool bWindowChanged = displayHdrChanged || (m_hWnd != hwnd);
547+ g_hWnd = m_hWnd = hwnd;
548+
549+ FillDisplayParams ();
498550
499551 if (m_bIsFullscreen != m_pFilter->m_bIsFullscreen ) {
500552 m_srcVideoTransferFunction = 0 ;
@@ -1429,6 +1481,7 @@ bool CDX11VideoProcessor::HandleHDRToggle()
14291481
14301482 m_bHdrDisplaySwitching = true ;
14311483 bool bRet = false ;
1484+ bool bEnableHDR = false ;
14321485
14331486 if (!m_bHDRModeChangeOutside) {
14341487 if (m_bHdrPassthrough && SourceIsHDR ()) {
@@ -1455,6 +1508,7 @@ bool CDX11VideoProcessor::HandleHDRToggle()
14551508 DLogIf (!bRet, L" CDX11VideoProcessor::HandleHDRToggle() : Toggle HDR ON failed" );
14561509
14571510 if (bRet) {
1511+ bEnableHDR = true ;
14581512 m_hdrModeSavedState.try_emplace (std::move (deviceName), false );
14591513 }
14601514 } else if (bNeedToggleOff) {
@@ -1495,17 +1549,11 @@ bool CDX11VideoProcessor::HandleHDRToggle()
14951549
14961550 if (bRet) {
14971551 Sleep (100 );
1552+ FillDisplayParams ();
14981553
1499- MONITORINFOEXW mi = { sizeof (mi) };
1500- GetMonitorInfoW (MonitorFromWindow (m_hWnd, MONITOR_DEFAULTTOPRIMARY), (MONITORINFO*)&mi);
1501- DisplayConfig_t displayConfig = {};
1502-
1503- if (GetDisplayConfig (mi.szDevice , displayConfig)) {
1504- m_bHdrDisplayModeEnabled = displayConfig.HDREnabled ();
1505- m_bHdrPassthroughSupport = displayConfig.HDRSupported () && m_bHdrDisplayModeEnabled;
1506- m_DisplayBitsPerChannel = displayConfig.bitsPerChannel ;
1507-
1508- m_bACMEnabled = !m_bHdrDisplayModeEnabled && displayConfig.ACMEnabled ();
1554+ for (int i = 0 ; i < 5 && bEnableHDR && !m_bHdrDisplayModeEnabled; i++) {
1555+ Sleep (100 );
1556+ FillDisplayParams ();
15091557 }
15101558 }
15111559
0 commit comments