mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
30 lines
729 B
Swift
30 lines
729 B
Swift
import Foundation
|
|
import AVFoundation
|
|
import Metal
|
|
import MetalKit
|
|
import Display
|
|
import Accelerate
|
|
|
|
final class ImageTextureSource: TextureSource {
|
|
weak var output: MediaEditorRenderer?
|
|
|
|
var texture: MTLTexture?
|
|
|
|
init(image: UIImage, renderTarget: RenderTarget) {
|
|
if let device = renderTarget.mtlDevice {
|
|
self.texture = loadTexture(image: image, device: device)
|
|
}
|
|
}
|
|
|
|
func connect(to consumer: MediaEditorRenderer) {
|
|
self.output = consumer
|
|
if let texture = self.texture {
|
|
self.output?.consume(main: .texture(texture, .zero), additional: nil, render: false)
|
|
}
|
|
}
|
|
|
|
func invalidate() {
|
|
self.texture = nil
|
|
}
|
|
}
|