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