d2d: Using DeviceContext with Swapchain
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.4k
- Forks
- 98
- PR merge metrics
- No merged PRs in 30d
Description
Repository: https://github.com/msiglreith/piet_d2d_tests
As mentioned a few days ago I has some issues with integrating `piet` in my GUI library in the past. Here are my attempts at using it in combination with winit and further initializing the piet context from a DeviceContext + Swapchain. The issue actually seems to be inside the underlying `direct2d` crate which fails the create a rendertarget from the swapchain backbuffer. Nonetheless it might be interesting as well for this project:
```
D2D DEBUG ERROR - The bitmap options [0x0] must be a subset of the flags associated with the DXGI surface.
```
So to be fair not really a piet issue. After some tries to guess the flags I gave up. I investigated a bit more and compared it to my current way of creating the bitmap:
paw:
```rust
let surface = backbuffer.cast::().unwrap();
unsafe {
let mut bitmap = ptr::null_mut();
let _hr = self.CreateBitmapFromDxgiSurface(
surface.as_raw(),
ptr::null(),
&mut bitmap as *mut _,
);
Bitmap(BitmapRaw::from_raw(bitmap))
}
```
direct2d:
```rust
const DEFAULT_BITMAP_PROPS: D2D1_BITMAP_PROPERTIES1 = D2D1_BITMAP_PROPERTIES1 {
pixelFormat: D2D1_PIXEL_FORMAT {
format: Format::Unknown as u32,
alphaMode: AlphaMode::Premultiplied as u32,
},
dpiX: 96.0,
dpiY: 96.0,
bitmapOptions: BitmapOptions::NONE.0,
colorContext: ptr::null(),
};
BitmapSource::Dxgi(surface, context) => {
let mut ptr = ptr::null_mut();
let hr = (*context.get_raw()).CreateBitmapFromDxgiSurface(
surface.get_raw(),
&self.properties,
&mut ptr,
);
if SUCCEEDED(hr) {
Ok(Bitmap::from_raw(ptr as _))
} else {
Err(hr.into())
}
}
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the DeviceContext + Swapchain setup from piet_d2d_tests and inspect the direct2d CreateBitmapFromDxgiSurface path, comparing it with the raw call shown in the issue. Confirm whether the failure belongs in piet or direct2d; done means a documented diagnosis or a tested fix that creates a render target from the swapchain backbuffer without the bitmap-options error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100