CreateBitmapFromDxgiSurface uses D2D1_BITMAP_PROPERTIES1_unmanaged even though D2D1_BITMAP_PROPERTIES1 already has the same layout
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.5k
- Forks
- 124
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 9
Description
Actual behavior
When generating bindings for ID2D1DeviceContext6, CsWin32 generates ID2D1DeviceContext.CreateBitmapFromDxgiSurface with D2D1_BITMAP_PROPERTIES1_unmanaged instead of D2D1_BITMAP_PROPERTIES1.
The generated signature is:
unsafe void CreateBitmapFromDxgiSurface(
IDXGISurface surface,
[Optional] D2D1_BITMAP_PROPERTIES1_unmanaged* bitmapProperties,
out ID2D1Bitmap1 bitmap);
CsWin32 also generates an extra D2D1_BITMAP_PROPERTIES1_unmanaged struct.
In the generated output, D2D1_BITMAP_PROPERTIES1_unmanaged appears to have the same layout and field types as D2D1_BITMAP_PROPERTIES1, including ID2D1ColorContext_unmanaged* colorContext.
Because of this, I have to construct D2D1_BITMAP_PROPERTIES1_unmanaged in my own code to call CreateBitmapFromDxgiSurface, even though the Win32 API uses const D2D1_BITMAP_PROPERTIES1* and D2D1_BITMAP_PROPERTIES1 already seems usable as-is.
Expected behavior
CreateBitmapFromDxgiSurface should accept D2D1_BITMAP_PROPERTIES1 (or D2D1_BITMAP_PROPERTIES1? in the convenience overload), and CsWin32 should not generate a duplicate D2D1_BITMAP_PROPERTIES1_unmanaged type for this case.
Repro steps
NativeMethods.txtcontent:
ID2D1DeviceContext6
NativeMethods.jsoncontent (if present):
{
"$schema": "https://aka.ms/CsWin32.schema.json"
}
- Any of your own code that should be shared?
var bitmapProperties = new D2D1_BITMAP_PROPERTIES1_unmanaged() {
bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
pixelFormat = new() {
format = DXGI_FORMAT_UNKNOWN,
alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED
},
dpiX = _dpi,
dpiY = _dpi,
colorContext = null
};
_d2dDeviceContext.CreateBitmapFromDxgiSurface(tempDXGISurface, bitmapProperties, out _d2dRenderTarget[i]);
Context
- CsWin32 version:
0.3.275 - Win32Metadata version (if explicitly set by project): not explicitly set
- Target Framework:
net11.0-windows10.0.17763.0 LangVersion(if explicitly set by project): not explicitly setDisableRuntimeMarshalling:truePublishAot:true
This issue report was drafted with help from Codex based on the generated bindings and local project configuration.
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
Start with the NativeMethods.txt entry for ID2D1DeviceContext6 and inspect the generated CreateBitmapFromDxgiSurface signature and duplicate D2D1_BITMAP_PROPERTIES1_unmanaged type. Trace the binding-generation logic that selects unmanaged struct variants, then add a regression case for this repro using the NativeMethods.json configuration. Done means the method uses D2D1_BITMAP_PROPERTIES1 and no duplicate type is generated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100