Skip to content

Commit

Permalink
wayland: implement fifo-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Sep 13, 2024
1 parent e514c32 commit 3f1c961
Show file tree
Hide file tree
Showing 17 changed files with 403 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/backends/metal/present.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl MetalConnector {
self.latch_cursor(&node)?;
let cursor_programming = self.compute_cursor_programming();
let latched = self.latch(&node);
node.latched();
node.latched(self.try_async_flip());

if cursor_programming.is_none() && latched.is_none() {
return Ok(());
Expand Down
4 changes: 3 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl Clients {
bounding_caps: ClientCaps,
is_xwayland: bool,
) -> Result<Rc<Client>, ClientError> {
let data = Rc::new(Client {
let data = Rc::new_cyclic(|slf| Client {
id,
state: global.clone(),
checking_queue_size: Cell::new(false),
Expand All @@ -171,6 +171,8 @@ impl Clients {
commit_timelines: Rc::new(CommitTimelines::new(
&global.wait_for_sync_obj,
&global.ring,
&global.eng,
slf,
)),
});
track!(data, data);
Expand Down
4 changes: 3 additions & 1 deletion src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use {
scale::Scale,
sighand::{self, SighandError},
state::{ConnectorData, IdleState, ScreenlockState, State, XWaylandState},
tasks::{self, idle},
tasks::{self, handle_const_40hz_latch, idle},
tree::{
container_layout, container_render_data, float_layout, float_titles,
output_render_data, DisplayNode, NodeIds, OutputNode, TearingMode, VrrMode,
Expand Down Expand Up @@ -263,6 +263,7 @@ fn start_compositor2(
ei_clients: EiClients::new(),
slow_ei_clients: Default::default(),
cpu_worker,
const_40hz_latch: Default::default(),
});
state.tracker.register(ClientId::from_raw(0));
create_dummy_output(&state);
Expand Down Expand Up @@ -368,6 +369,7 @@ fn start_global_event_handlers(
eng.spawn2(Phase::PostLayout, perform_screencast_realloc(state.clone())),
eng.spawn2(Phase::PostLayout, visualize_damage(state.clone())),
eng.spawn(tasks::handle_slow_ei_clients(state.clone())),
eng.spawn2(Phase::Present, handle_const_40hz_latch(state.clone())),
]
}

Expand Down
2 changes: 2 additions & 0 deletions src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use {
wp_alpha_modifier_v1::WpAlphaModifierV1Global,
wp_content_type_manager_v1::WpContentTypeManagerV1Global,
wp_cursor_shape_manager_v1::WpCursorShapeManagerV1Global,
wp_fifo_manager_v1::WpFifoManagerV1Global,
wp_fractional_scale_manager_v1::WpFractionalScaleManagerV1Global,
wp_presentation::WpPresentationGlobal,
wp_security_context_manager_v1::WpSecurityContextManagerV1Global,
Expand Down Expand Up @@ -197,6 +198,7 @@ impl Globals {
add_singleton!(ZwpPointerGesturesV1Global);
add_singleton!(ZwpTabletManagerV2Global);
add_singleton!(JayDamageTrackingGlobal);
add_singleton!(WpFifoManagerV1Global);
}

pub fn add_backend_singletons(&self, backend: &Rc<dyn Backend>) {
Expand Down
1 change: 1 addition & 0 deletions src/ifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub mod wp_drm_lease_connector_v1;
pub mod wp_drm_lease_device_v1;
pub mod wp_drm_lease_request_v1;
pub mod wp_drm_lease_v1;
pub mod wp_fifo_manager_v1;
pub mod wp_fractional_scale_manager_v1;
pub mod wp_linux_drm_syncobj_manager_v1;
pub mod wp_linux_drm_syncobj_timeline_v1;
Expand Down
2 changes: 1 addition & 1 deletion src/ifs/jay_screencast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ enum Target {
}

impl LatchListener for JayScreencast {
fn after_latch(self: Rc<Self>) {
fn after_latch(self: Rc<Self>, _tearing: bool) {
self.schedule_toplevel_screencast();
}
}
Expand Down
35 changes: 33 additions & 2 deletions src/ifs/wl_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod dnd_icon;
pub mod ext_session_lock_surface_v1;
pub mod wl_subsurface;
pub mod wp_alpha_modifier_surface_v1;
pub mod wp_fifo_v1;
pub mod wp_fractional_scale_v1;
pub mod wp_linux_drm_syncobj_surface_v1;
pub mod wp_tearing_control_v1;
Expand Down Expand Up @@ -46,6 +47,7 @@ use {
dnd_icon::DndIcon,
wl_subsurface::{PendingSubsurfaceData, SubsurfaceId, WlSubsurface},
wp_alpha_modifier_surface_v1::WpAlphaModifierSurfaceV1,
wp_fifo_v1::WpFifoV1,
wp_fractional_scale_v1::WpFractionalScaleV1,
wp_linux_drm_syncobj_surface_v1::WpLinuxDrmSyncobjSurfaceV1,
wp_tearing_control_v1::WpTearingControlV1,
Expand Down Expand Up @@ -312,6 +314,8 @@ pub struct WlSurface {
presentation_listener: EventListener<dyn PresentationListener>,
commit_version: NumCell<u64>,
latched_commit_version: Cell<u64>,
fifo: CloneCell<Option<Rc<WpFifoV1>>>,
clear_fifo_on_vblank: Cell<bool>,
}

impl Debug for WlSurface {
Expand Down Expand Up @@ -433,6 +437,8 @@ struct PendingState {
release_point: Option<(Rc<SyncObj>, SyncObjPoint)>,
alpha_multiplier: Option<Option<f32>>,
explicit_sync: bool,
fifo_barrier_set: bool,
fifo_barrier_wait: bool,
}

struct AttachedSubsurfaceState {
Expand Down Expand Up @@ -510,6 +516,8 @@ impl PendingState {
&mut self.presentation_feedback,
&mut next.presentation_feedback,
);
self.fifo_barrier_set |= mem::take(&mut next.fifo_barrier_set);
self.fifo_barrier_wait |= mem::take(&mut next.fifo_barrier_wait);
macro_rules! merge_ext {
($name:ident) => {
if let Some(e) = &mut self.$name {
Expand Down Expand Up @@ -632,6 +640,8 @@ impl WlSurface {
presentation_listener: EventListener::new(slf.clone()),
commit_version: Default::default(),
latched_commit_version: Default::default(),
fifo: Default::default(),
clear_fifo_on_vblank: Default::default(),
}
}

Expand Down Expand Up @@ -1284,12 +1294,16 @@ impl WlSurface {
}
}
self.ext.get().after_apply_commit();
let fifo_barrier_set = mem::take(&mut pending.fifo_barrier_set);
if fifo_barrier_set {
self.commit_timeline.set_fifo_barrier();
}
if self.visible.get() {
let output = self.output.get();
if has_frame_requests {
self.vblank_listener.attach(&output.vblank_event);
}
if has_presentation_feedback {
if has_presentation_feedback || fifo_barrier_set {
self.latch_listener.attach(&output.latch_event);
}
if damage_full {
Expand All @@ -1311,10 +1325,16 @@ impl WlSurface {
let rect = output.global.pos.get();
self.client.state.damage(rect);
}
} else {
if fifo_barrier_set {
self.latch_listener
.attach(&self.client.state.const_40hz_latch);
}
}
pending.buffer_damage.clear();
pending.surface_damage.clear();
pending.damage_full = false;
pending.fifo_barrier_wait = false;
if tearing_changed {
if let Some(tl) = self.toplevel.get() {
if tl.tl_data().is_fullscreen.get() {
Expand Down Expand Up @@ -2062,12 +2082,15 @@ impl VblankListener for WlSurface {
let _ = fr.client.remove_obj(&*fr);
}
}
if self.clear_fifo_on_vblank.take() {
self.commit_timeline.clear_fifo_barrier();
}
self.vblank_listener.detach();
}
}

impl LatchListener for WlSurface {
fn after_latch(self: Rc<Self>) {
fn after_latch(self: Rc<Self>, tearing: bool) {
if self.visible.get() {
if self.latched_commit_version.get() < self.commit_version.get() {
let latched = &mut *self.latched_presentation_feedback.borrow_mut();
Expand All @@ -2083,6 +2106,14 @@ impl LatchListener for WlSurface {
self.latched_commit_version.set(self.commit_version.get());
}
}
if tearing && self.visible.get() {
if self.commit_timeline.has_fifo_barrier() {
self.vblank_listener.attach(&self.output.get().vblank_event);
self.clear_fifo_on_vblank.set(true);
}
} else {
self.commit_timeline.clear_fifo_barrier();
}
self.latch_listener.detach();
}
}
Expand Down
Loading

0 comments on commit 3f1c961

Please sign in to comment.