|
1 |
| -// FIXME |
2 |
| -struct DisplayList {} |
| 1 | +// |
| 2 | +// DisplayList.swift |
| 3 | +// OpenSwiftUICore |
| 4 | +// |
| 5 | +// Audited for RELEASE_2024 |
| 6 | +// Status: WIP |
| 7 | +// ID: F37E3733E490AA5E3BDC045E3D34D9F8 |
| 8 | + |
| 9 | + |
| 10 | +// MARK: - _DisplayList_Identity |
| 11 | + |
| 12 | +private var lastIdentity: UInt32 = 0 |
| 13 | + |
| 14 | +package struct _DisplayList_Identity: Hashable, Codable, CustomStringConvertible { |
| 15 | + package private(set) var value: UInt32 |
| 16 | + |
| 17 | + init(value: UInt32) { |
| 18 | + self.value = value |
| 19 | + } |
| 20 | + |
| 21 | + package init() { |
| 22 | + lastIdentity += 1 |
| 23 | + self.init(value: lastIdentity) |
| 24 | + } |
| 25 | + |
| 26 | + package init(decodedValue value: UInt32) { |
| 27 | + self.init(value: value) |
| 28 | + } |
| 29 | + |
| 30 | + package static let none = _DisplayList_Identity(value: 0) |
| 31 | + package var description: String { "#\(value)" } |
| 32 | +} |
| 33 | + |
| 34 | +// MARK: - DisplayList |
| 35 | + |
| 36 | +package struct DisplayList: Equatable { |
| 37 | + package private(set) var items: [Item] |
| 38 | + |
| 39 | + package struct Features: OptionSet { |
| 40 | + package let rawValue: UInt16 |
| 41 | + package init(rawValue: UInt16) { |
| 42 | + self.rawValue = rawValue |
| 43 | + } |
| 44 | + package static let required = Features(rawValue: 1 << 0) |
| 45 | + package static let views = Features(rawValue: 1 << 1) |
| 46 | + package static let animations = Features(rawValue: 1 << 2) |
| 47 | + package static let dynamicContent = Features(rawValue: 1 << 3) |
| 48 | + package static let interpolatorLayers = Features(rawValue: 1 << 4) |
| 49 | + package static let interpolatorRoots = Features(rawValue: 1 << 5) |
| 50 | + package static let stateEffects = Features(rawValue: 1 << 6) |
| 51 | + package static let states = Features(rawValue: 1 << 7) |
| 52 | + package static let flattened = Features(rawValue: 1 << 9) |
| 53 | + } |
| 54 | + |
| 55 | + package private(set) var features: Features |
| 56 | + package private(set) var properties: Properties |
| 57 | + |
| 58 | + package init() { |
| 59 | + items = [] |
| 60 | + features = [] |
| 61 | + properties = [] |
| 62 | + } |
| 63 | + |
| 64 | + package init(_ item: Item) { |
| 65 | + fatalError("TODO") |
| 66 | + } |
| 67 | + |
| 68 | + package init(_ items: [Item]) { |
| 69 | + fatalError("TODO") |
| 70 | + } |
| 71 | + |
| 72 | + package mutating func append(_ item: Item) { |
| 73 | + } |
| 74 | + |
| 75 | + package mutating func append(contentsOf other: DisplayList) { |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | + // TODO |
| 80 | +} |
| 81 | + |
| 82 | +@available(*, unavailable) |
| 83 | +extension DisplayList: Sendable {} |
| 84 | + |
| 85 | +@available(*, unavailable) |
| 86 | +extension DisplayList.Version: Sendable {} |
3 | 87 |
|
4 |
| -// FIXME |
5 | 88 | extension DisplayList {
|
6 |
| - struct Key: PreferenceKey { |
7 |
| - static var defaultValue: Void = () |
| 89 | +// package typealias Identity = _DisplayList_Identity |
| 90 | +// package typealias StableIdentity = _DisplayList_StableIdentity |
| 91 | +// package typealias StableIdentityMap = _DisplayList_StableIdentityMap |
| 92 | +// package typealias StableIdentityRoot = _DisplayList_StableIdentityRoot |
| 93 | +// package typealias StableIdentityScope = _DisplayList_StableIdentityScope |
| 94 | + package struct Item : Equatable { |
| 95 | +// package var frame: CGRect |
| 96 | +// package var version: Version |
| 97 | +// package var value: Item.Value |
| 98 | +// package var identity: Identity |
| 99 | +// package enum Value { |
| 100 | +// case empty |
| 101 | +// case content(Content) |
| 102 | +// case effect(Effect, DisplayList) |
| 103 | +// case states([(StrongHash, DisplayList)]) |
| 104 | +// } |
| 105 | +// package init(_ value: Item.Value, frame: CGRect, identity: Identity, version: Version) |
| 106 | +// package static func == (lhs: Item, rhs: Item) -> Bool |
| 107 | +// package var position: CGPoint { |
| 108 | +// get |
| 109 | +// } |
| 110 | +// package var size: CGSize { |
| 111 | +// get |
| 112 | +// } |
| 113 | + } |
| 114 | +// package struct Content { |
| 115 | +// package var value: Content.Value |
| 116 | +// package var seed: Seed |
| 117 | +// package enum Value { |
| 118 | +// indirect case backdrop(BackdropEffect) |
| 119 | +// indirect case color(Color.Resolved) |
| 120 | +// indirect case chameleonColor(fallback: Color.Resolved, filters: [GraphicsFilter]) |
| 121 | +// indirect case image(GraphicsImage) |
| 122 | +// indirect case shape(Path, AnyResolvedPaint, FillStyle) |
| 123 | +// indirect case shadow(Path, ResolvedShadowStyle) |
| 124 | +// indirect case platformView(any PlatformViewFactory) |
| 125 | +// indirect case platformLayer(any PlatformLayerFactory) |
| 126 | +// indirect case text(StyledTextContentView, CGSize) |
| 127 | +// indirect case flattened(DisplayList, CGPoint, RasterizationOptions) |
| 128 | +// indirect case drawing(any RenderBox.RBDisplayListContents, CGPoint, RasterizationOptions) |
| 129 | +// indirect case view(any _DisplayList_ViewFactory) |
| 130 | +// case placeholder(id: Identity) |
| 131 | +// } |
| 132 | +// package init(_ value: Content.Value, seed: Seed) |
| 133 | +// } |
| 134 | +// package typealias ViewFactory = _DisplayList_ViewFactory |
| 135 | +// package enum Effect { |
| 136 | +// case identity |
| 137 | +// case geometryGroup |
| 138 | +// case compositingGroup |
| 139 | +// case backdropGroup(Bool) |
| 140 | +// indirect case archive(ArchiveIDs?) |
| 141 | +// case properties(Properties) |
| 142 | +// indirect case platformGroup(any PlatformGroupFactory) |
| 143 | +// case opacity(Float) |
| 144 | +// case blendMode(GraphicsBlendMode) |
| 145 | +// indirect case clip(Path, FillStyle, _: GraphicsContext.ClipOptions = .init()) |
| 146 | +// indirect case mask(DisplayList, _: GraphicsContext.ClipOptions = .init()) |
| 147 | +// indirect case transform(Transform) |
| 148 | +// indirect case filter(GraphicsFilter) |
| 149 | +// indirect case animation(any _DisplayList_AnyEffectAnimation) |
| 150 | +// indirect case contentTransition(ContentTransition.State) |
| 151 | +// indirect case view(any _DisplayList_ViewFactory) |
| 152 | +// indirect case accessibility([AccessibilityNodeAttachment]) |
| 153 | +// indirect case platform(PlatformEffect) |
| 154 | +// indirect case state(StrongHash) |
| 155 | +// indirect case interpolatorRoot(InterpolatorGroup, contentOrigin: CGPoint, contentOffset: CGSize) |
| 156 | +// case interpolatorLayer(InterpolatorGroup, serial: UInt32) |
| 157 | +// indirect case interpolatorAnimation(InterpolatorAnimation) |
| 158 | +// } |
| 159 | +// package enum Transform { |
| 160 | +// case affine(CGAffineTransform) |
| 161 | +// case projection(ProjectionTransform) |
| 162 | +// case rotation(_RotationEffect.Data) |
| 163 | +// case rotation3D(_Rotation3DEffect.Data) |
| 164 | +// } |
| 165 | +// package typealias AnyEffectAnimation = _DisplayList_AnyEffectAnimation |
| 166 | +// package typealias AnyEffectAnimator = _DisplayList_AnyEffectAnimator |
| 167 | +// package struct ArchiveIDs { |
| 168 | +// package var uuid: Foundation.UUID |
| 169 | +// package var stableIDs: StableIdentityMap |
| 170 | +// package init(uuid: Foundation.UUID, stableIDs: StableIdentityMap) |
| 171 | +// } |
| 172 | +// package struct InterpolatorAnimation { |
| 173 | +// package var value: StrongHash? |
| 174 | +// package var animation: Animation? |
| 175 | +// } |
| 176 | + package struct Version: Comparable, Hashable { |
| 177 | + package private(set) var value: Int |
8 | 178 |
|
9 |
| - static func reduce(value _: inout Void, nextValue _: () -> Void) {} |
| 179 | + package init() { value = .zero } |
| 180 | + package init(decodedValue value: Int) { self.value = value } |
| 181 | + |
| 182 | + private static var lastValue: Int = .zero |
| 183 | + |
| 184 | + package init(forUpdate: Void) { |
| 185 | + Version.lastValue &+= 1 |
| 186 | + value = Version.lastValue |
| 187 | + } |
| 188 | + |
| 189 | + package mutating func combine(with other: Version) { |
| 190 | + value = max(value, other.value) |
| 191 | + } |
10 | 192 |
|
11 |
| - typealias Value = Void |
| 193 | + package static func < (lhs: Version, rhs: Version) -> Bool { |
| 194 | + lhs.value < rhs.value |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + package struct Seed: Hashable { |
| 199 | + package private(set) var value: UInt16 |
| 200 | + |
| 201 | + init(value: UInt16) { |
| 202 | + self.value = value |
| 203 | + } |
| 204 | + |
| 205 | + package init() { self.init(value: .zero) } |
| 206 | + package init(decodedValue value: UInt16) { self.init(value: value) } |
| 207 | + package init(_ version: Version) { |
| 208 | + if version.value == .zero { |
| 209 | + self.init(value: .zero) |
| 210 | + } else { |
| 211 | + var rawValue = UInt32(bitPattern: Int32(truncatingIfNeeded: version.value >> 16)) |
| 212 | + rawValue += (rawValue << 5) |
| 213 | + rawValue ^= UInt32(bitPattern: Int32(truncatingIfNeeded: version.value)) |
| 214 | + rawValue = 1 | (rawValue << 1) |
| 215 | + self.init(value: UInt16(truncatingIfNeeded: rawValue)) |
| 216 | + } |
| 217 | + } |
| 218 | + |
| 219 | + package mutating func invalidate() { |
| 220 | + guard value != .zero else { return } |
| 221 | + value = (~value | 1) |
| 222 | + } |
| 223 | + |
| 224 | + package static let undefined: Seed = Seed(value: 2) |
| 225 | + } |
| 226 | + package struct Properties: OptionSet { |
| 227 | + package let rawValue: UInt8 |
| 228 | + package init(rawValue: UInt8) { |
| 229 | + self.rawValue = rawValue |
| 230 | + } |
| 231 | + package static let foregroundLayer = Properties(rawValue: 1 << 0) |
| 232 | + package static let ignoresEvents = Properties(rawValue: 1 << 1) |
| 233 | + package static let privacySensitive = Properties(rawValue: 1 << 2) |
| 234 | + package static let archivesInteractiveControls = Properties(rawValue: 1 << 3) |
| 235 | + package static let secondaryForegroundLayer = Properties(rawValue: 1 << 4) |
| 236 | + package static let tertiaryForegroundLayer = Properties(rawValue: 1 << 5) |
| 237 | + package static let quaternaryForegroundLayer = Properties(rawValue: 1 << 6) |
| 238 | + package static let screencaptureProhibited = Properties(rawValue: 1 << 7) |
| 239 | + } |
| 240 | + |
| 241 | + package struct Key : PreferenceKey { |
| 242 | + package static let _includesRemovedValues: Bool = true |
| 243 | + package static let defaultValue = DisplayList() |
| 244 | + package static func reduce(value: inout DisplayList, nextValue: () -> DisplayList) { |
| 245 | + value.append(contentsOf: nextValue()) |
| 246 | + } |
| 247 | + } |
| 248 | + |
| 249 | + package struct Options: OptionSet, ViewInput { |
| 250 | + package let rawValue: UInt8 |
| 251 | + package init(rawValue: UInt8) { |
| 252 | + self.rawValue = rawValue |
| 253 | + } |
| 254 | + |
| 255 | + package static let disableCanonicalization = Options(rawValue: 1 << 0) |
| 256 | + package static let defaultValue: Options = [] |
| 257 | + } |
| 258 | + |
| 259 | + package struct Index { |
| 260 | + package private(set) var identity: _DisplayList_Identity = .none |
| 261 | + package private(set) var serial: UInt32 = .zero |
| 262 | + package private(set) var archiveIdentity: _DisplayList_Identity = .none |
| 263 | + package private(set) var archiveSerial: UInt32 = .zero |
| 264 | + private var restored: RestoreOptions = [] |
| 265 | + |
| 266 | + package init() {} |
| 267 | +// package mutating func enter(identity: Identity) -> Index |
| 268 | +// package mutating func leave(index saved: Index) |
| 269 | +// package mutating func updateArchive(entering: Bool) |
| 270 | +// package mutating func skip(list: DisplayList) |
| 271 | +// package mutating func skip(item: Item) |
| 272 | +// package mutating func skip(effect: Effect) |
| 273 | +// package func assertItem(_ item: Item) |
| 274 | + |
| 275 | + package var id: ID { |
| 276 | + ID(identity: identity, serial: serial, archiveIdentity: archiveIdentity, archiveSerial: archiveSerial) |
| 277 | + } |
| 278 | + |
| 279 | + package struct ID: Hashable { |
| 280 | + var identity: _DisplayList_Identity |
| 281 | + var serial: UInt32 |
| 282 | + var archiveIdentity: _DisplayList_Identity |
| 283 | + var archiveSerial: UInt32 |
| 284 | + } |
| 285 | + |
| 286 | + private struct RestoreOptions: OptionSet { |
| 287 | + let rawValue: UInt8 |
| 288 | + } |
12 | 289 | }
|
13 | 290 | }
|
0 commit comments