-
Notifications
You must be signed in to change notification settings - Fork 117
Windows image attachments #1245
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
grynspan
wants to merge
30
commits into
main
Choose a base branch
from
jgrynspan/gdiplus-image-overlay
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
03d8390
[WIP] GDI+ Image overlay
grynspan a2f76fc
Merge branch 'main' into jgrynspan/gdiplus-image-overlay
bfcf2e0
More work
grynspan 3b77380
HBITMAP working now
grynspan 7737882
Documentation comments etc.
grynspan fa90923
Opt-out of calling GdiplusStartup() if needed
grynspan e02d699
Merge remote-tracking branch 'origin/main' into jgrynspan/gdiplus-ima…
grynspan 00475be
Add HICON support, describe errors
grynspan c5dc10b
Refactor around pointers
grynspan 3a420d7
Missing files
grynspan 9d860e6
Lots of documentation, rearranging of modules, and general cleanup
grynspan 2aa478c
Don't use _Pointer in the interface
grynspan af7086e
Make UnsafeMutablePointer recursively conformant to AttachableAsGDIPl…
grynspan c2e3f04
Missing a file, sigh
grynspan 2ec1708
Get type inference working
grynspan fd22406
Define an abstraction over OpaquePointer to use until Gdiplus.Image c…
grynspan 16c9e02
Stop forgetting my files!
grynspan 97c7150
Fix typo
grynspan 4750c9d
Work around SIL crash, add init(pathExtension:), fix some whitespace …
grynspan d2d1bec
Cleanup, _withGDIPlusImage -> _copyAttachableGDIPlusImage
grynspan a8f3c68
Fix typos
grynspan fb4ce8e
Simplify the GDI+ image logic by having the protocol just create them…
grynspan a9840b6
Remove some redundant logic around CLSIDs
grynspan 0a079db
Get rid of some redundant code
grynspan f2dc015
Microsoft defines DWORD as unsigned long, not unsigned int (despite t…
grynspan 241f5ba
Suppress some warnings
grynspan 031ba94
Merge branch 'main' into jgrynspan/gdiplus-image-overlay
grynspan 125989b
Oh right, that buffer is used
grynspan e175ccd
Merge remote-tracking branch 'origin' into jgrynspan/gdiplus-image-ov…
grynspan ec54a9e
Merge branch 'jgrynspan/gdiplus-image-overlay' of github.com:swiftlan…
grynspan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
129 changes: 129 additions & 0 deletions
129
Sources/Overlays/_Testing_WinSDK/Attachments/AttachableAsGDIPlusImage.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
// | ||
|
||
#if os(Windows) | ||
@_spi(Experimental) import Testing | ||
private import _TestingInternals.GDIPlus | ||
|
||
internal import WinSDK | ||
|
||
/// A protocol describing images that can be converted to instances of | ||
/// ``Testing/Attachment``. | ||
/// | ||
/// Instances of types conforming to this protocol do not themselves conform to | ||
/// ``Testing/Attachable``. Instead, the testing library provides additional | ||
/// initializers on ``Testing/Attachment`` that take instances of such types and | ||
/// handle converting them to image data when needed. | ||
/// | ||
/// The following system-provided image types conform to this protocol and can | ||
/// be attached to a test: | ||
/// | ||
/// - [`HBITMAP`](https://learn.microsoft.com/en-us/windows/win32/gdi/bitmaps) | ||
/// - [`HICON`](https://learn.microsoft.com/en-us/windows/win32/menurc/icons) | ||
/// | ||
/// You do not generally need to add your own conformances to this protocol. If | ||
/// you have an image in another format that needs to be attached to a test, | ||
/// first convert it to an instance of one of the types above. | ||
@_spi(Experimental) | ||
public protocol _AttachableByAddressAsGDIPlusImage { | ||
/// Create a GDI+ image representing an instance of this type at the given | ||
/// address. | ||
/// | ||
/// - Parameters: | ||
/// - imageAddress: The address of the instance of this type. | ||
/// | ||
/// - Returns: A pointer to a new GDI+ image representing this image. The | ||
/// caller is responsible for deleting this image when done with it. | ||
/// | ||
/// - Throws: Any error that prevented the creation of the GDI+ image. | ||
/// | ||
/// - Note: This function returns a value of C++ type `Gdiplus::Image *`. That | ||
/// type cannot be directly represented in Swift. If this function returns a | ||
/// value of any other concrete type, the result is undefined. | ||
/// | ||
/// The testing library automatically calls `GdiplusStartup()` and | ||
/// `GdiplusShutdown()` before and after calling this function. This function | ||
/// can therefore assume that GDI+ is correctly configured on the current | ||
/// thread when it is called. | ||
/// | ||
/// This function is not part of the public interface of the testing library. | ||
/// It may be removed in a future update. | ||
static func _copyAttachableGDIPlusImage(at imageAddress: UnsafeMutablePointer<Self>) throws -> OpaquePointer | ||
|
||
/// Clean up any resources at the given address. | ||
/// | ||
/// - Parameters: | ||
/// - imageAddress: The address of the instance of this type. | ||
/// | ||
/// The implementation of this function cleans up any resources (such as | ||
/// handles or COM objects) associated with this value. The testing library | ||
/// automatically invokes this function as needed. | ||
/// | ||
/// This function is not responsible for deleting the image returned from | ||
/// `_copyAttachableGDIPlusImage(at:)`. | ||
/// | ||
/// This function is not part of the public interface of the testing library. | ||
/// It may be removed in a future update. | ||
static func _cleanUpAttachment(at imageAddress: UnsafeMutablePointer<Self>) | ||
} | ||
|
||
/// A protocol describing images that can be converted to instances of | ||
/// ``Testing/Attachment``. | ||
/// | ||
/// Instances of types conforming to this protocol do not themselves conform to | ||
/// ``Testing/Attachable``. Instead, the testing library provides additional | ||
/// initializers on ``Testing/Attachment`` that take instances of such types and | ||
/// handle converting them to image data when needed. | ||
/// | ||
/// The following system-provided image types conform to this protocol and can | ||
/// be attached to a test: | ||
/// | ||
/// - [`HBITMAP`](https://learn.microsoft.com/en-us/windows/win32/gdi/bitmaps) | ||
/// - [`HICON`](https://learn.microsoft.com/en-us/windows/win32/menurc/icons) | ||
/// | ||
/// You do not generally need to add your own conformances to this protocol. If | ||
/// you have an image in another format that needs to be attached to a test, | ||
/// first convert it to an instance of one of the types above. | ||
@_spi(Experimental) | ||
public protocol AttachableAsGDIPlusImage { | ||
/// Create a GDI+ image representing this instance. | ||
/// | ||
/// - Returns: A pointer to a new GDI+ image representing this image. The | ||
/// caller is responsible for deleting this image when done with it. | ||
/// | ||
/// - Throws: Any error that prevented the creation of the GDI+ image. | ||
/// | ||
/// - Note: This function returns a value of C++ type `Gdiplus::Image *`. That | ||
/// type cannot be directly represented in Swift. If this function returns a | ||
/// value of any other concrete type, the result is undefined. | ||
/// | ||
/// The testing library automatically calls `GdiplusStartup()` and | ||
/// `GdiplusShutdown()` before and after calling this function. This function | ||
/// can therefore assume that GDI+ is correctly configured on the current | ||
/// thread when it is called. | ||
/// | ||
/// This function is not part of the public interface of the testing library. | ||
/// It may be removed in a future update. | ||
func _copyAttachableGDIPlusImage() throws -> OpaquePointer | ||
|
||
/// Clean up any resources associated with this instance. | ||
/// | ||
/// The implementation of this function cleans up any resources (such as | ||
/// handles or COM objects) associated with this value. The testing library | ||
/// automatically invokes this function as needed. | ||
/// | ||
/// This function is not responsible for deleting the image returned from | ||
/// `_copyAttachableGDIPlusImage()`. | ||
/// | ||
/// This function is not part of the public interface of the testing library. | ||
/// It may be removed in a future update. | ||
func _cleanUpAttachment() | ||
} | ||
#endif |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.