winsafe\dxgi\com_interfaces/
idxgiswapchain.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::dxgi::vts::*;
6use crate::kernel::privs::*;
7use crate::ole::privs::*;
8use crate::prelude::*;
9
10com_interface! { IDXGISwapChain: "310d36a0-d2e7-4c0a-aa04-6a9d23b8886a";
11	/// [`IDXGISwapChain`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nn-dxgi-idxgiswapchain)
12	/// COM interface.
13	///
14	/// Automatically calls
15	/// [`Release`](https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-release)
16	/// when the object goes out of scope.
17}
18
19impl dxgi_IDXGIObject for IDXGISwapChain {}
20impl dxgi_IDXGIDeviceSubObject for IDXGISwapChain {}
21impl dxgi_IDXGISwapChain for IDXGISwapChain {}
22
23/// This trait is enabled with the `dxgi` feature, and provides methods for
24/// [`IDXGISwapChain`](crate::IDXGISwapChain).
25///
26/// Prefer importing this trait through the prelude:
27///
28/// ```no_run
29/// use winsafe::prelude::*;
30/// ```
31pub trait dxgi_IDXGISwapChain: dxgi_IDXGIDeviceSubObject {
32	/// [`IDXGISwapChain::GetBuffer`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-getbuffer)
33	/// method.
34	#[must_use]
35	fn GetBuffer<T: ole_IUnknown>(&self, buffer_index: u32) -> HrResult<T> {
36		let mut queried = unsafe { T::null() };
37		HrRet(unsafe {
38			(vt::<IDXGISwapChainVT>(self).GetBuffer)(
39				self.ptr(),
40				buffer_index,
41				pcvoid(&T::IID),
42				queried.as_mut(),
43			)
44		})
45		.to_hrresult()
46		.map(|_| queried)
47	}
48
49	fn_com_interface_get! { GetContainingOutput: IDXGISwapChainVT => IDXGIOutput;
50		/// [`IDXGISwapChain::GetContainingOutput`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-getcontainingoutput)
51		/// method.
52	}
53
54	/// [`IDXGISwapChain::GetDesc`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-getdesc)
55	/// method.
56	#[must_use]
57	fn GetDesc(&self) -> HrResult<DXGI_SWAP_CHAIN_DESC> {
58		let mut desc = DXGI_SWAP_CHAIN_DESC::default();
59		HrRet(unsafe { (vt::<IDXGISwapChainVT>(self).GetDesc)(self.ptr(), pvoid(&mut desc)) })
60			.to_hrresult()
61			.map(|_| desc)
62	}
63
64	/// [`IDXGISwapChain::GetFrameStatistics`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-getframestatistics)
65	/// method.
66	fn GetFrameStatistics(&self) -> HrResult<DXGI_FRAME_STATISTICS> {
67		let mut stats = DXGI_FRAME_STATISTICS::default();
68		HrRet(unsafe { (vt::<IDXGISwapChainVT>(self).GetDesc)(self.ptr(), pvoid(&mut stats)) })
69			.to_hrresult()
70			.map(|_| stats)
71	}
72
73	/// [`IDXGISwapChain::GetFullscreenState`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-getfullscreenstate)
74	/// method.
75	#[must_use]
76	fn GetFullscreenState(&self) -> HrResult<(bool, Option<IDXGIOutput>)> {
77		let mut fullscreen = 0;
78		let mut queried = unsafe { IDXGIOutput::null() };
79
80		HrRet(unsafe {
81			(vt::<IDXGISwapChainVT>(self).GetFullscreenState)(
82				self.ptr(),
83				&mut fullscreen,
84				queried.as_mut(),
85			)
86		})
87		.to_hrresult()
88		.map(|_| (fullscreen != 0, if queried.ptr().is_null() { None } else { Some(queried) }))
89	}
90
91	/// [`IDXGISwapChain::GetLastPresentCount`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-getlastpresentcount)
92	/// method.
93	#[must_use]
94	fn GetLastPresentCount(&self) -> HrResult<u32> {
95		let mut count = 0u32;
96		HrRet(unsafe { (vt::<IDXGISwapChainVT>(self).GetLastPresentCount)(self.ptr(), &mut count) })
97			.to_hrresult()
98			.map(|_| count)
99	}
100
101	/// [`IDXGISwapChain::Present`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-present)
102	/// method.
103	fn Present(&self, sync_interval: u32, flags: co::DXGI_PRESENT) -> HrResult<()> {
104		HrRet(unsafe {
105			(vt::<IDXGISwapChainVT>(self).Present)(self.ptr(), sync_interval, flags.raw())
106		})
107		.to_hrresult()
108	}
109
110	/// [`IDXGISwapChain::ResizeBuffers`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-resizebuffers)
111	/// method.
112	fn ResizeBuffers(
113		&self,
114		buffer_count: u32,
115		width: u32,
116		height: u32,
117		new_format: co::DXGI_FORMAT,
118		swap_chain_flags: co::DXGI_SWAP_CHAIN_FLAG,
119	) -> HrResult<()> {
120		HrRet(unsafe {
121			(vt::<IDXGISwapChainVT>(self).ResizeBuffers)(
122				self.ptr(),
123				buffer_count,
124				width,
125				height,
126				new_format.raw(),
127				swap_chain_flags.raw(),
128			)
129		})
130		.to_hrresult()
131	}
132
133	/// [`IDXGISwapChain::ResizeTarget`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-resizetarget)
134	/// method.
135	fn ResizeTarget(&self, new_target_parameters: &DXGI_MODE_DESC) -> HrResult<()> {
136		HrRet(unsafe {
137			(vt::<IDXGISwapChainVT>(self).ResizeTarget)(self.ptr(), pcvoid(new_target_parameters))
138		})
139		.to_hrresult()
140	}
141
142	/// [`IDXGISwapChain::SetFullscreenState`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-setfullscreenstate)
143	/// method.
144	fn SetFullscreenState(
145		&self,
146		fullscreen: bool,
147		target: Option<&impl dxgi_IDXGIOutput>,
148	) -> HrResult<()> {
149		HrRet(unsafe {
150			(vt::<IDXGISwapChainVT>(self).SetFullscreenState)(
151				self.ptr(),
152				fullscreen as _,
153				target.map_or(std::ptr::null_mut(), |t| t.ptr()),
154			)
155		})
156		.to_hrresult()
157	}
158}