Skip to content

Commit d9e349d

Browse files
committed
pixman: Add framebuffer accessor
1 parent 20d2dac commit d9e349d

File tree

1 file changed

+18
-0
lines changed
  • src/backend/renderer/pixman

1 file changed

+18
-0
lines changed

src/backend/renderer/pixman/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,24 @@ impl PixmanFrame<'_, '_> {
349349

350350
Ok(())
351351
}
352+
353+
/// Run custom drawing code on the framebuffer used by this frame.
354+
///
355+
/// You are given mutable access to the underlying [`pixman::Image`].
356+
/// The state of the image is considered an implementation detail, some modifications may have undesired side effects.
357+
///
358+
/// # Safety
359+
///
360+
/// - The image must still referr to the same memory region after `func` was executed.
361+
pub unsafe fn with_framebuffer<R, F>(&mut self, func: F) -> Result<R, PixmanError>
362+
where
363+
F: for<'a> FnOnce(&'a mut Image<'static, 'static>) -> R,
364+
{
365+
match &mut self.target.0 {
366+
PixmanTargetInternal::Dmabuf { ref mut image, .. } => image.accessor()?.with_image(func),
367+
PixmanTargetInternal::Image(ref mut image) => Ok(func(*image)),
368+
}
369+
}
352370
}
353371

354372
impl Frame for PixmanFrame<'_, '_> {

0 commit comments

Comments
 (0)