Skip to content

Commit 29d0e6d

Browse files
Treehugger RobotGerrit Code Review
authored andcommitted
Merge "Add methods to get properties of Buffer." into main
2 parents a26652b + cd6e4e6 commit 29d0e6d

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)