Repository: xbmc/xbmc
File: xbmc/platform/win32/WIN32Util.cpp (C++)

Code before:
      getSourceName.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME;
      getSourceName.header.size = sizeof(getSourceName);

      for (const auto& path : paths)
      {
        getSourceName.header.adapterId.HighPart = path.sourceInfo.adapterId.HighPart;
        getSourceName.header.adapterId.LowPart = path.sourceInfo.adapterId.LowPart;
        getSourceName.header.id = path.sourceInfo.id;

        if (ERROR_SUCCESS == DisplayConfigGetDeviceInfo(&getSourceName.header))
        {
          const std::wstring sourceNameW = getSourceName.viewGdiDeviceName;
          if (g_hWnd == nullptr || deviceNameW == sourceNameW)
          {
            const auto& mode = modes.at(path.targetInfo.modeInfoIdx);

            getColorInfo.header.adapterId.HighPart = mode.adapterId.HighPart;
            getColorInfo.header.adapterId.LowPart = mode.adapterId.LowPart;
            getColorInfo.header.id = mode.id;

            if (ERROR_SUCCESS == DisplayConfigGetDeviceInfo(&getColorInfo.header))
            {
              if (getColorInfo.advancedColorEnabled)
                advancedColorEnabled = true;

              if (getColorInfo.advancedColorSupported && !getColorInfo.wideColorEnforced)
                advancedColorSupported = true;
            }

            if (g_hWnd != nullptr)
              break;
          }
        }
      }
    }
  }
#endif

  if (!advancedColorSupported)
  {
    status = HDR_STATUS::HDR_UNSUPPORTED;
    if (CServiceBroker::IsServiceManagerUp())
      CLog::LogF(LOGDEBUG, "Display is not HDR capable or cannot be detected");
  }
  else
  {
    status = advancedColorEnabled ? HDR_STATUS::HDR_ON : HDR_STATUS::HDR_OFF;
    if (CServiceBroker::IsServiceManagerUp())
      CLog::LogF(LOGDEBUG, "Display is HDR capable and current HDR status is {}",
                 advancedColorEnabled ? "ON" : "OFF");
  }

Review comment (suggestion):
This is a ugly hack that mostly will break and cause issues in all others systems. Please not do that.

`getColorInfo.advancedColorSupported` by itself signals that display _supports_ HDR  (enabled or not enabled) you can not add other conditions here.

HDR may be supported but not enabled in Windows as you know (and even not enabled needs to be detected as supported).

`getColorInfo.advancedColorEnabled` by itself signals that HDR is _enabled_ this by logic includes that is supported.

Code after:
                advancedColorEnabled = true;

              if (getColorInfo.advancedColorSupported)
                advancedColorSupported = true;
            }

            if (g_hWnd != nullptr)
              break;
          }
        }
      }
    }
  }

  if (!advancedColorSupported)
  {
    status = HDR_STATUS::HDR_UNSUPPORTED;
    if (CServiceBroker::IsServiceManagerUp())
      CLog::LogF(LOGDEBUG, "Display is not HDR capable or cannot be detected");
  }
  else
  {
    status = advancedColorEnabled ? HDR_STATUS::HDR_ON : HDR_STATUS::HDR_OFF;
    if (CServiceBroker::IsServiceManagerUp())
      CLog::LogF(LOGDEBUG, "Display is HDR capable and current HDR status is {}",
                 advancedColorEnabled ? "ON" : "OFF");
  }
#endif // TARGET_WINDOWS_DESKTOP

  return status;
}

HDR_STATUS CWIN32Util::GetWindowsHDRStatus()
{
  HDR_STATUS status = HDR_STATUS::HDR_UNKNOWN;

#ifdef TARGET_WINDOWS_STORE
  if (CSysInfo::GetWindowsDeviceFamily() == CSysInfo::Xbox &&
      HDR_STATUS::HDR_UNKNOWN != (status = CWinRtUtil::GetWindowsHDRStatus()))
    return status;

  // Not Xbox or detection failure: fallback to traditional UWP method
  status = CWinRtUtil::GetWindowsHDRStatusUWP();
  return status == HDR_STATUS::HDR_UNKNOWN ? HDR_STATUS::HDR_UNSUPPORTED : status;
#else
  // WinRT detection available for Win 11 22621 and above.
  if (CSysInfo::IsWindowsVersionAtLeast(CSysInfo::WindowsVersionWin11_22H2) &&
      HDR_STATUS::HDR_UNKNOWN != (status = CWinRtUtil::GetWindowsHDRStatus()))
    return status;

  // Not Win11 or detection failure: fallback to traditional Win32 method