diff --git a/.swift-version b/.swift-version index 8c50098..819e07a 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.1 +5.0 diff --git a/MetalScope.podspec b/MetalScope.podspec index b6d8886..98cbe6d 100644 --- a/MetalScope.podspec +++ b/MetalScope.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MetalScope' - s.version = '0.16.0' + s.version = '0.19.0' s.summary = 'Metal-backed 360° panorama view for iOS' s.homepage = 'https://github.com/ejeinc/MetalScope' diff --git a/MetalScope.xcodeproj/project.pbxproj b/MetalScope.xcodeproj/project.pbxproj index 7d830cd..fe1ff76 100644 --- a/MetalScope.xcodeproj/project.pbxproj +++ b/MetalScope.xcodeproj/project.pbxproj @@ -258,22 +258,23 @@ BFB8916F1E2E013400FA9129 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1020; ORGANIZATIONNAME = "eje Inc."; TargetAttributes = { BFB891771E2E013400FA9129 = { CreatedOnToolsVersion = 8.2.1; - LastSwiftMigration = 0820; + LastSwiftMigration = 1020; ProvisioningStyle = Automatic; }; }; }; buildConfigurationList = BFB891721E2E013400FA9129 /* Build configuration list for PBXProject "MetalScope" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = BFB8916E1E2E013400FA9129; productRefGroup = BFB891791E2E013400FA9129 /* Products */; @@ -355,6 +356,7 @@ 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; @@ -362,6 +364,7 @@ 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; @@ -395,6 +398,7 @@ SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -414,6 +418,7 @@ 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; @@ -421,6 +426,7 @@ 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; @@ -446,6 +452,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -471,7 +478,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -492,7 +499,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.eje-c.MetalScope"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/MetalScope.xcodeproj/xcshareddata/xcschemes/MetalScope.xcscheme b/MetalScope.xcodeproj/xcshareddata/xcschemes/MetalScope.xcscheme index acbc580..6f13c81 100644 --- a/MetalScope.xcodeproj/xcshareddata/xcschemes/MetalScope.xcscheme +++ b/MetalScope.xcodeproj/xcshareddata/xcschemes/MetalScope.xcscheme @@ -1,6 +1,6 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.16.0 + 0.19.0 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass diff --git a/Sources/InterfaceOrientationUpdater.swift b/Sources/InterfaceOrientationUpdater.swift index f7d3873..e9001de 100644 --- a/Sources/InterfaceOrientationUpdater.swift +++ b/Sources/InterfaceOrientationUpdater.swift @@ -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 } @@ -76,21 +76,33 @@ internal final class InterfaceOrientationUpdater { } } -private extension UIViewAnimationCurve { +private extension UIView.AnimationCurve { var caMediaTimingFunction: CAMediaTimingFunction { let name: String switch self { case .easeIn: - name = kCAMediaTimingFunctionEaseIn + name = convertFromCAMediaTimingFunctionName(CAMediaTimingFunctionName.easeIn) case .easeOut: - name = kCAMediaTimingFunctionEaseOut + name = convertFromCAMediaTimingFunctionName(CAMediaTimingFunctionName.easeOut) case .easeInOut: - name = kCAMediaTimingFunctionEaseInEaseOut + name = convertFromCAMediaTimingFunctionName(CAMediaTimingFunctionName.easeInEaseOut) case .linear: - name = kCAMediaTimingFunctionLinear + name = convertFromCAMediaTimingFunctionName(CAMediaTimingFunctionName.linear) + @unknown default: + name = convertFromCAMediaTimingFunctionName(CAMediaTimingFunctionName.easeIn) } - return CAMediaTimingFunction(name: name) + return CAMediaTimingFunction(name: convertToCAMediaTimingFunctionName(name)) } } + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertFromCAMediaTimingFunctionName(_ input: CAMediaTimingFunctionName) -> String { + return input.rawValue +} + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertToCAMediaTimingFunctionName(_ input: String) -> CAMediaTimingFunctionName { + return CAMediaTimingFunctionName(rawValue: input) +} diff --git a/Sources/OrientationIndicator.swift b/Sources/OrientationIndicator.swift index a03bc13..783d2b1 100644 --- a/Sources/OrientationIndicator.swift +++ b/Sources/OrientationIndicator.swift @@ -15,8 +15,7 @@ public protocol OrientationIndicatorDataSource: class { } public protocol OrientationIndicator { - weak var dataSource: OrientationIndicatorDataSource? { get set } - + var dataSource: OrientationIndicatorDataSource? { get set } func updateOrientation() } diff --git a/Sources/PanoramaView.swift b/Sources/PanoramaView.swift index b2e1ab2..06985e6 100644 --- a/Sources/PanoramaView.swift +++ b/Sources/PanoramaView.swift @@ -129,28 +129,28 @@ extension PanoramaView { } } - public func snapshot() -> UIImage { + @objc public func snapshot() -> UIImage { return scnView.snapshot() } - public var panGestureRecognizer: UIPanGestureRecognizer { + @objc public var panGestureRecognizer: UIPanGestureRecognizer { return panGestureManager.gestureRecognizer } - public func updateInterfaceOrientation() { + @objc public func updateInterfaceOrientation() { interfaceOrientationUpdater.updateInterfaceOrientation() } - public func updateInterfaceOrientation(with transitionCoordinator: UIViewControllerTransitionCoordinator) { + @objc public func updateInterfaceOrientation(with transitionCoordinator: UIViewControllerTransitionCoordinator) { interfaceOrientationUpdater.updateInterfaceOrientation(with: transitionCoordinator) } - public func setNeedsResetRotation(animated: Bool = false) { + @objc public func setNeedsResetRotation(animated: Bool = false) { panGestureManager.stopAnimations() orientationNode.setNeedsResetRotation(animated: animated) } - public func setNeedsResetRotation(_ sender: Any?) { + @objc public func setNeedsResetRotation(_ sender: Any?) { setNeedsResetRotation(animated: true) } } diff --git a/Sources/PlayerItemRenderer.swift b/Sources/PlayerItemRenderer.swift index f422bd8..ec3c1cf 100644 --- a/Sources/PlayerItemRenderer.swift +++ b/Sources/PlayerItemRenderer.swift @@ -121,8 +121,8 @@ public final class PlayerItemRenderer { 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() + 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 { diff --git a/Sources/RenderLoop.swift b/Sources/RenderLoop.swift index f95f829..5da6eec 100644 --- a/Sources/RenderLoop.swift +++ b/Sources/RenderLoop.swift @@ -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 }() diff --git a/Sources/StereoRenderer.swift b/Sources/StereoRenderer.swift index 3fd4208..7bff619 100644 --- a/Sources/StereoRenderer.swift +++ b/Sources/StereoRenderer.swift @@ -52,8 +52,8 @@ internal final class StereoRenderer { eyeTextureDescriptor.usage = .renderTarget eyeRenderingConfigurations = [ - .left: EyeRenderingConfiguration(texture: device.makeTexture(descriptor: eyeTextureDescriptor)), - .right: EyeRenderingConfiguration(texture: device.makeTexture(descriptor: eyeTextureDescriptor)) + .left: EyeRenderingConfiguration(texture: device.makeTexture(descriptor: eyeTextureDescriptor)!), + .right: EyeRenderingConfiguration(texture: device.makeTexture(descriptor: eyeTextureDescriptor)!) ] } @@ -75,7 +75,7 @@ internal final class StereoRenderer { for (eye, configuration) in eyeRenderingConfigurations { semaphore.wait() - let commandBuffer = commandQueue.makeCommandBuffer() + guard let commandBuffer = commandQueue.makeCommandBuffer()else { return} rendererDelegateProxy.currentRenderingEye = eye @@ -99,7 +99,7 @@ internal final class StereoRenderer { destinationOrigin = MTLOrigin(x: outputTexture.width / 2, y: 0, z: 0) } - let blitCommandEncoder = commandBuffer.makeBlitCommandEncoder() + guard let blitCommandEncoder = commandBuffer.makeBlitCommandEncoder() else { return} blitCommandEncoder.copy( from: texture, sourceSlice: 0, diff --git a/Sources/StereoScene.swift b/Sources/StereoScene.swift index 105ea48..bd11742 100644 --- a/Sources/StereoScene.swift +++ b/Sources/StereoScene.swift @@ -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) ], diff --git a/Sources/StereoView.swift b/Sources/StereoView.swift index 1819d76..ad51305 100644 --- a/Sources/StereoView.swift +++ b/Sources/StereoView.swift @@ -144,7 +144,7 @@ public final class StereoView: UIView, SceneLoadable { height: Int(textureSize.height), mipmapped: true ) - let texture = device.makeTexture(descriptor: textureDescriptor) + let texture = device.makeTexture(descriptor: textureDescriptor)! self.init(stereoTexture: texture) diff --git a/Sources/StereoViewController.swift b/Sources/StereoViewController.swift index 71cb12a..0b4331b 100644 --- a/Sources/StereoViewController.swift +++ b/Sources/StereoViewController.swift @@ -11,7 +11,7 @@ import SceneKit open class StereoViewController: UIViewController, SceneLoadable { #if (arch(arm) || arch(arm64)) && os(iOS) - open let device: MTLDevice + public let device: MTLDevice #endif open var scene: SCNScene? { @@ -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 diff --git a/Sources/VideoScene.swift b/Sources/VideoScene.swift index 00fc5b9..3fda6ff 100644 --- a/Sources/VideoScene.swift +++ b/Sources/VideoScene.swift @@ -59,7 +59,7 @@ public final class MonoSphericalVideoScene: MonoSphericalMediaScene, VideoScene } }() - private let commandQueue: MTLCommandQueue + private let commandQueue: MTLCommandQueue? public let renderer: PlayerRenderer @@ -113,9 +113,17 @@ public final class MonoSphericalVideoScene: MonoSphericalMediaScene, VideoScene guard let texture = playerTexture else { return } - + var commandQueueHolder : MTLCommandQueue! + if let queue = commandQueue { + commandQueueHolder = queue + }else if let queue = self.commandQueue{ + commandQueueHolder = queue + }else{ + return + } + do { - let commandBuffer = (commandQueue ?? self.commandQueue).makeCommandBuffer() + guard let commandBuffer = commandQueueHolder.makeCommandBuffer() else { return} try renderer.render(atHostTime: time, to: texture, commandBuffer: commandBuffer) commandBuffer.commit() } catch let error as CVError { @@ -147,7 +155,7 @@ public final class StereoSphericalVideoScene: StereoSphericalMediaScene, VideoSc } }() - private let commandQueue: MTLCommandQueue + private let commandQueue: MTLCommandQueue? public let renderer: PlayerRenderer @@ -163,7 +171,7 @@ public final class StereoSphericalVideoScene: StereoSphericalMediaScene, VideoSc public init(renderer: PlayerRenderer) { self.renderer = renderer - commandQueue = renderer.device.makeCommandQueue() + self.commandQueue = renderer.device.makeCommandQueue() super.init() renderLoop.resume() } @@ -205,15 +213,24 @@ public final class StereoSphericalVideoScene: StereoSphericalMediaScene, VideoSc guard let playerTexture = playerTexture else { return } + var commandQueueHolder : MTLCommandQueue! + if let queue = commandQueue { + commandQueueHolder = queue + }else if let queue = self.commandQueue{ + commandQueueHolder = queue - let commandBuffer = (commandQueue ?? self.commandQueue).makeCommandBuffer() + }else{ + return + } + + guard let commandBuffer = commandQueueHolder.makeCommandBuffer() 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( + blitCommandEncoder?.copy( from: playerTexture, sourceSlice: 0, sourceLevel: 0, @@ -224,7 +241,7 @@ public final class StereoSphericalVideoScene: StereoSphericalMediaScene, VideoSc destinationLevel: 0, destinationOrigin: MTLOrigin(x: 0, y: 0, z: 0) ) - blitCommandEncoder.endEncoding() + blitCommandEncoder?.endEncoding() } let halfHeight = playerTexture.height / 2