-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathPathData.swift
More file actions
108 lines (91 loc) · 2.99 KB
/
PathData.swift
File metadata and controls
108 lines (91 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// PathData.swift
// OpenSwiftUICore
#if !OPENSWIFTUI_CF_CGTYPES
package import OpenCoreGraphicsShims
package import OpenRenderBoxShims
// ORBPath typealias is defined in Path.swift to resolve Xcode module ambiguity
// MARK: - PathData
/// A union-like structure matching the C PathData union layout.
/// Size: 0x60 (96) bytes to match the buffer size.
///
/// C definition:
///
/// typedef union PathData {
/// CGPathRef cgPath; // 8 bytes (pointer)
/// ORBPath rbPath; // 16 bytes (2 pointers)
/// uint8_t buffer[0x60]; // 96 bytes
/// } PathData;
package struct PathData {
// 96 bytes of raw storage (0x60)
package typealias Buffer = (
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
)
private var storage: Buffer = (
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
)
package init() {}
// MARK: - CGPath access
package init(cgPath: Unmanaged<CGPath>) {
self.cgPath = cgPath
}
package var cgPath: Unmanaged<CGPath> {
get {
withUnsafeBytes(of: storage) { buffer in
buffer.load(as: Unmanaged<CGPath>.self)
}
}
set {
withUnsafeMutableBytes(of: &storage) { buffer in
buffer.storeBytes(of: newValue, as: Unmanaged<CGPath>.self)
}
}
}
// MARK: - ORBPath access
package init(rbPath: ORBPath) {
self.rbPath = rbPath
}
package var rbPath: ORBPath {
get {
withUnsafeBytes(of: storage) { buffer in
buffer.load(as: ORBPath.self)
}
}
set {
withUnsafeMutableBytes(of: &storage) { buffer in
buffer.storeBytes(of: newValue, as: ORBPath.self)
}
}
}
// MARK: - Buffer access
package init(buffer: Buffer) {
self.storage = buffer
}
package var buffer: Buffer {
get { storage }
set { storage = newValue }
}
}
#endif