wvr_server: release dma buffer after next buffer is loaded

This commit is contained in:
galister 2026-07-04 05:36:06 +09:00
parent 8fa29c0e28
commit 0cea27c066
2 changed files with 22 additions and 14 deletions

View File

@ -145,15 +145,11 @@ impl compositor::CompositorHandler for Application {
match buffer_type(&buffer) {
Some(BufferType::Dma) => {
let dmabuf = get_dmabuf(&buffer).unwrap(); // always Ok due to buffer_type
if let Ok(image) = self
.image_importer
.get_or_import_dmabuf(dmabuf.clone())
.inspect_err(|e| {
log::warn!("wayland_server failed to import DMA-buf: {e:?}");
})
if let Ok(image) =
self.image_importer.get_or_import_dmabuf(dmabuf.clone())
{
let sbwi = SurfaceBufWithImage {
buffer: Some(buffer.clone()),
image,
transform: wl_transform_to_frame_transform(
attrs.buffer_transform,
@ -161,7 +157,14 @@ impl compositor::CompositorHandler for Application {
scale: attrs.buffer_scale,
dmabuf: true,
};
sbwi.apply_to_surface(states);
if let Some(old_buffer) =
sbwi.apply_to_surface(states, Some(buffer.clone()))
{
old_buffer.release();
}
} else {
buffer.release();
}
}
Some(BufferType::Shm) => {
@ -174,7 +177,6 @@ impl compositor::CompositorHandler for Application {
})
{
let sbwi = SurfaceBufWithImage {
buffer: None,
image,
transform: wl_transform_to_frame_transform(
attrs.buffer_transform,
@ -182,7 +184,7 @@ impl compositor::CompositorHandler for Application {
scale: attrs.buffer_scale,
dmabuf: false,
};
sbwi.apply_to_surface(states);
sbwi.apply_to_surface(states, None);
}
});
buffer.release();
@ -195,7 +197,6 @@ impl compositor::CompositorHandler for Application {
})
{
let sbwi = SurfaceBufWithImage {
buffer: None,
image,
transform: wl_transform_to_frame_transform(
// does this even matter
@ -204,7 +205,7 @@ impl compositor::CompositorHandler for Application {
scale: attrs.buffer_scale,
dmabuf: false,
};
sbwi.apply_to_surface(states);
sbwi.apply_to_surface(states, None);
}
buffer.release();
}

View File

@ -716,12 +716,12 @@ fn generate_auth_key() -> String {
struct SurfaceBufWithImageContainer {
inner: RefCell<SurfaceBufWithImage>,
retained_dmabuf_buffer: RefCell<Option<wl_buffer::WlBuffer>>,
}
#[derive(Clone)]
#[allow(dead_code)]
pub struct SurfaceBufWithImage {
pub buffer: Option<wl_buffer::WlBuffer>,
pub image: Arc<ImageView>,
pub transform: Transform,
pub scale: i32,
@ -729,15 +729,22 @@ pub struct SurfaceBufWithImage {
}
impl SurfaceBufWithImage {
fn apply_to_surface(self, surface_data: &SurfaceData) {
fn apply_to_surface(
self,
surface_data: &SurfaceData,
retained_buffer: Option<wl_buffer::WlBuffer>,
) -> Option<wl_buffer::WlBuffer> {
if let Some(container) = surface_data.data_map.get::<SurfaceBufWithImageContainer>() {
container.inner.replace(self);
container.retained_dmabuf_buffer.replace(retained_buffer)
} else {
surface_data
.data_map
.insert_if_missing(|| SurfaceBufWithImageContainer {
inner: RefCell::new(self),
retained_dmabuf_buffer: RefCell::new(retained_buffer),
});
None
}
}