Skip to main content

AHbInner

Struct AHbInner 

Source
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

Source

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
  • handle must point to a live AHardwareBuffer — one obtained from AHardwareBuffer_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 to AHardwareBuffer_acquire, which does not validate it.
  • Null is not a caller obligation: it is rejected as InvalidHandleError::NullHandle before the acquire, and the handle is thereafter stored as a core::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_release for the reference taken here; exactly one is issued, by Drop.
  • No thread affinity: AHardwareBuffer refcounts are atomic and the object is designed for cross-process, cross-thread sharing, so the release may run on any thread.
Source

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
  • handle must point to a live AHardwareBuffer on 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_getHardwareBuffer result, say, whose reference belongs to the AImage) under-counts the buffer: Drop then releases a reference that was never taken. Use Self::acquire for borrowed handles.
  • Null is not a caller obligation: it is rejected as InvalidHandleError::NullHandle.
  • No thread affinity, as for Self::acquire.
Source

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§

Source§

impl Debug for AHbInner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for AHbInner

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for AHbInner

Source§

impl Sync for AHbInner

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSendSync for T
where T: Send + Sync + ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,