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

Initial support for DRM async page flip #1335

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
42 changes: 33 additions & 9 deletions anvil/src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use smithay::{
gles::{GlesRenderer, GlesTexture},
multigpu::{gbm::GbmGlesBackend, GpuManager, MultiRenderer},
sync::SyncPoint,
Bind, DebugFlags, ExportMem, ImportDma, ImportMemWl, Offscreen, Renderer,
Bind, DebugFlags, ExportMem, ImportDma, ImportMemWl, Offscreen, PresentationMode, Renderer,
},
session::{
libseat::{self, LibSeatSession},
Expand Down Expand Up @@ -67,8 +67,9 @@ use smithay::{
control::{connector, crtc, Device, ModeTypeFlags},
Device as _,
},
gbm::Modifier,
input::{DeviceCapability, Libinput},
rustix::fs::OFlags,
rustix::{self, fs::OFlags},
wayland_protocols::wp::{
linux_dmabuf::zv1::server::zwp_linux_dmabuf_feedback_v1,
presentation_time::server::wp_presentation_feedback,
Expand Down Expand Up @@ -560,6 +561,7 @@ struct SurfaceCompositorRenderResult<'a> {
states: RenderElementStates,
sync: Option<SyncPoint>,
damage: Option<&'a Vec<Rectangle<i32, Physical>>>,
presentation_mode: PresentationMode,
}

impl SurfaceComposition {
Expand Down Expand Up @@ -610,14 +612,15 @@ impl SurfaceComposition {
sync: Option<SyncPoint>,
damage: Option<Vec<Rectangle<i32, Physical>>>,
user_data: Option<OutputPresentationFeedback>,
presentation_mode: PresentationMode,
) -> Result<(), SwapBuffersError> {
match self {
SurfaceComposition::Surface { surface, .. } => surface
.queue_buffer(sync, damage, user_data)
.queue_buffer(sync, damage, user_data, presentation_mode)
.map_err(Into::<SwapBuffersError>::into),
SurfaceComposition::Compositor(c) => c
.queue_frame(user_data, presentation_mode)
.map_err(Into::<SwapBuffersError>::into),
SurfaceComposition::Compositor(c) => {
c.queue_frame(user_data).map_err(Into::<SwapBuffersError>::into)
}
}
}

Expand Down Expand Up @@ -655,6 +658,7 @@ impl SurfaceComposition {
damage: res.damage,
states: res.states,
sync: rendered.then_some(res.sync),
presentation_mode: PresentationMode::VSync,
}
})
.map_err(|err| match err {
Expand All @@ -671,11 +675,13 @@ impl SurfaceComposition {
if let PrimaryPlaneElement::Swapchain(element) = render_frame_result.primary_element {
element.sync.wait();
}
let presentation_mode = render_frame_result.presentation_mode();
SurfaceCompositorRenderResult {
rendered: !render_frame_result.is_empty,
damage: None,
states: render_frame_result.states,
sync: None,
presentation_mode,
}
})
.map_err(|err| match err {
Expand Down Expand Up @@ -769,11 +775,13 @@ fn get_surface_dmabuf_feedback(
.single_renderer(&render_node)
.ok()?
.dmabuf_formats()
.filter(|f| f.modifier == Modifier::Linear)
.collect::<HashSet<_>>();

let all_render_formats = primary_formats
.iter()
.chain(render_formats.iter())
.filter(|f| f.modifier == Modifier::Linear)
.copied()
.collect::<HashSet<_>>();

Expand Down Expand Up @@ -898,7 +906,14 @@ impl AnvilState<UdevData> {
.gpus
.single_renderer(&device.render_node)
.unwrap();
let render_formats = renderer.as_mut().egl_context().dmabuf_render_formats().clone();
let render_formats = renderer
.as_mut()
.egl_context()
.dmabuf_render_formats()
.iter()
.filter(|f| f.modifier == Modifier::Linear)
.copied()
.collect();

let output_name = format!("{}-{}", connector.interface().as_str(), connector.interface_id());
info!(?crtc, "Trying to setup connector {}", output_name,);
Expand Down Expand Up @@ -1445,6 +1460,7 @@ impl AnvilState<UdevData> {
Some(DrmError::DeviceInactive) => true,
Some(DrmError::Access(DrmAccessError { source, .. })) => {
source.kind() == io::ErrorKind::PermissionDenied
|| source.raw_os_error() == Some(rustix::io::Errno::BUSY.raw_os_error())
}
_ => false,
},
Expand Down Expand Up @@ -1616,6 +1632,7 @@ fn render_surface<'a>(
states,
sync,
damage,
presentation_mode,
} = surface
.compositor
.render_frame::<_, _, GlesTexture>(renderer, &elements, clear_color)?;
Expand All @@ -1639,7 +1656,12 @@ fn render_surface<'a>(
let damage = damage.cloned();
surface
.compositor
.queue_frame(sync, damage, Some(output_presentation_feedback))
.queue_frame(
sync,
damage,
Some(output_presentation_feedback),
presentation_mode,
)
.map_err(Into::<SwapBuffersError>::into)?;
}

Expand All @@ -1653,7 +1675,9 @@ fn initial_render(
surface
.compositor
.render_frame::<_, CustomRenderElements<_>, GlesTexture>(renderer, &[], CLEAR_COLOR)?;
surface.compositor.queue_frame(None, None, None)?;
surface
.compositor
.queue_frame(None, None, None, PresentationMode::VSync)?;
surface.compositor.reset_buffers();

Ok(())
Expand Down
Loading
Loading