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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#![allow(non_camel_case_types, non_snake_case)]

use crate::co;
use crate::decl::*;
use crate::kernel::ffi_types::*;

/// [`DXGI_ADAPTER_DESC`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/ns-dxgi-dxgi_adapter_desc)
/// struct.
#[repr(C)]
pub struct DXGI_ADAPTER_DESC {
	Description: [u16; 128],
	pub VendorId: u32,
	pub DeviceId: u32,
	pub SubSysId: u32,
	pub Revision: u32,
	pub DedicatedVideoMemory: usize,
	pub DedicatedSystemMemory: usize,
	pub SharedSystemMemory: usize,
	pub AdapterLuid: LUID,
}

impl_default!(DXGI_ADAPTER_DESC);

impl DXGI_ADAPTER_DESC {
	pub_fn_string_arr_get_set!(Description, set_Description);
}

/// [`DXGI_ADAPTER_DESC1`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/ns-dxgi-dxgi_adapter_desc1)
/// struct.
#[repr(C)]
pub struct DXGI_ADAPTER_DESC1 {
	Description: [u16; 128],
	pub VendorId: u32,
	pub DeviceId: u32,
	pub SubSysId: u32,
	pub Revision: u32,
	pub DedicatedVideoMemory: usize,
	pub DedicatedSystemMemory: usize,
	pub SharedSystemMemory: usize,
	pub AdapterLuid: LUID,
	pub flags: co::DXGI_ADAPTER_FLAG,
}

impl_default!(DXGI_ADAPTER_DESC1);

impl DXGI_ADAPTER_DESC1 {
	pub_fn_string_arr_get_set!(Description, set_Description);
}

/// [`DXGI_FRAME_STATISTICS`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/ns-dxgi-dxgi_frame_statistics)
/// struct.
#[repr(C)]
#[derive(Default, PartialEq, Eq)]
pub struct DXGI_FRAME_STATISTICS {
	pub PresentCount: u32,
	pub PresentRefreshCount: u32,
	pub SyncRefreshCount: u32,
	pub SyncQPCTime: i64,
	pub SyncGPUTime: i64,
}

/// [`DXGI_GAMMA_CONTROL`](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/bb173061(v=vs.85))
/// struct.
#[repr(C)]
pub struct DXGI_GAMMA_CONTROL {
	pub Scale: DXGI_RGB,
	pub Offset: DXGI_RGB,
	pub GammaCurve: [DXGI_RGB; 1025],
}

impl_default!(DXGI_GAMMA_CONTROL);

/// [`DXGI_GAMMA_CONTROL_CAPABILITIES`](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/dxgitype/ns-dxgitype-dxgi_gamma_control_capabilities)
/// struct.
#[repr(C)]
pub struct DXGI_GAMMA_CONTROL_CAPABILITIES {
	ScaleAndOffsetSupported: BOOL,
	pub MaxConvertedValue: f32,
	pub MinConvertedValue: f32,
	pub NumGammaControlPoints: u32,
	pub ControlPointPositions: [f32; 1025],
}

impl_default!(DXGI_GAMMA_CONTROL_CAPABILITIES);

impl DXGI_GAMMA_CONTROL_CAPABILITIES {
	pub_fn_bool_get_set!(ScaleAndOffsetSupported, set_ScaleAndOffsetSupported);
}

/// [`DXGI_MAPPED_RECT`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/ns-dxgi-dxgi_mapped_rect)
/// struct.
#[repr(C)]
pub struct DXGI_MAPPED_RECT {
	Pitch: i32,
	pBits: *mut u8,
}

impl_default!(DXGI_MAPPED_RECT);

impl DXGI_MAPPED_RECT {
	/// Returns a slice over the `pBits` buffer.
	#[must_use]
	pub fn pBits(&self) -> Option<&[u8]> {
		if self.pBits.is_null() {
			None
		} else {
			Some(unsafe { std::slice::from_raw_parts(self.pBits, self.Pitch as _) })
		}
	}
}

/// [`DXGI_MODE_DESC`](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/bb173064(v=vs.85))
/// struct.
#[repr(C)]
#[derive(Default, Clone, PartialEq, Eq)]
pub struct DXGI_MODE_DESC {
	pub Width: u32,
	pub Height: u32,
	pub RefreshRate: DXGI_RATIONAL,
	pub Format: co::DXGI_FORMAT,
	pub ScanlineOrdering: co::DXGI_MODE_SCANLINE_ORDER,
	pub Scaling: co::DXGI_MODE_SCALING,
}

/// [`DXGI_OUTPUT_DESC`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/ns-dxgi-dxgi_output_desc)
/// struct.
#[repr(C)]
pub struct DXGI_OUTPUT_DESC {
	DeviceName: [u16; 32],
	pub DesktopCoordinates: RECT,
	AttachedToDesktop: BOOL,
	pub Rotation: co::DXGI_MODE_ROTATION,
	pub Monitor: HMONITOR,
}

impl_default!(DXGI_OUTPUT_DESC);

impl DXGI_OUTPUT_DESC {
	pub_fn_string_arr_get_set!(DeviceName, set_DeviceName);
	pub_fn_bool_get_set!(AttachedToDesktop, set_AttachedToDesktop);

}

/// [`DXGI_RATIONAL`](https://learn.microsoft.com/en-us/windows/win32/api/dxgicommon/ns-dxgicommon-dxgi_rational?redirectedfrom=MSDN)
/// struct.
#[repr(C)]
#[derive(Default, Clone, Copy, PartialEq, Eq)]
pub struct DXGI_RATIONAL {
	pub Numerator: u32,
	pub Denominator: u32,
}

/// [`DXGI_RGB`](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/bb173071(v=vs.85))
/// struct.
#[repr(C)]
#[derive(Default, Clone, Copy, PartialEq)]
pub struct DXGI_RGB {
	pub Red: f32,
	pub Green: f32,
	pub Blue: f32,
}

/// [`DXGI_SAMPLE_DESC`](https://learn.microsoft.com/en-us/windows/win32/api/dxgicommon/ns-dxgicommon-dxgi_sample_desc)
/// struct.
#[repr(C)]
#[derive(Default, Clone, Copy, PartialEq, Eq)]
pub struct DXGI_SAMPLE_DESC {
	pub Count: u32,
	pub Quality: u32,
}

/// [`DXGI_SHARED_RESOURCE`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/ns-dxgi-dxgi_shared_resource)
/// struct.
#[repr(C)]
#[derive(Clone, Copy)]
pub struct DXGI_SHARED_RESOURCE {
	pub Handle: *mut std::ffi::c_void,
}

impl_default!(DXGI_SHARED_RESOURCE);

/// [`DXGI_SURFACE_DESC`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/ns-dxgi-dxgi_surface_desc)
/// struct.
#[repr(C)]
#[derive(Default, Clone, Copy, PartialEq, Eq)]
pub struct DXGI_SURFACE_DESC {
	pub Width: u32,
	pub Height: u32,
	pub Format: co::DXGI_FORMAT,
	pub SampleDesc: DXGI_SAMPLE_DESC,
}

/// [`DXGI_SWAP_CHAIN_DESC`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/ns-dxgi-dxgi_swap_chain_desc)
/// struct.
#[repr(C)]
#[derive(PartialEq, Eq)]
pub struct DXGI_SWAP_CHAIN_DESC {
	pub BufferDesc: DXGI_MODE_DESC,
	pub SampleDesc: DXGI_SAMPLE_DESC,
	pub BufferUsage: co::DXGI_USAGE,
	pub BufferCount: u32,
	pub OutputWindow: HWND,
	Windowed: BOOL,
	pub SwapEffect: co::DXGI_SWAP_EFFECT,
	pub Flags: co::DXGI_SWAP_CHAIN_FLAG,
}

impl_default!(DXGI_SWAP_CHAIN_DESC);

impl DXGI_SWAP_CHAIN_DESC {
	pub_fn_bool_get_set!(Windowed, set_Windowed);
}