Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/sidestep-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kbvm = { version = "0.2", default-features = false, features = ["compose"] }
wayland-cursor = "0.31"
# Non-blocking clipboard pipes, and faulting in window memory ahead
# (madvise); already built for the Wayland crates.
rustix = { version = "1", default-features = false, features = ["std", "mm", "param"] }
rustix = { version = "1", default-features = false, features = ["std", "mm", "param", "time"] }
# Loads fontconfig from where it's found when the dynamic linker can't
# find it by name (NixOS; see src/system.rs). fontique's loader uses it.
libloading = "0.8"
Expand Down
16 changes: 15 additions & 1 deletion crates/sidestep-engine/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mod selection;
mod sheet;
mod textinput;
mod tiles;
mod video;

pub use decor::{HEADER, TITLE_SIZE, explicit_theme};

Expand Down Expand Up @@ -167,6 +168,7 @@ impl Drop for MainSender {
/// it drops the `Backend` the render thread ends (its channel closes), so
/// another may start after it.
pub fn start(wake: Waker) -> Backend {
crate::video::render_started();
let backend = if null::chosen() {
null::start(wake)
} else {
Expand Down Expand Up @@ -271,6 +273,7 @@ fn run(channel: Channel<ToRender>, to_main: MainSender) {
} else {
globals.bind::<WpFractionalScaleManagerV1, _, _>(&qh, 1..=1, ()).ok()
};
let videos = video::Videos::new(&globals, &qh);
let mut state = State {
registry: RegistryState::new(&globals),
outputs: OutputState::new(&globals, &qh),
Expand Down Expand Up @@ -300,10 +303,12 @@ fn run(channel: Channel<ToRender>, to_main: MainSender) {
// The environment isn't changed: other threads may be reading it.
startup_token: std::env::var("XDG_ACTIVATION_TOKEN").ok().filter(|t| !t.is_empty()),
empty_region: None,
videos,
ca: crate::ca::tree::Compositor::default(),
exit: false,
};
seat::bind_existing(&mut state, &globals);
state.videos.ask_caps(&state.conn, &state.qh);
outputs::started(&state, &globals);
while !state.exit {
// While tiles have paints to rasterize, look for events without
Expand Down Expand Up @@ -372,6 +377,8 @@ pub struct State {
/// An input region with nothing in it, made the first time a window
/// lets pointer input through.
empty_region: Option<Region>,
/// Video subsurfaces and the buffers their frames show (see `video`).
videos: video::Videos,
/// Core Animation's layer trees, animated here (see `ca::tree`).
ca: crate::ca::tree::Compositor,
exit: bool,
Expand Down Expand Up @@ -1110,6 +1117,9 @@ impl State {
// Pixel capture is a null-backend diagnostic only.
let _ = reply.send(None);
}
ToRender::PlaceVideo { window, video, place } => video::place(self, window, video, place),
ToRender::ShowVideo { window, video, frame } => video::show(self, window, video, *frame),
ToRender::ClearVideo { window, video } => video::clear(self, window, video),
ToRender::SetSelection { contents } => selection::set(self, contents),
ToRender::ReadSelection { mime, token, source, drag } => selection::read(self, mime, token, source, drag),
ToRender::SelectionData { token, data } => selection::provided(self, token, data),
Expand Down Expand Up @@ -1400,7 +1410,9 @@ impl State {
if let Some(i) = &win.foreign_parent {
i.destroy();
}
// Tiles and decorations go first: they're subsurfaces of the root.
// Tiles, videos and decorations go first: they're subsurfaces of
// the root.
self.videos.window_closed(window);
drop(win.layers);
drop(win.decor);
drop(win.menubar);
Expand Down Expand Up @@ -1824,9 +1836,11 @@ impl State {
self.draw_frame(window, rgba);
}
self.place_decorations(window);
let placed = video::before_commit(self, window);
let Some(win) = self.windows.get(&window) else { return };
win.surface().frame(&self.qh, FrameTag { window, seq });
win.commit();
video::after_commit(self, placed);
}

/// Draw the paints since the last present straight into a buffer, and
Expand Down
35 changes: 35 additions & 0 deletions crates/sidestep-engine/src/backend/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ pub enum Seen {
window: u32,
rects: Option<Vec<crate::protocol::Rect>>,
},
/// A video of the window was placed there, or taken away.
VideoPlaced {
window: u32,
video: u32,
place: Option<crate::video::VideoPlace>,
},
/// A frame of a video showed (at once, as presented), so big in
/// pixels; or the video was cleared (none).
VideoShown {
window: u32,
video: u32,
size: Option<(u32, u32)>,
},
}

/// A run of text the main thread asked the null render thread to paint.
Expand Down Expand Up @@ -242,6 +255,17 @@ pub fn chosen() -> bool {

pub fn start(wake: Waker) -> Backend {
RUNNING.store(true, Ordering::Relaxed);
// A compositor that takes shared memory and dmabufs of nothing, and
// shows frames at the times they ask for.
crate::video::publish_caps(crate::video::VideoCaps {
known: true,
dmabuf: Vec::new(),
shm: vec![0, 1],
commit_timing: true,
presentation: true,
monotonic: true,
main_device: 0,
});
let (tx, channel) = channel::channel();
let (to_main, rx) = mpsc::channel();
let to_main = MainSender::new(to_main, wake);
Expand Down Expand Up @@ -482,6 +506,17 @@ fn run(channel: Channel<ToRender>, to_main: MainSender) {
}),
ToRender::SelectionData { token, data } => note(Seen::Provided { token, data: data.map(|d| d.to_vec()) }),
ToRender::SetOpaqueRegion { window, rects } => note(Seen::OpaqueRegion { window, rects }),
ToRender::PlaceVideo { window, video, place } => note(Seen::VideoPlaced { window, video, place }),
ToRender::ShowVideo { window, video, mut frame } => {
// Shown at once, as a compositor always ready for a frame
// would, and released at once.
let size = Some(frame.buffer.size());
let time = crate::video::monotonic_now();
frame.report(crate::video::Shown::Presented { time, refresh: 16_666_667 });
drop(frame);
note(Seen::VideoShown { window, video, size });
}
ToRender::ClearVideo { window, video } => note(Seen::VideoShown { window, video, size: None }),
ToRender::Paint { window: _, target: crate::protocol::Target::Content(layer), rects, ops } => {
with_ca(|ca| ca.paint_content(layer, &rects, &ops, &mut glyphs));
}
Expand Down
Loading
Loading