Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drm: preserve GbmBos while they are in use #198

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/backends/metal/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -2849,6 +2851,8 @@ impl MetalBackend {
#[derive(Debug)]
pub struct RenderBuffer {
drm: Rc<DrmFramebuffer>,
_dev_bo: GbmBo,
_render_bo: Option<GbmBo>,
// ctx = dev
// buffer location = dev
dev_fb: Rc<dyn GfxFramebuffer>,
Expand Down
4 changes: 3 additions & 1 deletion src/backends/x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -1023,6 +1024,7 @@ struct XOutput {

struct XImage {
pixmap: Cell<u32>,
_bo: GbmBo,
fb: CloneCell<Rc<dyn GfxFramebuffer>>,
tex: CloneCell<Rc<dyn GfxTexture>>,
idle: Cell<bool>,
Expand Down
4 changes: 3 additions & 1 deletion src/ifs/jay_screencast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -100,6 +100,7 @@ struct Pending {
}

struct ScreencastBuffer {
_bo: GbmBo,
dmabuf: DmaBuf,
fb: Rc<dyn GfxFramebuffer>,
free: bool,
Expand Down Expand Up @@ -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,
});
Expand Down
6 changes: 5 additions & 1 deletion src/portal/ptr_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -843,11 +844,13 @@ pub struct GuiBuffer {
pub wl: Rc<UsrWlBuffer>,
pub window: Rc<WindowData>,
pub fb: Rc<dyn GfxFramebuffer>,
pub _bo: Option<GbmBo>,
pub free: Cell<bool>,
pub size: (i32, i32),
}

struct GuiBufferPending {
pub bo: Cell<Option<GbmBo>>,
pub window: Rc<WindowData>,
pub fb: Rc<dyn GfxFramebuffer>,
pub params: Rc<UsrLinuxBufferParams>,
Expand Down Expand Up @@ -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,
});
Expand Down
6 changes: 6 additions & 0 deletions src/video/gbm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GbmBo>,
data: *mut [u8],
Expand Down
Loading