Skip to content
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

Gdiplus missing some functions/enums GdipCreateSolidFill, GdipCloneBrush, GpStatus #1287

Closed
elachlan opened this issue Sep 29, 2022 · 19 comments · Fixed by #1679 or #1709
Closed

Gdiplus missing some functions/enums GdipCreateSolidFill, GdipCloneBrush, GpStatus #1287

elachlan opened this issue Sep 29, 2022 · 19 comments · Fixed by #1679 or #1709
Assignees
Labels
help wanted Extra attention is needed missing api Some documented API is missing from the metadata WinForms

Comments

@elachlan
Copy link
Contributor

elachlan commented Sep 29, 2022

https://learn.microsoft.com/en-au/windows/win32/api/gdiplustypes/ne-gdiplustypes-status

GdipCreateSolidFill
https://learn.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-solidbrush-flat

GdipCloneBrush
https://learn.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-brush-flat

I can't find the direct documentation on it.

Winforms tracking: dotnet/winforms#7468

@elachlan elachlan changed the title Gdiplus missing some functions/enums GdipCreateSolidFill, GdipCloneBrush Gdiplus missing some functions/enums GdipCreateSolidFill, GdipCloneBrush, GpStatus Sep 29, 2022
@mikebattista mikebattista added the missing api Some documented API is missing from the metadata label Oct 3, 2022
@chenss3
Copy link
Collaborator

chenss3 commented Oct 17, 2022

These functions are in the header gdiplusflat.h, which are purposefully omitted from the scraper since they're C++ classes. I think at this point, there's not much we can do since these APIs reference C++ types.

/um/gdiplusflat.h,true,Can't use C++ classes

@elachlan
Copy link
Contributor Author

@sotteson1 is there any way around this for win32metadata?

CC: @JeremyKuhne, we might have to add these manually to winforms in the shorter term if we can't get them included here.

@kennykerr
Copy link
Contributor

Note that GDI+ has a C++ wrapper library around a flat C API. The latter should be expressible by win32 metadata. The "C++ classes" are only use as opaque pointers and could be represented as NativeTypeDef structs.

@elachlan
Copy link
Contributor Author

elachlan commented Nov 3, 2022

@mikebattista any idea on this? Kennykerr's idea above sounds like a plan, but I am unsure how to go about it.

@mikebattista
Copy link
Contributor

First step would be to add the header to the right Partition and rebuild to see if the C APIs get picked up.

@elachlan
Copy link
Contributor Author

elachlan commented Dec 3, 2022

@mikebattista I see you looked into adding the headers, how did you go?

@mikebattista
Copy link
Contributor

It became a non-trivial addition. Someone more familiar with that API would have a better time trying to add the APIs and resolve build errors.

https://github.com/microsoft/win32metadata/compare/mikebattista/gdiplusflat is where I left off.

@JeremyKuhne
Copy link
Member

Fwiw, TerraFX has this stuff wrapped and might give some guidance: https://github.com/terrafx/terrafx.interop.windows/tree/main/generation/Gdiplus

I'm very interested in getting this in so we can flip System.Drawing over to CsWin32.

@mikebattista
Copy link
Contributor

@tannergooding is adding gdiplusflat.h here something you could help us with given you got this working in terrafx?

I left off at 4b7ed82.

@tannergooding
Copy link
Member

I'd need to better understand what the errors being hit were.

TerraFX is namely generated as a .NET Latest API surface (so doesn't support .NET Standard or .NET Framework) and is meant to be directly consumable from C#.

Win32Metadata on the other hand is defining a .NET Standard compatible surface area for the most part and is meant to be consumed somewhat indirectly via generators for a particular language.

In general TerraFX uses these central settings: https://github.com/terrafx/terrafx.interop.windows/blob/main/generation/settings.rsp

A series of remaps: https://github.com/terrafx/terrafx.interop.windows/blob/main/generation/remap.rsp

And then a series of "per-header" settings and "include headers" here: https://github.com/terrafx/terrafx.interop.windows/tree/main/generation/Gdiplus/um/gdiplusflat

There isn't really anything special being done for gdiplusflat.h. There are a couple of excludes and otherwise everything is handled by the global settings and remappings.

The relevant C++ "opaque type" remappings are here: https://github.com/terrafx/terrafx.interop.windows/blob/main/generation/remap-types.rsp#L93-L148

It just does things like Gdiplus.Bitmap=@GpBitmap. Things like GpBitmap are generated from gdiplusgpstubs.h

@tannergooding
Copy link
Member

I'd guess the only difference in success vs failure here is a lack of remappings on the Win32Metadata side.

Otherwise, the main difference is TerraFX uses --config preview-codegen vs Win32Metadata using --config compatible-codegen. Win32Metadata does specify somethings like exclude-anonymous-field-helpers and TerraFX specifies some additional things like generate-marker-interfaces and other generate-* APIs, but I wouldn't expect those to be impactful here.

@mikebattista
Copy link
Contributor

If you have the time/motivation, the ask is to try to build https://github.com/microsoft/win32metadata/tree/mikebattista/gdiplusflat and work through the errors.

Given potential settings and remaps needed and that you've worked through this already, you're probably most equipped to configure this.

@tannergooding
Copy link
Member

Not sure when I'm next going to have availability. Will let you know if I do.

In general I expect it's just the missing remappings and they are likely something that --config log-potential-typedef-remappings is probably already suggesting as things to fix. I'd expect anyone should be able to try the header and work through the suggested fixes that ClangSharp will print out for you, particularly for gdiplusflat.h since that doesn't actually declare any C++ code.

Something like gdipluspath is a bit different since it declares proper C++ types and those need to be excluded (https://github.com/terrafx/terrafx.interop.windows/blob/main/generation/Gdiplus/um/gdipluspath/generate.rsp)

@riverar
Copy link
Collaborator

riverar commented Feb 21, 2023

Why are there two separate similar projects? @tannergooding is there something blocking adoption of win32metadata directly?

@tannergooding
Copy link
Member

@riverar, Different use-cases and scenarios.


Win32Metadata isn't meant for direct consumption, you have to use an additional tool on top such as CsWin32

CsWin32 is ok if you're depending on a couple of interop APIs, it adds measurable compilation overhead for more complex scenarios where you need many types or headers.

CsWin32 also tries to make things "friendly" to use in terms of providing additional overloads, marshalling, etc. This can make it error prone in some cases, and add overhead that is not acceptable for some scenarios (like games/interop/etc).

CsWin32 doesn't currently support trimming or AOT and several other "modern" scenarios.


TerraFX on the other hand is a set of directly consumable 1-to-1 blittable bindings that are explicitly targeted towards and take advantage of modern .NET types and C# language features.

It supports trimming, reflection free AOT, and more.

It is specifically geared towards use in my own codebases and needs, which are high-perf 3D rendering, but has been adopted for use by several other prominent projects.

I've been maintaining TerraFX, and the sources that dotnet/ClangSharp were built off of for a bit over 10 years now. It was only around 2019 that I started making them available on GitHub after I had gotten enough requests from other users that I make it available for broader use.

@elachlan
Copy link
Contributor Author

@riverar did you end up getting anywhere?

@riverar
Copy link
Collaborator

riverar commented Sep 13, 2023

@elachlan Hey there, I have time to revisit this now, thanks for your patience!

@elachlan
Copy link
Contributor Author

For the templates you were having issues with. Should we manually define them to avoid the issues in ClangSharp?

@riverar
Copy link
Collaborator

riverar commented Sep 13, 2023

Oh those were unrelated to GDI. Was something that bubbled up while helping another Microsoft employee with another C++ project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed missing api Some documented API is missing from the metadata WinForms
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants