-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ndk: Fix
HardwareBuffer
leak for AndroidBitmap
and clarify handli…
…ng in docs (#296) According to [`AndroidBitmap_getHardwareBuffer`]: outBuffer On success, is set to a pointer to the AHardwareBuffer associated with bitmap. This acquires a reference on the buffer, and the client must call AHardwareBuffer_release when finished with it. By returning the `outBuffer` wrapped in `HardwareBuffer` we represent a weak instead of strong reference, and don't `_release` it on `Drop`. If we instead wrap it in a `HardwareBufferRef` we get the desired `release` semantics on `Drop` and prevent resource leaks for the user. Note that a similar API on [`AImage_getHardwareBuffer`] does **not** aquire a strong reference, and should remain returning a weak `HardwareBuffer`. This feat isn't very well described in the docs, so we now echo what was only stated on `HardwareBufferRef` across the `from_ptr()`/`from_jni()` implementations. Finally, just like `ForeignLooper` and `NativeWindow` this `acquire`+`release` kind of type can implement `Clone` to allow the user to take advantage of internal refcounting instead of having to re-wrap it in `Rc` or `Arc`. [`AndroidBitmap_getHardwareBuffer`]: https://developer.android.com/ndk/reference/group/bitmap#androidbitmap_gethardwarebuffer [`AImage_getHardwareBuffer`]: https://developer.android.com/ndk/reference/group/media#aimage_gethardwarebuffer
- Loading branch information
Showing
4 changed files
with
65 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters