pub struct AHbInner { /* private fields */ }Available on Android only.
Expand description
Android AHardwareBuffer* refcount-destructor wrapper. Drop calls
AHardwareBuffer_release(handle). Constructor expects the caller’s
handle is uniquely refcounted and bumps via AHardwareBuffer_acquire.
Implementations§
Source§impl AHbInner
impl AHbInner
Sourcepub unsafe fn acquire(
handle: *mut AHardwareBuffer,
) -> Result<Self, InvalidHandleError>
pub unsafe fn acquire( handle: *mut AHardwareBuffer, ) -> Result<Self, InvalidHandleError>
Take one new reference to handle via AHardwareBuffer_acquire,
released again by this value’s Drop.
§Safety
handlemust point to a liveAHardwareBuffer— one obtained fromAHardwareBuffer_allocate,AImage_getHardwareBuffer,AHardwareBuffer_fromHardwareBuffer, or an equivalent NDK entry point — and must still be live at the moment of this call: the caller must hold a reference it has not released. The pointer is passed toAHardwareBuffer_acquire, which does not validate it.- Null is not a caller obligation: it is rejected as
InvalidHandleError::NullHandlebefore the acquire, and the handle is thereafter stored as acore::ptr::NonNull. - This takes a new reference and leaves the caller’s alone. A
caller that acquired specifically to hand ownership over must
release its own reference after this returns, or use
Self::from_acquired, which adopts instead of bumping. Doing neither leaks the buffer’s underlying graphics allocation, which on Android is a shared, tightly-budgeted gralloc resource. - The caller must not issue the balancing
AHardwareBuffer_releasefor the reference taken here; exactly one is issued, byDrop. - No thread affinity:
AHardwareBufferrefcounts are atomic and the object is designed for cross-process, cross-thread sharing, so the release may run on any thread.
Sourcepub unsafe fn from_acquired(
handle: *mut AHardwareBuffer,
) -> Result<Self, InvalidHandleError>
pub unsafe fn from_acquired( handle: *mut AHardwareBuffer, ) -> Result<Self, InvalidHandleError>
Adopt one reference the caller already holds on handle. No
AHardwareBuffer_acquire is issued; the balancing
AHardwareBuffer_release still runs in this value’s Drop.
§Safety
handlemust point to a liveAHardwareBufferon which the caller holds a reference that it has not yet released.- That reference is transferred here. The caller must not use
it to keep the buffer alive afterwards, and must never release
it itself — the single balancing release is issued by
Drop, so a caller-side release is a double free that corrupts a refcount shared across processes. - Passing a handle the caller does not own a reference on
(a borrowed
AImage_getHardwareBufferresult, say, whose reference belongs to theAImage) under-counts the buffer:Dropthen releases a reference that was never taken. UseSelf::acquirefor borrowed handles. - Null is not a caller obligation: it is rejected as
InvalidHandleError::NullHandle. - No thread affinity, as for
Self::acquire.
Sourcepub fn as_ptr(&self) -> *mut AHardwareBuffer
pub fn as_ptr(&self) -> *mut AHardwareBuffer
Borrow the raw pointer. Caller must not call AHardwareBuffer_release
on it — the inner struct owns one refcount.
Trait Implementations§
impl Send for AHbInner
impl Sync for AHbInner
Auto Trait Implementations§
impl Freeze for AHbInner
impl RefUnwindSafe for AHbInner
impl Unpin for AHbInner
impl UnsafeUnpin for AHbInner
impl UnwindSafe for AHbInner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more