Skip to content
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
2 changes: 1 addition & 1 deletion Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Sources/OpenSwiftUICore/Graphic/Color/ConstantColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ extension Color {
}

package func multiplyingOpacity(by opacity: Float) -> Color.Resolved {
Color.Resolved(linearRed: linearRed, linearGreen: linearGreen, linearBlue: linearBlue, opacity: opacity * self.opacity)
var resolved = self
resolved.opacity = opacity * self.opacity
return resolved
}

package func over(_ s: Color.Resolved) -> Color.Resolved {
Expand Down
17 changes: 0 additions & 17 deletions Sources/OpenSwiftUICore/Render/DisplayList/DisplayList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -510,21 +510,4 @@ extension GraphicsContext {

package protocol _DisplayList_AnyEffectAnimation {}

package struct GraphicsImage: Equatable {
package init() {}
}

extension GraphicsImage: ProtobufMessage {
package func encode(to encoder: inout ProtobufEncoder) throws {
// GraphicsImage is currently empty, no fields to encode
}

package init(from decoder: inout ProtobufDecoder) throws {
// GraphicsImage is currently empty, skip all fields
while let field = try decoder.nextField() {
try decoder.skipField(field)
}
self = GraphicsImage()
}
}
package struct ResolvedShadowStyle {}
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
//
// ShapeStyle_ResolverMode.swift
// ShapeStyleResolverMode.swift
// OpenSwiftUICore
//
// Audited for 6.0.87
// Status: Blocked by Image.Location
// Audited for 6.5.4
// Status: Complete

package import Foundation

package struct _ShapeStyle_ResolverMode: Equatable {
package var bundle: Bundle?

package var foregroundLevels: UInt16

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

package static let foregroundPalette: Options = .init(rawValue: 1 << 0)

package static let background: Options = .init(rawValue: 1 << 1)

package static let multicolor: Options = .init(rawValue: 1 << 2)
}

Expand All @@ -27,7 +31,44 @@ package struct _ShapeStyle_ResolverMode: Equatable {
self.options = options
}

// package init(rbSymbolStyleMask mask: UInt32, location: Image.Location)
package init(rbSymbolStyleMask mask: UInt32, location: Image.Location) {
let bundle: Bundle?
var options: Options
if mask & (1 << 9) != 0 {
options = .multicolor
bundle = location.bundle
} else {
options = []
bundle = nil
}
let foregroundLevels: UInt16
let hasForegroundPalette: Bool
if mask & (1 << 8) != 0 {
foregroundLevels = 5
hasForegroundPalette = true
} else if mask & (1 << 7) != 0 {
foregroundLevels = 4
hasForegroundPalette = true
} else if mask & (1 << 6) != 0 {
foregroundLevels = 3
hasForegroundPalette = true
} else if mask & (1 << 5) != 0 {
foregroundLevels = 2
hasForegroundPalette = true
} else if mask & (1 << 0) != 0 {
foregroundLevels = 1
hasForegroundPalette = false
} else {
foregroundLevels = 0
hasForegroundPalette = false
}
if hasForegroundPalette {
options.formUnion(.foregroundPalette)
}
self.bundle = bundle
self.foregroundLevels = foregroundLevels
self.options = options
}

package mutating func formUnion(_ rhs: _ShapeStyle_ResolverMode) {
bundle = bundle ?? rhs.bundle
Expand Down
20 changes: 18 additions & 2 deletions Sources/OpenSwiftUICore/View/Image/CGImageProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// OpenSwiftUICore
//
// Audited for 6.5.4
// Status: Blocked by Image.Resolved
// Status: Complete
// ID: BB7900A03A030BC988C08113497314C3 (SwiftUICore?)

public import OpenCoreGraphicsShims
Expand Down Expand Up @@ -75,7 +75,23 @@ private struct CGImageProvider: ImageProvider {
var decorative: Bool

func resolve(in context: ImageResolutionContext) -> Image.Resolved {
_openSwiftUIUnimplementedFailure()
var graphicsImage = GraphicsImage(
contents: .cgImage(image),
scale: scale,
unrotatedPixelSize: image.size,
orientation: orientation,
isTemplate: context.environment.imageIsTemplate()
)
graphicsImage.allowedDynamicRange = context.effectiveAllowedDynamicRange(for: graphicsImage)
if context.environment.shouldRedactContent {
let color = Color.foreground.resolve(in: context.environment)
graphicsImage.contents = .color(color.multiplyingOpacity(by: 0.16))
}
return Image.Resolved(
image: graphicsImage,
decorative: decorative,
label: AccessibilityImageLabel(label)
)
}

func resolveNamedImage(in context: ImageResolutionContext) -> Image.NamedResolved? {
Expand Down
205 changes: 205 additions & 0 deletions Sources/OpenSwiftUICore/View/Image/GraphicsImage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
//
// GraphicsImage.swift
// OpenSwiftUICore
//
// Audited for 6.5.4
// Status: Complete with WIP implementation
// ID: B4F00EDEBAA4ECDCB2CAB650A00E4160 (SwiftUICore)

package import OpenCoreGraphicsShims
#if canImport(CoreGraphics)
import CoreGraphics_Private
#endif

// MARK: - GraphicsImage

package struct GraphicsImage: Equatable, Sendable {
package enum Contents: Equatable, @unchecked Sendable {
case cgImage(CGImage)
case ioSurface(IOSurfaceRef)
indirect case vectorGlyph(ResolvedVectorGlyph)
indirect case vectorLayer(VectorImageLayer)
indirect case color(Color.Resolved)
indirect case named(NamedImage.Key)
}

package var contents: GraphicsImage.Contents?

package var scale: CGFloat

package var unrotatedPixelSize: CGSize

package var orientation: Image.Orientation

package var maskColor: Color.Resolved?

package var resizingInfo: Image.ResizingInfo?

package var isAntialiased: Bool

package var interpolation: Image.Interpolation

package var allowedDynamicRange: Image.DynamicRange?

package var isTemplate: Bool {
maskColor != nil
}

package var size: CGSize {
guard scale != .zero else { return .zero }
return unrotatedPixelSize.apply(orientation) * (1.0 / scale)
}

package var pixelSize: CGSize {
unrotatedPixelSize.apply(orientation)
}

package init(
contents: GraphicsImage.Contents?,
scale: CGFloat,
unrotatedPixelSize: CGSize,
orientation: Image.Orientation,
isTemplate: Bool,
resizingInfo: Image.ResizingInfo? = nil,
antialiased: Bool = true,
interpolation: Image.Interpolation = .low
) {
self.contents = contents
self.scale = scale
self.unrotatedPixelSize = unrotatedPixelSize
self.orientation = orientation
self.maskColor = isTemplate ? .white : nil
self.resizingInfo = resizingInfo
self.isAntialiased = antialiased
self.interpolation = interpolation
self.allowedDynamicRange = nil
}

package func slicesAndTiles(at extent: CGSize? = nil) -> Image.ResizingInfo? {
guard size != extent, let resizingInfo else {
return nil
}
guard !resizingInfo.capInsets.isEmpty || resizingInfo.mode == .tile else {
return nil
}
if case .color = contents {
return nil
}
return resizingInfo
}

package var styleResolverMode: ShapeStyle.ResolverMode {
switch contents {
case .cgImage:
return .init()
case let .vectorGlyph(resolvedVectorGlyph):
return .init(
rbSymbolStyleMask: resolvedVectorGlyph.animator.styleMask,
location: resolvedVectorGlyph.location
)
default:
return .init(foregroundLevels: isTemplate ? 1 : 0)
}
}

package var headroom: Image.Headroom {
#if canImport(CoreGraphics)
guard case let .cgImage(image) = contents,
let colorSpace = image.colorSpace,
CGColorSpaceUsesITUR_2100TF(colorSpace)
else {
return .standard
}
var headroom: Float = .zero
guard CGImageGetHeadroom(image, &headroom) || headroom > 0 else {
if CGColorSpaceIsHLGBased(colorSpace) {
return .highHLG
} else {
return .high
}
}
return .init(rawValue: CGFloat(headroom))
#else
_openSwiftUIPlatformUnimplementedFailure()
#endif
}
}

// MARK: - GraphicsImage + ProtobufMessage [WIP]

extension GraphicsImage: ProtobufMessage {
package func encode(to encoder: inout ProtobufEncoder) throws {
_openSwiftUIUnimplementedFailure()
}

package init(from decoder: inout ProtobufDecoder) throws {
_openSwiftUIUnimplementedFailure()
}
}

// MARK: - GraphicsImage.Contents + Equatable

extension GraphicsImage.Contents {
package static func == (lhs: GraphicsImage.Contents, rhs: GraphicsImage.Contents) -> Bool {
switch (lhs, rhs) {
case let (.cgImage(a), .cgImage(b)): a === b
case let (.ioSurface(a), .ioSurface(b)): a === b
case let (.vectorGlyph(a), .vectorGlyph(b)): a == b
case let (.vectorLayer(a), .vectorLayer(b)): a == b
case let (.color(a), .color(b)): a == b
/* OpenSwiftUI Addition Begin */
// named is omitted on SwiftUI's implementation
case let (.named(a), .named(b)): a == b
/* OpenSwiftUI Addition End */
default: false
}
}
}

// TODO: ResolvedVectorGlyph

package struct ResolvedVectorGlyph: Equatable {
package let animator: ORBSymbolAnimator
package let layoutDirection: LayoutDirection
package let location: Image.Location
package var animatorVersion: UInt32
package var allowsContentTransitions: Bool
package var preservesVectorRepresentation: Bool

package var flipsRightToLeft: Bool {
animator.flipsRightToLeft
}
}

extension GraphicsImage {
package var bitmapOrientation: Image.Orientation {
guard case let .vectorGlyph(vectorGlyph) = contents else {
return orientation
}
return vectorGlyph.flipsRightToLeft ? orientation.mirrored : orientation
}

package func render(at targetSize: CGSize, prefersMask: Bool = false) -> CGImage? {
_openSwiftUIUnimplementedFailure()
}
}

// FIXME

package class ORBSymbolAnimator: Hashable {
var styleMask: UInt32 {
.zero
}

var flipsRightToLeft: Bool {
false
}

package func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(self))
}

package static func == (lhs: ORBSymbolAnimator, rhs: ORBSymbolAnimator) -> Bool {
lhs === rhs
}
}
Loading
Loading