Skip to content

Commit 027c339

Browse files
authored
Update PlatformDrawable API (#673)
1 parent 5534e8a commit 027c339

File tree

8 files changed

+393
-66
lines changed

8 files changed

+393
-66
lines changed

Sources/OpenSwiftUICore/Graphic/Color/ColorRenderingMode.swift

Lines changed: 0 additions & 55 deletions
This file was deleted.

Sources/OpenSwiftUICore/Render/DisplayList/DisplayList.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,3 @@ extension GraphicsImage: ProtobufMessage {
528528
}
529529
}
530530
package struct ResolvedShadowStyle {}
531-
532-
package struct RasterizationOptions {}
533-
package protocol RBDisplayListContents {} // RenderBox.RBDisplayListContents
534-
public struct PlatformDrawableOptions {}
535-
public protocol PlatformDrawable : AnyObject {}

Sources/OpenSwiftUICore/Render/DisplayList/DisplayListViewPlatform.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// PlatformViewDefinition.swift
2+
// DisplayListViewPlatform.swift
33
// OpenSwiftUICore
44
//
55
// Audited for 6.0.87
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
//
2+
// PlatformDrawable.swift
3+
// OpenSwiftUICore
4+
//
5+
// Audited for 6.5.4
6+
// Status: WIP
7+
8+
import OpenAttributeGraphShims
9+
import OpenRenderBoxShims
10+
public import OpenCoreGraphicsShims
11+
#if canImport(QuarzCore)
12+
public import QuartzCore
13+
import CoreAnimation_Private
14+
#endif
15+
16+
// MARK: - PlatformDrawable
17+
18+
@_spi(DisplayList_ViewSystem)
19+
@available(OpenSwiftUI_v6_0, *)
20+
public protocol PlatformDrawable: AnyObject {
21+
var options: PlatformDrawableOptions { get set }
22+
23+
static var allowsContentsMultiplyColor: Bool { get }
24+
25+
func update(content: PlatformDrawableContent?, required: Bool) -> Bool
26+
27+
#if canImport(QuarzCore)
28+
func makeAsyncUpdate(
29+
content: PlatformDrawableContent,
30+
required: Bool,
31+
layer: CALayer,
32+
bounds: CGRect
33+
) -> (() -> Void)?
34+
#endif
35+
36+
func setContentsScale(_ scale: CGFloat)
37+
38+
func drawForTesting(in: RBDisplayList) -> ()
39+
}
40+
41+
// MARK: - PlatformDrawableContent [WIP]
42+
43+
@_spi(DisplayList_ViewSystem)
44+
@available(OpenSwiftUI_v6_0, *)
45+
public struct PlatformDrawableContent: @unchecked Sendable {
46+
enum Storage {
47+
case graphicsCallback((inout GraphicsContext, CGSize) -> ())
48+
case platformCallback((CGSize) -> ())
49+
case displayList(DisplayList, CGPoint, Time)
50+
case rbDisplayList(RBDisplayListContents, CGPoint)
51+
case rbInterpolator(RBDisplayListInterpolator, Float, CGPoint)
52+
case empty
53+
}
54+
55+
private var storage: Storage = .empty
56+
57+
public struct State {
58+
package var mode: DisplayList.GraphicsRenderer.PlatformViewMode
59+
60+
package var _renderer: DisplayList.GraphicsRenderer?
61+
62+
package init() {
63+
mode = .unsupported
64+
_renderer = nil
65+
}
66+
67+
package init(platformViewMode: DisplayList.GraphicsRenderer.PlatformViewMode) {
68+
mode = platformViewMode
69+
_renderer = nil
70+
}
71+
72+
package mutating func renderer() -> DisplayList.GraphicsRenderer {
73+
guard let _renderer else {
74+
let render = DisplayList.GraphicsRenderer(platformViewMode: mode)
75+
_renderer = render
76+
return render
77+
}
78+
return _renderer
79+
}
80+
}
81+
82+
public init() {
83+
_openSwiftUIEmptyStub()
84+
}
85+
86+
#if canImport(CoreGraphics)
87+
public func draw(
88+
in ctx: CGContext,
89+
size: CGSize,
90+
contentsScale: CGFloat,
91+
state: inout PlatformDrawableContent.State
92+
) {
93+
_openSwiftUIUnimplementedFailure()
94+
}
95+
#endif
96+
97+
public func draw(
98+
in list: RBDisplayList,
99+
size: CGSize,
100+
state: inout PlatformDrawableContent.State
101+
) {
102+
_openSwiftUIUnimplementedFailure()
103+
}
104+
}
105+
106+
@_spi(DisplayList_ViewSystem)
107+
@available(*, unavailable)
108+
extension PlatformDrawableContent.State: Sendable {}
109+
110+
// MARK: - PlatformDrawableOptions [Blocked by RBLayer]
111+
112+
@_spi(DisplayList_ViewSystem)
113+
@available(OpenSwiftUI_v6_0, *)
114+
public struct PlatformDrawableOptions: Equatable, Sendable {
115+
var base: RasterizationOptions
116+
117+
public var isAccelerated: Bool {
118+
base.isAccelerated
119+
}
120+
121+
public var isOpaque: Bool {
122+
base.isOpaque
123+
}
124+
125+
public var rendersAsynchronously: Bool {
126+
base.rendersAsynchronously
127+
}
128+
129+
public var rendersFirstFrameAsynchronously: Bool {
130+
base.rendersFirstFrameAsynchronously
131+
}
132+
133+
#if canImport(QuarzCore)
134+
public var caLayerContentsFormat: CALayerContentsFormat {
135+
var format = CALayerContentsFormat.automatic
136+
if base.flags.contains(.rgbaContext) {
137+
format = .RGBA8Uint
138+
}
139+
if base.flags.contains(.alphaOnly) {
140+
format = .A8
141+
}
142+
return format
143+
}
144+
#endif
145+
146+
public func update(rbLayer: AnyObject) {
147+
// TODO: RBLayer
148+
_openSwiftUIUnimplementedFailure()
149+
}
150+
}

0 commit comments

Comments
 (0)