Skip to content

Commit d7fb516

Browse files
authored
Update ViewRender (#144)
* Add RendererConfiguration * Add PlatformViewDefinition * Update ViewRenderer * Add GraphicsRenderer * Add empty ViewRasterizer implementation * Add ViewGraphFeature and update ViewGraphDelegate * Add ViewRenderingPhase and update ViewRenderHostProperties * Add EmptyViewRendererHost * Update ViewRendererHost * Update PreferenceBridge * Fix WASI build issue
1 parent ab3f0e9 commit d7fb516

21 files changed

+896
-180
lines changed

Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,15 @@ let package = Package(
164164
cSettings: [
165165
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
166166
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
167+
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
167168
]
168169
),
169170
.target(
170171
name: "COpenSwiftUICore",
171172
cSettings: [
172173
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
173174
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
175+
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
174176
]
175177
),
176178
.binaryTarget(name: "CoreServices", path: "PrivateFrameworks/CoreServices.xcframework"),

[email protected]

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,15 @@ let package = Package(
160160
cSettings: [
161161
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
162162
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
163+
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
163164
]
164165
),
165166
.target(
166167
name: "COpenSwiftUICore",
167168
cSettings: [
168169
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
169170
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
171+
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
170172
]
171173
),
172174
.binaryTarget(name: "CoreServices", path: "PrivateFrameworks/CoreServices.xcframework"),

Sources/COpenSwiftUICore/include/OpenSwiftUIBase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef OpenSwiftUIBase_h
99
#define OpenSwiftUIBase_h
1010

11+
#include <CoreFoundation/CoreFoundation.h>
1112
#include <stdint.h>
1213
#include <stdbool.h>
1314
#include <stdio.h>
@@ -67,4 +68,6 @@
6768
# define OPENSWIFTUI_SWIFT_NAME(_name)
6869
#endif
6970

71+
#define OPENSWIFTUI_ENUM CF_ENUM
72+
7073
#endif /* OpenSwiftUIBase_h */
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// ViewSystem.h
3+
// COpenSwiftUICore
4+
// Audited for RELEASE_2024
5+
// Status: Complete
6+
7+
#ifndef ViewSystem_h
8+
#define ViewSystem_h
9+
10+
#include "OpenSwiftUIBase.h"
11+
12+
typedef OPENSWIFTUI_ENUM(uint8_t, ViewSystem) {
13+
ViewSystemUIView,
14+
ViewSystemNSView,
15+
ViewSystem_2,
16+
};
17+
18+
#endif /* ViewSystem_h */

Sources/OpenSwiftUI/Integration/UIKit/UIHostingView.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,44 @@ open class _UIHostingView<Content>: UIView where Content: View {
154154
}
155155

156156
extension _UIHostingView: ViewRendererHost {
157+
package var renderingPhase: OpenSwiftUICore.ViewRenderingPhase {
158+
get {
159+
fatalError("TODO")
160+
}
161+
set(newValue) {
162+
fatalError("TODO")
163+
}
164+
}
165+
166+
package var externalUpdateCount: Int {
167+
get {
168+
fatalError("TODO")
169+
}
170+
set(newValue) {
171+
fatalError("TODO")
172+
}
173+
}
174+
175+
package func updateEnvironment() {
176+
fatalError("TODO")
177+
}
178+
179+
package func updateSize() {
180+
fatalError("TODO")
181+
}
182+
183+
package func updateSafeArea() {
184+
fatalError("TODO")
185+
}
186+
187+
package func updateScrollableContainerSize() {
188+
fatalError("TODO")
189+
}
190+
191+
package func renderDisplayList(_ list: DisplayList, asynchronously: Bool, time: Time, nextTime: Time, targetTimestamp: Time?, version: DisplayList.Version, maxVersion: DisplayList.Version) -> Time {
192+
fatalError("TODO")
193+
}
194+
157195
package func addImplicitPropertiesNeedingUpdate(to _: inout ViewRendererHostProperties) {}
158196

159197
package func updateRootView() {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// UIViewPlatformViewDefinition.swift
3+
// OpenSwiftUI
4+
//
5+
// Audited for RELEASE_2024
6+
// Status: WIP
7+
8+
@_spi(DisplayList_ViewSystem) internal import OpenSwiftUICore
9+
10+
final class UIViewPlatformViewDefinition: PlatformViewDefinition, @unchecked Sendable {
11+
override final class var system: PlatformViewDefinition.System { .uiView }
12+
// TODO
13+
}

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
//
22
// PreferenceBridge.swift
3-
// OpenSwiftUI
3+
// OpenSwiftUICore
44
//
5-
// Audited for RELEASE_2021
6-
// Status: Complete
7-
// ID: A9FAE381E99529D5274BA37A9BC9B074
5+
// Audited for RELEASE_2024
6+
// Status: TO BE AUDITED
7+
// ID: A9FAE381E99529D5274BA37A9BC9B074 (RELEASE_2021)
8+
// ID: DF57A19C61B44C613EB77C1D47FC679A (RELEASE_2024)
89

910
internal import OpenGraphShims
1011

1112
package final class PreferenceBridge {
12-
unowned let viewGraph: ViewGraph
13+
weak var viewGraph: ViewGraph?
14+
var isValid: Bool = true
1315
private(set) var children: [Unmanaged<ViewGraph>] = []
1416
var requestedPreferences = PreferenceKeys()
1517
var bridgedViewInputs = PropertyList()
@@ -23,9 +25,15 @@ package final class PreferenceBridge {
2325
}
2426

2527
init() {
26-
viewGraph = GraphHost.currentHost as! ViewGraph
28+
viewGraph = ViewGraph.current
2729
}
2830

31+
deinit {
32+
if isValid { invalidate() }
33+
}
34+
35+
// FIXME: TO BE AUDITED
36+
2937
#if canImport(Darwin) // FIXME: See #39
3038
func addValue(_ value: AnyAttribute, for keyType: AnyPreferenceKey.Type) {
3139
struct AddValue: PreferenceKeyVisitor {
@@ -48,7 +56,7 @@ package final class PreferenceBridge {
4856
}
4957
var visitor = AddValue(combiner: combiner, value: value)
5058
keyType.visitKey(&visitor)
51-
viewGraph.graphInvalidation(from: value)
59+
viewGraph?.graphInvalidation(from: value)
5260
}
5361

5462
func removeValue(_ value: AnyAttribute, for keyType: AnyPreferenceKey.Type, isInvalidating: Bool) {
@@ -78,7 +86,7 @@ package final class PreferenceBridge {
7886
var visitor = RemoveValue(combiner: combiner, value: value)
7987
keyType.visitKey(&visitor)
8088
if visitor.changed {
81-
viewGraph.graphInvalidation(from: isInvalidating ? nil : value)
89+
viewGraph?.graphInvalidation(from: isInvalidating ? nil : value)
8290
}
8391
}
8492

@@ -92,7 +100,7 @@ package final class PreferenceBridge {
92100
) { combiner in
93101
combiner.addChild(keys: keys, values: values)
94102
}
95-
viewGraph.graphInvalidation(from: combiner.identifier)
103+
viewGraph?.graphInvalidation(from: combiner.identifier)
96104
}
97105

98106
func removeHostValue(for keys: Attribute<PreferenceKeys>, isInvalidating: Bool) {
@@ -112,7 +120,7 @@ package final class PreferenceBridge {
112120
hasRemoved = true
113121
}
114122
if hasRemoved {
115-
viewGraph.graphInvalidation(from: isInvalidating ? nil : keys.identifier)
123+
viewGraph?.graphInvalidation(from: isInvalidating ? nil : keys.identifier)
116124
}
117125
}
118126

Sources/OpenSwiftUICore/Data/Preference/View_Preference.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,3 @@ extension View {
2222
modifier(_PreferenceTransformModifier<K>(transform: callback))
2323
}
2424
}
25-
26-
extension EnvironmentValues {
27-
private struct PreferenceBridgeKey: EnvironmentKey {
28-
struct Value {
29-
weak var value: PreferenceBridge?
30-
}
31-
static let defaultValue: Value = Value()
32-
}
33-
34-
var preferenceBridge: PreferenceBridge? {
35-
get { self[PreferenceBridgeKey.self].value }
36-
set { self[PreferenceBridgeKey.self] = PreferenceBridgeKey.Value(value: newValue) }
37-
}
38-
}

Sources/OpenSwiftUICore/EventHandling/InputEvent/HitTesting/ContentShapeKinds.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// ContentShapeKinds.swift
33
// OpenSwiftUI
44
//
5-
// Audited for RELEASE_2023
5+
// Audited for RELEASE_2024
66
// Status: Complete
77

88
import Foundation
@@ -55,7 +55,6 @@ public struct ContentShapeKinds: OptionSet, Sendable {
5555
/// When using this kind, only the preview shape will be affected. To
5656
/// control the shape used to hit-test and start the context menu
5757
/// presentation, use the `.interaction` kind.
58-
@available(tvOS 17.0, *)
5958
@available(macOS, unavailable)
6059
@available(watchOS, unavailable)
6160
public static let contextMenuPreview: ContentShapeKinds = ContentShapeKinds(rawValue: 1 << 2)
@@ -69,10 +68,8 @@ public struct ContentShapeKinds: OptionSet, Sendable {
6968
/// This kind does not affect the `onHover` modifier.
7069
@available(macOS, unavailable)
7170
@available(watchOS, unavailable)
72-
@available(tvOS, unavailable)
7371
public static let hoverEffect: ContentShapeKinds = ContentShapeKinds(rawValue: 1 << 3)
7472

75-
#if OPENSWIFTUI_SUPPORT_2023_API
7673
/// The kind for accessibility visuals and sorting.
7774
///
7875
/// Setting a content shape with this kind causes the accessibility frame
@@ -85,5 +82,4 @@ public struct ContentShapeKinds: OptionSet, Sendable {
8582
///
8683
/// To control the shape for accessibility and hit-testing, use the `interaction` kind.
8784
public static let accessibility: ContentShapeKinds = ContentShapeKinds(rawValue: 1 << 4)
88-
#endif
8985
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//
2+
// DisplayList.GraphicsRenderer.swift
3+
// OpenSwiftUICore
4+
//
5+
// Audited for RELEASE_2024
6+
// Status: Blocked by RenderBox and GraphicsContext
7+
// ID: EFAEDE41CB8C85EF3A6A18DC05438A3C
8+
9+
import Foundation
10+
11+
extension DisplayList {
12+
final package class GraphicsRenderer {
13+
package enum PlatformViewMode {
14+
case ignored
15+
case unsupported
16+
case rendered(update: Bool)
17+
}
18+
19+
private struct Cache {
20+
var callbacks: [CallbackKey: Void /* RBDisplayListContents */]
21+
var animators: [AnimatorKey: Void /* _DisplayList_AnyEffectAnimator */ ]
22+
23+
struct CallbackKey: Hashable {
24+
var index: DisplayList.Index.ID
25+
var seed: DisplayList.Seed
26+
var scale: CGFloat
27+
}
28+
29+
struct AnimatorKey: Hashable {
30+
var index: DisplayList.Index.ID
31+
}
32+
}
33+
34+
private var oldCache: DisplayList.GraphicsRenderer.Cache
35+
private var newCache: DisplayList.GraphicsRenderer.Cache
36+
var index: DisplayList.Index
37+
var time: Time
38+
var nextTime: Time
39+
var stableIDs: _DisplayList_StableIdentityMap?
40+
var inTransitionGroup: Bool
41+
var stateHashes: [StrongHash]
42+
package var platformViewMode: DisplayList.GraphicsRenderer.PlatformViewMode
43+
44+
package init(platformViewMode: DisplayList.GraphicsRenderer.PlatformViewMode) {
45+
fatalError("TODO")
46+
}
47+
48+
package func render(at time: Time, do body: () -> Void) {
49+
fatalError("TODO")
50+
}
51+
52+
package func renderDisplayList(_ list: DisplayList, at time: Time, in ctx: inout GraphicsContext) {
53+
fatalError("TODO")
54+
}
55+
56+
package func render(list: DisplayList, in ctx: inout GraphicsContext) {
57+
fatalError("TODO")
58+
}
59+
60+
package func render(item: DisplayList.Item, in ctx: inout GraphicsContext) {
61+
fatalError("TODO")
62+
}
63+
64+
package func drawImplicitLayer(in ctx: inout GraphicsContext, content: (inout GraphicsContext) -> Void) {
65+
fatalError("TODO")
66+
}
67+
68+
package func renderPlatformView(_ view: AnyObject?, in ctx: GraphicsContext, size: CGSize, viewType: any Any.Type) {
69+
fatalError("TODO")
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)