Owned pixel buffer for no-copy presentation
This is based on the API that will be used for no-copy presentation. But wraps it in `set_buffer`. This also fixes the Wayland buffer code to set `self.width` and `self.height` on resize, and set the length of the shared memory file when the buffer is created. Co-authored-by: jtnunley <jtnunley01@gmail.com>
This commit is contained in:
parent
e5d546ff9e
commit
a09e4cf679
19 changed files with 1176 additions and 438 deletions
|
|
@ -2,6 +2,7 @@ use instant::Instant;
|
|||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use rayon::prelude::*;
|
||||
use std::f64::consts::PI;
|
||||
use std::num::NonZeroU32;
|
||||
use winit::event::{Event, WindowEvent};
|
||||
use winit::event_loop::{ControlFlow, EventLoop};
|
||||
use winit::window::WindowBuilder;
|
||||
|
|
@ -47,8 +48,17 @@ fn main() {
|
|||
frames = pre_render_frames(width as usize, height as usize);
|
||||
};
|
||||
|
||||
let buffer = &frames[((elapsed * 60.0).round() as usize).clamp(0, 59)];
|
||||
surface.set_buffer(buffer.as_slice(), width as u16, height as u16);
|
||||
let frame = &frames[((elapsed * 60.0).round() as usize).clamp(0, 59)];
|
||||
|
||||
surface
|
||||
.resize(
|
||||
NonZeroU32::new(width).unwrap(),
|
||||
NonZeroU32::new(height).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
let mut buffer = surface.buffer_mut().unwrap();
|
||||
buffer.copy_from_slice(frame);
|
||||
buffer.present().unwrap();
|
||||
}
|
||||
Event::MainEventsCleared => {
|
||||
window.request_redraw();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue