mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Group call optimizations
This commit is contained in:
@@ -230,10 +230,10 @@ vertex BlobVertexOut callBlobVertex(
|
||||
}
|
||||
|
||||
fragment half4 callBlobFragment(
|
||||
BlobVertexOut in [[stage_in]]
|
||||
BlobVertexOut in [[stage_in]],
|
||||
const device float4 &color [[ buffer(0) ]]
|
||||
) {
|
||||
half alpha = 0.35;
|
||||
return half4(1.0 * alpha, 1.0 * alpha, 1.0 * alpha, alpha);
|
||||
return half4(color.r * color.a, color.g * color.a, color.b * color.a, color.a);
|
||||
}
|
||||
|
||||
kernel void videoBiPlanarToRGBA(
|
||||
|
||||
@@ -7,10 +7,13 @@ public final class CallBlobsLayer: MetalEngineSubjectLayer, MetalEngineSubject {
|
||||
public var internalData: MetalEngineSubjectInternalData?
|
||||
|
||||
private struct Blob {
|
||||
var color: SIMD4<Float>
|
||||
var points: [Float]
|
||||
var nextPoints: [Float]
|
||||
|
||||
init(count: Int) {
|
||||
init(count: Int, color: SIMD4<Float>) {
|
||||
self.color = color
|
||||
|
||||
self.points = (0 ..< count).map { _ in
|
||||
Float.random(in: 0.0 ... 1.0)
|
||||
}
|
||||
@@ -71,7 +74,7 @@ public final class CallBlobsLayer: MetalEngineSubjectLayer, MetalEngineSubject {
|
||||
|
||||
private var displayLinkSubscription: SharedDisplayLinkDriver.Link?
|
||||
|
||||
override public init() {
|
||||
public init(colors: [UIColor] = [UIColor(white: 1.0, alpha: 0.35), UIColor(white: 1.0, alpha: 0.35)]) {
|
||||
super.init()
|
||||
|
||||
self.didEnterHierarchy = { [weak self] in
|
||||
@@ -100,8 +103,14 @@ public final class CallBlobsLayer: MetalEngineSubjectLayer, MetalEngineSubject {
|
||||
}
|
||||
|
||||
self.isOpaque = false
|
||||
self.blobs = (0 ..< 2).map { _ in
|
||||
Blob(count: 8)
|
||||
self.blobs = colors.reversed().map { color in
|
||||
var r: CGFloat = 0.0
|
||||
var g: CGFloat = 0.0
|
||||
var b: CGFloat = 0.0
|
||||
var a: CGFloat = 0.0
|
||||
color.getRed(&r, green: &g, blue: &b, alpha: &a)
|
||||
|
||||
return Blob(count: 8, color: SIMD4<Float>(Float(r), Float(g), Float(b), Float(a)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +146,9 @@ public final class CallBlobsLayer: MetalEngineSubjectLayer, MetalEngineSubject {
|
||||
encoder.setVertexBytes(&points, length: MemoryLayout<Float>.size * points.count, index: 1)
|
||||
encoder.setVertexBytes(&count, length: MemoryLayout<Float>.size, index: 2)
|
||||
|
||||
var color = blobs[i].color
|
||||
encoder.setFragmentBytes(&color, length: MemoryLayout<Float>.size * 4, index: 0)
|
||||
|
||||
encoder.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: 3 * 8 * points.count)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user