microsoft / microsoft/CsWin32

CreateBitmapFromDxgiSurface uses D2D1_BITMAP_PROPERTIES1_unmanaged even though D2D1_BITMAP_PROPERTIES1 already has the same layout

Open
#1,682 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

  1. NativeMethods.txt content:
ID2D1DeviceContext6
  1. NativeMethods.json content (if present):
{
  "$schema": "https://aka.ms/CsWin32.schema.json"
}
  1. 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 set
  • DisableRuntimeMarshalling: true
  • PublishAot: true

This issue report was drafted with help from Codex based on the generated bindings and local project configuration.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.