Skip to content
This repository has been archived by the owner on Jul 3, 2021. It is now read-only.

Update for Swift 4.2 #49

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 13 additions & 5 deletions MetalScope.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
BFB8916F1E2E013400FA9129 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0900;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = "eje Inc.";
TargetAttributes = {
BFB891771E2E013400FA9129 = {
Expand Down Expand Up @@ -355,13 +355,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -389,12 +391,13 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -414,13 +417,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand All @@ -442,10 +447,11 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -466,12 +472,13 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Sources/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.eje-c.MetalScope";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -488,11 +495,12 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Sources/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.eje-c.MetalScope";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Sources/DeviceOrientationProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension DeviceOrientationProvider {

let queue = DispatchQueue(label: "com.eje-c.MetalScope.DeviceOrientationProvider.waitingQueue")
let timer = DispatchSource.makeTimerSource(queue: queue)
timer.scheduleRepeating(deadline: .now(), interval: .milliseconds(10))
timer.schedule(deadline: .now(), repeating: .milliseconds(10))
timer.setEventHandler {
guard let _ = self.deviceOrientation(atTime: time) else {
return
Expand Down
14 changes: 7 additions & 7 deletions Sources/InterfaceOrientationUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal final class InterfaceOrientationUpdater {

UIDevice.current.beginGeneratingDeviceOrientationNotifications()

let observer = NotificationCenter.default.addObserver(forName: .UIDeviceOrientationDidChange, object: nil, queue: .main) { [weak self] _ in
let observer = NotificationCenter.default.addObserver(forName: UIDevice.orientationDidChangeNotification, object: nil, queue: .main) { [weak self] _ in
guard UIDevice.current.orientation.isValidInterfaceOrientation, self?.isTransitioning == false else {
return
}
Expand All @@ -76,21 +76,21 @@ internal final class InterfaceOrientationUpdater {
}
}

private extension UIViewAnimationCurve {
private extension UIView.AnimationCurve {
var caMediaTimingFunction: CAMediaTimingFunction {
let name: String

switch self {
case .easeIn:
name = kCAMediaTimingFunctionEaseIn
name = CAMediaTimingFunctionName.easeIn.rawValue
case .easeOut:
name = kCAMediaTimingFunctionEaseOut
name = CAMediaTimingFunctionName.easeOut.rawValue
case .easeInOut:
name = kCAMediaTimingFunctionEaseInEaseOut
name = CAMediaTimingFunctionName.easeInEaseOut.rawValue
case .linear:
name = kCAMediaTimingFunctionLinear
name = CAMediaTimingFunctionName.linear.rawValue
}

return CAMediaTimingFunction(name: name)
return CAMediaTimingFunction(name: CAMediaTimingFunctionName(rawValue: name))
}
}
7 changes: 4 additions & 3 deletions Sources/PlayerItemRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ public final class PlayerItemRenderer {
let sourceSize = MTLSizeMake(sourceTexture.width, sourceTexture.height, sourceTexture.depth)
let destinationOrigin = MTLOriginMake(0, 0, 0)

let blitCommandEncoder = commandBuffer.makeBlitCommandEncoder()
blitCommandEncoder.copy(from: sourceTexture, sourceSlice: 0, sourceLevel: 0, sourceOrigin: sourceOrigin, sourceSize: sourceSize, to: texture, destinationSlice: 0, destinationLevel: 0, destinationOrigin: destinationOrigin)
blitCommandEncoder.endEncoding()
if let blitCommandEncoder = commandBuffer.makeBlitCommandEncoder() {
blitCommandEncoder.copy(from: sourceTexture, sourceSlice: 0, sourceLevel: 0, sourceOrigin: sourceOrigin, sourceSize: sourceSize, to: texture, destinationSlice: 0, destinationLevel: 0, destinationOrigin: destinationOrigin)
blitCommandEncoder.endEncoding()
}
}

public func hasNewPixelBuffer(atHostTime time: TimeInterval) -> Bool {
Expand Down
2 changes: 1 addition & 1 deletion Sources/RenderLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public final class RenderLoop {

private lazy var displayLink: CADisplayLink = {
let link = CADisplayLink(target: self, selector: #selector(handleDisplayLink(_:)))
link.add(to: .main, forMode: .commonModes)
link.add(to: .main, forMode: RunLoop.Mode.common)
link.isPaused = true
return link
}()
Expand Down
14 changes: 10 additions & 4 deletions Sources/StereoRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ internal final class StereoRenderer {
)
eyeTextureDescriptor.usage = .renderTarget

guard let texture = device.makeTexture(descriptor: eyeTextureDescriptor) else {
fatalError("Failed to makeTexture")
}

eyeRenderingConfigurations = [
.left: EyeRenderingConfiguration(texture: device.makeTexture(descriptor: eyeTextureDescriptor)),
.right: EyeRenderingConfiguration(texture: device.makeTexture(descriptor: eyeTextureDescriptor))
.left: EyeRenderingConfiguration(texture: texture),
.right: EyeRenderingConfiguration(texture: texture)
]
}

Expand All @@ -75,7 +79,10 @@ internal final class StereoRenderer {
for (eye, configuration) in eyeRenderingConfigurations {
semaphore.wait()

let commandBuffer = commandQueue.makeCommandBuffer()
guard
let commandBuffer = commandQueue.makeCommandBuffer(),
let blitCommandEncoder = commandBuffer.makeBlitCommandEncoder()
else { return }

rendererDelegateProxy.currentRenderingEye = eye

Expand All @@ -99,7 +106,6 @@ internal final class StereoRenderer {
destinationOrigin = MTLOrigin(x: outputTexture.width / 2, y: 0, z: 0)
}

let blitCommandEncoder = commandBuffer.makeBlitCommandEncoder()
blitCommandEncoder.copy(
from: texture,
sourceSlice: 0,
Expand Down
2 changes: 1 addition & 1 deletion Sources/StereoScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal final class StereoScene: SCNScene {

let mesh = SCNGeometry(
sources: [
SCNGeometrySource(vertices: vertices, count: vertices.count),
SCNGeometrySource(vertices: vertices),
SCNGeometrySource(texcoord: texcoord),
SCNGeometrySource(colors: colors)
],
Expand Down
5 changes: 4 additions & 1 deletion Sources/StereoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ public final class StereoView: UIView, SceneLoadable {
height: Int(textureSize.height),
mipmapped: true
)
let texture = device.makeTexture(descriptor: textureDescriptor)

guard let texture = device.makeTexture(descriptor: textureDescriptor) else {
fatalError("Failed to makeTexture")
}

self.init(stereoTexture: texture)

Expand Down
2 changes: 1 addition & 1 deletion Sources/StereoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ open class StereoViewController: UIViewController, SceneLoadable {
precondition(introductionViewUpdateTimer == nil)

let timer = DispatchSource.makeTimerSource(queue: .main)
timer.scheduleRepeating(deadline: .now() + delay, interval: interval)
timer.schedule(deadline: .now() + delay, repeating: interval)
timer.setEventHandler { [weak self] in
guard self?.isViewLoaded == true, let _ = self?.introductionView else {
return
Expand Down
29 changes: 17 additions & 12 deletions Sources/VideoScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ public final class MonoSphericalVideoScene: MonoSphericalMediaScene, VideoScene

public init(renderer: PlayerRenderer) {
self.renderer = renderer
commandQueue = renderer.device.makeCommandQueue()
guard let commandQueue = renderer.device.makeCommandQueue() else {
fatalError("Failed to makeCommandQueue()")
}
self.commandQueue = commandQueue
super.init()
renderLoop.resume()
}
Expand Down Expand Up @@ -110,12 +113,12 @@ public final class MonoSphericalVideoScene: MonoSphericalMediaScene, VideoScene

updateTextureIfNeeded()

guard let texture = playerTexture else {
return
}
guard
let texture = playerTexture,
let commandBuffer = (commandQueue ?? self.commandQueue).makeCommandBuffer()
else { return }

do {
let commandBuffer = (commandQueue ?? self.commandQueue).makeCommandBuffer()
try renderer.render(atHostTime: time, to: texture, commandBuffer: commandBuffer)
commandBuffer.commit()
} catch let error as CVError {
Expand Down Expand Up @@ -163,7 +166,10 @@ public final class StereoSphericalVideoScene: StereoSphericalMediaScene, VideoSc

public init(renderer: PlayerRenderer) {
self.renderer = renderer
commandQueue = renderer.device.makeCommandQueue()
guard let commandQueue = renderer.device.makeCommandQueue() else {
fatalError("Failed to makeCommandQueue()")
}
self.commandQueue = commandQueue
super.init()
renderLoop.resume()
}
Expand Down Expand Up @@ -202,17 +208,16 @@ public final class StereoSphericalVideoScene: StereoSphericalMediaScene, VideoSc

updateTexturesIfNeeded()

guard let playerTexture = playerTexture else {
return
}

let commandBuffer = (commandQueue ?? self.commandQueue).makeCommandBuffer()
guard
let playerTexture = playerTexture,
let commandBuffer = (commandQueue ?? self.commandQueue).makeCommandBuffer(),
let blitCommandEncoder = commandBuffer.makeBlitCommandEncoder()
else { return }

do {
try renderer.render(atHostTime: time, to: playerTexture, commandBuffer: commandBuffer)

func copyPlayerTexture(region: MTLRegion, to sphereTexture: MTLTexture) {
let blitCommandEncoder = commandBuffer.makeBlitCommandEncoder()
blitCommandEncoder.copy(
from: playerTexture,
sourceSlice: 0,
Expand Down