CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/UWP/Common/DeviceResources.h
Views: 1401
1
#pragma once
2
3
#include <vector>
4
#include <string>
5
6
namespace DX
7
{
8
// Provides an interface for an application that owns DeviceResources to be notified of the device being lost or created.
9
interface IDeviceNotify
10
{
11
virtual void OnDeviceLost() = 0;
12
virtual void OnDeviceRestored() = 0;
13
};
14
15
// Controls all the DirectX device resources.
16
class DeviceResources
17
{
18
public:
19
DeviceResources();
20
void CreateWindowSizeDependentResources();
21
void SetWindow(Windows::UI::Core::CoreWindow^ window);
22
void SetLogicalSize(Windows::Foundation::Size logicalSize);
23
void SetCurrentOrientation(Windows::Graphics::Display::DisplayOrientations currentOrientation);
24
void SetDpi(float dpi);
25
void ValidateDevice();
26
void HandleDeviceLost();
27
void RegisterDeviceNotify(IDeviceNotify* deviceNotify);
28
void Trim();
29
void Present();
30
31
// The size of the render target, in pixels.
32
Windows::Foundation::Size GetOutputSize() const { return m_outputSize; }
33
34
// The size of the render target, in dips.
35
Windows::Foundation::Size GetLogicalSize() const { return m_logicalSize; }
36
float GetDpi() const { return m_effectiveDpi; }
37
float GetActualDpi() const { return m_dpi; }
38
39
// D3D Accessors.
40
ID3D11Device3* GetD3DDevice() const { return m_d3dDevice.Get(); }
41
ID3D11DeviceContext3* GetD3DDeviceContext() const { return m_d3dContext.Get(); }
42
IDXGISwapChain3* GetSwapChain() const { return m_swapChain.Get(); }
43
D3D_FEATURE_LEVEL GetDeviceFeatureLevel() const { return m_d3dFeatureLevel; }
44
ID3D11RenderTargetView1* GetBackBufferRenderTargetView() const { return m_d3dRenderTargetView.Get(); }
45
D3D11_VIEWPORT GetScreenViewport() const { return m_screenViewport; }
46
DirectX::XMFLOAT4X4 GetOrientationTransform3D() const { return m_orientationTransform3D; }
47
48
// D2D Accessors.
49
ID2D1Factory3* GetD2DFactory() const { return m_d2dFactory.Get(); }
50
ID2D1Device2* GetD2DDevice() const { return m_d2dDevice.Get(); }
51
ID2D1DeviceContext2* GetD2DDeviceContext() const { return m_d2dContext.Get(); }
52
ID2D1Bitmap1* GetD2DTargetBitmap() const { return m_d2dTargetBitmap.Get(); }
53
IDWriteFactory3* GetDWriteFactory() const { return m_dwriteFactory.Get(); }
54
IWICImagingFactory2* GetWicImagingFactory() const { return m_wicFactory.Get(); }
55
D2D1::Matrix3x2F GetOrientationTransform2D() const { return m_orientationTransform2D; }
56
57
DXGI_MODE_ROTATION ComputeDisplayRotation();
58
59
std::vector <std::string> GetAdapters() const { return m_vAdapters; };
60
61
private:
62
void CreateDeviceIndependentResources();
63
void CreateDeviceResources(IDXGIAdapter* vAdapter = nullptr);
64
void UpdateRenderTargetSize();
65
bool CreateAdaptersList(Microsoft::WRL::ComPtr<ID3D11Device> device);
66
67
// Direct3D objects.
68
Microsoft::WRL::ComPtr<ID3D11Device3> m_d3dDevice;
69
Microsoft::WRL::ComPtr<ID3D11DeviceContext3> m_d3dContext;
70
Microsoft::WRL::ComPtr<IDXGISwapChain3> m_swapChain;
71
Microsoft::WRL::ComPtr<IDXGIDevice3> m_dxgiDevice;
72
Microsoft::WRL::ComPtr<IDXGIFactory4> m_dxgiFactory;
73
Microsoft::WRL::ComPtr<IDXGIAdapter> m_dxgiAdapter;
74
75
// Direct3D adapters
76
std::vector <std::string> m_vAdapters;
77
78
// Direct3D rendering objects. Required for 3D.
79
Microsoft::WRL::ComPtr<ID3D11RenderTargetView1> m_d3dRenderTargetView;
80
D3D11_VIEWPORT m_screenViewport;
81
82
// Direct2D drawing components.
83
Microsoft::WRL::ComPtr<ID2D1Factory3> m_d2dFactory;
84
Microsoft::WRL::ComPtr<ID2D1Device2> m_d2dDevice;
85
Microsoft::WRL::ComPtr<ID2D1DeviceContext2> m_d2dContext;
86
Microsoft::WRL::ComPtr<ID2D1Bitmap1> m_d2dTargetBitmap;
87
88
// DirectWrite drawing components.
89
Microsoft::WRL::ComPtr<IDWriteFactory3> m_dwriteFactory;
90
Microsoft::WRL::ComPtr<IWICImagingFactory2> m_wicFactory;
91
92
// Cached device properties.
93
D3D_FEATURE_LEVEL m_d3dFeatureLevel;
94
Windows::Foundation::Size m_d3dRenderTargetSize;
95
Windows::Foundation::Size m_outputSize;
96
Windows::Foundation::Size m_logicalSize;
97
Windows::Graphics::Display::DisplayOrientations m_nativeOrientation;
98
Windows::Graphics::Display::DisplayOrientations m_currentOrientation;
99
float m_dpi;
100
101
// This is the DPI that will be reported back to the app. It takes into account whether the app supports high resolution screens or not.
102
float m_effectiveDpi;
103
104
// Transforms used for display orientation.
105
D2D1::Matrix3x2F m_orientationTransform2D;
106
DirectX::XMFLOAT4X4 m_orientationTransform3D;
107
108
// The IDeviceNotify can be held directly as it owns the DeviceResources.
109
IDeviceNotify* m_deviceNotify;
110
};
111
}
112
113