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.

35 changes: 35 additions & 0 deletions Sources/OpenRenderBox/Render/ORBImage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ORBImage.swift
// OpenRenderBox

#if !canImport(ObjectiveC)
public import Foundation
public import OpenCoreGraphicsShims

public struct ORBImage {
public var type: Int32
public var data: UnsafeMutableRawPointer?

public init(type: Int32 = 0, data: UnsafeMutableRawPointer? = nil) {
self.type = type
self.data = data
}

public init(_ image: CGImage) { self.init() }
public init(surface: IOSurfaceRef) { self.init() }

public static func transform(for destination: CGRect) -> CGAffineTransform { .identity }
public static func tiledTransform(pixelSize: CGSize, scale: CGFloat, origin: CGPoint, source: CGRect) -> CGAffineTransform { .identity }
}

public struct ORBImageCapInsets {
public var top, left, bottom, right: CGFloat

public init(top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0) {
self.top = top
self.left = left
self.bottom = bottom
self.right = right
}
}
#endif
60 changes: 60 additions & 0 deletions Sources/OpenRenderBox/Render/ORBShader.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// ORBShader.swift
// OpenRenderBox

#if !canImport(ObjectiveC)
public import Foundation
public import OpenRenderBoxCxx

public class ORBShaderLibrary: NSObject {
public static let standard = ORBShaderLibrary()
public static func inBundle(_ bundle: Bundle) -> ORBShaderLibrary { ORBShaderLibrary() }
public static func from(data: Data) -> ORBShaderLibrary { ORBShaderLibrary() }
public static func from(url: URL) -> ORBShaderLibrary { ORBShaderLibrary() }
}

public struct ORBShaderArgument {
public var type: UInt32 = 0
public var flags: UInt32 = 0
public var count: UInt = 0
public var bytes: UnsafeMutableRawPointer?
public var colorSpace: Int32 = 0
}

public class ORBShader: NSObject, NSCopying {
public var type: Int32 = 0
public var numberOfArguments: UInt { 0 }

public init(library: ORBShaderLibrary, function: String) {}

private override init() {}

public func copy(with zone: NSZone?) -> Any {
let copy = ORBShader()
copy.type = type
return copy
}

public func argument(at index: UInt) -> ORBShaderArgument { ORBShaderArgument() }
public func setBytes(_ bytes: UnsafeRawPointer?, at index: UInt, type: UInt32, count: UInt, flags: UInt32) {}
public func setData(_ data: Data, at index: UInt, type: UInt32, flags: UInt32) {}
public func setColorSpace(_ space: ORBColor.ColorSpace, at index: UInt) {}

public func encodedData(for delegate: (any ORBEncoderDelegate)?) throws -> Data {
throw CocoaError(.featureUnsupported)
}

public static func decodedObject(with data: Data, delegate: (any ORBDecoderDelegate)?) throws -> Any {
throw CocoaError(.featureUnsupported)
}
}

public protocol ORBEncoderDelegate: AnyObject {}
public protocol ORBDecoderDelegate: AnyObject {}

private final class EmptyArchiveDelegate: ORBEncoderDelegate, ORBDecoderDelegate {}

public func ORBArchiveDelegate(_ flags: UInt32) -> any ORBEncoderDelegate & ORBDecoderDelegate {
EmptyArchiveDelegate()
}
#endif
5 changes: 4 additions & 1 deletion Sources/OpenRenderBoxCxx/Device/ORBDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <OpenRenderBox/ORBImageRenderer.h>
#include <dispatch/dispatch.h>

@class ORBShader;
@protocol MTLCaptureScope, MTLDevice, OS_dispatch_queue;

ORB_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -44,7 +45,9 @@ ORB_ASSUME_NONNULL_BEGIN
- (instancetype)initWithDevice:(id<MTLDevice>)device;
- (nullable CGImageRef)renderImageInRect:(CGRect)rect options:(nullable id)options renderer:(nullable id /* block */)renderer;
- (void)collectResources;
- (void)compileShader:(id)shader completionQueue:(nullable id)queue handler:(nullable id /* block */)handler;
- (void)compileShader:(ORBShader *)shader
completionQueue:(nullable dispatch_queue_t)queue
handler:(void (^ _Nullable)(NSError *_Nullable error))handler;
- (BOOL)compileShader:(id)shader error:(id _Nullable * _Nullable)error;
- (nullable id)pipelineDescriptions:(nullable id)descriptions extraColorFormats:(nullable id)formats;
- (void)renderImageInRect:(CGRect)rect options:(nullable id)options renderer:(nullable id /* block */)renderer completionQueue:(nullable id)queue handler:(nullable id /* block */)handler;
Expand Down
8 changes: 8 additions & 0 deletions Sources/OpenRenderBoxCxx/Device/ORBDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ - (instancetype)initWithDevice:(id<MTLDevice>)device {
return self;
}

- (void)compileShader:(ORBShader *)shader completionQueue:(dispatch_queue_t)queue handler:(void (^)(NSError *))handler {
if (handler) {
dispatch_async(queue ?: dispatch_get_main_queue(), ^{
handler([NSError errorWithDomain:NSCocoaErrorDomain code:NSFeatureUnsupportedError userInfo:nil]);
});
}
}

@end

#endif /* ORB_OBJC_FOUNDATION */
32 changes: 32 additions & 0 deletions Sources/OpenRenderBoxCxx/Render/ORBImage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// ORBImage.h
// OpenRenderBox

#pragma once

#include <OpenRenderBox/ORBBase.h>
#if ORB_OBJC_FOUNDATION
#import <CoreGraphics/CoreGraphics.h>
#import <IOSurface/IOSurfaceRef.h>

ORB_ASSUME_NONNULL_BEGIN
ORB_EXTERN_C_BEGIN

typedef struct {
int32_t type;
void *_Nullable data;
} ORBImage;

typedef struct {
CGFloat top, left, bottom, right;
} ORBImageCapInsets;

ORB_EXPORT CGAffineTransform ORBImageSimpleTransform(CGRect destination) ORB_SWIFT_NAME(ORBImage.transform(for:));
ORB_EXPORT CGAffineTransform ORBTiledImageTransform(CGSize pixelSize, CGFloat scale, CGPoint origin, CGRect source) ORB_SWIFT_NAME(ORBImage.tiledTransform(pixelSize:scale:origin:source:));

ORB_EXPORT ORBImage ORBImageMakeCGImage(CGImageRef image) ORB_SWIFT_NAME(ORBImage.init(_:));
ORB_EXPORT ORBImage ORBImageMakeIOSurface(IOSurfaceRef surface) ORB_SWIFT_NAME(ORBImage.init(surface:));

ORB_EXTERN_C_END
ORB_ASSUME_NONNULL_END
#endif
25 changes: 25 additions & 0 deletions Sources/OpenRenderBoxCxx/Render/ORBImage.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// ORBImage.m
// OpenRenderBox

#include <OpenRenderBox/ORBImage.h>

#if ORB_OBJC_FOUNDATION

CGAffineTransform ORBImageSimpleTransform(CGRect destination) {
return CGAffineTransformIdentity;
}

CGAffineTransform ORBTiledImageTransform(CGSize pixelSize, CGFloat scale, CGPoint origin, CGRect source) {
return CGAffineTransformIdentity;
}

ORBImage ORBImageMakeCGImage(CGImageRef image) {
return (ORBImage){0};
}

ORBImage ORBImageMakeIOSurface(IOSurfaceRef surface) {
return (ORBImage){0};
}

#endif /* ORB_OBJC_FOUNDATION */
48 changes: 48 additions & 0 deletions Sources/OpenRenderBoxCxx/Render/ORBShader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// ORBShader.h
// OpenRenderBox

#pragma once

#include <OpenRenderBox/ORBColor.h>

#if ORB_OBJC_FOUNDATION
#import <Foundation/Foundation.h>
#import <OpenRenderBox/ORBDecodable.h>
#import <OpenRenderBox/ORBDecoderDelegate.h>
#import <OpenRenderBox/ORBEncodable.h>
#import <OpenRenderBox/ORBEncoderDelegate.h>

ORB_ASSUME_NONNULL_BEGIN

@interface ORBShaderLibrary : NSObject
@property (class, nonatomic, readonly) ORBShaderLibrary *defaultLibrary NS_SWIFT_NAME(standard);
+ (ORBShaderLibrary *)defaultLibraryWithBundle:(NSBundle *)bundle NS_SWIFT_NAME(inBundle(_:));
+ (ORBShaderLibrary *)libraryWithData:(NSData *)data NS_SWIFT_NAME(from(data:));
+ (ORBShaderLibrary *)libraryWithContentsOfURL:(NSURL *)url NS_SWIFT_NAME(from(url:));
@end

typedef struct {
uint32_t type;
uint32_t flags;
NSUInteger count;
void *_Nullable bytes;
int32_t colorSpace;
} ORBShaderArgument;

@interface ORBShader : NSObject <NSCopying, ORBEncodable, ORBDecodable>
@property (nonatomic) int32_t type;
@property (nonatomic, readonly) NSUInteger numberOfArguments;

- (instancetype)initWithLibrary:(ORBShaderLibrary *)library function:(NSString *)function;
- (ORBShaderArgument)argumentAtIndex:(NSUInteger)index;
- (void)setArgumentBytes:(const void *_Nullable)bytes atIndex:(NSUInteger)index type:(uint32_t)type count:(NSUInteger)count flags:(uint32_t)flags NS_SWIFT_NAME(setBytes(_:at:type:count:flags:));
- (void)setArgumentData:(NSData *)data atIndex:(NSUInteger)index type:(uint32_t)type flags:(uint32_t)flags NS_SWIFT_NAME(setData(_:at:type:flags:));
- (void)setArgumentColorSpace:(ORBColorSpace)space atIndex:(NSUInteger)index NS_SWIFT_NAME(setColorSpace(_:at:));
@end

ORB_EXTERN_C_BEGIN
ORB_EXPORT id<ORBEncoderDelegate, ORBDecoderDelegate> ORBArchiveDelegate(uint32_t flags);
ORB_EXTERN_C_END

ORB_ASSUME_NONNULL_END
#endif
68 changes: 68 additions & 0 deletions Sources/OpenRenderBoxCxx/Render/ORBShader.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// ORBShader.m
// OpenRenderBox

#include <OpenRenderBox/ORBShader.h>

#if ORB_OBJC_FOUNDATION

@implementation ORBShaderLibrary

+ (ORBShaderLibrary *)defaultLibrary {
static ORBShaderLibrary *library;
static dispatch_once_t once;
dispatch_once(&once, ^{ library = [[self alloc] init]; });
return library;
}

+ (ORBShaderLibrary *)defaultLibraryWithBundle:(NSBundle *)bundle { return [[self alloc] init]; }
+ (ORBShaderLibrary *)libraryWithData:(NSData *)data { return [[self alloc] init]; }
+ (ORBShaderLibrary *)libraryWithContentsOfURL:(NSURL *)url { return [[self alloc] init]; }

@end

@implementation ORBShader

- (instancetype)initWithLibrary:(ORBShaderLibrary *)library function:(NSString *)function {
return [super init];
}

- (id)copyWithZone:(NSZone *)zone {
ORBShader *copy = [[[self class] allocWithZone:zone] init];
copy.type = self.type;
return copy;
}

- (NSUInteger)numberOfArguments { return 0; }
- (ORBShaderArgument)argumentAtIndex:(NSUInteger)index { return (ORBShaderArgument){0}; }
- (void)setArgumentBytes:(const void *)bytes atIndex:(NSUInteger)index type:(uint32_t)type count:(NSUInteger)count flags:(uint32_t)flags {}
- (void)setArgumentData:(NSData *)data atIndex:(NSUInteger)index type:(uint32_t)type flags:(uint32_t)flags {}
- (void)setArgumentColorSpace:(ORBColorSpace)space atIndex:(NSUInteger)index {}

- (NSData *)encodedDataForDelegate:(id<ORBEncoderDelegate>)delegate error:(NSError **)error {
if (error) {
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFeatureUnsupportedError userInfo:nil];
}
return nil;
}

+ (id)decodedObjectWithData:(NSData *)data delegate:(id<ORBDecoderDelegate>)delegate error:(NSError **)error {
if (error) {
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFeatureUnsupportedError userInfo:nil];
}
return nil;
}

@end

@interface ORBEmptyArchiveDelegate : NSObject <ORBEncoderDelegate, ORBDecoderDelegate>
@end

@implementation ORBEmptyArchiveDelegate
@end

id<ORBEncoderDelegate, ORBDecoderDelegate> ORBArchiveDelegate(uint32_t flags) {
return [[ORBEmptyArchiveDelegate alloc] init];
}

#endif /* ORB_OBJC_FOUNDATION */
1 change: 1 addition & 0 deletions Sources/OpenRenderBoxCxx/include/OpenRenderBox/ORBImage.h
1 change: 1 addition & 0 deletions Sources/OpenRenderBoxCxx/include/OpenRenderBox/ORBShader.h
2 changes: 2 additions & 0 deletions Sources/OpenRenderBoxCxx/include/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ explicit module OpenRenderBoxCxx.ObjC {
header "OpenRenderBox/ORBDisplayListPredicate.h"
header "OpenRenderBox/ORBDisplayListTransform.h"
header "OpenRenderBox/ORBDrawableStatistics.h"
header "OpenRenderBox/ORBImage.h"
header "OpenRenderBox/ORBImageRenderer.h"
header "OpenRenderBox/ORBLayer.h"
header "OpenRenderBox/ORBLayerDelegate.h"
header "OpenRenderBox/ORBShader.h"
header "../Render/Private/_ORBDisplayListContents.h"
header "../Render/Private/_ORBDrawableDelegate.h"
export *
Expand Down
7 changes: 7 additions & 0 deletions Sources/OpenRenderBoxShims/ORBShims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public struct RenderBoxVendor: RawRepresentable, CaseIterable {
public typealias ORBAnimation = RBAnimation
public typealias ORBBlendMode = RBBlendMode
public typealias ORBColor = RBColor
public typealias ORBDecoderDelegate = RBDecoderDelegate
public typealias ORBDevice = RBDevice
public typealias ORBDisplayList = RBDisplayList
public typealias ORBDisplayListContents = RBDisplayListContents
Expand All @@ -35,9 +36,15 @@ public typealias ORBDisplayListPredicate = RBDisplayListPredicate
public typealias ORBDisplayListRenderKey = RBDisplayListRenderKey
public typealias ORBDisplayListTransform = RBDisplayListTransform
public typealias ORBDrawingState = RBDrawingState
public typealias ORBEncoderDelegate = RBEncoderDelegate
public typealias ORBImage = RBImage
public typealias ORBImageCapInsets = RBImageCapInsets
public typealias ORBLayer = RBLayer
public typealias ORBLayerDelegate = RBLayerDelegate
public typealias ORBMeshGradientFlags = RBMeshGradientFlags
public typealias ORBShader = RBShader
public typealias ORBShaderLibrary = RBShaderLibrary
public let ORBArchiveDelegate = RBArchiveDelegate
public let __ORBPathElementArgumentCount = __RBPathElementArgumentCount
public typealias ORBPath = RBPath
public typealias ORBPathApplyCallback = RBPathApplyCallback
Expand Down
Loading