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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <RenderBox/RBImageRenderer.h>
#include <dispatch/dispatch.h>

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

RB_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -44,7 +45,9 @@ RB_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:(RBShader *)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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// RBImage.h
// RenderBox

#pragma once

#include <RenderBox/RBBase.h>

#if RB_OBJC_FOUNDATION

#include <CoreGraphics/CoreGraphics.h>
#include <IOSurface/IOSurfaceRef.h>
#include <Metal/MTLTexture.h>
#include <RenderBox/RBSurface.h>

RB_ASSUME_NONNULL_BEGIN
RB_IMPLICIT_BRIDGING_ENABLED
RB_EXTERN_C_BEGIN

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

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

RB_EXPORT CGAffineTransform RBImageTransform(CGSize pixelSize, CGRect destination, CGRect source) RB_SWIFT_NAME(RBImage.transform(pixelSize:destination:source:));
RB_EXPORT CGAffineTransform RBImageSimpleTransform(CGRect destination) RB_SWIFT_NAME(RBImage.transform(for:));
RB_EXPORT CGAffineTransform RBTiledImageTransform(CGSize pixelSize, CGFloat scale, CGPoint origin, CGRect source) RB_SWIFT_NAME(RBImage.tiledTransform(pixelSize:scale:origin:source:));

// These factories borrow their input. Keep the source alive while using the image.
RB_EXPORT RBImage RBImageMakeCGImage(CGImageRef image) RB_SWIFT_NAME(RBImage.init(_:));
RB_EXPORT RBImage RBImageMakeIOSurface(IOSurfaceRef surface) RB_SWIFT_NAME(RBImage.init(surface:));
RB_EXPORT RBImage RBImageMakeRBSurface(RBSurface *surface) RB_SWIFT_NAME(RBImage.init(renderBoxSurface:));
RB_EXPORT RBImage RBImageMakeMTLTexture(id<MTLTexture> texture) RB_SWIFT_NAME(RBImage.init(texture:));

// Returns a retained image when the source is a CGImage.
RB_EXPORT CGImageRef _Nullable RBImageCopyCGImage(RBImage image) CF_RETURNS_RETAINED RB_SWIFT_NAME(RBImage.copyCGImage(self:));

RB_EXTERN_C_END
RB_IMPLICIT_BRIDGING_DISABLED
RB_ASSUME_NONNULL_END

#endif /* RB_OBJC_FOUNDATION */
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// RBShader.h
// RenderBox

#pragma once

#include <RenderBox/RBColor.h>

#if RB_OBJC_FOUNDATION

#include <CoreGraphics/CGAffineTransform.h>
#include <CoreImage/CIFilter.h>
#include <Foundation/Foundation.h>
#include <RenderBox/RBDecodable.h>
#include <RenderBox/RBDecoderDelegate.h>
#include <RenderBox/RBEncodable.h>
#include <RenderBox/RBEncoderDelegate.h>
#include <RenderBox/RBShaderLibrary.h>

RB_ASSUME_NONNULL_BEGIN

@class RBShader;

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

typedef CIFilter *_Nullable (^RBShaderCIFilterProvider)(RBShader *shader, CGRect bounds);

@interface RBShader : NSObject <NSCopying, RBEncodable, RBDecodable>

@property (nonatomic, readonly, nullable) RBShaderLibrary *library;
@property (nonatomic) int32_t type;
@property (nonatomic, copy, readonly, nullable) NSString *function;
@property (nonatomic, readonly) NSUInteger numberOfArguments;
@property (nonatomic, copy, nullable) RBShaderCIFilterProvider CIFilterProvider API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));
@property (nonatomic) CGAffineTransform CIFilterCTM API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));

- (instancetype)initWithLibrary:(RBShaderLibrary *)library function:(NSString *)function;
- (instancetype)initWithSystemShader:(NSString *)function API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));

- (void)removeAllArguments;
// The shader owns the argument bytes. Read them before modifying the arguments.
- (RBShaderArgument)argumentAtIndex:(NSUInteger)index;
- (float)argumentHeadroomAtIndex:(NSUInteger)index API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));
- (void)setArgumentHeadroom:(float)headroom atIndex:(NSUInteger)index API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));
- (void)setArgumentBytes:(const void *_Nullable)bytes atIndex:(NSUInteger)index type:(uint32_t)type count:(NSUInteger)count flags:(uint32_t)flags RB_SWIFT_NAME(setBytes(_:at:type:count:flags:));
- (void)setArgumentData:(NSData *)data atIndex:(NSUInteger)index type:(uint32_t)type flags:(uint32_t)flags RB_SWIFT_NAME(setData(_:at:type:flags:));
- (void)setArgumentColorSpace:(RBColorSpace)space atIndex:(NSUInteger)index RB_SWIFT_NAME(setColorSpace(_:at:));

@end

RB_EXTERN_C_BEGIN
RB_EXPORT id<RBEncoderDelegate, RBDecoderDelegate> RBArchiveDelegate(uint32_t flags);
RB_EXTERN_C_END

RB_ASSUME_NONNULL_END

#endif /* RB_OBJC_FOUNDATION */
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// RBShaderLibrary.h
// RenderBox

#pragma once

#include <RenderBox/RBBase.h>

#if RB_OBJC_FOUNDATION

#include <Foundation/Foundation.h>
#include <Metal/MTLLibrary.h>

RB_ASSUME_NONNULL_BEGIN

@interface RBShaderLibrary : NSObject

@property (class, nonatomic, readonly) RBShaderLibrary *defaultLibrary RB_SWIFT_NAME(standard);
@property (class, nonatomic, readonly) RBShaderLibrary *systemLibrary RB_SWIFT_NAME(system) API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));

@property (nonatomic, readonly, nullable) NSBundle *bundle;
@property (nonatomic, copy, readonly, nullable) NSData *data;
@property (nonatomic, copy, readonly, nullable) NSURL *URL;
@property (nonatomic, readonly, nullable) id<MTLLibrary> metalLibrary;
@property (nonatomic, copy, readonly, nullable) NSString *source;
@property (nonatomic) int32_t ABIVersion API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));
@property (nonatomic, copy, nullable) NSURL *binaryArchiveURL API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));

+ (RBShaderLibrary *)defaultLibraryWithBundle:(NSBundle *)bundle RB_SWIFT_NAME(inBundle(_:));
+ (RBShaderLibrary *)libraryWithData:(NSData *)data RB_SWIFT_NAME(from(data:));
+ (RBShaderLibrary *)libraryWithContentsOfURL:(NSURL *)url RB_SWIFT_NAME(from(url:));
+ (RBShaderLibrary *)libraryWithMetalLibrary:(id<MTLLibrary>)library RB_SWIFT_NAME(from(metalLibrary:));
+ (RBShaderLibrary *)libraryWithSource:(NSString *)source RB_SWIFT_NAME(from(source:));

- (uint32_t)addErrorHandler:(void (^)(NSError *error))handler;
- (void)removeErrorHandler:(uint32_t)token;

@end

RB_ASSUME_NONNULL_END

#endif /* RB_OBJC_FOUNDATION */
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// RBSurface.h
// RenderBox

#pragma once

#include <RenderBox/RBBase.h>

#if RB_OBJC_FOUNDATION

#include <Foundation/Foundation.h>

@interface RBSurface : NSObject
@end

#endif /* RB_OBJC_FOUNDATION */
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
#include <RenderBox/RBEncodable.h>
#include <RenderBox/RBEncoderDelegate.h>
#include <RenderBox/RBEncoderSet.h>
#include <RenderBox/RBImage.h>
#include <RenderBox/RBImageRenderer.h>
#include <RenderBox/RBLayer.h>
#include <RenderBox/RBLayerDelegate.h>
#include <RenderBox/RBMeshGradientFlags.h>
#include <RenderBox/RBPath.h>
#include <RenderBox/RBPathCallbacks.h>
#include <RenderBox/RBPathStorage.h>
#include <RenderBox/RBShader.h>
#include <RenderBox/RBShaderLibrary.h>
#include <RenderBox/RBSurface.h>
#include <RenderBox/RBSymbolAnimator.h>
#include <RenderBox/RBSymbolAnimation.h>
#include <RenderBox/RBSymbolAnimatorObserver.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <RenderBox/RBImageRenderer.h>
#include <dispatch/dispatch.h>

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

RB_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -44,7 +45,9 @@ RB_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:(RBShader *)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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// RBImage.h
// RenderBox

#pragma once

#include <RenderBox/RBBase.h>

#if RB_OBJC_FOUNDATION

#include <CoreGraphics/CoreGraphics.h>
#include <IOSurface/IOSurfaceRef.h>
#include <Metal/MTLTexture.h>
#include <RenderBox/RBSurface.h>

RB_ASSUME_NONNULL_BEGIN
RB_IMPLICIT_BRIDGING_ENABLED
RB_EXTERN_C_BEGIN

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

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

RB_EXPORT CGAffineTransform RBImageTransform(CGSize pixelSize, CGRect destination, CGRect source) RB_SWIFT_NAME(RBImage.transform(pixelSize:destination:source:));
RB_EXPORT CGAffineTransform RBImageSimpleTransform(CGRect destination) RB_SWIFT_NAME(RBImage.transform(for:));
RB_EXPORT CGAffineTransform RBTiledImageTransform(CGSize pixelSize, CGFloat scale, CGPoint origin, CGRect source) RB_SWIFT_NAME(RBImage.tiledTransform(pixelSize:scale:origin:source:));

// These factories borrow their input. Keep the source alive while using the image.
RB_EXPORT RBImage RBImageMakeCGImage(CGImageRef image) RB_SWIFT_NAME(RBImage.init(_:));
RB_EXPORT RBImage RBImageMakeIOSurface(IOSurfaceRef surface) RB_SWIFT_NAME(RBImage.init(surface:));
RB_EXPORT RBImage RBImageMakeRBSurface(RBSurface *surface) RB_SWIFT_NAME(RBImage.init(renderBoxSurface:));
RB_EXPORT RBImage RBImageMakeMTLTexture(id<MTLTexture> texture) RB_SWIFT_NAME(RBImage.init(texture:));

// Returns a retained image when the source is a CGImage.
RB_EXPORT CGImageRef _Nullable RBImageCopyCGImage(RBImage image) CF_RETURNS_RETAINED RB_SWIFT_NAME(RBImage.copyCGImage(self:));

RB_EXTERN_C_END
RB_IMPLICIT_BRIDGING_DISABLED
RB_ASSUME_NONNULL_END

#endif /* RB_OBJC_FOUNDATION */
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// RBShader.h
// RenderBox

#pragma once

#include <RenderBox/RBColor.h>

#if RB_OBJC_FOUNDATION

#include <CoreGraphics/CGAffineTransform.h>
#include <CoreImage/CIFilter.h>
#include <Foundation/Foundation.h>
#include <RenderBox/RBDecodable.h>
#include <RenderBox/RBDecoderDelegate.h>
#include <RenderBox/RBEncodable.h>
#include <RenderBox/RBEncoderDelegate.h>
#include <RenderBox/RBShaderLibrary.h>

RB_ASSUME_NONNULL_BEGIN

@class RBShader;

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

typedef CIFilter *_Nullable (^RBShaderCIFilterProvider)(RBShader *shader, CGRect bounds);

@interface RBShader : NSObject <NSCopying, RBEncodable, RBDecodable>

@property (nonatomic, readonly, nullable) RBShaderLibrary *library;
@property (nonatomic) int32_t type;
@property (nonatomic, copy, readonly, nullable) NSString *function;
@property (nonatomic, readonly) NSUInteger numberOfArguments;
@property (nonatomic, copy, nullable) RBShaderCIFilterProvider CIFilterProvider API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));
@property (nonatomic) CGAffineTransform CIFilterCTM API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));

- (instancetype)initWithLibrary:(RBShaderLibrary *)library function:(NSString *)function;
- (instancetype)initWithSystemShader:(NSString *)function API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));

- (void)removeAllArguments;
// The shader owns the argument bytes. Read them before modifying the arguments.
- (RBShaderArgument)argumentAtIndex:(NSUInteger)index;
- (float)argumentHeadroomAtIndex:(NSUInteger)index API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));
- (void)setArgumentHeadroom:(float)headroom atIndex:(NSUInteger)index API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));
- (void)setArgumentBytes:(const void *_Nullable)bytes atIndex:(NSUInteger)index type:(uint32_t)type count:(NSUInteger)count flags:(uint32_t)flags RB_SWIFT_NAME(setBytes(_:at:type:count:flags:));
- (void)setArgumentData:(NSData *)data atIndex:(NSUInteger)index type:(uint32_t)type flags:(uint32_t)flags RB_SWIFT_NAME(setData(_:at:type:flags:));
- (void)setArgumentColorSpace:(RBColorSpace)space atIndex:(NSUInteger)index RB_SWIFT_NAME(setColorSpace(_:at:));

@end

RB_EXTERN_C_BEGIN
RB_EXPORT id<RBEncoderDelegate, RBDecoderDelegate> RBArchiveDelegate(uint32_t flags);
RB_EXTERN_C_END

RB_ASSUME_NONNULL_END

#endif /* RB_OBJC_FOUNDATION */
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// RBShaderLibrary.h
// RenderBox

#pragma once

#include <RenderBox/RBBase.h>

#if RB_OBJC_FOUNDATION

#include <Foundation/Foundation.h>
#include <Metal/MTLLibrary.h>

RB_ASSUME_NONNULL_BEGIN

@interface RBShaderLibrary : NSObject

@property (class, nonatomic, readonly) RBShaderLibrary *defaultLibrary RB_SWIFT_NAME(standard);
@property (class, nonatomic, readonly) RBShaderLibrary *systemLibrary RB_SWIFT_NAME(system) API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));

@property (nonatomic, readonly, nullable) NSBundle *bundle;
@property (nonatomic, copy, readonly, nullable) NSData *data;
@property (nonatomic, copy, readonly, nullable) NSURL *URL;
@property (nonatomic, readonly, nullable) id<MTLLibrary> metalLibrary;
@property (nonatomic, copy, readonly, nullable) NSString *source;
@property (nonatomic) int32_t ABIVersion API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));
@property (nonatomic, copy, nullable) NSURL *binaryArchiveURL API_AVAILABLE(macos(26.0), ios(26.0), visionos(26.0));

+ (RBShaderLibrary *)defaultLibraryWithBundle:(NSBundle *)bundle RB_SWIFT_NAME(inBundle(_:));
+ (RBShaderLibrary *)libraryWithData:(NSData *)data RB_SWIFT_NAME(from(data:));
+ (RBShaderLibrary *)libraryWithContentsOfURL:(NSURL *)url RB_SWIFT_NAME(from(url:));
+ (RBShaderLibrary *)libraryWithMetalLibrary:(id<MTLLibrary>)library RB_SWIFT_NAME(from(metalLibrary:));
+ (RBShaderLibrary *)libraryWithSource:(NSString *)source RB_SWIFT_NAME(from(source:));

- (uint32_t)addErrorHandler:(void (^)(NSError *error))handler;
- (void)removeErrorHandler:(uint32_t)token;

@end

RB_ASSUME_NONNULL_END

#endif /* RB_OBJC_FOUNDATION */
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// RBSurface.h
// RenderBox

#pragma once

#include <RenderBox/RBBase.h>

#if RB_OBJC_FOUNDATION

#include <Foundation/Foundation.h>

@interface RBSurface : NSObject
@end

#endif /* RB_OBJC_FOUNDATION */
Loading
Loading