-
Notifications
You must be signed in to change notification settings - Fork 489
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
Transparent background for d2d examples? #541
Comments
If there was d2d clock example with "most performant" transparency, it would be helpful. |
Sure, I'll see what I can do about updating the sample. Yes, that's basically still the way to do it. If you're in a hurry I also cover high-performance transparency here: https://www.pluralsight.com/courses/directcomposition-in-action My other DirectX courses are also helpful if you need more information about the mechanics of it all. Here's a teaser of the card game demo. 😉 |
If you use composition to host your swapchain, the EDIT: Oops, I was late to the party 🙂 |
Oh great, I will check these contents gladly! I'm not myself D2D guru, just someone who wanted a transparent windows in Druid. It's very nice to see that how rust effort progresses. Transparent window need pops up many times, I knew few ways to do them several years back with WinAPI, all of them are outdated (layered windows and some other ways like with |
@robmikh is on the composition team 😉 so yes |
I apologize if I'm hijacking this thread, the transparency itself seems pretty straightforward, but the artifacts during resizing are giving me all kinds of trouble. Any kind of insights (@robmikh ?) would be appreciated. Is there any way to have DirectComposition ( But this, while mostly gives "non-wobbly" content, causes weird transparency issues at the right and bottom edges of window. Somewhat weirdly, |
I'm also interested about resizing artefacts, even though I don't have persistent artefacts, we are seeing some during resizing for split second when the window resizes I think. And in addition, I must say, nothing about transparency was straight forward 😀 in Mac it was straight forward, basically // Create IDCompositionDevice
let mut ptr: *mut c_void = null_mut();
DCompositionCreateDevice(
d3d11_device.raw_ptr() as *mut IDXGIDevice,
&IDCompositionDevice::uuidof(),
&mut ptr,
);
let composition_device = ComPtr::<IDCompositionDevice>::from_raw(ptr as _);
// Create IDCompositionTarget for the window
let mut ptr: *mut IDCompositionTarget = null_mut();
composition_device.CreateTargetForHwnd(hwnd as _, 1, &mut ptr);
let composition_target = ComPtr::from_raw(ptr);
// Create IDCompositionVisual and assign to swap chain
let mut ptr: *mut IDCompositionVisual = null_mut();
composition_device.CreateVisual(&mut ptr);
let composition_visual = ComPtr::from_raw(ptr);
composition_visual.SetContent(swap_chain as *mut IUnknown);
// Set the root as composition target and commit
composition_target.SetRoot(composition_visual.as_raw());
composition_device.Commit(); They were in the tutorial that was great though! |
Could you describe what you mean by "weird transparency issues"? Any images would be helpful. I think what you've outlined is the best that can be done with DirectComposition, but I can double check. DirectComposition's successor, Windows.UI.Composition, solves this problem a different way. In the minesweeper-rs sample, we set the Here's where we do it in minesweeper-rs: let compositor = Compositor::new()?;
let target = window.create_window_target(&compositor, false)?;
let root = compositor.create_container_visual()?;
root.set_relative_size_adjustment(Vector2 { x: 1.0, y: 1.0 })?;
target.set_root(&root)?; |
@robmikh, thank you for the response. However we need this to be working with DXGI (the content is rendered through Angle) and handle events through HWND. Regarding the artifacts, this is a brief overview of what different approaches do:
frame-wmsize-redirection.mov
noframe-wmsize-redirection.mov
noframe-nccalcsize-redirection.mov
noframe-wmnccalcsize-direct-composition.mov |
Just to be clear, Windows.UI.Composition is able to do both of these things. To use a DXGI swap chain as a surface, you'll need to QI the Compositor object for the ICompositorInterop interface. From there you can call CreateCompositionSurfaceForSwapChain which will give you an ICompositionSurface. You can place this surface into a CompositionSurfaceBrush and assign that as the Brush property to a SpriteVisual. You can also use a plain old Win32 window to host Windows.UI.Composition content. That's what the snipet I posted earlier is doing. You'll need to QI the Compositor object for the ICompositorDesktopInterop interface. From there call CreateDesktopWindowTarget with your HWND to create a DesktopWindowTarget. Assign a visual to the Root property and you should be all hooked up. I'll also take a look at those videos, thanks! |
@robmikh, I think you nudged me to the right track. Right now, we have top level HWND and a child HWND, that gets resized during top level HWND's WM_NCCSIZE. The IDCompositionTarget is created for the child hwnd. However I I actually create the IDComposition target for top level hwnd, this happens: noframe-wmnccalcsize-direct-composition-no-glitches.movThe transparency glitches are gone! Well, mostly gone. Occasionally the resizing won't keep up for a moment, as there doesn't seem to be any hard synchronization going on, but it's a night and day difference anyway. |
There is cross platform Rust GUI toolkit called Druid, we've been working on to create a transparent background for the window. Would it be possible to have an example of transparent window in this repo?
I found @kennykerr your tutorial for "high performance" version of it from 2014. As of writing, 2021, is that still the most high performant way to do it?
In Druid we also use Swap Chains but they won't work correctly for transparent windows because we use
CreateSwapChainForHwnd
and reading your article we have to switch usingCreateSwapChainForComposition
.Mac, and Linux GTK versions came really fast, but I'm struggling with this D2D scrabble still.
The text was updated successfully, but these errors were encountered: