diff --git a/xbmc/windowing/win10/WinSystemWin10.cpp b/xbmc/windowing/win10/WinSystemWin10.cpp index ccdbc395f3545..1461d797b04cc 100644 --- a/xbmc/windowing/win10/WinSystemWin10.cpp +++ b/xbmc/windowing/win10/WinSystemWin10.cpp @@ -692,7 +692,14 @@ float CWinSystemWin10::GetGuiSdrPeakLuminance() const */ bool CWinSystemWin10::HasSystemSdrPeakLuminance() { - return CWIN32Util::GetSystemSdrWhiteLevel(std::wstring(), nullptr); + if (m_uiThreadId == GetCurrentThreadId()) + { + const bool hasSystemSdrPeakLum = CWIN32Util::GetSystemSdrWhiteLevel(std::wstring(), nullptr); + m_cachedHasSystemSdrPeakLum = hasSystemSdrPeakLum; + return hasSystemSdrPeakLum; + } + + return m_cachedHasSystemSdrPeakLum; } /*! diff --git a/xbmc/windowing/win10/WinSystemWin10.h b/xbmc/windowing/win10/WinSystemWin10.h index c53fd01872835..6b5be4bb4e92f 100644 --- a/xbmc/windowing/win10/WinSystemWin10.h +++ b/xbmc/windowing/win10/WinSystemWin10.h @@ -156,6 +156,10 @@ class CWinSystemWin10 : public CWinSystemBase bool m_validSystemSdrPeakLuminance{false}; float m_systemSdrPeakLuminance{.0f}; + + DWORD m_uiThreadId{0}; + HDR_STATUS m_cachedHdrStatus{HDR_STATUS::HDR_UNSUPPORTED}; + bool m_cachedHasSystemSdrPeakLum{false}; }; #pragma pack(pop) diff --git a/xbmc/windowing/win10/WinSystemWin10DX.cpp b/xbmc/windowing/win10/WinSystemWin10DX.cpp index 1101b1a7efedd..55167ff3869cc 100644 --- a/xbmc/windowing/win10/WinSystemWin10DX.cpp +++ b/xbmc/windowing/win10/WinSystemWin10DX.cpp @@ -61,6 +61,14 @@ bool CWinSystemWin10DX::CreateNewWindow(const std::string& name, bool fullScreen m_deviceResources = DX::DeviceResources::Get(); m_deviceResources->SetWindow(m_coreWindow); + // saves threadId of current thread (UI thread) + m_uiThreadId = GetCurrentThreadId(); + + // calls these methods to make sure cached values are properly initialized + // and can be used later when called from other thread + IsHDRDisplay(); + HasSystemSdrPeakLuminance(); + if (CWinSystemWin10::CreateNewWindow(name, fullScreen, res) && m_deviceResources->HasValidDevice()) { CGenericTouchInputHandler::GetInstance().RegisterHandler(&CGenericTouchActionHandler::GetInstance()); @@ -166,7 +174,14 @@ void CWinSystemWin10DX::InitHooks(IDXGIOutput* pOutput) bool CWinSystemWin10DX::IsHDRDisplay() { - return (CWIN32Util::GetWindowsHDRStatus() != HDR_STATUS::HDR_UNSUPPORTED); + if (m_uiThreadId == GetCurrentThreadId()) + { + const HDR_STATUS hdrStatus = CWIN32Util::GetWindowsHDRStatus(); + m_cachedHdrStatus = hdrStatus; + return (hdrStatus != HDR_STATUS::HDR_UNSUPPORTED); + } + + return (m_cachedHdrStatus != HDR_STATUS::HDR_UNSUPPORTED); } HDR_STATUS CWinSystemWin10DX::GetOSHDRStatus()