1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-19 05:52:11 +01:00

[util] Factor out common monitor-related functions

This commit is contained in:
Philip Rebohle 2020-03-04 10:49:10 +01:00 committed by Joshie
parent 8c68cf1551
commit 66503aeaa0
9 changed files with 114 additions and 121 deletions

View File

@ -36,8 +36,9 @@
#include "../util/util_flags.h"
#include "../util/util_likely.h"
#include "../util/util_math.h"
#include "../util/util_string.h"
#include "../util/util_monitor.h"
#include "../util/util_misc.h"
#include "../util/util_string.h"
// Missed definitions in Wine/MinGW.

View File

@ -60,11 +60,6 @@ namespace dxvk {
}
HMONITOR GetDefaultMonitor() {
return ::MonitorFromPoint({ 0, 0 }, MONITOR_DEFAULTTOPRIMARY);
}
HRESULT SetMonitorDisplayMode(
HMONITOR hMonitor,
const D3DDISPLAYMODEEX* pMode) {
@ -106,56 +101,4 @@ namespace dxvk {
return status == DISP_CHANGE_SUCCESSFUL ? D3D_OK : D3DERR_NOTAVAILABLE;
}
void GetWindowClientSize(
HWND hWnd,
UINT* pWidth,
UINT* pHeight) {
RECT rect = { };
::GetClientRect(hWnd, &rect);
if (pWidth)
*pWidth = rect.right - rect.left;
if (pHeight)
*pHeight = rect.bottom - rect.top;
}
void GetMonitorClientSize(
HMONITOR hMonitor,
UINT* pWidth,
UINT* pHeight) {
::MONITORINFOEXW monInfo;
monInfo.cbSize = sizeof(monInfo);
if (!::GetMonitorInfoW(hMonitor, reinterpret_cast<MONITORINFO*>(&monInfo))) {
Logger::err("D3D9: Failed to query monitor info");
return;
}
auto rect = monInfo.rcMonitor;
if (pWidth)
*pWidth = rect.right - rect.left;
if (pHeight)
*pHeight = rect.bottom - rect.top;
}
void GetMonitorRect(
HMONITOR hMonitor,
RECT* pRect) {
::MONITORINFOEXW monInfo;
monInfo.cbSize = sizeof(monInfo);
if (!::GetMonitorInfoW(hMonitor, reinterpret_cast<MONITORINFO*>(&monInfo))) {
Logger::err("D3D9: Failed to query monitor info");
return;
}
*pRect = monInfo.rcMonitor;
}
}

View File

@ -35,8 +35,6 @@ namespace dxvk {
D3D9Format BackBufferFormat,
BOOL Windowed);
HMONITOR GetDefaultMonitor();
/**
* \brief Sets monitor display mode
*
@ -47,39 +45,5 @@ namespace dxvk {
HRESULT SetMonitorDisplayMode(
HMONITOR hMonitor,
const D3DDISPLAYMODEEX* pMode);
/**
* \brief Queries window client size
*
* \param [in] hWnd Window to query
* \param [out] pWidth Client width
* \param [out] pHeight Client height
*/
void GetWindowClientSize(
HWND hWnd,
UINT* pWidth,
UINT* pHeight);
/**
* \brief Queries monitor size
*
* \param [in] hMonitor Monitor to query
* \param [out] pWidth Client width
* \param [out] pHeight Client height
*/
void GetMonitorClientSize(
HMONITOR hMonitor,
UINT* pWidth,
UINT* pHeight);
/**
* \brief Queries monitor rect
*
* \param [in] hMonitor Monitor to query
* \param [out] pRect The rect to return
*/
void GetMonitorRect(
HMONITOR hMonitor,
RECT* pRect);
}

View File

@ -25,6 +25,7 @@
#include "../util/util_flags.h"
#include "../util/util_likely.h"
#include "../util/util_math.h"
#include "../util/util_monitor.h"
#include "../util/util_string.h"
#include <dxgi1_5.h>

View File

@ -152,19 +152,4 @@ namespace dxvk {
return status == DISP_CHANGE_SUCCESSFUL ? S_OK : DXGI_ERROR_NOT_CURRENTLY_AVAILABLE;;
}
void GetWindowClientSize(
HWND hWnd,
UINT* pWidth,
UINT* pHeight) {
RECT rect = { };
::GetClientRect(hWnd, &rect);
if (pWidth)
*pWidth = rect.right - rect.left;
if (pHeight)
*pHeight = rect.bottom - rect.top;
}
}

View File

@ -78,17 +78,5 @@ namespace dxvk {
HRESULT SetMonitorDisplayMode(
HMONITOR hMonitor,
const DXGI_MODE_DESC* pMode);
/**
* \brief Queries window client size
*
* \param [in] hWnd Window to query
* \param [out] pWidth Client width
* \param [out] pHeight Client height
*/
void GetWindowClientSize(
HWND hWnd,
UINT* pWidth,
UINT* pHeight);
}

View File

@ -4,6 +4,7 @@ util_src = files([
'util_gdi.cpp',
'util_luid.cpp',
'util_matrix.cpp',
'util_monitor.cpp',
'com/com_guid.cpp',
'com/com_private_data.cpp',

63
src/util/util_monitor.cpp Normal file
View File

@ -0,0 +1,63 @@
#include "util_monitor.h"
#include "./log/log.h"
namespace dxvk {
HMONITOR GetDefaultMonitor() {
return ::MonitorFromPoint({ 0, 0 }, MONITOR_DEFAULTTOPRIMARY);
}
void GetWindowClientSize(
HWND hWnd,
UINT* pWidth,
UINT* pHeight) {
RECT rect = { };
::GetClientRect(hWnd, &rect);
if (pWidth)
*pWidth = rect.right - rect.left;
if (pHeight)
*pHeight = rect.bottom - rect.top;
}
void GetMonitorClientSize(
HMONITOR hMonitor,
UINT* pWidth,
UINT* pHeight) {
::MONITORINFOEXW monInfo;
monInfo.cbSize = sizeof(monInfo);
if (!::GetMonitorInfoW(hMonitor, reinterpret_cast<MONITORINFO*>(&monInfo))) {
Logger::err("Failed to query monitor info");
return;
}
auto rect = monInfo.rcMonitor;
if (pWidth)
*pWidth = rect.right - rect.left;
if (pHeight)
*pHeight = rect.bottom - rect.top;
}
void GetMonitorRect(
HMONITOR hMonitor,
RECT* pRect) {
::MONITORINFOEXW monInfo;
monInfo.cbSize = sizeof(monInfo);
if (!::GetMonitorInfoW(hMonitor, reinterpret_cast<MONITORINFO*>(&monInfo))) {
Logger::err("Failed to query monitor info");
return;
}
*pRect = monInfo.rcMonitor;
}
}

47
src/util/util_monitor.h Normal file
View File

@ -0,0 +1,47 @@
#pragma once
#include "./com/com_include.h"
namespace dxvk {
/**
* \brief Retrieves primary monitor
* \returns The primary monitor
*/
HMONITOR GetDefaultMonitor();
/**
* \brief Queries window client size
*
* \param [in] hWnd Window to query
* \param [out] pWidth Client width
* \param [out] pHeight Client height
*/
void GetWindowClientSize(
HWND hWnd,
UINT* pWidth,
UINT* pHeight);
/**
* \brief Queries monitor size
*
* \param [in] hMonitor Monitor to query
* \param [out] pWidth Client width
* \param [out] pHeight Client height
*/
void GetMonitorClientSize(
HMONITOR hMonitor,
UINT* pWidth,
UINT* pHeight);
/**
* \brief Queries monitor rect
*
* \param [in] hMonitor Monitor to query
* \param [out] pRect The rect to return
*/
void GetMonitorRect(
HMONITOR hMonitor,
RECT* pRect);
}