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

metal: use triple buffering for hardware cursors #128

Merged
merged 1 commit into from
Mar 10, 2024
Merged
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
20 changes: 13 additions & 7 deletions src/backends/metal/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ use {
},
},
ahash::{AHashMap, AHashSet},
arrayvec::ArrayVec,
bstr::{BString, ByteSlice},
indexmap::{indexset, IndexSet},
jay_config::video::GfxApi,
std::{
any::Any,
cell::{Cell, RefCell},
ffi::CString,
fmt::{Debug, Formatter},
Expand Down Expand Up @@ -222,7 +224,7 @@ pub struct MetalConnector {
pub cursor_x: Cell<i32>,
pub cursor_y: Cell<i32>,
pub cursor_enabled: Cell<bool>,
pub cursor_buffers: CloneCell<Option<Rc<[RenderBuffer; 2]>>>,
pub cursor_buffers: CloneCell<Option<Rc<[RenderBuffer; 3]>>>,
pub cursor_front_buffer: NumCell<usize>,
pub cursor_swap_buffer: Cell<bool>,

Expand All @@ -241,7 +243,7 @@ pub struct MetalHardwareCursor {
pub cursor_enabled_pending: Cell<bool>,
pub cursor_x_pending: Cell<i32>,
pub cursor_y_pending: Cell<i32>,
pub cursor_buffers: Rc<[RenderBuffer; 2]>,
pub cursor_buffers: Rc<[RenderBuffer; 3]>,
pub have_changes: Cell<bool>,
}

Expand All @@ -253,7 +255,7 @@ impl HardwareCursor for MetalHardwareCursor {
}

fn get_buffer(&self) -> Rc<dyn GfxFramebuffer> {
let buffer = (self.connector.cursor_front_buffer.get() + 1) % 2;
let buffer = (self.connector.cursor_front_buffer.get() + 1) % self.cursor_buffers.len();
self.cursor_buffers[buffer].render_fb()
}

Expand Down Expand Up @@ -2090,7 +2092,7 @@ impl MetalBackend {
true
}

fn create_scanout_buffers(
fn create_scanout_buffers<const N: usize>(
&self,
dev: &Rc<MetalDrmDevice>,
format: &Format,
Expand All @@ -2099,10 +2101,14 @@ impl MetalBackend {
height: i32,
ctx: &MetalRenderContext,
cursor: bool,
) -> Result<[RenderBuffer; 2], MetalError> {
) -> Result<[RenderBuffer; N], MetalError> {
let create =
|| self.create_scanout_buffer(dev, format, plane_modifiers, width, height, ctx, cursor);
Ok([create()?, create()?])
let mut array = ArrayVec::<_, N>::new();
for _ in 0..N {
array.push(create()?);
}
Ok(array.into_inner().unwrap())
}

fn create_scanout_buffer(
Expand Down Expand Up @@ -2279,7 +2285,7 @@ impl MetalBackend {
connector: &Rc<MetalConnector>,
changes: &mut Change,
ctx: &MetalRenderContext,
old_buffers: &mut Vec<Rc<[RenderBuffer; 2]>>,
old_buffers: &mut Vec<Rc<dyn Any>>,
) -> Result<(), MetalError> {
let dd = connector.display.borrow_mut();
let crtc = match connector.crtc.get() {
Expand Down
Loading