Skip to main content

Module session

Module session 

Source
Expand description

Session: what a set of windows shares.

kui is one Core per window, and everything per frame (the tree, the display list, focus, hit regions) stays with its window. What must not be duplicated lives in a Session: the font database every window shapes against, the resource registry behind every FontId / ImageId / SoundId, the audio store (the process has one device), and the declared window set. Any number of cores are constructed against one session with Core::new_in, so a font, image or sound registered in one window draws and plays in every window. Core::new makes a private session, which is why a single-window app never has to know one exists.

use kui_core::{Core, Session};

let session = Session::new();
let main = Core::new_in(&session);
let popup = Core::new_in(&session);

// Registered through one window, visible to both.
let image = main.resources.add_image(2, 2, vec![255; 16]);
assert_eq!(popup.resources.image_size(image), Some((2, 2)));
assert!(main.session().is(&session));

The shaped-text cache and the glyph atlas stay per window even though they look like caches: a cache entry is only valid for the atlas page it was packed against, and Core::output lends that page to the window’s renderer.

A handle belongs to its session. Handles are unique to the process, so a FontId / ImageId / SoundId handed to a core of another session is a miss, never an alias: it behaves as a removed handle does, and the next Core::take_warnings reports it as foreign-resource. Two Core::new()s are two sessions.

The session is Rc<RefCell<_>>: a Core borrows it inside a method and drops the borrow before returning, and the windows of a multi-window app are driven one frame at a time on one thread, so the check never contends.

Structs§

Session
The font database, registries and audio store a set of windows share. Cloning one clones the handle, not the contents: that is how a second Core joins (Core::new_in(&session)).
SharedAudio
A window’s handle to the session’s audio store — Core‘s audio field. The process has one audio device, so the playbacks and the command queue are the session’s and not this window’s: whichever window’s driver drains the queue applies every window’s sounds. The audio nodes’ mounts are per window inside it (see the module doc), which is why the readers here take one.
SharedResources
A window’s handle to the session’s resource registry — Core’s resources field. A font, image or sound registered through one is registered for every window in the session, and draws in all of them.

Constants§

MAIN_WINDOW_NAME
The main window’s name: what view(model, window) is called with in Node, and what Core::window_name answers for WindowId::MAIN.