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/Device/ORBDevice.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ORBDevice.swift
// OpenRenderBox

#if !canImport(ObjectiveC)
#if canImport(Dispatch)
public import Dispatch
#endif
public import Foundation

public class ORBDevice: NSObject {
public class func sharedDefault() -> ORBDevice? { nil }

public class func allDevices() -> [ORBDevice] { [] }

public class func isSupported() -> Bool { false }

#if canImport(Dispatch)
public func compileShader(
_ shader: ORBShader,
completionQueue queue: DispatchQueue?,
handler: ((Error?) -> Void)? = nil
) {
guard let handler else { return }
(queue ?? .main).async {
handler(CocoaError(.featureUnsupported))
}
}
#endif

public func compileShader(_ shader: ORBShader) throws {
throw CocoaError(.featureUnsupported)
}
}
#endif
20 changes: 13 additions & 7 deletions Sources/OpenRenderBoxCxx/Device/ORBDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ORB_ASSUME_NONNULL_BEGIN
@property NSUInteger backgroundGPUPriority;

/* class methods */
+ (nullable instancetype)sharedDefaultDevice;
+ (nullable instancetype)sharedDefaultDevice ORB_SWIFT_NAME(sharedDefault());
+ (NSArray<ORBDevice *> *)allDevices;
+ (BOOL)isSupported;
+ (void)setAllowsRenderingInBackground:(BOOL)background;
Expand All @@ -37,20 +37,26 @@ ORB_ASSUME_NONNULL_BEGIN
+ (BOOL)isRunningInBackground;
+ (void)setDefaultBackgroundGPUPriority:(NSUInteger)gpupriority;
+ (void)setDefaultGPUPriority:(NSUInteger)gpupriority;
+ (nullable instancetype)sharedDevice:(id<MTLDevice>)device;
+ (nullable instancetype)sharedDeviceForDisplay:(unsigned int)display;
+ (nullable instancetype)sharedDevice:(id<MTLDevice>)device ORB_SWIFT_NAME(sharedDevice(_:));
#if TARGET_OS_OSX
+ (nullable instancetype)sharedDeviceForDisplay:(unsigned int)display ORB_SWIFT_NAME(sharedDevice(forDisplay:));
#endif

/* instance methods */
- (void)dealloc;
- (instancetype)initWithDevice:(id<MTLDevice>)device;
- (nullable CGImageRef)renderImageInRect:(CGRect)rect options:(nullable id)options renderer:(nullable id /* block */)renderer;
- (void)collectResources;
- (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;

@end

@interface ORBDevice (ORBShader)

- (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;
- (BOOL)compileShader:(ORBShader *)shader error:(NSError * _Nullable * _Nullable)error;

@end

Expand Down
11 changes: 11 additions & 0 deletions Sources/OpenRenderBoxCxx/Device/ORBDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ - (instancetype)initWithDevice:(id<MTLDevice>)device {
return self;
}

@end

@implementation ORBDevice (ORBShader)

- (void)compileShader:(ORBShader *)shader completionQueue:(dispatch_queue_t)queue handler:(void (^)(NSError *))handler {
if (handler) {
dispatch_async(queue ?: dispatch_get_main_queue(), ^{
Expand All @@ -41,6 +45,13 @@ - (void)compileShader:(ORBShader *)shader completionQueue:(dispatch_queue_t)queu
}
}

- (BOOL)compileShader:(ORBShader *)shader error:(NSError **)error {
if (error) {
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFeatureUnsupportedError userInfo:nil];
}
return NO;
}

@end

#endif /* ORB_OBJC_FOUNDATION */
Loading