Skip to main content

tilo_render_protocol/
lib.rs

1//! How a Tilo app hands its frames to the render service of its room, and
2//! how the service makes sure a frame is safe to draw.
3//!
4//! An app does not rasterize. Its toolkit builds the widget tree, lays it out
5//! and records the frame as vello's encoding, as before, then writes that
6//! encoding into shared memory instead of onto a GPU. The room's render
7//! service — the only toolkit-app process that opens the GPU — validates it,
8//! rasterizes it on its warm device into dma-bufs and hands those back; the app
9//! attaches them to its own `wl_surface`, so the compositor imports them like
10//! any client buffer (zero copies, direct scanout kept).
11//!
12//! This crate is the contract both sides compile:
13//!
14//! - [`scene`]: a vello [`Encoding`](vello_encoding::Encoding) as bytes, with
15//!   fonts, images and external surfaces referenced by id instead of by
16//!   pointer.
17//! - [`frame`]: one frame of one surface: its size, damage, scroll copies,
18//!   the layers it changes and the backdrops it blurs. Records are
19//!   type-length-value sections, so later steps (scene annotations,
20//!   service-run motion) add sections without breaking older peers.
21//! - [`validate`]: the CPU pass every scene passes before a GPU sees it, and
22//!   the per-app [`Limits`] it enforces. A scene is hostile until it passes.
23//! - [`control`]: the messages on the control channel ("frame N is in the
24//!   ring", "frame N is in buffer B", "frame N was presented"), and on Unix
25//!   [`channel`] carries them with descriptors over a packet socket pair, and
26//!   [`shm`] the shared memory: the ring frames are written to, and the images
27//!   an app uploads once.
28//! - [`patch`]: beside scenes, the component patches a tilolang app sends the
29//!   room's UI host instead of pixels, the events, bindings, focus and
30//!   composition that come back, and the check every batch passes.
31
32pub mod control;
33pub mod frame;
34pub mod limits;
35pub mod patch;
36pub mod scene;
37pub mod validate;
38
39// The render service's broker serves the Linux session's apps alone.
40#[cfg(target_os = "linux")]
41pub mod broker;
42#[cfg(unix)]
43pub mod channel;
44#[cfg(any(unix, windows))]
45pub mod shm;
46
47mod bytes;
48
49pub use limits::Limits;
50
51/// The version both peers name in their hello. A peer that speaks a newer
52/// version must still accept this one's sections; a section it does not
53/// know is skipped only when its sender marked it optional.
54pub const PROTOCOL_VERSION: u16 = 3;
55
56/// A font an app registered, by the number it chose.
57#[derive(
58    Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
59)]
60pub struct FontId(pub u32);
61
62/// An image an app uploaded once, by the number it chose.
63#[derive(
64    Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
65)]
66pub struct ImageId(pub u32);
67
68/// A surface (a window, a popup) the app renders through the service.
69#[derive(
70    Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
71)]
72pub struct SurfaceId(pub u32);
73
74/// One layer of a surface's scene. Layer 0 is the surface's content; others
75/// are parts of it the app updates on their own (scrolling regions,
76/// popovers) and, from step 2 on, parts the service animates.
77#[derive(
78    Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
79)]
80pub struct LayerId(pub u32);
81
82impl LayerId {
83    /// The layer a surface's whole content is drawn in.
84    pub const ROOT: Self = Self(0);
85}
86
87/// Why bytes could not be read as a record, or a record was refused.
88#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
89pub enum WireError {
90    /// The other end let go of the connection: it ended, as a window that closed does.
91    #[error("the other side closed the connection")]
92    Closed,
93    #[error("the record ends early")]
94    Truncated,
95    #[error("a count or offset overflows")]
96    Overflow,
97    #[error("malformed record: {0}")]
98    Malformed(&'static str),
99    #[error("unknown required section {0}")]
100    UnknownSection(u16),
101    #[error("the record names {0}, which this connection never registered")]
102    UnknownResource(&'static str),
103    #[error("the record is over its limit: {0}")]
104    OverLimit(&'static str),
105    #[error("invalid scene: {0}")]
106    Invalid(&'static str),
107}