Skip to content

Commit

Permalink
anvil: enable fifo protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeissl committed Nov 14, 2024
1 parent 6c23514 commit ee4acc9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 12 deletions.
28 changes: 26 additions & 2 deletions anvil/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use smithay::{
wayland::{
compositor::{get_parent, with_states, CompositorClientState, CompositorState},
dmabuf::DmabufFeedback,
fifo::{FifoBarrierCachedState, FifoManagerState},
fractional_scale::{with_fractional_scale, FractionalScaleHandler, FractionalScaleManagerState},
input_method::{InputMethodHandler, InputMethodManagerState, PopupSurface},
keyboard_shortcuts_inhibit::{
Expand Down Expand Up @@ -152,6 +153,7 @@ pub struct AnvilState<BackendData: Backend + 'static> {
#[cfg(feature = "xwayland")]
pub xwayland_shell_state: xwayland_shell::XWaylandShellState,
pub single_pixel_buffer_state: SinglePixelBufferState,
pub fifo_manager_state: FifoManagerState,

pub dnd_icon: Option<DndIcon>,

Expand Down Expand Up @@ -565,6 +567,8 @@ smithay::delegate_xdg_foreign!(@<BackendData: Backend + 'static> AnvilState<Back

smithay::delegate_single_pixel_buffer!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

smithay::delegate_fifo!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend + 'static> AnvilState<BackendData> {
pub fn init(
display: Display<AnvilState<BackendData>>,
Expand Down Expand Up @@ -627,6 +631,7 @@ impl<BackendData: Backend + 'static> AnvilState<BackendData> {
let fractional_scale_manager_state = FractionalScaleManagerState::new::<Self>(&dh);
let xdg_foreign_state = XdgForeignState::new::<Self>(&dh);
let single_pixel_buffer_state = SinglePixelBufferState::new::<Self>(&dh);
let fifo_manager_state = FifoManagerState::new::<Self>(&dh);
TextInputManagerState::new::<Self>(&dh);
InputMethodManagerState::new::<Self, _>(&dh, |_client| true);
VirtualKeyboardManagerState::new::<Self, _>(&dh, |_client| true);
Expand Down Expand Up @@ -686,6 +691,7 @@ impl<BackendData: Backend + 'static> AnvilState<BackendData> {
fractional_scale_manager_state,
xdg_foreign_state,
single_pixel_buffer_state,
fifo_manager_state,
dnd_icon: None,
suppressed_keys: Vec::new(),
cursor_status: CursorImageStatus::default_named(),
Expand Down Expand Up @@ -767,13 +773,16 @@ pub struct SurfaceDmabufFeedback<'a> {
}

#[profiling::function]
pub fn post_repaint(
pub fn post_repaint<F>(
output: &Output,
render_element_states: &RenderElementStates,
space: &Space<WindowElement>,
dmabuf_feedback: Option<SurfaceDmabufFeedback<'_>>,
time: impl Into<Duration>,
) {
mut blocker_cleared: F,
) where
F: FnMut(&WlSurface),
{
let time = time.into();
let throttle = Some(Duration::from_secs(1));

Expand Down Expand Up @@ -806,6 +815,21 @@ pub fn post_repaint(
)
});
}
if let Some(surface) = window.wl_surface() {
let fifo_barrier = with_states(&surface, |states| {
states
.cached_state
.get::<FifoBarrierCachedState>()
.current()
.barrier
.take()
});

if let Some(fifo_barrier) = fifo_barrier {
fifo_barrier.signal();
blocker_cleared(&surface);
}
}
}
});
let map = smithay::desktop::layer_map_for_output(output);
Expand Down
24 changes: 20 additions & 4 deletions anvil/src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ use smithay::{
linux_dmabuf::zv1::server::zwp_linux_dmabuf_feedback_v1,
presentation_time::server::wp_presentation_feedback,
},
wayland_server::{backend::GlobalId, protocol::wl_surface, Display, DisplayHandle},
wayland_server::{
backend::GlobalId,
protocol::wl_surface::{self, WlSurface},
Display, DisplayHandle, Resource,
},
},
utils::{Clock, DeviceFd, IsAlive, Logical, Monotonic, Physical, Point, Rectangle, Scale, Transform},
wayland::{
compositor,
compositor::{self, CompositorHandler},
dmabuf::{
DmabufFeedback, DmabufFeedbackBuilder, DmabufGlobal, DmabufHandler, DmabufState, ImportNotifier,
},
Expand Down Expand Up @@ -1488,6 +1492,13 @@ impl AnvilState<UdevData> {
&mut self.cursor_status,
&self.clock,
self.show_window_preview,
|surface| {
let client = surface.client().unwrap();
self.handle.insert_idle(move |data| {
let dh = data.display_handle.clone();
data.client_compositor_state(&client).blocker_cleared(data, &dh);
});
},
);
let reschedule = match &result {
Ok(has_rendered) => !has_rendered,
Expand Down Expand Up @@ -1586,7 +1597,7 @@ impl AnvilState<UdevData> {

#[allow(clippy::too_many_arguments)]
#[profiling::function]
fn render_surface<'a>(
fn render_surface<'a, F>(
surface: &'a mut SurfaceData,
renderer: &mut UdevRenderer<'a>,
space: &Space<WindowElement>,
Expand All @@ -1598,7 +1609,11 @@ fn render_surface<'a>(
cursor_status: &mut CursorImageStatus,
clock: &Clock<Monotonic>,
show_window_preview: bool,
) -> Result<bool, SwapBuffersError> {
blocker_cleared: F,
) -> Result<bool, SwapBuffersError>
where
F: FnMut(&WlSurface),
{
let output_geometry = space.output_geometry(output).unwrap();
let scale = Scale::from(output.current_scale().fractional_scale());

Expand Down Expand Up @@ -1697,6 +1712,7 @@ fn render_surface<'a>(
scanout_feedback: &feedback.scanout_feedback,
}),
clock.now(),
blocker_cleared,
);

if rendered {
Expand Down
19 changes: 16 additions & 3 deletions anvil/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ use smithay::{
reexports::{
calloop::EventLoop,
wayland_protocols::wp::presentation_time::server::wp_presentation_feedback,
wayland_server::{protocol::wl_surface, Display},
wayland_server::{protocol::wl_surface, Display, Resource},
winit::platform::pump_events::PumpStatus,
},
utils::{IsAlive, Scale, Transform},
wayland::{
compositor,
compositor::{self, CompositorHandler},
dmabuf::{
DmabufFeedback, DmabufFeedbackBuilder, DmabufGlobal, DmabufHandler, DmabufState, ImportNotifier,
},
Expand Down Expand Up @@ -385,7 +385,20 @@ pub fn run_winit() {

// Send frame events so that client start drawing their next frame
let time = state.clock.now();
post_repaint(&output, &render_output_result.states, &state.space, None, time);
post_repaint(
&output,
&render_output_result.states,
&state.space,
None,
time,
|surface| {
let client = surface.client().unwrap();
state.handle.insert_idle(move |data| {
let dh = data.display_handle.clone();
data.client_compositor_state(&client).blocker_cleared(data, &dh);
});
},
);

if has_rendered {
let mut output_presentation_feedback =
Expand Down
19 changes: 16 additions & 3 deletions anvil/src/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ use smithay::{
calloop::EventLoop,
gbm,
wayland_protocols::wp::presentation_time::server::wp_presentation_feedback,
wayland_server::{protocol::wl_surface, Display},
wayland_server::{protocol::wl_surface, Display, Resource},
},
utils::{DeviceFd, IsAlive, Scale},
wayland::{
compositor,
compositor::{self, CompositorHandler},
dmabuf::{
DmabufFeedback, DmabufFeedbackBuilder, DmabufGlobal, DmabufHandler, DmabufState, ImportNotifier,
},
Expand Down Expand Up @@ -402,7 +402,20 @@ pub fn run_x11() {

// Send frame events so that client start drawing their next frame
let time = state.clock.now();
post_repaint(&output, &render_output_result.states, &state.space, None, time);
post_repaint(
&output,
&render_output_result.states,
&state.space,
None,
time,
|surface| {
let client = surface.client().unwrap();
state.handle.insert_idle(move |data| {
let dh = data.display_handle.clone();
data.client_compositor_state(&client).blocker_cleared(data, &dh);
});
},
);

if render_output_result.damage.is_some() {
let mut output_presentation_feedback =
Expand Down

0 comments on commit ee4acc9

Please sign in to comment.