mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Animation debugging
This commit is contained in:
parent
05a0d399dd
commit
307f8a841d
@ -95,6 +95,8 @@ public final class CompressedImageRenderer {
|
|||||||
|
|
||||||
private let commandQueue: MTLCommandQueue
|
private let commandQueue: MTLCommandQueue
|
||||||
|
|
||||||
|
private var isRendering: Bool = false
|
||||||
|
|
||||||
public init?(sharedContext: AnimationCompressor.SharedContext) {
|
public init?(sharedContext: AnimationCompressor.SharedContext) {
|
||||||
self.sharedContext = sharedContext
|
self.sharedContext = sharedContext
|
||||||
self.shared = Shared.shared
|
self.shared = Shared.shared
|
||||||
@ -114,7 +116,23 @@ public final class CompressedImageRenderer {
|
|||||||
if metalLayer.drawableSize != drawableSize {
|
if metalLayer.drawableSize != drawableSize {
|
||||||
metalLayer.drawableSize = drawableSize
|
metalLayer.drawableSize = drawableSize
|
||||||
}
|
}
|
||||||
return metalLayer.nextDrawable()
|
let beginTime = CFAbsoluteTimeGetCurrent()
|
||||||
|
let drawableRequestDuration: Double
|
||||||
|
if let drawableRequestTimestamp = self.drawableRequestTimestamp {
|
||||||
|
drawableRequestDuration = beginTime - drawableRequestTimestamp
|
||||||
|
if drawableRequestDuration < 1.0 / 60.0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
drawableRequestDuration = 0.0
|
||||||
|
}
|
||||||
|
self.drawableRequestTimestamp = beginTime
|
||||||
|
let result = metalLayer.nextDrawable()
|
||||||
|
let duration = CFAbsoluteTimeGetCurrent() - beginTime
|
||||||
|
if duration > 1.0 / 60.0 {
|
||||||
|
print("lag \(duration * 1000.0) ms (\(drawableRequestDuration * 1000.0) ms)")
|
||||||
|
}
|
||||||
|
return result
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -323,10 +341,11 @@ public final class CompressedImageRenderer {
|
|||||||
|
|
||||||
var storedDrawable: MTLDrawable? = drawable
|
var storedDrawable: MTLDrawable? = drawable
|
||||||
commandBuffer.addScheduledHandler { _ in
|
commandBuffer.addScheduledHandler { _ in
|
||||||
|
autoreleasepool {
|
||||||
storedDrawable?.present()
|
storedDrawable?.present()
|
||||||
storedDrawable = nil
|
storedDrawable = nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if targetEnvironment(simulator)
|
#if targetEnvironment(simulator)
|
||||||
commandBuffer.addCompletedHandler { _ in
|
commandBuffer.addCompletedHandler { _ in
|
||||||
@ -384,6 +403,13 @@ public final class CompressedImageRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func renderRgb(metalLayer: CALayer, width: Int, height: Int, bytesPerRow: Int, data: Data, completion: @escaping () -> Void) {
|
public func renderRgb(metalLayer: CALayer, width: Int, height: Int, bytesPerRow: Int, data: Data, completion: @escaping () -> Void) {
|
||||||
|
if "".isEmpty {
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2.0 / 60.0, execute: {
|
||||||
|
completion()
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
self.updateRgbTexture(width: width, height: height, bytesPerRow: bytesPerRow, data: data)
|
self.updateRgbTexture(width: width, height: height, bytesPerRow: bytesPerRow, data: data)
|
||||||
|
|
||||||
guard let rgbTexture = self.rgbTexture else {
|
guard let rgbTexture = self.rgbTexture else {
|
||||||
@ -420,18 +446,44 @@ public final class CompressedImageRenderer {
|
|||||||
|
|
||||||
renderEncoder.endEncoding()
|
renderEncoder.endEncoding()
|
||||||
|
|
||||||
commandBuffer.present(drawable)
|
var storedDrawable: MTLDrawable? = drawable
|
||||||
|
commandBuffer.addScheduledHandler { _ in
|
||||||
|
autoreleasepool {
|
||||||
|
storedDrawable?.present()
|
||||||
|
storedDrawable = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if targetEnvironment(simulator)
|
||||||
commandBuffer.addCompletedHandler { _ in
|
commandBuffer.addCompletedHandler { _ in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
completion()
|
completion()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if #available(iOS 10.3, *) {
|
||||||
|
drawable.addPresentedHandler { _ in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
completion()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
commandBuffer.addCompletedHandler { _ in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
completion()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
commandBuffer.commit()
|
commandBuffer.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateYuvaTextures(width: Int, height: Int, data: Data) {
|
private func updateYuvaTextures(width: Int, height: Int, data: Data) {
|
||||||
|
if width % 2 != 0 || height % 2 != 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
self.compressedTextures = nil
|
self.compressedTextures = nil
|
||||||
self.outputTextures = nil
|
self.outputTextures = nil
|
||||||
self.rgbTexture = nil
|
self.rgbTexture = nil
|
||||||
@ -502,22 +554,56 @@ public final class CompressedImageRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func renderYuva(metalLayer: CALayer, width: Int, height: Int, data: Data, completion: @escaping () -> Void) {
|
public func renderYuva(metalLayer: CALayer, width: Int, height: Int, data: Data, completion: @escaping () -> Void) {
|
||||||
|
if self.isRendering {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
completion()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.isRendering = true
|
||||||
|
DispatchQueue.global().async {
|
||||||
|
autoreleasepool {
|
||||||
|
let renderStartTime = CFAbsoluteTimeGetCurrent()
|
||||||
|
|
||||||
|
var beginTime: Double = 0.0
|
||||||
|
var duration: Double = 0.0
|
||||||
|
beginTime = CFAbsoluteTimeGetCurrent()
|
||||||
|
|
||||||
self.updateYuvaTextures(width: width, height: height, data: data)
|
self.updateYuvaTextures(width: width, height: height, data: data)
|
||||||
|
|
||||||
|
duration = CFAbsoluteTimeGetCurrent() - beginTime
|
||||||
|
if duration > 1.0 / 60.0 {
|
||||||
|
print("update textures lag \(duration * 1000.0)")
|
||||||
|
}
|
||||||
|
|
||||||
guard let yuvaTextures = self.yuvaTextures else {
|
guard let yuvaTextures = self.yuvaTextures else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isRendering = false
|
||||||
|
completion()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
beginTime = CFAbsoluteTimeGetCurrent()
|
||||||
|
|
||||||
guard let commandBuffer = self.commandQueue.makeCommandBuffer() else {
|
guard let commandBuffer = self.commandQueue.makeCommandBuffer() else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isRendering = false
|
||||||
|
completion()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
commandBuffer.label = "MyCommand"
|
commandBuffer.label = "MyCommand"
|
||||||
|
|
||||||
let drawableSize = CGSize(width: CGFloat(yuvaTextures.width), height: CGFloat(yuvaTextures.height))
|
let drawableSize = CGSize(width: CGFloat(yuvaTextures.width), height: CGFloat(yuvaTextures.height))
|
||||||
|
|
||||||
guard let drawable = self.getNextDrawable(metalLayer: metalLayer, drawableSize: drawableSize) else {
|
guard let drawable = self.getNextDrawable(metalLayer: metalLayer, drawableSize: drawableSize) else {
|
||||||
commandBuffer.commit()
|
commandBuffer.commit()
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isRendering = false
|
||||||
completion()
|
completion()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,6 +613,10 @@ public final class CompressedImageRenderer {
|
|||||||
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColor(red: 0, green: 0, blue: 0, alpha: 0)
|
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColor(red: 0, green: 0, blue: 0, alpha: 0)
|
||||||
|
|
||||||
guard let renderEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: renderPassDescriptor) else {
|
guard let renderEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: renderPassDescriptor) else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isRendering = false
|
||||||
|
completion()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
renderEncoder.label = "MyRenderEncoder"
|
renderEncoder.label = "MyRenderEncoder"
|
||||||
@ -543,14 +633,52 @@ public final class CompressedImageRenderer {
|
|||||||
|
|
||||||
renderEncoder.endEncoding()
|
renderEncoder.endEncoding()
|
||||||
|
|
||||||
commandBuffer.present(drawable)
|
var storedDrawable: MTLDrawable? = drawable
|
||||||
|
commandBuffer.addScheduledHandler { _ in
|
||||||
|
autoreleasepool {
|
||||||
|
storedDrawable?.present()
|
||||||
|
storedDrawable = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if targetEnvironment(simulator)
|
||||||
commandBuffer.addCompletedHandler { _ in
|
commandBuffer.addCompletedHandler { _ in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isRendering = false
|
||||||
|
completion()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if #available(iOS 10.3, *) {
|
||||||
|
commandBuffer.addCompletedHandler { _ in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isRendering = false
|
||||||
|
}
|
||||||
|
let renderDuration = CFAbsoluteTimeGetCurrent() - renderStartTime
|
||||||
|
print("render duration \(renderDuration * 1000.0) ms")
|
||||||
|
}
|
||||||
|
drawable.addPresentedHandler { _ in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
completion()
|
completion()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
commandBuffer.addCompletedHandler { _ in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isRendering = false
|
||||||
|
completion()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
commandBuffer.commit()
|
commandBuffer.commit()
|
||||||
|
|
||||||
|
duration = CFAbsoluteTimeGetCurrent() - beginTime
|
||||||
|
if duration > 1.0 / 60.0 {
|
||||||
|
print("commit lag \(duration * 1000.0)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user