Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send frame callbacks for active screencast windows #642

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
40 changes: 35 additions & 5 deletions src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3170,16 +3170,13 @@ impl Niri {
// However, this should probably be restricted to sending frame callbacks to more surfaces,
// to err on the safe side.
self.send_frame_callbacks(output);
#[cfg(feature = "xdp-gnome-screencast")]
self.send_frame_callbacks_for_cast(output);
backend.with_primary_renderer(|renderer| {
#[cfg(feature = "xdp-gnome-screencast")]
{
// Render and send to PipeWire screencast streams.
self.render_for_screen_cast(renderer, output, target_presentation_time);

// FIXME: when a window is hidden, it should probably still receive frame callbacks
// and get rendered for screen cast. This is currently
// unimplemented, but happens to work by chance, since output
// redrawing is more eager than it should be.
Comment on lines -3178 to -3182
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this comment should not be removed, it still stands. What this PR does is sends frame callbacks to off-screen windows, which makes them commit a new buffer. Which currently makes niri always redraw the output and hence render a new frame for a screencast. However, ideally niri shouldn't redraw the output if the window that committed a new buffer is fully off-screen. I will at some point add that optimization, which will once again stop off-screen windows from rendering for screencasts (or receiving frame callbacks from this PR for that matter), until this is fixed in a different way.

self.render_windows_for_screen_cast(renderer, output, target_presentation_time);
}

Expand Down Expand Up @@ -3576,6 +3573,39 @@ impl Niri {
}
}

#[cfg(feature = "xdp-gnome-screencast")]
fn send_frame_callbacks_for_cast(&self, output: &Output) {
use smithay::wayland::seat::WaylandFocus;

let _span = tracy_client::span!("Niri::send_frame_callbacks_for_cast");
let frame_callback_time = get_monotonic_time();

for mapped in self.layout.windows_for_output(output) {
for cast in &self.casts {
if !cast.is_active.get() {
continue;
}
let CastTarget::Window { id } = cast.target else {
continue;
};
if mapped.id().get() != id {
continue;
};
let Some(surface) = mapped.window.wl_surface() else {
continue;
};

send_frames_surface_tree(
surface.as_ref(),
output,
frame_callback_time,
FRAME_CALLBACK_THROTTLE,
|_, _| Some(output.clone()),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of being a separate function, this cast check should be integrated into send_frame_callbacks() where it should be part of the if current_primary_output.as_ref() != Some(output) check. The stuff in send_frame_callbacks() does throttling to at most one frame callback per output refresh; without it windows will busy-loop frame callbacks (especially so off-screen windows, which is the primary case here).

);
}
}
}

pub fn take_presentation_feedbacks(
&mut self,
output: &Output,
Expand Down