forked from ge9/IddSampleDriver
-
-
Notifications
You must be signed in to change notification settings - Fork 365
Expand file tree
/
Copy pathDriver.h
More file actions
142 lines (119 loc) · 4.12 KB
/
Driver.h
File metadata and controls
142 lines (119 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#pragma once
#define NOMINMAX
#include <windows.h>
#include <bugcodes.h>
#include <wudfwdm.h>
#include <wdf.h>
#include <IddCx.h>
#include <dxgi1_5.h>
#include <d3d11_2.h>
#include <avrt.h>
#include <wrl.h>
#include <memory>
#include <vector>
#include <map>
#include <mutex>
#include <string>
#include <sstream>
#include "Trace.h"
// Utility function declarations
std::vector<std::string> split(std::string& input, char delimiter);
std::string WStringToString(const std::wstring& wstr);
// Phase 5: Final Integration function declarations
NTSTATUS ValidateEdidIntegration();
NTSTATUS PerformanceMonitor();
NTSTATUS CreateFallbackConfiguration();
NTSTATUS ValidateAndSanitizeConfiguration();
NTSTATUS RunComprehensiveDiagnostics();
NTSTATUS InitializePhase5Integration();
namespace Microsoft
{
namespace WRL
{
namespace Wrappers
{
// Adds a wrapper for thread handles to the existing set of WRL handle wrapper classes
typedef HandleT<HandleTraits::HANDLENullTraits> Thread;
}
}
}
namespace Microsoft
{
namespace IndirectDisp
{
/// <summary>
/// Manages the creation and lifetime of a Direct3D render device.
/// </summary>
struct Direct3DDevice
{
Direct3DDevice(LUID AdapterLuid);
Direct3DDevice();
HRESULT Init();
LUID AdapterLuid;
Microsoft::WRL::ComPtr<IDXGIFactory5> DxgiFactory;
Microsoft::WRL::ComPtr<IDXGIAdapter1> Adapter;
Microsoft::WRL::ComPtr<ID3D11Device> Device;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> DeviceContext;
};
/// <summary>
/// Manages a thread that consumes buffers from an indirect display swap-chain object.
/// </summary>
class SwapChainProcessor
{
public:
SwapChainProcessor(IDDCX_SWAPCHAIN hSwapChain, std::shared_ptr<Direct3DDevice> Device, HANDLE NewFrameEvent);
~SwapChainProcessor();
private:
static DWORD CALLBACK RunThread(LPVOID Argument);
void Run();
void RunCore();
public:
IDDCX_SWAPCHAIN m_hSwapChain;
std::shared_ptr<Direct3DDevice> m_Device;
HANDLE m_hAvailableBufferEvent;
Microsoft::WRL::Wrappers::Thread m_hThread;
Microsoft::WRL::Wrappers::Event m_hTerminateEvent;
};
/// <summary>
/// Custom comparator for LUID to be used in std::map
/// </summary>
struct LuidComparator
{
bool operator()(const LUID& a, const LUID& b) const
{
if (a.HighPart != b.HighPart)
return a.HighPart < b.HighPart;
return a.LowPart < b.LowPart;
}
};
/// <summary>
/// Provides a sample implementation of an indirect display driver.
/// </summary>
class IndirectDeviceContext
{
public:
IndirectDeviceContext(_In_ WDFDEVICE WdfDevice);
virtual ~IndirectDeviceContext();
void InitAdapter();
void FinishInit();
void CreateMonitor(unsigned int index);
void AssignSwapChain(IDDCX_MONITOR Monitor, IDDCX_SWAPCHAIN SwapChain, LUID RenderAdapter, HANDLE NewFrameEvent);
void UnassignSwapChain(IDDCX_MONITOR Monitor);
protected:
WDFDEVICE m_WdfDevice;
IDDCX_ADAPTER m_Adapter;
IDDCX_MONITOR m_Monitor;
IDDCX_MONITOR m_Monitor2;
std::map<IDDCX_MONITOR, std::unique_ptr<SwapChainProcessor>> m_ProcessingThreads;
std::mutex m_ProcessingThreadsMutex;
public:
static const DISPLAYCONFIG_VIDEO_SIGNAL_INFO s_KnownMonitorModes[];
static std::vector<BYTE> s_KnownMonitorEdid;
private:
static std::map<LUID, std::shared_ptr<Direct3DDevice>, LuidComparator> s_DeviceCache;
static std::mutex s_DeviceCacheMutex;
static std::shared_ptr<Direct3DDevice> GetOrCreateDevice(LUID RenderAdapter);
static void CleanupExpiredDevices();
};
}
}