Apply rendering fixes to udev

This commit is contained in:
Ottatop 2023-09-09 16:58:07 -05:00
parent 3b65ba5c1d
commit 8fd0469b82
3 changed files with 33 additions and 24 deletions

View file

@ -86,7 +86,9 @@ use smithay_drm_extras::{
use crate::{ use crate::{
api::msg::{Args, OutgoingMsg}, api::msg::{Args, OutgoingMsg},
render::{pointer::PointerElement, CustomRenderElements}, render::{pointer::PointerElement, CustomRenderElements},
state::{take_presentation_feedback, Backend, CalloopData, State, SurfaceDmabufFeedback}, state::{
take_presentation_feedback, Backend, CalloopData, State, SurfaceDmabufFeedback, WithState,
},
window::WindowElement, window::WindowElement,
}; };
@ -151,14 +153,10 @@ pub fn run_udev() -> anyhow::Result<()> {
let mut event_loop = EventLoop::try_new().unwrap(); let mut event_loop = EventLoop::try_new().unwrap();
let mut display = Display::new().unwrap(); let mut display = Display::new().unwrap();
/* // Initialize session
* Initialize session
*/
let (session, notifier) = LibSeatSession::new()?; let (session, notifier) = LibSeatSession::new()?;
/* // Initialize the compositor
* Initialize the compositor
*/
let primary_gpu = if let Ok(var) = std::env::var("ANVIL_DRM_DEVICE") { let primary_gpu = if let Ok(var) = std::env::var("ANVIL_DRM_DEVICE") {
DrmNode::from_path(var).expect("Invalid drm device path") DrmNode::from_path(var).expect("Invalid drm device path")
} else { } else {
@ -202,9 +200,7 @@ pub fn run_udev() -> anyhow::Result<()> {
event_loop.handle(), event_loop.handle(),
)?; )?;
/* // Initialize the udev backend
* Initialize the udev backend
*/
let udev_backend = UdevBackend::new(state.seat.name())?; let udev_backend = UdevBackend::new(state.seat.name())?;
// Create DrmNodes from already connected GPUs // Create DrmNodes from already connected GPUs
@ -245,9 +241,7 @@ pub fn run_udev() -> anyhow::Result<()> {
}) })
.unwrap(); .unwrap();
/* // Initialize libinput backend
* Initialize libinput backend
*/
let mut libinput_context = Libinput::new_with_udev::<LibinputSessionInterface<LibSeatSession>>( let mut libinput_context = Libinput::new_with_udev::<LibinputSessionInterface<LibSeatSession>>(
backend.session.clone().into(), backend.session.clone().into(),
); );
@ -256,9 +250,7 @@ pub fn run_udev() -> anyhow::Result<()> {
.unwrap(); .unwrap();
let libinput_backend = LibinputInputBackend::new(libinput_context.clone()); let libinput_backend = LibinputInputBackend::new(libinput_context.clone());
/* // Bind all our objects that get driven by the event loop
* Bind all our objects that get driven by the event loop
*/
let insert_ret = event_loop let insert_ret = event_loop
.handle() .handle()
.insert_source(libinput_backend, move |event, _, data| { .insert_source(libinput_backend, move |event, _, data| {
@ -1460,6 +1452,31 @@ fn render_surface<'a>(
pointer_location: Point<f64, Logical>, pointer_location: Point<f64, Logical>,
clock: &Clock<Monotonic>, clock: &Clock<Monotonic>,
) -> Result<bool, SwapBuffersError> { ) -> Result<bool, SwapBuffersError> {
let pending_win_count = windows
.iter()
.filter(|win| win.alive())
.filter(|win| win.with_state(|state| !state.loc_request_state.is_idle()))
.count() as u32;
tracing::debug!("pending_win_count is {pending_win_count}");
if pending_win_count > 0 {
for win in windows.iter() {
win.send_frame(output, clock.now(), Some(Duration::ZERO), |_, _| {
Some(output.clone())
});
}
surface
.compositor
.queue_frame(None, None, None)
.map_err(Into::<SwapBuffersError>::into)?;
// TODO: still draw the cursor here
return Ok(true);
}
let output_render_elements = crate::render::generate_render_elements( let output_render_elements = crate::render::generate_render_elements(
space, space,
windows, windows,

View file

@ -262,15 +262,11 @@ pub fn run_winit() -> anyhow::Result<()> {
.flush_clients() .flush_clients()
.expect("failed to flush client buffers"); .expect("failed to flush client buffers");
state.prev_pending_win_count = pending_win_count;
// TODO: still draw the cursor here // TODO: still draw the cursor here
return TimeoutAction::ToDuration(Duration::from_millis(1)); return TimeoutAction::ToDuration(Duration::from_millis(1));
} }
state.prev_pending_win_count = pending_win_count;
let Backend::Winit(backend) = &mut state.backend else { unreachable!() }; let Backend::Winit(backend) = &mut state.backend else { unreachable!() };
let full_redraw = &mut backend.full_redraw; let full_redraw = &mut backend.full_redraw;
*full_redraw = full_redraw.saturating_sub(1); *full_redraw = full_redraw.saturating_sub(1);

View file

@ -138,8 +138,6 @@ pub struct State {
pub xwayland: XWayland, pub xwayland: XWayland,
pub xwm: Option<X11Wm>, pub xwm: Option<X11Wm>,
pub xdisplay: Option<u32>, pub xdisplay: Option<u32>,
pub prev_pending_win_count: u32,
} }
impl State { impl State {
@ -359,8 +357,6 @@ impl State {
xwayland, xwayland,
xwm: None, xwm: None,
xdisplay: None, xdisplay: None,
prev_pending_win_count: 0,
}) })
} }