Merge pull request #91 from olekolek1000/wayvr_redraw_optim
WayVR: Redraw only if needed
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
use smithay::backend::renderer::utils::on_commit_buffer_handler;
|
||||
use smithay::input::{Seat, SeatHandler, SeatState};
|
||||
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::{self, Resource};
|
||||
use smithay::reexports::wayland_server::Resource;
|
||||
use smithay::wayland::buffer::BufferHandler;
|
||||
use smithay::wayland::shm::{ShmHandler, ShmState};
|
||||
use smithay::{
|
||||
delegate_compositor, delegate_data_device, delegate_seat, delegate_shm, delegate_xdg_shell,
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
use std::os::fd::OwnedFd;
|
||||
|
||||
use smithay::utils::Serial;
|
||||
@@ -35,8 +37,14 @@ pub struct Application {
|
||||
pub seat_state: SeatState<Application>,
|
||||
pub shm: ShmState,
|
||||
pub data_device: DataDeviceState,
|
||||
|
||||
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 {
|
||||
@@ -53,6 +61,7 @@ impl compositor::CompositorHandler for Application {
|
||||
|
||||
fn commit(&mut self, surface: &WlSurface) {
|
||||
on_commit_buffer_handler::<Self>(surface);
|
||||
self.redraw_requests.insert(surface.id());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,10 +27,10 @@ fn generate_auth_key() -> String {
|
||||
uuid.to_string()
|
||||
}
|
||||
|
||||
struct DisplayWindow {
|
||||
window_handle: window::WindowHandle,
|
||||
pub struct DisplayWindow {
|
||||
pub window_handle: window::WindowHandle,
|
||||
pub toplevel: ToplevelSurface,
|
||||
process_handle: process::ProcessHandle,
|
||||
toplevel: ToplevelSurface,
|
||||
}
|
||||
|
||||
pub struct SpawnProcessResult {
|
||||
@@ -49,8 +49,9 @@ pub struct Display {
|
||||
pub name: String,
|
||||
pub visible: bool,
|
||||
pub overlay_id: Option<OverlayID>,
|
||||
pub wants_redraw: bool,
|
||||
wm: Rc<RefCell<window::WindowManager>>,
|
||||
displayed_windows: Vec<DisplayWindow>,
|
||||
pub displayed_windows: Vec<DisplayWindow>,
|
||||
wayland_env: super::WaylandEnv,
|
||||
|
||||
// Render data stuff
|
||||
@@ -108,6 +109,7 @@ impl Display {
|
||||
height,
|
||||
name: String::from(name),
|
||||
displayed_windows: Vec::new(),
|
||||
wants_redraw: true,
|
||||
egl_data,
|
||||
dmabuf_data,
|
||||
egl_image,
|
||||
|
||||
@@ -10,7 +10,7 @@ mod smithay_wrapper;
|
||||
mod time;
|
||||
mod window;
|
||||
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use std::{cell::RefCell, collections::HashSet, rc::Rc};
|
||||
|
||||
use comp::Application;
|
||||
use display::DisplayVec;
|
||||
@@ -94,6 +94,7 @@ impl WayVR {
|
||||
shm,
|
||||
data_device,
|
||||
wayvr_tasks: tasks.clone(),
|
||||
redraw_requests: HashSet::new(),
|
||||
};
|
||||
|
||||
let time_start = get_millis();
|
||||
@@ -118,22 +119,41 @@ impl WayVR {
|
||||
// millis since the start of wayvr
|
||||
let display = self
|
||||
.displays
|
||||
.get(&display)
|
||||
.get_mut(&display)
|
||||
.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 {
|
||||
// Display is invisible, do not render
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let time_ms = get_millis() - self.time_start;
|
||||
|
||||
display.tick_render(&mut self.gles_renderer, time_ms)?;
|
||||
display.wants_redraw = false;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
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
|
||||
let mut to_remove: SmallVec<[(process::ProcessHandle, display::DisplayHandle); 2]> =
|
||||
SmallVec::new();
|
||||
|
||||
Reference in New Issue
Block a user