From 38b66acba1688ef360e3e31dd2fb7a7c92e04589 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 19 Aug 2025 18:29:42 +0200 Subject: [PATCH] pixman: Add framebuffer accessor --- src/backend/renderer/pixman/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/backend/renderer/pixman/mod.rs b/src/backend/renderer/pixman/mod.rs index 9a6ea5ffd12d..232c0ae64ad1 100644 --- a/src/backend/renderer/pixman/mod.rs +++ b/src/backend/renderer/pixman/mod.rs @@ -349,6 +349,24 @@ impl PixmanFrame<'_, '_> { Ok(()) } + + /// Run custom drawing code on the framebuffer used by this frame. + /// + /// You are given mutable access to the underlying [`pixman::Image`]. + /// The state of the image is considered an implementation detail, some modifications may have undesired side effects. + /// + /// # Safety + /// + /// - The image must still referr to the same memory region after `func` was executed. + pub unsafe fn with_framebuffer(&mut self, func: F) -> Result + where + F: for<'a> FnOnce(&'a mut Image<'static, 'static>) -> R, + { + match &mut self.target.0 { + PixmanTargetInternal::Dmabuf { ref mut image, .. } => image.accessor()?.with_image(func), + PixmanTargetInternal::Image(ref mut image) => Ok(func(image)), + } + } } impl Frame for PixmanFrame<'_, '_> {