This commit is contained in:
Nick Fisher
2024-04-30 14:14:54 +08:00
parent 8f9e309c34
commit 14b0b674c5
28 changed files with 423 additions and 1787 deletions

View File

@@ -0,0 +1,48 @@
import Foundation
import GLKit
import Flutter
public class FlutterFilamentTexture : NSObject, FlutterTexture {
public var pixelBuffer: CVPixelBuffer?
var pixelBufferAttrs = [
kCVPixelBufferPixelFormatTypeKey: NSNumber(value: kCVPixelFormatType_32BGRA),
kCVPixelBufferOpenGLCompatibilityKey: kCFBooleanTrue,
kCVPixelBufferOpenGLESCompatibilityKey: kCFBooleanTrue,
kCVPixelBufferIOSurfacePropertiesKey: [:]
] as CFDictionary
var flutterTextureId: Int64 = -1
var registry: FlutterTextureRegistry?
init(width:Int64, height:Int64, registry:FlutterTextureRegistry) {
self.registry = registry
super.init()
if(CVPixelBufferCreate(kCFAllocatorDefault, Int(width), Int(height),
kCVPixelFormatType_32BGRA, pixelBufferAttrs, &pixelBuffer) != kCVReturnSuccess) {
print("Error allocating pixel buffer")
} else {
self.flutterTextureId = registry.register(self)
}
}
public func copyPixelBuffer() -> Unmanaged<CVPixelBuffer>? {
return Unmanaged.passRetained(pixelBuffer!);
}
public func onTextureUnregistered(_ texture:FlutterTexture) {
print("Texture unregistered")
}
public func destroy() {
if(self.flutterTextureId != -1) {
self.registry!.unregisterTexture(self.flutterTextureId)
}
self.pixelBuffer = nil
}
}