From bd2290f4acb9a6793b909c1e4ce0838075084f24 Mon Sep 17 00:00:00 2001 From: Xiaopeng Li Date: Thu, 10 Nov 2022 17:38:01 +0800 Subject: [PATCH 1/2] Add FactoryMedia --- src/dxgi.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/dxgi.rs b/src/dxgi.rs index 0a66dcd027..01bbafc028 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, }; @@ -64,6 +64,7 @@ pub type Factory3 = WeakPtr; pub type Factory4 = WeakPtr; pub type Factory5 = WeakPtr; pub type Factory6 = WeakPtr; +pub type FactoryMedia = WeakPtr; crate::weak_com_inheritance_chain! { #[derive(Debug, Copy, Clone, PartialEq, Hash)] pub enum DxgiFactory { @@ -73,6 +74,7 @@ crate::weak_com_inheritance_chain! { Factory4(dxgi1_4::IDXGIFactory4), from_factory4, as_factory4, unwrap_factory4; Factory5(dxgi1_5::IDXGIFactory5), from_factory5, as_factory5, unwrap_factory5; Factory6(dxgi1_6::IDXGIFactory6), from_factory6, as_factory6, unwrap_factory6; + FactoryMedia(dxgi1_3::IDXGIFactoryMedia), from_factory_media, as_factory_media, unwrap_factory_media; } } @@ -295,6 +297,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; From fd0df189eff79ab2d7b91f48f5d5d38a9adfe3b5 Mon Sep 17 00:00:00 2001 From: Xiaopeng Li Date: Fri, 25 Nov 2022 15:21:08 +0800 Subject: [PATCH 2/2] Create IDXGIFactoryMedia by CreateDXGIFactory1 --- src/dxgi.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/dxgi.rs b/src/dxgi.rs index 01bbafc028..3c0396e88e 100644 --- a/src/dxgi.rs +++ b/src/dxgi.rs @@ -64,7 +64,6 @@ pub type Factory3 = WeakPtr; pub type Factory4 = WeakPtr; pub type Factory5 = WeakPtr; pub type Factory6 = WeakPtr; -pub type FactoryMedia = WeakPtr; crate::weak_com_inheritance_chain! { #[derive(Debug, Copy, Clone, PartialEq, Hash)] pub enum DxgiFactory { @@ -74,10 +73,11 @@ crate::weak_com_inheritance_chain! { Factory4(dxgi1_4::IDXGIFactory4), from_factory4, as_factory4, unwrap_factory4; Factory5(dxgi1_5::IDXGIFactory5), from_factory5, as_factory5, unwrap_factory5; Factory6(dxgi1_6::IDXGIFactory6), from_factory6, as_factory6, unwrap_factory6; - FactoryMedia(dxgi1_3::IDXGIFactoryMedia), from_factory_media, as_factory_media, unwrap_factory_media; } } +pub type FactoryMedia = WeakPtr; + pub type SwapChain = WeakPtr; pub type SwapChain1 = WeakPtr; pub type SwapChain2 = WeakPtr; @@ -142,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,