Skip to content
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

Update ViewRender #144

Merged
merged 11 commits into from
Oct 20, 2024
2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ let package = Package(
cSettings: [
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
]
),
.target(
name: "COpenSwiftUICore",
cSettings: [
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
]
),
.binaryTarget(name: "CoreServices", path: "PrivateFrameworks/CoreServices.xcframework"),
Expand Down
2 changes: 2 additions & 0 deletions Package@swift-5.10.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,15 @@ let package = Package(
cSettings: [
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
]
),
.target(
name: "COpenSwiftUICore",
cSettings: [
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
]
),
.binaryTarget(name: "CoreServices", path: "PrivateFrameworks/CoreServices.xcframework"),
Expand Down
3 changes: 3 additions & 0 deletions Sources/COpenSwiftUICore/include/OpenSwiftUIBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef OpenSwiftUIBase_h
#define OpenSwiftUIBase_h

#include <CoreFoundation/CoreFoundation.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
Expand Down Expand Up @@ -67,4 +68,6 @@
# define OPENSWIFTUI_SWIFT_NAME(_name)
#endif

#define OPENSWIFTUI_ENUM CF_ENUM

#endif /* OpenSwiftUIBase_h */
18 changes: 18 additions & 0 deletions Sources/COpenSwiftUICore/include/ViewSystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ViewSystem.h
// COpenSwiftUICore
// Audited for RELEASE_2024
// Status: Complete

#ifndef ViewSystem_h
#define ViewSystem_h

#include "OpenSwiftUIBase.h"

typedef OPENSWIFTUI_ENUM(uint8_t, ViewSystem) {
ViewSystemUIView,
ViewSystemNSView,
ViewSystem_2,
};

#endif /* ViewSystem_h */
38 changes: 38 additions & 0 deletions Sources/OpenSwiftUI/Integration/UIKit/UIHostingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,44 @@ open class _UIHostingView<Content>: UIView where Content: View {
}

extension _UIHostingView: ViewRendererHost {
package var renderingPhase: OpenSwiftUICore.ViewRenderingPhase {
get {
fatalError("TODO")
}
set(newValue) {
fatalError("TODO")
}
}

package var externalUpdateCount: Int {
get {
fatalError("TODO")
}
set(newValue) {
fatalError("TODO")
}
}

package func updateEnvironment() {
fatalError("TODO")
}

package func updateSize() {
fatalError("TODO")
}

package func updateSafeArea() {
fatalError("TODO")
}

package func updateScrollableContainerSize() {
fatalError("TODO")
}

package func renderDisplayList(_ list: DisplayList, asynchronously: Bool, time: Time, nextTime: Time, targetTimestamp: Time?, version: DisplayList.Version, maxVersion: DisplayList.Version) -> Time {
fatalError("TODO")
}

package func addImplicitPropertiesNeedingUpdate(to _: inout ViewRendererHostProperties) {}

package func updateRootView() {
Expand Down
13 changes: 13 additions & 0 deletions Sources/OpenSwiftUI/Render/UIViewPlatformViewDefinition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// UIViewPlatformViewDefinition.swift
// OpenSwiftUI
//
// Audited for RELEASE_2024
// Status: WIP

@_spi(DisplayList_ViewSystem) internal import OpenSwiftUICore

final class UIViewPlatformViewDefinition: PlatformViewDefinition, @unchecked Sendable {
override final class var system: PlatformViewDefinition.System { .uiView }

Check warning on line 11 in Sources/OpenSwiftUI/Render/UIViewPlatformViewDefinition.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Render/UIViewPlatformViewDefinition.swift#L11

Added line #L11 was not covered by tests
// TODO
}
28 changes: 18 additions & 10 deletions Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
//
// PreferenceBridge.swift
// OpenSwiftUI
// OpenSwiftUICore
//
// Audited for RELEASE_2021
// Status: Complete
// ID: A9FAE381E99529D5274BA37A9BC9B074
// Audited for RELEASE_2024
// Status: TO BE AUDITED
// ID: A9FAE381E99529D5274BA37A9BC9B074 (RELEASE_2021)
// ID: DF57A19C61B44C613EB77C1D47FC679A (RELEASE_2024)

internal import OpenGraphShims

package final class PreferenceBridge {
unowned let viewGraph: ViewGraph
weak var viewGraph: ViewGraph?
var isValid: Bool = true

Check warning on line 14 in Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift#L14

Added line #L14 was not covered by tests
private(set) var children: [Unmanaged<ViewGraph>] = []
var requestedPreferences = PreferenceKeys()
var bridgedViewInputs = PropertyList()
Expand All @@ -23,9 +25,15 @@
}

init() {
viewGraph = GraphHost.currentHost as! ViewGraph
viewGraph = ViewGraph.current

Check warning on line 28 in Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift#L28

Added line #L28 was not covered by tests
}

deinit {
if isValid { invalidate() }

Check warning on line 32 in Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift#L31-L32

Added lines #L31 - L32 were not covered by tests
}

// FIXME: TO BE AUDITED

#if canImport(Darwin) // FIXME: See #39
func addValue(_ value: AnyAttribute, for keyType: AnyPreferenceKey.Type) {
struct AddValue: PreferenceKeyVisitor {
Expand All @@ -48,7 +56,7 @@
}
var visitor = AddValue(combiner: combiner, value: value)
keyType.visitKey(&visitor)
viewGraph.graphInvalidation(from: value)
viewGraph?.graphInvalidation(from: value)

Check warning on line 59 in Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift#L59

Added line #L59 was not covered by tests
}

func removeValue(_ value: AnyAttribute, for keyType: AnyPreferenceKey.Type, isInvalidating: Bool) {
Expand Down Expand Up @@ -78,7 +86,7 @@
var visitor = RemoveValue(combiner: combiner, value: value)
keyType.visitKey(&visitor)
if visitor.changed {
viewGraph.graphInvalidation(from: isInvalidating ? nil : value)
viewGraph?.graphInvalidation(from: isInvalidating ? nil : value)

Check warning on line 89 in Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift#L89

Added line #L89 was not covered by tests
}
}

Expand All @@ -92,7 +100,7 @@
) { combiner in
combiner.addChild(keys: keys, values: values)
}
viewGraph.graphInvalidation(from: combiner.identifier)
viewGraph?.graphInvalidation(from: combiner.identifier)

Check warning on line 103 in Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift#L103

Added line #L103 was not covered by tests
}

func removeHostValue(for keys: Attribute<PreferenceKeys>, isInvalidating: Bool) {
Expand All @@ -112,7 +120,7 @@
hasRemoved = true
}
if hasRemoved {
viewGraph.graphInvalidation(from: isInvalidating ? nil : keys.identifier)
viewGraph?.graphInvalidation(from: isInvalidating ? nil : keys.identifier)

Check warning on line 123 in Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift#L123

Added line #L123 was not covered by tests
}
}

Expand Down
14 changes: 0 additions & 14 deletions Sources/OpenSwiftUICore/Data/Preference/View_Preference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,3 @@ extension View {
modifier(_PreferenceTransformModifier<K>(transform: callback))
}
}

extension EnvironmentValues {
private struct PreferenceBridgeKey: EnvironmentKey {
struct Value {
weak var value: PreferenceBridge?
}
static let defaultValue: Value = Value()
}

var preferenceBridge: PreferenceBridge? {
get { self[PreferenceBridgeKey.self].value }
set { self[PreferenceBridgeKey.self] = PreferenceBridgeKey.Value(value: newValue) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ContentShapeKinds.swift
// OpenSwiftUI
//
// Audited for RELEASE_2023
// Audited for RELEASE_2024
// Status: Complete

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

#if OPENSWIFTUI_SUPPORT_2023_API
/// The kind for accessibility visuals and sorting.
///
/// Setting a content shape with this kind causes the accessibility frame
Expand All @@ -85,5 +82,4 @@ public struct ContentShapeKinds: OptionSet, Sendable {
///
/// To control the shape for accessibility and hit-testing, use the `interaction` kind.
public static let accessibility: ContentShapeKinds = ContentShapeKinds(rawValue: 1 << 4)
#endif
}
72 changes: 72 additions & 0 deletions Sources/OpenSwiftUICore/Render/DisplayList.GraphicsRenderer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// DisplayList.GraphicsRenderer.swift
// OpenSwiftUICore
//
// Audited for RELEASE_2024
// Status: Blocked by RenderBox and GraphicsContext
// ID: EFAEDE41CB8C85EF3A6A18DC05438A3C

import Foundation

extension DisplayList {
final package class GraphicsRenderer {
package enum PlatformViewMode {
case ignored
case unsupported
case rendered(update: Bool)
}

private struct Cache {
var callbacks: [CallbackKey: Void /* RBDisplayListContents */]
var animators: [AnimatorKey: Void /* _DisplayList_AnyEffectAnimator */ ]

struct CallbackKey: Hashable {
var index: DisplayList.Index.ID
var seed: DisplayList.Seed
var scale: CGFloat
}

struct AnimatorKey: Hashable {
var index: DisplayList.Index.ID
}
}

private var oldCache: DisplayList.GraphicsRenderer.Cache
private var newCache: DisplayList.GraphicsRenderer.Cache
var index: DisplayList.Index
var time: Time
var nextTime: Time
var stableIDs: _DisplayList_StableIdentityMap?
var inTransitionGroup: Bool
var stateHashes: [StrongHash]
package var platformViewMode: DisplayList.GraphicsRenderer.PlatformViewMode

package init(platformViewMode: DisplayList.GraphicsRenderer.PlatformViewMode) {
fatalError("TODO")

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

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.GraphicsRenderer.swift#L44-L45

Added lines #L44 - L45 were not covered by tests
}

package func render(at time: Time, do body: () -> Void) {
fatalError("TODO")

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

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.GraphicsRenderer.swift#L48-L49

Added lines #L48 - L49 were not covered by tests
}

package func renderDisplayList(_ list: DisplayList, at time: Time, in ctx: inout GraphicsContext) {
fatalError("TODO")

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

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.GraphicsRenderer.swift#L52-L53

Added lines #L52 - L53 were not covered by tests
}

package func render(list: DisplayList, in ctx: inout GraphicsContext) {
fatalError("TODO")

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

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.GraphicsRenderer.swift#L56-L57

Added lines #L56 - L57 were not covered by tests
}

package func render(item: DisplayList.Item, in ctx: inout GraphicsContext) {
fatalError("TODO")

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

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.GraphicsRenderer.swift#L60-L61

Added lines #L60 - L61 were not covered by tests
}

package func drawImplicitLayer(in ctx: inout GraphicsContext, content: (inout GraphicsContext) -> Void) {
fatalError("TODO")

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

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.GraphicsRenderer.swift#L64-L65

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

package func renderPlatformView(_ view: AnyObject?, in ctx: GraphicsContext, size: CGSize, viewType: any Any.Type) {
fatalError("TODO")

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

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList.GraphicsRenderer.swift#L68-L69

Added lines #L68 - L69 were not covered by tests
}
}
}
Loading
Loading