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

wayland: implement fifo-v1 #141

Merged
merged 1 commit into from
Oct 11, 2024
Merged
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
1 change: 1 addition & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Jay supports the following wayland protocols:
| wp_content_type_manager_v1 | 1 | |
| wp_cursor_shape_manager_v1 | 1 | |
| wp_drm_lease_device_v1 | 1 | |
| wp_fifo_manager_v1 | 1 | |
| wp_fractional_scale_manager_v1 | 1 | |
| wp_linux_drm_syncobj_manager_v1 | 1 | |
| wp_presentation | 1 | |
Expand Down
1 change: 1 addition & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Implement ext-image-copy-capture-v1.
- Implement screencast session restoration.
- Fix screen sharing in zoom.
- Implement wp-fifo-v1.

# 1.6.0 (2024-09-25)

Expand Down
2 changes: 1 addition & 1 deletion src/backends/metal/present.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,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,
)),
wire_scale: Default::default(),
});
Expand Down
8 changes: 7 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},
tracy::enable_profiler,
tree::{
container_layout, container_render_positions, container_render_titles, float_layout,
Expand Down Expand Up @@ -272,6 +272,7 @@ fn start_compositor2(
ui_drag_enabled: Cell::new(true),
ui_drag_threshold_squared: Cell::new(10),
toplevels: Default::default(),
const_40hz_latch: Default::default(),
});
state.tracker.register(ClientId::from_raw(0));
create_dummy_output(&state);
Expand Down Expand Up @@ -435,6 +436,11 @@ fn start_global_event_handlers(
"slow ei clients",
tasks::handle_slow_ei_clients(state.clone()),
),
eng.spawn2(
"const 40hz latch",
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 @@ -39,6 +39,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 @@ -203,6 +204,7 @@ impl Globals {
add_singleton!(ExtOutputImageCaptureSourceManagerV1Global);
add_singleton!(ExtForeignToplevelImageCaptureSourceManagerV1Global);
add_singleton!(ExtImageCopyCaptureManagerV1Global);
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 @@ -53,6 +53,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
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl ExtImageCopyCaptureSessionV1RequestHandler for ExtImageCopyCaptureSessionV1
}

impl LatchListener for ExtImageCopyCaptureSessionV1 {
fn after_latch(self: Rc<Self>, on: &OutputNode) {
fn after_latch(self: Rc<Self>, on: &OutputNode, _tearing: bool) {
let ImageCaptureSource::Toplevel(tl) = &self.source else {
return;
};
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 @@ -89,7 +89,7 @@ enum Target {
}

impl LatchListener for JayScreencast {
fn after_latch(self: Rc<Self>, _on: &OutputNode) {
fn after_latch(self: Rc<Self>, _on: &OutputNode, _tearing: bool) {
self.schedule_toplevel_screencast();
}
}
Expand Down
41 changes: 39 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 @@ -317,6 +319,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 @@ -438,6 +442,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 @@ -515,6 +521,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 @@ -638,6 +646,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 @@ -1314,14 +1324,22 @@ 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 fifo_barrier_set {
// If we have a fifo barrier, must trigger latching.
output.global.connector.damage();
}
if damage_full {
let mut damage = buffer_abs_pos
.with_size(max_surface_size.0, max_surface_size.1)
Expand All @@ -1341,10 +1359,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 @@ -1631,6 +1655,8 @@ impl Object for WlSurface {
self.drm_feedback.clear();
self.commit_timeline.clear(ClearReason::BreakLoops);
self.alpha_modifier.take();
self.text_input_connections.clear();
self.fifo.take();
}
}

Expand Down Expand Up @@ -2101,12 +2127,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>, _on: &OutputNode) {
fn after_latch(self: Rc<Self>, _on: &OutputNode, 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 @@ -2122,6 +2151,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
Loading