Add a Buffer::age() method
Fixes https://github.com/rust-windowing/softbuffer/issues/90.
This commit is contained in:
parent
c1d6716eec
commit
29b3f4a978
8 changed files with 126 additions and 20 deletions
|
|
@ -57,6 +57,7 @@ pub struct OrbitalImpl {
|
|||
handle: OrbitalWindowHandle,
|
||||
width: u32,
|
||||
height: u32,
|
||||
presented: bool,
|
||||
}
|
||||
|
||||
impl OrbitalImpl {
|
||||
|
|
@ -65,12 +66,18 @@ impl OrbitalImpl {
|
|||
handle,
|
||||
width: 0,
|
||||
height: 0,
|
||||
presented: false,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn resize(&mut self, width: NonZeroU32, height: NonZeroU32) -> Result<(), SoftBufferError> {
|
||||
self.width = width.get();
|
||||
self.height = height.get();
|
||||
let width = width.get();
|
||||
let height = height.get();
|
||||
if width != self.width && height != self.height {
|
||||
self.presented = false;
|
||||
self.width = width;
|
||||
self.height = height;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -172,11 +179,19 @@ impl<'a> BufferImpl<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn age(&self) -> u8 {
|
||||
match self.pixels {
|
||||
Pixels::Mapping(_) if self.imp.presented => 1,
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn present(self) -> Result<(), SoftBufferError> {
|
||||
match self.pixels {
|
||||
Pixels::Mapping(mapping) => {
|
||||
drop(mapping);
|
||||
syscall::fsync(self.imp.window_fd()).expect("failed to sync orbital window");
|
||||
self.imp.presented = true;
|
||||
}
|
||||
Pixels::Buffer(buffer) => {
|
||||
self.imp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue