Skip to content

Commit cd6e4e6

Browse files
committed
Add methods to get properties of Buffer.
Bug: 307535208 Test: atest libnativewindow_rs-internal_test Change-Id: Id07eb850ad1db7fbb25ef2a563d1f212ea7145f7
1 parent 3026298 commit cd6e4e6

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

libs/nativewindow/rust/src/surface/buffer.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use super::{ErrorCode, Surface};
16-
use nativewindow_bindgen::ANativeWindow_Buffer;
16+
use nativewindow_bindgen::{AHardwareBuffer_Format, ANativeWindow_Buffer};
1717
use std::ptr::null_mut;
1818

1919
/// An empty `ANativeWindow_Buffer`.
@@ -43,4 +43,26 @@ impl<'a> Buffer<'a> {
4343
pub fn unlock_and_post(self) -> Result<(), ErrorCode> {
4444
self.surface.unlock_and_post()
4545
}
46+
47+
/// The number of pixels that are shown horizontally.
48+
pub fn width(&self) -> i32 {
49+
self.buffer.width
50+
}
51+
52+
/// The number of pixels that are shown vertically.
53+
pub fn height(&self) -> i32 {
54+
self.buffer.height
55+
}
56+
57+
/// The number of pixels that a line in the buffer takes in memory.
58+
///
59+
/// This may be greater than the width.
60+
pub fn stride(&self) -> i32 {
61+
self.buffer.stride
62+
}
63+
64+
/// The pixel format of the buffer.
65+
pub fn format(&self) -> Result<AHardwareBuffer_Format::Type, ErrorCode> {
66+
self.buffer.format.try_into().map_err(|_| ErrorCode(self.buffer.format))
67+
}
4668
}

0 commit comments

Comments
 (0)