mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-19 05:52:11 +01:00
[dxgi] Use new common monitor functions
This commit is contained in:
parent
4e16d65bb8
commit
a623e8e7d6
@ -89,67 +89,4 @@ namespace dxvk {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HRESULT GetMonitorDisplayMode(
|
||||
HMONITOR hMonitor,
|
||||
DWORD ModeNum,
|
||||
DXGI_MODE_DESC* pMode) {
|
||||
::MONITORINFOEXW monInfo;
|
||||
monInfo.cbSize = sizeof(monInfo);
|
||||
|
||||
if (!::GetMonitorInfoW(hMonitor, reinterpret_cast<MONITORINFO*>(&monInfo))) {
|
||||
Logger::err("DXGI: Failed to query monitor info");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
DEVMODEW devMode = { };
|
||||
devMode.dmSize = sizeof(devMode);
|
||||
|
||||
if (!::EnumDisplaySettingsW(monInfo.szDevice, ModeNum, &devMode))
|
||||
return DXGI_ERROR_NOT_FOUND;
|
||||
|
||||
pMode->Width = devMode.dmPelsWidth;
|
||||
pMode->Height = devMode.dmPelsHeight;
|
||||
pMode->RefreshRate = { devMode.dmDisplayFrequency, 1 };
|
||||
pMode->Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; // FIXME
|
||||
pMode->ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE;
|
||||
pMode->Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
HRESULT SetMonitorDisplayMode(
|
||||
HMONITOR hMonitor,
|
||||
const DXGI_MODE_DESC* pMode) {
|
||||
::MONITORINFOEXW monInfo;
|
||||
monInfo.cbSize = sizeof(monInfo);
|
||||
|
||||
if (!::GetMonitorInfoW(hMonitor, reinterpret_cast<MONITORINFO*>(&monInfo))) {
|
||||
Logger::err("DXGI: Failed to query monitor info");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
DEVMODEW devMode = { };
|
||||
devMode.dmSize = sizeof(devMode);
|
||||
devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
|
||||
devMode.dmPelsWidth = pMode->Width;
|
||||
devMode.dmPelsHeight = pMode->Height;
|
||||
devMode.dmBitsPerPel = GetMonitorFormatBpp(pMode->Format);
|
||||
|
||||
if (pMode->RefreshRate.Numerator != 0) {
|
||||
devMode.dmFields |= DM_DISPLAYFREQUENCY;
|
||||
devMode.dmDisplayFrequency = pMode->RefreshRate.Numerator
|
||||
/ pMode->RefreshRate.Denominator;
|
||||
}
|
||||
|
||||
Logger::info(str::format("DXGI: Setting display mode: ",
|
||||
devMode.dmPelsWidth, "x", devMode.dmPelsHeight, "@",
|
||||
devMode.dmDisplayFrequency));
|
||||
|
||||
LONG status = ::ChangeDisplaySettingsExW(
|
||||
monInfo.szDevice, &devMode, nullptr, CDS_FULLSCREEN, nullptr);
|
||||
|
||||
return status == DISP_CHANGE_SUCCESSFUL ? S_OK : DXGI_ERROR_NOT_CURRENTLY_AVAILABLE;;
|
||||
}
|
||||
|
||||
}
|
@ -55,28 +55,4 @@ namespace dxvk {
|
||||
uint32_t GetMonitorFormatBpp(
|
||||
DXGI_FORMAT Format);
|
||||
|
||||
/**
|
||||
* \brief Retrieves monitor display mode
|
||||
*
|
||||
* \param [in] hMonitor Monitor handle
|
||||
* \param [in] ModeNum Mode number
|
||||
* \param [out] Display mode properties
|
||||
* \returns S_OK on success
|
||||
*/
|
||||
HRESULT GetMonitorDisplayMode(
|
||||
HMONITOR hMonitor,
|
||||
DWORD ModeNum,
|
||||
DXGI_MODE_DESC* pMode);
|
||||
|
||||
/**
|
||||
* \brief Sets monitor display mode
|
||||
*
|
||||
* \param [in] hMonitor Monitor handle
|
||||
* \param [in] pMode Display mode properties
|
||||
* \returns S_OK on success
|
||||
*/
|
||||
HRESULT SetMonitorDisplayMode(
|
||||
HMONITOR hMonitor,
|
||||
const DXGI_MODE_DESC* pMode);
|
||||
|
||||
}
|
@ -121,8 +121,19 @@ namespace dxvk {
|
||||
if ((pModeToMatch->Width == 0) ^ (pModeToMatch->Height == 0))
|
||||
return DXGI_ERROR_INVALID_CALL;
|
||||
|
||||
DEVMODEW devMode;
|
||||
devMode.dmSize = sizeof(devMode);
|
||||
|
||||
if (!GetMonitorDisplayMode(m_monitor, ENUM_CURRENT_SETTINGS, &devMode))
|
||||
return DXGI_ERROR_NOT_CURRENTLY_AVAILABLE;
|
||||
|
||||
DXGI_MODE_DESC activeMode = { };
|
||||
GetMonitorDisplayMode(m_monitor, ENUM_CURRENT_SETTINGS, &activeMode);
|
||||
activeMode.Width = devMode.dmPelsWidth;
|
||||
activeMode.Height = devMode.dmPelsHeight;
|
||||
activeMode.RefreshRate = { devMode.dmDisplayFrequency, 1 };
|
||||
activeMode.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; // FIXME
|
||||
activeMode.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE;
|
||||
activeMode.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
|
||||
|
||||
DXGI_MODE_DESC1 defaultMode;
|
||||
defaultMode.Width = 0;
|
||||
@ -252,15 +263,6 @@ namespace dxvk {
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// Query monitor info to get the device name
|
||||
::MONITORINFOEXW monInfo;
|
||||
monInfo.cbSize = sizeof(monInfo);
|
||||
|
||||
if (!::GetMonitorInfoW(m_monitor, reinterpret_cast<MONITORINFO*>(&monInfo))) {
|
||||
Logger::err("DXGI: Failed to query monitor info");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
// Walk over all modes that the display supports and
|
||||
// return those that match the requested format etc.
|
||||
DEVMODEW devMode = { };
|
||||
@ -271,7 +273,7 @@ namespace dxvk {
|
||||
|
||||
std::vector<DXGI_MODE_DESC1> modeList;
|
||||
|
||||
while (::EnumDisplaySettingsW(monInfo.szDevice, srcModeId++, &devMode)) {
|
||||
while (GetMonitorDisplayMode(m_monitor, srcModeId++, &devMode)) {
|
||||
// Skip interlaced modes altogether
|
||||
if (devMode.dmDisplayFlags & DM_INTERLACED)
|
||||
continue;
|
||||
|
@ -690,7 +690,22 @@ namespace dxvk {
|
||||
return hr;
|
||||
}
|
||||
|
||||
return SetMonitorDisplayMode(outputDesc.Monitor, &selectedMode);
|
||||
DEVMODEW devMode = { };
|
||||
devMode.dmSize = sizeof(devMode);
|
||||
devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
|
||||
devMode.dmPelsWidth = selectedMode.Width;
|
||||
devMode.dmPelsHeight = selectedMode.Height;
|
||||
devMode.dmBitsPerPel = GetMonitorFormatBpp(selectedMode.Format);
|
||||
|
||||
if (selectedMode.RefreshRate.Numerator != 0) {
|
||||
devMode.dmFields |= DM_DISPLAYFREQUENCY;
|
||||
devMode.dmDisplayFrequency = selectedMode.RefreshRate.Numerator
|
||||
/ selectedMode.RefreshRate.Denominator;
|
||||
}
|
||||
|
||||
return SetMonitorDisplayMode(outputDesc.Monitor, &devMode)
|
||||
? S_OK
|
||||
: DXGI_ERROR_NOT_CURRENTLY_AVAILABLE;
|
||||
}
|
||||
|
||||
|
||||
@ -698,16 +713,9 @@ namespace dxvk {
|
||||
if (!hMonitor)
|
||||
return DXGI_ERROR_INVALID_CALL;
|
||||
|
||||
// Restore registry settings
|
||||
DXGI_MODE_DESC mode;
|
||||
|
||||
HRESULT hr = GetMonitorDisplayMode(
|
||||
hMonitor, ENUM_REGISTRY_SETTINGS, &mode);
|
||||
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
return SetMonitorDisplayMode(hMonitor, &mode);
|
||||
return RestoreMonitorDisplayMode(hMonitor)
|
||||
? S_OK
|
||||
: DXGI_ERROR_NOT_CURRENTLY_AVAILABLE;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user