Skip to content

Truly independent web browser

LibGfx: Let Rust take over a decoded image frame from C++

Andreas Kling0b6fb1797010
diff --git a/Libraries/LibGfx/Rust/src/image_frame.rs b/Libraries/LibGfx/Rust/src/image_frame.rs
index 20e15fb2be7..0bcd999af76 100644
--- a/Libraries/LibGfx/Rust/src/image_frame.rs
+++ b/Libraries/LibGfx/Rust/src/image_frame.rs
@@ -59,6 +59,20 @@ impl ImageFrameHandle {
Self(Arc::new(ImageFrameEntry { snapshot, raw }))
}
+ /// Takes over a frame that C++ allocated with `new` to hand it over, as when it decodes one for Rust.
+ ///
+ /// # Safety
+ ///
+ /// `frame` must point to a live `Gfx::DecodedImageFrame` that C++ allocated with `new`, which nothing uses after
+ /// this.
+ pub unsafe fn adopt(frame: *mut c_void) -> Self {
+ // SAFETY: The caller passes a live frame.
+ let handle = unsafe { Self::retain(frame) };
+ // SAFETY: The caller hands the frame over, and the handle holds a copy of it.
+ unsafe { ladybird_gfx_decoded_image_frame_release(frame) };
+ handle
+ }
+
#[inline]
pub fn id(&self) -> u64 {
self.0.snapshot.id