diff --git a/crates/reims-vgpu-c/include/reims_vgpu.h b/crates/reims-vgpu-c/include/reims_vgpu.h index a7042b80a..52dbb2e11 100644 --- a/crates/reims-vgpu-c/include/reims_vgpu.h +++ b/crates/reims-vgpu-c/include/reims_vgpu.h @@ -184,7 +184,8 @@ // host screen the window opens on, in place of the config's size; rvg_display_set_modes still // replaces the modes. With RvgWindowConfig's `mode_width` and `mode_height`, the modes are that // mode and the standard sizes within it, at a 1× density or `mode_pixels_per_inch`'s; without, -// the screen's own, at its density. +// the screen's own, at its density. With no screen to match (as with no window system to +// reach), they are those of the config's mode, or of 1920 × 1080 at 1× without one, at 60 Hz. #define RVG_WINDOW_MATCH_HOST_SCREEN 1 // The left button, in an RvgWindowPointerFn's `buttons`. @@ -640,7 +641,8 @@ typedef struct { // guest runs a 1× desktop at that mode (measured up to 3811 pixels wide; 5832 ran HiDPI) // and the window scales it to its size on the GPU; `mode_pixels_per_inch` tells another // density. 0 in either is none: the screen's own modes, at its density. Ignored without - // the flag. + // the flag. With no screen to match, the mode is offered at 60 Hz, and none is 1920 × 1080 + // at 1×. uint16_t mode_width; // As `mode_width`. uint16_t mode_height; @@ -895,7 +897,8 @@ void rvg_device_did_resume(RvgDevice *device); // its scale factor and its first modes are those of the window's host screen, where there is // one, or, with the window config's mode, that mode's at a 1× density or the config's // `mode_pixels_per_inch`, and the screen's refresh rate; a later rvg_display_set_modes -// replaces the modes. +// replaces the modes. With no screen, the size, scale factor and first modes are those of the +// config's mode, or of 1920 × 1080 at 1× without one, at 60 Hz. // // # Safety // `device` is NULL or a live device handle; `config` is NULL or a live config; `display` is diff --git a/crates/reims-vgpu-c/src/display.rs b/crates/reims-vgpu-c/src/display.rs index d9f8641dd..570da9e1f 100644 --- a/crates/reims-vgpu-c/src/display.rs +++ b/crates/reims-vgpu-c/src/display.rs @@ -286,7 +286,8 @@ unsafe fn live<'a>(display: *const RvgDisplay, call: &'static str) -> &'a RvgDis /// its scale factor and its first modes are those of the window's host screen, where there is /// one, or, with the window config's mode, that mode's at a 1× density or the config's /// `mode_pixels_per_inch`, and the screen's refresh rate; a later rvg_display_set_modes -/// replaces the modes. +/// replaces the modes. With no screen, the size, scale factor and first modes are those of the +/// config's mode, or of 1920 × 1080 at 1× without one, at 60 Hz. /// /// # Safety /// `device` is NULL or a live device handle; `config` is NULL or a live config; `display` is diff --git a/crates/reims-vgpu-c/src/window.rs b/crates/reims-vgpu-c/src/window.rs index 3a5d63846..67ae9b9dc 100644 --- a/crates/reims-vgpu-c/src/window.rs +++ b/crates/reims-vgpu-c/src/window.rs @@ -21,7 +21,8 @@ use crate::table::{RvgDestroyFn, Table}; /// host screen the window opens on, in place of the config's size; rvg_display_set_modes still /// replaces the modes. With RvgWindowConfig's `mode_width` and `mode_height`, the modes are that /// mode and the standard sizes within it, at a 1× density or `mode_pixels_per_inch`'s; without, -/// the screen's own, at its density. +/// the screen's own, at its density. With no screen to match (as with no window system to +/// reach), they are those of the config's mode, or of 1920 × 1080 at 1× without one, at 60 Hz. pub const RVG_WINDOW_MATCH_HOST_SCREEN: u32 = 1; /// The left button, in an RvgWindowPointerFn's `buttons`. @@ -232,7 +233,8 @@ pub struct RvgWindowConfig { /// guest runs a 1× desktop at that mode (measured up to 3811 pixels wide; 5832 ran HiDPI) /// and the window scales it to its size on the GPU; `mode_pixels_per_inch` tells another /// density. 0 in either is none: the screen's own modes, at its density. Ignored without - /// the flag. + /// the flag. With no screen to match, the mode is offered at 60 Hz, and none is 1920 × 1080 + /// at 1×. pub mode_width: u16, /// As `mode_width`. pub mode_height: u16, diff --git a/crates/reims-vgpu-window/features.md b/crates/reims-vgpu-window/features.md index 3e992f315..b8cb804b2 100644 --- a/crates/reims-vgpu-window/features.md +++ b/crates/reims-vgpu-window/features.md @@ -124,6 +124,12 @@ Unset or unparsable values give the defaults below. `test: policy::offered_modes_are_whole_and_distinct`, `test: policy::the_refresh_rate_can_be_overridden`, `test: policy::the_density_is_the_screens` +- With no host screen to match (as for a VM started from an ssh shell, with + no window system to reach), the guest is still offered the chosen mode and + the sizes within it, or 1920×1080 at 1× with `resolution=host`, at 60 Hz + or `REIMS_VGPU_WINDOW_REFRESH`'s rate, so it boots. + `test: policy::a_chosen_mode_without_a_screen_runs_at_60_hz`, + `manual` (a VM boot from an ssh shell) - Modes the host sets (QEMU's `display-modes`) replace the offered ones. `manual` diff --git a/crates/reims-vgpu-window/src/config.rs b/crates/reims-vgpu-window/src/config.rs index f509a4b47..eb60b3944 100644 --- a/crates/reims-vgpu-window/src/config.rs +++ b/crates/reims-vgpu-window/src/config.rs @@ -127,7 +127,8 @@ pub struct WindowConfig { /// 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. + /// modes at its density. With no screen to match, the mode is offered at 60 Hz, and `None` + /// is `policy::UNMATCHED_MODE` at 1×. 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 diff --git a/crates/reims-vgpu-window/src/native/linux/ui.rs b/crates/reims-vgpu-window/src/native/linux/ui.rs index 5db11c811..e31a0727a 100644 --- a/crates/reims-vgpu-window/src/native/linux/ui.rs +++ b/crates/reims-vgpu-window/src/native/linux/ui.rs @@ -16,7 +16,7 @@ //! //! 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 its config says. +//! a display matching its host screen then offers what `crate::policy` gives without a screen. //! //! **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 diff --git a/crates/reims-vgpu-window/src/policy.rs b/crates/reims-vgpu-window/src/policy.rs index 0acae12da..9c35bbf58 100644 --- a/crates/reims-vgpu-window/src/policy.rs +++ b/crates/reims-vgpu-window/src/policy.rs @@ -20,6 +20,11 @@ //! 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): @@ -119,6 +124,10 @@ 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; @@ -158,11 +167,11 @@ fn largest(pixels: (u64, u64), ratio: (u64, u64)) -> Option<(u16, u16)> { /// The rate the modes run at: `refresh_hz` where given, else the screen's highest, else /// [`DEFAULT_REFRESH_HZ`]. -fn refresh(screen: &HostScreen, refresh_hz: Option) -> f64 { +fn refresh(screen: Option<&HostScreen>, refresh_hz: Option) -> f64 { let valid = |hz: f64| hz.is_finite() && hz > 0.0; - match refresh_hz { - Some(hz) if valid(hz) => hz, - _ if valid(screen.max_refresh_hz) => screen.max_refresh_hz, + match (refresh_hz, screen) { + (Some(hz), _) if valid(hz) => hz, + (_, Some(screen)) if valid(screen.max_refresh_hz) => screen.max_refresh_hz, _ => DEFAULT_REFRESH_HZ, } } @@ -175,7 +184,7 @@ fn refresh(screen: &HostScreen, refresh_hz: Option) -> f64 { /// 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) -> Vec { - let refresh_hz = refresh(screen, refresh_hz); + let refresh_hz = refresh(Some(screen), refresh_hz); let limit = u64::from(u16::MAX); let pixels = ( u64::from(screen.pixels.0).min(limit), @@ -209,10 +218,11 @@ pub fn offered_modes(screen: &HostScreen, refresh_hz: Option) -> Vec, refresh_hz: Option, ) -> Vec { if mode.0 == 0 || mode.1 == 0 { @@ -509,7 +519,7 @@ mod tests { #[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), &s, None); + let modes = modes_up_to((1920, 1080), Some(&s), None); assert_eq!( sizes(&modes), vec![ @@ -525,12 +535,36 @@ mod tests { ); assert!(modes.iter().all(|m| m.refresh_hz == 120.0)); assert!( - modes_up_to((1920, 1080), &s, Some(60.0)) + 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), &s, None)), vec![(800, 600)]); - assert!(modes_up_to((0, 1080), &s, None).is_empty()); + 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 diff --git a/crates/reims-vgpu-window/src/screens.rs b/crates/reims-vgpu-window/src/screens.rs index 611f8ea4b..e10e13ea4 100644 --- a/crates/reims-vgpu-window/src/screens.rs +++ b/crates/reims-vgpu-window/src/screens.rs @@ -3,7 +3,7 @@ //! ([`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 what its config says. +//! its host screen offers its chosen mode, or `policy::UNMATCHED_MODE`, at 60 Hz (`policy`). use crate::env; use crate::native; diff --git a/crates/reims-vgpu/src/display.rs b/crates/reims-vgpu/src/display.rs index 8024d5885..0592bc5b3 100644 --- a/crates/reims-vgpu/src/display.rs +++ b/crates/reims-vgpu/src/display.rs @@ -305,7 +305,8 @@ impl Display

{ /// screen the platform names for the port, the scale factor and the size in millimetres are /// its density, and the display is made with its modes, as [`Display::set_modes`] sets them; /// the window opens sized for the first. The window is given the display's sink once the - /// display exists, and a refusal closes it before it returns. + /// display exists, and a refusal closes it before it returns. Where the platform names no + /// screen, the density and the modes are those [`window::host_matched`] gives without one. /// /// With the frame statistics on (`REIMS_VGPU_STATS`, [`stats`]), the new-frame callback, the /// tee's for a window display, counts each of the guest's presents before it runs, and the @@ -325,9 +326,8 @@ impl Display

{ let w = Window::new(wcfg, port, reims_vgpu_window::handle::title(port)); config.callbacks = window::tee(&w, std::mem::take(&mut config.callbacks)); if w.match_host_screen() - && let Some(screen) = window::host_screen::

(port) && let Some((modes, density)) = window::host_matched( - &screen, + window::host_screen::

(port).as_ref(), w.chosen_mode(), w.chosen_ppi(), reims_vgpu_window::env::settings().refresh_hz, diff --git a/crates/reims-vgpu/src/window.rs b/crates/reims-vgpu/src/window.rs index 30665c6fc..f0d62f5fa 100644 --- a/crates/reims-vgpu/src/window.rs +++ b/crates/reims-vgpu/src/window.rs @@ -40,7 +40,7 @@ use crate::stats::{self, DisplayStats}; /// The host screen the window of the display on `port` opens on: on the product's platform and /// on the Vulkan platform (feature `vulkan`), the one `reims_vgpu_window::screens` picks from /// the host's screens; on the testkit's, `crate::platform::FAKE_HOST_SCREEN`; on any other, -/// none, and a display matching its host screen offers what its config says. +/// none. A display matching its host screen is offered modes without one too ([`host_matched`]). pub(crate) fn host_screen(port: u64) -> Option { if on_host_screens::

() { return reims_vgpu_window::screens::screen_for_port(port); @@ -104,21 +104,26 @@ pub(crate) fn window_sink( /// screen's density. The density is that of the first mode. `None` when the policy offers no /// mode: the display then offers what its config says. The modes run at `refresh_hz` /// (`REIMS_VGPU_WINDOW_REFRESH`) where given, else at the screen's highest rate. +/// +/// With no `screen`, the chosen mode as with one, or else `policy::UNMATCHED_MODE` at 1×, at +/// `refresh_hz` or else 60 Hz: offering none would leave the guest no mode to set (`policy`). pub(crate) fn host_matched( - screen: &HostScreen, + screen: Option<&HostScreen>, mode: Option<(u16, u16)>, ppi: Option, refresh_hz: Option, ) -> Option<(Vec, Density)> { - let modes = match mode { - Some(mode) => policy::modes_up_to(mode, screen, refresh_hz), - None => policy::offered_modes(screen, refresh_hz), + let modes = match (mode, screen) { + (Some(mode), _) => policy::modes_up_to(mode, screen, refresh_hz), + (None, Some(screen)) => policy::offered_modes(screen, refresh_hz), + (None, None) => policy::modes_up_to(policy::UNMATCHED_MODE, None, refresh_hz), }; let first = modes.first()?; let first = (first.width, first.height); - let density = match mode { - Some(_) => policy::density_chosen(first, ppi), - None => policy::density(screen, first), + let density = match (mode, screen) { + (Some(_), _) => policy::density_chosen(first, ppi), + (None, Some(screen)) => policy::density(screen, first), + (None, None) => policy::density_1x(first), }; Some((modes, density)) } diff --git a/crates/reims-vgpu/src/window/tests.rs b/crates/reims-vgpu/src/window/tests.rs index 721ec1f50..188503ba5 100644 --- a/crates/reims-vgpu/src/window/tests.rs +++ b/crates/reims-vgpu/src/window/tests.rs @@ -240,7 +240,7 @@ fn matching_the_host_screen_offers_its_modes_and_density() { let d = device.new_display(c).unwrap(); let core = d.core(); assert!(d.window().unwrap().match_host_screen()); - let (modes, density) = host_matched(&FAKE_HOST_SCREEN, None, None, None).unwrap(); + let (modes, density) = host_matched(Some(&FAKE_HOST_SCREEN), None, None, None).unwrap(); assert_eq!(density.scale_factor, 2); assert_eq!(core.scale_factor(), 2); assert_eq!(core.size_in_millimeters(), density.size_in_millimeters); @@ -275,7 +275,8 @@ fn a_chosen_mode_is_offered_first_at_1x() { c.window = Some(w); let d = device.new_display(c).unwrap(); let core = d.core(); - let (modes, density) = host_matched(&FAKE_HOST_SCREEN, Some((1920, 1080)), None, None).unwrap(); + let (modes, density) = + host_matched(Some(&FAKE_HOST_SCREEN), Some((1920, 1080)), None, None).unwrap(); assert_eq!((modes[0].width, modes[0].height), (1920, 1080)); assert_eq!(density.scale_factor, 1); assert_eq!(core.scale_factor(), 1); @@ -307,17 +308,46 @@ fn a_chosen_mode_at_a_chosen_ppi_is_told_that_density() { c.window = Some(w); let d = device.new_display(c).unwrap(); let core = d.core(); - let (modes, density) = - host_matched(&FAKE_HOST_SCREEN, Some((2560, 1600)), Some(200.0), None).unwrap(); + let (modes, density) = host_matched( + Some(&FAKE_HOST_SCREEN), + Some((2560, 1600)), + Some(200.0), + None, + ) + .unwrap(); assert_eq!((modes[0].width, modes[0].height), (2560, 1600)); assert_eq!(density.scale_factor, 2); assert_eq!(core.scale_factor(), 2); assert_eq!(core.size_in_millimeters(), density.size_in_millimeters); assert_eq!(d.window().unwrap().offered(), Some((2560, 1600))); - let (_, at_1x) = host_matched(&FAKE_HOST_SCREEN, Some((2560, 1600)), None, None).unwrap(); + let (_, at_1x) = host_matched(Some(&FAKE_HOST_SCREEN), Some((2560, 1600)), None, None).unwrap(); assert_eq!(at_1x.scale_factor, 1); } +/// With no host screen (as with no window system to reach), a display matching it still offers +/// modes: the chosen mode and the sizes within it at its density, as on a screen, at 60 Hz +/// unless the rate is overridden; with no mode chosen, 1920×1080 at 1×. +/// Never none, which left a macOS guest no mode to set and stopped its boot at the Apple logo +#[test] +fn without_a_host_screen_the_chosen_mode_is_offered_at_60_hz() { + let sizes = |m: &[OfferedMode]| m.iter().map(|m| (m.width, m.height)).collect::>(); + let matched = |screen| host_matched(screen, Some((3840, 2400)), Some(331.0), None).unwrap(); + let (modes, density) = matched(None); + let (on_screen, screen_density) = matched(Some(&FAKE_HOST_SCREEN)); + assert_eq!(sizes(&modes), sizes(&on_screen)); + assert!(modes.iter().all(|m| m.refresh_hz == 60.0)); + assert_eq!(density, screen_density); + assert_eq!(density.scale_factor, 2); + let (modes, _) = host_matched(None, None, None, Some(120.0)).unwrap(); + assert!(modes.iter().all(|m| m.refresh_hz == 120.0)); + let (modes, density) = host_matched(None, None, None, None).unwrap(); + assert_eq!( + (modes[0].width, modes[0].height, modes[0].refresh_hz), + (1920, 1080, 60.0) + ); + assert_eq!(density, policy::density_1x((1920, 1080))); +} + /// A window display's window is told the first mode the display offers, which it opens sized /// for: matching the host screen, the policy's first; otherwise the first the host sets, each /// time it sets a list @@ -327,7 +357,7 @@ fn the_window_is_told_the_first_mode_offered() { let mut c = DisplayConfig::new(0, 0x5eed_a031); c.window = Some(window_config((), true)); let matched = device.new_display(c).unwrap(); - let (modes, _) = host_matched(&FAKE_HOST_SCREEN, None, None, None).unwrap(); + let (modes, _) = host_matched(Some(&FAKE_HOST_SCREEN), None, None, None).unwrap(); let first = (modes[0].width, modes[0].height); assert_eq!(matched.window().unwrap().offered(), Some(first)); let mut c = DisplayConfig::new(1, 0x5eed_a032); diff --git a/docs/api.md b/docs/api.md index 68a1854c4..780ae4d3a 100644 --- a/docs/api.md +++ b/docs/api.md @@ -195,7 +195,8 @@ The header has 35 functions and every type, callback typedef and constant, with - **`RVG_WINDOW_MATCH_HOST_SCREEN`** (flag 1; the other bits are ignored). The display offers the guest modes, a size in millimetres and a scale factor for the host screen its window opens on, in place of the config's size. - *With a mode* (`mode_width` and `mode_height` both above 0): that mode first, then the standard sizes of 16:10, 16:9 and 4:3 within it (neither side larger), at the screen's highest refresh rate or `REIMS_VGPU_WINDOW_REFRESH`'s, and the mode's size at 110 pixels per inch, scale factor 1: the guest runs a 1× desktop at that mode, which the window scales to its size on the GPU. That was measured for modes up to 3811 pixels wide; a mode 5832 pixels wide ran HiDPI at 128.8 ppi, and where between the two that starts was not measured. QEMU passes 1920 × 1080 unless told otherwise, since a guest at the screen's own 4K HiDPI mode runs much slower. `mode_pixels_per_inch` tells the mode's size at that density instead (QEMU's `resolution=2560x1600@200` is the display `macosvm`, over Virtualization.framework, gave the macOS 13.6 guest: its `vm.json`), and the scale factor the scale the window takes the guest to run. A macOS 13.6 guest reads the width in whole centimetres, rounded to whole millimetres and then up, and runs a HiDPI desktop at the mode's pixels where that comes to 2021 pixels per 35 cm (146.667 ppi) or more, for a mode 1920 to 3811 pixels wide: `2560x1600@148` reads as 44 cm, 147.8 ppi, and runs HiDPI, and `@146` as 45 cm, 144.5 ppi, and runs 1×. It ran 1× at up to 3811 pixels per 66 cm (146.666 ppi); a 1280 × 800 mode stayed 1× at 216.7 ppi, and HiDPI was measured from 1920 pixels wide and from 29 cm. The window takes a mode narrower than 1920 pixels, the densities between 146.666 and 146.667, and a mode wider than 3811 pixels below them as 1×; QEMU refuses a `resolution` density that does not tell the guest's scale for its mode (`reims-vgpu-window`'s `policy` lists the boots); it checks that mode alone, and the smaller modes offered with it are told the same size. 0, or a value that is not a positive finite number, is 110 ppi. - *Without one*, the host screen's own: the modes are the largest 16:10, 16:9 and 4:3 rectangles within the screen's pixels, each side rounded down to a multiple of 8, 16:10 first, then the standard smaller sizes of each ratio, at the screen's highest refresh rate or `REIMS_VGPU_WINDOW_REFRESH`'s. The density is that of the first mode: 110 pixels per inch per unit of the screen's backing scale, the size in millimetres the mode's pixels divided by `ppi / 25.46`, and the scale factor 2 above 143 ppi, else 1. A macOS 13.6 guest picks its HiDPI default from the size alone, so a Retina screen, told 220 ppi, gets a 2× desktop and a 1× screen a 1× one (`reims-vgpu-window`'s `policy` says what was measured). - - Either way, a later `rvg_display_set_modes` replaces the modes, and where the library finds no screen, the display offers what its config says. + - *Without a screen* (as from an ssh shell with no Wayland compositor or X server named, where the window does not open): the config's mode and the standard sizes within it at its density, as with a screen, or, without a mode, 1920 × 1080 and the sizes within it at 110 pixels per inch, at `REIMS_VGPU_WINDOW_REFRESH`'s rate or else 60 Hz. Offering none would leave the guest no mode to set, and a macOS guest stops its boot at the Apple logo. + - In each case, a later `rvg_display_set_modes` replaces the modes. - **The callbacks.** `pointer(ctx, x, y, width, height, buttons)`: the pointer at (`x`, `y`) in the guest's pixels, in a mode `width` by `height`, with `x` below `width` and `y` below `height` (off the image, and outside the window during a drag, it holds at the image's nearest edge), and `buttons` the `RVG_WINDOW_BUTTON_*` bits held: `LEFT` 1, `RIGHT` 2, `MIDDLE` 4 (the host's third button), `SIDE` 8 (its fourth, "back") and `EXTRA` 16 (its fifth, "forward"). `wheel(ctx, dy, dx)`: wheel notches, `dy` above 0 turned away from the person (up) and `dx` above 0 to the left, in the device's own direction whatever the host's scrolling setting; not called where the table has `scroll`. `key(ctx, usage, down)`: a USB HID keyboard usage (page 0x07) down or up; a held key is one down, which the guest repeats, and every key still down gets its up when the window loses focus, releases capture or closes. `close(ctx)`: the person closed the window or chose Quit; the window stays open, the host ends the VM, and its release of the display closes the window. `scroll(ctx, scroll)`: a scroll event, `scroll` an `RvgWindowScroll { struct_size, dy, dx, phase, momentum, notches_dy, notches_dx }` the library writes, which lives for the call. `dy` and `dx` are its distance in 1/256 of the host's point, in the same directions as `wheel`'s, a notched wheel's event being its lines at 10 points each; `phase` is where the event is in its gesture, an `RVG_WINDOW_SCROLL_PHASE_*`: `NONE` 0 (no gesture: a notched wheel, or momentum), `MAY_BEGIN` 1, `BEGAN` 2, `CHANGED` 3 (AppKit's Stationary too), `ENDED` 4, `CANCELLED` 5; `momentum` where it is in the momentum scrolling after the gesture, an `RVG_WINDOW_SCROLL_MOMENTUM_*`: `NONE` 0, `BEGAN` 1, `CHANGED` 2, `ENDED` 3 (AppKit's Cancelled too); `notches_dy` and `notches_dx` the notches `wheel` would have had, for a guest that takes no smooth scrolling. A gesture that begins over the image goes to `scroll` to its end, momentum included, wherever the pointer goes; one that begins elsewhere does not, and an event of no phase goes where the pointer is over the image. `scroll` came after the table's first version, which ends at `close`: 56 bytes. A host built against it passes 56, and its scrolling goes to `wheel` as notches (the unit test `window::tests::a_first_version_window_callbacks_is_56_bytes_and_has_no_scroll`). A callback the host leaves NULL sends that input nowhere, and without `close`, closing the window does nothing and Quit is ignored. - **The environment** picks the window's screen and style, and the offered modes' rate: `REIMS_VGPU_WINDOW_SCREENS` (a comma-separated list of host screen indices, the i-th for the display on port i; without one, or where it names no screen, display i opens on screen i, or on the main screen where there is none), `REIMS_VGPU_WINDOW_BORDERLESS` (`1`, `true`, `yes` or `on`: borderless windows that fill their screens) and `REIMS_VGPU_WINDOW_REFRESH` (the offered modes' refresh rate, above 0 Hz and up to 1000). The library reads them once per process; an unset or unparsable value is the default. Screen i is the i-th display CoreGraphics lists as active, the main one first, or, while every display sleeps, as online. What the window does for the person at the host is listed in `crates/reims-vgpu-window/features.md`. - **The window.** Once the display exists, its window opens on macOS on the main thread, and on Linux on the library's thread `reims-vgpu.ui` (section 5, "The main thread"). Its title is "Reims vGPU", followed by " (port N)" for a port N other than 0; the display's name is not in it. It opens on the screen the environment picks, found among AppKit's screens by its CoreGraphics display number, else on the main screen. @@ -575,7 +576,7 @@ With the `testkit` feature, `Device`, `Display` and `IoSurfaceDevice` also give - **The Rust API has no log hook.** It logs through the `log` crate, and a Rust host installs its own logger. The C layer's `rvg_log_set_handler` installs one that forwards to the host's function. - **Refusals leave the closures dropped.** A refused create drops the closures it was given before it returns, except a refused display's new-frame closure, which its source's cancel frees later on the display thread. The C layer's one `destroy` per table rides on that: every closure it builds holds one `Arc` of the table, whose last drop runs `destroy(ctx)` (section 5). A refused window display closes its window before it returns, which drops the window's closures even while that new-frame closure still holds the window (`window::tests::a_refused_window_display_closes_its_window`). -- **A display's window.** With `DisplayConfig::window`, `new_display` makes the window, gives the display the window's five callbacks in place of the config's (each tells the window, then calls the host's where it gave one), and, with `match_host_screen`, sets the display's scale factor and size in millimetres from the window's host screen and makes it with the offered modes, as `set_modes` sets them. Once the display exists, the window gets what draws its frames. Both are chosen by the platform's type (`window::host_screen`, `window::window_sink`): `MetalPlatform` answers from the host's screens (`reims_vgpu_window::screens`) and with `window::metal::MetalSink`, and the Vulkan platform (feature `vulkan`) from the same screens and with the sink of `window::vulkan`, `SwapchainSink`, which draws each frame into the window's swapchain on the runtime's device, on either OS (on macOS a swapchain of the window's `CAMetalLayer`). So `ApiPlatform` names no window type. Every `clone_ref` shares the window, and the last reference's drop closes it before that reference lets the display go (`window::tests::the_last_reference_closes_the_window_before_the_display_ends`). The testkit's platform answers `FAKE_HOST_SCREEN` and no sink, so its window displays never open a window. +- **A display's window.** With `DisplayConfig::window`, `new_display` makes the window, gives the display the window's five callbacks in place of the config's (each tells the window, then calls the host's where it gave one), and, with `match_host_screen`, sets the display's scale factor and size in millimetres from the window's host screen, or, without one, from the window's mode or 1920 × 1080, and makes it with the offered modes, as `set_modes` sets them. Once the display exists, the window gets what draws its frames. Both are chosen by the platform's type (`window::host_screen`, `window::window_sink`): `MetalPlatform` answers from the host's screens (`reims_vgpu_window::screens`) and with `window::metal::MetalSink`, and the Vulkan platform (feature `vulkan`) from the same screens and with the sink of `window::vulkan`, `SwapchainSink`, which draws each frame into the window's swapchain on the runtime's device, on either OS (on macOS a swapchain of the window's `CAMetalLayer`). So `ApiPlatform` names no window type. Every `clone_ref` shares the window, and the last reference's drop closes it before that reference lets the display go (`window::tests::the_last_reference_closes_the_window_before_the_display_ends`). The testkit's platform answers `FAKE_HOST_SCREEN` and no sink, so its window displays never open a window. ### 3.2 How it sits on core