1
0
Fork 0
forked from wry/wry

drm: preserve GbmBos while they are in use

This commit is contained in:
Julian Orth 2024-05-08 23:10:22 +02:00
parent 760658522c
commit 110f45fef7
5 changed files with 25 additions and 7 deletions

View file

@ -35,7 +35,7 @@ use {
DrmPropertyType, DrmVersion, PropBlob, DRM_CLIENT_CAP_ATOMIC, DrmPropertyType, DrmVersion, PropBlob, DRM_CLIENT_CAP_ATOMIC,
DRM_MODE_ATOMIC_ALLOW_MODESET, DRM_MODE_ATOMIC_NONBLOCK, DRM_MODE_PAGE_FLIP_EVENT, 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, Modifier, INVALID_MODIFIER,
}, },
}, },
@ -2593,12 +2593,12 @@ impl MetalBackend {
Err(e) => return Err(MetalError::ImportFb(e)), Err(e) => return Err(MetalError::ImportFb(e)),
}; };
dev_fb.clear().map_err(MetalError::Clear)?; 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() { let render_tex = match dev_img.to_texture() {
Ok(fb) => fb, Ok(fb) => fb,
Err(e) => return Err(MetalError::ImportTexture(e)), Err(e) => return Err(MetalError::ImportTexture(e)),
}; };
(None, render_tex, None) (None, render_tex, None, None)
} else { } else {
// Create a _bridge_ BO in the render device // Create a _bridge_ BO in the render device
let render_gfx_formats = render_ctx.gfx.formats(); let render_gfx_formats = render_ctx.gfx.formats();
@ -2657,10 +2657,12 @@ impl MetalBackend {
Err(e) => return Err(MetalError::ImportTexture(e)), 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 { Ok(RenderBuffer {
drm: drm_fb, drm: drm_fb,
_dev_bo: dev_bo,
_render_bo: render_bo,
dev_fb, dev_fb,
dev_tex, dev_tex,
render_tex, render_tex,
@ -2849,6 +2851,8 @@ impl MetalBackend {
#[derive(Debug)] #[derive(Debug)]
pub struct RenderBuffer { pub struct RenderBuffer {
drm: Rc<DrmFramebuffer>, drm: Rc<DrmFramebuffer>,
_dev_bo: GbmBo,
_render_bo: Option<GbmBo>,
// ctx = dev // ctx = dev
// buffer location = dev // buffer location = dev
dev_fb: Rc<dyn GfxFramebuffer>, dev_fb: Rc<dyn GfxFramebuffer>,

View file

@ -19,7 +19,7 @@ use {
}, },
video::{ video::{
drm::{ConnectorType, Drm, DrmError, DrmVersion}, drm::{ConnectorType, Drm, DrmError, DrmVersion},
gbm::{GbmDevice, GbmError, GBM_BO_USE_RENDERING}, gbm::{GbmBo, GbmDevice, GbmError, GBM_BO_USE_RENDERING},
}, },
wire_xcon::{ wire_xcon::{
ChangeProperty, ChangeWindowAttributes, ConfigureNotify, CreateCursor, CreatePixmap, ChangeProperty, ChangeWindowAttributes, ConfigureNotify, CreateCursor, CreatePixmap,
@ -437,6 +437,7 @@ impl XBackend {
}; };
*image = Some(XImage { *image = Some(XImage {
pixmap: Cell::new(pixmap), pixmap: Cell::new(pixmap),
_bo: bo,
fb: CloneCell::new(fb), fb: CloneCell::new(fb),
tex: CloneCell::new(tex), tex: CloneCell::new(tex),
idle: Cell::new(true), idle: Cell::new(true),
@ -1023,6 +1024,7 @@ struct XOutput {
struct XImage { struct XImage {
pixmap: Cell<u32>, pixmap: Cell<u32>,
_bo: GbmBo,
fb: CloneCell<Rc<dyn GfxFramebuffer>>, fb: CloneCell<Rc<dyn GfxFramebuffer>>,
tex: CloneCell<Rc<dyn GfxTexture>>, tex: CloneCell<Rc<dyn GfxTexture>>,
idle: Cell<bool>, idle: Cell<bool>,

View file

@ -17,7 +17,7 @@ use {
}, },
video::{ video::{
dmabuf::DmaBuf, 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, Modifier, INVALID_MODIFIER, LINEAR_MODIFIER,
}, },
wire::{jay_screencast::*, JayScreencastId}, wire::{jay_screencast::*, JayScreencastId},
@ -100,6 +100,7 @@ struct Pending {
} }
struct ScreencastBuffer { struct ScreencastBuffer {
_bo: GbmBo,
dmabuf: DmaBuf, dmabuf: DmaBuf,
fb: Rc<dyn GfxFramebuffer>, fb: Rc<dyn GfxFramebuffer>,
free: bool, free: bool,
@ -403,6 +404,7 @@ impl JayScreencast {
let fb = ctx.clone().dmabuf_img(buffer.dmabuf())?.to_framebuffer()?; let fb = ctx.clone().dmabuf_img(buffer.dmabuf())?.to_framebuffer()?;
buffers.push(ScreencastBuffer { buffers.push(ScreencastBuffer {
dmabuf: buffer.dmabuf().clone(), dmabuf: buffer.dmabuf().clone(),
_bo: buffer,
fb, fb,
free: true, free: true,
}); });

View file

@ -15,7 +15,7 @@ use {
asyncevent::AsyncEvent, clonecell::CloneCell, copyhashmap::CopyHashMap, asyncevent::AsyncEvent, clonecell::CloneCell, copyhashmap::CopyHashMap,
errorfmt::ErrorFmt, rc_eq::rc_eq, errorfmt::ErrorFmt, rc_eq::rc_eq,
}, },
video::gbm::GBM_BO_USE_RENDERING, video::gbm::{GbmBo, GBM_BO_USE_RENDERING},
wire::{ wire::{
wp_fractional_scale_v1::PreferredScale, zwlr_layer_surface_v1::Configure, wp_fractional_scale_v1::PreferredScale, zwlr_layer_surface_v1::Configure,
ZwpLinuxBufferParamsV1Id, ZwpLinuxBufferParamsV1Id,
@ -757,6 +757,7 @@ impl WindowData {
let params = dmabuf.create_params(); let params = dmabuf.create_params();
params.create(bo.dmabuf()); params.create(bo.dmabuf());
let pending = Rc::new(GuiBufferPending { let pending = Rc::new(GuiBufferPending {
bo: Cell::new(Some(bo)),
window: self.clone(), window: self.clone(),
fb, fb,
params, params,
@ -843,11 +844,13 @@ pub struct GuiBuffer {
pub wl: Rc<UsrWlBuffer>, pub wl: Rc<UsrWlBuffer>,
pub window: Rc<WindowData>, pub window: Rc<WindowData>,
pub fb: Rc<dyn GfxFramebuffer>, pub fb: Rc<dyn GfxFramebuffer>,
pub _bo: Option<GbmBo>,
pub free: Cell<bool>, pub free: Cell<bool>,
pub size: (i32, i32), pub size: (i32, i32),
} }
struct GuiBufferPending { struct GuiBufferPending {
pub bo: Cell<Option<GbmBo>>,
pub window: Rc<WindowData>, pub window: Rc<WindowData>,
pub fb: Rc<dyn GfxFramebuffer>, pub fb: Rc<dyn GfxFramebuffer>,
pub params: Rc<UsrLinuxBufferParams>, pub params: Rc<UsrLinuxBufferParams>,
@ -892,6 +895,7 @@ impl UsrLinuxBufferParamsOwner for GuiBufferPending {
wl: buffer, wl: buffer,
window: self.window.clone(), window: self.window.clone(),
fb: self.fb.clone(), fb: self.fb.clone(),
_bo: self.bo.take(),
free: Cell::new(true), free: Cell::new(true),
size: self.size, size: self.size,
}); });

View file

@ -138,6 +138,12 @@ pub struct GbmBo {
dmabuf: DmaBuf, 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 { pub struct GbmBoMap {
bo: Rc<GbmBo>, bo: Rc<GbmBo>,
data: *mut [u8], data: *mut [u8],