Files
VirtualDisplay/src/Resolution.swift
2026-04-11 03:50:41 +09:00

41 lines
1.2 KiB
Swift

import Foundation
struct VDConfig: Equatable {
let pixelWidth: Int
let pixelHeight: Int
let logicalWidth: Int
let logicalHeight: Int
let refreshRate: Int
}
let scalePercents: [Int] = [100, 125, 133, 150, 166, 175, 200]
let maxFramebufferPixelWidth = 6144
let maxFramebufferPixelHeight = 3456
func vdConfig(physicalPixelWidth pw: Int,
physicalPixelHeight ph: Int,
refreshRate: Int,
scalePercent s: Int) -> VDConfig {
let lw = max(1, Int((Double(pw) * 100.0 / Double(s)).rounded()))
let lh = max(1, Int((Double(ph) * 100.0 / Double(s)).rounded()))
return VDConfig(
pixelWidth: lw * 2,
pixelHeight: lh * 2,
logicalWidth: lw,
logicalHeight: lh,
refreshRate: refreshRate
)
}
func availableScales(physicalPixelWidth pw: Int, physicalPixelHeight ph: Int) -> [Int] {
return scalePercents.filter { s in
let cfg = vdConfig(physicalPixelWidth: pw,
physicalPixelHeight: ph,
refreshRate: 60,
scalePercent: s)
return cfg.pixelWidth <= maxFramebufferPixelWidth
&& cfg.pixelHeight <= maxFramebufferPixelHeight
}
}