Merge pull request #91 from olekolek1000/wayvr_redraw_optim

WayVR: Redraw only if needed
This commit is contained in:
Aleksander
2024-10-26 22:09:14 +02:00
committed by GitHub
3 changed files with 40 additions and 9 deletions

View File

@@ -1,13 +1,15 @@
use smithay::backend::renderer::utils::on_commit_buffer_handler; use smithay::backend::renderer::utils::on_commit_buffer_handler;
use smithay::input::{Seat, SeatHandler, SeatState}; use smithay::input::{Seat, SeatHandler, SeatState};
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
use smithay::reexports::wayland_server;
use smithay::reexports::wayland_server::protocol::{wl_buffer, wl_seat, wl_surface}; use smithay::reexports::wayland_server::protocol::{wl_buffer, wl_seat, wl_surface};
use smithay::reexports::wayland_server::{self, Resource}; use smithay::reexports::wayland_server::Resource;
use smithay::wayland::buffer::BufferHandler; use smithay::wayland::buffer::BufferHandler;
use smithay::wayland::shm::{ShmHandler, ShmState}; use smithay::wayland::shm::{ShmHandler, ShmState};
use smithay::{ use smithay::{
delegate_compositor, delegate_data_device, delegate_seat, delegate_shm, delegate_xdg_shell, delegate_compositor, delegate_data_device, delegate_seat, delegate_shm, delegate_xdg_shell,
}; };
use std::collections::HashSet;
use std::os::fd::OwnedFd; use std::os::fd::OwnedFd;
use smithay::utils::Serial; use smithay::utils::Serial;
@@ -35,8 +37,14 @@ pub struct Application {
pub seat_state: SeatState<Application>, pub seat_state: SeatState<Application>,
pub shm: ShmState, pub shm: ShmState,
pub data_device: DataDeviceState, pub data_device: DataDeviceState,
pub wayvr_tasks: SyncEventQueue<WayVRTask>, pub wayvr_tasks: SyncEventQueue<WayVRTask>,
pub redraw_requests: HashSet<wayland_server::backend::ObjectId>,
}
impl Application {
pub fn check_redraw(&mut self, surface: &WlSurface) -> bool {
self.redraw_requests.remove(&surface.id())
}
} }
impl compositor::CompositorHandler for Application { impl compositor::CompositorHandler for Application {
@@ -53,6 +61,7 @@ impl compositor::CompositorHandler for Application {
fn commit(&mut self, surface: &WlSurface) { fn commit(&mut self, surface: &WlSurface) {
on_commit_buffer_handler::<Self>(surface); on_commit_buffer_handler::<Self>(surface);
self.redraw_requests.insert(surface.id());
} }
} }

View File

@@ -27,10 +27,10 @@ fn generate_auth_key() -> String {
uuid.to_string() uuid.to_string()
} }
struct DisplayWindow { pub struct DisplayWindow {
window_handle: window::WindowHandle, pub window_handle: window::WindowHandle,
pub toplevel: ToplevelSurface,
process_handle: process::ProcessHandle, process_handle: process::ProcessHandle,
toplevel: ToplevelSurface,
} }
pub struct SpawnProcessResult { pub struct SpawnProcessResult {
@@ -49,8 +49,9 @@ pub struct Display {
pub name: String, pub name: String,
pub visible: bool, pub visible: bool,
pub overlay_id: Option<OverlayID>, pub overlay_id: Option<OverlayID>,
pub wants_redraw: bool,
wm: Rc<RefCell<window::WindowManager>>, wm: Rc<RefCell<window::WindowManager>>,
displayed_windows: Vec<DisplayWindow>, pub displayed_windows: Vec<DisplayWindow>,
wayland_env: super::WaylandEnv, wayland_env: super::WaylandEnv,
// Render data stuff // Render data stuff
@@ -108,6 +109,7 @@ impl Display {
height, height,
name: String::from(name), name: String::from(name),
displayed_windows: Vec::new(), displayed_windows: Vec::new(),
wants_redraw: true,
egl_data, egl_data,
dmabuf_data, dmabuf_data,
egl_image, egl_image,

View File

@@ -10,7 +10,7 @@ mod smithay_wrapper;
mod time; mod time;
mod window; mod window;
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, collections::HashSet, rc::Rc};
use comp::Application; use comp::Application;
use display::DisplayVec; use display::DisplayVec;
@@ -94,6 +94,7 @@ impl WayVR {
shm, shm,
data_device, data_device,
wayvr_tasks: tasks.clone(), wayvr_tasks: tasks.clone(),
redraw_requests: HashSet::new(),
}; };
let time_start = get_millis(); let time_start = get_millis();
@@ -118,22 +119,41 @@ impl WayVR {
// millis since the start of wayvr // millis since the start of wayvr
let display = self let display = self
.displays .displays
.get(&display) .get_mut(&display)
.ok_or(anyhow::anyhow!(STR_INVALID_HANDLE_DISP))?; .ok_or(anyhow::anyhow!(STR_INVALID_HANDLE_DISP))?;
let time_ms = get_millis() - self.time_start; if !display.wants_redraw {
// Nothing changed, do not render
return Ok(());
}
if !display.visible { if !display.visible {
// Display is invisible, do not render // Display is invisible, do not render
return Ok(()); return Ok(());
} }
let time_ms = get_millis() - self.time_start;
display.tick_render(&mut self.gles_renderer, time_ms)?; display.tick_render(&mut self.gles_renderer, time_ms)?;
display.wants_redraw = false;
Ok(()) Ok(())
} }
pub fn tick_events(&mut self) -> anyhow::Result<()> { pub fn tick_events(&mut self) -> anyhow::Result<()> {
// Check for redraw events
self.displays.iter_mut(&mut |_, disp| {
for disp_window in &disp.displayed_windows {
if self
.manager
.state
.check_redraw(disp_window.toplevel.wl_surface())
{
disp.wants_redraw = true;
}
}
});
// Tick all child processes // Tick all child processes
let mut to_remove: SmallVec<[(process::ProcessHandle, display::DisplayHandle); 2]> = let mut to_remove: SmallVec<[(process::ProcessHandle, display::DisplayHandle); 2]> =
SmallVec::new(); SmallVec::new();