@@ -107,6 +107,9 @@ pub(crate) struct BufferImpl<'a, D: ?Sized, W: ?Sized> {
107
107
/// The current size.
108
108
size : ( NonZeroU32 , NonZeroU32 ) ,
109
109
110
+ /// The current stride/pitch (length of a single row of pixels) in bytes.
111
+ stride : NonZeroU32 ,
112
+
110
113
/// The display implementation.
111
114
display : & ' a KmsDisplayImpl < D > ,
112
115
@@ -244,6 +247,7 @@ impl<D: ?Sized, W: HasWindowHandle> KmsImpl<D, W> {
244
247
. expect ( "Must set size of surface before calling `buffer_mut()`" ) ;
245
248
246
249
let size = set. size ( ) ;
250
+ let stride = set. pitch ( ) ;
247
251
248
252
let [ first_buffer, second_buffer] = & mut set. buffers ;
249
253
let ( front_buffer, back_buffer) = if set. first_is_front {
@@ -264,6 +268,7 @@ impl<D: ?Sized, W: HasWindowHandle> KmsImpl<D, W> {
264
268
Ok ( BufferImpl {
265
269
mapping,
266
270
size,
271
+ stride,
267
272
first_is_front : & mut set. first_is_front ,
268
273
front_fb,
269
274
crtc_handle : self . crtc . handle ( ) ,
@@ -304,6 +309,12 @@ impl<D: ?Sized, W: ?Sized> BufferImpl<'_, D, W> {
304
309
bytemuck:: cast_slice_mut ( self . mapping . as_mut ( ) )
305
310
}
306
311
312
+ #[ inline]
313
+ pub fn stride ( & self ) -> u32 {
314
+ // TODO Return NonZeroU32?
315
+ self . stride . get ( )
316
+ }
317
+
307
318
#[ inline]
308
319
pub fn age ( & self ) -> u8 {
309
320
* self . front_age
@@ -403,11 +414,20 @@ impl SharedBuffer {
403
414
. and_then ( |width| NonZeroU32 :: new ( height) . map ( |height| ( width, height) ) )
404
415
. expect ( "buffer size is zero" )
405
416
}
417
+
418
+ pub ( crate ) fn pitch ( & self ) -> NonZeroU32 {
419
+ NonZeroU32 :: new ( self . db . pitch ( ) ) . expect ( "Pitch (stride in bytes) is zero" )
420
+ }
406
421
}
407
422
408
423
impl Buffers {
409
424
/// Get the size of this buffer.
410
425
pub ( crate ) fn size ( & self ) -> ( NonZeroU32 , NonZeroU32 ) {
411
426
self . buffers [ 0 ] . size ( )
412
427
}
428
+
429
+ /// Get the pitch (stride) of this buffer.
430
+ pub ( crate ) fn pitch ( & self ) -> NonZeroU32 {
431
+ self . buffers [ 0 ] . pitch ( )
432
+ }
413
433
}
0 commit comments