summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ren-Pei Zeng <kamesan@google.com> 2024-10-22 15:20:18 +0000
committer Ren-Pei Zeng <kamesan@google.com> 2024-10-22 15:27:08 +0000
commit8237ba6696590098fadfb08295eaa327c0d7c55b (patch)
tree89575b9c8802cb3a53762638ba68d82b98985bec
parent8a482fd1ad8e53e45fd741801813a6eaad640f3d (diff)
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
-rw-r--r--libs/nativewindow/rust/src/lib.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/libs/nativewindow/rust/src/lib.rs b/libs/nativewindow/rust/src/lib.rs
index f19b908074..a1d986ed2b 100644
--- a/libs/nativewindow/rust/src/lib.rs
+++ b/libs/nativewindow/rust/src/lib.rs
@@ -220,7 +220,13 @@ impl HardwareBuffer {
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);