Merge commit '7621e2f8dec938cf48181c8b10afc9b01f444e68' into beta

This commit is contained in:
Ilya Laktyushin
2025-12-06 02:17:48 +04:00
commit 8344b97e03
28070 changed files with 7995182 additions and 0 deletions
+157
View File
@@ -0,0 +1,157 @@
load("@build_bazel_rules_apple//apple:ios.bzl",
"ios_application",
)
load("@build_bazel_rules_swift//swift:swift.bzl",
"swift_library",
)
load("//build-system/bazel-utils:plist_fragment.bzl",
"plist_fragment",
)
module_name = "AnimationCacheTest"
filegroup(
name = "AppResources",
srcs = glob([
"Resources/**/*",
], exclude = ["Resources/**/.*"]),
)
swift_library(
name = "Lib",
srcs = glob([
"Sources/**/*.swift",
]),
data = [
":AppResources",
],
deps = [
"//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit",
"//submodules/Display:Display",
"//submodules/TelegramUI/Components/AnimationCache:AnimationCache",
"//submodules/TelegramUI/Components/VideoAnimationCache:VideoAnimationCache",
"//submodules/TelegramUI/Components/LottieAnimationCache:LottieAnimationCache",
"//submodules/rlottie:RLottieBinding",
],
)
plist_fragment(
name = "BuildNumberInfoPlist",
extension = "plist",
template =
"""
<key>CFBundleVersion</key>
<string>1</string>
"""
)
plist_fragment(
name = "VersionInfoPlist",
extension = "plist",
template =
"""
<key>CFBundleShortVersionString</key>
<string>1.0</string>
"""
)
plist_fragment(
name = "AppNameInfoPlist",
extension = "plist",
template =
"""
<key>CFBundleDisplayName</key>
<string>Test</string>
"""
)
plist_fragment(
name = "AppInfoPlist",
extension = "plist",
template =
"""
<key>CFBundleAllowMixedLocalizations</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>Test</string>
<key>CFBundleIdentifier</key>
<string>org.telegram.{module_name}</string>
<key>CFBundleName</key>
<string>Telegram</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UIFileSharingEnabled</key>
<false/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleDefault</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIViewEdgeAntialiasing</key>
<false/>
<key>UIViewGroupOpacity</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
""".format(module_name=module_name)
)
ios_application(
name = module_name,
bundle_id = "org.telegram.{}".format(module_name),
families = ["iphone", "ipad"],
minimum_os_version = "9.0",
provisioning_profile = "@build_configuration//provisioning:Wildcard.mobileprovision",
infoplists = [
":AppInfoPlist",
":BuildNumberInfoPlist",
":VersionInfoPlist",
],
resources = [
"//Tests/Common:LaunchScreen",
],
frameworks = [
],
deps = [
"//Tests/Common:Main",
":Lib",
],
)
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -0,0 +1,21 @@
import Foundation
import UIKit
@objc(Application)
public final class Application: UIApplication {
}
@objc(AppDelegate)
public final class AppDelegate: NSObject, UIApplicationDelegate {
public var window: UIWindow?
public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
let window = UIWindow()
self.window = window
window.rootViewController = ViewController()
window.makeKeyAndVisible()
return true
}
}
@@ -0,0 +1,118 @@
import Foundation
import UIKit
import Display
import AnimationCache
import SwiftSignalKit
import VideoAnimationCache
import LottieAnimationCache
public final class ViewController: UIViewController {
private var imageView: UIImageView?
private var imageViewLarge: UIImageView?
private var cache: AnimationCache?
private var animationCacheItem: AnimationCacheItem?
//private let playbackSize = CGSize(width: 512, height: 512)
//private let playbackSize = CGSize(width: 256, height: 256)
private let playbackSize = CGSize(width: 48.0, height: 48.0)
//private let playbackSize = CGSize(width: 16, height: 16)
private var fpsCount: Int = 0
override public func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .white
let imageView = UIImageView(frame: CGRect(origin: CGPoint(x: 0.0, y: 20.0), size: CGSize(width: 48.0, height: 48.0)))
self.imageView = imageView
self.view.addSubview(imageView)
let imageViewLarge = UIImageView(frame: CGRect(origin: CGPoint(x: 0.0, y: 20.0 + 48.0 + 10.0), size: CGSize(width: 256.0, height: 256.0)))
//imageViewLarge.layer.magnificationFilter = .nearest
self.imageViewLarge = imageViewLarge
self.view.addSubview(imageViewLarge)
self.loadItem()
if #available(iOS 10.0, *) {
let timer = Foundation.Timer(timeInterval: 1.0, repeats: true, block: { _ in
print(self.fpsCount)
self.fpsCount = 0
})
RunLoop.main.add(timer, forMode: .common)
}
}
private func loadItem() {
let basePath = NSTemporaryDirectory() + "/animation-cache"
let _ = try? FileManager.default.removeItem(atPath: basePath)
let _ = try? FileManager.default.createDirectory(at: URL(fileURLWithPath: basePath), withIntermediateDirectories: true)
self.cache = AnimationCacheImpl(basePath: basePath, allocateTempFile: {
return basePath + "/\(Int64.random(in: 0 ... Int64.max))"
})
let path = Bundle.main.path(forResource: "sticker", ofType: "webm")!
let scaledSize = CGSize(width: self.playbackSize.width * 2.0, height: self.playbackSize.height * 2.0)
let _ = (self.cache!.get(sourceId: "Item\(Int64.random(in: 0 ... Int64.max))", size: scaledSize, fetch: { options in
options.writer.queue.async {
if path.hasSuffix(".webm") {
cacheVideoAnimation(path: path, width: Int(options.size.width), height: Int(options.size.height), writer: options.writer, firstFrameOnly: options.firstFrameOnly)
} else {
let data = try! Data(contentsOf: URL(fileURLWithPath: path))
cacheLottieAnimation(data: data, width: Int(options.size.width), height: Int(options.size.height), keyframeOnly: false, writer: options.writer, firstFrameOnly: options.firstFrameOnly)
}
options.writer.finish()
}
return EmptyDisposable
})
|> deliverOnMainQueue).start(next: { result in
if !result.isFinal {
return
}
self.animationCacheItem = result.item
self.updateImage()
})
}
private func updateImage() {
guard let animationCacheItem = self.animationCacheItem else {
self.loadItem()
return
}
if let frame = animationCacheItem.advance(advance: .frames(1), requestedFormat: .rgba) {
switch frame.format {
case let .rgba(data, width, height, bytesPerRow):
let context = DrawingContext(size: CGSize(width: CGFloat(width), height: CGFloat(height)), scale: 1.0, opaque: false, bytesPerRow: bytesPerRow)
data.withUnsafeBytes { bytes -> Void in
memcpy(context.bytes, bytes.baseAddress!, height * bytesPerRow)
}
self.imageView?.image = context.generateImage()
self.imageViewLarge?.image = self.imageView?.image
self.fpsCount += 1
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.0 / 30.0, execute: { [weak self] in
self?.updateImage()
})
/*DispatchQueue.main.async {
self.updateImage()
}*/
default:
break
}
} else {
self.loadItem()
}
}
}