| 1 |
/* |
| 2 |
* Copyright (C) 2005-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "WinSystemWin10DX.h" |
| 10 |
|
| 11 |
#include "input/touch/generic/GenericTouchActionHandler.h" |
| 12 |
#include "input/touch/generic/GenericTouchInputHandler.h" |
| 13 |
#include "rendering/dx/DirectXHelper.h" |
| 14 |
#include "utils/XTimeUtils.h" |
| 15 |
#include "utils/log.h" |
| 16 |
#include "windowing/WindowSystemFactory.h" |
| 17 |
|
| 18 |
#include "platform/win32/WIN32Util.h" |
| 19 |
|
| 20 |
using namespace std::chrono_literals; |
| 21 |
|
| 22 |
void CWinSystemWin10DX::Register() |
| 23 |
{ |
| 24 |
KODI::WINDOWING::CWindowSystemFactory::RegisterWindowSystem(CreateWinSystem); |
| 25 |
} |
| 26 |
|
| 27 |
std::unique_ptr<CWinSystemBase> CWinSystemWin10DX::CreateWinSystem() |
| 28 |
{ |
| 29 |
return std::make_unique<CWinSystemWin10DX>(); |
| 30 |
} |
| 31 |
|
| 32 |
CWinSystemWin10DX::CWinSystemWin10DX() : CRenderSystemDX() |
| 33 |
{ |
| 34 |
} |
| 35 |
|
| 36 |
CWinSystemWin10DX::~CWinSystemWin10DX() |
| 37 |
{ |
| 38 |
} |
| 39 |
|
| 40 |
void CWinSystemWin10DX::PresentRenderImpl(bool rendered) |
| 41 |
{ |
| 42 |
if (rendered) |
| 43 |
m_deviceResources->Present(); |
| 44 |
|
| 45 |
if (m_delayDispReset && m_dispResetTimer.IsTimePast()) |
| 46 |
{ |
| 47 |
m_delayDispReset = false; |
| 48 |
OnDisplayReset(); |
| 49 |
} |
| 50 |
|
| 51 |
if (!rendered) |
| 52 |
KODI::TIME::Sleep(40ms); |
| 53 |
} |
| 54 |
|
| 55 |
bool CWinSystemWin10DX::CreateNewWindow(const std::string& name, bool fullScreen, RESOLUTION_INFO& res) |
| 56 |
{ |
| 57 |
const MONITOR_DETAILS* monitor = GetDefaultMonitor(); |
| 58 |
if (!monitor) |
| 59 |
return false; |
| 60 |
|
| 61 |
m_deviceResources = DX::DeviceResources::Get(); |
| 62 |
m_deviceResources->SetWindow(m_coreWindow); |
| 63 |
|
| 64 |
// saves threadId of current thread (UI thread) |
| 65 |
m_uiThreadId = GetCurrentThreadId(); |
| 66 |
|
| 67 |
// calls these methods to make sure cached values are properly initialized |
| 68 |
// and can be used later when called from other thread |
| 69 |
IsHDRDisplay(); |
| 70 |
HasSystemSdrPeakLuminance(); |
| 71 |
|
| 72 |
if (CWinSystemWin10::CreateNewWindow(name, fullScreen, res) && m_deviceResources->HasValidDevice()) |
| 73 |
{ |
| 74 |
CGenericTouchInputHandler::GetInstance().RegisterHandler(&CGenericTouchActionHandler::GetInstance()); |
| 75 |
CGenericTouchInputHandler::GetInstance().SetScreenDPI(m_deviceResources->GetDpi()); |
| 76 |
return true; |
| 77 |
} |
| 78 |
return false; |
| 79 |
} |
| 80 |
|
| 81 |
bool CWinSystemWin10DX::DestroyRenderSystem() |
| 82 |
{ |
| 83 |
CRenderSystemDX::DestroyRenderSystem(); |
| 84 |
|
| 85 |
m_deviceResources->Release(); |
| 86 |
m_deviceResources.reset(); |
| 87 |
return true; |
| 88 |
} |
| 89 |
|
| 90 |
void CWinSystemWin10DX::ShowSplash(const std::string & message) |
| 91 |
{ |
| 92 |
CRenderSystemBase::ShowSplash(message); |
| 93 |
|
| 94 |
// this will prevent killing the app by watchdog timeout during loading |
| 95 |
if (m_coreWindow != nullptr) |
| 96 |
m_coreWindow.Dispatcher().ProcessEvents(winrt::Windows::UI::Core::CoreProcessEventsOption::ProcessAllIfPresent); |
| 97 |
} |
| 98 |
|
| 99 |
void CWinSystemWin10DX::SetDeviceFullScreen(bool fullScreen, RESOLUTION_INFO& res) |
| 100 |
{ |
| 101 |
m_deviceResources->SetFullScreen(fullScreen, res); |
| 102 |
} |
| 103 |
|
| 104 |
bool CWinSystemWin10DX::ResizeWindow(int newWidth, int newHeight, int newLeft, int newTop) |
| 105 |
{ |
| 106 |
CWinSystemWin10::ResizeWindow(newWidth, newHeight, newLeft, newTop); |
| 107 |
CRenderSystemDX::OnResize(); |
| 108 |
|
| 109 |
return true; |
| 110 |
} |
| 111 |
|
| 112 |
void CWinSystemWin10DX::OnMove(int x, int y) |
| 113 |
{ |
| 114 |
m_deviceResources->SetWindowPos(m_coreWindow.Bounds()); |
| 115 |
} |
| 116 |
|
| 117 |
bool CWinSystemWin10DX::DPIChanged(WORD dpi, RECT windowRect) const |
| 118 |
{ |
| 119 |
m_deviceResources->SetDpi(dpi); |
| 120 |
if (!IsAlteringWindow()) |
| 121 |
return CWinSystemWin10::DPIChanged(dpi, windowRect); |
| 122 |
|
| 123 |
return true; |
| 124 |
} |
| 125 |
|
| 126 |
void CWinSystemWin10DX::ReleaseBackBuffer() |
| 127 |
{ |
| 128 |
m_deviceResources->ReleaseBackBuffer(); |
| 129 |
} |
| 130 |
|
| 131 |
void CWinSystemWin10DX::CreateBackBuffer() |
| 132 |
{ |
| 133 |
m_deviceResources->CreateBackBuffer(); |
| 134 |
} |
| 135 |
|
| 136 |
void CWinSystemWin10DX::ResizeDeviceBuffers() |
| 137 |
{ |
| 138 |
m_deviceResources->ResizeBuffers(); |
| 139 |
} |
| 140 |
|
| 141 |
bool CWinSystemWin10DX::IsStereoEnabled() |
| 142 |
{ |
| 143 |
return m_deviceResources->IsStereoEnabled(); |
| 144 |
} |
| 145 |
|
| 146 |
void CWinSystemWin10DX::OnResize(int width, int height) |
| 147 |
{ |
| 148 |
if (!m_deviceResources) |
| 149 |
return; |
| 150 |
|
| 151 |
if (!m_IsAlteringWindow) |
| 152 |
ReleaseBackBuffer(); |
| 153 |
|
| 154 |
m_deviceResources->SetLogicalSize(width, height); |
| 155 |
|
| 156 |
if (!m_IsAlteringWindow) |
| 157 |
CreateBackBuffer(); |
| 158 |
} |
| 159 |
|
| 160 |
bool CWinSystemWin10DX::SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays) |
| 161 |
{ |
| 162 |
bool const result = CWinSystemWin10::SetFullScreen(fullScreen, res, blankOtherDisplays); |
| 163 |
CRenderSystemDX::OnResize(); |
| 164 |
return result; |
| 165 |
} |
| 166 |
|
| 167 |
void CWinSystemWin10DX::UninitHooks() |
| 168 |
{ |
| 169 |
} |
| 170 |
|
| 171 |
void CWinSystemWin10DX::InitHooks(IDXGIOutput* pOutput) |
| 172 |
{ |
| 173 |
} |
| 174 |
|
| 175 |
bool CWinSystemWin10DX::IsHDRDisplay() |
| 176 |
{ |
| 177 |
if (m_uiThreadId == GetCurrentThreadId()) |
| 178 |
{ |
| 179 |
const HDR_STATUS hdrStatus = CWIN32Util::GetWindowsHDRStatus(); |
| 180 |
m_cachedHdrStatus = hdrStatus; |
| 181 |
return (hdrStatus != HDR_STATUS::HDR_UNSUPPORTED); |
| 182 |
} |
| 183 |
|
| 184 |
return (m_cachedHdrStatus != HDR_STATUS::HDR_UNSUPPORTED); |
| 185 |
} |
| 186 |
|
| 187 |
HDR_STATUS CWinSystemWin10DX::GetOSHDRStatus() |
| 188 |
{ |
| 189 |
return CWIN32Util::GetWindowsHDRStatus(); |
| 190 |
} |
| 191 |
|
| 192 |
HDR_STATUS CWinSystemWin10DX::ToggleHDR() |
| 193 |
{ |
| 194 |
return m_deviceResources->ToggleHDR(); |
| 195 |
} |
| 196 |
|
| 197 |
bool CWinSystemWin10DX::IsHDROutput() const |
| 198 |
{ |
| 199 |
return m_deviceResources->IsHDROutput(); |
| 200 |
} |
| 201 |
|
| 202 |
bool CWinSystemWin10DX::IsTransferPQ() const |
| 203 |
{ |
| 204 |
return m_deviceResources->IsTransferPQ(); |
| 205 |
} |
| 206 |
|
| 207 |
void CWinSystemWin10DX::SetHdrMetaData(DXGI_HDR_METADATA_HDR10& hdr10) const |
| 208 |
{ |
| 209 |
m_deviceResources->SetHdrMetaData(hdr10); |
| 210 |
} |
| 211 |
|
| 212 |
void CWinSystemWin10DX::SetHdrColorSpace(const DXGI_COLOR_SPACE_TYPE colorSpace) const |
| 213 |
{ |
| 214 |
m_deviceResources->SetHdrColorSpace(colorSpace); |
| 215 |
} |
| 216 |
|
| 217 |
DEBUG_INFO_RENDER CWinSystemWin10DX::GetDebugInfo() |
| 218 |
{ |
| 219 |
return m_deviceResources->GetDebugInfo(); |
| 220 |
} |