🔥 Delete the window's apple-gfx mode list and density

The apple-gfx device's paravirt glue, deleted in 110b53637, was the only
caller of the window crate's mode list and density, and nothing has called
them since:

- policy.rs: the modes matching a host screen, a chosen mode and the sizes
  within it, the densities told for them, and the scale a macOS 13.6 guest
  runs a mode at from the size it is told. The module goes; the 60 Hz a
  screen of unknown rate runs at moves to screens.rs, which alone used it.
- WindowConfig's match_host_screen and mode_ppi, and Window's
  match_host_screen, chosen_mode, chosen_ppi and told_size.
- REIMS_VGPU_WINDOW_REFRESH, whose rate only those modes took.
- The guest's scale. Nothing told the window a size, so Window::guest_scale
  was 1 for every mode, and the window's sizing on AppKit and SDL, through
  geometry::initial_content_size, divided the mode by 1. The parameter goes
  from each. The tests that sized a mode at guest scale 2 now size the mode
  at half its pixels, and expect the same sizes.

WindowConfig::mode stays: the reims-graphics display offers it first and
opens its window sized for it. The C API is unchanged; reims-vgpu-c's
conversion only drops the two deleted fields. What the guest and the host
observe does not change.
This commit is contained in:
Anees Iqbal committed 2026-11-08 00:20:56 -08:00
1 parent 6659b74e02
commit 3395fa9975
15 files changed
+116 -974

No files matched your search

-2
View File
@@ -221,9 +221,7 @@ impl RvgWindowConfig {
let mode = (self.mode_width != 0 && self.mode_height != 0)
.then_some((self.mode_width, self.mode_height));
WindowConfig {
match_host_screen: false,
mode,
mode_ppi: None,
keeps_its_size: false,
callbacks,
}
+4 -15
View File
@@ -119,22 +119,11 @@ impl std::fmt::Debug for WindowCallbacks {
/// A display's window.
#[derive(Clone, Debug, Default)]
pub struct WindowConfig {
/// The library offers the guest modes, a size in millimetres and a scale factor matching the
/// host screen the window opens on (`policy`), in place of the display config's size and of
/// modes the host sets. A host's own `set_modes` still replaces the modes.
pub match_host_screen: bool,
/// With `match_host_screen`, the mode offered first in place of the screen's own, with the
/// standard sizes within it, at the screen's refresh rate and a 1× density, 110 ppi, or at
/// `mode_ppi`: at 110 the guest runs that mode at 1× (measured up to 3811 pixels wide), and
/// the window scales it on the GPU (`policy::modes_up_to`). `None` offers the screen's own
/// modes at its density. With no screen to match, the mode is offered at 60 Hz, and `None`
/// is `policy::UNMATCHED_MODE` at 1×.
/// The mode the display offers the guest first, `None` leaving it to the display. The
/// window does not read it: the display tells it the mode it offers
/// ([`Window::offered_mode`](crate::Window::offered_mode)), which the window opens sized for
/// until the guest sets one.
pub mode: Option<(u16, u16)>,
/// With `mode`, the density the guest is told for it, in pixels per inch, in place of 110
/// (`policy::density_chosen`): where the guest reads it as 146.67 ppi or more, across the
/// width in whole centimetres (`policy::guest_scale`), it runs a HiDPI desktop at the mode's
/// pixels. `None` is 110. Ignored without `mode`.
pub mode_ppi: Option<f64>,
/// The guest follows the window: the window keeps the size it opened at, or the person gave
/// it, and never resizes for the guest's mode, whose image it fits between black bars as it
/// does once the person has resized it. The reims-graphics display's window, whose guest
+12 -47
View File
@@ -6,8 +6,6 @@
//! - `REIMS_VGPU_WINDOW_SCREENS`: a comma-separated list of host screen indices (spaces
//! allowed): display i opens on the screen the list's i-th entry names. One bad entry unsets
//! the whole list. Default: display i on screen i (`screens::pick_screen`).
//! - `REIMS_VGPU_WINDOW_REFRESH`: the refresh rate, in Hz, of the modes offered to the guest, a
//! number above 0 and up to 1000. Default: the screen's highest (`policy::offered_modes`).
//! - `REIMS_VGPU_WINDOW_IMPL`: on macOS, `sdl`, in any case, opens SDL3's window (`sdl`) in
//! place of AppKit's, in a build with the `macos-sdl` feature, on by default (one without it
//! logs that, and opens AppKit's). Default: AppKit's. Linux has SDL3's alone, and reads no
@@ -19,14 +17,9 @@ use std::sync::OnceLock;
pub const BORDERLESS_VAR: &str = "REIMS_VGPU_WINDOW_BORDERLESS";
/// The screen list's variable.
pub const SCREENS_VAR: &str = "REIMS_VGPU_WINDOW_SCREENS";
/// The refresh rate's variable.
pub const REFRESH_VAR: &str = "REIMS_VGPU_WINDOW_REFRESH";
/// The window implementation's variable (macOS).
pub const IMPL_VAR: &str = "REIMS_VGPU_WINDOW_IMPL";
/// The highest refresh rate the variable accepts, in Hz.
const MAX_REFRESH_HZ: f64 = 1000.0;
/// What the variables say.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Settings {
@@ -34,8 +27,6 @@ pub struct Settings {
pub borderless: bool,
/// The host screen of each display, by port; empty when unset.
pub screens: Vec<usize>,
/// The refresh rate of the offered modes, in Hz, when set.
pub refresh_hz: Option<f64>,
/// Which window a display opens on macOS.
pub window_impl: WindowImpl,
}
@@ -60,11 +51,10 @@ pub fn parse_impl(value: Option<&str>) -> WindowImpl {
}
/// The settings the variables' values give, each `None` where unset.
pub fn parse(borderless: Option<&str>, screens: Option<&str>, refresh: Option<&str>) -> Settings {
pub fn parse(borderless: Option<&str>, screens: Option<&str>) -> Settings {
Settings {
borderless: borderless.is_some_and(parse_switch),
screens: screens.and_then(parse_screens).unwrap_or_default(),
refresh_hz: refresh.and_then(parse_refresh),
window_impl: WindowImpl::AppKit,
}
}
@@ -85,27 +75,16 @@ fn parse_screens(value: &str) -> Option<Vec<usize>> {
.collect()
}
/// A refresh rate above 0 and up to [`MAX_REFRESH_HZ`].
fn parse_refresh(value: &str) -> Option<f64> {
let hz = value.trim().parse::<f64>().ok()?;
(hz.is_finite() && hz > 0.0 && hz <= MAX_REFRESH_HZ).then_some(hz)
}
/// The process's settings, read from its environment the first time they are asked for. A
/// value that is not UTF-8 counts as unset.
pub fn settings() -> &'static Settings {
static SETTINGS: OnceLock<Settings> = OnceLock::new();
SETTINGS.get_or_init(|| {
let var = |name: &str| std::env::var(name).ok();
let (borderless, screens, refresh) =
(var(BORDERLESS_VAR), var(SCREENS_VAR), var(REFRESH_VAR));
let (borderless, screens) = (var(BORDERLESS_VAR), var(SCREENS_VAR));
Settings {
window_impl: parse_impl(var(IMPL_VAR).as_deref()),
..parse(
borderless.as_deref(),
screens.as_deref(),
refresh.as_deref(),
)
..parse(borderless.as_deref(), screens.as_deref())
}
})
}
@@ -117,51 +96,37 @@ mod tests {
/// Unset or unparsable values are the defaults
#[test]
fn unset_or_unparsable_values_are_the_defaults() {
assert_eq!(parse(None, None, None), Settings::default());
assert_eq!(
parse(Some("maybe"), Some("one,two"), Some("fast")),
Settings::default()
);
assert_eq!(parse(Some(""), Some(""), Some("")), Settings::default());
assert_eq!(parse(None, None), Settings::default());
assert_eq!(parse(Some("maybe"), Some("one,two")), Settings::default());
assert_eq!(parse(Some(""), Some("")), Settings::default());
}
/// Borderless is on for 1, true, yes and on, in any case
#[test]
fn borderless_takes_the_usual_words() {
for on in ["1", "true", "TRUE", "Yes", "on", "ON", " on "] {
assert!(parse(Some(on), None, None).borderless, "{on:?}");
assert!(parse(Some(on), None).borderless, "{on:?}");
}
for off in ["0", "false", "no", "off", "2", "enabled", "y"] {
assert!(!parse(Some(off), None, None).borderless, "{off:?}");
assert!(!parse(Some(off), None).borderless, "{off:?}");
}
}
/// The screen list is comma-separated indices, spaces allowed; one bad entry unsets it
#[test]
fn the_screen_list_is_all_or_nothing() {
assert_eq!(parse(None, Some("1,0"), None).screens, vec![1, 0]);
assert_eq!(parse(None, Some(" 2 , 0,1 "), None).screens, vec![2, 0, 1]);
assert_eq!(parse(None, Some("3"), None).screens, vec![3]);
assert_eq!(parse(None, Some("1,0")).screens, vec![1, 0]);
assert_eq!(parse(None, Some(" 2 , 0,1 ")).screens, vec![2, 0, 1]);
assert_eq!(parse(None, Some("3")).screens, vec![3]);
for bad in ["1,,0", "1,0,", "1;0", "-1,0", "1,x", "1.5", ","] {
assert_eq!(
parse(None, Some(bad), None).screens,
parse(None, Some(bad)).screens,
Vec::<usize>::new(),
"{bad:?}"
);
}
}
/// The refresh rate is a finite number above 0 and up to 1000
#[test]
fn the_refresh_rate_is_a_positive_rate_up_to_1000() {
assert_eq!(parse(None, None, Some("120")).refresh_hz, Some(120.0));
assert_eq!(parse(None, None, Some(" 59.94 ")).refresh_hz, Some(59.94));
assert_eq!(parse(None, None, Some("1000")).refresh_hz, Some(1000.0));
for bad in ["0", "-60", "1000.5", "inf", "NaN", "60Hz", ""] {
assert_eq!(parse(None, None, Some(bad)).refresh_hz, None, "{bad:?}");
}
}
/// The window is AppKit's unless the variable names SDL3's
#[test]
fn the_window_is_appkits_unless_sdl_is_named() {
+19 -26
View File
@@ -256,16 +256,13 @@ pub fn button_bit(ns_button_number: i64) -> u32 {
}
}
/// A new window's content size in points, for a guest mode `guest` (width, height) the guest
/// runs at scale `scale` (its pixels per point: 2 for a HiDPI desktop, 1 for a 1× one), with
/// A new window's content size in points, for a guest mode `guest` (width, height), with
/// `visible` the room there is for the content (the screen's visible area less the window's
/// title bar): one guest point per host point, shrunk with its ratio kept where it does not fit.
/// So a HiDPI guest on a Retina screen is one guest pixel per screen pixel, and a 1× guest's
/// pixel is a point, which the draw scales on the GPU. At least one point each way; `visible`
/// with no room is ignored.
pub fn initial_content_size(guest: (u16, u16), scale: f64, visible: (f64, f64)) -> (f64, f64) {
let scale = valid_scale(scale);
let (width, height) = (f64::from(guest.0) / scale, f64::from(guest.1) / scale);
/// title bar): one guest pixel per host point, shrunk with its ratio kept where it does not fit.
/// So on a Retina screen the window's drawable is twice the mode each way. At least one point
/// each way; `visible` with no room is ignored.
pub fn initial_content_size(guest: (u16, u16), visible: (f64, f64)) -> (f64, f64) {
let (width, height) = (f64::from(guest.0), f64::from(guest.1));
let (room_w, room_h) = (non_negative(visible.0), non_negative(visible.1));
let shrink = if room_w > 0.0 && room_h > 0.0 && width > 0.0 && height > 0.0 {
(room_w / width).min(room_h / height).min(1.0)
@@ -687,21 +684,20 @@ mod tests {
assert_eq!(all.iter().fold(0, |a, b| a | b).count_ones(), 5);
}
/// A new window shows a guest point per host point: a HiDPI guest one guest pixel per screen
/// pixel, a 1× guest's pixel as a point
/// A new window shows a guest pixel per host point
#[test]
fn a_new_window_shows_a_guest_point_per_host_point() {
assert_eq!(
initial_content_size((1920, 1200), 2.0, (1728.0, 1080.0)),
initial_content_size((960, 600), (1728.0, 1080.0)),
(960.0, 600.0)
);
assert_eq!(
initial_content_size((1280, 800), 1.0, (1920.0, 1050.0)),
initial_content_size((1280, 800), (1920.0, 1050.0)),
(1280.0, 800.0)
);
// Its drawable, at that scale, is the guest mode, and the image fills it.
let size = initial_content_size((1920, 1200), 2.0, (1728.0, 1080.0));
let l = layout(size, 2.0, NO_INSETS, Some((1920, 1200)));
// On a 1× screen its drawable is the guest mode, and the image fills it.
let size = initial_content_size((1920, 1200), (1920.0, 1200.0));
let l = layout(size, 1.0, NO_INSETS, Some((1920, 1200)));
assert_eq!(l.drawable, (1920, 1200));
assert_eq!(
l.pixels,
@@ -712,9 +708,9 @@ mod tests {
height: 1200
}
);
// A 1× 1920×1080 guest on a Retina screen opens at 1920×1080 points where they fit: its
// drawable is twice the mode each way, and the image, scaled on the GPU, fills it.
let size = initial_content_size((1920, 1080), 1.0, (1920.0, 1200.0));
// 1920×1080 on a Retina screen opens at 1920×1080 points where they fit: its drawable is
// twice the mode each way, and the image, scaled on the GPU, fills it.
let size = initial_content_size((1920, 1080), (1920.0, 1200.0));
assert_eq!(size, (1920.0, 1080.0));
let l = layout(size, 2.0, NO_INSETS, Some((1920, 1080)));
assert_eq!(l.drawable, (3840, 2160));
@@ -732,23 +728,20 @@ mod tests {
/// A guest larger than the screen's visible area is shrunk to fit it, ratio kept
#[test]
fn a_new_window_shrinks_to_the_visible_area() {
let (w, h) = initial_content_size((3456, 2160), 2.0, (1728.0, 1050.0));
let (w, h) = initial_content_size((1728, 1080), (1728.0, 1050.0));
assert!(
(w - 1680.0).abs() < 1e-9 && (h - 1050.0).abs() < 1e-9,
"{w}x{h}"
);
let (w, h) = initial_content_size((3840, 2160), 1.0, (1920.0, 1200.0));
let (w, h) = initial_content_size((3840, 2160), (1920.0, 1200.0));
assert_eq!((w, h), (1920.0, 1080.0));
// No room given: left at 1:1.
assert_eq!(
initial_content_size((1024, 768), 1.0, (0.0, 0.0)),
initial_content_size((1024, 768), (0.0, 0.0)),
(1024.0, 768.0)
);
// Never below a point.
assert_eq!(
initial_content_size((0, 0), 2.0, (100.0, 100.0)),
(1.0, 1.0)
);
assert_eq!(initial_content_size((0, 0), (100.0, 100.0)), (1.0, 1.0));
}
/// A window following the guest's mode keeps its top left corner where the new size fits
-43
View File
@@ -54,7 +54,6 @@ pub use crate::present::FrameSink;
use crate::config::{WindowCallbacks, WindowConfig};
use crate::native::{self, Surface};
use crate::policy;
/// The next window's id.
static NEXT_ID: AtomicU64 = AtomicU64::new(1);
@@ -216,12 +215,6 @@ pub struct Window {
port: u64,
/// The window's title.
title: String,
/// The config's flag.
match_host_screen: bool,
/// The config's chosen mode.
chosen_mode: Option<(u16, u16)>,
/// The config's density for the chosen mode.
chosen_ppi: Option<f64>,
/// The config's `keeps_its_size`.
keeps_its_size: bool,
/// The host's callbacks, until the window's end takes them out.
@@ -230,9 +223,6 @@ pub struct Window {
guest: Mutex<GuestState>,
/// The first mode the display offers the guest, once it offers one.
offered: Mutex<Option<(u16, u16)>>,
/// The size in millimetres the display tells the guest, once it is known: what the guest's
/// scale follows ([`policy::guest_scale`]).
told_size: Mutex<Option<(f64, f64)>>,
/// What draws the display's frames, once the display exists.
sink: Mutex<Option<Arc<dyn FrameSink>>>,
/// Set at the window's end.
@@ -280,14 +270,10 @@ impl Window {
id: NEXT_ID.fetch_add(1, Ordering::Relaxed),
port,
title,
match_host_screen: config.match_host_screen,
chosen_mode: config.mode,
chosen_ppi: config.mode_ppi,
keeps_its_size: config.keeps_its_size,
callbacks: Mutex::new(Some(config.callbacks)),
guest: Mutex::new(GuestState::default()),
offered: Mutex::new(None),
told_size: Mutex::new(None),
sink: Mutex::new(None),
closed: AtomicBool::new(false),
attached: AtomicBool::new(false),
@@ -309,11 +295,6 @@ impl Window {
&self.title
}
/// Whether the config asked for modes and a density matching the host's screen.
pub fn match_host_screen(&self) -> bool {
self.match_host_screen
}
/// Opens the window over `sink`, the display's: its render thread starts, and the window
/// opens on the UI thread (on macOS, when the main thread runs its run loop). Does nothing
/// after the end; a second attach only replaces the sink.
@@ -475,26 +456,10 @@ impl Window {
*self.offered.lock()
}
/// The config's chosen mode (`WindowConfig::mode`).
pub fn chosen_mode(&self) -> Option<(u16, u16)> {
self.chosen_mode
}
/// The config's density for its chosen mode (`WindowConfig::mode_ppi`).
pub fn chosen_ppi(&self) -> Option<f64> {
self.chosen_ppi
}
/// Whether the window never resizes for the guest's mode (`WindowConfig::keeps_its_size`).
pub fn keeps_its_size(&self) -> bool {
self.keeps_its_size
}
/// The display tells the guest it is `size_in_millimeters`: the window opens and resizes at
/// a guest point per host point, the guest's scale for each mode following it.
pub fn told_size(&self, size_in_millimeters: (f64, f64)) {
*self.told_size.lock() = Some(size_in_millimeters);
}
}
/// What the window's backend reads of it.
@@ -566,14 +531,6 @@ impl Window {
self.guest.lock().mode
}
/// The scale the guest runs `mode` at: 2 or 1 by the size the display tells it
/// ([`policy::guest_scale`]), 1 before the display says.
pub(crate) fn guest_scale(&self, mode: (u16, u16)) -> u8 {
self.told_size
.lock()
.map_or(1, |size| policy::guest_scale(mode, size))
}
/// The sink, copied out of its lock, until the window's end.
pub(crate) fn sink(&self) -> Option<Arc<dyn FrameSink>> {
self.sink.lock().clone()
+2 -5
View File
@@ -22,9 +22,8 @@
//! - what a window decides, with no AppKit in it, each unit-tested: [`geometry`] (the image's
//! rectangle and the pointer's position in it), [`keymap`] (macOS key codes to USB usages),
//! [`keys`] (modifiers and the keys held down), [`capture`] (who gets the keyboard, and where
//! the pointer may go), [`scroll`] (wheel and trackpad deltas to notches or smooth scrolling),
//! [`policy`] (the modes and density the guest is offered for a host screen) and
//! [`env`](mod@env) (the `REIMS_VGPU_WINDOW_*` variables);
//! the pointer may go), [`scroll`] (wheel and trackpad deltas to notches or smooth scrolling)
//! and [`env`](mod@env) (the `REIMS_VGPU_WINDOW_*` variables);
//! - the host's screens ([`screens`]), as the OS lists them;
//! - the window itself: [`handle`] (the [`Window`] the display holds), and its OS side
//! (`native`, one directory per OS behind one file). On macOS (`native/macos/`) that is the
@@ -49,7 +48,6 @@ pub mod handle;
pub mod keymap;
pub mod keys;
mod native;
pub mod policy;
mod present;
pub mod screens;
pub mod scroll;
@@ -65,7 +63,6 @@ pub use config::{
WindowConfig,
};
pub use handle::{DrawnCursor, FrameSink, Glyph, PixelRect, Window};
pub use policy::{Density, OfferedMode};
pub use present::{Drawn, Presenter, VulkanTarget};
pub use screens::HostScreen;
@@ -129,9 +129,9 @@ fn units_of(display: SDL_DisplayID) -> Units {
Units::new(density, content)
}
/// The content size, in SDL's sizes, of a windowed window for a guest mode `mode` at
/// `guest_scale`, on screen `display` (the module doc): at least `shell::MIN_CONTENT` points.
fn windowed_size(display: SDL_DisplayID, mode: (u16, u16), guest_scale: u8) -> (i32, i32) {
/// The content size, in SDL's sizes, of a windowed window for a guest mode `mode`, on screen
/// `display` (the module doc): at least `shell::MIN_CONTENT` points.
fn windowed_size(display: SDL_DisplayID, mode: (u16, u16)) -> (i32, i32) {
let mut usable = SDL_Rect {
x: 0,
y: 0,
@@ -141,7 +141,7 @@ fn windowed_size(display: SDL_DisplayID, mode: (u16, u16), guest_scale: u8) -> (
// SAFETY: SDL's video runs on this thread.
let known = unsafe { SDL_GetDisplayUsableBounds(display, &mut usable) };
let usable = known.then_some((usable.w, usable.h));
units::windowed_size(mode, guest_scale, usable, TITLE_ROOM, units_of(display))
units::windowed_size(mode, usable, TITLE_ROOM, units_of(display))
}
/// Makes and shows `window`'s SDL window (the module doc), and hands its render thread SDL's
@@ -153,7 +153,7 @@ pub(crate) fn open(window: &Arc<Window>, borderless: bool, _taken: &[Frame]) ->
|s| SDL_DisplayID(s.id),
);
let mode = window.mode().or(window.offered()).unwrap_or(DEFAULT_MODE);
let size = windowed_size(display, mode, window.guest_scale(mode));
let size = windowed_size(display, mode);
let min = units_of(display).min_content();
let title = c_string(window.title());
let flags = SDL_WINDOW_VULKAN
@@ -194,7 +194,7 @@ pub(crate) fn open(window: &Arc<Window>, borderless: bool, _taken: &[Frame]) ->
/// Resizes a window following the guest's mode for `mode`, as it would open on its screen.
pub(crate) fn follow(shell: &mut Shell, mode: (u16, u16), _taken: &[Frame]) {
let size = windowed_size(shell.os.display, mode, shell.window.guest_scale(mode));
let size = windowed_size(shell.os.display, mode);
if size != shell.asked {
shell.asked = size;
// SAFETY: the window is SDL's, on this thread.
@@ -15,8 +15,7 @@
//! window closes, as the windows' end is the display's.
//!
//! Where SDL's video does not start (no Wayland compositor and no X server to reach), the reason
//! is logged once, no window opens, the work posted is dropped, and the host's screens are none:
//! a display matching its host screen then offers what `crate::policy` gives without a screen.
//! is logged once, no window opens, the work posted is dropped, and the host's screens are none.
//!
//! **The host's screens** ([`screens`]): a snapshot the UI thread takes once SDL's video starts
//! and again when SDL reports a screen added, removed, moved or changed. The main screen (SDL's
@@ -166,13 +166,7 @@ pub(crate) fn open(window: &Arc<Window>, borderless: bool, taken: &[Frame]) -> O
appkit::screen_frame(screen.as_deref())
} else {
let mode = window.mode().or(window.offered()).unwrap_or(DEFAULT_MODE);
appkit::windowed_frame(
screen.as_deref(),
mode,
window.guest_scale(mode),
taken,
mtm,
)
appkit::windowed_frame(screen.as_deref(), mode, taken, mtm)
};
let title = c_string(window.title());
let flags =
@@ -241,8 +235,7 @@ pub(crate) fn follow(shell: &mut Shell, mode: (u16, u16), taken: &[Frame]) {
};
let ns_window = &shell.os.ns_window;
let frame = msg::get("frame", || ns_window.frame());
let resized =
appkit::followed_frame(ns_window, mode, shell.window.guest_scale(mode), taken, mtm);
let resized = appkit::followed_frame(ns_window, mode, taken, mtm);
if resized != frame {
msg::get("setFrame:display:", || {
ns_window.setFrame_display(resized, true);
@@ -3,20 +3,18 @@
//!
//! **The screen.** A window opens on the `NSScreen` whose `deviceDescription["NSScreenNumber"]`
//! is the CoreGraphics display [`screens::screen_for_port`] picks for the display's port, else on
//! `NSScreen.mainScreen`, so the screen whose density the guest was told of is the one it opens
//! on.
//! `NSScreen.mainScreen`.
//!
//! **Windowed** (the default): titled, closable, miniaturizable and resizable, and able to go
//! full screen; while its input is captured it is not resizable, and it is again once released
//! ([`resizable_change`], which the view applies). Its content is the guest's mode, else the first mode the display offers, else
//! 1920×1080, at one guest point per host point (a HiDPI guest's pixel is a screen pixel, a 1×
//! guest's a point, which the draw scales on the GPU), shrunk to fit the screen's visible area
//! less the title bar ([`geometry::initial_content_size`]), centred there. The guest's scale
//! for a mode follows the size in millimetres the display told it ([`Window::told_size`]). A display offers its
//! modes when it is made, before its window opens, and the guest sets a mode later, so a window
//! opens at the mode offered first. A window whose top left would be another windowed window's
//! moves 24 points right and down, made smaller, its ratio kept, where it would leave the
//! visible area, but not below [`MIN_CONTENT`] ([`cascade`]).
//! ([`resizable_change`], which the view applies). Its content is the guest's mode, else the
//! first mode the display offers, else 1920×1080, at one guest pixel per host point (on a Retina
//! screen a guest pixel is two screen pixels each way, scaled on the GPU), shrunk to fit the
//! screen's visible area less the title bar ([`geometry::initial_content_size`]), centred there.
//! A display offers its modes when it is made, before its window opens, and the guest sets a
//! mode later, so a window opens at the mode offered first. A window whose top left would be
//! another windowed window's moves 24 points right and down, made smaller, its ratio kept, where
//! it would leave the visible area, but not below [`MIN_CONTENT`] ([`cascade`]).
//!
//! Until the person resizes it (an edge, tiling, zoom, full screen), a windowed window follows
//! the guest's mode: each mode change resizes its content as the window would open on its
@@ -417,8 +415,6 @@ const CASCADE: f64 = 24.0;
struct Sizing {
/// The guest's mode, whose ratio the content keeps.
mode: (u16, u16),
/// The scale the guest runs the mode at: its pixels per point.
guest_scale: f64,
/// The screen's backing scale.
scale: f64,
/// The title bar and borders: the frame less the content.
@@ -426,7 +422,7 @@ struct Sizing {
}
impl Sizing {
/// The content of a frame at most `room`: one guest point per host point, shrunk with its
/// The content of a frame at most `room`: one guest pixel per host point, shrunk with its
/// ratio kept where it does not fit ([`geometry::initial_content_size`]), on whole pixels, a
/// multiple of [`geometry::MODE_WIDTH_STEP`] wide and of [`geometry::MODE_HEIGHT_STEP`]
/// high, so the drawable is the content exactly and the mode the guest is offered for it
@@ -434,7 +430,6 @@ impl Sizing {
fn content(&self, room: NSSize) -> NSSize {
let (width, height) = geometry::initial_content_size(
self.mode,
self.guest_scale,
(
room.width - self.chrome.width,
room.height - self.chrome.height,
@@ -517,15 +512,10 @@ struct Fit {
frame: NSSize,
}
/// The size of a windowed window showing a guest mode `mode`, which the guest runs at
/// `guest_scale`, on `screen` (module doc): one guest point per host point, shrunk to fit the
/// screen's visible area less the title bar, on whole pixels.
fn windowed_fit(
screen: Option<&NSScreen>,
mode: (u16, u16),
guest_scale: u8,
mtm: MainThreadMarker,
) -> Fit {
/// The size of a windowed window showing a guest mode `mode` on `screen` (module doc): one guest
/// pixel per host point, shrunk to fit the screen's visible area less the title bar, on whole
/// pixels.
fn windowed_fit(screen: Option<&NSScreen>, mode: (u16, u16), mtm: MainThreadMarker) -> Fit {
let (visible, scale) = screen.map_or(
(
NSRect::new(NSPoint::new(0.0, 0.0), NSSize::new(1920.0, 1080.0)),
@@ -545,7 +535,6 @@ fn windowed_fit(
});
let sizing = Sizing {
mode,
guest_scale: f64::from(guest_scale.max(1)),
scale,
chrome: NSSize::new(
framed.size.width - probe.size.width,
@@ -561,13 +550,11 @@ fn windowed_fit(
}
}
/// The frame of a windowed window for a guest mode `mode`, which the guest runs at
/// `guest_scale`, on `screen`, clear of the frames `taken` (module doc): centred in the screen's
/// visible frame, then cascaded.
/// The frame of a windowed window for a guest mode `mode` on `screen`, clear of the frames
/// `taken` (module doc): centred in the screen's visible frame, then cascaded.
pub(crate) fn windowed_frame(
screen: Option<&NSScreen>,
mode: (u16, u16),
guest_scale: u8,
taken: &[NSRect],
mtm: MainThreadMarker,
) -> NSRect {
@@ -576,31 +563,29 @@ pub(crate) fn windowed_frame(
sizing,
frame: frame_size,
..
} = windowed_fit(screen, mode, guest_scale, mtm);
} = windowed_fit(screen, mode, mtm);
let origin = NSPoint::new(
visible.origin.x + ((visible.size.width - frame_size.width) / 2.0).floor(),
visible.origin.y + ((visible.size.height - frame_size.height) / 2.0).floor(),
);
let frame = cascade(NSRect::new(origin, frame_size), &sizing, visible, taken);
log::debug!(
"windowed: visible {visible:?} at scale {}, mode {mode:?} at guest scale \
{guest_scale}: frame {frame:?}",
"windowed: visible {visible:?} at scale {}, mode {mode:?}: frame {frame:?}",
sizing.scale
);
frame
}
/// A windowed window for a guest mode `mode`, which the guest runs at `guest_scale`, on
/// `screen`, clear of the frames `taken` (module doc).
/// A windowed window for a guest mode `mode` on `screen`, clear of the frames `taken` (module
/// doc).
fn windowed(
screen: Option<&NSScreen>,
mode: (u16, u16),
guest_scale: u8,
taken: &[NSRect],
mtm: MainThreadMarker,
) -> Retained<DisplayWindow> {
let style = windowed_style();
let frame = windowed_frame(screen, mode, guest_scale, taken, mtm);
let frame = windowed_frame(screen, mode, taken, mtm);
let content_rect = msg::get("contentRectForFrameRect:styleMask:", || {
NSWindow::contentRectForFrameRect_styleMask(frame, style, mtm)
});
@@ -665,20 +650,19 @@ fn y_up(rect: Rect) -> NSRect {
)
}
/// Resizes windowed `window`, whose delegate is `delegate`, for the guest mode `mode`, which the
/// guest runs at `guest_scale`, as it would open on its screen, keeping its top left corner, moved inside the screen's visible area
/// Resizes windowed `window`, whose delegate is `delegate`, for the guest mode `mode`, as it would
/// open on its screen, keeping its top left corner, moved inside the screen's visible area
/// ([`geometry::resized_frame`]), then clear of the frames `taken` ([`cascade`]). The delegate
/// knows the resize for the library's.
fn follow(
window: &DisplayWindow,
delegate: &WindowDelegate,
mode: (u16, u16),
guest_scale: u8,
taken: &[NSRect],
mtm: MainThreadMarker,
) {
let frame = msg::get("frame", || window.frame());
let resized = followed_frame(window, mode, guest_scale, taken, mtm);
let resized = followed_frame(window, mode, taken, mtm);
if resized != frame {
delegate.ivars().resizing.set(true);
msg::get("setFrame:display:", || {
@@ -688,19 +672,17 @@ fn follow(
}
}
/// The frame windowed `window` takes for the guest mode `mode`, which the guest runs at
/// `guest_scale`, as it would open on its screen, keeping its top left corner, moved inside the
/// screen's visible area ([`geometry::resized_frame`]), then clear of the frames `taken`
/// ([`cascade`]).
/// The frame windowed `window` takes for the guest mode `mode`, as it would open on its screen,
/// keeping its top left corner, moved inside the screen's visible area
/// ([`geometry::resized_frame`]), then clear of the frames `taken` ([`cascade`]).
pub(crate) fn followed_frame(
window: &NSWindow,
mode: (u16, u16),
guest_scale: u8,
taken: &[NSRect],
mtm: MainThreadMarker,
) -> NSRect {
let screen = msg::get("screen", || window.screen()).or_else(|| main_screen(mtm));
let fit = windowed_fit(screen.as_deref(), mode, guest_scale, mtm);
let fit = windowed_fit(screen.as_deref(), mode, mtm);
let frame = msg::get("frame", || window.frame());
let resized = y_up(geometry::resized_frame(
y_down(frame),
@@ -709,8 +691,7 @@ pub(crate) fn followed_frame(
));
let resized = cascade(resized, &fit.sizing, fit.visible, taken);
log::debug!(
"following guest mode {mode:?} at guest scale {guest_scale}, scale {}: content {:?}, \
frame {frame:?} to {resized:?}",
"following guest mode {mode:?}, scale {}: content {:?}, frame {frame:?} to {resized:?}",
fit.sizing.scale,
fit.content
);
@@ -847,13 +828,7 @@ pub(crate) fn open(window: &Arc<Window>, mtm: MainThreadMarker) {
} else {
let taken = windowed_frames(None, mtm);
let mode = window.mode().or(window.offered()).unwrap_or(DEFAULT_MODE);
windowed(
screen.as_deref(),
mode,
window.guest_scale(mode),
&taken,
mtm,
)
windowed(screen.as_deref(), mode, &taken, mtm)
};
let frame = msg::get("frame", || ns_window.frame());
let bounds = msg::get("contentRectForFrameRect:", || {
@@ -938,14 +913,7 @@ pub(crate) fn guest_mode_changed(id: u64, mtm: MainThreadMarker) {
&& let Some(mode) = view.guest_mode()
{
let taken = windowed_frames(Some(id), mtm);
follow(
&window,
&delegate,
mode,
view.guest_scale(mode),
&taken,
mtm,
);
follow(&window, &delegate, mode, &taken, mtm);
}
view.relayout();
}
@@ -1022,8 +990,7 @@ mod tests {
fn windows_on_one_screen_cascade() {
let visible = rect((0.0, 100.0), (1728.0, 962.0));
let sizing = Sizing {
mode: (1920, 1080),
guest_scale: 2.0,
mode: (960, 540),
scale: 2.0,
chrome: NSSize::new(0.0, 32.0),
};
@@ -1047,7 +1014,6 @@ mod tests {
let visible = rect((0.0, 0.0), (400.0, 260.0));
let sizing = Sizing {
mode: (640, 400),
guest_scale: 1.0,
scale: 1.0,
chrome: NSSize::new(0.0, 30.0),
};
@@ -1071,8 +1037,7 @@ mod tests {
fn a_cascaded_window_shrinks_rather_than_overlap() {
let visible = rect((0.0, 100.0), (1728.0, 1110.0));
let sizing = Sizing {
mode: (3456, 2160),
guest_scale: 2.0,
mode: (1728, 1080),
scale: 2.0,
chrome: NSSize::new(0.0, 30.0),
};
@@ -1096,8 +1061,7 @@ mod tests {
assert_eq!(resize_increments(f64::NAN), NSSize::new(16.0, 2.0));
// A content on those steps stays on them at any count of steps.
let sizing = Sizing {
mode: (3456, 2160),
guest_scale: 2.0,
mode: (1728, 1080),
scale: 2.0,
chrome: NSSize::new(0.0, 30.0),
};
@@ -437,11 +437,6 @@ impl DisplayView {
self.ivars().window.mode()
}
/// The scale the guest runs `mode` at (`Window::guest_scale`).
pub(crate) fn guest_scale(&self, mode: (u16, u16)) -> u8 {
self.ivars().window.guest_scale(mode)
}
/// Whether the window never resizes for the guest's mode (`Window::keeps_its_size`).
pub(crate) fn keeps_its_size(&self) -> bool {
self.ivars().window.keeps_its_size()
-708
View File
@@ -1,708 +0,0 @@
//! The modes, the size in millimetres and the scale factor a display matching its host screen
//! offers the guest (`WindowConfig::match_host_screen`), and the scale a guest runs a mode at.
//!
//! **A chosen mode** (`WindowConfig::mode`, QEMU's `resolution`, 1920×1080 by default there):
//! the mode first, then the standard sizes of each ratio within it ([`modes_up_to`]), at 110
//! ppi, a 1× guest desktop ([`density_1x`]). The window scales it to its size on the GPU. A
//! density chosen with it (`WindowConfig::mode_ppi`, QEMU's `resolution=2560x1600@200`) is told
//! in place of 110 ppi ([`density_chosen`]): where the guest reads it as 146.67 ppi or more
//! ([`guest_scale`]), it runs a HiDPI desktop at the mode's pixels.
//!
//! **The screen's own modes** (no mode chosen) fill the screen: the largest 16:10, 16:9 and 4:3
//! rectangles within its pixels, 16:10 first (the one the guest prefers), then the standard
//! smaller sizes of each ratio ([`offered_modes`]). Their density follows the screen's backing
//! scale: 110 pixels per inch per unit of scale, so a Retina screen (scale 2) is told 220 ppi
//! and gets a HiDPI guest desktop, and a 1× screen is told 110 ppi and gets a 1× one
//! ([`density`]).
//!
//! Either way the modes run at the screen's refresh rate (its current mode's, the rate the
//! person set it to, `crate::screens`), or at `REIMS_VGPU_WINDOW_REFRESH`'s, and the size in millimetres is the first mode's pixels at the
//! density. The scale factor is 2 above 143 ppi for the screen's own modes, and for a chosen
//! density the scale the guest runs the mode at ([`guest_scale`]).
//!
//! **Without a screen** (as for a VM started from an ssh shell, with no window system to reach):
//! the chosen mode as above, or [`UNMATCHED_MODE`] at 1× where none is chosen, at 60 Hz
//! ([`DEFAULT_REFRESH_HZ`]) or `REIMS_VGPU_WINDOW_REFRESH`'s. A display that offered nothing
//! would leave the guest no mode to set, and macOS stops its boot at the Apple logo.
//!
//! **The guest's scale.** Measured with a macOS 13.6 guest (22G120) on the M3 Max's built-in
//! screen, each boot from a fresh clone, so that no display settings were saved for it (the
//! scale shows in the menu bar's height in the guest's pixels: 24 at 1×, 48 at HiDPI):
//! - the guest reads the width it is told in whole centimetres: rounded to whole millimetres,
//! as the display's settings page holds it, then up to whole centimetres. 611.04 mm reads as
//! 62 cm, 590.54 as 60 (591 mm), 446.42 as 45 and 440.39 as 44 (440 mm);
//! - it picks its default from the pixels per inch across that width, pixels / (centimetres ×
//! 10 / 25.4): 1× (the mode at 1×) at up to 3811 pixels across 66 cm (146.666 ppi), HiDPI
//! (looking like half the mode) from 2021 pixels across 35 cm (146.667 ppi), for modes from
//! 1920 to 3811 pixels wide:
//! - 1× at 141.6 and 143.9 (3456 pixels across 62 and 61 cm), 144.5 (2560 across 45), 146.30
//! (3456 across 60), 146.62 (2944 across 51), 146.657 (2656 across 46), 146.665 (1790
//! across 31) and 146.666 (3811 across 66);
//! - HiDPI at 146.667 (2021 across 35), 146.673 (3176 across 55), 146.76 (2080 across 36),
//! 146.93 (3008 across 52), 147.8 (2560 across 44, 1920 across 33), 148.1 (2624 across 45),
//! 148.6 (2048 across 35), 216.7 (5120 across 60), 224.2 (2560 across 29), and 148.8,
//! 159.6, 219.5 and 250.8 (3456 across 59, 55, 40 and 35);
//! - between 146.666 and 146.667 it was not measured, and [`guest_scale`] takes it as 1×;
//! - the height does not change it: 3456 across 60 cm is 1× with 2160 pixels across 37 cm
//! (148.3 ppi), and 2048 across 35 is HiDPI with 1536 across 27 (144.5);
//! - neither does the page's scale factor: told 254 ppi with a scale factor of 1, it still runs
//! at 2×. The guest never sent its compositor's parameters;
//! - a much wider mode does not follow it: 5832×3645 ran HiDPI where it read 128.8 ppi (115 cm)
//! as well as at 146.666 (101 cm), and ran 1× nowhere. Where between 3811 and 5832 pixels
//! the guest turns HiDPI below 146.667 ppi, 110 ppi included, was not measured, and
//! [`guest_scale`] takes such a mode as 1×;
//! - nor does a narrow mode: 1280×800 ran 1× where it read 216.7 ppi across 15 cm (HiDPI would
//! look like 640×400). HiDPI was measured from 1920 pixels wide (33 cm) and from 29 cm (2560
//! pixels); whether the pixels or the centimetres kept 1280×800 at 1×, and where between,
//! was not measured. [`guest_scale`] takes a mode narrower than 1920 pixels as 1×, and a
//! size below 29 cm by its density;
//! - so 72 ppi per unit of scale, 144 for a Retina screen, read as 141.6, gave that screen a 1×
//! desktop; 110 per unit of scale puts 1× and 2× screens each well on their own side.
use crate::screens::HostScreen;
/// A mode offered to the guest.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct OfferedMode {
/// Pixels wide.
pub width: u16,
/// Pixels high.
pub height: u16,
/// The refresh rate, in Hz.
pub refresh_hz: f64,
}
/// What the guest is told of the display's density.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Density {
/// Width, then height.
pub size_in_millimeters: (f64, f64),
/// The descriptor's scale factor: 2 for a HiDPI screen, else 1. A macOS 13.6 guest picks its
/// default from the size alone (module doc).
pub scale_factor: u8,
}
/// A ratio the guest is offered, and its standard sizes.
struct Ratio {
/// Width to height.
ratio: (u64, u64),
/// Its standard sizes, largest first.
sizes: &'static [(u16, u16)],
}
/// The ratios offered, in the order their largest modes are listed.
const RATIOS: [Ratio; 3] = [
Ratio {
ratio: (16, 10),
sizes: &[
(2560, 1600),
(1920, 1200),
(1680, 1050),
(1440, 900),
(1280, 800),
],
},
Ratio {
ratio: (16, 9),
sizes: &[
(3840, 2160),
(2560, 1440),
(1920, 1080),
(1600, 900),
(1280, 720),
],
},
Ratio {
ratio: (4, 3),
sizes: &[(2048, 1536), (1600, 1200), (1400, 1050), (1024, 768)],
},
];
/// The most modes offered.
pub const MAX_MODES: usize = 128;
/// The rate used where neither the override nor the screen gives one, in Hz.
pub const DEFAULT_REFRESH_HZ: f64 = 60.0;
/// The mode offered first, at 1×, where there is no screen to match and no mode is chosen:
/// QEMU's default `resolution`.
pub const UNMATCHED_MODE: (u16, u16) = (1920, 1080);
/// The pixels per inch the guest is told per unit of the screen's backing scale.
const PPI_PER_SCALE: f64 = 110.0;
/// Above this many pixels per inch the scale factor told for the screen's own modes is 2.
const HIDPI_ABOVE_PPI: f64 = 143.0;
/// The least density a macOS 13.6 guest was measured to run a mode 1920 to 3811 pixels wide
/// HiDPI at, as pixels across whole centimetres: 2021 across 35 (146.667 ppi). It ran 1× at
/// 3811 across 66 (146.666 ppi), the most measured there (module doc); a wider mode ran HiDPI
/// below both.
const HIDPI_FROM: (f64, f64) = (2021.0, 35.0);
/// The narrowest mode a macOS 13.6 guest was measured to run HiDPI, in pixels: 1920 across 33
/// cm. 1280 across 15 cm ran 1× at 216.7 ppi (module doc).
const HIDPI_NARROWEST: u16 = 1920;
/// The divisor of pixels per inch that gives pixels per millimetre. It is 25.46, not the 25.4
/// millimetres of an inch, and kept so: changing it changes the size every guest is told.
const MILLIMETERS_DIVISOR: f64 = 25.46;
/// The largest `ratio` rectangle within `pixels`, each side rounded down to a multiple of 8.
/// `None` where that leaves a side empty.
fn largest(pixels: (u64, u64), ratio: (u64, u64)) -> Option<(u16, u16)> {
let (pw, ph) = pixels;
let (rw, rh) = ratio;
let (w, h) = if pw * rh <= ph * rw {
(pw, pw * rh / rw)
} else {
(ph * rw / rh, ph)
};
let (w, h) = (w & !7, h & !7);
if w == 0 || h == 0 {
return None;
}
Some((u16::try_from(w).ok()?, u16::try_from(h).ok()?))
}
/// The rate the modes run at: `refresh_hz` where given, else the screen's, else
/// [`DEFAULT_REFRESH_HZ`].
fn refresh(screen: Option<&HostScreen>, refresh_hz: Option<f64>) -> f64 {
let valid = |hz: f64| hz.is_finite() && hz > 0.0;
match (refresh_hz, screen) {
(Some(hz), _) if valid(hz) => hz,
(_, Some(screen)) if valid(screen.refresh_hz) => screen.refresh_hz,
_ => DEFAULT_REFRESH_HZ,
}
}
/// The modes offered for `screen`, the first the preferred one. `refresh_hz` overrides the
/// screen's rate. Empty for a screen with no pixels.
///
/// First the largest 16:10, 16:9 and 4:3 rectangles within the screen's pixels, each side
/// rounded down to a multiple of 8; then, for each ratio in that order, its standard sizes
/// smaller than its largest. No mode is listed twice; every side is below 65536; there are at
/// most [`MAX_MODES`].
pub fn offered_modes(screen: &HostScreen, refresh_hz: Option<f64>) -> Vec<OfferedMode> {
let refresh_hz = refresh(Some(screen), refresh_hz);
let limit = u64::from(u16::MAX);
let pixels = (
u64::from(screen.pixels.0).min(limit),
u64::from(screen.pixels.1).min(limit),
);
let largest: Vec<Option<(u16, u16)>> =
RATIOS.iter().map(|r| largest(pixels, r.ratio)).collect();
let smaller = RATIOS.iter().zip(&largest).flat_map(|(r, top)| {
r.sizes
.iter()
.copied()
.filter(move |&(w, h)| top.is_some_and(|(top_w, top_h)| w < top_w && h < top_h))
});
let mut modes: Vec<OfferedMode> = Vec::new();
for (width, height) in largest.iter().flatten().copied().chain(smaller) {
if modes.len() == MAX_MODES {
break;
}
if modes.iter().any(|m| (m.width, m.height) == (width, height)) {
continue;
}
modes.push(OfferedMode {
width,
height,
refresh_hz,
});
}
modes
}
/// The modes offered for a chosen mode `mode` (width, height) on `screen`: `mode` first, then,
/// for each ratio in order, its standard sizes within `mode` (neither side larger). No mode is
/// listed twice. `refresh_hz` overrides the screen's rate, as for [`offered_modes`].
/// Empty for a mode with an empty side. With no `screen`, the rate is `refresh_hz`, or else
/// [`DEFAULT_REFRESH_HZ`].
pub fn modes_up_to(
mode: (u16, u16),
screen: Option<&HostScreen>,
refresh_hz: Option<f64>,
) -> Vec<OfferedMode> {
if mode.0 == 0 || mode.1 == 0 {
return Vec::new();
}
let refresh_hz = refresh(screen, refresh_hz);
let within = RATIOS
.iter()
.flat_map(|r| r.sizes.iter().copied())
.filter(|&(w, h)| w <= mode.0 && h <= mode.1);
let mut modes: Vec<OfferedMode> = Vec::new();
for (width, height) in std::iter::once(mode).chain(within) {
if modes.iter().any(|m| (m.width, m.height) == (width, height)) {
continue;
}
modes.push(OfferedMode {
width,
height,
refresh_hz,
});
}
modes
}
/// The density of `screen` for a guest mode `mode` (width, height) in pixels: ppi is 110 times
/// the screen's backing scale; the size is the mode's pixels at that density (divided by
/// `ppi / 25.46`); the scale factor is 2 above 143 ppi, else 1.
pub fn density(screen: &HostScreen, mode: (u16, u16)) -> Density {
let scale = if screen.scale.is_finite() && screen.scale > 0.0 {
screen.scale
} else {
1.0
};
density_at(PPI_PER_SCALE * scale, mode)
}
/// The density of a chosen mode `mode`: 110 ppi, whatever the screen, so the guest runs a 1×
/// desktop, which the window scales on the GPU.
pub fn density_1x(mode: (u16, u16)) -> Density {
density_at(PPI_PER_SCALE, mode)
}
/// The density of a chosen mode `mode` told `ppi` pixels per inch: the size is the mode's
/// pixels at `ppi`, and the scale factor the scale the guest runs the mode at on that size
/// ([`guest_scale`]), which the guest does not follow but the window does. `None`, or a `ppi`
/// that is not a positive finite number, is 110 ppi ([`density_1x`]).
pub fn density_chosen(mode: (u16, u16), ppi: Option<f64>) -> Density {
match ppi {
Some(ppi) if ppi.is_finite() && ppi > 0.0 => {
let at = density_at(ppi, mode);
Density {
scale_factor: guest_scale(mode, at.size_in_millimeters),
..at
}
}
_ => density_1x(mode),
}
}
/// A mode `mode` at `ppi` pixels per inch.
fn density_at(ppi: f64, mode: (u16, u16)) -> Density {
let per_millimeter = ppi / MILLIMETERS_DIVISOR;
Density {
size_in_millimeters: (
f64::from(mode.0) / per_millimeter,
f64::from(mode.1) / per_millimeter,
),
scale_factor: if ppi > HIDPI_ABOVE_PPI { 2 } else { 1 },
}
}
/// The whole centimetres a guest reads a told width of `millimeters` as: rounded to whole
/// millimetres as the display's settings page holds it (its `float`, plus 0.5, truncated), then
/// up to whole centimetres. `None` for a width that is not a positive finite number, or that
/// comes to no centimetre.
fn guest_centimeters(millimeters: f64) -> Option<f64> {
if !(millimeters.is_finite() && millimeters > 0.0) {
return None;
}
let whole = (f64::from(millimeters as f32) + 0.5).floor();
let centimeters = (whole / 10.0).ceil();
(centimeters.is_finite() && centimeters > 0.0).then_some(centimeters)
}
/// The scale a guest runs a mode `mode` at on a display told `size_in_millimeters`, as a macOS
/// 13.6 guest picks it (module doc): it reads the width in whole centimetres, rounded to whole
/// millimetres and then up, and runs HiDPI where the mode's width comes to 2021 pixels per 35
/// cm (146.667 ppi) or more across it, for a mode at least 1920 pixels wide. 2 there, else 1,
/// and 1 for an empty or unknown size. The unmeasured densities just below, modes wider than
/// 3811 pixels below it, where the guest may run HiDPI anyway, and modes narrower than 1920
/// pixels, which 1280 was not, are 1. The window shows a guest point per host point by it.
pub fn guest_scale(mode: (u16, u16), size_in_millimeters: (f64, f64)) -> u8 {
if mode.0 < HIDPI_NARROWEST {
return 1;
}
let Some(centimeters) = guest_centimeters(size_in_millimeters.0) else {
return 1;
};
// Pixels per centimetre at least 2021 / 35, cross-multiplied: whole numbers, exact in f64
// wherever the two sides are close.
let (pixels, across) = HIDPI_FROM;
if f64::from(mode.0) * across >= pixels * centimeters {
2
} else {
1
}
}
#[cfg(test)]
mod tests {
use super::*;
fn screen(pixels: (u32, u32), scale: f64, refresh_hz: f64) -> HostScreen {
HostScreen {
id: 1,
pixels,
scale,
refresh_hz,
}
}
fn sizes(modes: &[OfferedMode]) -> Vec<(u16, u16)> {
modes.iter().map(|m| (m.width, m.height)).collect()
}
/// A 3456×2234 built-in Retina screen at 120 Hz
#[test]
fn offered_modes_for_a_built_in_retina_screen() {
let modes = offered_modes(&screen((3456, 2234), 2.0, 120.0), None);
assert_eq!(
sizes(&modes),
vec![
(3456, 2160),
(3456, 1944),
(2976, 2232),
(2560, 1600),
(1920, 1200),
(1680, 1050),
(1440, 900),
(1280, 800),
(2560, 1440),
(1920, 1080),
(1600, 900),
(1280, 720),
(2048, 1536),
(1600, 1200),
(1400, 1050),
(1024, 768),
]
);
assert!(modes.iter().all(|m| m.refresh_hz == 120.0));
}
/// A 5120×2880 screen: its largest 16:9 is the whole screen
#[test]
fn offered_modes_for_a_5k_screen() {
let modes = offered_modes(&screen((5120, 2880), 2.0, 60.0), None);
assert_eq!(
sizes(&modes),
vec![
(4608, 2880),
(5120, 2880),
(3840, 2880),
(2560, 1600),
(1920, 1200),
(1680, 1050),
(1440, 900),
(1280, 800),
(3840, 2160),
(2560, 1440),
(1920, 1080),
(1600, 900),
(1280, 720),
(2048, 1536),
(1600, 1200),
(1400, 1050),
(1024, 768),
]
);
}
/// A 1920×1080 1× screen: no standard size of its full 16:9 is listed twice
#[test]
fn offered_modes_for_a_1080p_screen() {
let modes = offered_modes(&screen((1920, 1080), 1.0, 60.0), None);
assert_eq!(
sizes(&modes),
vec![
(1728, 1080),
(1920, 1080),
(1440, 1080),
(1680, 1050),
(1440, 900),
(1280, 800),
(1600, 900),
(1280, 720),
(1400, 1050),
(1024, 768),
]
);
}
/// Every mode is a multiple of 8 each way, below 65536, listed once, and there are at most
/// 128
#[test]
fn offered_modes_are_whole_and_distinct() {
for pixels in [
(3456, 2234),
(5120, 2880),
(1920, 1080),
(2560, 1664),
(1366, 768),
(800, 600),
(100_000, 100_000),
(7, 7),
(0, 0),
] {
let modes = offered_modes(&screen(pixels, 1.0, 60.0), None);
assert!(modes.len() <= MAX_MODES);
for (i, m) in modes.iter().enumerate() {
assert!(m.width > 0 && m.height > 0, "{pixels:?}: {m:?}");
let listed = modes[..i]
.iter()
.any(|n| (n.width, n.height) == (m.width, m.height));
assert!(!listed, "{pixels:?}: {m:?} twice");
}
for m in modes.iter().take(3) {
assert_eq!((m.width % 8, m.height % 8), (0, 0), "{pixels:?}: {m:?}");
assert!(u32::from(m.width) <= pixels.0 && u32::from(m.height) <= pixels.1);
}
}
assert!(offered_modes(&screen((0, 0), 1.0, 60.0), None).is_empty());
let huge = offered_modes(&screen((100_000, 100_000), 1.0, 60.0), None);
assert_eq!((huge[0].width, huge[0].height), (65528, 40952));
}
/// The refresh rate: the override, else the screen's, else 60 Hz
#[test]
fn the_refresh_rate_can_be_overridden() {
let s = screen((3456, 2234), 2.0, 120.0);
assert!(
offered_modes(&s, Some(60.0))
.iter()
.all(|m| m.refresh_hz == 60.0)
);
assert!(
offered_modes(&s, None)
.iter()
.all(|m| m.refresh_hz == 120.0)
);
let unknown = screen((1920, 1080), 1.0, 0.0);
assert!(
offered_modes(&unknown, None)
.iter()
.all(|m| m.refresh_hz == 60.0)
);
assert!(
offered_modes(&unknown, Some(144.0))
.iter()
.all(|m| m.refresh_hz == 144.0)
);
assert!(
offered_modes(&s, Some(f64::NAN))
.iter()
.all(|m| m.refresh_hz == 120.0)
);
}
/// A Retina screen gives a HiDPI guest, a 1× screen a 1× one, sized at the screen's density
#[test]
fn the_density_is_the_screens() {
let retina = density(&screen((3456, 2234), 2.0, 120.0), (3456, 2160));
assert_eq!(retina.scale_factor, 2);
// 220 ppi: 3456 × 25.46 / 220 and 2160 × 25.46 / 220.
assert!((retina.size_in_millimeters.0 - 399.953_454_545_454_6).abs() < 1e-9);
assert!((retina.size_in_millimeters.1 - 249.970_909_090_909_1).abs() < 1e-9);
let one = density(&screen((1920, 1080), 1.0, 60.0), (1920, 1080));
assert_eq!(one.scale_factor, 1);
// 110 ppi: 1920 × 25.46 / 110 and 1080 × 25.46 / 110.
assert!((one.size_in_millimeters.0 - 444.392_727_272_727_3).abs() < 1e-9);
assert!((one.size_in_millimeters.1 - 249.970_909_090_909_1).abs() < 1e-9);
// About the boundary: 141.9 ppi is 1×, 144.1 ppi 2×.
assert_eq!(density(&screen((1, 1), 1.29, 60.0), (8, 8)).scale_factor, 1);
assert_eq!(density(&screen((1, 1), 1.31, 60.0), (8, 8)).scale_factor, 2);
// A scale that is not one is taken as 1×.
assert_eq!(
density(&screen((1, 1), f64::NAN, 60.0), (8, 8)).scale_factor,
1
);
}
/// A chosen 1920×1080 on a 120 Hz Retina screen: it first, then the standard sizes within
/// it, at the screen's rate
#[test]
fn a_chosen_mode_comes_first_with_the_sizes_within_it() {
let s = screen((3456, 2234), 2.0, 120.0);
let modes = modes_up_to((1920, 1080), Some(&s), None);
assert_eq!(
sizes(&modes),
vec![
(1920, 1080),
(1680, 1050),
(1440, 900),
(1280, 800),
(1600, 900),
(1280, 720),
(1400, 1050),
(1024, 768),
]
);
assert!(modes.iter().all(|m| m.refresh_hz == 120.0));
assert!(
modes_up_to((1920, 1080), Some(&s), Some(60.0))
.iter()
.all(|m| m.refresh_hz == 60.0)
);
assert_eq!(
sizes(&modes_up_to((800, 600), Some(&s), None)),
vec![(800, 600)]
);
assert!(modes_up_to((0, 1080), Some(&s), None).is_empty());
}
/// With no screen to match, a chosen mode is offered as on a screen, at 60 Hz unless the
/// rate is overridden
#[test]
fn a_chosen_mode_without_a_screen_runs_at_60_hz() {
let s = screen((3456, 2234), 2.0, 120.0);
let on_screen = modes_up_to((3840, 2400), Some(&s), None);
let modes = modes_up_to((3840, 2400), None, None);
assert_eq!(sizes(&modes), sizes(&on_screen));
assert!(modes.iter().all(|m| m.refresh_hz == DEFAULT_REFRESH_HZ));
assert!(
modes_up_to((3840, 2400), None, Some(144.0))
.iter()
.all(|m| m.refresh_hz == 144.0)
);
assert!(
modes_up_to((3840, 2400), None, Some(f64::NAN))
.iter()
.all(|m| m.refresh_hz == DEFAULT_REFRESH_HZ)
);
}
/// A chosen mode is told 110 ppi on any screen: a 1× guest desktop
#[test]
fn a_chosen_mode_is_1x() {
let d = density_1x((1920, 1080));
assert_eq!(d.scale_factor, 1);
assert!((d.size_in_millimeters.0 - 444.392_727_272_727_3).abs() < 1e-9);
assert!((d.size_in_millimeters.1 - 249.970_909_090_909_1).abs() < 1e-9);
assert_eq!(density_1x((3456, 2160)).scale_factor, 1);
}
/// A chosen mode told a chosen density: 2560×1600 at 200 ppi is sized at 200 ppi with a
/// scale factor of 2, and the guest runs it at 2×; no density, or one that is not a positive
/// finite number, is 110 ppi
#[test]
fn a_chosen_mode_at_a_chosen_ppi() {
let d = density_chosen((2560, 1600), Some(200.0));
assert_eq!(d.scale_factor, 2);
// 2560 × 25.46 / 200 and 1600 × 25.46 / 200.
assert!((d.size_in_millimeters.0 - 325.888).abs() < 1e-9);
assert!((d.size_in_millimeters.1 - 203.68).abs() < 1e-9);
assert_eq!(guest_scale((2560, 1600), d.size_in_millimeters), 2);
// 130 ppi is below the HiDPI boundary.
let low = density_chosen((1920, 1080), Some(130.0));
assert_eq!(low.scale_factor, 1);
assert_eq!(guest_scale((1920, 1080), low.size_in_millimeters), 1);
for ppi in [
None,
Some(0.0),
Some(-200.0),
Some(f64::NAN),
Some(f64::INFINITY),
] {
assert_eq!(
density_chosen((1920, 1080), ppi),
density_1x((1920, 1080)),
"{ppi:?}"
);
}
}
/// A chosen density tells the scale the guest runs the mode at, not 2 above 143 ppi:
/// 2560×1600 told 146 ppi reads as 45 cm, 144.5 ppi, and is 1×; told 148, 44 cm and 2×
#[test]
fn a_chosen_density_tells_the_scale_the_guest_runs() {
let at_146 = density_chosen((2560, 1600), Some(146.0));
assert_eq!(at_146.scale_factor, 1);
assert_eq!(
at_146.size_in_millimeters,
density_at(146.0, (2560, 1600)).size_in_millimeters
);
assert_eq!(density_chosen((2560, 1600), Some(148.0)).scale_factor, 2);
for mode in [
(2560, 1600),
(1920, 1080),
(3456, 2160),
(2021, 1263),
(800, 600),
] {
for ppi in 1..=400 {
let d = density_chosen(mode, Some(f64::from(ppi)));
assert_eq!(
d.scale_factor,
guest_scale(mode, d.size_in_millimeters),
"{mode:?} at {ppi}"
);
}
}
}
/// The densities a macOS 13.6 guest was booted at, and the scale it ran: it reads the width
/// in whole centimetres, rounded to whole millimetres and then up, and runs HiDPI from 2021
/// pixels across 35 cm on, but not 1280 pixels wide
#[test]
fn the_guest_scale_follows_its_reading_in_whole_centimetres() {
// (mode, told ppi, whole centimetres read, scale run)
let measured = [
((3456, 2160), 144.0, 62.0, 1),
((2560, 1600), 146.0, 45.0, 1),
((3456, 2160), 147.0, 60.0, 1),
// 590.54 mm: 591, then 60 cm (146.30 ppi), where 590 would be 59 (148.8). Its
// 2160 pixels across 37 cm come to 148.3 ppi: the height does not count.
((3456, 2160), 149.0, 60.0, 1),
((2944, 1840), 148.0, 51.0, 1),
((2656, 1660), 149.0, 46.0, 1),
((1790, 1119), 148.0, 31.0, 1),
((3811, 2382), 148.0, 66.0, 1),
((2021, 1263), 149.0, 35.0, 2),
((3176, 1984), 148.0, 55.0, 2),
((2080, 1300), 149.0, 36.0, 2),
((3008, 1880), 148.0, 52.0, 2),
// 440.39 mm: 440, then 44 cm (147.8 ppi), where 45 would be 144.5.
((2560, 1600), 148.0, 44.0, 2),
((2560, 1600), 149.0, 44.0, 2),
((1920, 1200), 149.0, 33.0, 2),
((2624, 1640), 149.0, 45.0, 2),
// 1536 pixels across 27 cm come to 144.5 ppi.
((2048, 1536), 149.0, 35.0, 2),
((3456, 2160), 220.0, 40.0, 2),
((3456, 2160), 254.0, 35.0, 2),
((5120, 2880), 218.0, 60.0, 2),
((2560, 1600), 227.0, 29.0, 2),
// 216.7 ppi, but 1280 pixels wide: HiDPI would look like 640×400.
((1280, 800), 220.0, 15.0, 1),
];
for (mode, ppi, centimeters, scale) in measured {
let size = density_at(ppi, mode).size_in_millimeters;
assert_eq!(
guest_centimeters(size.0),
Some(centimeters),
"{mode:?} at {ppi}"
);
assert_eq!(guest_scale(mode, size), scale, "{mode:?} at {ppi}");
}
// Whole millimetres to nearest, then whole centimetres up.
assert_eq!(guest_centimeters(440.49), Some(44.0));
assert_eq!(guest_centimeters(440.5), Some(45.0));
assert_eq!(guest_centimeters(430.5), Some(44.0));
assert_eq!(guest_centimeters(0.6), Some(1.0));
for none in [0.4, 0.0, -1.0, f64::NAN, f64::INFINITY, 1e300] {
assert_eq!(guest_centimeters(none), None, "{none}");
}
}
/// The guest's scale follows the density its mode has on the size the display was told
#[test]
fn the_guest_scale_follows_the_told_density() {
let retina = density(&screen((3456, 2234), 2.0, 120.0), (3456, 2160));
assert_eq!(guest_scale((3456, 2160), retina.size_in_millimeters), 2);
// A smaller mode on the same size is below 143 ppi.
assert_eq!(guest_scale((1920, 1200), retina.size_in_millimeters), 1);
let chosen = density_1x((1920, 1080));
assert_eq!(guest_scale((1920, 1080), chosen.size_in_millimeters), 1);
// QEMU's 400 × 300 mm without a window's policy.
assert_eq!(guest_scale((1920, 1080), (400.0, 300.0)), 1);
assert_eq!(guest_scale((3456, 2160), (400.0, 300.0)), 2);
assert_eq!(guest_scale((1920, 1080), (0.0, 0.0)), 1);
assert_eq!(guest_scale((1920, 1080), (f64::NAN, 1.0)), 1);
}
}
+7 -5
View File
@@ -2,8 +2,8 @@
//! main one first, and the window of the display on port i opens on screen i
//! ([`screen_for_port`]). On macOS they come from CoreGraphics, which answers on any thread; on
//! Linux from SDL, on the library's UI thread, which takes a snapshot of them
//! (`native/linux/ui.rs`). Where there are none (no window system to reach), a display matching
//! its host screen offers its chosen mode, or `policy::UNMATCHED_MODE`, at 60 Hz (`policy`).
//! (`native/linux/ui.rs`). Where there are none (no window system to reach), there is no screen
//! to open on ([`screen_for_port`]).
//!
//! A screen's refresh rate is the one it runs at ([`screen_refresh`]): its current mode's, so a
//! screen the person set below its highest rate gives the guest the rate it was set to, as the
@@ -12,6 +12,9 @@
use crate::env;
use crate::native;
/// The rate a screen runs at where the OS gives none, in Hz ([`screen_refresh`]).
const DEFAULT_REFRESH_HZ: f64 = 60.0;
/// A host screen.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct HostScreen {
@@ -49,8 +52,7 @@ pub fn pick_screen(port: u64, list: &[usize], count: usize) -> usize {
/// the same pixels stands in, as the most a variable-rate screen runs at, the way ProMotion's
/// current mode reports the top of its range. A mode of other pixels does not count, as the
/// screen does not run its rate at its current size (a 4K screen listing 1920×1080 at 120 Hz runs
/// 4K at 60). [`policy::DEFAULT_REFRESH_HZ`](crate::policy::DEFAULT_REFRESH_HZ) where every rate
/// is unknown.
/// 4K at 60). [`DEFAULT_REFRESH_HZ`] where every rate is unknown.
pub(crate) fn screen_refresh(
pixels: (u32, u32),
current_hz: f64,
@@ -68,7 +70,7 @@ pub(crate) fn screen_refresh(
if highest > 0.0 {
highest
} else {
crate::policy::DEFAULT_REFRESH_HZ
DEFAULT_REFRESH_HZ
}
}
+5 -6
View File
@@ -4,12 +4,11 @@
//! surface, its input, its end) is its [`os`]'s.
//!
//! **Opening.** A window opens on the screen [`crate::screens::screen_for_port`] picks for the
//! display's port, else on the main screen, so the screen whose density the guest was told of is
//! the one it opens on. Windowed (the default), its content is the guest's mode, else the first
//! mode the display offers, else [`DEFAULT_MODE`], at one guest point per host point, shrunk to fit
//! the screen ([`crate::geometry::initial_content_size`]), on whole pixels at the screen's scale,
//! and never below [`MIN_CONTENT`]. Borderless (`REIMS_VGPU_WINDOW_BORDERLESS=1`), it fills its
//! screen.
//! display's port, else on the main screen. Windowed (the default), its content is the guest's
//! mode, else the first mode the display offers, else [`DEFAULT_MODE`], at one guest pixel per
//! host point, shrunk to fit the screen ([`crate::geometry::initial_content_size`]), on whole
//! pixels at the screen's scale, and never below [`MIN_CONTENT`]. Borderless
//! (`REIMS_VGPU_WINDOW_BORDERLESS=1`), it fills its screen.
//!
//! **Following the guest's mode.** Until the person resizes it (an edge, tiling, maximizing or
//! zooming, full screen), a windowed window follows the guest's mode: each mode change resizes its
+24 -25
View File
@@ -96,9 +96,9 @@ impl Units {
}
}
/// The content size, in `units`, of a windowed window for a guest mode `mode` at `guest_scale`,
/// on a screen whose usable bounds are `usable` in those units, where known: a guest point per
/// host point ([`geometry::initial_content_size`]), shrunk to fit the usable bounds less
/// The content size, in `units`, of a windowed window for a guest mode `mode`, on a screen whose
/// usable bounds are `usable` in those units, where known: a guest pixel per host point
/// ([`geometry::initial_content_size`]), shrunk to fit the usable bounds less
/// `title_room` points, on whole pixels, made smaller where it takes that to come to a multiple
/// of [`geometry::MODE_WIDTH_STEP`] pixels wide and of [`geometry::MODE_HEIGHT_STEP`] high, and
/// at least [`MIN_CONTENT`] points. The guest is offered the window's pixels rounded down to
@@ -106,7 +106,6 @@ impl Units {
/// no black beside it.
pub(crate) fn windowed_size(
mode: (u16, u16),
guest_scale: u8,
usable: Option<(i32, i32)>,
title_room: f64,
units: Units,
@@ -118,7 +117,7 @@ pub(crate) fn windowed_size(
f64::from(h) / per_point - title_room,
)
});
let (width, height) = geometry::initial_content_size(mode, f64::from(guest_scale.max(1)), room);
let (width, height) = geometry::initial_content_size(mode, room);
let min = units.min_content();
(
units.aligned(
@@ -160,42 +159,42 @@ mod tests {
// Wayland at 1×, and at 2×: points, the usable bounds in points.
let wayland = Units::new(1.0, 1.0);
assert_eq!(
windowed_size(fhd, 1, Some((2560, 1400)), ROOM, wayland),
windowed_size(fhd, Some((2560, 1400)), ROOM, wayland),
(1920, 1080)
);
let wayland_2x = Units::new(2.0, 1.0);
assert_eq!(
windowed_size((3840, 2160), 2, Some((1920, 1080)), ROOM, wayland_2x),
windowed_size(fhd, Some((1920, 1080)), ROOM, wayland_2x),
(1832, 1032)
);
// Wayland at 150%: whole pixels, 1280 points of 1.5 pixels.
let wayland_150 = Units::new(1.5, 1.0);
assert_eq!(
windowed_size((1280, 800), 1, Some((1707, 960)), ROOM, wayland_150),
windowed_size((1280, 800), Some((1707, 960)), ROOM, wayland_150),
(1280, 800)
);
// X11 at a content scale of 2: pixels, two to the point; a 1× guest of 1920 × 1080
// shrinks to fit 1920 × 1008 points, 3584 × 2016 pixels.
// X11 at a content scale of 2: pixels, two to the point; 1920 × 1080 shrinks to fit
// 1920 × 1008 points, 3584 × 2016 pixels.
let x11_2x = Units::new(1.0, 2.0);
assert_eq!(
windowed_size(fhd, 1, Some((3840, 2112)), ROOM, x11_2x),
windowed_size(fhd, Some((3840, 2112)), ROOM, x11_2x),
(3584, 2016)
);
// A HiDPI guest there is a guest pixel per screen pixel.
// 1280 × 800 fits there whole, at 2560 × 1600 pixels.
assert_eq!(
windowed_size((2560, 1600), 2, Some((3840, 2112)), ROOM, x11_2x),
windowed_size((1280, 800), Some((3840, 2112)), ROOM, x11_2x),
(2560, 1600)
);
// X11 at 150%: 1280 × 800 points are 1920 × 1200 pixels.
let x11_150 = Units::new(1.0, 1.5);
assert_eq!(
windowed_size((1280, 800), 1, Some((2560, 1392)), ROOM, x11_150),
windowed_size((1280, 800), Some((2560, 1392)), ROOM, x11_150),
(1920, 1200)
);
// The smallest content, 320 × 200 points, in pixels at 2.
assert_eq!(x11_2x.min_content(), (640, 400));
assert_eq!(wayland_2x.min_content(), (320, 200));
assert_eq!(windowed_size((400, 300), 2, None, ROOM, x11_2x), (640, 400));
assert_eq!(windowed_size((200, 150), None, ROOM, x11_2x), (640, 400));
}
/// At the fractional scales desktops offer, a window opens a multiple of 16 pixels wide and an
@@ -205,11 +204,11 @@ mod tests {
fn a_window_opens_a_multiple_of_16_pixels_wide_at_fractional_scales() {
const ROOM: f64 = 48.0;
let modes = [
((1920, 1080), 1),
((2560, 1600), 1),
((3840, 2160), 2),
((1366, 768), 1),
((1280, 800), 1),
(1920, 1080),
(2560, 1600),
(3840, 2160),
(1366, 768),
(1280, 800),
];
for scale in [1.25_f32, 1.5, 1.75, 2.1] {
// A 3840 × 2160 screen: its points on Wayland, its pixels on X11.
@@ -219,9 +218,9 @@ mod tests {
);
let wayland = Units::new(scale, 1.0);
let x11 = Units::new(1.0, scale);
for (mode, guest_scale) in modes {
for mode in modes {
for (units, usable) in [(wayland, points), (x11, (3840, 2160))] {
let size = windowed_size(mode, guest_scale, Some(usable), ROOM, units);
let size = windowed_size(mode, Some(usable), ROOM, units);
let pixels = (units.pixels_of(size.0), units.pixels_of(size.1));
assert!(
pixels.0 % 16 == 0 && pixels.1 % 2 == 0,
@@ -233,7 +232,7 @@ mod tests {
// Wayland at 2.1: 1570 points are 3297 pixels, and 1562 the next size down that comes to
// a multiple of 16.
let wayland_21 = Units::new(2.1, 1.0);
let size = windowed_size((2560, 1600), 1, Some((1829, 1029)), ROOM, wayland_21);
let size = windowed_size((2560, 1600), Some((1829, 1029)), ROOM, wayland_21);
assert_eq!(size, (1562, 981));
assert_eq!(
(wayland_21.pixels_of(size.0), wayland_21.pixels_of(size.1)),
@@ -242,14 +241,14 @@ mod tests {
// At 1.5: 2227 points are 3341 pixels (3340.5 rounded away from zero), 2208 are 3312.
let wayland_15 = Units::new(1.5, 1.0);
assert_eq!(
windowed_size((2560, 1600), 1, Some((2560, 1440)), ROOM, wayland_15),
windowed_size((2560, 1600), Some((2560, 1440)), ROOM, wayland_15),
(2208, 1392)
);
assert_eq!(wayland_15.pixels_of(2208), 3312);
// X11 at 2.1: 3660 × 2059 pixels, 3648 wide and one fewer high.
let x11_21 = Units::new(1.0, 2.1);
assert_eq!(
windowed_size((1920, 1080), 1, Some((3840, 2160)), ROOM, x11_21),
windowed_size((1920, 1080), Some((3840, 2160)), ROOM, x11_21),
(3648, 2058)
);
// The ten sizes from 965 to 974 points are odd at 2.1 (2027 to 2045 pixels); 964 is even,