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.

38 changes: 38 additions & 0 deletions Sources/OpenRenderBoxCxx/Device/ORBDevice.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// ORBDevice.mm
// OpenRenderBox

#include <OpenRenderBoxObjC/Device/ORBDevice.h>

#if ORB_OBJC_FOUNDATION

#include <Foundation/Foundation.h>

@implementation ORBDevice

+ (id)sharedDefaultDevice {
// TODO
return nil;
}

+ (id)allDevices {
// TODO
return nil;
}

+ (BOOL)isSupported {
id device = [self sharedDefaultDevice];
return device != nil;
}

- (instancetype)initWithDevice:(id<MTLDevice>)device {
self = [super init];
if (self) {
// TODO
}
return self;
}

@end

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

#include <OpenRenderBoxObjC/Render/ORBLayer.h>

#if ORB_OBJC_FOUNDATION

@implementation ORBLayer

// TODO

@end

#endif /* ORB_OBJC_FOUNDATION */
8 changes: 4 additions & 4 deletions Sources/OpenRenderBoxCxx/include/OpenRenderBox/ORBBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@
#define ORB_EXPORT CF_EXPORT
#define ORB_BRIDGED_TYPE CF_BRIDGED_TYPE

#if ORB_TARGET_OS_DARWIN && __ORBJC__
#define ORB_ORBJC_FOUNDATION 1
#if ORB_TARGET_OS_DARWIN && __OBJC__
#define ORB_OBJC_FOUNDATION 1
#else
#define ORB_ORBJC_FOUNDATION 0
#endif /* TARGET_OS_DARWIN && __ORBJC__ */
#define ORB_OBJC_FOUNDATION 0
#endif /* TARGET_OS_DARWIN && __OBJC__ */

#if !ORB_TRRET_OS_DARWIN
#include "CFCGTypes.h"
Expand Down
23 changes: 23 additions & 0 deletions Sources/OpenRenderBoxCxx/include/OpenRenderBox/ORBColor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// ORBColor.h
// OpenRenderBox

#pragma once

#include <OpenRenderBox/ORBBase.h>

ORB_ASSUME_NONNULL_BEGIN

ORB_EXTERN_C_BEGIN

typedef struct ORBColor {
float red;
float green;
float blue;
float alpha;
} ORBColor;

ORB_EXTERN_C_END

ORB_ASSUME_NONNULL_END

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <OpenRenderBox/ORBBase.h>
#include <OpenRenderBox/ORBColor.h>
#include <OpenRenderBox/ORBPath.h>
#include <OpenRenderBox/ORBPathCallbacks.h>
#include <OpenRenderBox/ORBPathStorage.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// ORBDevice.hpp
// OpenRenderBoxCxx

namespace ORB {

// WIP
class Device {

};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ namespace ORB {
void precondition_failure(const char *format, ...) __cold __dead2;
void non_fatal_precondition_failure(const char *format, ...);
} /* ORB */

Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ os_log_t error_log();
ORB_ASSUME_NONNULL_END

#endif /* ORB_TARGET_OS_DARWIN */

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// ORBDevice.h
// OpenRenderBox

#pragma once

#include <OpenRenderBox/ORBBase.h>

#if ORB_OBJC_FOUNDATION

#include <Foundation/Foundation.h>
#include <Metal/Metal.h>
#include <OpenRenderBoxObjC/Render/ORBImageRenderer.h>
#include <dispatch/dispatch.h>

@protocol MTLCaptureScope, MTLDevice, OS_dispatch_queue;

ORB_ASSUME_NONNULL_BEGIN

@interface ORBDevice: NSObject <ORBImageRenderer>

@property (readonly, nonatomic) id<MTLDevice> device;
@property (readonly, nonatomic) NSObject<OS_dispatch_queue> *queue;
@property (readonly, nonatomic, nullable) id<MTLCaptureScope> captureScope;
@property NSUInteger GPUPriority;
@property NSUInteger backgroundGPUPriority;

/* class methods */
+ (nullable instancetype)sharedDefaultDevice;
+ (NSArray<ORBDevice *> *)allDevices;
+ (BOOL)isSupported;
+ (void)setAllowsRenderingInBackground:(BOOL)background;
+ (BOOL)allowsRenderingInBackground;
+ (NSUInteger)defaultBackgroundGPUPriority;
+ (NSUInteger)defaultGPUPriority;
+ (BOOL)isRunningInBackground;
+ (void)setDefaultBackgroundGPUPriority:(NSUInteger)gpupriority;
+ (void)setDefaultGPUPriority:(NSUInteger)gpupriority;
+ (nullable instancetype)sharedDevice:(id<MTLDevice>)device;
+ (nullable instancetype)sharedDeviceForDisplay:(unsigned int)display;

/* 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;
- (void)compileShader:(id)shader completionQueue:(nullable id)queue handler:(nullable id /* block */)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;

@end

ORB_ASSUME_NONNULL_END

#endif /* ORB_OBJC_FOUNDATION */
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// ORBDrawableStatistics.h
// OpenRenderBox

#pragma once

#include <OpenRenderBox/ORBBase.h>

#if ORB_OBJC_FOUNDATION

#include <Foundation/Foundation.h>

ORB_ASSUME_NONNULL_BEGIN

@protocol ORBDrawableStatistics

@required

@property (readonly, copy, nonatomic, nullable) NSDictionary *statistics;
@property (copy, nonatomic, nullable) id /* block */ statisticsHandler;

- (void)resetStatistics:(NSUInteger)statistics alpha:(double)alpha;

@end

ORB_ASSUME_NONNULL_END

#endif /* ORB_OBJC_FOUNDATION */
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// ORBImageRenderer.h
// OpenRenderBox

#pragma once

#include <OpenRenderBox/ORBBase.h>

#if ORB_OBJC_FOUNDATION

#include <Foundation/Foundation.h>
#include <CoreGraphics/CoreGraphics.h>

ORB_ASSUME_NONNULL_BEGIN

@protocol ORBImageRenderer <NSObject>

@required

- (nullable CGImageRef)renderImageInRect:(CGRect)rect options:(nullable id)options renderer:(nullable id /* block */)renderer;
- (void)renderImageInRect:(CGRect)rect options:(nullable id)options renderer:(nullable id /* block */)renderer completionQueue:(nullable id)queue handler:(nullable id /* block */)handler;

@end

ORB_ASSUME_NONNULL_END

#endif /* ORB_OBJC_FOUNDATION */
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// ORBLayer.h
// OpenRenderBox

#pragma once

#include <OpenRenderBox/ORBBase.h>

#if ORB_OBJC_FOUNDATION

#include <OpenRenderBoxObjC/Device/ORBDevice.h>
#include <OpenRenderBoxObjC/Render/ORBDrawableStatistics.h>
#include <OpenRenderBox/ORBColor.h>

//#include "RBImageQueueLayer.h"
//#include "RBSurfaceContentsLayer.h"
//#include "_RBDrawableDelegate-Protocol.h"
//#include "_RBSharedSurfaceOwner-Protocol.h"

#include <QuartzCore/QuartzCore.h>
#include <Foundation/Foundation.h>

@class CAContext, CALayer;

ORB_ASSUME_NONNULL_BEGIN

@interface ORBLayer: CALayer </*_RBDrawableDelegate, _RBSharedSurfaceOwner,*/ ORBDrawableStatistics>

@property (retain, nonatomic, nullable) ORBDevice *device;
@property (nonatomic) BOOL rendersAsynchronously;
@property (nonatomic) int colorMode;
@property (nonatomic) BOOL promotesFramebuffer;
@property (nonatomic) NSUInteger pixelFormat;
@property (nonatomic) BOOL clearsBackground;
@property (nonatomic) ORBColor clearColor;
@property (nonatomic) NSInteger maxDrawableCount;
@property (nonatomic) BOOL allowsPackedDrawable;
@property (nonatomic) BOOL allowsBottomLeftOrigin;
@property (readonly, nonatomic, getter=isDrawableAvailable) BOOL drawableAvailable;
@property (nonatomic) BOOL needsSynchronousUpdate;
@property (readonly) NSUInteger hash;
@property (readonly) Class superclass;
@property (readonly, copy) NSString *description;
@property (readonly, copy, nullable) NSString *debugDescription;
@property (readonly, copy, nonatomic, nullable) NSDictionary *statistics;
@property (copy, nonatomic, nullable) id /* block */ statisticsHandler;

/* class methods */
+ (nullable id)defaultValueForKey:(NSString *)key;

/* instance methods */
- (void)dealloc;
- (instancetype)init;
- (nullable instancetype)initWithCoder:(NSCoder *)coder;
- (void)display;
- (void)layoutSublayers;
- (void)displayIfNeeded;
- (void)_renderForegroundInContext:(CGContextRef)context;
- (nullable id<CAAction>)actionForKey:(NSString *)key;
- (instancetype)initWithLayer:(id)layer;
- (BOOL)isDrawableAvailable;
- (void)layerDidBecomeVisible:(BOOL)visible;
- (void)renderInContext:(CGContextRef)context;
- (void)setBounds:(CGRect)bounds;
- (void)setContents:(nullable id)contents;
- (void)_RBDrawableStatisticsDidChange;
- (void)_moveSubsurface:(void *)subsurface;
- (BOOL)_willMoveSubsurface:(unsigned int)subsurface;
- (void)copyImageInRect:(CGRect)rect options:(nullable id)options completionQueue:(nullable id)queue handler:(nullable id /* block */)handler;
- (BOOL)displayWithBounds:(CGRect)bounds callback:(nullable id /* block */)callback;
- (void)drawInDisplayList:(nullable id)list;
- (void)resetStatistics:(NSUInteger)statistics alpha:(double)alpha;
- (void)waitUntilAsyncRenderingCompleted;

@end

ORB_ASSUME_NONNULL_END

#endif
6 changes: 6 additions & 0 deletions Sources/OpenRenderBoxCxx/include/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ module OpenRenderBoxCxx.Util {
umbrella "OpenRenderBoxCxx/Util"
export *
}

module OpenRenderBoxCxx.ObjC {
requires objc
umbrella "OpenRenderBoxObjC"
export *
}
5 changes: 4 additions & 1 deletion Sources/OpenRenderBoxShims/Export.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

#if OPENRENDERBOX_RENDERBOX
@_exported public import RenderBox
public typealias ORBUUID = RBUUID
public typealias ORBColor = RBColor
public typealias ORBDevice = RBDevice
public typealias ORBLayer = RBLayer
public typealias ORBPath = RBPath
public typealias ORBUUID = RBUUID
public let renderBoxEnabled = true
#else
@_exported import OpenRenderBox
Expand Down
34 changes: 34 additions & 0 deletions Tests/OpenRenderBoxCompatibilityTests/DeviceTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// DeviceTests.swift
// OpenRenderBoxCompatibilityTests

import Testing

#if canImport(Darwin)

@MainActor
@Suite(.enabled(if: compatibilityTestEnabled))
struct DeviceTests {
@Test
func classMethods() {
let device = ORBDevice.sharedDefault()
#expect(device != nil)

let devices = ORBDevice.allDevices()
#expect(!devices.isEmpty)

let supported = ORBDevice.isSupported()
#expect(supported == true)

let priority = ORBDevice.defaultGPUPriority()
#expect(priority >= 0)

let backgroundPriority = ORBDevice.defaultBackgroundGPUPriority()
#expect(backgroundPriority >= 0)

let _ = ORBDevice.allowsRenderingInBackground()
}
}

#endif

Loading