Skip to content

Commit

Permalink
Updating to match latest OSS Swift compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
BradLarson committed Aug 5, 2016
1 parent 6295ec6 commit 6e5a777
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 26 deletions.
2 changes: 1 addition & 1 deletion framework/Source/FramebufferCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class FramebufferCache {
public func requestFramebufferWithProperties(orientation:ImageOrientation, size:GLSize, textureOnly:Bool = false, minFilter:Int32 = GL_LINEAR, magFilter:Int32 = GL_LINEAR, wrapS:Int32 = GL_CLAMP_TO_EDGE, wrapT:Int32 = GL_CLAMP_TO_EDGE, internalFormat:Int32 = GL_RGBA, format:Int32 = GL_BGRA, type:Int32 = GL_UNSIGNED_BYTE, stencil:Bool = false) -> Framebuffer {
let hash = hashForFramebufferWithProperties(orientation:orientation, size:size, textureOnly:textureOnly, minFilter:minFilter, magFilter:magFilter, wrapS:wrapS, wrapT:wrapT, internalFormat:internalFormat, format:format, type:type, stencil:stencil)
let framebuffer:Framebuffer
if (framebufferCache[hash]?.count > 0) {
if ((framebufferCache[hash]?.count ?? -1) > 0) {
// print("Restoring previous framebuffer")
framebuffer = framebufferCache[hash]!.removeLast()
framebuffer.orientation = orientation
Expand Down
6 changes: 3 additions & 3 deletions framework/Source/Mac/Camera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ public class Camera: NSObject, ImageSource, AVCaptureVideoDataOutputSampleBuffer

if (supportsFullYUVRange) {
yuvConversionShader = crashOnShaderCompileFailure("Camera"){try sharedImageProcessingContext.programForVertexShader(defaultVertexShaderForInputs(2), fragmentShader:YUVConversionFullRangeFragmentShader)}
videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey:NSNumber(value:Int32(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange))]
videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as AnyHashable:NSNumber(value:Int32(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange))]
} else {
yuvConversionShader = crashOnShaderCompileFailure("Camera"){try sharedImageProcessingContext.programForVertexShader(defaultVertexShaderForInputs(2), fragmentShader:YUVConversionVideoRangeFragmentShader)}
videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey:NSNumber(value:Int32(kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange))]
videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as AnyHashable:NSNumber(value:Int32(kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange))]
}
} else {
yuvConversionShader = nil
videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey:NSNumber(value:Int32(kCVPixelFormatType_32BGRA))]
videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as AnyHashable:NSNumber(value:Int32(kCVPixelFormatType_32BGRA))]
}

if (captureSession.canAddOutput(videoOutput)) {
Expand Down
2 changes: 1 addition & 1 deletion framework/Source/Mac/MovieOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MovieOutput: ImageConsumer, AudioEncodingTarget {

localSettings[AVVideoWidthKey] = localSettings[AVVideoWidthKey] ?? NSNumber(value:size.width)
localSettings[AVVideoHeightKey] = localSettings[AVVideoHeightKey] ?? NSNumber(value:size.height)
localSettings[AVVideoCodecKey] = localSettings[AVVideoCodecKey] ?? AVVideoCodecH264
localSettings[AVVideoCodecKey] = localSettings[AVVideoCodecKey] ?? AVVideoCodecH264 as NSString

assetWriterVideoInput = AVAssetWriterInput(mediaType:AVMediaTypeVideo, outputSettings:localSettings)
assetWriterVideoInput.expectsMediaDataInRealTime = liveVideo
Expand Down
2 changes: 1 addition & 1 deletion framework/Source/Mac/OpenGLContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class OpenGLContext: SerialDispatch {
lazy var extensionString:String = {
return self.runOperationSynchronously{
self.makeCurrentContext()
return String(cString:UnsafePointer<CChar>(glGetString(GLenum(GL_EXTENSIONS))))
return String(cString:unsafeBitCast(glGetString(GLenum(GL_EXTENSIONS)), to:UnsafePointer<CChar>.self))
}
}()
}
4 changes: 2 additions & 2 deletions framework/Source/Mac/PictureInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public class PictureInput: ImageSource {

let imageContext = CGContext(data:imageData, width:Int(widthToUseForTexture), height:Int(heightToUseForTexture), bitsPerComponent:8, bytesPerRow:Int(widthToUseForTexture) * 4, space:genericRGBColorspace, bitmapInfo:CGImageAlphaInfo.premultipliedFirst.rawValue | CGBitmapInfo.byteOrder32Little.rawValue)
// CGContextSetBlendMode(imageContext, kCGBlendModeCopy); // From Technical Q&A QA1708: http://developer.apple.com/library/ios/#qa/qa1708/_index.html
imageContext?.draw(in:CGRect(x:0.0, y:0.0, width:CGFloat(widthToUseForTexture), height:CGFloat(heightToUseForTexture)), image:image)
imageContext?.draw(image, in:CGRect(x:0.0, y:0.0, width:CGFloat(widthToUseForTexture), height:CGFloat(heightToUseForTexture)))
} else {
// Access the raw image bytes directly
dataFromImageDataProvider = image.dataProvider?.data
imageData = UnsafeMutablePointer<GLubyte>(CFDataGetBytePtr(dataFromImageDataProvider))
imageData = UnsafeMutablePointer<GLubyte>(mutating:CFDataGetBytePtr(dataFromImageDataProvider)!)
}

sharedImageProcessingContext.makeCurrentContext()
Expand Down
10 changes: 6 additions & 4 deletions framework/Source/Mac/PictureOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,23 @@ public extension NSImage {
}
}

public func filterWithPipeline(_ pipeline:(input:PictureInput, output:PictureOutput) -> ()) -> NSImage {
public func filterWithPipeline(_ pipeline:(PictureInput, PictureOutput) -> ()) -> NSImage {
let picture = PictureInput(image:self)
var outputImage:NSImage?
let pictureOutput = PictureOutput()
pictureOutput.onlyCaptureNextFrame = true
pictureOutput.imageAvailableCallback = {image in
outputImage = image
}
pipeline(input:picture, output:pictureOutput)
pipeline(picture, pictureOutput)
picture.processImage(synchronously:true)
return outputImage!
}
}

// Why are these flipped in the callback definition?
func dataProviderReleaseCallback(_ context:UnsafeMutablePointer<Void>?, data:UnsafePointer<Void>, size:Int) {
UnsafeMutablePointer<UInt8>(data).deallocate(capacity:size)
func dataProviderReleaseCallback(_ context:UnsafeMutableRawPointer?, data:UnsafeRawPointer, size:Int) {
// UnsafeMutablePointer<UInt8>(data).deallocate(capacity:size)
// FIXME: Verify this is correct
data.deallocate(bytes:size, alignedTo:1)
}
2 changes: 1 addition & 1 deletion framework/Source/OpenGLContext_Shared.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ extension OpenGLContext {

@_semantics("sil.optimize.never") public func debugPrint(_ stringToPrint:String, file: StaticString = #file, line: UInt = #line, function: StaticString = #function) {
#if DEBUG
print("\(stringToPrint) --> \((String(file) as NSString).lastPathComponent): \(function): \(line)")
print("\(stringToPrint) --> \((String(describing:file) as NSString).lastPathComponent): \(function): \(line)")
#endif
}
4 changes: 2 additions & 2 deletions framework/Source/OperationGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class OperationGroup: ImageProcessingOperation {
inputImageRelay.newFramebufferAvailable(framebuffer, fromSourceIndex:fromSourceIndex)
}

public func configureGroup(_ configurationOperation:(input:ImageRelay, output:ImageRelay) -> ()) {
configurationOperation(input:inputImageRelay, output:outputImageRelay)
public func configureGroup(_ configurationOperation:(_ input:ImageRelay, _ output:ImageRelay) -> ()) {
configurationOperation(inputImageRelay, outputImageRelay)
}

public func transmitPreviousImage(to target:ImageConsumer, atIndex:UInt) {
Expand Down
4 changes: 2 additions & 2 deletions framework/Source/Operations/MotionDetector.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public class MotionDetector: OperationGroup {
public var lowPassStrength:Float = 1.0 { didSet {lowPassFilter.strength = lowPassStrength}}
public var motionDetectedCallback:((position:Position, strength:Float) -> ())?
public var motionDetectedCallback:((Position, Float) -> ())?

let lowPassFilter = LowPassFilter()
let motionComparison = BasicOperation(fragmentShader:MotionComparisonFragmentShader, numberOfInputs:2)
Expand All @@ -10,7 +10,7 @@ public class MotionDetector: OperationGroup {
super.init()

averageColorExtractor.extractedColorCallback = {[weak self] color in
self?.motionDetectedCallback?(position:Position(color.redComponent / color.alphaComponent, color.greenComponent / color.alphaComponent), strength:color.alphaComponent)
self?.motionDetectedCallback?(Position(color.redComponent / color.alphaComponent, color.greenComponent / color.alphaComponent), color.alphaComponent)
}

self.configureGroup{input, output in
Expand Down
7 changes: 5 additions & 2 deletions framework/Source/Pipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ public protocol ImageConsumer:AnyObject {
public protocol ImageProcessingOperation: ImageConsumer, ImageSource {
}

infix operator --> { associativity left precedence 140 }

infix operator --> : AdditionPrecedence
//precedencegroup ProcessingOperationPrecedence {
// associativity: left
//// higherThan: Multiplicative
//}
@discardableResult public func --><T:ImageConsumer>(source:ImageSource, destination:T) -> T {
source.addTarget(destination)
return destination
Expand Down
12 changes: 6 additions & 6 deletions framework/Source/SerialDispatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public let lowProcessingQueuePriority:DispatchQueue.GlobalQueuePriority = {
}
}()

func runAsynchronouslyOnMainQueue(_ mainThreadOperation:() -> ()) {
func runAsynchronouslyOnMainQueue(_ mainThreadOperation:@escaping () -> ()) {
// FIXME: Xcode 8 beta 2
if (Thread.isMainThread) {
// if (Thread.isMainThread()) {
// if (Thread.isMainThread) {
if (Thread.isMainThread()) {
mainThreadOperation()
} else {
DispatchQueue.main.async(execute:mainThreadOperation)
Expand All @@ -47,8 +47,8 @@ func runAsynchronouslyOnMainQueue(_ mainThreadOperation:() -> ()) {

func runOnMainQueue(_ mainThreadOperation:() -> ()) {
// FIXME: Xcode 8 beta 2
if (Thread.isMainThread) {
// if (Thread.isMainThread()) {
// if (Thread.isMainThread) {
if (Thread.isMainThread()) {
mainThreadOperation()
} else {
DispatchQueue.main.sync(execute:mainThreadOperation)
Expand All @@ -73,7 +73,7 @@ public protocol SerialDispatch {
}

public extension SerialDispatch {
public func runOperationAsynchronously(_ operation:() -> ()) {
public func runOperationAsynchronously(_ operation:@escaping () -> ()) {
self.serialDispatchQueue.async {
self.makeCurrentContext()
operation()
Expand Down
2 changes: 1 addition & 1 deletion framework/Source/ShaderProgram.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public func shaderFromFile(_ file:URL) throws -> String {
// Note: this is a hack until Foundation's String initializers are fully functional
// let fragmentShaderString = String(contentsOfURL:fragmentShaderFile, encoding:NSASCIIStringEncoding)
// FIXME: Xcode 8 beta 2
guard (FileManager.default.fileExists(atPath: file.path)) else { throw ShaderCompileError(compileLog:"Shader file \(file) missing")}
guard (FileManager.default().fileExists(atPath: file.path)) else { throw ShaderCompileError(compileLog:"Shader file \(file) missing")}
// guard (FileManager.default().fileExists(atPath: file.path!)) else { throw ShaderCompileError(compileLog:"Shader file \(file) missing")}

let fragmentShaderString = try NSString(contentsOfFile:file.path, encoding:String.Encoding.ascii.rawValue)
Expand Down

0 comments on commit 6e5a777

Please sign in to comment.