mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Optimize pattern wallpapers rendering
This commit is contained in:
@@ -18,6 +18,7 @@ import WallpaperResources
|
||||
import GZip
|
||||
import TelegramUniversalVideoContent
|
||||
import GradientBackground
|
||||
import Svg
|
||||
|
||||
public func fetchCachedResourceRepresentation(account: Account, resource: MediaResource, representation: CachedMediaResourceRepresentation) -> Signal<CachedMediaResourceRepresentationResult, NoError> {
|
||||
if let representation = representation as? CachedStickerAJpegRepresentation {
|
||||
@@ -122,6 +123,14 @@ public func fetchCachedResourceRepresentation(account: Account, resource: MediaR
|
||||
return fetchMapSnapshotResource(resource: resource)
|
||||
} else if let resource = resource as? YoutubeEmbedStoryboardMediaResource, let _ = representation as? YoutubeEmbedStoryboardMediaResourceRepresentation {
|
||||
return fetchYoutubeEmbedStoryboardResource(resource: resource)
|
||||
} else if let representation = representation as? CachedPreparedPatternWallpaperRepresentation {
|
||||
return account.postbox.mediaBox.resourceData(resource, option: .complete(waitUntilFetchStatus: false))
|
||||
|> mapToSignal { data -> Signal<CachedMediaResourceRepresentationResult, NoError> in
|
||||
if !data.complete {
|
||||
return .complete()
|
||||
}
|
||||
return fetchPreparedPatternWallpaperRepresentation(resource: resource, resourceData: data, representation: representation)
|
||||
}
|
||||
}
|
||||
return .never()
|
||||
}
|
||||
@@ -719,3 +728,18 @@ private func fetchAnimatedStickerRepresentation(account: Account, resource: Medi
|
||||
|> runOn(Queue.concurrentDefaultQueue())
|
||||
}
|
||||
|
||||
|
||||
private func fetchPreparedPatternWallpaperRepresentation(resource: MediaResource, resourceData: MediaResourceData, representation: CachedPreparedPatternWallpaperRepresentation) -> Signal<CachedMediaResourceRepresentationResult, NoError> {
|
||||
return Signal({ subscriber in
|
||||
if let data = try? Data(contentsOf: URL(fileURLWithPath: resourceData.path), options: [.mappedIfSafe]) {
|
||||
if let unpackedData = TGGUnzipData(data, 2 * 1024 * 1024), let data = prepareSvgImage(unpackedData) {
|
||||
let path = NSTemporaryDirectory() + "\(Int64.random(in: Int64.min ... Int64.max))"
|
||||
let url = URL(fileURLWithPath: path)
|
||||
let _ = try? data.write(to: url)
|
||||
subscriber.putNext(.temporaryPath(path))
|
||||
subscriber.putCompletion()
|
||||
}
|
||||
}
|
||||
return EmptyDisposable
|
||||
}) |> runOn(Queue.concurrentDefaultQueue())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user