mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-20 19:54:19 +01:00
[dxgi] Add functions to share per-monitor data between DXGI objects
This commit is contained in:
parent
57e814717e
commit
e30bb498b6
47
src/dxgi/dxgi_monitor.cpp
Normal file
47
src/dxgi/dxgi_monitor.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include "dxgi_monitor.h"
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
std::mutex g_monitorMutex;
|
||||
std::unordered_map<HMONITOR, DXGI_VK_MONITOR_DATA> g_monitorData;
|
||||
|
||||
|
||||
HRESULT InitMonitorData(
|
||||
HMONITOR hMonitor,
|
||||
const DXGI_VK_MONITOR_DATA* pData) {
|
||||
if (!hMonitor || !pData)
|
||||
return E_INVALIDARG;
|
||||
|
||||
std::lock_guard<std::mutex> lock(g_monitorMutex);
|
||||
auto result = g_monitorData.insert({ hMonitor, *pData });
|
||||
|
||||
return result.second ? S_OK : E_INVALIDARG;
|
||||
}
|
||||
|
||||
|
||||
HRESULT AcquireMonitorData(
|
||||
HMONITOR hMonitor,
|
||||
DXGI_VK_MONITOR_DATA** ppData) {
|
||||
InitReturnPtr(ppData);
|
||||
|
||||
if (!hMonitor || !ppData)
|
||||
return E_INVALIDARG;
|
||||
|
||||
g_monitorMutex.lock();
|
||||
|
||||
auto entry = g_monitorData.find(hMonitor);
|
||||
if (entry == g_monitorData.end()) {
|
||||
g_monitorMutex.unlock();
|
||||
return DXGI_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
*ppData = &entry->second;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
void ReleaseMonitorData() {
|
||||
g_monitorMutex.unlock();
|
||||
}
|
||||
|
||||
}
|
54
src/dxgi/dxgi_monitor.h
Normal file
54
src/dxgi/dxgi_monitor.h
Normal file
@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "dxgi_include.h"
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
class DxgiSwapChain;
|
||||
|
||||
/**
|
||||
* \brief Per-monitor data
|
||||
*/
|
||||
struct DXGI_VK_MONITOR_DATA {
|
||||
DxgiSwapChain* pSwapChain;
|
||||
DXGI_FRAME_STATISTICS FrameStats;
|
||||
DXGI_GAMMA_CONTROL GammaCurve;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Initializes monitor data
|
||||
*
|
||||
* Fails if data for the given monitor already exists.
|
||||
* \param [in] hMonitor The monitor handle
|
||||
* \param [in] pData Initial data
|
||||
*/
|
||||
HRESULT InitMonitorData(
|
||||
HMONITOR hMonitor,
|
||||
const DXGI_VK_MONITOR_DATA* pData);
|
||||
|
||||
/**
|
||||
* \brief Retrieves and locks monitor data
|
||||
*
|
||||
* Fails if no data for the given monitor exists.
|
||||
* \param [in] hMonitor The monitor handle
|
||||
* \param [out] Pointer to monitor data
|
||||
* \returns S_OK on success
|
||||
*/
|
||||
HRESULT AcquireMonitorData(
|
||||
HMONITOR hMonitor,
|
||||
DXGI_VK_MONITOR_DATA** ppData);
|
||||
|
||||
/**
|
||||
* \brief Unlocks monitor data
|
||||
*
|
||||
* Must be called after each successful
|
||||
* call to \ref AcquireMonitorData.
|
||||
* \param [in] hMonitor The monitor handle
|
||||
*/
|
||||
void ReleaseMonitorData();
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ dxgi_src = [
|
||||
'dxgi_factory.cpp',
|
||||
'dxgi_format.cpp',
|
||||
'dxgi_main.cpp',
|
||||
'dxgi_monitor.cpp',
|
||||
'dxgi_options.cpp',
|
||||
'dxgi_output.cpp',
|
||||
'dxgi_swapchain.cpp',
|
||||
|
Loading…
x
Reference in New Issue
Block a user