shm: Release buffer as soon as possible
This commit is contained in:
parent
c41cc9828f
commit
55b4d4b89a
|
@ -24,13 +24,15 @@ use smithay::{
|
||||||
use crate::shell::{MyCompositorToken, MyWindowMap, SurfaceData};
|
use crate::shell::{MyCompositorToken, MyWindowMap, SurfaceData};
|
||||||
|
|
||||||
struct BufferTextures<T> {
|
struct BufferTextures<T> {
|
||||||
buffer: wl_buffer::WlBuffer,
|
buffer: Option<wl_buffer::WlBuffer>,
|
||||||
texture: T,
|
texture: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Drop for BufferTextures<T> {
|
impl<T> Drop for BufferTextures<T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.buffer.release();
|
if let Some(buffer) = self.buffer.take() {
|
||||||
|
buffer.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +88,12 @@ where
|
||||||
if let Some(buffer) = data.current_state.buffer.take() {
|
if let Some(buffer) = data.current_state.buffer.take() {
|
||||||
match renderer.import_buffer(&buffer, Some(&attributes), egl_buffer_reader) {
|
match renderer.import_buffer(&buffer, Some(&attributes), egl_buffer_reader) {
|
||||||
Ok(m) => {
|
Ok(m) => {
|
||||||
|
let buffer = if smithay::wayland::shm::with_buffer_contents(&buffer, |_,_| ()).is_ok() {
|
||||||
|
buffer.release();
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(buffer)
|
||||||
|
};
|
||||||
data.texture = Some(Box::new(BufferTextures { buffer, texture: m })
|
data.texture = Some(Box::new(BufferTextures { buffer, texture: m })
|
||||||
as Box<dyn std::any::Any + 'static>)
|
as Box<dyn std::any::Any + 'static>)
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,13 +94,6 @@ pub fn run_winit(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send frame events so that client start drawing their next frame
|
|
||||||
state
|
|
||||||
.window_map
|
|
||||||
.borrow()
|
|
||||||
.send_frames(start_time.elapsed().as_millis() as u32);
|
|
||||||
display.borrow_mut().flush_clients(&mut state);
|
|
||||||
|
|
||||||
// drawing logic
|
// drawing logic
|
||||||
{
|
{
|
||||||
let mut renderer = renderer.borrow_mut();
|
let mut renderer = renderer.borrow_mut();
|
||||||
|
@ -174,6 +167,13 @@ pub fn run_winit(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send frame events so that client start drawing their next frame
|
||||||
|
state
|
||||||
|
.window_map
|
||||||
|
.borrow()
|
||||||
|
.send_frames(start_time.elapsed().as_millis() as u32);
|
||||||
|
display.borrow_mut().flush_clients(&mut state);
|
||||||
|
|
||||||
if event_loop
|
if event_loop
|
||||||
.dispatch(Some(Duration::from_millis(16)), &mut state)
|
.dispatch(Some(Duration::from_millis(16)), &mut state)
|
||||||
.is_err()
|
.is_err()
|
||||||
|
|
Loading…
Reference in New Issue