diff --git a/addons/resource.language.en_gb/resources/strings.po b/addons/resource.language.en_gb/resources/strings.po
index b15369af00bfb..d5382d719cc24 100644
--- a/addons/resource.language.en_gb/resources/strings.po
+++ b/addons/resource.language.en_gb/resources/strings.po
@@ -6129,7 +6129,17 @@ msgctxt "#13036"
msgid "Failed for {0:s}"
msgstr ""
-#empty strings from id 13037 to 13049
+#: addons/skin.estuary/xml/DialogButtonMenu.xml
+msgctxt "#13037"
+msgid "Toggle Windows HDR On"
+msgstr ""
+
+#: addons/skin.estuary/xml/DialogButtonMenu.xml
+msgctxt "#13038"
+msgid "Toggle Windows HDR Off"
+msgstr ""
+
+#empty strings from id 13039 to 13049
#: xbmc/powermanagement/PowerManager.cpp
msgctxt "#13050"
diff --git a/addons/skin.estuary/xml/DialogButtonMenu.xml b/addons/skin.estuary/xml/DialogButtonMenu.xml
index 90839ff75b149..46db09c477885 100644
--- a/addons/skin.estuary/xml/DialogButtonMenu.xml
+++ b/addons/skin.estuary/xml/DialogButtonMenu.xml
@@ -22,6 +22,16 @@
Quit()
System.ShowExitButton
+ -
+
+ WindowsHDRSwitch()
+ System.WindowsHdrOff
+
+ -
+
+ WindowsHDRSwitch()
+ System.WindowsHdrOn
+
-
Powerdown()
diff --git a/xbmc/GUIInfoManager.cpp b/xbmc/GUIInfoManager.cpp
index b35196033f183..4252f917bd911 100644
--- a/xbmc/GUIInfoManager.cpp
+++ b/xbmc/GUIInfoManager.cpp
@@ -1705,7 +1705,9 @@ const infomap system_labels[] = {{ "hasnetwork", SYSTEM_ETHERNET_LINK_ACT
{ "hascms", SYSTEM_HAS_CMS },
{ "privacypolicy", SYSTEM_PRIVACY_POLICY },
{ "haspvraddon", SYSTEM_HAS_PVR_ADDON },
- { "supportscpuusage", SYSTEM_SUPPORTS_CPU_USAGE }};
+ { "supportscpuusage", SYSTEM_SUPPORTS_CPU_USAGE },
+ { "windowshdroff", SYSTEM_WINDOWS_HDR_OFF },
+ { "windowshdron", SYSTEM_WINDOWS_HDR_ON }};
/// \page modules__infolabels_boolean_conditions
/// \table_row3{ `System.HasAddon(id)`,
diff --git a/xbmc/guilib/guiinfo/GUIInfoLabels.h b/xbmc/guilib/guiinfo/GUIInfoLabels.h
index c484bfdcfe3e8..504ec1e985ae1 100644
--- a/xbmc/guilib/guiinfo/GUIInfoLabels.h
+++ b/xbmc/guilib/guiinfo/GUIInfoLabels.h
@@ -134,6 +134,8 @@
#define SYSTEM_INTERNET_STATE 159
#define SYSTEM_HAS_INPUT_HIDDEN 160
#define SYSTEM_HAS_PVR_ADDON 161
+#define SYSTEM_WINDOWS_HDR_OFF 170
+#define SYSTEM_WINDOWS_HDR_ON 171
#define SYSTEM_ALARM_LESS_OR_EQUAL 180
#define SYSTEM_PROFILECOUNT 181
#define SYSTEM_ISFULLSCREEN 182
diff --git a/xbmc/guilib/guiinfo/SystemGUIInfo.cpp b/xbmc/guilib/guiinfo/SystemGUIInfo.cpp
index 2736d2bec788e..15b7da43d92e7 100644
--- a/xbmc/guilib/guiinfo/SystemGUIInfo.cpp
+++ b/xbmc/guilib/guiinfo/SystemGUIInfo.cpp
@@ -22,6 +22,9 @@
#endif
#include "powermanagement/PowerManager.h"
#include "profiles/ProfileManager.h"
+#if defined(TARGET_WINDOWS)
+#include "rendering/dx/deviceresources.h"
+#endif
#include "settings/AdvancedSettings.h"
#include "settings/DisplaySettings.h"
#include "settings/MediaSettings.h"
@@ -570,6 +573,20 @@ bool CSystemGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int context
case SYSTEM_SHOW_EXIT_BUTTON:
value = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_showExitButton;
return true;
+ case SYSTEM_WINDOWS_HDR_OFF:
+#if defined(TARGET_WINDOWS)
+ value = DX::DeviceResources::Get()->IsDisplayHDRCapable() && !DX::DeviceResources::Get()->IsDisplayHDREnabled();
+#else
+ value = false;
+#endif
+ return true;
+ case SYSTEM_WINDOWS_HDR_ON:
+#if defined(TARGET_WINDOWS)
+ value = DX::DeviceResources::Get()->IsDisplayHDRCapable() && DX::DeviceResources::Get()->IsDisplayHDREnabled();
+#else
+ value = false;
+#endif
+ return true;
case SYSTEM_HAS_LOGINSCREEN:
value = CServiceBroker::GetSettingsComponent()->GetProfileManager()->UsingLoginScreen();
return true;
diff --git a/xbmc/interfaces/builtins/GUIBuiltins.cpp b/xbmc/interfaces/builtins/GUIBuiltins.cpp
index b872fedf3b735..be9de5a718128 100644
--- a/xbmc/interfaces/builtins/GUIBuiltins.cpp
+++ b/xbmc/interfaces/builtins/GUIBuiltins.cpp
@@ -31,6 +31,9 @@
#include "utils/URIUtils.h"
#include "utils/log.h"
#include "windows/GUIMediaWindow.h"
+#if defined(TARGET_WINDOWS)
+#include "windowing/windows/WinSystemWin32.h"
+#endif
using namespace KODI::MESSAGING;
@@ -375,6 +378,15 @@ static int ToggleDirty(const std::vector&)
return 0;
}
+static int WindowsHDRSwitch(const std::vector&)
+{
+#if defined(TARGET_WINDOWS)
+ CWinSystemWin32::WindowsHDRSwitch();
+ CApplicationMessenger::GetInstance().SendMsg(TMSG_RESTARTAPP);
+#endif
+ return 0;
+}
+
// Note: For new Texts with comma add a "\" before!!! Is used for table text.
//
/// \page page_List_of_built_in_functions
@@ -564,6 +576,7 @@ CBuiltins::CommandMap CGUIBuiltins::GetOperations() const
{"setproperty", {"Sets a window property for the current focused window/dialog (key,value)", 2, SetProperty}},
{"setstereomode", {"Changes the stereo mode of the GUI. Params can be: toggle, next, previous, select, tomono or any of the supported stereomodes (off, split_vertical, split_horizontal, row_interleaved, hardware_based, anaglyph_cyan_red, anaglyph_green_magenta, anaglyph_yellow_blue, monoscopic)", 1, SetStereoMode}},
{"takescreenshot", {"Takes a Screenshot", 0, Screenshot}},
- {"toggledirtyregionvisualization", {"Enables/disables dirty-region visualization", 0, ToggleDirty}}
+ {"toggledirtyregionvisualization", {"Enables/disables dirty-region visualization", 0, ToggleDirty}},
+ {"windowshdrswitch", {"Enables/disables Windows HDR and restart Kodi", 0, WindowsHDRSwitch}}
};
}
diff --git a/xbmc/rendering/dx/DeviceResources.cpp b/xbmc/rendering/dx/DeviceResources.cpp
index 3b3333895b2e5..9caee3098e327 100644
--- a/xbmc/rendering/dx/DeviceResources.cpp
+++ b/xbmc/rendering/dx/DeviceResources.cpp
@@ -1118,7 +1118,7 @@ bool DX::DeviceResources::IsDisplayHDREnabled()
ComPtr pOutput;
ComPtr pOutput6;
DXGI_HDR_METADATA_HDR10 hdr10 = {};
- DXGI_OUTPUT_DESC1 od;
+ DXGI_OUTPUT_DESC1 od = {};
bool hdrCapable = false;
bool hdrEnabled = false;
@@ -1272,3 +1272,34 @@ void DX::DeviceResources::SetColorSpace1(const DXGI_COLOR_SPACE_TYPE colorSpace)
}
}
}
+
+bool DX::DeviceResources::IsDisplayHDRCapable() const
+{
+ ComPtr pOutput;
+ ComPtr pOutput6;
+ DXGI_OUTPUT_DESC1 od = {};
+
+ if (m_swapChain == nullptr)
+ return false;
+
+ if (SUCCEEDED(m_swapChain->GetContainingOutput(pOutput.GetAddressOf())))
+ {
+ if (SUCCEEDED(pOutput.As(&pOutput6)))
+ {
+ if (SUCCEEDED(pOutput6->GetDesc1(&od)))
+ {
+ if (od.MaxLuminance >= 400.0)
+ {
+ CLog::LogF(LOGDEBUG, "Monitor HDR capable detected.");
+ return true;
+ }
+ }
+ else
+ {
+ CLog::LogF(LOGERROR, "DXGI GetDesc1 failed");
+ }
+ }
+ }
+
+ return false;
+}
diff --git a/xbmc/rendering/dx/DeviceResources.h b/xbmc/rendering/dx/DeviceResources.h
index a859f0210af35..4ef8ff6d2d7d9 100644
--- a/xbmc/rendering/dx/DeviceResources.h
+++ b/xbmc/rendering/dx/DeviceResources.h
@@ -79,6 +79,7 @@ namespace DX
bool SetFullScreen(bool fullscreen, RESOLUTION_INFO& res);
+ bool IsDisplayHDRCapable() const;
bool IsDisplayHDREnabled();
void SetHdrMetaData(DXGI_HDR_METADATA_HDR10& hdr10) const;
void SetColorSpace1(const DXGI_COLOR_SPACE_TYPE colorSpace) const;
diff --git a/xbmc/windowing/windows/WinSystemWin32.cpp b/xbmc/windowing/windows/WinSystemWin32.cpp
index 9c44f46d5e855..597381f594243 100644
--- a/xbmc/windowing/windows/WinSystemWin32.cpp
+++ b/xbmc/windowing/windows/WinSystemWin32.cpp
@@ -1193,3 +1193,72 @@ bool CWinSystemWin32::MessagePump()
{
return m_winEvents->MessagePump();
}
+
+void CWinSystemWin32::WindowsHDRSwitch()
+{
+ uint32_t pathCount, modeCount;
+
+ uint8_t set[] = {0x0A, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x14, 0x81, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
+
+ uint8_t request[] = {0x09, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x7C, 0x6F, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0xDB, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00};
+
+ if (ERROR_SUCCESS == GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &pathCount, &modeCount))
+ {
+ DISPLAYCONFIG_PATH_INFO* pathsArray = nullptr;
+ DISPLAYCONFIG_MODE_INFO* modesArray = nullptr;
+
+ const size_t sizePathsArray = pathCount * sizeof(DISPLAYCONFIG_PATH_INFO);
+ const size_t sizeModesArray = modeCount * sizeof(DISPLAYCONFIG_MODE_INFO);
+
+ pathsArray = static_cast(std::malloc(sizePathsArray));
+ modesArray = static_cast(std::malloc(sizeModesArray));
+
+ if (pathsArray != nullptr && modesArray != nullptr)
+ {
+ std::memset(pathsArray, 0, sizePathsArray);
+ std::memset(modesArray, 0, sizeModesArray);
+
+ if (ERROR_SUCCESS == QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &pathCount, pathsArray,
+ &modeCount, modesArray, 0))
+ {
+ DISPLAYCONFIG_DEVICE_INFO_HEADER* setPacket =
+ reinterpret_cast(set);
+ DISPLAYCONFIG_DEVICE_INFO_HEADER* requestPacket =
+ reinterpret_cast(request);
+
+ for (int i = 0; i < modeCount; i++)
+ {
+ if (modesArray[i].infoType == DISPLAYCONFIG_MODE_INFO_TYPE_TARGET)
+ {
+ setPacket->adapterId.HighPart = modesArray[i].adapterId.HighPart;
+ setPacket->adapterId.LowPart = modesArray[i].adapterId.LowPart;
+ setPacket->id = modesArray[i].id;
+
+ requestPacket->adapterId.HighPart = modesArray[i].adapterId.HighPart;
+ requestPacket->adapterId.LowPart = modesArray[i].adapterId.LowPart;
+ requestPacket->id = modesArray[i].id;
+ }
+ }
+
+ if (ERROR_SUCCESS == DisplayConfigGetDeviceInfo(requestPacket))
+ {
+ if (request[20] == 0xD1) // HDR is OFF
+ {
+ set[20] = 1;
+ DisplayConfigSetDeviceInfo(setPacket);
+ }
+ else if (request[20] == 0xD3) // HDR is ON
+ {
+ set[20] = 0;
+ DisplayConfigSetDeviceInfo(setPacket);
+ }
+ }
+ }
+ std::free(pathsArray);
+ std::free(modesArray);
+ }
+ }
+}
diff --git a/xbmc/windowing/windows/WinSystemWin32.h b/xbmc/windowing/windows/WinSystemWin32.h
index b5c8cef4ac40e..41846590fa0c4 100644
--- a/xbmc/windowing/windows/WinSystemWin32.h
+++ b/xbmc/windowing/windows/WinSystemWin32.h
@@ -127,6 +127,8 @@ class CWinSystemWin32 : public CWinSystemBase
// winevents override
bool MessagePump() override;
+ static void WindowsHDRSwitch();
+
protected:
bool CreateNewWindow(const std::string& name, bool fullScreen, RESOLUTION_INFO& res) override = 0;
virtual void UpdateStates(bool fullScreen);