diff --git a/src/backends/metal/video.rs b/src/backends/metal/video.rs index 4e229d1d..c0752eee 100644 --- a/src/backends/metal/video.rs +++ b/src/backends/metal/video.rs @@ -35,7 +35,7 @@ use { DrmPropertyType, DrmVersion, PropBlob, DRM_CLIENT_CAP_ATOMIC, DRM_MODE_ATOMIC_ALLOW_MODESET, DRM_MODE_ATOMIC_NONBLOCK, DRM_MODE_PAGE_FLIP_EVENT, }, - gbm::{GbmDevice, GBM_BO_USE_LINEAR, GBM_BO_USE_RENDERING, GBM_BO_USE_SCANOUT}, + gbm::{GbmBo, GbmDevice, GBM_BO_USE_LINEAR, GBM_BO_USE_RENDERING, GBM_BO_USE_SCANOUT}, Modifier, INVALID_MODIFIER, }, }, @@ -2593,12 +2593,12 @@ impl MetalBackend { Err(e) => return Err(MetalError::ImportFb(e)), }; dev_fb.clear().map_err(MetalError::Clear)?; - let (dev_tex, render_tex, render_fb) = if dev.id == render_ctx.dev_id { + let (dev_tex, render_tex, render_fb, render_bo) = if dev.id == render_ctx.dev_id { let render_tex = match dev_img.to_texture() { Ok(fb) => fb, Err(e) => return Err(MetalError::ImportTexture(e)), }; - (None, render_tex, None) + (None, render_tex, None, None) } else { // Create a _bridge_ BO in the render device let render_gfx_formats = render_ctx.gfx.formats(); @@ -2657,10 +2657,12 @@ impl MetalBackend { Err(e) => return Err(MetalError::ImportTexture(e)), }; - (Some(dev_tex), render_tex, Some(render_fb)) + (Some(dev_tex), render_tex, Some(render_fb), Some(render_bo)) }; Ok(RenderBuffer { drm: drm_fb, + _dev_bo: dev_bo, + _render_bo: render_bo, dev_fb, dev_tex, render_tex, @@ -2849,6 +2851,8 @@ impl MetalBackend { #[derive(Debug)] pub struct RenderBuffer { drm: Rc, + _dev_bo: GbmBo, + _render_bo: Option, // ctx = dev // buffer location = dev dev_fb: Rc, diff --git a/src/backends/x.rs b/src/backends/x.rs index 3b8ed707..4c34f267 100644 --- a/src/backends/x.rs +++ b/src/backends/x.rs @@ -19,7 +19,7 @@ use { }, video::{ drm::{ConnectorType, Drm, DrmError, DrmVersion}, - gbm::{GbmDevice, GbmError, GBM_BO_USE_RENDERING}, + gbm::{GbmBo, GbmDevice, GbmError, GBM_BO_USE_RENDERING}, }, wire_xcon::{ ChangeProperty, ChangeWindowAttributes, ConfigureNotify, CreateCursor, CreatePixmap, @@ -437,6 +437,7 @@ impl XBackend { }; *image = Some(XImage { pixmap: Cell::new(pixmap), + _bo: bo, fb: CloneCell::new(fb), tex: CloneCell::new(tex), idle: Cell::new(true), @@ -1023,6 +1024,7 @@ struct XOutput { struct XImage { pixmap: Cell, + _bo: GbmBo, fb: CloneCell>, tex: CloneCell>, idle: Cell, diff --git a/src/ifs/jay_screencast.rs b/src/ifs/jay_screencast.rs index e5308f4b..344a1b06 100644 --- a/src/ifs/jay_screencast.rs +++ b/src/ifs/jay_screencast.rs @@ -17,7 +17,7 @@ use { }, video::{ dmabuf::DmaBuf, - gbm::{GbmError, GBM_BO_USE_LINEAR, GBM_BO_USE_RENDERING}, + gbm::{GbmBo, GbmError, GBM_BO_USE_LINEAR, GBM_BO_USE_RENDERING}, Modifier, INVALID_MODIFIER, LINEAR_MODIFIER, }, wire::{jay_screencast::*, JayScreencastId}, @@ -100,6 +100,7 @@ struct Pending { } struct ScreencastBuffer { + _bo: GbmBo, dmabuf: DmaBuf, fb: Rc, free: bool, @@ -403,6 +404,7 @@ impl JayScreencast { let fb = ctx.clone().dmabuf_img(buffer.dmabuf())?.to_framebuffer()?; buffers.push(ScreencastBuffer { dmabuf: buffer.dmabuf().clone(), + _bo: buffer, fb, free: true, }); diff --git a/src/portal/ptr_gui.rs b/src/portal/ptr_gui.rs index 3020d219..c3e54e12 100644 --- a/src/portal/ptr_gui.rs +++ b/src/portal/ptr_gui.rs @@ -15,7 +15,7 @@ use { asyncevent::AsyncEvent, clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, rc_eq::rc_eq, }, - video::gbm::GBM_BO_USE_RENDERING, + video::gbm::{GbmBo, GBM_BO_USE_RENDERING}, wire::{ wp_fractional_scale_v1::PreferredScale, zwlr_layer_surface_v1::Configure, ZwpLinuxBufferParamsV1Id, @@ -757,6 +757,7 @@ impl WindowData { let params = dmabuf.create_params(); params.create(bo.dmabuf()); let pending = Rc::new(GuiBufferPending { + bo: Cell::new(Some(bo)), window: self.clone(), fb, params, @@ -843,11 +844,13 @@ pub struct GuiBuffer { pub wl: Rc, pub window: Rc, pub fb: Rc, + pub _bo: Option, pub free: Cell, pub size: (i32, i32), } struct GuiBufferPending { + pub bo: Cell>, pub window: Rc, pub fb: Rc, pub params: Rc, @@ -892,6 +895,7 @@ impl UsrLinuxBufferParamsOwner for GuiBufferPending { wl: buffer, window: self.window.clone(), fb: self.fb.clone(), + _bo: self.bo.take(), free: Cell::new(true), size: self.size, }); diff --git a/src/video/gbm.rs b/src/video/gbm.rs index 3338e2fb..4eb888b8 100644 --- a/src/video/gbm.rs +++ b/src/video/gbm.rs @@ -138,6 +138,12 @@ pub struct GbmBo { dmabuf: DmaBuf, } +impl Debug for GbmBo { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GbmBo").finish_non_exhaustive() + } +} + pub struct GbmBoMap { bo: Rc, data: *mut [u8],