Skip to content

Update DisplayList #136

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

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
389 changes: 382 additions & 7 deletions Sources/OpenSwiftUICore/Render/DisplayList.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,388 @@
// FIXME
struct DisplayList {}
//
// DisplayList.swift
// OpenSwiftUICore
//
// Audited for RELEASE_2024
// Status: WIP
// ID: F37E3733E490AA5E3BDC045E3D34D9F8

import Foundation

// MARK: - _DisplayList_Identity

private var lastIdentity: UInt32 = 0

package struct _DisplayList_Identity: Hashable, Codable, CustomStringConvertible {
package private(set) var value: UInt32

init(value: UInt32) {
self.value = value
}

package init() {
lastIdentity += 1
self.init(value: lastIdentity)

Check warning on line 24 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L22-L24

Added lines #L22 - L24 were not covered by tests
}

package init(decodedValue value: UInt32) {
self.init(value: value)
}

package static let none = _DisplayList_Identity(value: 0)
package var description: String { "#\(value)" }

Check warning on line 32 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L32

Added line #L32 was not covered by tests
}

// MARK: - DisplayList

package struct DisplayList: Equatable {
package private(set) var items: [Item]

package struct Features: OptionSet {
package let rawValue: UInt16
package init(rawValue: UInt16) {
self.rawValue = rawValue

Check warning on line 43 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L42-L43

Added lines #L42 - L43 were not covered by tests
}
package static let required = Features(rawValue: 1 << 0)
package static let views = Features(rawValue: 1 << 1)
package static let animations = Features(rawValue: 1 << 2)
package static let dynamicContent = Features(rawValue: 1 << 3)
package static let interpolatorLayers = Features(rawValue: 1 << 4)
package static let interpolatorRoots = Features(rawValue: 1 << 5)
package static let stateEffects = Features(rawValue: 1 << 6)
package static let states = Features(rawValue: 1 << 7)
package static let flattened = Features(rawValue: 1 << 9)
}

package private(set) var features: Features
package private(set) var properties: Properties

package init() {
items = []
features = []
properties = []

Check warning on line 62 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L59-L62

Added lines #L59 - L62 were not covered by tests
}

package init(_ item: Item) {
fatalError("TODO")

Check warning on line 66 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L65-L66

Added lines #L65 - L66 were not covered by tests
}

package init(_ items: [Item]) {
guard !items.isEmpty else {
self.init()
return

Check warning on line 72 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L69-L72

Added lines #L69 - L72 were not covered by tests
}
fatalError("TODO")

Check warning on line 74 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L74

Added line #L74 was not covered by tests
}

package mutating func append(_ item: Item) {
fatalError("TODO")

Check warning on line 78 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L77-L78

Added lines #L77 - L78 were not covered by tests
}

package mutating func append(contentsOf other: DisplayList) {
fatalError("TODO")

Check warning on line 82 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L81-L82

Added lines #L81 - L82 were not covered by tests
}
}

@available(*, unavailable)
extension DisplayList: Sendable {}

@available(*, unavailable)
extension DisplayList.Version: Sendable {}

// FIXME
extension DisplayList {
struct Key: PreferenceKey {
static var defaultValue: Void = ()
package typealias Identity = _DisplayList_Identity
package typealias StableIdentity = _DisplayList_StableIdentity
package typealias StableIdentityMap = _DisplayList_StableIdentityMap
package typealias StableIdentityRoot = _DisplayList_StableIdentityRoot
package typealias StableIdentityScope = _DisplayList_StableIdentityScope

package struct Item: Equatable {
package var frame: CGRect
package var version: Version
package var value: Item.Value
package var identity: Identity
package enum Value {
case empty
case content(Content)
case effect(Effect, DisplayList)
case states([(StrongHash, DisplayList)])
}
package init(_ value: Item.Value, frame: CGRect, identity: Identity, version: Version) {
self.frame = frame
self.version = version
self.value = value
self.identity = identity

Check warning on line 114 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L110-L114

Added lines #L110 - L114 were not covered by tests
}

package static func == (lhs: Item, rhs: Item) -> Bool {
lhs.identity == rhs.identity && lhs.version == rhs.version

Check warning on line 118 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L117-L118

Added lines #L117 - L118 were not covered by tests
}

package var position: CGPoint { frame.origin }
package var size: CGSize { frame.size }

Check warning on line 122 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L121-L122

Added lines #L121 - L122 were not covered by tests
}

package struct Content {
package var value: Content.Value
package var seed: Seed
package enum Value {
// indirect case backdrop(BackdropEffect)
indirect case color(Color.Resolved)
// indirect case chameleonColor(fallback: Color.Resolved, filters: [GraphicsFilter])
// indirect case image(GraphicsImage)
// indirect case shape(Path, AnyResolvedPaint, FillStyle)
// indirect case shadow(Path, ResolvedShadowStyle)
// indirect case platformView(any PlatformViewFactory)
// indirect case platformLayer(any PlatformLayerFactory)
// indirect case text(StyledTextContentView, CGSize)
// indirect case flattened(DisplayList, CGPoint, RasterizationOptions)
// indirect case drawing(any RenderBox.RBDisplayListContents, CGPoint, RasterizationOptions)
// indirect case view(any _DisplayList_ViewFactory)
case placeholder(id: Identity)
}
package init(_ value: Content.Value, seed: Seed) {
self.value = value
self.seed = seed

Check warning on line 145 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L143-L145

Added lines #L143 - L145 were not covered by tests
}
}

// package typealias ViewFactory = _DisplayList_ViewFactory

package enum Effect {
case identity
case geometryGroup
case compositingGroup
case backdropGroup(Bool)
indirect case archive(ArchiveIDs?)
case properties(Properties)
// indirect case platformGroup(any PlatformGroupFactory)
case opacity(Float)
// case blendMode(GraphicsBlendMode)
// indirect case clip(Path, FillStyle, _: GraphicsContext.ClipOptions = .init())
// indirect case mask(DisplayList, _: GraphicsContext.ClipOptions = .init())
// indirect case transform(Transform)
// indirect case filter(GraphicsFilter)
// indirect case animation(any _DisplayList_AnyEffectAnimation)
// indirect case contentTransition(ContentTransition.State)
// indirect case view(any _DisplayList_ViewFactory)
// indirect case accessibility([AccessibilityNodeAttachment])
// indirect case platform(PlatformEffect)
indirect case state(StrongHash)
// indirect case interpolatorRoot(InterpolatorGroup, contentOrigin: CGPoint, contentOffset: CGSize)
// case interpolatorLayer(InterpolatorGroup, serial: UInt32)
// indirect case interpolatorAnimation(InterpolatorAnimation)
}

package enum Transform {
#if canImport(Darwin)
case affine(CGAffineTransform)
#endif
case projection(ProjectionTransform)
// case rotation(_RotationEffect.Data)
// case rotation3D(_Rotation3DEffect.Data)
}

// package typealias AnyEffectAnimation = _DisplayList_AnyEffectAnimation
// package typealias AnyEffectAnimator = _DisplayList_AnyEffectAnimator

package struct ArchiveIDs {
package var uuid: UUID
package var stableIDs: StableIdentityMap
package init(uuid: UUID, stableIDs: StableIdentityMap) {
self.uuid = uuid
self.stableIDs = stableIDs

Check warning on line 193 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L191-L193

Added lines #L191 - L193 were not covered by tests
}
}

// package struct InterpolatorAnimation {
// package var value: StrongHash?
// package var animation: Animation?
// }

package struct Version: Comparable, Hashable {
package private(set) var value: Int

package init() { value = .zero }
package init(decodedValue value: Int) { self.value = value }

Check warning on line 206 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L205-L206

Added lines #L205 - L206 were not covered by tests

private static var lastValue: Int = .zero

package init(forUpdate: Void) {
Version.lastValue &+= 1
value = Version.lastValue

Check warning on line 212 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L210-L212

Added lines #L210 - L212 were not covered by tests
}

package mutating func combine(with other: Version) {
value = max(value, other.value)

Check warning on line 216 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L215-L216

Added lines #L215 - L216 were not covered by tests
}

package static func < (lhs: Version, rhs: Version) -> Bool {
lhs.value < rhs.value

Check warning on line 220 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L219-L220

Added lines #L219 - L220 were not covered by tests
}
}

static func reduce(value _: inout Void, nextValue _: () -> Void) {}
package struct Seed: Hashable {
package private(set) var value: UInt16

init(value: UInt16) {
self.value = value

Check warning on line 228 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L227-L228

Added lines #L227 - L228 were not covered by tests
}

package init() { self.init(value: .zero) }
package init(decodedValue value: UInt16) { self.init(value: value) }
package init(_ version: Version) {
if version.value == .zero {
self.init(value: .zero)
} else {
var rawValue = UInt32(bitPattern: Int32(truncatingIfNeeded: version.value >> 16))
rawValue += (rawValue << 5)
rawValue ^= UInt32(bitPattern: Int32(truncatingIfNeeded: version.value))
rawValue = 1 | (rawValue << 1)
self.init(value: UInt16(truncatingIfNeeded: rawValue))

Check warning on line 241 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L231-L241

Added lines #L231 - L241 were not covered by tests
}
}

package mutating func invalidate() {
guard value != .zero else { return }
value = (~value | 1)

Check warning on line 247 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L245-L247

Added lines #L245 - L247 were not covered by tests
}

package static let undefined: Seed = Seed(value: 2)
}
package struct Properties: OptionSet {
package let rawValue: UInt8
package init(rawValue: UInt8) {
self.rawValue = rawValue

Check warning on line 255 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L254-L255

Added lines #L254 - L255 were not covered by tests
}
package static let foregroundLayer = Properties(rawValue: 1 << 0)
package static let ignoresEvents = Properties(rawValue: 1 << 1)
package static let privacySensitive = Properties(rawValue: 1 << 2)
package static let archivesInteractiveControls = Properties(rawValue: 1 << 3)
package static let secondaryForegroundLayer = Properties(rawValue: 1 << 4)
package static let tertiaryForegroundLayer = Properties(rawValue: 1 << 5)
package static let quaternaryForegroundLayer = Properties(rawValue: 1 << 6)
package static let screencaptureProhibited = Properties(rawValue: 1 << 7)
}

package struct Key : PreferenceKey {
package static let _includesRemovedValues: Bool = true
package static let defaultValue = DisplayList()
package static func reduce(value: inout DisplayList, nextValue: () -> DisplayList) {
value.append(contentsOf: nextValue())

Check warning on line 271 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L270-L271

Added lines #L270 - L271 were not covered by tests
}
}

package struct Options: OptionSet, ViewInput {
package let rawValue: UInt8
package init(rawValue: UInt8) {
self.rawValue = rawValue

Check warning on line 278 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L277-L278

Added lines #L277 - L278 were not covered by tests
}

typealias Value = Void
package static let disableCanonicalization = Options(rawValue: 1 << 0)
package static let defaultValue: Options = []
}

package struct Index {
package private(set) var identity: _DisplayList_Identity = .none
package private(set) var serial: UInt32 = .zero
package private(set) var archiveIdentity: _DisplayList_Identity = .none
package private(set) var archiveSerial: UInt32 = .zero
private var restored: RestoreOptions = []

Check warning on line 290 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L286-L290

Added lines #L286 - L290 were not covered by tests

package init() {}
package mutating func enter(identity: Identity) -> Index {
if identity == .none {
self.serial &+= 1
let copy = self
self.restored = []
return copy
} else {
let copy = self
self.identity = identity
self.serial = 0
self.restored = ._1
return copy

Check warning on line 304 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L292-L304

Added lines #L292 - L304 were not covered by tests
}
}

package mutating func leave(index saved: Index) {
if restored.contains(._4) || saved.restored.contains(._8) {
let oldIdentity = identity
let oldSerial = serial
if restored.contains(._4) {
identity = archiveIdentity
serial = archiveSerial

Check warning on line 314 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L308-L314

Added lines #L308 - L314 were not covered by tests
}
if restored.contains(._8) {
archiveIdentity = oldIdentity
archiveSerial = oldSerial

Check warning on line 318 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L316-L318

Added lines #L316 - L318 were not covered by tests
}
}
if restored.contains(._1) {
identity = saved.identity
serial = saved.serial

Check warning on line 323 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L321-L323

Added lines #L321 - L323 were not covered by tests
}
if restored.contains(._2) {
archiveIdentity = saved.archiveIdentity
archiveSerial = saved.archiveSerial

Check warning on line 327 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L325-L327

Added lines #L325 - L327 were not covered by tests
}
restored = saved.restored

Check warning on line 329 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L329

Added line #L329 was not covered by tests
}

package mutating func updateArchive(entering: Bool) {
if entering {
archiveIdentity = identity
archiveSerial = serial
identity = .none
serial = .zero
if !restored.contains([._2, ._4]) {
restored = restored.union([._2, ._4])

Check warning on line 339 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L332-L339

Added lines #L332 - L339 were not covered by tests
}
} else {
// false
identity = archiveIdentity
serial = archiveSerial
archiveIdentity = .none
archiveSerial = .zero
if !restored.contains([._1, ._8]) {
restored = restored.union([._1, ._8])

Check warning on line 348 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L341-L348

Added lines #L341 - L348 were not covered by tests
}
}
}

package mutating func skip(list: DisplayList) {
fatalError("TODO")

Check warning on line 354 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L353-L354

Added lines #L353 - L354 were not covered by tests
}

package mutating func skip(item: Item) {
fatalError("TODO")

Check warning on line 358 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L357-L358

Added lines #L357 - L358 were not covered by tests
}

package mutating func skip(effect: Effect) {

fatalError("TODO")

Check warning on line 363 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L361-L363

Added lines #L361 - L363 were not covered by tests
}

package func assertItem(_ item: Item) {}

Check warning on line 366 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L366

Added line #L366 was not covered by tests

package var id: ID {
ID(identity: identity, serial: serial, archiveIdentity: archiveIdentity, archiveSerial: archiveSerial)

Check warning on line 369 in Sources/OpenSwiftUICore/Render/DisplayList.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.swift#L368-L369

Added lines #L368 - L369 were not covered by tests
}

package struct ID: Hashable {
var identity: _DisplayList_Identity
var serial: UInt32
var archiveIdentity: _DisplayList_Identity
var archiveSerial: UInt32
}

private struct RestoreOptions: OptionSet {
let rawValue: UInt8

static let _1 = RestoreOptions(rawValue: 1 << 0)
static let _2 = RestoreOptions(rawValue: 1 << 1)
static let _4 = RestoreOptions(rawValue: 1 << 2)
static let _8 = RestoreOptions(rawValue: 1 << 3)
}
}
}
Loading
Loading