Adopted Span and MutableSpan for buffers across the library to adapt to Swift 6.4.
This commit is contained in:
@@ -279,15 +279,25 @@ extension Graphics {
|
||||
|
||||
// MARK: - Framebuffer
|
||||
|
||||
/// The current working framebuffer. Rows are `rowSize` bytes.
|
||||
/// Calls `body` with the current working framebuffer: `rows` rows of
|
||||
/// `rowSize` bytes each. Returns `nil` if there is no framebuffer.
|
||||
/// Call `markUpdatedRows(from:to:)` after writing directly.
|
||||
public static var frame: UnsafeMutablePointer<UInt8>? {
|
||||
gfx.pointee.getFrame.unsafelyUnwrapped()
|
||||
public static func withFrame<Result, Failure: Error>(
|
||||
_ body: (inout MutableSpan<UInt8>) throws(Failure) -> Result
|
||||
) throws(Failure) -> Result? {
|
||||
guard let frame = gfx.pointee.getFrame.unsafelyUnwrapped() else { return nil }
|
||||
var span = UnsafeMutableBufferPointer(start: frame, count: rows * rowSize).mutableSpan
|
||||
return try body(&span)
|
||||
}
|
||||
|
||||
/// The framebuffer currently shown on the display. Rows are `rowSize` bytes.
|
||||
public static var displayFrame: UnsafeMutablePointer<UInt8>? {
|
||||
gfx.pointee.getDisplayFrame.unsafelyUnwrapped()
|
||||
/// Calls `body` with the framebuffer currently shown on the display:
|
||||
/// `rows` rows of `rowSize` bytes each. Returns `nil` if there is no
|
||||
/// framebuffer.
|
||||
public static func withDisplayFrame<Result, Failure: Error>(
|
||||
_ body: (Span<UInt8>) throws(Failure) -> Result
|
||||
) throws(Failure) -> Result? {
|
||||
guard let frame = gfx.pointee.getDisplayFrame.unsafelyUnwrapped() else { return nil }
|
||||
return try body(UnsafeBufferPointer(start: frame, count: rows * rowSize).span)
|
||||
}
|
||||
|
||||
/// A bitmap view of the display framebuffer. Simulator only; `nil` on device.
|
||||
|
||||
Reference in New Issue
Block a user