-
Notifications
You must be signed in to change notification settings - Fork 58
Update GraphicsImage and ResolvedImage #723
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
Merged
+659
−65
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e5d5e74
Update GraphicsImage
Kyle-Ye dc25cfc
Update ShapeStyleResolverMode
Kyle-Ye 9e57be2
Update GraphicImage API
Kyle-Ye 6f56f34
Fix Equatable issue
Kyle-Ye 662b501
Update GraphicImage implementation
Kyle-Ye bad5ffa
Implement bitmapOrientation
Kyle-Ye a832d03
Update Image.Resolved
Kyle-Ye 580caa0
Add missing resolver logic
Kyle-Ye 2078ab6
Update ImageResolutionContext
Kyle-Ye 51990e5
Complete CGImageProvider
Kyle-Ye eb1eeaf
Add ImageAccessibilityProvider
Kyle-Ye 7cb04f1
Fix bundle access
Kyle-Ye 0ab2964
Fix IOSurfaceRef issue
Kyle-Ye 16ee4e9
Fix VariableBlurStyleTests compile issue
Kyle-Ye a6ab412
Fix test case failure
Kyle-Ye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.