diff options
author | 2024-10-15 10:05:22 +0000 | |
---|---|---|
committer | 2024-10-15 10:05:22 +0000 | |
commit | dc6117a4b21b8c6450f531369967d20d91f4137c (patch) | |
tree | d73c489e3204e4b78b5bf397c9cf5d31a2053268 | |
parent | 16117cd8183bf466b8ec348d38e1c5caa062d701 (diff) | |
parent | b739439f651285cd48841cc98e6cec3d5e885737 (diff) |
Merge "Add methods to get properties of Buffer." into main am: 29d0e6dd36 am: b739439f65
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/3285578
Change-Id: Icb44fe7258a5db13f4ec52687ab96bcef45b3815
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | libs/nativewindow/rust/src/surface/buffer.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/libs/nativewindow/rust/src/surface/buffer.rs b/libs/nativewindow/rust/src/surface/buffer.rs index 91f5de5343..a2d74d4ed6 100644 --- a/libs/nativewindow/rust/src/surface/buffer.rs +++ b/libs/nativewindow/rust/src/surface/buffer.rs @@ -13,7 +13,7 @@ // limitations under the License. use super::{ErrorCode, Surface}; -use nativewindow_bindgen::ANativeWindow_Buffer; +use nativewindow_bindgen::{AHardwareBuffer_Format, ANativeWindow_Buffer}; use std::ptr::null_mut; /// An empty `ANativeWindow_Buffer`. @@ -43,4 +43,26 @@ impl<'a> Buffer<'a> { pub fn unlock_and_post(self) -> Result<(), ErrorCode> { self.surface.unlock_and_post() } + + /// The number of pixels that are shown horizontally. + pub fn width(&self) -> i32 { + self.buffer.width + } + + /// The number of pixels that are shown vertically. + pub fn height(&self) -> i32 { + self.buffer.height + } + + /// The number of pixels that a line in the buffer takes in memory. + /// + /// This may be greater than the width. + pub fn stride(&self) -> i32 { + self.buffer.stride + } + + /// The pixel format of the buffer. + pub fn format(&self) -> Result<AHardwareBuffer_Format::Type, ErrorCode> { + self.buffer.format.try_into().map_err(|_| ErrorCode(self.buffer.format)) + } } |