🆕 Open the display's window on Windows through SDL3
On Windows the window is the SDL thread's, as on Linux: SDL3's Win32 window on the library's own reims-vgpu.ui thread, its Vulkan surface made by the render thread through SDL_Vulkan_CreateSurface (VK_KHR_win32_surface). SDL3 is built from its pinned source release and linked statically, as on Linux. A Win32 window's messages go to the thread that made it, and SDL makes and pumps it on the thread its video started on, the UI thread. native/windows.rs holds what Windows adds: it names no compositor GPU, so the window presents on the runtime's device. Its doc records what SDL does there (read from SDL 3.4.18's code): the process declared per-monitor DPI aware, sizes in pixels with the monitor's DPI as the content scale, and the keyboard grab as a low-level keyboard hook on the UI thread. Linux and macOS build what they built before.
This commit is contained in:
1 parent
17c164836e
commit
77e5df577b
15 files changed
+149
-87
No files matched your search
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "reims-vgpu-window"
|
||||
description = "A guest display's own window: on macOS AppKit (or SDL3) and a CAMetalLayer, on Linux SDL3 and Vulkan; input and the host's screens"
|
||||
description = "A guest display's own window: on macOS AppKit (or SDL3) and a CAMetalLayer, on Linux and Windows SDL3 and Vulkan; input and the host's screens"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
@@ -9,23 +9,26 @@ license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
log.workspace = true
|
||||
# ash's Vulkan types for a window's surface (`present`): SDL's on Linux, the layer's on macOS.
|
||||
# ash's Vulkan types for a window's surface (`present`): SDL's on Linux and Windows, the layer's
|
||||
# on macOS.
|
||||
ash.workspace = true
|
||||
# The Vulkan crate: core's threads and holds (`reims_vgpu_vulkan::core`), and its OS layer: its
|
||||
# threads, and on macOS its clock and the message layer the AppKit side sends through
|
||||
# (`reims_vgpu_vulkan::os`).
|
||||
reims-vgpu-vulkan.workspace = true
|
||||
|
||||
# The window on Linux (`sdl`): SDL3 for the window, its input and its Vulkan surface.
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
# The window on Linux and Windows (`sdl`): SDL3 for the window, its input and its Vulkan surface.
|
||||
[target.'cfg(any(target_os = "linux", target_os = "windows"))'.dependencies]
|
||||
sdl3-sys.workspace = true
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
# libwayland-client's calls, looked up in the library SDL opened (`native/linux/feedback.rs`).
|
||||
libc.workspace = true
|
||||
|
||||
[features]
|
||||
default = ["macos-sdl"]
|
||||
# SDL's library left unbuilt and unlinked: for a check of the Linux target on another OS, which
|
||||
# compiles but never links (`cargo xtask check`'s clippy of the Linux target on a Mac).
|
||||
# SDL's library left unbuilt and unlinked: for a check of the Linux or Windows target on another
|
||||
# OS, which compiles but never links (`cargo xtask check`'s clippy of the Linux target on a Mac).
|
||||
sdl-no-link = ["sdl3-sys?/no-link"]
|
||||
# SDL3's window on macOS (`sdl`, `native/macos/sdl.rs`), which `REIMS_VGPU_WINDOW_IMPL=sdl` opens
|
||||
# in place of AppKit's. `cargo xtask dist` keeps SDL's symbols out of the archive's globals and
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
//! scroll input goes to the host through [`WindowCallbacks`] (or, built with the `macos-sdl`
|
||||
//! feature and run with `REIMS_VGPU_WINDOW_IMPL=sdl`, SDL3's window over Cocoa, drawn and taking
|
||||
//! input the same way);
|
||||
//! on Linux an SDL3 window per display, on Wayland or X11, whose Vulkan swapchain the frame is
|
||||
//! drawn into the same way, on the runtime's own device. On macOS's Vulkan platform the frame goes
|
||||
//! on Linux and Windows an SDL3 window per display, on Wayland or X11, or Win32, whose Vulkan
|
||||
//! swapchain the frame is drawn into the same way, on the runtime's own device. On macOS's Vulkan platform the frame goes
|
||||
//! into a Vulkan swapchain over the window's `CAMetalLayer` likewise, through the same presenter
|
||||
//! (`present`).
|
||||
//!
|
||||
@@ -15,8 +15,8 @@
|
||||
//! created with a [`WindowConfig`], tells it what the guest does (a new frame, a mode, the cursor)
|
||||
//! and gives it a [`FrameSink`] that presents the display's current frame in it. On macOS
|
||||
//! the window opens once the process's main thread runs its run loop, as QEMU's does under
|
||||
//! `-display none`: nothing here waits for the main thread. On Linux it opens on the library's
|
||||
//! UI thread, and the process's main thread is never used.
|
||||
//! `-display none`: nothing here waits for the main thread. On Linux and Windows it opens on the
|
||||
//! library's UI thread, and the process's main thread is never used.
|
||||
//!
|
||||
//! Modules:
|
||||
//! - what a window decides, with no AppKit in it, each unit-tested: [`geometry`] (the image's
|
||||
@@ -32,13 +32,15 @@
|
||||
//! `shell` (a display's `NSWindow` and its delegate), `view` (its content view, layer and
|
||||
//! layout), `render` (the thread that draws each frame into the layer), `input` (the view's and
|
||||
//! the application's events to the host's callbacks), `cursor` (the guest's cursor as the
|
||||
//! host's) and `hotkeys` (the system's hot keys while captured). On Linux
|
||||
//! host's) and `hotkeys` (the system's hot keys while captured). On Linux and Windows
|
||||
//! (`native/sdl_thread/`) it is SDL's: a UI thread of the library's own that SDL runs on
|
||||
//! (`ui`), a window's input there (`input`, `keymap`), and its render thread (`render`), which
|
||||
//! draws through a presenter the display's sink makes over the window's swapchain (`present`,
|
||||
//! which macOS's render thread draws through too on the Vulkan platform), with the window's
|
||||
//! shell and cursor SDL's shared ones (`sdl`), and what only Linux has in `native/linux.rs`. SDL's window on macOS shares `sdl`'s shell and cursor, and AppKit's
|
||||
//! application, render thread, input and hot keys, with its own side in `native/macos/sdl.rs`.
|
||||
//! shell and cursor SDL's shared ones (`sdl`), and what each OS adds in its own file
|
||||
//! (`native/linux.rs`, `native/windows.rs`). SDL's window on macOS shares `sdl`'s shell and
|
||||
//! cursor, and AppKit's application, render thread, input and hot keys, with its own side in
|
||||
//! `native/macos/sdl.rs`.
|
||||
|
||||
pub mod capture;
|
||||
pub mod config;
|
||||
@@ -52,9 +54,9 @@ mod present;
|
||||
pub mod screens;
|
||||
pub mod scroll;
|
||||
|
||||
// The SDL3 window: Linux's (`native/sdl_thread.rs`), and macOS's with the `macos-sdl` feature, behind
|
||||
// `REIMS_VGPU_WINDOW_IMPL`.
|
||||
#[cfg(any(target_os = "linux", feature = "macos-sdl"))]
|
||||
// The SDL3 window: Linux's and Windows's (`native/sdl_thread.rs`), and macOS's with the
|
||||
// `macos-sdl` feature, behind `REIMS_VGPU_WINDOW_IMPL`.
|
||||
#[cfg(any(target_os = "linux", target_os = "windows", feature = "macos-sdl"))]
|
||||
mod sdl;
|
||||
|
||||
pub use config::{
|
||||
|
||||
@@ -6,22 +6,26 @@
|
||||
//! built with the `macos-sdl` feature and run with `REIMS_VGPU_WINDOW_IMPL=sdl`, SDL3 in
|
||||
//! AppKit's application there, with AppKit's window's extensions over SDL's `NSWindow`
|
||||
//! (`native/macos/sdl.rs`).
|
||||
//! - **Linux** (`native/sdl_thread.rs`): SDL3, on Wayland or X11, on the library's UI thread
|
||||
//! (`reims-vgpu.ui`) but for the render thread, which draws into the window's Vulkan swapchain;
|
||||
//! the window's shell and cursor are SDL's shared ones (`sdl`), with the SDL thread's side in
|
||||
//! `native/sdl_thread/sdl.rs`, and what only Linux has (the GPU a Wayland compositor composites
|
||||
//! on) in `native/linux.rs`.
|
||||
//! - **Linux and Windows** (`native/sdl_thread.rs`): SDL3, on Wayland or X11, or Win32, on the
|
||||
//! library's UI thread (`reims-vgpu.ui`) but for the render thread, which draws into the
|
||||
//! window's Vulkan swapchain; the window's shell and cursor are SDL's shared ones (`sdl`), with
|
||||
//! the SDL thread's side in `native/sdl_thread/sdl.rs`, and what each OS adds in its own file
|
||||
//! (`native/linux.rs`: the GPU a Wayland compositor composites on; `native/windows.rs`).
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
mod linux;
|
||||
#[cfg(target_os = "macos")]
|
||||
mod macos;
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
mod sdl_thread;
|
||||
#[cfg(target_os = "windows")]
|
||||
mod windows;
|
||||
|
||||
// What the OS adds under the SDL thread's windows: the GPU its compositor composites on.
|
||||
#[cfg(target_os = "linux")]
|
||||
use linux::compositor_device;
|
||||
#[cfg(target_os = "windows")]
|
||||
use windows::compositor_device;
|
||||
|
||||
#[cfg(all(target_os = "macos", feature = "macos-sdl"))]
|
||||
pub(crate) use macos::sdl as sdl_os;
|
||||
@@ -31,7 +35,7 @@ pub(crate) use macos::{
|
||||
key_input_captured, launched, monitored_events, now, open, quit_requested, release_key_input,
|
||||
screens_changed,
|
||||
};
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
pub(crate) use sdl_thread::{
|
||||
Surface, close, cursor_changed, guest_mode_changed, host_screens, now, open, sdl as sdl_os,
|
||||
};
|
||||
@@ -1,12 +1,13 @@
|
||||
//! The window through SDL3 on a thread of the library's own: Linux's, on Wayland or X11, drawn
|
||||
//! through Vulkan. The window's shell and cursor are SDL's shared ones (`crate::sdl`), and what
|
||||
//! the SDL thread does its own way is here: SDL runs on the library's UI thread (`ui`), where the
|
||||
//! window opens, changes and ends, as `sdl` places, sizes and ends it, and its events become the
|
||||
//! host's input (`input`, `keymap`); each window's render thread draws into its swapchain
|
||||
//! (`render`). What the OS under it adds is its own file (`super::linux`: the GPU a Wayland
|
||||
//! compositor composites on). This file is what the shared window code asks of it: the render
|
||||
//! thread (`render`, through the display's [`FrameSink`](crate::FrameSink)), the window's
|
||||
//! opening, changes and end, posted to the UI thread, and the host's screens as SDL lists them.
|
||||
//! The window through SDL3 on a thread of the library's own: Linux's, on Wayland or X11, and
|
||||
//! Windows's, drawn through Vulkan. The window's shell and cursor are SDL's shared ones
|
||||
//! (`crate::sdl`), and what the SDL thread does its own way is here: SDL runs on the library's UI
|
||||
//! thread (`ui`), where the window opens, changes and ends, as `sdl` places, sizes and ends it,
|
||||
//! and its events become the host's input (`input`, `keymap`); each window's render thread draws
|
||||
//! into its swapchain (`render`). What the OS under it adds is its own file (`super::linux`: the
|
||||
//! GPU a Wayland compositor composites on; `super::windows`). This file is what the shared window
|
||||
//! code asks of it: the render thread (`render`, through the display's
|
||||
//! [`FrameSink`](crate::FrameSink)), the window's opening, changes and end, posted to the UI
|
||||
//! thread, and the host's screens as SDL lists them.
|
||||
|
||||
mod input;
|
||||
mod keymap;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! SDL's scancodes to the USB HID keyboard usages (page 0x07) the guest's keyboard sends.
|
||||
//!
|
||||
//! SDL names a key by its position (its scancode, from the host's evdev code on Linux), and its
|
||||
//! scancodes up to 0xE7 are the USB usages themselves: a key reaches the guest by position, so
|
||||
//! the guest's own layout applies, and the ISO key left of 1 and the one right of left Shift are
|
||||
//! the guest's own. The scancodes past 0xE7 (media and application keys) are SDL's own, with no
|
||||
//! SDL names a key by its position (its scancode, from the host's evdev code on Linux and from the
|
||||
//! keyboard's scan code on Windows), and its scancodes up to 0xE7 are the USB usages themselves: a
|
||||
//! key reaches the guest by position, so the guest's own layout applies, and the ISO key left of 1
|
||||
//! and the one right of left Shift are the guest's own. The scancodes past 0xE7 (media and application keys) are SDL's own, with no
|
||||
//! usage on the keyboard page: they are dropped, as are 0 to 3, which name no key.
|
||||
|
||||
/// The first usage of a key (`a`).
|
||||
|
||||
@@ -80,7 +80,8 @@ impl VulkanTarget for Target {
|
||||
}
|
||||
|
||||
/// The GPU the OS's compositor composites the window on (`super::super::compositor_device`):
|
||||
/// on Linux the main device of the dma-buf feedback of SDL's window's Wayland surface.
|
||||
/// on Linux the main device of the dma-buf feedback of SDL's window's Wayland surface, none on
|
||||
/// Windows.
|
||||
fn compositor_device(&self) -> Option<(u32, u32)> {
|
||||
// SAFETY: the window lives while the render thread holds the target (above).
|
||||
unsafe { super::super::compositor_device(self.0) }
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
//! The SDL window's Linux side ([`crate::sdl::os`]): Wayland's or X11's window, drawn through
|
||||
//! Vulkan, on the library's UI thread.
|
||||
//! The SDL window's side on Linux and Windows ([`crate::sdl::os`]): Wayland's or X11's window, or
|
||||
//! Win32's, drawn through Vulkan, on the library's UI thread.
|
||||
//!
|
||||
//! **The screen.** The screen a window opens on is SDL's display of that ID (the host's screens
|
||||
//! are SDL's on Linux, `super::ui`), else SDL's primary display. Wayland lets no client place a
|
||||
//! windowed window: the compositor puts it where it likes, and only a borderless window is sure to
|
||||
//! be on its screen. SDL's answer to which screen a window is on is not used: on Wayland it names
|
||||
//! are SDL's on Linux and Windows, `super::ui`), else SDL's primary display. Wayland lets no
|
||||
//! client place a windowed window: the compositor puts it where it likes, and only a borderless
|
||||
//! window is sure to be on its screen. SDL's answer to which screen a window is on is not used: on Wayland it names
|
||||
//! the first screen for a window the compositor shows on another. A window resized for a guest's
|
||||
//! mode fits the screen it opened on.
|
||||
//!
|
||||
//! **Windowed**: decorated and resizable, centred on its screen where the window system lets it
|
||||
//! be placed, its content shrunk to fit the screen's usable area less [`TITLE_ROOM`] for the title
|
||||
//! bar and a panel, which Wayland does not tell a client. Its size and its smallest are asked for
|
||||
//! in SDL's sizes (`crate::sdl::units`): points on Wayland, and on X11 pixels, the desktop's
|
||||
//! content scale of them to the point.
|
||||
//! be placed (X11, Windows), its content shrunk to fit the screen's usable area less
|
||||
//! [`TITLE_ROOM`] for the title bar and a panel, which Wayland does not tell a client. Its size
|
||||
//! and its smallest are asked for in SDL's sizes (`crate::sdl::units`): points on Wayland, and on
|
||||
//! X11 and Windows pixels, the desktop's content scale of them to the point.
|
||||
//!
|
||||
//! **Borderless**: through the compositor's own full screen on its screen, over its panels.
|
||||
//!
|
||||
@@ -30,7 +30,9 @@
|
||||
//! cosmic-comp 1.9.0, nested: through either route, while captured, its shortcuts (Super alone,
|
||||
//! Super+Q, Super+A, Alt+Tab) stay unused and their keys reach the guest, a click that focuses the
|
||||
//! window included; not captured, Super+Q closes the window. Each capture and release is logged
|
||||
//! with whether SDL holds the grab ([`grab_keyboard`]).
|
||||
//! with whether SDL holds the grab ([`grab_keyboard`]). On Windows the grab is a low-level keyboard
|
||||
//! hook on this thread, which takes the system's shortcuts while the window has the keyboard
|
||||
//! (`super::super::windows`).
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -47,19 +49,20 @@ use crate::sdl::shell::{self, DEFAULT_MODE, Opened, Shell};
|
||||
use crate::sdl::units::{self, Units};
|
||||
|
||||
/// Points of a screen's height kept for a window's title bar and a panel: Wayland gives a client
|
||||
/// no work area, nor the size of the compositor's decorations.
|
||||
/// no work area, nor the size of the compositor's decorations, and Windows's work area leaves out
|
||||
/// the task bar but not a window's title bar.
|
||||
pub(crate) const TITLE_ROOM: f64 = 48.0;
|
||||
|
||||
/// Where an open window is, for placing others: nothing on Linux, where the window system places
|
||||
/// them.
|
||||
/// Where an open window is, for placing others: nothing here, where each window is centred on its
|
||||
/// screen or placed by the window system.
|
||||
pub(crate) type Frame = std::convert::Infallible;
|
||||
|
||||
/// Where `shell`'s window is: nothing on Linux.
|
||||
/// Where `shell`'s window is: nothing here.
|
||||
pub(crate) fn frame_of(_shell: &Shell) -> Option<Frame> {
|
||||
None
|
||||
}
|
||||
|
||||
/// What Linux keeps of a window.
|
||||
/// What this side keeps of a window.
|
||||
pub(crate) struct State {
|
||||
/// The screen it opened on: SDL's answer to which screen a window is on is not used (the
|
||||
/// module doc).
|
||||
@@ -314,8 +317,8 @@ pub(crate) fn grab_keyboard(shell: &Shell, captured: bool) {
|
||||
|
||||
/// Nothing: the window stays resizable while captured. The hold keeps the pointer on the window's
|
||||
/// own surface, and the window's resize edges lie outside it, the compositor's (xdg-decoration's
|
||||
/// decorations, libdecor's frame, an X11 window manager's frame window), where the pointer held
|
||||
/// over the image cannot go. A window SDL made not resizable would also be held on X11 at its
|
||||
/// decorations, libdecor's frame, an X11 window manager's frame window, Windows's non-client
|
||||
/// frame), where the pointer held over the image cannot go. A window SDL made not resizable would also be held on X11 at its
|
||||
/// size from before it was maximized or tiled (`X11_SetWindowMinMax`, read from SDL 3.4.18's
|
||||
/// code).
|
||||
pub(crate) fn hold_size(_shell: &Shell) {}
|
||||
@@ -350,7 +353,7 @@ pub(crate) fn close(shell: &mut Shell) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// The window goes: nothing of Linux's stays.
|
||||
/// The window goes: nothing of this side's stays.
|
||||
pub(crate) fn destroy(_shell: Shell) {}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! The UI thread on Linux, `reims-vgpu.ui`: SDL's thread, the work posted to it, and the host's
|
||||
//! screens as SDL lists them.
|
||||
//! The UI thread on Linux and Windows, `reims-vgpu.ui`: SDL's thread, the work posted to it, and
|
||||
//! the host's screens as SDL lists them.
|
||||
//!
|
||||
//! It starts at the first window's opening or the first look at the host's screens, and runs for
|
||||
//! the process: SDL's video is initialized there (so SDL takes it for its main thread) and every
|
||||
@@ -10,12 +10,14 @@
|
||||
//!
|
||||
//! **SDL's settings**, before its video starts: no signal handlers of its own (the host's stay
|
||||
//! the host's), the screen saver allowed (the windows keep the host from sleeping no more than
|
||||
//! any other window), `reims-vgpu` the windows' application ID (the task bar's entry on Wayland),
|
||||
//! any other window), `reims-vgpu` the windows' application ID (the task bar's entry on Wayland;
|
||||
//! SDL 3.4.18's Windows driver does not read it),
|
||||
//! cursors given for the screen's scale ([`crate::sdl::cursor`]), and no quit event when the last
|
||||
//! 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.
|
||||
//! Where SDL's video does not start (no Wayland compositor and no X server to reach on Linux), the
|
||||
//! reason 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
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
//! The window on Windows: SDL3's Win32 window, on the library's UI thread
|
||||
//! (`super::sdl_thread`), and what Windows adds under it.
|
||||
//!
|
||||
//! - **The UI thread owns the window.** A Win32 window's messages go to the thread that made it,
|
||||
//! and SDL makes the window and pumps its messages on the thread its video started on, the UI
|
||||
//! thread, which waits in SDL between its events as on Linux.
|
||||
//! - **DPI.** SDL's video start declares the process per-monitor DPI aware (v2), unless the
|
||||
//! process has declared its awareness already (read from SDL 3.4.18's code,
|
||||
//! `WIN_InitDPIAwareness`): SDL's sizes are then pixels, its modes have a pixel density of 1,
|
||||
//! and a screen's content scale is its DPI over 96, as on X11 (`crate::sdl::units`).
|
||||
//! - **The keyboard grab** while captured (`SDL_SetWindowKeyboardGrab`) is a low-level keyboard
|
||||
//! hook SDL installs on the UI thread while the window has the keyboard, which takes the
|
||||
//! system's shortcuts (the Windows key, Alt+Tab, Alt+Esc) before Windows does (read from SDL
|
||||
//! 3.4.18's code, `WIN_GrabKeyboard`). Windows calls the hook on that thread, so it is answered
|
||||
//! between the thread's events and jobs.
|
||||
//! - **The compositor's GPU**: Windows names none to a window's client ([`compositor_device`]),
|
||||
//! so the window presents on the runtime's device, as a window does where Linux names none.
|
||||
|
||||
use sdl3_sys::everything::SDL_Window;
|
||||
|
||||
/// The GPU the compositor composites SDL's window on: none known on Windows (the module doc).
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// None of its own: `unsafe` as Linux's, which reads SDL's window.
|
||||
pub(super) unsafe fn compositor_device(_window: *mut SDL_Window) -> Option<(u32, u32)> {
|
||||
None
|
||||
}
|
||||
@@ -107,8 +107,8 @@ pub trait VulkanTarget {
|
||||
|
||||
/// The GPU the host's compositor composites the window on, as its DRM node's major and minor
|
||||
/// numbers: on Linux under Wayland the main device of the window's surface's dma-buf feedback
|
||||
/// (`native/linux/feedback.rs`). `None` where the window system does not say, as on X11 and
|
||||
/// macOS: the window then presents from the runtime's own GPU.
|
||||
/// (`native/linux/feedback.rs`). `None` where the window system does not say, as on X11,
|
||||
/// Windows and macOS: the window then presents from the runtime's own GPU.
|
||||
fn compositor_device(&self) -> Option<(u32, u32)> {
|
||||
None
|
||||
}
|
||||
@@ -139,8 +139,11 @@ impl Presenting {
|
||||
/// Whether the last presenter was parked, once: the render thread then has a new window
|
||||
/// opened, over which the next presenter is made (the module doc, "A parked presenter").
|
||||
#[cfg_attr(
|
||||
all(not(target_os = "linux"), not(test)),
|
||||
expect(dead_code, reason = "only Linux's render thread opens a new window")
|
||||
all(not(any(target_os = "linux", target_os = "windows")), not(test)),
|
||||
expect(
|
||||
dead_code,
|
||||
reason = "only the SDL thread's render thread opens a new window (Linux, Windows)"
|
||||
)
|
||||
)]
|
||||
pub(crate) fn take_parked(&mut self) -> bool {
|
||||
std::mem::take(&mut self.parked)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! The host's screens, which the OS's side lists (`native`): "screen i" is the i-th of them, the
|
||||
//! 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/sdl_thread/ui.rs`). Where there are none (no window system to reach), there is no screen
|
||||
//! to open on ([`screen_for_port`]).
|
||||
//! Linux and Windows from SDL, on the library's UI thread, which takes a snapshot of them
|
||||
//! (`native/sdl_thread/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
|
||||
@@ -18,7 +18,7 @@ const DEFAULT_REFRESH_HZ: f64 = 60.0;
|
||||
/// A host screen.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct HostScreen {
|
||||
/// Its display ID: CoreGraphics' on macOS, SDL's on Linux.
|
||||
/// Its display ID: CoreGraphics' on macOS, SDL's on Linux and Windows.
|
||||
pub id: u32,
|
||||
/// Its current mode's size in pixels, width then height.
|
||||
pub pixels: (u32, u32),
|
||||
|
||||
@@ -3,14 +3,15 @@
|
||||
//! guest's cursor, and gives the surface the window is drawn into, so this crate speaks no window
|
||||
//! system's protocol of its own but where an OS's extension does ([`os`]).
|
||||
//!
|
||||
//! - **Linux** (`native/sdl_thread/sdl.rs`, the only window there): Wayland's or X11's window,
|
||||
//! presented through Vulkan on the runtime's own device. SDL runs on a thread of the library's
|
||||
//! own, `reims-vgpu.ui` (`native/sdl_thread/ui.rs`), started with the first window or the first look
|
||||
//! at the host's screens: QEMU's main thread is never taken nor waited on. Work for it is posted
|
||||
//! and runs between its events; the window's input reaches the host's callbacks there, one at a
|
||||
//! time, in the order the events came (`native/sdl_thread/input.rs`, `native/sdl_thread/keymap.rs`). Each
|
||||
//! window has a render thread too, `reims-vgpu.window` (`native/sdl_thread/render.rs`), which draws
|
||||
//! the display's current frame into the window's swapchain through the display's sink.
|
||||
//! - **Linux and Windows** (`native/sdl_thread/sdl.rs`, the only window there): Wayland's or
|
||||
//! X11's window, or Win32's, presented through Vulkan on the runtime's own device. SDL runs on a
|
||||
//! thread of the library's own, `reims-vgpu.ui` (`native/sdl_thread/ui.rs`), started with the
|
||||
//! first window or the first look at the host's screens: QEMU's main thread is never taken nor
|
||||
//! waited on. Work for it is posted and runs between its events; the window's input reaches the
|
||||
//! host's callbacks there, one at a time, in the order the events came
|
||||
//! (`native/sdl_thread/input.rs`, `native/sdl_thread/keymap.rs`). Each window has a render
|
||||
//! thread too, `reims-vgpu.window` (`native/sdl_thread/render.rs`), which draws the display's
|
||||
//! current frame into the window's swapchain through the display's sink.
|
||||
//! - **macOS** (`native/macos/sdl.rs`, with `REIMS_VGPU_WINDOW_IMPL=sdl`): Cocoa's window, drawn
|
||||
//! into a `CAMetalLayer` in SDL's Metal view by the same render thread as AppKit's window
|
||||
//! (`native/macos/render.rs`). SDL runs on the main thread, which AppKit needs, inside the
|
||||
|
||||
@@ -208,8 +208,11 @@ pub(crate) fn close(id: u64) {
|
||||
|
||||
/// Window `id`'s render thread let its surface go: SDL's window goes where the display has ended.
|
||||
#[cfg_attr(
|
||||
not(target_os = "linux"),
|
||||
expect(dead_code, reason = "only Linux's render thread holds SDL's window")
|
||||
not(any(target_os = "linux", target_os = "windows")),
|
||||
expect(
|
||||
dead_code,
|
||||
reason = "only the SDL thread's render thread holds SDL's window (Linux, Windows)"
|
||||
)
|
||||
)]
|
||||
pub(crate) fn released(id: u64) {
|
||||
let gone = with_shell(id, |shell| {
|
||||
@@ -226,8 +229,11 @@ pub(crate) fn released(id: u64) {
|
||||
/// has ended, the old one is kept and the window forgotten; where SDL makes no new one, the old
|
||||
/// one stays as it is, drawn no more.
|
||||
#[cfg_attr(
|
||||
not(target_os = "linux"),
|
||||
expect(dead_code, reason = "only Linux's render thread holds SDL's window")
|
||||
not(any(target_os = "linux", target_os = "windows")),
|
||||
expect(
|
||||
dead_code,
|
||||
reason = "only the SDL thread's render thread holds SDL's window (Linux, Windows)"
|
||||
)
|
||||
)]
|
||||
pub(crate) fn park(id: u64) {
|
||||
let Some((window, closed)) = with_shell(id, |s| (Arc::clone(&s.window), s.closed)) else {
|
||||
|
||||
@@ -4,12 +4,16 @@
|
||||
//! size asked for in pixels, its display bounds and usable bounds are pixels, its modes have a
|
||||
//! pixel density of 1, and the content scale is the desktop's (`Xft.dpi` over 96, else GDK's
|
||||
//! scale). Wayland's modes have the output's scale as their density, with SDL's sizes in points.
|
||||
//! Windows's are as X11's, in a process SDL declares per-monitor DPI aware (`native/windows.rs`):
|
||||
//! read from SDL 3.4.18's code, its windows driver makes a window's client area of the size asked
|
||||
//! for in pixels, its display bounds and usable bounds (the monitor's work area) are pixels, its
|
||||
//! modes have a pixel density of 1, and the content scale is the monitor's effective DPI over 96.
|
||||
//!
|
||||
//! Linux sizes its windows here (`native/sdl_thread/sdl.rs`); macOS's SDL windows open in the frames
|
||||
//! AppKit's window takes, in points.
|
||||
//! Linux and Windows size their windows here (`native/sdl_thread/sdl.rs`); macOS's SDL windows
|
||||
//! open in the frames AppKit's window takes, in points.
|
||||
|
||||
#![cfg_attr(
|
||||
all(not(target_os = "linux"), not(test)),
|
||||
all(not(any(target_os = "linux", target_os = "windows")), not(test)),
|
||||
expect(dead_code, reason = "macOS's SDL windows open in AppKit's frames")
|
||||
)]
|
||||
|
||||
|
||||
+8
-4
@@ -17,10 +17,14 @@ repeats the ones code cites.
|
||||
`memory/mapping.rs`, `display/pipeline.rs`), never after `-init` or an
|
||||
Objective-C class. One module style: `foo.rs` beside `foo/` (D44).
|
||||
- **Code for one OS** goes in files of its own (the window crate's
|
||||
`native/macos/` and `native/linux/`, the Vulkan crate's `os/macos.rs`
|
||||
and `os/linux.rs`, the C API's `ffi/catch/{macos,linux}.rs`), which the
|
||||
module above them picks with `#[cfg(target_os = ...)]`, rather than in
|
||||
`cfg`s spread through shared code. It sits in the crates both OSes share:
|
||||
`native/macos/`, `native/linux/` and `native/windows.rs`, the Vulkan
|
||||
crate's `os/macos.rs` and `os/linux.rs`, the C API's
|
||||
`ffi/catch/{macos,linux}.rs`), which the module above them picks with
|
||||
`#[cfg(target_os = ...)]`, rather than in `cfg`s spread through shared
|
||||
code. Code some OSes share and others do not goes in a module of its own
|
||||
that the index picks for those OSes (the window crate's
|
||||
`native/sdl_thread/`, SDL on the library's own thread, for Linux and
|
||||
Windows). It sits in the crates both OSes share:
|
||||
no crate is one OS's. A file both OSes share is the exception, where
|
||||
splitting cannot be avoided, and keeps its `cfg`s to a few whole items;
|
||||
index files that pick modules are exempt.
|
||||
|
||||
Reference in new issue
Block a user