Skip to content

Commit

Permalink
Toggles Windows HDR On/Off from power options menu
Browse files Browse the repository at this point in the history
  • Loading branch information
thexai committed Dec 24, 2019
1 parent 7bd9d54 commit 0d6d586
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 4 deletions.
12 changes: 11 additions & 1 deletion addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions addons/skin.estuary/xml/DialogButtonMenu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
<onclick>Quit()</onclick>
<visible>System.ShowExitButton</visible>
</item>
<item>
<label>$LOCALIZE[13037]</label>
<onclick>WindowsHDRSwitch()</onclick>
<visible>System.WindowsHdrOff</visible>
</item>
<item>
<label>$LOCALIZE[13038]</label>
<onclick>WindowsHDRSwitch()</onclick>
<visible>System.WindowsHdrOn</visible>
</item>
<item>
<label>$LOCALIZE[13016]</label>
<onclick>Powerdown()</onclick>
Expand Down
4 changes: 3 additions & 1 deletion xbmc/GUIInfoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{ <b>`System.HasAddon(id)`</b>,
Expand Down
2 changes: 2 additions & 0 deletions xbmc/guilib/guiinfo/GUIInfoLabels.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions xbmc/guilib/guiinfo/SystemGUIInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 14 additions & 1 deletion xbmc/interfaces/builtins/GUIBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -375,6 +378,15 @@ static int ToggleDirty(const std::vector<std::string>&)
return 0;
}

static int WindowsHDRSwitch(const std::vector<std::string>&)
{
#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
Expand Down Expand Up @@ -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}}
};
}
33 changes: 32 additions & 1 deletion xbmc/rendering/dx/DeviceResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ bool DX::DeviceResources::IsDisplayHDREnabled()
ComPtr<IDXGIOutput> pOutput;
ComPtr<IDXGIOutput6> pOutput6;
DXGI_HDR_METADATA_HDR10 hdr10 = {};
DXGI_OUTPUT_DESC1 od;
DXGI_OUTPUT_DESC1 od = {};
bool hdrCapable = false;
bool hdrEnabled = false;

Expand Down Expand Up @@ -1272,3 +1272,34 @@ void DX::DeviceResources::SetColorSpace1(const DXGI_COLOR_SPACE_TYPE colorSpace)
}
}
}

bool DX::DeviceResources::IsDisplayHDRCapable() const
{
ComPtr<IDXGIOutput> pOutput;
ComPtr<IDXGIOutput6> 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;
}
1 change: 1 addition & 0 deletions xbmc/rendering/dx/DeviceResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
69 changes: 69 additions & 0 deletions xbmc/windowing/windows/WinSystemWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DISPLAYCONFIG_PATH_INFO*>(std::malloc(sizePathsArray));
modesArray = static_cast<DISPLAYCONFIG_MODE_INFO*>(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<DISPLAYCONFIG_DEVICE_INFO_HEADER*>(set);
DISPLAYCONFIG_DEVICE_INFO_HEADER* requestPacket =
reinterpret_cast<DISPLAYCONFIG_DEVICE_INFO_HEADER*>(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);
}
}
}
2 changes: 2 additions & 0 deletions xbmc/windowing/windows/WinSystemWin32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0d6d586

Please sign in to comment.