-
Notifications
You must be signed in to change notification settings - Fork 109
Add a CoreGraphics cross-import overlay with support for attaching CGImage
s.
#827
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@swift-ci test |
753920d
to
0e9b551
Compare
stmontgomery
reviewed
Dec 5, 2024
stmontgomery
reviewed
Dec 5, 2024
Sources/Overlays/_Testing_CoreGraphics/Attachments/ImageAttachmentError.swift
Outdated
Show resolved
Hide resolved
stmontgomery
reviewed
Dec 5, 2024
Sources/Overlays/_Testing_CoreGraphics/Attachments/_AttachableImageContainer.swift
Outdated
Show resolved
Hide resolved
stmontgomery
reviewed
Dec 5, 2024
Sources/Overlays/_Testing_CoreGraphics/Attachments/_AttachableImageContainer.swift
Outdated
Show resolved
Hide resolved
stmontgomery
reviewed
Dec 5, 2024
Sources/Overlays/_Testing_CoreGraphics/Attachments/_AttachableImageContainer.swift
Show resolved
Hide resolved
stmontgomery
reviewed
Dec 5, 2024
Sources/Overlays/_Testing_CoreGraphics/Attachments/_AttachableImageContainer.swift
Show resolved
Hide resolved
stmontgomery
reviewed
Dec 5, 2024
Sources/Overlays/_Testing_CoreGraphics/Attachments/Attachment+AttachableAsCGImage.swift
Outdated
Show resolved
Hide resolved
…GImage`s. This PR adds a new cross-import overlay target with Apple's Core Graphics framework that allows attaching a `CGImage` as an attachment in an arbitrary image format (PNG, JPEG, etc.) Because `CGImage` is imported into Swift as a non-final class, it cannot conform directly to `Attachable`, so an `AttachableContainer` type acts as a proxy. This type is not meant to be used directly, so its name is underscored. Initializers on `Attachment` are provided so that this abstraction is almost entirely transparent to test authors. A new protocol, `AttachableAsCGImage`, is introduced that abstracts away the relationship between the attached image and Core Graphics; in the future, I intend to make additional image types like `NSImage and `UIImage` conform to this protocol too. The code in this PR is, by definition, specific to Apple's platforms. In the future, I'd be interested in adding Windows/Linux equivalents (`HBITMAP`? Whatever Gnome/KDE/Qt use?) but that's beyond the scope of this PR.
0e9b551
to
d11f84e
Compare
@swift-ci test |
grynspan
commented
Dec 6, 2024
Sources/Overlays/_Testing_CoreGraphics/Attachments/ImageAttachmentError.swift
Outdated
Show resolved
Hide resolved
grynspan
commented
Dec 6, 2024
Sources/Overlays/_Testing_CoreGraphics/Attachments/ImageAttachmentError.swift
Outdated
Show resolved
Hide resolved
@swift-ci test |
stmontgomery
reviewed
Dec 9, 2024
Sources/Overlays/_Testing_CoreGraphics/Attachments/Attachment+AttachableAsCGImage.swift
Show resolved
Hide resolved
stmontgomery
approved these changes
Dec 9, 2024
grynspan
added a commit
that referenced
this pull request
Dec 19, 2024
This PR adds on to the Core Graphics cross-import overlay added in #827 to allow attaching instances of `NSImage` to a test. `NSImage` is a more complicated animal because it is not `Sendable`, but we don't want to make a (potentially very expensive) deep copy of its data until absolutely necessary. So we check inside the image to see if its contained representations are known to be safely copyable (i.e. copies made with `NSCopying` do not share any mutable state with their originals.) If it looks safe to make a copy of the image by calling `copy()`, we do so; otherwise, we try to make a deep copy of the image. Due to how Swift implements polymorphism in protocol requirements, and because we don't really know what they're doing, subclasses of `NSImage` just get a call to `copy()` instead of deep introspection. `UIImage` support will be implemented in a separate PR. > [!NOTE] > Attachments remain an experimental feature.
2 tasks
grynspan
added a commit
that referenced
this pull request
May 20, 2025
This PR adds on to the Core Graphics cross-import overlay added in #827 to allow attaching instances of `NSImage` to a test. `NSImage` is a more complicated animal because it is not `Sendable`, but we don't want to make a (potentially very expensive) deep copy of its data until absolutely necessary. So we check inside the image to see if its contained representations are known to be safely copyable (i.e. copies made with `NSCopying` do not share any mutable state with their originals.) If it looks safe to make a copy of the image by calling `copy()`, we do so; otherwise, we try to make a deep copy of the image. Due to how Swift implements polymorphism in protocol requirements, and because we don't really know what they're doing, subclasses of `NSImage` just get a call to `copy()` instead of deep introspection. `UIImage` support will be implemented in a separate PR. > [!NOTE] > Attachments remain an experimental feature.
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
cross-import-overlays
🍰 Cross-import overlays (Foundation, Core Graphics, etc.)
darwin
🍎 macOS, iOS, watchOS, tvOS, and visionOS support
enhancement
New feature or request
public-api
Affects public API
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a new cross-import overlay target with Apple's Core Graphics framework that allows attaching a
CGImage
as an attachment in an arbitrary image format (PNG, JPEG, etc.)Because
CGImage
is imported into Swift as a non-final class, it cannot conform directly toAttachable
, so anAttachableContainer
type acts as a proxy. This type is not meant to be used directly, so its name is underscored. Initializers onAttachment
are provided so that this abstraction is almost entirely transparent to test authors.A new protocol,
AttachableAsCGImage
, is introduced that abstracts away the relationship between the attached image and Core Graphics; in the future, I intend to make additional image types likeNSImage
andUIImage
conform to this protocol too.Example usage:
The code in this PR is, by definition, specific to Apple's platforms. In the future, I'd be interested in adding Windows/Linux equivalents (
HBITMAP
? Whatever Gnome/KDE/Qt use?) but that's beyond the scope of this PR.Checklist: