diff --git a/src/dxgi.rs b/src/dxgi.rs index 0a66dcd027..3c0396e88e 100644 --- a/src/dxgi.rs +++ b/src/dxgi.rs @@ -5,7 +5,7 @@ use winapi::{ dxgi, dxgi1_2, dxgi1_3, dxgi1_4, dxgi1_5, dxgi1_6, dxgiformat, dxgitype, minwindef::TRUE, windef::HWND, }, - um::{d3d12, dxgidebug, unknwnbase::IUnknown}, + um::{d3d12, dxgidebug, unknwnbase::IUnknown, winnt::HANDLE}, Interface, }; @@ -76,6 +76,8 @@ crate::weak_com_inheritance_chain! { } } +pub type FactoryMedia = WeakPtr; + pub type SwapChain = WeakPtr; pub type SwapChain1 = WeakPtr; pub type SwapChain2 = WeakPtr; @@ -140,6 +142,22 @@ impl DxgiLib { Ok((factory, hr)) } + pub fn create_factory_media(&self) -> Result, libloading::Error> { + type Fun = extern "system" fn( + winapi::shared::guiddef::REFIID, + *mut *mut winapi::ctypes::c_void, + ) -> HRESULT; + + let mut factory = FactoryMedia::null(); + let hr = unsafe { + // https://learn.microsoft.com/en-us/windows/win32/api/dxgi1_3/nn-dxgi1_3-idxgifactorymedia + let func: libloading::Symbol = self.lib.get(b"CreateDXGIFactory1")?; + func(&dxgi1_3::IDXGIFactoryMedia::uuidof(), factory.mut_void()) + }; + + Ok((factory, hr)) + } + pub fn get_debug_interface1(&self) -> Result, libloading::Error> { type Fun = extern "system" fn( winapi::shared::minwindef::UINT, @@ -295,6 +313,28 @@ impl Factory4 { } } +impl FactoryMedia { + pub fn create_swapchain_for_composition_surface_handle( + &self, + queue: *mut IUnknown, + surface_handle: HANDLE, + desc: &SwapchainDesc, + ) -> D3DResult { + let mut swap_chain = SwapChain1::null(); + let hr = unsafe { + self.CreateSwapChainForCompositionSurfaceHandle( + queue, + surface_handle, + &desc.to_desc1(), + ptr::null_mut(), + swap_chain.mut_void() as *mut *mut _, + ) + }; + + (swap_chain, hr) + } +} + bitflags! { pub struct SwapChainPresentFlags: u32 { const DXGI_PRESENT_DO_NOT_SEQUENCE = dxgi::DXGI_PRESENT_DO_NOT_SEQUENCE;