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 Mar 30, 2024
1 parent ba98103 commit f69a0c9
Show file tree
Hide file tree
Showing 14 changed files with 351 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/backends/metal/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ impl MetalConnector {
if let Some(node) = self.state.root.outputs.get(&self.connector_id) {
let buffer = &buffers[self.next_buffer.get() % buffers.len()];
let mut rr = self.render_result.borrow_mut();
rr.output_id = node.id;
let fb =
self.prepare_present_fb(&mut rr, buffer, &plane, &node, try_direct_scanout)?;
rr.dispatch_frame_requests();
Expand Down
11 changes: 8 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use {
activation_token::ActivationToken,
asyncevent::AsyncEvent,
buffd::{MsgFormatter, MsgParser, MsgParserError, OutBufferSwapchain},
clonecell::CloneCell,
copyhashmap::{CopyHashMap, Locked},
errorfmt::ErrorFmt,
numcell::NumCell,
Expand Down Expand Up @@ -153,13 +154,15 @@ impl Clients {
last_xwayland_serial: Cell::new(0),
surfaces_by_xwayland_serial: Default::default(),
activation_tokens: Default::default(),
commit_timelines: Rc::new(CommitTimelines::new(&global.wait_for_sync_obj)),
commit_timelines: Default::default(),
});
track!(data, data);
let display = Rc::new(WlDisplay::new(&data));
track!(data, display);
data.objects.display.set(Some(display.clone()));
data.objects.add_client_object(display).expect("");
let commit_timelines = Rc::new(CommitTimelines::new(&data));
data.commit_timelines.set(Some(commit_timelines));
let client = ClientHolder {
_handler: global.eng.spawn(tasks::client(data.clone())),
data: data.clone(),
Expand Down Expand Up @@ -225,7 +228,9 @@ impl Drop for ClientHolder {
self.data.shutdown.clear();
self.data.surfaces_by_xwayland_serial.clear();
self.data.remove_activation_tokens();
self.data.commit_timelines.clear();
if let Some(ct) = self.data.commit_timelines.take() {
ct.clear();
}
}
}

Expand Down Expand Up @@ -266,7 +271,7 @@ pub struct Client {
pub last_xwayland_serial: Cell<u64>,
pub surfaces_by_xwayland_serial: CopyHashMap<u64, Rc<WlSurface>>,
pub activation_tokens: RefCell<VecDeque<ActivationToken>>,
pub commit_timelines: Rc<CommitTimelines>,
pub commit_timelines: CloneCell<Option<Rc<CommitTimelines>>>,
}

pub const NUM_CACHED_SERIAL_RANGES: usize = 64;
Expand Down
2 changes: 2 additions & 0 deletions src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use {
wl_surface::xwayland_shell_v1::XwaylandShellV1Global,
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_single_pixel_buffer_manager_v1::WpSinglePixelBufferManagerV1Global,
Expand Down Expand Up @@ -171,6 +172,7 @@ impl Globals {
add_singleton!(ZwpIdleInhibitManagerV1Global);
add_singleton!(ExtIdleNotifierV1Global);
add_singleton!(XdgToplevelDragManagerV1Global);
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 @@ -37,6 +37,7 @@ pub mod wp_content_type_manager_v1;
pub mod wp_content_type_v1;
pub mod wp_cursor_shape_device_v1;
pub mod wp_cursor_shape_manager_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
12 changes: 11 additions & 1 deletion src/ifs/wl_compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@ impl WlCompositorGlobal {

impl WlCompositor {
fn create_surface(&self, parser: MsgParser<'_, '_>) -> Result<(), WlCompositorError> {
let Some(commit_timelines) = self.client.commit_timelines.get() else {
return Err(WlCompositorError::CommitTimelines);
};
let surface: CreateSurface = self.client.parse(self, parser)?;
let surface = Rc::new(WlSurface::new(surface.id, &self.client, self.version));
let surface = Rc::new(WlSurface::new(
surface.id,
&self.client,
self.version,
&commit_timelines,
));
track!(self.client, surface);
self.client.add_client_obj(&surface)?;
if self.client.is_xwayland {
Expand Down Expand Up @@ -103,6 +111,8 @@ pub enum WlCompositorError {
ClientError(Box<ClientError>),
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
#[error("Commit timelines are not available")]
CommitTimelines,
}

efrom!(WlCompositorError, ClientError);
Expand Down
32 changes: 28 additions & 4 deletions src/ifs/wl_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod commit_timeline;
pub mod cursor;
pub mod ext_session_lock_surface_v1;
pub mod wl_subsurface;
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 All @@ -27,9 +28,12 @@ use {
NodeSeatState, SeatId, WlSeatGlobal,
},
wl_surface::{
commit_timeline::{ClearReason, CommitTimeline, CommitTimelineError},
commit_timeline::{
ClearReason, CommitTimeline, CommitTimelineError, CommitTimelines,
},
cursor::CursorSurface,
wl_subsurface::{PendingSubsurfaceData, SubsurfaceId, WlSubsurface},
wp_fifo_v1::WpFifoV1,
wp_fractional_scale_v1::WpFractionalScaleV1,
wp_linux_drm_syncobj_surface_v1::WpLinuxDrmSyncobjSurfaceV1,
wp_tearing_control_v1::WpTearingControlV1,
Expand All @@ -48,7 +52,7 @@ use {
renderer::Renderer,
tree::{
FindTreeResult, FoundNode, Node, NodeId, NodeVisitor, NodeVisitorBase, OutputNode,
ToplevelNode,
OutputNodeId, ToplevelNode,
},
utils::{
buffd::{MsgParser, MsgParserError},
Expand Down Expand Up @@ -251,6 +255,7 @@ pub struct WlSurface {
sync_obj_surface: CloneCell<Option<Rc<WpLinuxDrmSyncobjSurfaceV1>>>,
destroyed: Cell<bool>,
commit_timeline: CommitTimeline,
fifo: CloneCell<Option<Rc<WpFifoV1>>>,
}

impl Debug for WlSurface {
Expand Down Expand Up @@ -374,6 +379,7 @@ struct PendingState {
acquire_point: Option<(Rc<SyncObj>, SyncObjPoint)>,
release_point: Option<(Rc<SyncObj>, SyncObjPoint)>,
explicit_sync: bool,
fifo: bool,
}

struct CommittedSubsurface {
Expand Down Expand Up @@ -484,7 +490,12 @@ pub struct StackElement {
}

impl WlSurface {
pub fn new(id: WlSurfaceId, client: &Rc<Client>, version: u32) -> Self {
pub fn new(
id: WlSurfaceId,
client: &Rc<Client>,
version: u32,
commit_timelines: &Rc<CommitTimelines>,
) -> Self {
Self {
id,
node_id: client.state.node_ids.next(),
Expand Down Expand Up @@ -529,7 +540,8 @@ impl WlSurface {
drm_feedback: Default::default(),
sync_obj_surface: Default::default(),
destroyed: Cell::new(false),
commit_timeline: client.commit_timelines.create_timeline(),
commit_timeline: commit_timelines.create_timeline(),
fifo: Default::default(),
}
}

Expand Down Expand Up @@ -852,6 +864,7 @@ impl WlSurface {
if self.destroyed.get() {
return Ok(());
}
pending.fifo = false;
self.ext.get().before_apply_commit(pending)?;
let mut scale_changed = false;
if let Some(scale) = pending.scale.take() {
Expand Down Expand Up @@ -915,6 +928,9 @@ impl WlSurface {
cursor.dec_hotspot(dx, dy);
}
}
if self.visible.get() {
self.commit_timeline.committed();
}
} else {
self.buf_x.set(0);
self.buf_y.set(0);
Expand Down Expand Up @@ -1202,10 +1218,17 @@ impl WlSurface {
}
if !visible {
self.send_seat_release_events();
self.commit_timeline.presented();
}
self.seat_state.set_visible(self, visible);
}

pub fn presented(&self, on: OutputNodeId) {
if on == self.output.get().id {
self.commit_timeline.presented();
}
}

pub fn detach_node(&self, set_invisible: bool) {
for (_, constraint) in &self.constraints {
constraint.deactivate();
Expand Down Expand Up @@ -1238,6 +1261,7 @@ impl WlSurface {
}
if set_invisible {
self.visible.set(false);
self.commit_timeline.presented();
}
}

Expand Down
Loading

0 comments on commit f69a0c9

Please sign in to comment.