Skip to content

Commit 3569284

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

File tree

1 file changed

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

1 file changed

+17
-0
lines changed

src/backend/renderer/pixman/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,23 @@ 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+
/// - The image must still referr to the same memory region after `func` was executed.
360+
pub unsafe fn with_framebuffer<R, F>(&mut self, func: F) -> Result<R, PixmanError>
361+
where
362+
F: for<'a> FnOnce(&'a mut Image<'static, 'static>) -> R,
363+
{
364+
match &mut self.target.0 {
365+
PixmanTargetInternal::Dmabuf { ref mut image, .. } => image.accessor()?.with_image(func),
366+
PixmanTargetInternal::Image(ref mut image) => Ok(func(*image)),
367+
}
368+
}
352369
}
353370

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

0 commit comments

Comments
 (0)