我尝试使用Apple提供的默认过滤器使用driver.Url = "http://www.gmail.net";
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("window.open();");
和MTLTexture
属性裁剪clipRect
,并且它可以正常使用实时视频过滤。
但是对于自定义过滤器(使用offset
),属性custom shaders
和clipRect
对裁剪offset
无效,我尝试使用{{1}进行裁剪提到Crop and scale MTLTexture。
MTLTexture
正如你在这里看到的那样,我们正在尝试裁剪纹理,然后对过滤器进行编码,这是一个双向操作,过程非常慢。
但如果应用滤镜而不裁剪纹理,则表现非常流畅。编码方法如下所示。
MPSImageLanczosScale
无需使用模糊滤镜进行编码。但是我添加了这个跳跃,它会使用func encodeWithTransform(to commandBuffer: MTLCommandBuffer, sourceTexture: MTLTexture, destinationTexture: MTLTexture, transform: MPSScaleTransform) {
var newTransform = transform
withUnsafePointer(to: &newTransform) { (transformPtr: UnsafePointer<MPSScaleTransform>) -> () in
lanczosScaleFilter.scaleTransform = transformPtr
lanczosScaleFilter.encode(commandBuffer: commandBuffer, sourceTexture: sourceTexture, destinationTexture: newCroppingTexture)
self.imageFilter.encode(to: commandBuffer!, sourceTexture: newCroppingTexture, destinationTexture: destinationTexture, cropRect: MTLRegionMake2D(0, 0, Int(uiscreenWidth) / 4, sourceTexture.height), offset : CGPoint(x: 0 / scale, y:0))
}
}
和 blur.clipRect = cropRect
blur.offset = MPSOffset(x: Int(offset.x), y: Int(offset.y), z: 0)
let threadsPerThreadgroup = MTLSizeMake(10, 10, 1)
let threadgroupsPerGrid = MTLSizeMake(destinationTexture.width / threadsPerThreadgroup.width, sourceTexture.height / threadsPerThreadgroup.height, 1)
let commandEncoder = commandBuffer.makeComputeCommandEncoder()
commandEncoder.setComputePipelineState(pipelineState!)
commandEncoder.setTexture(sourceTexture, at: 0)
commandEncoder.setTexture(destinationTexture, at: 1)
commandEncoder.dispatchThreadgroups(threadgroupsPerGrid, threadsPerThreadgroup: threadsPerThreadgroup)
commandEncoder.endEncoding()
autoreleasepool {
var inplaceTexture = destinationTexture
blur.encode(commandBuffer: commandBuffer, inPlaceTexture: &inplaceTexture, fallbackCopyAllocator: nil)
}
属性进行裁剪,但没有运气。
因此,如果有人有更好的解决方案,可能会修改自定义着色器方法中的纹理rect,这将有所帮助。此外,如果有人建议苹果如何使用clipRect
和offset
属性来帮助我。