-
Notifications
You must be signed in to change notification settings - Fork 58
Update PlatformDrawable API #673
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
Changes from all commits
e908143
d9da712
58ed491
662b5fd
7685c81
f2f84d3
3cd6e73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| // | ||
| // PlatformViewDefinition.swift | ||
| // DisplayListViewPlatform.swift | ||
| // OpenSwiftUICore | ||
| // | ||
| // Audited for 6.0.87 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| // | ||
| // PlatformDrawable.swift | ||
| // OpenSwiftUICore | ||
| // | ||
| // Audited for 6.5.4 | ||
| // Status: WIP | ||
|
|
||
| import OpenAttributeGraphShims | ||
| import OpenRenderBoxShims | ||
| public import OpenCoreGraphicsShims | ||
| #if canImport(QuarzCore) | ||
| public import QuartzCore | ||
| import CoreAnimation_Private | ||
| #endif | ||
|
|
||
| // MARK: - PlatformDrawable | ||
|
|
||
| @_spi(DisplayList_ViewSystem) | ||
| @available(OpenSwiftUI_v6_0, *) | ||
| public protocol PlatformDrawable: AnyObject { | ||
| var options: PlatformDrawableOptions { get set } | ||
|
|
||
| static var allowsContentsMultiplyColor: Bool { get } | ||
|
|
||
| func update(content: PlatformDrawableContent?, required: Bool) -> Bool | ||
|
|
||
| #if canImport(QuarzCore) | ||
| func makeAsyncUpdate( | ||
| content: PlatformDrawableContent, | ||
| required: Bool, | ||
| layer: CALayer, | ||
| bounds: CGRect | ||
| ) -> (() -> Void)? | ||
| #endif | ||
|
|
||
| func setContentsScale(_ scale: CGFloat) | ||
|
|
||
| func drawForTesting(in: RBDisplayList) -> () | ||
| } | ||
|
|
||
| // MARK: - PlatformDrawableContent [WIP] | ||
|
|
||
| @_spi(DisplayList_ViewSystem) | ||
| @available(OpenSwiftUI_v6_0, *) | ||
| public struct PlatformDrawableContent: @unchecked Sendable { | ||
| enum Storage { | ||
| case graphicsCallback((inout GraphicsContext, CGSize) -> ()) | ||
| case platformCallback((CGSize) -> ()) | ||
| case displayList(DisplayList, CGPoint, Time) | ||
| case rbDisplayList(RBDisplayListContents, CGPoint) | ||
| case rbInterpolator(RBDisplayListInterpolator, Float, CGPoint) | ||
| case empty | ||
| } | ||
|
|
||
| private var storage: Storage = .empty | ||
|
|
||
| public struct State { | ||
| package var mode: DisplayList.GraphicsRenderer.PlatformViewMode | ||
|
|
||
| package var _renderer: DisplayList.GraphicsRenderer? | ||
|
|
||
| package init() { | ||
| mode = .unsupported | ||
| _renderer = nil | ||
| } | ||
|
|
||
| package init(platformViewMode: DisplayList.GraphicsRenderer.PlatformViewMode) { | ||
| mode = platformViewMode | ||
| _renderer = nil | ||
| } | ||
|
|
||
| package mutating func renderer() -> DisplayList.GraphicsRenderer { | ||
| guard let _renderer else { | ||
| let render = DisplayList.GraphicsRenderer(platformViewMode: mode) | ||
| _renderer = render | ||
| return render | ||
| } | ||
| return _renderer | ||
| } | ||
| } | ||
|
|
||
| public init() { | ||
| _openSwiftUIEmptyStub() | ||
| } | ||
|
|
||
| #if canImport(CoreGraphics) | ||
| public func draw( | ||
| in ctx: CGContext, | ||
| size: CGSize, | ||
| contentsScale: CGFloat, | ||
| state: inout PlatformDrawableContent.State | ||
| ) { | ||
| _openSwiftUIUnimplementedFailure() | ||
| } | ||
| #endif | ||
|
|
||
| public func draw( | ||
| in list: RBDisplayList, | ||
| size: CGSize, | ||
| state: inout PlatformDrawableContent.State | ||
| ) { | ||
| _openSwiftUIUnimplementedFailure() | ||
| } | ||
| } | ||
|
|
||
| @_spi(DisplayList_ViewSystem) | ||
| @available(*, unavailable) | ||
| extension PlatformDrawableContent.State: Sendable {} | ||
|
|
||
| // MARK: - PlatformDrawableOptions [Blocked by RBLayer] | ||
|
|
||
| @_spi(DisplayList_ViewSystem) | ||
| @available(OpenSwiftUI_v6_0, *) | ||
| public struct PlatformDrawableOptions: Equatable, Sendable { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🤖 Was this useful? React with 👍 or 👎 |
||
| var base: RasterizationOptions | ||
|
|
||
| public var isAccelerated: Bool { | ||
| base.isAccelerated | ||
| } | ||
|
|
||
| public var isOpaque: Bool { | ||
| base.isOpaque | ||
| } | ||
|
|
||
| public var rendersAsynchronously: Bool { | ||
| base.rendersAsynchronously | ||
| } | ||
|
|
||
| public var rendersFirstFrameAsynchronously: Bool { | ||
| base.rendersFirstFrameAsynchronously | ||
| } | ||
|
|
||
| #if canImport(QuarzCore) | ||
| public var caLayerContentsFormat: CALayerContentsFormat { | ||
| var format = CALayerContentsFormat.automatic | ||
| if base.flags.contains(.rgbaContext) { | ||
| format = .RGBA8Uint | ||
| } | ||
| if base.flags.contains(.alphaOnly) { | ||
| format = .A8 | ||
| } | ||
| return format | ||
| } | ||
| #endif | ||
|
|
||
| public func update(rbLayer: AnyObject) { | ||
| // TODO: RBLayer | ||
| _openSwiftUIUnimplementedFailure() | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PlatformDrawableContent.Stateispublicbut its initializers arepackage, andPlatformDrawableContent.draw(...)requires an inoutState; SPI clients outside this package may have no way to create/retain aState. Ifdrawis intended for externalPlatformDrawableimplementers, it likely needs a constructible state type.🤖 Was this useful? React with 👍 or 👎