pub struct AHardwareBufferHandle { /* private fields */ }Available on Android only.
Expand description
AHardwareBuffer* with refcount-anchored lifetime via AHbInner.
Implementations§
Source§impl AHardwareBufferHandle
impl AHardwareBufferHandle
Sourcepub unsafe fn acquire(
handle: *mut AHardwareBuffer,
) -> Result<Self, InvalidHandleError>
pub unsafe fn acquire( handle: *mut AHardwareBuffer, ) -> Result<Self, InvalidHandleError>
Wrap an AHardwareBuffer*, taking one new reference via
AHardwareBuffer_acquire. Refcount-owning: the reference taken
here is released on the last Clone’s drop.
§Safety
handlemust point to a liveAHardwareBufferon which the caller currently holds a reference. Use this for borrowed handles — anAImage_getHardwareBufferresult, aMediaCodecoutput buffer, a gralloc handle owned by someone else — where the reference stays with its original owner.- Ownership is shared, not transferred. The
+1taken here is released by the lastArc<AHbInner>drop; the caller’s reference is untouched and remains the caller’s to release.Clonebumps only theArc, never gralloc. - The caller must not issue the balancing
AHardwareBuffer_releasefor the reference taken here. - Null is rejected as
InvalidHandleError::NullHandle, so it is not a caller obligation. - No thread affinity —
AHardwareBufferrefcounts are atomic and the buffer is meant for cross-process sharing. Concurrent access to the pixels still needs the usual fence orAHardwareBuffer_lockdiscipline, which this type does not provide.
Sourcepub unsafe fn from_acquired(
handle: *mut AHardwareBuffer,
) -> Result<Self, InvalidHandleError>
pub unsafe fn from_acquired( handle: *mut AHardwareBuffer, ) -> Result<Self, InvalidHandleError>
Wrap an AHardwareBuffer* by adopting a reference the caller
already holds. No AHardwareBuffer_acquire is issued.
Refcount-owning: the adopted reference is released on the last
Clone’s drop.
§Safety
handlemust point to a liveAHardwareBufferon which the caller holds a reference it has not yet released — one it took itself viaAHardwareBuffer_allocate,AHardwareBuffer_acquire, or arecvBuffer/fromHardwareBuffercall that returned an owned reference.- That reference is transferred here. The caller must never
release it: the single balancing
AHardwareBuffer_releaseis issued by the lastArc<AHbInner>drop, so a caller-side release is a double-free of a refcount shared across processes. - Conversely, passing a borrowed handle under-counts the
buffer —
Dropwill release a reference that was never taken, freeing it out from under its real owner. UseSelf::acquirefor borrowed handles. - Null is rejected as
InvalidHandleError::NullHandle, so it is not a caller obligation. - No thread affinity, as for
Self::acquire.
pub fn as_ptr(&self) -> *mut AHardwareBuffer
pub fn inner(&self) -> &Arc<AHbInner> ⓘ
Trait Implementations§
Source§impl Clone for AHardwareBufferHandle
impl Clone for AHardwareBufferHandle
Auto Trait Implementations§
impl Freeze for AHardwareBufferHandle
impl RefUnwindSafe for AHardwareBufferHandle
impl Send for AHardwareBufferHandle
impl Sync for AHardwareBufferHandle
impl Unpin for AHardwareBufferHandle
impl UnsafeUnpin for AHardwareBufferHandle
impl UnwindSafe for AHardwareBufferHandle
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