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
29
README.md
29
README.md
|
|
@ -58,6 +58,7 @@ To run an example with the web backend: `cargo run-wasm --example winit`
|
|||
Example
|
||||
==
|
||||
```rust,no_run
|
||||
use std::num::NonZeroU32;
|
||||
use winit::event::{Event, WindowEvent};
|
||||
use winit::event_loop::{ControlFlow, EventLoop};
|
||||
use winit::window::WindowBuilder;
|
||||
|
|
@ -77,21 +78,25 @@ fn main() {
|
|||
let size = window.inner_size();
|
||||
(size.width, size.height)
|
||||
};
|
||||
let buffer = (0..((width * height) as usize))
|
||||
.map(|index| {
|
||||
let y = index / (width as usize);
|
||||
let x = index % (width as usize);
|
||||
let red = x % 255;
|
||||
let green = y % 255;
|
||||
let blue = (x * y) % 255;
|
||||
surface
|
||||
.resize(
|
||||
NonZeroU32::new(width).unwrap(),
|
||||
NonZeroU32::new(height).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let color = blue | (green << 8) | (red << 16);
|
||||
let mut buffer = surface.buffer_mut().unwrap();
|
||||
for index in 0..(width * height) {
|
||||
let y = index / width;
|
||||
let x = index % width;
|
||||
let red = x % 255;
|
||||
let green = y % 255;
|
||||
let blue = (x * y) % 255;
|
||||
|
||||
color as u32
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
buffer[index as usize] = blue | (green << 8) | (red << 16);
|
||||
}
|
||||
|
||||
surface.set_buffer(&buffer, width as u16, height as u16);
|
||||
buffer.present().unwrap();
|
||||
}
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue