mirror of
https://github.com/morgan9e/VirtualDisplay
synced 2026-04-15 00:34:10 +09:00
Add source
This commit is contained in:
40
src/Resolution.swift
Normal file
40
src/Resolution.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user