Merge commit '677f1584c7026393cfb9bf66f3a89aad7b1628b1'

This commit is contained in:
Isaac
2023-12-08 22:34:29 +04:00
11 changed files with 59 additions and 22 deletions

View File

@@ -2,6 +2,7 @@
import UIKit
#else
import AppKit
import TGUIKit
#endif
import CoreMedia
import Accelerate

View File

@@ -3,6 +3,7 @@ import Foundation
import UIKit
#else
import AppKit
import TGUIKit
#endif
import CoreMedia
import SwiftSignalKit

View File

@@ -3,6 +3,7 @@ import Foundation
import UIKit
#else
import AppKit
import TGUIKit
#endif
import SwiftSignalKit
import Postbox

View File

@@ -5,6 +5,7 @@ import PackageDescription
let package = Package(
name: "MetalEngine",
platforms: [.macOS(.v10_13)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
@@ -13,6 +14,7 @@ let package = Package(
],
dependencies: [
.package(name: "ShelfPack", path: "../Utils/ShelfPack"),
.package(name: "TGUIKit", path: "../../../../packages/TGUIKit"),
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
@@ -21,7 +23,8 @@ let package = Package(
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "MetalEngine",
dependencies: [.product(name: "ShelfPack", package: "ShelfPack", condition: nil)],
path: "Sources/MetalEngine"),
dependencies: [.product(name: "ShelfPack", package: "ShelfPack", condition: nil),
.product(name: "TGUIKit", package: "TGUIKit", condition: nil)],
path: "Sources/"),
]
)

View File

@@ -4,8 +4,12 @@ import Metal
#if os(iOS)
import Display
import UIKit
#else
import AppKit
import TGUIKit
#endif
import IOSurface
import ShelfPack
@@ -662,13 +666,6 @@ public final class MetalEngine {
fileprivate var computeStates: [ObjectIdentifier: ComputeState] = [:]
init?(device: MTLDevice) {
let mainBundle = Bundle(for: Impl.self)
guard let path = mainBundle.path(forResource: "MetalEngineMetalSourcesBundle", ofType: "bundle") else {
return nil
}
guard let bundle = Bundle(path: path) else {
return nil
}
self.device = device
@@ -677,15 +674,42 @@ public final class MetalEngine {
}
self.commandQueue = commandQueue
guard let library = try? device.makeDefaultLibrary(bundle: bundle) else {
return nil
}
self.library = library
let library: MTLLibrary?
guard let vertexFunction = library.makeFunction(name: "clearVertex") else {
#if os(iOS)
let mainBundle = Bundle(for: Impl.self)
guard let path = mainBundle.path(forResource: "MetalEngineMetalSourcesBundle", ofType: "bundle") else {
return nil
}
guard let fragmentFunction = library.makeFunction(name: "clearFragment") else {
guard let bundle = Bundle(path: path) else {
return nil
}
library = try? device.makeDefaultLibrary(bundle: bundle)
#else
let mainBundle = Bundle(for: Impl.self)
guard let path = mainBundle.path(forResource: "MetalEngineMetalSourcesBundle", ofType: "bundle") else {
return nil
}
guard let bundle = Bundle(path: path) else {
return nil
}
guard let path = bundle.path(forResource: "MetalEngineShaders", ofType: "metallib") else {
return nil
}
library = try? device.makeLibrary(URL: .init(fileURLWithPath: path))
#endif
guard let lib = library else {
return nil
}
self.library = lib
guard let vertexFunction = lib.makeFunction(name: "clearVertex") else {
return nil
}
guard let fragmentFunction = lib.makeFunction(name: "clearFragment") else {
return nil
}

View File

@@ -84,7 +84,7 @@ private final class WrappedLegacyReachability: NSObject {
}
}
@available(iOSApplicationExtension 12.0, iOS 12.0, OSX 13.0, *)
@available(iOSApplicationExtension 12.0, iOS 12.0, macOS 14.0, *)
private final class PathMonitor {
private let queue: Queue
private let monitor: NWPathMonitor
@@ -133,7 +133,7 @@ private final class PathMonitor {
}
}
@available(iOSApplicationExtension 12.0, iOS 12.0, OSX 13.0, *)
@available(iOSApplicationExtension 12.0, iOS 12.0, macOS 14.0, *)
private final class SharedPathMonitor {
static let queue = Queue()
static let impl = QueueLocalObject<PathMonitor>(queue: queue, generate: {
@@ -149,7 +149,7 @@ public enum Reachability {
}
public static var networkType: Signal<NetworkType, NoError> {
if #available(iOSApplicationExtension 12.0, iOS 12.0, OSX 13.0, *) {
if #available(iOSApplicationExtension 12.0, iOS 12.0, macOS 14.0, *) {
return Signal { subscriber in
let disposable = MetaDisposable()

View File

@@ -514,7 +514,7 @@ func initializedNetwork(accountId: AccountRecordId, arguments: NetworkInitializa
}
if useNetworkFramework {
if #available(iOS 12.0, macOS 10.14, *) {
if #available(iOS 12.0, macOS 14.0, *) {
context.makeTcpConnectionInterface = { delegate, delegateQueue in
return NetworkFrameworkTcpConnectionInterface(delegate: delegate, delegateQueue: delegateQueue)
}

View File

@@ -4,7 +4,7 @@ import Network
import MtProtoKit
import SwiftSignalKit
@available(iOS 12.0, macOS 10.14, *)
@available(iOS 12.0, macOS 14.0, *)
final class NetworkFrameworkTcpConnectionInterface: NSObject, MTTcpConnectionInterface {
private struct ReadRequest {
let length: Int

View File

@@ -18,6 +18,10 @@ public enum WebpagePreviewResult: Equatable {
case progress
case result(Result?)
}
#if os(macOS)
private typealias UIImage = NSImage
#endif
public func webpagePreview(account: Account, urls: [String], webpageId: MediaId? = nil, forPeerId: PeerId? = nil) -> Signal<WebpagePreviewResult, NoError> {
return webpagePreviewWithProgress(account: account, urls: urls, webpageId: webpageId, forPeerId: forPeerId)
@@ -48,7 +52,7 @@ public func webpagePreviewWithProgress(account: Account, urls: [String], webpage
}
return .single(.result(WebpagePreviewResult.Result(webpage: webpage, sourceUrl: sourceUrl)))
} else {
if #available(iOS 13.0, *) {
if #available(iOS 13.0, macOS 10.15, *) {
if let forPeerId, forPeerId.namespace == Namespaces.Peer.SecretChat, let sourceUrl = urls.first, let url = URL(string: sourceUrl) {
let localHosts: [String] = [
"twitter.com",

View File

@@ -5,6 +5,7 @@ import PackageDescription
let package = Package(
name: "LokiRng",
platforms: [.macOS(.v10_13)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(

View File

@@ -5,6 +5,7 @@ import PackageDescription
let package = Package(
name: "ShelfPack",
platforms: [.macOS(.v10_13)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
@@ -23,5 +24,6 @@ let package = Package(
dependencies: [],
path: ".",
publicHeadersPath: "PublicHeaders"),
]
],
cxxLanguageStandard: .cxx20
)