1
0
Fork 0
forked from wry/wry

cursor: merge set_sync_file/swap_buffer

This commit is contained in:
Julian Orth 2026-02-16 13:40:08 +01:00
parent 9ac9fb5623
commit cc56632c68
4 changed files with 12 additions and 21 deletions

View file

@ -183,8 +183,7 @@ pub trait HardwareCursorUpdate {
fn set_enabled(&mut self, enabled: bool); fn set_enabled(&mut self, enabled: bool);
fn get_buffer(&self) -> Rc<dyn GfxFramebuffer>; fn get_buffer(&self) -> Rc<dyn GfxFramebuffer>;
fn set_position(&mut self, x: i32, y: i32); fn set_position(&mut self, x: i32, y: i32);
fn swap_buffer(&mut self); fn swap_buffer(&mut self, sync_file: Option<SyncFile>);
fn set_sync_file(&mut self, sync_file: Option<SyncFile>);
fn size(&self) -> (i32, i32); fn size(&self) -> (i32, i32);
} }

View file

@ -522,24 +522,22 @@ impl MetalConnector {
let buffer_idx = ((connector_drm_state.cursor_fb_idx + 1) % buffers.len() as u64) as usize; let buffer_idx = ((connector_drm_state.cursor_fb_idx + 1) % buffers.len() as u64) as usize;
let mut c = MetalHardwareCursorChange { let mut c = MetalHardwareCursorChange {
cursor_enabled: self.cursor_enabled.get(), cursor_enabled: self.cursor_enabled.get(),
cursor_swap_buffer: false, cursor_swap_buffer: None,
cursor_x: self.cursor_x.get(), cursor_x: self.cursor_x.get(),
cursor_y: self.cursor_y.get(), cursor_y: self.cursor_y.get(),
cursor_buffer: &buffers[buffer_idx], cursor_buffer: &buffers[buffer_idx],
sync_file: None,
cursor_size: (self.dev.cursor_width as _, self.dev.cursor_height as _), cursor_size: (self.dev.cursor_width as _, self.dev.cursor_height as _),
}; };
self.state.present_hardware_cursor(node, &mut c); self.state.present_hardware_cursor(node, &mut c);
if c.cursor_swap_buffer { let swap_buffers = c.cursor_swap_buffer.is_some();
c.sync_file = c.cursor_buffer.copy_to_dev(cd, c.sync_file)?; self.cursor_swap_buffer.set(swap_buffers);
} if let Some(sf) = c.cursor_swap_buffer.take() {
self.cursor_swap_buffer.set(c.cursor_swap_buffer); let sf = c.cursor_buffer.copy_to_dev(cd, sf)?;
if c.sync_file.is_some() { self.cursor_sync_file.set(sf);
self.cursor_sync_file.set(c.sync_file);
} }
let mut cursor_changed = false; let mut cursor_changed = false;
cursor_changed |= self.cursor_enabled.replace(c.cursor_enabled) != c.cursor_enabled; cursor_changed |= self.cursor_enabled.replace(c.cursor_enabled) != c.cursor_enabled;
cursor_changed |= c.cursor_swap_buffer; cursor_changed |= swap_buffers;
cursor_changed |= self.cursor_x.replace(c.cursor_x) != c.cursor_x; cursor_changed |= self.cursor_x.replace(c.cursor_x) != c.cursor_x;
cursor_changed |= self.cursor_y.replace(c.cursor_y) != c.cursor_y; cursor_changed |= self.cursor_y.replace(c.cursor_y) != c.cursor_y;
if cursor_changed { if cursor_changed {

View file

@ -557,12 +557,11 @@ pub struct MetalHardwareCursor {
} }
pub struct MetalHardwareCursorChange<'a> { pub struct MetalHardwareCursorChange<'a> {
pub cursor_swap_buffer: bool, pub cursor_swap_buffer: Option<Option<SyncFile>>,
pub cursor_enabled: bool, pub cursor_enabled: bool,
pub cursor_x: i32, pub cursor_x: i32,
pub cursor_y: i32, pub cursor_y: i32,
pub cursor_buffer: &'a RenderBuffer, pub cursor_buffer: &'a RenderBuffer,
pub sync_file: Option<SyncFile>,
pub cursor_size: (i32, i32), pub cursor_size: (i32, i32),
} }
@ -596,12 +595,8 @@ impl HardwareCursorUpdate for MetalHardwareCursorChange<'_> {
self.cursor_y = y; self.cursor_y = y;
} }
fn swap_buffer(&mut self) { fn swap_buffer(&mut self, sync_file: Option<SyncFile>) {
self.cursor_swap_buffer = true; self.cursor_swap_buffer = Some(sync_file);
}
fn set_sync_file(&mut self, sync_file: Option<SyncFile>) {
self.sync_file = sync_file;
} }
fn size(&self) -> (i32, i32) { fn size(&self) -> (i32, i32) {

View file

@ -515,8 +515,7 @@ impl CursorUser {
); );
match res { match res {
Ok(sync_file) => { Ok(sync_file) => {
hc.set_sync_file(sync_file); hc.swap_buffer(sync_file);
hc.swap_buffer();
} }
Err(e) => { Err(e) => {
log::error!("Could not render hardware cursor: {}", ErrorFmt(e)); log::error!("Could not render hardware cursor: {}", ErrorFmt(e));