123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- //
- // Copyright © 2022 osy. All rights reserved.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- //
- import Foundation
- import Virtualization
- @available(iOS, unavailable, message: "Apple Virtualization not available on iOS")
- @available(macOS 11, *)
- struct UTMAppleConfigurationDisplay: Codable, Identifiable {
-
- var widthInPixels: Int = 1920
-
- var heightInPixels: Int = 1200
-
- var pixelsPerInch: Int = 80
-
- let id = UUID()
-
- enum CodingKeys: String, CodingKey {
- case widthInPixels = "WidthPixels"
- case heightInPixels = "HeightPixels"
- case pixelsPerInch = "PixelsPerInch"
- }
-
- init() {
- }
-
- init(width: Int, height: Int, ppi: Int = 80) {
- widthInPixels = width
- heightInPixels = height
- pixelsPerInch = ppi
- }
-
- init(from decoder: Decoder) throws {
- let values = try decoder.container(keyedBy: CodingKeys.self)
- widthInPixels = try values.decode(Int.self, forKey: .widthInPixels)
- heightInPixels = try values.decode(Int.self, forKey: .heightInPixels)
- pixelsPerInch = try values.decode(Int.self, forKey: .pixelsPerInch)
- }
-
- func encode(to encoder: Encoder) throws {
- var container = encoder.container(keyedBy: CodingKeys.self)
- try container.encode(widthInPixels, forKey: .widthInPixels)
- try container.encode(heightInPixels, forKey: .heightInPixels)
- try container.encode(pixelsPerInch, forKey: .pixelsPerInch)
- }
-
- #if arch(arm64)
- @available(macOS 12, *)
- init(from config: VZMacGraphicsDisplayConfiguration) {
- widthInPixels = config.widthInPixels
- heightInPixels = config.heightInPixels
- pixelsPerInch = config.pixelsPerInch
- }
-
- @available(macOS 12, *)
- func vzMacDisplay() -> VZMacGraphicsDisplayConfiguration {
- VZMacGraphicsDisplayConfiguration(widthInPixels: widthInPixels,
- heightInPixels: heightInPixels,
- pixelsPerInch: pixelsPerInch)
- }
- #endif
-
- @available(macOS 13, *)
- func vzVirtioDisplay() -> VZVirtioGraphicsScanoutConfiguration {
- VZVirtioGraphicsScanoutConfiguration(widthInPixels: widthInPixels,
- heightInPixels: heightInPixels)
- }
- }
- // MARK: - Conversion of old config format
- #if arch(arm64)
- @available(iOS, unavailable, message: "Apple Virtualization not available on iOS")
- @available(macOS 12, *)
- extension UTMAppleConfigurationDisplay {
- init(migrating oldDisplay: Display) {
- widthInPixels = oldDisplay.widthInPixels
- heightInPixels = oldDisplay.heightInPixels
- pixelsPerInch = oldDisplay.pixelsPerInch
- }
- }
- #endif
|