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
|
|
@ -1,3 +1,4 @@
|
|||
use std::num::NonZeroU32;
|
||||
use winit::event::{Event, WindowEvent};
|
||||
use winit::event_loop::{ControlFlow, EventLoop};
|
||||
use winit::window::WindowBuilder;
|
||||
|
|
@ -31,21 +32,25 @@ fn main() {
|
|||
|
||||
match event {
|
||||
Event::RedrawRequested(window_id) if window_id == window.id() => {
|
||||
let buffer = (0..(BUFFER_WIDTH * BUFFER_HEIGHT))
|
||||
.map(|index| {
|
||||
let y = index / BUFFER_WIDTH;
|
||||
let x = index % BUFFER_WIDTH;
|
||||
let red = x % 255;
|
||||
let green = y % 255;
|
||||
let blue = (x * y) % 255;
|
||||
surface
|
||||
.resize(
|
||||
NonZeroU32::new(BUFFER_WIDTH as u32).unwrap(),
|
||||
NonZeroU32::new(BUFFER_HEIGHT as u32).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut buffer = surface.buffer_mut().unwrap();
|
||||
for y in 0..BUFFER_HEIGHT {
|
||||
for x in 0..BUFFER_WIDTH {
|
||||
let red = x as u32 % 255;
|
||||
let green = y as u32 % 255;
|
||||
let blue = (x as u32 * y as u32) % 255;
|
||||
|
||||
let color = blue | (green << 8) | (red << 16);
|
||||
|
||||
color as u32
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
surface.set_buffer(&buffer, BUFFER_WIDTH as u16, BUFFER_HEIGHT as u16);
|
||||
buffer[y * BUFFER_WIDTH + x] = color;
|
||||
}
|
||||
}
|
||||
buffer.present().unwrap();
|
||||
}
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue