Skip to content

Commit 793b5ec

Browse files
authored
[NFC] Optimize shape related code (#681)
1 parent 732d7ad commit 793b5ec

File tree

9 files changed

+52
-48
lines changed

9 files changed

+52
-48
lines changed

Sources/OpenSwiftUICore/Graphic/GraphicsContext.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public enum CGBlendMode: Int32, @unchecked Sendable {
4040
}
4141
#endif
4242

43+
package enum PathDrawingStyle {
44+
case fill(FillStyle)
45+
case stroke(StrokeStyle)
46+
}
47+
4348
/// An immediate mode drawing destination, and its current state.
4449
///
4550
/// Use a context to execute 2D drawing primitives. For example, you can draw

Sources/OpenSwiftUICore/Render/CoreAnimation/CAFrameRateRangeUtil.swift renamed to Sources/OpenSwiftUICore/Render/Util/CAFrameRateRangeUtil.swift

File renamed without changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// CGBlendModeUtil.swift
3+
// OpenSwiftUICore
4+
//
5+
// Audited for 6.5.4
6+
// Status: Complete
7+
8+
#if canImport(CoreGraphics)
9+
package import CoreGraphics
10+
11+
extension BlendMode {
12+
package init(_ blendMode: CGBlendMode) {
13+
self = switch blendMode {
14+
case .normal: .normal
15+
case .multiply: .multiply
16+
case .screen: .screen
17+
case .overlay: .overlay
18+
case .darken: .darken
19+
case .lighten: .lighten
20+
case .colorDodge: .colorDodge
21+
case .colorBurn: .colorBurn
22+
case .softLight: .softLight
23+
case .hardLight: .hardLight
24+
case .difference: .difference
25+
case .exclusion: .exclusion
26+
case .hue: .hue
27+
case .saturation: .saturation
28+
case .color: .color
29+
case .luminosity: .luminosity
30+
case .sourceAtop: .sourceAtop
31+
case .destinationOver: .destinationOver
32+
case .destinationOut: .destinationOut
33+
case .plusDarker: .plusDarker
34+
case .plusLighter: .plusLighter
35+
default: .normal
36+
}
37+
}
38+
}
39+
#endif

Sources/OpenSwiftUICore/Shape/FillStyle.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// FillStyle.swift
33
// OpenSwiftUICore
44
//
5-
// Audited for 6.0.87
5+
// Audited for 6.5.4
66
// Status: Complete
77

88
/// A style for rasterizing vector shapes.
9+
@available(OpenSwiftUI_v1_0, *)
910
@frozen
1011
public struct FillStyle: Equatable {
1112

Sources/OpenSwiftUICore/Shape/PathDrawingStyle.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

Sources/OpenSwiftUICore/Shape/ShapeStyle/BlendMode.swift

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// MARK: - BlendMode
99

1010
/// Modes for compositing a view with overlapping content.
11+
@available(OpenSwiftUI_v1_0, *)
1112
public enum BlendMode: Sendable {
1213
case normal
1314
case multiply
@@ -32,39 +33,6 @@ public enum BlendMode: Sendable {
3233
case plusLighter
3334
}
3435

35-
#if canImport(CoreGraphics)
36-
package import CoreGraphics
37-
38-
extension BlendMode {
39-
package init(_ blendMode: CGBlendMode) {
40-
self = switch blendMode {
41-
case .normal: .normal
42-
case .multiply: .multiply
43-
case .screen: .screen
44-
case .overlay: .overlay
45-
case .darken: .darken
46-
case .lighten: .lighten
47-
case .colorDodge: .colorDodge
48-
case .colorBurn: .colorBurn
49-
case .softLight: .softLight
50-
case .hardLight: .hardLight
51-
case .difference: .difference
52-
case .exclusion: .exclusion
53-
case .hue: .hue
54-
case .saturation: .saturation
55-
case .color: .color
56-
case .luminosity: .luminosity
57-
case .sourceAtop: .sourceAtop
58-
case .destinationOver: .destinationOver
59-
case .destinationOut: .destinationOut
60-
case .plusDarker: .plusDarker
61-
case .plusLighter: .plusLighter
62-
default: .normal
63-
}
64-
}
65-
}
66-
#endif
67-
6836
extension ShapeStyle {
6937
/// Returns a new style based on `self` that applies the specified
7038
/// blend mode when drawing.

Sources/OpenSwiftUICore/Shape/ShapeStyle/ShapeStyleRenderedShape.swift renamed to Sources/OpenSwiftUICore/Shape/ShapeStyle/ShapeStyleRendering.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//
2-
// ShapeStyle_RenderedShape.swift
2+
// ShapeStyleRendering.swift
33
// OpenSwiftUICore
44
//
55
// Audited for 6.0.87
66
// Status: WIP
7-
// ID: 3890C65F12EA82A4BC5FBD33046B67FA (?)
7+
// ID: 3890C65F12EA82A4BC5FBD33046B67FA (SwiftUICore)
88

99
extension ShapeStyle {
1010
package typealias RenderedShape = _ShapeStyle_RenderedShape

Sources/OpenSwiftUICore/Shape/StrokeStyle.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
// StrokeStyle.swift
33
// OpenSwiftUICore
44
//
5-
// Audited for 6.0.87
5+
// Audited for 6.5.4
66
// Status: Complete
77

88
public import Foundation
99
public import OpenCoreGraphicsShims
1010

1111
/// The characteristics of a stroke that traces a path.
12+
@available(OpenSwiftUI_v1_0, *)
1213
@frozen
1314
public struct StrokeStyle: Equatable {
1415
/// The width of the stroked path.
@@ -51,6 +52,7 @@ public struct StrokeStyle: Equatable {
5152
}
5253
}
5354

55+
@available(OpenSwiftUI_v1_0, *)
5456
extension StrokeStyle: Animatable {
5557
public var animatableData: AnimatablePair<CGFloat, AnimatablePair<CGFloat, CGFloat>> {
5658
get {

Tests/OpenSwiftUICoreTests/Render/CoreAnimation/CAFrameRateRangeUtilTests.swift renamed to Tests/OpenSwiftUICoreTests/Render/Util/CAFrameRateRangeUtilTests.swift

File renamed without changes.

0 commit comments

Comments
 (0)