Skip to content

Commit 08f39d6

Browse files
authored
Promote Windows image attachments to API. (#1333)
Remove `@_spi` and adjust documentation as needed now that [ST-0015](https://forums.swift.org/t/st-0015-image-attachments-in-swift-testing-windows/82241) has been approved. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent d276e45 commit 08f39d6

16 files changed

+51
-45
lines changed

Sources/Overlays/_Testing_CoreGraphics/Attachments/AttachableAsCGImage.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ private import ImageIO
2727
/// |-|-|
2828
/// | macOS | [`CGImage`](https://developer.apple.com/documentation/coregraphics/cgimage), [`CIImage`](https://developer.apple.com/documentation/coreimage/ciimage), [`NSImage`](https://developer.apple.com/documentation/appkit/nsimage) |
2929
/// | iOS, watchOS, tvOS, and visionOS | [`CGImage`](https://developer.apple.com/documentation/coregraphics/cgimage), [`CIImage`](https://developer.apple.com/documentation/coreimage/ciimage), [`UIImage`](https://developer.apple.com/documentation/uikit/uiimage) |
30-
/// @Comment {
3130
/// | Windows | [`HBITMAP`](https://learn.microsoft.com/en-us/windows/win32/gdi/bitmaps), [`HICON`](https://learn.microsoft.com/en-us/windows/win32/menurc/icons), [`IWICBitmapSource`](https://learn.microsoft.com/en-us/windows/win32/api/wincodec/nn-wincodec-iwicbitmapsource) (including its subclasses declared by Windows Imaging Component) |
32-
/// }
3331
///
3432
/// You do not generally need to add your own conformances to this protocol. If
3533
/// you have an image in another format that needs to be attached to a test,

Sources/Overlays/_Testing_CoreGraphics/Attachments/AttachableImageFormat+UTType.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,7 @@ extension AttachableImageFormat {
107107
)
108108
self.init(kind: .systemValue(contentType), encodingQuality: encodingQuality)
109109
}
110-
}
111110

112-
@available(_uttypesAPI, *)
113-
@_spi(Experimental) // STOP: not part of ST-0014
114-
extension AttachableImageFormat {
115111
/// Construct an instance of this type with the given path extension and
116112
/// encoding quality.
117113
///
@@ -132,6 +128,10 @@ extension AttachableImageFormat {
132128
/// must conform to [`UTType.image`](https://developer.apple.com/documentation/uniformtypeidentifiers/uttype-swift.struct/image).
133129
/// - On Windows, there must be a corresponding subclass of [`IWICBitmapEncoder`](https://learn.microsoft.com/en-us/windows/win32/api/wincodec/nn-wincodec-iwicbitmapencoder)
134130
/// registered with Windows Imaging Component.
131+
///
132+
/// @Metadata {
133+
/// @Available(Swift, introduced: 6.3)
134+
/// }
135135
public init?(pathExtension: String, encodingQuality: Float = 1.0) {
136136
let pathExtension = pathExtension.drop { $0 == "." }
137137

Sources/Overlays/_Testing_WinSDK/Attachments/AttachableAsIWICBitmapSource.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public import WinSDK
3232
/// You do not generally need to add your own conformances to this protocol. If
3333
/// you have an image in another format that needs to be attached to a test,
3434
/// first convert it to an instance of one of the types above.
35-
@_spi(Experimental)
3635
public protocol _AttachableByAddressAsIWICBitmapSource {
3736
/// Create a WIC bitmap source representing an instance of this type at the
3837
/// given address.
@@ -112,14 +111,21 @@ public protocol _AttachableByAddressAsIWICBitmapSource {
112111
/// You do not generally need to add your own conformances to this protocol. If
113112
/// you have an image in another format that needs to be attached to a test,
114113
/// first convert it to an instance of one of the types above.
115-
@_spi(Experimental)
114+
///
115+
/// @Metadata {
116+
/// @Available(Swift, introduced: 6.3)
117+
/// }
116118
public protocol AttachableAsIWICBitmapSource: _AttachableAsImage, SendableMetatype {
117119
/// Create a WIC bitmap source representing an instance of this type.
118120
///
119121
/// - Returns: A pointer to a new WIC bitmap source representing this image.
120122
/// The caller is responsible for releasing this image when done with it.
121123
///
122124
/// - Throws: Any error that prevented the creation of the WIC bitmap source.
125+
///
126+
/// @Metadata {
127+
/// @Available(Swift, introduced: 6.3)
128+
/// }
123129
func copyAttachableIWICBitmapSource() throws -> UnsafeMutablePointer<IWICBitmapSource>
124130

125131
/// Create a WIC bitmap representing an instance of this type.

Sources/Overlays/_Testing_WinSDK/Attachments/AttachableImageFormat+CLSID.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
//
1010

1111
#if os(Windows)
12-
@_spi(Experimental) public import Testing
12+
public import Testing
1313
public import WinSDK
1414

15-
@_spi(Experimental)
1615
extension AttachableImageFormat {
1716
private static let _encoderPathExtensionsByCLSID = Result<[UInt128: [String]], any Error> {
1817
var result = [UInt128: [String]]()
@@ -235,6 +234,13 @@ extension AttachableImageFormat {
235234
///
236235
/// For example, if this image format equals ``png``, the value of this
237236
/// property equals [`CLSID_WICPngEncoder`](https://learn.microsoft.com/en-us/windows/win32/wic/-wic-guids-clsids#wic-guids-and-clsids).
237+
///
238+
/// @Metadata {
239+
/// @Available(Swift, introduced: 6.3)
240+
/// }
241+
#if compiler(>=6.3) && !SWT_FIXED_84466
242+
@_spi(_)
243+
#endif
238244
public var encoderCLSID: CLSID {
239245
switch kind {
240246
case .png:
@@ -263,6 +269,13 @@ extension AttachableImageFormat {
263269
/// result is undefined. For a list of image encoder classes supported by WIC,
264270
/// see the documentation for the [`IWICBitmapEncoder`](https://learn.microsoft.com/en-us/windows/win32/api/wincodec/nn-wincodec-iwicbitmapencoder)
265271
/// class.
272+
///
273+
/// @Metadata {
274+
/// @Available(Swift, introduced: 6.3)
275+
/// }
276+
#if compiler(>=6.3) && !SWT_FIXED_84466
277+
@_spi(_)
278+
#endif
266279
public init(encoderCLSID: CLSID, encodingQuality: Float = 1.0) {
267280
if encoderCLSID == CLSID_WICPngEncoder {
268281
self = .png
@@ -293,6 +306,10 @@ extension AttachableImageFormat {
293306
/// must conform to [`UTType.image`](https://developer.apple.com/documentation/uniformtypeidentifiers/uttype-swift.struct/image).
294307
/// - On Windows, there must be a corresponding subclass of [`IWICBitmapEncoder`](https://learn.microsoft.com/en-us/windows/win32/api/wincodec/nn-wincodec-iwicbitmapencoder)
295308
/// registered with Windows Imaging Component.
309+
///
310+
/// @Metadata {
311+
/// @Available(Swift, introduced: 6.3)
312+
/// }
296313
public init?(pathExtension: String, encodingQuality: Float = 1.0) {
297314
let pathExtension = pathExtension.drop { $0 == "." }
298315

Sources/Overlays/_Testing_WinSDK/Attachments/HBITMAP+AttachableAsIWICBitmapSource.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
private import Testing
1313
public import WinSDK
1414

15-
@_spi(Experimental)
1615
extension HBITMAP__: _AttachableByAddressAsIWICBitmapSource {
1716
public static func _copyAttachableIWICBitmapSource(
1817
from imageAddress: UnsafeMutablePointer<Self>,

Sources/Overlays/_Testing_WinSDK/Attachments/HICON+AttachableAsIWICBitmapSource.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
private import Testing
1313
public import WinSDK
1414

15-
@_spi(Experimental)
1615
extension HICON__: _AttachableByAddressAsIWICBitmapSource {
1716
public static func _copyAttachableIWICBitmapSource(
1817
from imageAddress: UnsafeMutablePointer<Self>,

Sources/Overlays/_Testing_WinSDK/Attachments/IWICBitmapSource+AttachableAsIWICBitmapSource.swift

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,14 @@ public import WinSDK
3434
/// allows us to reuse code across all subclasses of `IWICBitmapSource`.
3535
protocol IWICBitmapSourceProtocol: _AttachableByAddressAsIWICBitmapSource {}
3636

37-
@_spi(Experimental)
3837
extension IWICBitmapSource: _AttachableByAddressAsIWICBitmapSource, IWICBitmapSourceProtocol {}
39-
40-
@_spi(Experimental)
4138
extension IWICBitmap: _AttachableByAddressAsIWICBitmapSource, IWICBitmapSourceProtocol {}
42-
43-
@_spi(Experimental)
4439
extension IWICBitmapClipper: _AttachableByAddressAsIWICBitmapSource, IWICBitmapSourceProtocol {}
45-
46-
@_spi(Experimental)
4740
extension IWICBitmapFlipRotator: _AttachableByAddressAsIWICBitmapSource, IWICBitmapSourceProtocol {}
48-
49-
@_spi(Experimental)
5041
extension IWICBitmapFrameDecode: _AttachableByAddressAsIWICBitmapSource, IWICBitmapSourceProtocol {}
51-
52-
@_spi(Experimental)
5342
extension IWICBitmapScaler: _AttachableByAddressAsIWICBitmapSource, IWICBitmapSourceProtocol {}
54-
55-
@_spi(Experimental)
5643
extension IWICColorTransform: _AttachableByAddressAsIWICBitmapSource, IWICBitmapSourceProtocol {}
57-
58-
@_spi(Experimental)
5944
extension IWICFormatConverter: _AttachableByAddressAsIWICBitmapSource, IWICBitmapSourceProtocol {}
60-
61-
@_spi(Experimental)
6245
extension IWICPlanarFormatConverter: _AttachableByAddressAsIWICBitmapSource, IWICBitmapSourceProtocol {}
6346

6447
// MARK: - Upcasting conveniences
@@ -96,7 +79,6 @@ extension UnsafeMutablePointer where Pointee: IWICBitmapSourceProtocol {
9679

9780
// MARK: - _AttachableByAddressAsIWICBitmapSource implementation
9881

99-
@_spi(Experimental)
10082
extension IWICBitmapSourceProtocol {
10183
public static func _copyAttachableIWICBitmapSource(
10284
from imageAddress: UnsafeMutablePointer<Self>,
@@ -120,7 +102,6 @@ extension IWICBitmapSourceProtocol {
120102
}
121103

122104
extension IWICBitmapSource {
123-
@_spi(Experimental)
124105
public static func _copyAttachableIWICBitmapSource(
125106
from imageAddress: UnsafeMutablePointer<Self>,
126107
using factory: UnsafeMutablePointer<IWICImagingFactory>

Sources/Overlays/_Testing_WinSDK/Attachments/UnsafeMutablePointer+AttachableAsIWICBitmapSource.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212
private import Testing
1313
public import WinSDK
1414

15-
@_spi(Experimental)
15+
/// @Metadata {
16+
/// @Available(Swift, introduced: 6.3)
17+
/// }
1618
extension UnsafeMutablePointer: _AttachableAsImage, AttachableAsIWICBitmapSource where Pointee: _AttachableByAddressAsIWICBitmapSource {
19+
/// @Metadata {
20+
/// @Available(Swift, introduced: 6.3)
21+
/// }
1722
public func copyAttachableIWICBitmapSource() throws -> UnsafeMutablePointer<IWICBitmapSource> {
1823
let factory = try IWICImagingFactory.create()
1924
defer {

Sources/Overlays/_Testing_WinSDK/Attachments/_AttachableImageWrapper+AttachableWrapper.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
//
1010

1111
#if os(Windows)
12-
@_spi(Experimental) public import Testing
12+
public import Testing
1313
private import WinSDK
1414

15-
@_spi(Experimental)
1615
extension _AttachableImageWrapper: Attachable, AttachableWrapper where Image: AttachableAsIWICBitmapSource {
1716
public func withUnsafeBytes<R>(for attachment: borrowing Attachment<_AttachableImageWrapper>, _ body: (UnsafeRawBufferPointer) throws -> R) throws -> R {
1817
// Create an in-memory stream to write the image data to. Note that Windows

Sources/Overlays/_Testing_WinSDK/ReexportTesting.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
@_exported @_spi(Experimental) @_spi(ForToolsIntegrationOnly) public import Testing
11+
@_exported public import Testing

0 commit comments

Comments
 (0)