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
use crate::adapter::AdapterType; use dcommon::error::Error; use winapi::shared::dxgi1_4::IDXGIFactory4; use winapi::um::winnt::LUID; use winapi::Interface; use wio::com::ComPtr; #[derive(Clone, PartialEq, ComWrapper)] #[com(send, sync, debug)] #[repr(transparent)] pub struct Factory4 { ptr: ComPtr<IDXGIFactory4>, } impl Factory4 { pub fn adapter_by_luid<A: AdapterType>(&self, luid: i64) -> Result<A, Error> { let luid = LUID { HighPart: (luid >> 32) as i32, LowPart: luid as u32, }; unsafe { let mut ptr = std::ptr::null_mut(); let hr = self .ptr .EnumAdapterByLuid(luid, &A::Interface::uuidof(), &mut ptr); Error::map_if(hr, || A::from_raw(ptr as _)) } } pub fn warp_adapter<A: AdapterType>(&self) -> Result<A, Error> { unsafe { let mut ptr = std::ptr::null_mut(); let hr = self.ptr.EnumWarpAdapter(&A::Interface::uuidof(), &mut ptr); Error::map_if(hr, || A::from_raw(ptr as _)) } } } impl super::FactoryType for Factory4 {} impl std::ops::Deref for Factory4 { type Target = super::Factory3; fn deref(&self) -> &Self::Target { unsafe { crate::helpers::deref_com_wrapper(self) } } } impl std::ops::DerefMut for Factory4 { fn deref_mut(&mut self) -> &mut Self::Target { unsafe { crate::helpers::deref_com_wrapper_mut(self) } } }