Merge pull request #99 from mahkoh/jorth/simplify-fb-management
metal: simplify framebuffer swapchain
This commit is contained in:
commit
0d296de53f
3 changed files with 38 additions and 11 deletions
|
|
@ -18,7 +18,7 @@ use {
|
||||||
utils::{
|
utils::{
|
||||||
asyncevent::AsyncEvent, bitflags::BitflagsExt, clonecell::CloneCell,
|
asyncevent::AsyncEvent, bitflags::BitflagsExt, clonecell::CloneCell,
|
||||||
copyhashmap::CopyHashMap, debug_fn::debug_fn, errorfmt::ErrorFmt, numcell::NumCell,
|
copyhashmap::CopyHashMap, debug_fn::debug_fn, errorfmt::ErrorFmt, numcell::NumCell,
|
||||||
oserror::OsError, syncqueue::SyncQueue,
|
opaque_cell::OpaqueCell, oserror::OsError, syncqueue::SyncQueue,
|
||||||
},
|
},
|
||||||
video::{
|
video::{
|
||||||
dmabuf::DmaBufId,
|
dmabuf::DmaBufId,
|
||||||
|
|
@ -39,7 +39,6 @@ use {
|
||||||
jay_config::video::GfxApi,
|
jay_config::video::GfxApi,
|
||||||
std::{
|
std::{
|
||||||
cell::{Cell, RefCell},
|
cell::{Cell, RefCell},
|
||||||
collections::VecDeque,
|
|
||||||
ffi::CString,
|
ffi::CString,
|
||||||
fmt::{Debug, Formatter},
|
fmt::{Debug, Formatter},
|
||||||
mem,
|
mem,
|
||||||
|
|
@ -223,7 +222,8 @@ pub struct MetalConnector {
|
||||||
|
|
||||||
pub drm_feedback: CloneCell<Option<Rc<DrmFeedback>>>,
|
pub drm_feedback: CloneCell<Option<Rc<DrmFeedback>>>,
|
||||||
pub scanout_buffers: RefCell<AHashMap<DmaBufId, DirectScanoutCache>>,
|
pub scanout_buffers: RefCell<AHashMap<DmaBufId, DirectScanoutCache>>,
|
||||||
pub active_framebuffers: RefCell<VecDeque<PresentFb>>,
|
pub active_framebuffer: OpaqueCell<Option<PresentFb>>,
|
||||||
|
pub next_framebuffer: OpaqueCell<Option<PresentFb>>,
|
||||||
pub direct_scanout_active: Cell<bool>,
|
pub direct_scanout_active: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -657,7 +657,7 @@ impl MetalConnector {
|
||||||
dsd.tex.reservations().acquire();
|
dsd.tex.reservations().acquire();
|
||||||
dsd.acquired.set(true);
|
dsd.acquired.set(true);
|
||||||
}
|
}
|
||||||
self.active_framebuffers.borrow_mut().push_back(fb);
|
self.next_framebuffer.set(Some(fb));
|
||||||
}
|
}
|
||||||
self.can_present.set(false);
|
self.can_present.set(false);
|
||||||
self.has_damage.set(false);
|
self.has_damage.set(false);
|
||||||
|
|
@ -869,7 +869,8 @@ fn create_connector(
|
||||||
cursor_swap_buffer: Cell::new(false),
|
cursor_swap_buffer: Cell::new(false),
|
||||||
drm_feedback: Default::default(),
|
drm_feedback: Default::default(),
|
||||||
scanout_buffers: Default::default(),
|
scanout_buffers: Default::default(),
|
||||||
active_framebuffers: Default::default(),
|
active_framebuffer: Default::default(),
|
||||||
|
next_framebuffer: Default::default(),
|
||||||
direct_scanout_active: Cell::new(false),
|
direct_scanout_active: Cell::new(false),
|
||||||
});
|
});
|
||||||
let futures = ConnectorFutures {
|
let futures = ConnectorFutures {
|
||||||
|
|
@ -1557,12 +1558,9 @@ impl MetalBackend {
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
connector.can_present.set(true);
|
connector.can_present.set(true);
|
||||||
{
|
connector
|
||||||
let mut scanout_buffers = connector.active_framebuffers.borrow_mut();
|
.active_framebuffer
|
||||||
while scanout_buffers.len() > 1 {
|
.set(connector.next_framebuffer.take());
|
||||||
scanout_buffers.pop_front();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if connector.has_damage.get() || connector.cursor_changed.get() {
|
if connector.has_damage.get() || connector.cursor_changed.get() {
|
||||||
connector.schedule_present();
|
connector.schedule_present();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ pub mod num_cpus;
|
||||||
pub mod numcell;
|
pub mod numcell;
|
||||||
pub mod once;
|
pub mod once;
|
||||||
pub mod opaque;
|
pub mod opaque;
|
||||||
|
pub mod opaque_cell;
|
||||||
pub mod option_ext;
|
pub mod option_ext;
|
||||||
pub mod oserror;
|
pub mod oserror;
|
||||||
pub mod page_size;
|
pub mod page_size;
|
||||||
|
|
|
||||||
28
src/utils/opaque_cell.rs
Normal file
28
src/utils/opaque_cell.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
use std::{
|
||||||
|
cell::Cell,
|
||||||
|
fmt::{Debug, Formatter},
|
||||||
|
ops::{Deref, DerefMut},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct OpaqueCell<T>(Cell<T>);
|
||||||
|
|
||||||
|
impl<T> Deref for OpaqueCell<T> {
|
||||||
|
type Target = Cell<T>;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> DerefMut for OpaqueCell<T> {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Debug for OpaqueCell<T> {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "Cell<{}> {{ ... }}", std::any::type_name::<T>())
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue