Add HardwareBuffer::as_raw for C FFI boundary
Add method to get raw AHardwareBuffer pointer from Rust HardwareBuffer.
Ownership to the buffer is not transferred to the pointer so the client
can still keep the HardwareBuffer instance.
Bug: 362894809
Test: m libnativewindow_rs
Change-Id: Ic960301a0c2c5b6cf08f55078464da845765d10c
diff --git a/libs/nativewindow/rust/src/lib.rs b/libs/nativewindow/rust/src/lib.rs
index f19b908..a1d986e 100644
--- a/libs/nativewindow/rust/src/lib.rs
+++ b/libs/nativewindow/rust/src/lib.rs
@@ -220,7 +220,13 @@
Self(buffer)
}
- /// Get the internal |AHardwareBuffer| pointer without decrementing the refcount. This can
+ /// Get the internal `AHardwareBuffer` pointer that is only valid when this `HardwareBuffer`
+ /// exists. This can be used to provide a pointer to the AHB for a C/C++ API over the FFI.
+ pub fn as_raw(&self) -> NonNull<AHardwareBuffer> {
+ self.0
+ }
+
+ /// Get the internal `AHardwareBuffer` pointer without decrementing the refcount. This can
/// be used to provide a pointer to the AHB for a C/C++ API over the FFI.
pub fn into_raw(self) -> NonNull<AHardwareBuffer> {
let buffer = ManuallyDrop::new(self);