//
|
// MetalVideoView.swift
|
// LiveProject
|
// 视频绘制
|
// Created by 倪路朋 on 6/26/25.
|
//
|
import SwiftUI
|
import MetalKit
|
|
struct VideoRendererView: UIViewRepresentable {
|
@Binding var pixelBuffer: CVPixelBuffer?
|
@Binding var rotate:Int?;
|
|
//用 Coordinator 缓存实例
|
func makeCoordinator() -> Coordinator {
|
return Coordinator()
|
}
|
|
func makeUIView(context: Context) -> MTKView {
|
return context.coordinator.mtkView
|
}
|
|
func updateUIView(_ uiView: MTKView, context: Context) {
|
if let buffer = pixelBuffer {
|
//print("updateUIView")
|
context.coordinator.renderer.display(pixelBuffer: buffer)
|
}
|
if let angle = rotate{
|
//print("updateUIView rotate \(angle)")
|
context.coordinator.renderer.updateRotate(angle: angle)
|
}
|
}
|
|
|
class Coordinator {
|
let mtkView: MTKView
|
let renderer: MetalRenderer
|
|
init() {
|
print("📦 MetalRendererWrapper 初始化了")
|
mtkView = MTKView()
|
renderer = MetalRenderer(mtkView: mtkView)
|
}
|
}
|
}
|