-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd2d.hpp
186 lines (146 loc) · 4.94 KB
/
d2d.hpp
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//
inline DXGI_FORMAT uu = DXGI_FORMAT_B8G8R8A8_UNORM;
//DXGI_FORMAT uu = DXGI_FORMAT_R16G16B16A16_FLOAT;
inline D2D1_ALPHA_MODE alphamode = D2D1_ALPHA_MODE_PREMULTIPLIED;
inline int MainHDR = 0;
inline float MaxHDRLuminance = 0;
struct D2D;
class TEXTALIGNPUSH
{
IDWriteTextFormat* Text = 0;
DWRITE_TEXT_ALIGNMENT c1;
DWRITE_PARAGRAPH_ALIGNMENT c2;
public:
TEXTALIGNPUSH(IDWriteTextFormat* t, DWRITE_TEXT_ALIGNMENT nc1 = DWRITE_TEXT_ALIGNMENT_CENTER, DWRITE_PARAGRAPH_ALIGNMENT nc2 = DWRITE_PARAGRAPH_ALIGNMENT_CENTER)
{
if (!t)
return;
Text = t;
c1 = Text->GetTextAlignment();
c2 = Text->GetParagraphAlignment();
s(nc1, nc2);
}
void s(DWRITE_TEXT_ALIGNMENT nc1, DWRITE_PARAGRAPH_ALIGNMENT nc2)
{
if (Text)
{
Text->SetTextAlignment(nc1);
Text->SetParagraphAlignment(nc2);
}
}
~TEXTALIGNPUSH()
{
if (!Text)
return;
Text->SetTextAlignment(c1);
Text->SetParagraphAlignment(c2);
}
};
struct D2D
{
void FailDraw()
{
OutputDebugString(L"FAIL DRAW\r\n");
}
void dd(bool jpg);
operator bool()
{
if (rt())
return true;
return false;
}
bool OnceSwapChain = 0; // For WUI
SIZEL SizeCreated = { 0 };
// CComPtr<IDWriteFactory> WriteFactory;
// Windows 7
CComPtr<ID2D1HwndRenderTarget> d;
CComPtr<ID2D1Factory> fa;
CComPtr<ID2D1Factory1> fa1;
CComPtr<ID2D1Factory5> fa5;
// Windows 8
CComPtr<ID3D11Device> device;
// CComPtr<ID3D11Device1> device1;
CComPtr<ID3D11DeviceContext> context;
// CComPtr<ID3D11DeviceContext1> context1;
CComPtr<IDXGIDevice1> dxgiDevice;
CComPtr<ID2D1Device> m_d2dDevice;
CComPtr<ID2D1Device5> m_d2dDevice5;
CComPtr<ID2D1DeviceContext> m_d2dContext;
CComPtr<ID2D1DeviceContext5> m_d2dContext5;
CComPtr<ID2D1DeviceContext6> m_d2dContext6;
CComPtr<ID2D1DeviceContext7> m_d2dContext7;
CComPtr<IDXGIAdapter> dxgiAdapter;
CComPtr<IDXGIFactory2> dxgiFactory;
CComPtr<IDXGISwapChain1> m_swapChain1;
int SwapChainForWUI3 = 0;
std::vector<RECT> SwapChain1Rects;
CComPtr<ID3D11Texture2D> backBuffer;
CComPtr<IDXGISurface> dxgiBackBuffer;
CComPtr<ID2D1Bitmap1> m_d2dTargetBitmap;
CComPtr<ID2D1Bitmap1> m_TempBitmapForCopying;
CComPtr<IWICBitmap> CopyToBitmap(CComPtr<IWICBitmap> UseThis);
CComPtr<IWICImagingFactory> wicfac = 0;
CComPtr<IWICBitmap> bmp = 0;
CComPtr<ID2D1RenderTarget> bitmaprender;
DXGI_OUTPUT_DESC1 desc1 = {}; // hdr
// Brushes for mixer
CComPtr<ID2D1SolidColorBrush> SeparatorBrush;
CComPtr<ID2D1SolidColorBrush> SnapBrush2;
CComPtr<ID2D1SolidColorBrush> WhiteBrush;
CComPtr<ID2D1SolidColorBrush> YellowBrush;
CComPtr<ID2D1SolidColorBrush> RedBrush;
CComPtr<ID2D1SolidColorBrush> CyanBrush;
CComPtr<ID2D1SolidColorBrush> GreenBrush;
CComPtr<ID2D1SolidColorBrush> BlackBrush;
CComPtr<ID2D1SolidColorBrush> BGBrush;
CComPtr<IDWriteTextFormat> Text;
CComPtr<IDWriteTextFormat> Text2;
CComPtr<IDWriteTextFormat> Text3;
CComPtr<ID2D1SolidColorBrush> GetD2SolidBrush(ID2D1RenderTarget* p, D2D1_COLOR_F cc)
{
CComPtr<ID2D1SolidColorBrush> b = 0;
p->CreateSolidColorBrush(cc, &b);
return b;
}
void Off(bool KeepDevice = false);
HRESULT OffOnSize(int wi, int he, bool Quick = 0, bool KeepDevice = false);
// Multithread-manager stuff
UINT mmanager_reset = 0;
HRESULT CreateMultithreadManager();
CComPtr<ID2D1RenderTarget> rt()
{
CComPtr<ID2D1RenderTarget> rr;
if (m_d2dContext5)
rr = m_d2dContext5;
else
if (m_d2dContext)
rr = m_d2dContext;
else
rr = d;
return rr;
}
GUID PixelFormatForBitmap(int ctx = 0);
WICBitmapInterpolationMode ScalingModeForBitmap(int ctx = 0);
int HDRSupported = 0;
int HDRMode = 0;
int WithoutEffectsRegistration = 0;
DXGI_FORMAT pform = DXGI_FORMAT_B8G8R8A8_UNORM; // Guess that DXGI_FORMAT_R16G16B16A16_FLOAT also supported, continue trying here.
// Direct3D stuff if needed
CComPtr<ID3D11RenderTargetView> pRenderTargetView;
CComPtr<ID3D11DepthStencilView> pDepthStencilView;
std::vector<CComPtr<IUnknown>> ObjectsForDrawingSelection; // See render2.cpp
bool CreateRenderingBitmap(RECT rc);
bool CreateIf(HWND hh, RECT rc, bool w7 = false, int SwapChainForWUI3 = 0);
bool CreateWin7(HWND hh, RECT rc);
HRESULT Resize(int wi, int he);
HRESULT Resize2(int wi, int he);
bool CreateD2(IDXGIAdapter* wad, HWND hh, D3D_DRIVER_TYPE de = D3D_DRIVER_TYPE_HARDWARE, int wi = 0, int he = 0, bool IncreaseTiles = 0, int forwhat = 0, int hdr_if = 0, int SwapChainForWUI3 = 0);
bool CreateD2X(IDXGIAdapter* wad, HWND hh, int wi, int he, bool IncreaseTiles, int forwhat, int hdr_if = 0, int SwapChainForWUI3 = 0);
int OnResize(HWND hh, bool RR, int wi = 0, int he = 0);
std::shared_ptr<IDWriteFactory> WriteFa;
void CreateWriteFa();
std::tuple<float, float, DWRITE_OVERHANG_METRICS> MeasureString(IDWriteFactory* pWriteFactory, IDWriteTextFormat* ffo, const wchar_t* txt, int l = -1);
HWND m_hwnd = 0;
};
inline std::shared_ptr<D2D> d2d;
inline int iVisiblePage = -1;