@@ -99,7 +99,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for Android
9999 ) ) ;
100100 }
101101
102- let buffer = vec ! [ 0 ; native_window_buffer. width ( ) * native_window_buffer. height( ) ] ;
102+ let buffer = vec ! [ 0 ; native_window_buffer. stride ( ) * native_window_buffer. height( ) ] ;
103103
104104 Ok ( BufferImpl {
105105 native_window_buffer,
@@ -124,7 +124,7 @@ unsafe impl Send for BufferImpl<'_> {}
124124
125125impl BufferInterface for BufferImpl < ' _ > {
126126 fn byte_stride ( & self ) -> NonZeroU32 {
127- NonZeroU32 :: new ( self . width ( ) . get ( ) * 4 ) . unwrap ( )
127+ NonZeroU32 :: new ( self . native_window_buffer . stride ( ) as u32 * 4 ) . unwrap ( )
128128 }
129129
130130 fn width ( & self ) -> NonZeroU32 {
@@ -147,26 +147,18 @@ impl BufferInterface for BufferImpl<'_> {
147147
148148 // TODO: This function is pretty slow this way
149149 fn present ( mut self ) -> Result < ( ) , SoftBufferError > {
150- let input_lines = self . buffer . chunks ( self . native_window_buffer . width ( ) ) ;
151- for ( output, input) in self
152- . native_window_buffer
153- . lines ( )
154- // Unreachable as we checked before that this is a valid, mappable format
155- . unwrap ( )
156- . zip ( input_lines)
157- {
158- // .lines() removed the stride
159- assert_eq ! ( output. len( ) , input. len( ) * 4 ) ;
160-
161- for ( i, pixel) in input. iter ( ) . enumerate ( ) {
162- // Swizzle colors from BGR(A) to RGB(A)
163- let [ b, g, r, a] = pixel. to_le_bytes ( ) ;
164- output[ i * 4 ] . write ( r) ;
165- output[ i * 4 + 1 ] . write ( g) ;
166- output[ i * 4 + 2 ] . write ( b) ;
167- output[ i * 4 + 3 ] . write ( a) ;
168- }
150+ // Unreachable as we checked before that this is a valid, mappable format
151+ let native_buffer = self . native_window_buffer . bytes ( ) . unwrap ( ) ;
152+
153+ for ( pixel, output) in self . buffer . iter ( ) . zip ( native_buffer. chunks_mut ( 4 ) ) {
154+ // Swizzle colors from BGR(A) to RGB(A)
155+ let [ b, g, r, a] = pixel. to_le_bytes ( ) ;
156+ output[ 0 ] . write ( r) ;
157+ output[ 1 ] . write ( g) ;
158+ output[ 2 ] . write ( b) ;
159+ output[ 3 ] . write ( a) ;
169160 }
161+
170162 Ok ( ( ) )
171163 }
172164
0 commit comments