-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add dcomp on windows #7550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
n1ght-hunter
wants to merge
19
commits into
gfx-rs:trunk
Choose a base branch
from
n1ght-hunter:dev/windows-os-transparent
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add dcomp on windows #7550
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e6d7e5f
add dx12 dcomp option to backend options
n1ght-hunter c328699
impl dcomp for the dx12 backend
n1ght-hunter 3f91a00
Merge branch 'gfx-rs:trunk' into dev/windows-os-transparent
n1ght-hunter b8131bf
Merge branch 'gfx-rs:trunk' into dev/windows-os-transparent
n1ght-hunter 1f70a9a
Add Dcomp support to DX12 backend in changelog
n1ght-hunter 60a747c
move decomp to another module
n1ght-hunter 8b012f3
refactor: replace use_dcomp with presentation_system in Dx12BackendOp…
n1ght-hunter 91d98af
refactor: enhance Dx12PresentationSystem with Copy, PartialEq, and Eq…
n1ght-hunter bae60c3
refactor: replace use_dcomp with presentation_system in Dx12 backend …
n1ght-hunter 194a685
Merge branch 'trunk' into dev/windows-os-transparent
n1ght-hunter 32ce523
refactor: update Dx12BackendOptions to use presentation_system instea…
n1ght-hunter 157c1c6
Merge branch 'dev/windows-os-transparent' of https://github.com/n1ght…
n1ght-hunter cd41a6e
Merge branch 'trunk' into dev/windows-os-transparent
n1ght-hunter 73579d3
refactor(dx12): update DirectComposition device creation to use DComp…
n1ght-hunter cae67ca
Merge branch 'trunk' into dev/windows-os-transparent
n1ght-hunter 830bf2b
cleanup dcomp create device types
n1ght-hunter f40d9b5
clean dcomp code
n1ght-hunter 2302705
refactor(dx12): remove unused Direct3D 11 dependencies from Cargo.toml
n1ght-hunter 504dfa1
refactor(dx12): remove unnecessary device parameter from DirectCompos…
n1ght-hunter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use windows::Win32::{Foundation::HWND, Graphics::DirectComposition}; | ||
|
||
#[derive(Default)] | ||
pub struct DCompState { | ||
inner: Option<InnerState>, | ||
} | ||
|
||
impl DCompState { | ||
/// This will create a DirectComposition device and a target for the window handle if not already initialized. | ||
/// If the device is already initialized, it will return the existing state. | ||
pub unsafe fn get_or_init( | ||
&mut self, | ||
hwnd: &HWND, | ||
) -> Result<&mut InnerState, crate::SurfaceError> { | ||
if self.inner.is_none() { | ||
self.inner = Some(unsafe { InnerState::init(hwnd) }?); | ||
} | ||
Ok(self.inner.as_mut().unwrap()) | ||
} | ||
} | ||
|
||
pub struct InnerState { | ||
pub visual: DirectComposition::IDCompositionVisual, | ||
pub device: DirectComposition::IDCompositionDevice, | ||
// Must be kept alive but is otherwise unused after initialization. | ||
pub _target: DirectComposition::IDCompositionTarget, | ||
} | ||
|
||
impl InnerState { | ||
/// Creates a DirectComposition device and a target for the given window handle. | ||
pub unsafe fn init(hwnd: &HWND) -> Result<Self, crate::SurfaceError> { | ||
let dcomp_device: DirectComposition::IDCompositionDevice = { | ||
profiling::scope!("DirectComposition::DCompositionCreateDevice"); | ||
unsafe { DirectComposition::DCompositionCreateDevice2(None) }.map_err(|err| { | ||
log::error!("DirectComposition::DCompositionCreateDevice failed: {err}"); | ||
crate::SurfaceError::Other("DirectComposition::DCompositionCreateDevice") | ||
})? | ||
}; | ||
|
||
let target = { | ||
profiling::scope!("IDCompositionDevice::CreateTargetForHwnd"); | ||
unsafe { dcomp_device.CreateTargetForHwnd(*hwnd, false) }.map_err(|err| { | ||
log::error!("IDCompositionDevice::CreateTargetForHwnd failed: {err}"); | ||
crate::SurfaceError::Other("IDCompositionDevice::CreateTargetForHwnd") | ||
})? | ||
}; | ||
|
||
let visual = { | ||
profiling::scope!("IDCompositionDevice::CreateVisual"); | ||
unsafe { dcomp_device.CreateVisual() }.map_err(|err| { | ||
log::error!("IDCompositionDevice::CreateVisual failed: {err}"); | ||
crate::SurfaceError::Other("IDCompositionDevice::CreateVisual") | ||
})? | ||
}; | ||
|
||
{ | ||
profiling::scope!("IDCompositionTarget::SetRoot"); | ||
unsafe { target.SetRoot(&visual) }.map_err(|err| { | ||
log::error!("IDCompositionTarget::SetRoot failed: {err}"); | ||
crate::SurfaceError::Other("IDCompositionTarget::SetRoot") | ||
})?; | ||
} | ||
|
||
Ok(InnerState { | ||
visual, | ||
device: dcomp_device, | ||
_target: target, | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.