Skip to content

Allow attaching an IWICBitmapSource instance directly. #1266

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Aug 13, 2025

This PR adjusts the experimental WIC bitmap attachment support I recently added so that a test author can attach an instance of IWICBitmapSource (which is the parent type of the already-supported IWICBitmap.) Protocols and conformances are adjusted to match.

This PR then explicitly adds conformances to every COM class in WIC that subclasses IWICBitmapSource since we can't see COM class inheritance in Swift (yet?)

I could have left the protocols as-is, but then you'd have to convert an IWICBitmapSource to an IWICBitmap (by allocating a new COM object) then cast it back to an IWICBitmapSource (by calling QueryInterface() and juggling the refcount) in order to actually attach it.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

This PR adjusts the experimental WIC bitmap attachment support I recently added
so that a test author can attach an instance of `IWICBitmapSource` (which is the
parent type of the already-supported `IWICBitmap`.) Protocols and conformances
are adjusted to match.

I could have left the protocols as-is, but then you'd have to convert an
`IWICBitmapSource` to an `IWICBitmap` (by allocating a new COM object) then cast
it back to an `IWICBitmapSource` (by calling `QueryInterface()` and juggling the
refcount) in order to actually attach it.
@grynspan grynspan added this to the Swift 6.x (main) milestone Aug 13, 2025
@grynspan grynspan self-assigned this Aug 13, 2025
@grynspan grynspan added the enhancement New feature or request label Aug 13, 2025
@grynspan grynspan added windows 🪟 Windows support attachments/activities 🖇️ Work related to attachments and/or activities labels Aug 13, 2025
@grynspan grynspan requested a review from compnerd August 13, 2025 19:25
@grynspan
Copy link
Contributor Author

@swift-ci test

/// - Important: This function consumes a reference to `self` even if the cast
/// fails.
consuming func cast(to _: IWICBitmapSource.Type) throws -> UnsafeMutablePointer<IWICBitmapSource> {
try self.withMemoryRebound(to: IUnknown.self, capacity: 1) { `self` in
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The casts in this file to IUnknown are safe insofar as we use them to access fixed members of the COM vtable. The casts would become unsafe if we allowed the resulting pointers to escape and if any of the types we use them on have multiple non-virtual inheritance to IUnknown.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we capture this in a code comment for future reference?

@grynspan
Copy link
Contributor Author

@swift-ci test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attachments/activities 🖇️ Work related to attachments and/or activities enhancement New feature or request windows 🪟 Windows support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants